]> git.sesse.net Git - vlc/blob - modules/gui/wince/messages.cpp
For consistency, remove references to vlc from libvlc
[vlc] / modules / gui / wince / messages.cpp
1 /*****************************************************************************
2  * messages.cpp : WinCE gui plugin for VLC
3  *****************************************************************************
4  * Copyright (C) 2000-2004 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Marodon Cedric <cedric_marodon@yahoo.fr>
8  *          Gildas Bazin <gbazin@videolan.org>
9  *
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.
14  *
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.
19  *
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #include <stdlib.h>                                      /* malloc(), free() */
29 #include <string.h>                                            /* strerror() */
30 #include <stdio.h>
31 #include <vlc/vlc.h>
32 #include <vlc/intf.h>
33
34 #include "wince.h"
35
36 #include <winuser.h>
37 #include <windows.h>
38 #include <windowsx.h>
39 #include <commctrl.h>
40 #include <commdlg.h>
41
42 #ifndef NMAXFILE
43 #define NMAXFILE 512 // at least 256
44 #endif
45
46 #ifndef TEXTMAXBUF
47 #define TEXTMAXBUF 512 // at least 500
48 #endif
49
50 /*****************************************************************************
51  * Constructor.
52  *****************************************************************************/
53
54 Messages::Messages( intf_thread_t *p_intf, CBaseWindow *p_parent,
55                     HINSTANCE h_inst )
56   :  CBaseWindow( p_intf, p_parent, h_inst )
57 {
58     /* Initializations */
59     hListView = NULL;
60
61     hWnd = CreateWindow( _T("VLC WinCE"), _T("Messages"),
62                          WS_POPUP|WS_CAPTION|WS_SYSMENU|WS_SIZEBOX,
63                          0, 0, /*CW_USEDEFAULT*/300, /*CW_USEDEFAULT*/300,
64                          p_parent->GetHandle(), NULL, h_inst, (void *)this );
65 }
66
67 /***********************************************************************
68 FUNCTION: 
69   WndProc
70
71 PURPOSE: 
72   Processes messages sent to the main window.
73 ***********************************************************************/
74 LRESULT Messages::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
75 {
76     SHINITDLGINFO shidi;
77
78     TCHAR psz_text[TEXTMAXBUF];
79     OPENFILENAME ofn;
80     int i_dummy;
81     HANDLE fichier;
82
83     switch( msg )
84     {
85     case WM_CREATE:
86         shidi.dwMask = SHIDIM_FLAGS;
87         shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN |
88             SHIDIF_FULLSCREENNOMENUBAR;//SHIDIF_SIZEDLGFULLSCREEN;
89         shidi.hDlg = hwnd;
90         SHInitDialog( &shidi );
91
92         hListView = CreateWindow( WC_LISTVIEW, NULL,
93                                   WS_VISIBLE | WS_CHILD | LVS_REPORT |
94                                   LVS_SHOWSELALWAYS | WS_VSCROLL | WS_HSCROLL |
95                                   WS_BORDER | LVS_NOCOLUMNHEADER, 0, 0, 0, 0,
96                                   hwnd, NULL, hInst, NULL );            
97         ListView_SetExtendedListViewStyle( hListView, LVS_EX_FULLROWSELECT );
98
99         LVCOLUMN lv;
100         lv.mask = LVCF_FMT;
101         lv.fmt = LVCFMT_LEFT ;
102         ListView_InsertColumn( hListView, 0, &lv );
103
104         SetTimer( hwnd, 1, 500 /*milliseconds*/, NULL );
105         break;
106
107     case WM_WINDOWPOSCHANGED:
108         {
109             RECT rect;
110             if( !GetClientRect( hwnd, &rect ) ) break;
111             SetWindowPos( hListView, 0, 0, 0,
112                           rect.right - rect.left, rect.bottom - rect.top, 0 );
113
114             LVCOLUMN lv;
115             lv.cx = rect.right - rect.left;
116             lv.mask = LVCF_WIDTH;
117             ListView_SetColumn( hListView, 0, &lv );
118         }
119         break;
120
121     case WM_SETFOCUS:
122         SHSipPreference( hwnd, SIP_DOWN ); 
123         SHFullScreen( hwnd, SHFS_HIDESIPBUTTON );
124         break;
125
126     case WM_TIMER:
127         UpdateLog();
128         break;
129
130     case WM_CLOSE:
131         Show( FALSE );
132         return TRUE;
133
134     case WM_COMMAND:
135         switch( LOWORD(wp) )
136         {
137         case IDOK:
138             Show( FALSE );
139             break;
140
141         case IDCLEAR:
142             ListView_DeleteAllItems( hListView );
143             break;
144
145         case IDSAVEAS:  
146             memset( &(ofn), 0, sizeof(ofn) );
147             ofn.lStructSize = sizeof(ofn);
148             ofn.hwndOwner = hwnd;
149             ofn.lpstrFile = _T("");
150             ofn.nMaxFile = NMAXFILE;    
151             ofn.lpstrFilter = _T("Text (*.txt)\0*.txt\0");
152             ofn.lpstrTitle = _T("Save File As");
153             ofn.Flags = OFN_HIDEREADONLY; 
154             ofn.lpstrDefExt = _T("txt");
155
156             if( GetSaveFileName( (LPOPENFILENAME)&ofn ) )
157             {
158                 fichier = CreateFile( ofn.lpstrFile, GENERIC_WRITE,
159                                       FILE_SHARE_READ|FILE_SHARE_WRITE,
160                                       NULL, CREATE_ALWAYS,
161                                       FILE_ATTRIBUTE_NORMAL, NULL );
162
163                 if( fichier != INVALID_HANDLE_VALUE )
164                 {
165                     int n;
166
167                     //SetFilePointer( fichier, 0, NULL, FILE_END );
168                     for( n = 0; n < ListView_GetItemCount( hListView ); n++ )
169                     {
170                         ListView_GetItemText( hListView, n, 0, psz_text,
171                                               TEXTMAXBUF );
172                         string text_out = (string)_TOMB(psz_text) + "\n";
173                         WriteFile( fichier, text_out.c_str(), text_out.size(),
174                                    (LPDWORD)&i_dummy, NULL );
175                     }
176                     FlushFileBuffers( fichier );
177                     CloseHandle(fichier);
178                 }
179             }
180             break;
181
182         default:
183             break;
184         }
185
186     default:
187         break;
188     }
189
190     return DefWindowProc( hwnd, msg, wp, lp );
191 }
192
193 void Messages::UpdateLog()
194 {
195     msg_subscription_t *p_sub = p_intf->p_sys->p_sub;
196     string debug;
197     int i_start, i_stop;
198
199     vlc_mutex_lock( p_sub->p_lock );
200     i_stop = *p_sub->pi_stop;
201     vlc_mutex_unlock( p_sub->p_lock );
202
203     if( p_sub->i_start != i_stop )
204     {
205         for( i_start = p_sub->i_start; i_start != i_stop;
206              i_start = (i_start+1) % VLC_MSG_QSIZE )
207         {
208             switch( p_sub->p_msg[i_start].i_type )
209             {
210             case VLC_MSG_ERR:
211             case VLC_MSG_INFO:
212                 if( p_intf->p_libvlc_global->i_verbose < 0 ) continue;
213                 break;
214             case VLC_MSG_WARN:
215                 if( p_intf->p_libvlc_global->i_verbose < 1 ) continue;
216                 break;
217             case VLC_MSG_DBG:
218                 if( p_intf->p_libvlc_global->i_verbose < 2 ) continue;
219                 break;
220             }
221
222             /* Append all messages to log window */
223             debug = p_sub->p_msg[i_start].psz_module;
224         
225             switch( p_sub->p_msg[i_start].i_type )
226             {
227             case VLC_MSG_INFO: debug += ": "; break;
228             case VLC_MSG_ERR: debug += " error: "; break;
229             case VLC_MSG_WARN: debug += " warning: "; break;
230             default: debug += " debug: "; break;
231             }
232
233             /* Add message */
234             debug += p_sub->p_msg[i_start].psz_msg;
235
236             LVITEM lv;
237             lv.mask = LVIF_TEXT;
238             lv.pszText = TEXT("");
239             lv.cchTextMax = 1;
240             lv.iSubItem = 0;
241             lv.iItem = ListView_GetItemCount( hListView );
242             ListView_InsertItem( hListView, &lv );
243             ListView_SetItemText( hListView, lv.iItem, 0,
244                                   (TCHAR *)_FROMMB(debug.c_str()) );
245         }
246
247         vlc_mutex_lock( p_sub->p_lock );
248         p_sub->i_start = i_start;
249         vlc_mutex_unlock( p_sub->p_lock );
250     }
251 }