1 /*****************************************************************************
2 * event.cpp: Event class
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: event.cpp,v 1.17 2003/06/20 21:34:37 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;
84 //---------------------------------------------------------------------------
85 bool Event::IsEqual( Event *evt )
87 return( evt->GetMessage() == Message && evt->GetParam1() == Param1 &&
88 evt->GetParam2() == Param2 );
90 //---------------------------------------------------------------------------
91 void Event::PostSynchroMessage( bool autodelete )
93 OSAPI_PostMessage( NULL, CTRL_SYNCHRO, (unsigned int)this,
96 //---------------------------------------------------------------------------
97 void Event::PostTextMessage( string text )
99 char *txt = new char[text.size()+1];
100 strcpy( txt, text.c_str() );
101 OSAPI_PostMessage( NULL, CTRL_SET_TEXT, (unsigned int)this, (long)txt );
103 //---------------------------------------------------------------------------
104 unsigned int Event::GetMessageType( string Desc )
106 if( Desc == "VLC_NOTHING" )
110 else if( Desc == "VLC_QUIT" )
112 else if( Desc == "VLC_HIDE" )
114 else if( Desc == "VLC_OPEN" )
116 else if( Desc == "VLC_LOAD_SKIN" )
117 return VLC_LOAD_SKIN;
118 else if( Desc == "VLC_CHANGE_TRAY" )
119 return VLC_CHANGE_TRAY;
120 else if( Desc == "VLC_CHANGE_TASKBAR" )
121 return VLC_CHANGE_TASKBAR;
124 else if( Desc == "VLC_PLAY" )
126 else if( Desc == "VLC_STOP" )
128 else if( Desc == "VLC_PAUSE" )
130 else if( Desc == "VLC_NEXT" )
132 else if( Desc == "VLC_PREV" )
134 else if( Desc == "VLC_STREAMPOS" )
135 return VLC_STREAMPOS;
136 else if( Desc == "VLC_ENDSTREAMPOS" )
137 return VLC_ENDSTREAMPOS;
138 else if( Desc == "VLC_TOTALSTREAMPOS" )
139 return VLC_TOTALSTREAMPOS;
140 else if( Desc == "VLC_STREAM_NAME" )
141 return VLC_STREAM_NAME;
142 else if( Desc == "VLC_STREAM_TITLE" )
143 return VLC_STREAM_TITLE;
144 else if( Desc == "VLC_HELP_TEXT" )
145 return VLC_HELP_TEXT;
148 else if( Desc == "VLC_VOLUME_CHANGE" )
149 return VLC_VOLUME_CHANGE;
150 else if( Desc == "VLC_VOLUME_MUTE" )
151 return VLC_VOLUME_MUTE;
152 else if( Desc == "VLC_VOLUME_UP" )
153 return VLC_VOLUME_UP;
154 else if( Desc == "VLC_VOLUME_DOWN" )
155 return VLC_VOLUME_DOWN;
156 else if( Desc == "VLC_VOLUME_SET" )
157 return VLC_VOLUME_SET;
160 else if( Desc == "VLC_LOG_SHOW" )
162 else if( Desc == "VLC_LOG_CLEAR" )
163 return VLC_LOG_CLEAR;
164 else if( Desc == "VLC_PREFS_SHOW" )
165 return VLC_PREFS_SHOW;
166 else if( Desc == "VLC_INFO_SHOW" )
167 return VLC_INFO_SHOW;
170 else if( Desc == "VLC_PLAYLIST_ADD_FILE" )
171 return VLC_PLAYLIST_ADD_FILE;
173 // Video output events
174 else if( Desc == "VLC_FULLSCREEN" )
175 return VLC_FULLSCREEN;
178 else if( Desc == "VLC_NET_ADDUDP" )
179 return VLC_NET_ADDUDP;
182 else if( Desc == "WINDOW_MOVE" )
184 else if( Desc == "WINDOW_OPEN" )
186 else if( Desc == "WINDOW_CLOSE" )
188 else if( Desc == "WINDOW_SHOW" )
190 else if( Desc == "WINDOW_HIDE" )
192 else if( Desc == "WINDOW_FADE" )
196 else if( Desc == "CTRL_ENABLED" )
198 else if( Desc == "CTRL_VISIBLE" )
200 else if( Desc == "CTRL_SYNCHRO" )
202 else if( Desc == "CTRL_SET_TEXT" )
203 return CTRL_SET_TEXT;
204 else if( Desc == "CTRL_SET_SLIDER" )
205 return CTRL_SET_SLIDER;
208 // Control events by ID
209 else if( Desc == "CTRL_ID_VISIBLE" )
210 return CTRL_ID_VISIBLE;
211 else if( Desc == "CTRL_ID_ENABLED" )
212 return CTRL_ID_ENABLED;
213 else if( Desc == "CTRL_ID_MOVE" )
216 // Control definition
217 else if( Desc == "CTRL_SLIDER" )
219 else if( Desc == "CTRL_TIME" )
221 else if( Desc == "CTRL_PLAYLIST" )
222 return CTRL_PLAYLIST;
225 else if( Desc == "PLAYLIST_ID_DEL" )
226 return PLAYLIST_ID_DEL;
231 msg_Warn( p_intf, "Theme: Unknown event (%s)", EventDesc.c_str() );
235 //---------------------------------------------------------------------------
236 void Event::CreateEvent()
240 char *msg = new char[MAX_EVENT_SIZE];
241 char *para1 = new char[MAX_PARAM_SIZE];
242 char *para2 = new char[MAX_PARAM_SIZE];
243 char *para3 = new char[MAX_PARAM_SIZE];
246 int scan = sscanf( EventDesc.c_str(),
247 "%[^(](%[^,)],%[^,)],%[^,)])", msg, para1, para2, para3 );
251 strcpy( msg, "VLC_NOTHING" );
260 Message = GetMessageType( msg );
266 Param1 = GetMessageType( para1 );
269 case VLC_VOLUME_CHANGE:
270 if( strcmp( para1, "MUTE" ) == 0 )
271 Param1 = VLC_VOLUME_MUTE;
272 else if( strcmp( para1, "UP" ) == 0 )
273 Param1 = VLC_VOLUME_UP;
274 else if( strcmp( para1, "DOWN" ) == 0 )
275 Param1 = VLC_VOLUME_DOWN;
276 else if( strcmp( para1, "SET" ) == 0 )
278 Param1 = VLC_VOLUME_SET;
279 Param2 = atoi( para2 ) * AOUT_VOLUME_MAX / 100;
284 Param2 = GetBool( para1 );
288 Param2 = atoi( para1 );
291 case CTRL_ID_VISIBLE:
292 Param1 = (unsigned int)FindControl( para1 );
293 Param2 = GetBool( para2 );
296 case CTRL_ID_ENABLED:
297 Param1 = (unsigned int)FindControl( para1 );
298 Param2 = GetBool( para2 );
302 Param1 = (unsigned int)FindControl( para1 );
309 Param2 = ( y << 16 ) | x;
313 Param1 = GetBool( para2 );
317 Param1 = GetBool( para2 );
320 case PLAYLIST_ID_DEL:
321 Param1 = (unsigned int)FindControl( para1 );
328 // Get OS specific parameters
329 CreateOSEvent( para1, para2, para3 );
341 //---------------------------------------------------------------------------
342 GenericControl * Event::FindControl( string id )
344 list<SkinWindow *>::const_iterator win;
347 for( win = p_intf->p_sys->p_theme->WindowList.begin();
348 win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
350 for( i = 0; i < (*win)->ControlList.size(); i++ )
352 if( (*win)->ControlList[i]->GetId() == id )
353 return (*win)->ControlList[i];
359 //---------------------------------------------------------------------------
360 int Event::GetBool( string expr )
362 if( expr == "FALSE" )
366 else if( expr == "TRUE" )
370 else if( expr == "CHANGE" )
376 //---------------------------------------------------------------------------
377 void Event::CreateShortcut()
379 if( Shortcut == "none" )
383 char *mod = new char[5];
384 char *key = new char[4];
387 int scan = sscanf( Shortcut.c_str(), "%[^+]+%s", mod, key );
393 if( (string)mod == "ALT" )
395 else if( (string)mod == "CTRL" )
409 //---------------------------------------------------------------------------
410 bool Event::MatchShortcut( int key, int mod )
416 if( Shortcut != "none" && key == Key && mod == KeyModifier )
421 //---------------------------------------------------------------------------
426 //---------------------------------------------------------------------------
428 //---------------------------------------------------------------------------
429 Action::Action( intf_thread_t *_p_intf, string code )
435 char *evt = new char[MAX_EVENT_SIZE];
436 char *next = new char[MAX_PARAM_SIZE];
438 // Create events separated with a semicolon
439 while( code != "none" )
441 scan = sscanf( code.c_str(), "%[^;];%s", evt, next );
442 EventList.push_back( p_intf->p_sys->p_theme->EvtBank->Get( evt ) );
444 // Check if script is finished
456 //---------------------------------------------------------------------------
461 //---------------------------------------------------------------------------
462 bool Action::SendEvent()
465 for( list<Event *>::const_iterator evt = EventList.begin();
466 evt != EventList.end(); evt++ )
468 res |= (*evt)->SendEvent();
472 //---------------------------------------------------------------------------
473 bool Action::MatchEvent( Event *evt, int flag )
475 list<Event *>::const_iterator event;
479 case ACTION_MATCH_ALL:
480 for( event = EventList.begin(); event != EventList.end(); event++ )
481 if( !(*event)->IsEqual( evt ) )
485 case ACTION_MATCH_ONE:
486 for( event = EventList.begin(); event != EventList.end(); event++ )
487 if( (*event)->IsEqual( evt ) )
492 case ACTION_MATCH_FIRST:
493 if( !(*EventList.begin())->IsEqual( evt ) )
499 //---------------------------------------------------------------------------