]> git.sesse.net Git - vlc/blob - modules/gui/skins2/macosx/macosx_loop.cpp
cosmetic: remove nullity test on free() and delete
[vlc] / modules / gui / skins2 / macosx / macosx_loop.cpp
1 /*****************************************************************************
2  * macosx_loop.cpp
3  *****************************************************************************
4  * Copyright (C) 2003 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #ifdef MACOSX_SKINS
25
26 #include "macosx_loop.hpp"
27 #include "macosx_window.hpp"
28 #include "../src/generic_window.hpp"
29 #include "../events/evt_refresh.hpp"
30
31 static pascal OSStatus WinEventHandler( EventHandlerCallRef handler,
32                                         EventRef event, void *data )
33 {
34     GenericWindow *pWin = (GenericWindow*)data;
35     intf_thread_t *pIntf = pWin->getIntf();
36
37     //fprintf(stderr, "event\n" );
38     UInt32 evclass = GetEventClass( event );
39     UInt32 evkind = GetEventKind( event );
40
41     switch( evclass )
42     {
43     case kEventClassWindow:
44         EvtRefresh evt( pIntf, 0, 0, -1, -1);
45         pWin->processEvent( evt );
46         break;
47     }
48 }
49
50
51 MacOSXLoop::MacOSXLoop( intf_thread_t *pIntf ):
52     OSLoop( pIntf ), m_exit( false )
53 {
54 }
55
56
57 MacOSXLoop::~MacOSXLoop()
58 {
59 }
60
61
62 OSLoop *MacOSXLoop::instance( intf_thread_t *pIntf )
63 {
64     if( pIntf->p_sys->p_osLoop == NULL )
65     {
66         OSLoop *pOsLoop = new MacOSXLoop( pIntf );
67         pIntf->p_sys->p_osLoop = pOsLoop;
68     }
69     return pIntf->p_sys->p_osLoop;
70 }
71
72
73 void MacOSXLoop::destroy( intf_thread_t *pIntf )
74 {
75     delete pIntf->p_sys->p_osLoop;
76     pIntf->p_sys->p_osLoop = NULL;
77 }
78
79
80 void MacOSXLoop::run()
81 {
82     // Main event loop
83     while( !m_exit )
84     {
85         sleep(1);
86     }
87 }
88
89
90 void MacOSXLoop::exit()
91 {
92     m_exit = true;
93 }
94
95
96 void MacOSXLoop::registerWindow( GenericWindow &rGenWin, WindowRef win )
97 {
98     // Create the event handler
99     EventTypeSpec evList[] = {
100         { kEventClassWindow, kEventWindowUpdate },
101         { kEventClassMouse, kEventMouseMoved }
102     };
103     EventHandlerUPP handler = NewEventHandlerUPP( WinEventHandler );
104     InstallWindowEventHandler( win, handler, GetEventTypeCount( evList ),
105                                evList, &rGenWin, NULL );
106 }
107
108 #endif