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