1 /*****************************************************************************
2 * event.cpp: Event class
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: event.cpp,v 1.13 2003/04/21 21:51:16 asmax 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 if( Param2 == (int)true || force )
84 delete[] (char *)Param1;
89 //---------------------------------------------------------------------------
90 bool Event::IsEqual( Event *evt )
92 return( evt->GetMessage() == Message && evt->GetParam1() == Param1 &&
93 evt->GetParam2() == Param2 );
95 //---------------------------------------------------------------------------
96 void Event::PostSynchroMessage( bool autodelete )
98 OSAPI_PostMessage( NULL, CTRL_SYNCHRO, (unsigned int)this,
101 //---------------------------------------------------------------------------
102 void Event::PostTextMessage( string text )
104 char *txt = new char[text.size()+1];
105 strcpy( txt, text.c_str() );
106 OSAPI_PostMessage( NULL, CTRL_SET_TEXT, (unsigned int)this, (long)txt );
108 //---------------------------------------------------------------------------
109 unsigned int Event::GetMessageType( string Desc )
111 if( Desc == "VLC_NOTHING" )
115 else if( Desc == "VLC_QUIT" )
117 else if( Desc == "VLC_HIDE" )
119 else if( Desc == "VLC_OPEN" )
121 else if( Desc == "VLC_LOAD_SKIN" )
122 return VLC_LOAD_SKIN;
123 else if( Desc == "VLC_CHANGE_TRAY" )
124 return VLC_CHANGE_TRAY;
125 else if( Desc == "VLC_CHANGE_TASKBAR" )
126 return VLC_CHANGE_TASKBAR;
129 else if( Desc == "VLC_PLAY" )
131 else if( Desc == "VLC_STOP" )
133 else if( Desc == "VLC_PAUSE" )
135 else if( Desc == "VLC_NEXT" )
137 else if( Desc == "VLC_PREV" )
139 else if( Desc == "VLC_STREAMPOS" )
140 return VLC_STREAMPOS;
141 else if( Desc == "VLC_ENDSTREAMPOS" )
142 return VLC_ENDSTREAMPOS;
143 else if( Desc == "VLC_TOTALSTREAMPOS" )
144 return VLC_TOTALSTREAMPOS;
145 else if( Desc == "VLC_STREAMNAME" )
146 return VLC_STREAMNAME;
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_LOG_CLEAR" )
166 return VLC_LOG_CLEAR;
167 else if( Desc == "VLC_PREFS_SHOW" )
168 return VLC_PREFS_SHOW;
169 else if( Desc == "VLC_INFO_SHOW" )
170 return VLC_INFO_SHOW;
173 else if( Desc == "VLC_PLAYLIST_ADD_FILE" )
174 return VLC_PLAYLIST_ADD_FILE;
176 // Video output events
177 else if( Desc == "VLC_FULLSCREEN" )
178 return VLC_FULLSCREEN;
181 else if( Desc == "VLC_NET_ADDUDP" )
182 return VLC_NET_ADDUDP;
183 else if( Desc == "VLC_NET_ADDCS" )
184 return VLC_NET_ADDCS;
187 else if( Desc == "WINDOW_MOVE" )
189 else if( Desc == "WINDOW_OPEN" )
191 else if( Desc == "WINDOW_CLOSE" )
193 else if( Desc == "WINDOW_SHOW" )
195 else if( Desc == "WINDOW_HIDE" )
197 else if( Desc == "WINDOW_FADE" )
201 else if( Desc == "CTRL_ENABLED" )
203 else if( Desc == "CTRL_VISIBLE" )
205 else if( Desc == "CTRL_SYNCHRO" )
207 else if( Desc == "CTRL_SET_TEXT" )
208 return CTRL_SET_TEXT;
209 else if( Desc == "CTRL_SET_SLIDER" )
210 return CTRL_SET_SLIDER;
213 // Control event by ID
214 else if( Desc == "CTRL_ID_VISIBLE" )
215 return CTRL_ID_VISIBLE;
216 else if( Desc == "CTRL_ID_ENABLED" )
217 return CTRL_ID_ENABLED;
218 else if( Desc == "CTRL_ID_MOVE" )
221 // Control definition
222 else if( Desc == "CTRL_SLIDER" )
224 else if( Desc == "CTRL_TIME" )
226 else if( Desc == "CTRL_PLAYLIST" )
227 return CTRL_PLAYLIST;
230 else if( Desc == "PLAYLIST_ID_DEL" )
231 return PLAYLIST_ID_DEL;
236 msg_Warn( p_intf, "Theme: Unknown event (%s)", EventDesc.c_str() );
240 //---------------------------------------------------------------------------
241 void Event::CreateEvent()
245 char *msg = new char[MAX_EVENT_SIZE];
246 char *para1 = new char[MAX_PARAM_SIZE];
247 char *para2 = new char[MAX_PARAM_SIZE];
248 char *para3 = new char[MAX_PARAM_SIZE];
250 // Buffer to create strings
254 int scan = sscanf( EventDesc.c_str(),
255 "%[^(](%[^,)],%[^,)],%[^,)])", msg, para1, para2, para3 );
259 strcpy( msg, "VLC_NOTHING" );
268 Message = GetMessageType( msg );
274 Param1 = GetMessageType( para1 );
277 case VLC_VOLUME_CHANGE:
278 if( strcmp( para1, "MUTE" ) == 0 )
279 Param1 = VLC_VOLUME_MUTE;
280 else if( strcmp( para1, "UP" ) == 0 )
281 Param1 = VLC_VOLUME_UP;
282 else if( strcmp( para1, "DOWN" ) == 0 )
283 Param1 = VLC_VOLUME_DOWN;
284 else if( strcmp( para1, "SET" ) == 0 )
286 Param1 = VLC_VOLUME_SET;
287 Param2 = atoi( para2 ) * AOUT_VOLUME_MAX / 100;
292 Param2 = GetBool( para1 );
296 Param2 = atoi( para1 );
300 buf = new char[MAX_PARAM_SIZE + 7];
301 sprintf( buf, "%s:%s", para1, para2 );
302 Param1 = (unsigned int)buf;
306 case CTRL_ID_VISIBLE:
307 Param1 = (unsigned int)FindControl( para1 );
308 Param2 = GetBool( para2 );
311 case CTRL_ID_ENABLED:
312 Param1 = (unsigned int)FindControl( para1 );
313 Param2 = GetBool( para2 );
317 Param1 = (unsigned int)FindControl( para1 );
324 Param2 = ( y << 16 ) | x;
328 Param1 = GetBool( para2 );
332 Param1 = GetBool( para2 );
335 case PLAYLIST_ID_DEL:
336 Param1 = (unsigned int)FindControl( para1 );
343 // Get OS specific parameters
344 CreateOSEvent( para1, para2, para3 );
356 //---------------------------------------------------------------------------
357 GenericControl * Event::FindControl( string id )
359 list<SkinWindow *>::const_iterator win;
362 for( win = p_intf->p_sys->p_theme->WindowList.begin();
363 win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
365 for( i = 0; i < (*win)->ControlList.size(); i++ )
367 if( (*win)->ControlList[i]->IsID( id ) )
368 return (*win)->ControlList[i];
374 //---------------------------------------------------------------------------
375 int Event::GetBool( string expr )
377 if( expr == "FALSE" )
381 else if( expr == "TRUE" )
385 else if( expr == "CHANGE" )
391 //---------------------------------------------------------------------------
392 void Event::CreateShortcut()
394 if( Shortcut == "none" )
398 char *mod = new char[5];
399 char *key = new char[4];
402 int scan = sscanf( Shortcut.c_str(), "%[^+]+%s", mod, key );
408 if( (string)mod == "ALT" )
410 else if( (string)mod == "CTRL" )
424 //---------------------------------------------------------------------------
425 bool Event::MatchShortcut( int key, int mod )
431 if( Shortcut != "none" && key == Key && mod == KeyModifier )
436 //---------------------------------------------------------------------------
441 //---------------------------------------------------------------------------
443 //---------------------------------------------------------------------------
444 Action::Action( intf_thread_t *_p_intf, string code )
450 char *evt = new char[MAX_EVENT_SIZE];
451 char *next = new char[MAX_PARAM_SIZE];
453 // Create events separated with a semicolon
454 while( code != "none" )
456 scan = sscanf( code.c_str(), "%[^;];%s", evt, next );
457 EventList.push_back( p_intf->p_sys->p_theme->EvtBank->Get( evt ) );
459 // Check if script is finished
471 //---------------------------------------------------------------------------
476 //---------------------------------------------------------------------------
477 bool Action::SendEvent()
480 for( list<Event *>::const_iterator evt = EventList.begin();
481 evt != EventList.end(); evt++ )
483 res |= (*evt)->SendEvent();
487 //---------------------------------------------------------------------------
488 bool Action::MatchEvent( Event *evt, int flag )
490 list<Event *>::const_iterator event;
494 case ACTION_MATCH_ALL:
495 for( event = EventList.begin(); event != EventList.end(); event++ )
496 if( !(*event)->IsEqual( evt ) )
500 case ACTION_MATCH_ONE:
501 for( event = EventList.begin(); event != EventList.end(); event++ )
502 if( (*event)->IsEqual( evt ) )
507 case ACTION_MATCH_FIRST:
508 if( !(*EventList.begin())->IsEqual( evt ) )
514 //---------------------------------------------------------------------------