1 /*****************************************************************************
2 * messages.cpp : WinCE gui plugin for VLC
3 *****************************************************************************
4 * Copyright (C) 2000-2004 the VideoLAN team
7 * Authors: Marodon Cedric <cedric_marodon@yahoo.fr>
8 * Gildas Bazin <gbazin@videolan.org>
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.
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.
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 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
32 #include <vlc_common.h>
33 #include <vlc_interface.h>
44 #define NMAXFILE 512 // at least 256
48 #define TEXTMAXBUF 512 // at least 500
51 /*****************************************************************************
53 *****************************************************************************/
55 Messages::Messages( intf_thread_t *p_intf, CBaseWindow *p_parent,
57 : CBaseWindow( p_intf, p_parent, h_inst )
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 // Suscribe to messages bank
67 cb_data = new msg_cb_data_t;
69 sub = msg_Subscribe( p_intf->p_libvlc, sinkMessage, cb_data );
78 /***********************************************************************
83 Processes messages sent to the main window.
84 ***********************************************************************/
85 LRESULT Messages::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
89 TCHAR psz_text[TEXTMAXBUF];
97 shidi.dwMask = SHIDIM_FLAGS;
98 shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN |
99 SHIDIF_FULLSCREENNOMENUBAR;//SHIDIF_SIZEDLGFULLSCREEN;
101 SHInitDialog( &shidi );
103 hListView = CreateWindow( WC_LISTVIEW, NULL,
104 WS_VISIBLE | WS_CHILD | LVS_REPORT |
105 LVS_SHOWSELALWAYS | WS_VSCROLL | WS_HSCROLL |
106 WS_BORDER | LVS_NOCOLUMNHEADER, 0, 0, 0, 0,
107 hwnd, NULL, hInst, NULL );
108 ListView_SetExtendedListViewStyle( hListView, LVS_EX_FULLROWSELECT );
112 lv.fmt = LVCFMT_LEFT ;
113 ListView_InsertColumn( hListView, 0, &lv );
115 SetTimer( hwnd, 1, 500 /*milliseconds*/, NULL );
118 case WM_WINDOWPOSCHANGED:
121 if( !GetClientRect( hwnd, &rect ) ) break;
122 SetWindowPos( hListView, 0, 0, 0,
123 rect.right - rect.left, rect.bottom - rect.top, 0 );
126 lv.cx = rect.right - rect.left;
127 lv.mask = LVCF_WIDTH;
128 ListView_SetColumn( hListView, 0, &lv );
133 SHSipPreference( hwnd, SIP_DOWN );
134 SHFullScreen( hwnd, SHFS_HIDESIPBUTTON );
149 ListView_DeleteAllItems( hListView );
153 memset( &(ofn), 0, sizeof(ofn) );
154 ofn.lStructSize = sizeof(ofn);
155 ofn.hwndOwner = hwnd;
156 ofn.lpstrFile = _T("");
157 ofn.nMaxFile = NMAXFILE;
158 ofn.lpstrFilter = _T("Text (*.txt)\0*.txt\0");
159 ofn.lpstrTitle = _T("Save File As");
160 ofn.Flags = OFN_HIDEREADONLY;
161 ofn.lpstrDefExt = _T("txt");
163 if( GetSaveFileName( (LPOPENFILENAME)&ofn ) )
165 fichier = CreateFile( ofn.lpstrFile, GENERIC_WRITE,
166 FILE_SHARE_READ|FILE_SHARE_WRITE,
168 FILE_ATTRIBUTE_NORMAL, NULL );
170 if( fichier != INVALID_HANDLE_VALUE )
174 //SetFilePointer( fichier, 0, NULL, FILE_END );
175 for( n = 0; n < ListView_GetItemCount( hListView ); n++ )
177 ListView_GetItemText( hListView, n, 0, psz_text,
179 string text_out = (string)_TOMB(psz_text) + "\n";
180 WriteFile( fichier, text_out.c_str(), text_out.size(),
181 (LPDWORD)&i_dummy, NULL );
183 FlushFileBuffers( fichier );
184 CloseHandle(fichier);
197 return DefWindowProc( hwnd, msg, wp, lp );
200 void Messages::sinkMessage (msg_cb_data_t *data, msg_item_t *item,
203 Messages *self = data->self;
205 self->sinkMessage (item, overruns);
208 void Messages::sinkMessage (msg_item_t *item, unsigned overruns)
211 var_Get( p_intf->p_libvlc, "verbose", &val );
214 /* Append all messages to log window */
215 string debug = item->psz_module;
217 switch( item->i_type )
219 case VLC_MSG_INFO: debug += ": "; break;
220 case VLC_MSG_ERR: debug += " error: "; break;
221 case VLC_MSG_WARN: debug += " warning: "; break;
222 default: debug += " debug: "; break;
226 debug += item->psz_msg;
230 lv.pszText = TEXT("");
233 lv.iItem = ListView_GetItemCount( hListView );
234 ListView_InsertItem( hListView, &lv );
235 ListView_SetItemText( hListView, lv.iItem, 0,
236 (TCHAR *)_FROMMB(debug.c_str()) );