1 /*****************************************************************************
2 * event.cpp: Event class
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: event.cpp,v 1.24 2004/02/15 18:58:38 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;
149 else if( Desc == "VLC_SLOWER" )
151 else if( Desc == "VLC_FASTER" )
155 else if( Desc == "VLC_VOLUME_CHANGE" )
156 return VLC_VOLUME_CHANGE;
157 else if( Desc == "VLC_VOLUME_MUTE" )
158 return VLC_VOLUME_MUTE;
159 else if( Desc == "VLC_VOLUME_UP" )
160 return VLC_VOLUME_UP;
161 else if( Desc == "VLC_VOLUME_DOWN" )
162 return VLC_VOLUME_DOWN;
163 else if( Desc == "VLC_VOLUME_SET" )
164 return VLC_VOLUME_SET;
167 else if( Desc == "VLC_LOG_SHOW" )
169 else if( Desc == "VLC_PREFS_SHOW" )
170 return VLC_PREFS_SHOW;
171 else if( Desc == "VLC_INFO_SHOW" )
172 return VLC_INFO_SHOW;
175 else if( Desc == "VLC_PLAYLIST_ADD_FILE" )
176 return VLC_PLAYLIST_ADD_FILE;
178 // Video output events
179 else if( Desc == "VLC_FULLSCREEN" )
180 return VLC_FULLSCREEN;
183 else if( Desc == "WINDOW_MOVE" )
185 else if( Desc == "WINDOW_OPEN" )
187 else if( Desc == "WINDOW_CLOSE" )
189 else if( Desc == "WINDOW_SHOW" )
191 else if( Desc == "WINDOW_HIDE" )
193 else if( Desc == "WINDOW_FADE" )
197 else if( Desc == "CTRL_ENABLED" )
199 else if( Desc == "CTRL_VISIBLE" )
201 else if( Desc == "CTRL_SYNCHRO" )
203 else if( Desc == "CTRL_SET_TEXT" )
204 return CTRL_SET_TEXT;
205 else if( Desc == "CTRL_SET_SLIDER" )
206 return CTRL_SET_SLIDER;
209 // Control events by ID
210 else if( Desc == "CTRL_ID_VISIBLE" )
211 return CTRL_ID_VISIBLE;
212 else if( Desc == "CTRL_ID_ENABLED" )
213 return CTRL_ID_ENABLED;
214 else if( Desc == "CTRL_ID_MOVE" )
217 // Control definition
218 else if( Desc == "CTRL_SLIDER" )
220 else if( Desc == "CTRL_TIME" )
222 else if( Desc == "CTRL_PLAYLIST" )
223 return CTRL_PLAYLIST;
226 else if( Desc == "PLAYLIST_ID_DEL" )
227 return PLAYLIST_ID_DEL;
232 msg_Warn( p_intf, "Theme: Unknown event (%s)", EventDesc.c_str() );
236 //---------------------------------------------------------------------------
237 void Event::CreateEvent()
241 char *msg = new char[MAX_EVENT_SIZE];
242 char *para1 = new char[MAX_PARAM_SIZE];
243 char *para2 = new char[MAX_PARAM_SIZE];
244 char *para3 = new char[MAX_PARAM_SIZE];
247 int scan = sscanf( EventDesc.c_str(),
248 "%[^(](%[^,)],%[^,)],%[^,)])", msg, para1, para2, para3 );
252 strcpy( msg, "VLC_NOTHING" );
261 Message = GetMessageType( msg );
267 Param1 = GetMessageType( para1 );
270 case VLC_VOLUME_CHANGE:
271 if( strcmp( para1, "MUTE" ) == 0 )
272 Param1 = VLC_VOLUME_MUTE;
273 else if( strcmp( para1, "UP" ) == 0 )
274 Param1 = VLC_VOLUME_UP;
275 else if( strcmp( para1, "DOWN" ) == 0 )
276 Param1 = VLC_VOLUME_DOWN;
277 else if( strcmp( para1, "SET" ) == 0 )
279 Param1 = VLC_VOLUME_SET;
280 Param2 = atoi( para2 ) * (AOUT_VOLUME_MAX * 2) / 100;
285 Param2 = GetBool( para1 );
288 case CTRL_ID_VISIBLE:
289 Param1 = (unsigned int)FindControl( para1 );
290 Param2 = GetBool( para2 );
293 case CTRL_ID_ENABLED:
294 Param1 = (unsigned int)FindControl( para1 );
295 Param2 = GetBool( para2 );
299 Param1 = (unsigned int)FindControl( para1 );
306 Param2 = ( y << 16 ) | x;
310 Param1 = GetBool( para2 );
314 Param1 = GetBool( para2 );
317 case PLAYLIST_ID_DEL:
318 Param1 = (unsigned int)FindControl( para1 );
325 // Get OS specific parameters
326 CreateOSEvent( para1, para2, para3 );
337 //---------------------------------------------------------------------------
338 GenericControl * Event::FindControl( string id )
340 list<SkinWindow *>::const_iterator win;
343 for( win = p_intf->p_sys->p_theme->WindowList.begin();
344 win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
346 for( i = 0; i < (*win)->ControlList.size(); i++ )
348 if( (*win)->ControlList[i]->GetId() == id )
349 return (*win)->ControlList[i];
354 //---------------------------------------------------------------------------
355 int Event::GetBool( string expr )
357 if( expr == "FALSE" )
361 else if( expr == "TRUE" )
365 else if( expr == "CHANGE" )
371 //---------------------------------------------------------------------------
372 void Event::CreateShortcut()
374 if( Shortcut == "none" )
378 char *mod = new char[5];
379 char *key = new char[4];
382 int scan = sscanf( Shortcut.c_str(), "%[^+]+%s", mod, key );
388 if( (string)mod == "ALT" )
390 else if( (string)mod == "CTRL" )
404 //---------------------------------------------------------------------------
405 bool Event::MatchShortcut( int key, int mod )
411 if( Shortcut != "none" && key == Key && mod == KeyModifier )
416 //---------------------------------------------------------------------------
421 //---------------------------------------------------------------------------
423 //---------------------------------------------------------------------------
424 Action::Action( intf_thread_t *_p_intf, string code )
430 char *evt = new char[MAX_EVENT_SIZE];
431 char *next = new char[MAX_PARAM_SIZE];
433 // Create events separated with a semicolon
434 while( code != "none" )
436 scan = sscanf( code.c_str(), "%[^;];%s", evt, next );
437 EventList.push_back( p_intf->p_sys->p_theme->EvtBank->Get( evt ) );
439 // Check if script is finished
450 //---------------------------------------------------------------------------
454 //---------------------------------------------------------------------------
455 bool Action::SendEvent()
458 for( list<Event *>::const_iterator evt = EventList.begin();
459 evt != EventList.end(); evt++ )
461 res |= (*evt)->SendEvent();
465 //---------------------------------------------------------------------------
466 bool Action::MatchEvent( Event *evt, int flag )
468 list<Event *>::const_iterator event;
472 case ACTION_MATCH_ALL:
473 for( event = EventList.begin(); event != EventList.end(); event++ )
474 if( !(*event)->IsEqual( evt ) )
478 case ACTION_MATCH_ONE:
479 for( event = EventList.begin(); event != EventList.end(); event++ )
480 if( (*event)->IsEqual( evt ) )
485 case ACTION_MATCH_FIRST:
486 if( !(*EventList.begin())->IsEqual( evt ) )
492 //---------------------------------------------------------------------------