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