1 /*****************************************************************************
2 * event.cpp: Event class
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: event.cpp,v 1.5 2003/04/11 22:08:06 videolan 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 ------------------------------------------------------------------
32 #include "skin_common.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()
74 if( Param2 == (int)true )
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;
164 else if( Desc == "VLC_PLAYLIST_ADD_FILE" )
165 return VLC_PLAYLIST_ADD_FILE;
167 // Video output events
168 else if( Desc == "VLC_FULLSCREEN" )
169 return VLC_FULLSCREEN;
172 else if( Desc == "VLC_NET_ADDUDP" )
173 return VLC_NET_ADDUDP;
176 else if( Desc == "WINDOW_MOVE" )
178 else if( Desc == "WINDOW_OPEN" )
180 else if( Desc == "WINDOW_CLOSE" )
182 else if( Desc == "WINDOW_SHOW" )
184 else if( Desc == "WINDOW_HIDE" )
186 else if( Desc == "WINDOW_FADE" )
190 else if( Desc == "CTRL_ENABLED" )
192 else if( Desc == "CTRL_VISIBLE" )
194 else if( Desc == "CTRL_SYNCHRO" )
196 else if( Desc == "CTRL_SET_TEXT" )
197 return CTRL_SET_TEXT;
198 else if( Desc == "CTRL_SET_SLIDER" )
199 return CTRL_SET_SLIDER;
202 // Control event by ID
203 else if( Desc == "CTRL_ID_VISIBLE" )
204 return CTRL_ID_VISIBLE;
205 else if( Desc == "CTRL_ID_ENABLED" )
206 return CTRL_ID_ENABLED;
207 else if( Desc == "CTRL_ID_MOVE" )
210 // Control definition
211 else if( Desc == "CTRL_SLIDER" )
213 else if( Desc == "CTRL_TIME" )
215 else if( Desc == "CTRL_PLAYLIST" )
216 return CTRL_PLAYLIST;
219 else if( Desc == "PLAYLIST_ID_DEL" )
220 return PLAYLIST_ID_DEL;
225 msg_Warn( p_intf, "Theme: Unknown event (%s)", EventDesc.c_str() );
229 //---------------------------------------------------------------------------
230 void Event::CreateEvent()
234 char *msg = new char[MAX_EVENT_SIZE];
235 char *para1 = new char[MAX_PARAM_SIZE];
236 char *para2 = new char[MAX_PARAM_SIZE];
237 char *para3 = new char[MAX_PARAM_SIZE];
240 int scan = sscanf( EventDesc.c_str(),
241 "%[^(](%[^,)],%[^,)],%[^,)])", msg, para1, para2, para3 );
245 strcpy( msg, "VLC_NOTHING" );
254 Message = GetMessageType( msg );
260 Param1 = GetMessageType( para1 );
263 case VLC_VOLUME_CHANGE:
264 if( strcmp( para1, "MUTE" ) == 0 )
265 Param1 = VLC_VOLUME_MUTE;
266 else if( strcmp( para1, "UP" ) == 0 )
267 Param1 = VLC_VOLUME_UP;
268 else if( strcmp( para1, "DOWN" ) == 0 )
269 Param1 = VLC_VOLUME_DOWN;
270 else if( strcmp( para1, "SET" ) == 0 )
272 Param1 = VLC_VOLUME_SET;
273 Param2 = atoi( para2 ) * AOUT_VOLUME_MAX / 100;
278 Param2 = GetBool( para1 );
282 Param2 = atoi( para1 );
285 case CTRL_ID_VISIBLE:
286 Param1 = (unsigned int)FindControl( para1 );
287 Param2 = GetBool( para2 );
290 case CTRL_ID_ENABLED:
291 Param1 = (unsigned int)FindControl( para1 );
292 Param2 = GetBool( para2 );
296 Param1 = (unsigned int)FindControl( para1 );
303 Param2 = ( y << 16 ) | x;
307 Param1 = GetBool( para2 );
311 Param1 = GetBool( para2 );
314 case PLAYLIST_ID_DEL:
315 Param1 = (unsigned int)FindControl( para1 );
322 // Get OS specific parameters
323 CreateOSEvent( para1, para2, para3 );
335 //---------------------------------------------------------------------------
336 GenericControl * Event::FindControl( string id )
338 list<Window *>::const_iterator win;
341 for( win = p_intf->p_sys->p_theme->WindowList.begin();
342 win != p_intf->p_sys->p_theme->WindowList.end(); win++ )
344 for( i = 0; i < (*win)->ControlList.size(); i++ )
346 if( (*win)->ControlList[i]->IsID( id ) )
347 return (*win)->ControlList[i];
353 //---------------------------------------------------------------------------
354 int Event::GetBool( string expr )
356 if( expr == "FALSE" )
360 else if( expr == "TRUE" )
364 else if( expr == "CHANGE" )
370 //---------------------------------------------------------------------------
371 void Event::CreateShortcut()
373 if( Shortcut == "none" )
377 char *mod = new char[4];
378 char *key = new char[4];
381 int scan = sscanf( Shortcut.c_str(), "%[^+]+%s", mod, key );
387 if( (string)mod == "ALT" )
389 else if( (string)mod == "CTRL" )
403 //---------------------------------------------------------------------------
404 bool Event::MatchShortcut( int key, int mod )
410 if( Shortcut != "none" && key == Key && mod == KeyModifier )
415 //---------------------------------------------------------------------------
420 //---------------------------------------------------------------------------
422 //---------------------------------------------------------------------------
423 Action::Action( intf_thread_t *_p_intf, string code )
429 char *evt = new char[MAX_EVENT_SIZE];
430 char *next = new char[MAX_PARAM_SIZE];
432 // Create events separated with a semicolon
433 while( code != "none" )
435 scan = sscanf( code.c_str(), "%[^;];%s", evt, next );
436 EventList.push_back( p_intf->p_sys->p_theme->EvtBank->Get( evt ) );
438 // Check if script is finished
450 //---------------------------------------------------------------------------
455 //---------------------------------------------------------------------------
456 bool Action::SendEvent()
459 for( list<Event *>::const_iterator evt = EventList.begin();
460 evt != EventList.end(); evt++ )
462 res |= (*evt)->SendEvent();
466 //---------------------------------------------------------------------------
467 bool Action::MatchEvent( Event *evt, int flag )
469 list<Event *>::const_iterator event;
473 case ACTION_MATCH_ALL:
474 for( event = EventList.begin(); event != EventList.end(); event++ )
475 if( !(*event)->IsEqual( evt ) )
479 case ACTION_MATCH_ONE:
480 for( event = EventList.begin(); event != EventList.end(); event++ )
481 if( (*event)->IsEqual( evt ) )
486 case ACTION_MATCH_FIRST:
487 if( !(*EventList.begin())->IsEqual( evt ) )
493 //---------------------------------------------------------------------------