1 /*****************************************************************************
2 * event.cpp: Event class
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: event.cpp,v 1.23 2003/10/17 18:17:28 ipkiss Exp $
7 * Authors: Olivier Teulière <ipkiss@via.ecp.fr>
8 * Emmanuel Puig <karibu@via.ecp.fr>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111,
24 *****************************************************************************/
27 //--- VLC -------------------------------------------------------------------
30 //--- SKIN ------------------------------------------------------------------
31 #include "../os_api.h"
32 #include "skin_common.h"
34 #include "../controls/generic.h"
38 #include "../os_event.h"
42 //---------------------------------------------------------------------------
44 //---------------------------------------------------------------------------
45 Event::Event( intf_thread_t *_p_intf, string Desc, string shortcut )
49 Message = VLC_NOTHING;
54 //---------------------------------------------------------------------------
55 Event::Event( intf_thread_t *_p_intf, unsigned int msg, unsigned int par1,
64 //---------------------------------------------------------------------------
68 //---------------------------------------------------------------------------
69 void Event::DestructParameters( bool force )
74 if( Param2 == (int)true || force )
75 delete (Event *)Param1;
79 delete[] (char *)Param2;
83 //---------------------------------------------------------------------------
84 bool Event::IsEqual( Event *evt )
86 return( evt->GetMessage() == Message && evt->GetParam1() == Param1 &&
87 evt->GetParam2() == Param2 );
89 //---------------------------------------------------------------------------
90 void Event::PostSynchroMessage( bool autodelete )
92 OSAPI_PostMessage( NULL, CTRL_SYNCHRO, (unsigned int)this,
95 //---------------------------------------------------------------------------
96 void Event::PostTextMessage( string text )
98 char *txt = new char[text.size()+1];
99 strcpy( txt, text.c_str() );
100 OSAPI_PostMessage( NULL, CTRL_SET_TEXT, (unsigned int)this, (long)txt );
102 //---------------------------------------------------------------------------
103 unsigned int Event::GetMessageType( string Desc )
105 if( Desc == "VLC_NOTHING" )
109 else if( Desc == "VLC_QUIT" )
111 else if( Desc == "VLC_HIDE" )
113 else if( Desc == "VLC_OPEN" )
115 else if( Desc == "VLC_NET" )
117 else if( Desc == "VLC_LOAD_SKIN" )
118 return VLC_LOAD_SKIN;
119 else if( Desc == "VLC_ON_TOP" )
121 else if( Desc == "VLC_CHANGE_TRAY" )
122 return VLC_CHANGE_TRAY;
123 else if( Desc == "VLC_CHANGE_TASKBAR" )
124 return VLC_CHANGE_TASKBAR;
127 else if( Desc == "VLC_PLAY" )
129 else if( Desc == "VLC_STOP" )
131 else if( Desc == "VLC_PAUSE" )
133 else if( Desc == "VLC_NEXT" )
135 else if( Desc == "VLC_PREV" )
137 else if( Desc == "VLC_STREAMPOS" )
138 return VLC_STREAMPOS;
139 else if( Desc == "VLC_ENDSTREAMPOS" )
140 return VLC_ENDSTREAMPOS;
141 else if( Desc == "VLC_TOTALSTREAMPOS" )
142 return VLC_TOTALSTREAMPOS;
143 else if( Desc == "VLC_STREAM_NAME" )
144 return VLC_STREAM_NAME;
145 else if( Desc == "VLC_STREAM_TITLE" )
146 return VLC_STREAM_TITLE;
147 else if( Desc == "VLC_HELP_TEXT" )
148 return VLC_HELP_TEXT;
151 else if( Desc == "VLC_VOLUME_CHANGE" )
152 return VLC_VOLUME_CHANGE;
153 else if( Desc == "VLC_VOLUME_MUTE" )
154 return VLC_VOLUME_MUTE;
155 else if( Desc == "VLC_VOLUME_UP" )
156 return VLC_VOLUME_UP;
157 else if( Desc == "VLC_VOLUME_DOWN" )
158 return VLC_VOLUME_DOWN;
159 else if( Desc == "VLC_VOLUME_SET" )
160 return VLC_VOLUME_SET;
163 else if( Desc == "VLC_LOG_SHOW" )
165 else if( Desc == "VLC_PREFS_SHOW" )
166 return VLC_PREFS_SHOW;
167 else if( Desc == "VLC_INFO_SHOW" )
168 return VLC_INFO_SHOW;
171 else if( Desc == "VLC_PLAYLIST_ADD_FILE" )
172 return VLC_PLAYLIST_ADD_FILE;
174 // Video output events
175 else if( Desc == "VLC_FULLSCREEN" )
176 return VLC_FULLSCREEN;
179 else if( Desc == "WINDOW_MOVE" )
181 else if( Desc == "WINDOW_OPEN" )
183 else if( Desc == "WINDOW_CLOSE" )
185 else if( Desc == "WINDOW_SHOW" )
187 else if( Desc == "WINDOW_HIDE" )
189 else if( Desc == "WINDOW_FADE" )
193 else if( Desc == "CTRL_ENABLED" )
195 else if( Desc == "CTRL_VISIBLE" )
197 else if( Desc == "CTRL_SYNCHRO" )
199 else if( Desc == "CTRL_SET_TEXT" )
200 return CTRL_SET_TEXT;
201 else if( Desc == "CTRL_SET_SLIDER" )
202 return CTRL_SET_SLIDER;
205 // Control events by ID
206 else if( Desc == "CTRL_ID_VISIBLE" )
207 return CTRL_ID_VISIBLE;
208 else if( Desc == "CTRL_ID_ENABLED" )
209 return CTRL_ID_ENABLED;
210 else if( Desc == "CTRL_ID_MOVE" )
213 // Control definition
214 else if( Desc == "CTRL_SLIDER" )
216 else if( Desc == "CTRL_TIME" )
218 else if( Desc == "CTRL_PLAYLIST" )
219 return CTRL_PLAYLIST;
222 else if( Desc == "PLAYLIST_ID_DEL" )
223 return PLAYLIST_ID_DEL;
228 msg_Warn( p_intf, "Theme: Unknown event (%s)", EventDesc.c_str() );
232 //---------------------------------------------------------------------------
233 void Event::CreateEvent()
237 char *msg = new char[MAX_EVENT_SIZE];
238 char *para1 = new char[MAX_PARAM_SIZE];
239 char *para2 = new char[MAX_PARAM_SIZE];
240 char *para3 = new char[MAX_PARAM_SIZE];
243 int scan = sscanf( EventDesc.c_str(),
244 "%[^(](%[^,)],%[^,)],%[^,)])", msg, para1, para2, para3 );
248 strcpy( msg, "VLC_NOTHING" );
257 Message = GetMessageType( msg );
263 Param1 = GetMessageType( para1 );
266 case VLC_VOLUME_CHANGE:
267 if( strcmp( para1, "MUTE" ) == 0 )
268 Param1 = VLC_VOLUME_MUTE;
269 else if( strcmp( para1, "UP" ) == 0 )
270 Param1 = VLC_VOLUME_UP;
271 else if( strcmp( para1, "DOWN" ) == 0 )
272 Param1 = VLC_VOLUME_DOWN;
273 else if( strcmp( para1, "SET" ) == 0 )
275 Param1 = VLC_VOLUME_SET;
276 Param2 = atoi( para2 ) * (AOUT_VOLUME_MAX * 2) / 100;
281 Param2 = GetBool( para1 );
284 case CTRL_ID_VISIBLE:
285 Param1 = (unsigned int)FindControl( para1 );
286 Param2 = GetBool( para2 );
289 case CTRL_ID_ENABLED:
290 Param1 = (unsigned int)FindControl( para1 );
291 Param2 = GetBool( para2 );
295 Param1 = (unsigned int)FindControl( para1 );
302 Param2 = ( y << 16 ) | x;
306 Param1 = GetBool( para2 );
310 Param1 = GetBool( para2 );
313 case PLAYLIST_ID_DEL:
314 Param1 = (unsigned int)FindControl( para1 );
321 // Get OS specific parameters
322 CreateOSEvent( para1, para2, para3 );
333 //---------------------------------------------------------------------------
334 GenericControl * Event::FindControl( string id )
336 list<SkinWindow *>::const_iterator win;
339 for( win = p_intf->p_sys->p_theme->WindowList.begin();
340 win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
342 for( i = 0; i < (*win)->ControlList.size(); i++ )
344 if( (*win)->ControlList[i]->GetId() == id )
345 return (*win)->ControlList[i];
350 //---------------------------------------------------------------------------
351 int Event::GetBool( string expr )
353 if( expr == "FALSE" )
357 else if( expr == "TRUE" )
361 else if( expr == "CHANGE" )
367 //---------------------------------------------------------------------------
368 void Event::CreateShortcut()
370 if( Shortcut == "none" )
374 char *mod = new char[5];
375 char *key = new char[4];
378 int scan = sscanf( Shortcut.c_str(), "%[^+]+%s", mod, key );
384 if( (string)mod == "ALT" )
386 else if( (string)mod == "CTRL" )
400 //---------------------------------------------------------------------------
401 bool Event::MatchShortcut( int key, int mod )
407 if( Shortcut != "none" && key == Key && mod == KeyModifier )
412 //---------------------------------------------------------------------------
417 //---------------------------------------------------------------------------
419 //---------------------------------------------------------------------------
420 Action::Action( intf_thread_t *_p_intf, string code )
426 char *evt = new char[MAX_EVENT_SIZE];
427 char *next = new char[MAX_PARAM_SIZE];
429 // Create events separated with a semicolon
430 while( code != "none" )
432 scan = sscanf( code.c_str(), "%[^;];%s", evt, next );
433 EventList.push_back( p_intf->p_sys->p_theme->EvtBank->Get( evt ) );
435 // Check if script is finished
446 //---------------------------------------------------------------------------
450 //---------------------------------------------------------------------------
451 bool Action::SendEvent()
454 for( list<Event *>::const_iterator evt = EventList.begin();
455 evt != EventList.end(); evt++ )
457 res |= (*evt)->SendEvent();
461 //---------------------------------------------------------------------------
462 bool Action::MatchEvent( Event *evt, int flag )
464 list<Event *>::const_iterator event;
468 case ACTION_MATCH_ALL:
469 for( event = EventList.begin(); event != EventList.end(); event++ )
470 if( !(*event)->IsEqual( evt ) )
474 case ACTION_MATCH_ONE:
475 for( event = EventList.begin(); event != EventList.end(); event++ )
476 if( (*event)->IsEqual( evt ) )
481 case ACTION_MATCH_FIRST:
482 if( !(*EventList.begin())->IsEqual( evt ) )
488 //---------------------------------------------------------------------------