]> git.sesse.net Git - vlc/blob - modules/gui/wince/wince.cpp
* modules/gui/wince: try to save up a bit on memory usage.
[vlc] / modules / gui / wince / wince.cpp
1 /*****************************************************************************
2  * wince.cpp: WinCE gui plugin for VLC
3  *****************************************************************************
4  * Copyright (C) 2003 VideoLAN
5  * $Id$
6  *
7  * Author: Gildas Bazin <gbazin@videolan.org>
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., 59 Temple Place - Suite 330, Boston, MA  02111,
22  * USA.
23  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #include <vlc/vlc.h>
29 #include <vlc/intf.h>
30
31 #if defined( UNDER_CE ) && defined(__MINGW32__)
32 /* This is a gross hack for the wince gcc cross-compiler */
33 #define _off_t long
34 #endif
35
36 #include "wince.h"
37
38 #include <commctrl.h>
39 #include <commdlg.h>
40
41 /*****************************************************************************
42  * Local prototypes.
43  *****************************************************************************/
44 static int  Open   ( vlc_object_t * );
45 static void Close  ( vlc_object_t * );
46 static void Run    ( intf_thread_t * );
47
48 /*****************************************************************************
49  * Module descriptor
50  *****************************************************************************/
51 #define EMBED_TEXT N_("Embed video in interface")
52 #define EMBED_LONGTEXT N_("Embed the video inside the interface instead " \
53     "of having it in a separate window.")
54
55 vlc_module_begin();
56     set_description( (char *) _("WinCE interface module") );
57     set_capability( "interface", 100 );
58     set_callbacks( Open, Close );
59     add_shortcut( "wince" );
60     set_program( "wcevlc" );
61
62     add_bool( "wince-embed", 1, NULL,
63               EMBED_TEXT, EMBED_LONGTEXT, VLC_FALSE );
64 vlc_module_end();
65
66 HINSTANCE hInstance = 0;
67
68 #if !defined(__BUILTIN__)
69 extern "C" BOOL WINAPI
70 DllMain( HANDLE hModule, DWORD fdwReason, LPVOID lpReserved )
71 {
72     hInstance = (HINSTANCE)hModule;
73     return TRUE;
74 }
75 #endif
76
77 /* Global variables used by _TOMB() / _FROMB() */
78 wchar_t pwsz_mbtow_wince[2048];
79 char psz_wtomb_wince[2048];
80
81 /*****************************************************************************
82  * Open: initialize interface
83  *****************************************************************************/
84 static int Open( vlc_object_t *p_this )
85 {
86     intf_thread_t *p_intf = (intf_thread_t *)p_this;
87
88     // Check if the application is running.
89     // If it's running then focus its window and bail out.
90     HWND hwndMain = FindWindow( _T("VLC WinCE"), _T("VLC media player") );  
91     if( hwndMain )
92     {
93         SetForegroundWindow( hwndMain );
94         return VLC_EGENERIC;
95     }
96
97     // Allocate instance and initialize some members
98     p_intf->p_sys = (intf_sys_t *)malloc( sizeof( intf_sys_t ) );
99     if( p_intf->p_sys == NULL )
100     {
101         msg_Err( p_intf, "out of memory" );
102         return VLC_EGENERIC;
103     }
104
105     // Suscribe to messages bank
106     p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
107
108     // Misc init
109     p_intf->p_sys->p_audio_menu = NULL;
110     p_intf->p_sys->p_video_menu = NULL;
111     p_intf->p_sys->p_navig_menu = NULL;
112     p_intf->p_sys->p_settings_menu = NULL;
113
114     p_intf->pf_run = Run;
115
116     p_intf->p_sys->p_input = NULL;
117     p_intf->p_sys->b_playing = 0;
118     p_intf->p_sys->i_playing = -1;
119     p_intf->p_sys->b_slider_free = 1;
120     p_intf->p_sys->i_slider_pos = p_intf->p_sys->i_slider_oldpos = 0;
121
122     p_intf->p_sys->GetOpenFile = 0;
123     p_intf->p_sys->h_gsgetfile_dll = LoadLibrary( _T("gsgetfile") );
124     if( p_intf->p_sys->h_gsgetfile_dll )
125     {
126         p_intf->p_sys->GetOpenFile = (BOOL (WINAPI *)(void *))
127             GetProcAddress( p_intf->p_sys->h_gsgetfile_dll,
128                             _T("gsGetOpenFileName") );
129     }
130
131     if( !p_intf->p_sys->GetOpenFile )
132         p_intf->p_sys->GetOpenFile = (BOOL (WINAPI *)(void *))GetOpenFileName;
133
134     return VLC_SUCCESS;
135 }
136
137 /*****************************************************************************
138  * Close: destroy interface
139  *****************************************************************************/
140 static void Close( vlc_object_t *p_this )
141 {
142     intf_thread_t *p_intf = (intf_thread_t *)p_this;
143
144     if( p_intf->p_sys->p_input )
145     {
146         vlc_object_release( p_intf->p_sys->p_input );
147     }
148
149     // Unsuscribe to messages bank
150     msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
151
152     if( p_intf->p_sys->h_gsgetfile_dll )
153         FreeLibrary( p_intf->p_sys->h_gsgetfile_dll );
154
155     // Destroy structure
156     free( p_intf->p_sys );
157 }
158
159 /*****************************************************************************
160  * Run: main loop
161  *****************************************************************************/
162 static void Run( intf_thread_t *p_intf )
163 {
164     MSG msg;
165     Interface *pInterface = new Interface();
166     p_intf->p_sys->p_main_window = pInterface;
167
168     if( !hInstance ) hInstance = GetModuleHandle(NULL);
169
170     if( !pInterface->InitInstance( hInstance, p_intf ) ) return;
171
172     // Main message loop
173     while( GetMessage( &msg, NULL, 0, 0 ) > 0 )
174     {
175         TranslateMessage( &msg );
176         DispatchMessage( &msg );
177     }
178 }