1 /*****************************************************************************
2 * event.cpp: Event class
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: event.cpp,v 1.16 2003/05/31 23:23:59 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_STREAMNAME" )
141 return VLC_STREAMNAME;
142 else if( Desc == "VLC_HELP_TEXT" )
143 return VLC_HELP_TEXT;
146 else if( Desc == "VLC_VOLUME_CHANGE" )
147 return VLC_VOLUME_CHANGE;
148 else if( Desc == "VLC_VOLUME_MUTE" )
149 return VLC_VOLUME_MUTE;
150 else if( Desc == "VLC_VOLUME_UP" )
151 return VLC_VOLUME_UP;
152 else if( Desc == "VLC_VOLUME_DOWN" )
153 return VLC_VOLUME_DOWN;
154 else if( Desc == "VLC_VOLUME_SET" )
155 return VLC_VOLUME_SET;
158 else if( Desc == "VLC_LOG_SHOW" )
160 else if( Desc == "VLC_LOG_CLEAR" )
161 return VLC_LOG_CLEAR;
162 else if( Desc == "VLC_PREFS_SHOW" )
163 return VLC_PREFS_SHOW;
164 else if( Desc == "VLC_INFO_SHOW" )
165 return VLC_INFO_SHOW;
168 else if( Desc == "VLC_PLAYLIST_ADD_FILE" )
169 return VLC_PLAYLIST_ADD_FILE;
171 // Video output events
172 else if( Desc == "VLC_FULLSCREEN" )
173 return VLC_FULLSCREEN;
176 else if( Desc == "VLC_NET_ADDUDP" )
177 return VLC_NET_ADDUDP;
180 else if( Desc == "WINDOW_MOVE" )
182 else if( Desc == "WINDOW_OPEN" )
184 else if( Desc == "WINDOW_CLOSE" )
186 else if( Desc == "WINDOW_SHOW" )
188 else if( Desc == "WINDOW_HIDE" )
190 else if( Desc == "WINDOW_FADE" )
194 else if( Desc == "CTRL_ENABLED" )
196 else if( Desc == "CTRL_VISIBLE" )
198 else if( Desc == "CTRL_SYNCHRO" )
200 else if( Desc == "CTRL_SET_TEXT" )
201 return CTRL_SET_TEXT;
202 else if( Desc == "CTRL_SET_SLIDER" )
203 return CTRL_SET_SLIDER;
206 // Control events by ID
207 else if( Desc == "CTRL_ID_VISIBLE" )
208 return CTRL_ID_VISIBLE;
209 else if( Desc == "CTRL_ID_ENABLED" )
210 return CTRL_ID_ENABLED;
211 else if( Desc == "CTRL_ID_MOVE" )
214 // Control definition
215 else if( Desc == "CTRL_SLIDER" )
217 else if( Desc == "CTRL_TIME" )
219 else if( Desc == "CTRL_PLAYLIST" )
220 return CTRL_PLAYLIST;
223 else if( Desc == "PLAYLIST_ID_DEL" )
224 return PLAYLIST_ID_DEL;
229 msg_Warn( p_intf, "Theme: Unknown event (%s)", EventDesc.c_str() );
233 //---------------------------------------------------------------------------
234 void Event::CreateEvent()
238 char *msg = new char[MAX_EVENT_SIZE];
239 char *para1 = new char[MAX_PARAM_SIZE];
240 char *para2 = new char[MAX_PARAM_SIZE];
241 char *para3 = new char[MAX_PARAM_SIZE];
244 int scan = sscanf( EventDesc.c_str(),
245 "%[^(](%[^,)],%[^,)],%[^,)])", msg, para1, para2, para3 );
249 strcpy( msg, "VLC_NOTHING" );
258 Message = GetMessageType( msg );
264 Param1 = GetMessageType( para1 );
267 case VLC_VOLUME_CHANGE:
268 if( strcmp( para1, "MUTE" ) == 0 )
269 Param1 = VLC_VOLUME_MUTE;
270 else if( strcmp( para1, "UP" ) == 0 )
271 Param1 = VLC_VOLUME_UP;
272 else if( strcmp( para1, "DOWN" ) == 0 )
273 Param1 = VLC_VOLUME_DOWN;
274 else if( strcmp( para1, "SET" ) == 0 )
276 Param1 = VLC_VOLUME_SET;
277 Param2 = atoi( para2 ) * AOUT_VOLUME_MAX / 100;
282 Param2 = GetBool( para1 );
286 Param2 = atoi( para1 );
289 case CTRL_ID_VISIBLE:
290 Param1 = (unsigned int)FindControl( para1 );
291 Param2 = GetBool( para2 );
294 case CTRL_ID_ENABLED:
295 Param1 = (unsigned int)FindControl( para1 );
296 Param2 = GetBool( para2 );
300 Param1 = (unsigned int)FindControl( para1 );
307 Param2 = ( y << 16 ) | x;
311 Param1 = GetBool( para2 );
315 Param1 = GetBool( para2 );
318 case PLAYLIST_ID_DEL:
319 Param1 = (unsigned int)FindControl( para1 );
326 // Get OS specific parameters
327 CreateOSEvent( para1, para2, para3 );
339 //---------------------------------------------------------------------------
340 GenericControl * Event::FindControl( string id )
342 list<SkinWindow *>::const_iterator win;
345 for( win = p_intf->p_sys->p_theme->WindowList.begin();
346 win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
348 for( i = 0; i < (*win)->ControlList.size(); i++ )
350 if( (*win)->ControlList[i]->GetId() == id )
351 return (*win)->ControlList[i];
357 //---------------------------------------------------------------------------
358 int Event::GetBool( string expr )
360 if( expr == "FALSE" )
364 else if( expr == "TRUE" )
368 else if( expr == "CHANGE" )
374 //---------------------------------------------------------------------------
375 void Event::CreateShortcut()
377 if( Shortcut == "none" )
381 char *mod = new char[5];
382 char *key = new char[4];
385 int scan = sscanf( Shortcut.c_str(), "%[^+]+%s", mod, key );
391 if( (string)mod == "ALT" )
393 else if( (string)mod == "CTRL" )
407 //---------------------------------------------------------------------------
408 bool Event::MatchShortcut( int key, int mod )
414 if( Shortcut != "none" && key == Key && mod == KeyModifier )
419 //---------------------------------------------------------------------------
424 //---------------------------------------------------------------------------
426 //---------------------------------------------------------------------------
427 Action::Action( intf_thread_t *_p_intf, string code )
433 char *evt = new char[MAX_EVENT_SIZE];
434 char *next = new char[MAX_PARAM_SIZE];
436 // Create events separated with a semicolon
437 while( code != "none" )
439 scan = sscanf( code.c_str(), "%[^;];%s", evt, next );
440 EventList.push_back( p_intf->p_sys->p_theme->EvtBank->Get( evt ) );
442 // Check if script is finished
454 //---------------------------------------------------------------------------
459 //---------------------------------------------------------------------------
460 bool Action::SendEvent()
463 for( list<Event *>::const_iterator evt = EventList.begin();
464 evt != EventList.end(); evt++ )
466 res |= (*evt)->SendEvent();
470 //---------------------------------------------------------------------------
471 bool Action::MatchEvent( Event *evt, int flag )
473 list<Event *>::const_iterator event;
477 case ACTION_MATCH_ALL:
478 for( event = EventList.begin(); event != EventList.end(); event++ )
479 if( !(*event)->IsEqual( evt ) )
483 case ACTION_MATCH_ONE:
484 for( event = EventList.begin(); event != EventList.end(); event++ )
485 if( (*event)->IsEqual( evt ) )
490 case ACTION_MATCH_FIRST:
491 if( !(*EventList.begin())->IsEqual( evt ) )
497 //---------------------------------------------------------------------------