Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

messages.cpp

00001 /*****************************************************************************
00002  * messages.cpp : WinCE gui plugin for VLC
00003  *****************************************************************************
00004  * Copyright (C) 2000-2004 the VideoLAN team
00005  * $Id: messages.cpp 11664 2005-07-09 06:17:09Z courmisch $
00006  *
00007  * Authors: Marodon Cedric <[email protected]>
00008  *          Gildas Bazin <[email protected]>
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00023  *****************************************************************************/
00024 
00025 /*****************************************************************************
00026  * Preamble
00027  *****************************************************************************/
00028 #include <stdlib.h>                                      /* malloc(), free() */
00029 #include <string.h>                                            /* strerror() */
00030 #include <stdio.h>
00031 #include <vlc/vlc.h>
00032 #include <vlc/intf.h>
00033 
00034 #include "wince.h"
00035 
00036 #include <winuser.h>
00037 #include <windows.h>
00038 #include <windowsx.h>
00039 #include <commctrl.h>
00040 #include <commdlg.h>
00041 
00042 #ifndef NMAXFILE
00043 #define NMAXFILE 512 // at least 256
00044 #endif
00045 
00046 #ifndef TEXTMAXBUF
00047 #define TEXTMAXBUF 512 // at least 500
00048 #endif
00049 
00050 /*****************************************************************************
00051  * Constructor.
00052  *****************************************************************************/
00053 
00054 Messages::Messages( intf_thread_t *p_intf, CBaseWindow *p_parent,
00055                     HINSTANCE h_inst )
00056   :  CBaseWindow( p_intf, p_parent, h_inst )
00057 {
00058     /* Initializations */
00059     hListView = NULL;
00060 
00061     hWnd = CreateWindow( _T("VLC WinCE"), _T("Messages"),
00062                          WS_POPUP|WS_CAPTION|WS_SYSMENU|WS_SIZEBOX,
00063                          0, 0, /*CW_USEDEFAULT*/300, /*CW_USEDEFAULT*/300,
00064                          p_parent->GetHandle(), NULL, h_inst, (void *)this );
00065 }
00066 
00067 /***********************************************************************
00068 FUNCTION: 
00069   WndProc
00070 
00071 PURPOSE: 
00072   Processes messages sent to the main window.
00073 ***********************************************************************/
00074 LRESULT Messages::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
00075 {
00076     SHINITDLGINFO shidi;
00077 
00078     TCHAR psz_text[TEXTMAXBUF];
00079     OPENFILENAME ofn;
00080     int i_dummy;
00081     HANDLE fichier;
00082 
00083     switch( msg )
00084     {
00085     case WM_CREATE:
00086         shidi.dwMask = SHIDIM_FLAGS;
00087         shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN |
00088             SHIDIF_FULLSCREENNOMENUBAR;//SHIDIF_SIZEDLGFULLSCREEN;
00089         shidi.hDlg = hwnd;
00090         SHInitDialog( &shidi );
00091 
00092         hListView = CreateWindow( WC_LISTVIEW, NULL,
00093                                   WS_VISIBLE | WS_CHILD | LVS_REPORT |
00094                                   LVS_SHOWSELALWAYS | WS_VSCROLL | WS_HSCROLL |
00095                                   WS_BORDER | LVS_NOCOLUMNHEADER, 0, 0, 0, 0,
00096                                   hwnd, NULL, hInst, NULL );            
00097         ListView_SetExtendedListViewStyle( hListView, LVS_EX_FULLROWSELECT );
00098 
00099         LVCOLUMN lv;
00100         lv.mask = LVCF_FMT;
00101         lv.fmt = LVCFMT_LEFT ;
00102         ListView_InsertColumn( hListView, 0, &lv );
00103 
00104         SetTimer( hwnd, 1, 500 /*milliseconds*/, NULL );
00105         break;
00106 
00107     case WM_WINDOWPOSCHANGED:
00108         {
00109             RECT rect;
00110             if( !GetClientRect( hwnd, &rect ) ) break;
00111             SetWindowPos( hListView, 0, 0, 0,
00112                           rect.right - rect.left, rect.bottom - rect.top, 0 );
00113 
00114             LVCOLUMN lv;
00115             lv.cx = rect.right - rect.left;
00116             lv.mask = LVCF_WIDTH;
00117             ListView_SetColumn( hListView, 0, &lv );
00118         }
00119         break;
00120 
00121     case WM_SETFOCUS:
00122         SHSipPreference( hwnd, SIP_DOWN ); 
00123         SHFullScreen( hwnd, SHFS_HIDESIPBUTTON );
00124         break;
00125 
00126     case WM_TIMER:
00127         UpdateLog();
00128         break;
00129 
00130     case WM_CLOSE:
00131         Show( FALSE );
00132         return TRUE;
00133 
00134     case WM_COMMAND:
00135         switch( LOWORD(wp) )
00136         {
00137         case IDOK:
00138             Show( FALSE );
00139             break;
00140 
00141         case IDCLEAR:
00142             ListView_DeleteAllItems( hListView );
00143             break;
00144 
00145         case IDSAVEAS:  
00146             memset( &(ofn), 0, sizeof(ofn) );
00147             ofn.lStructSize = sizeof(ofn);
00148             ofn.hwndOwner = hwnd;
00149             ofn.lpstrFile = _T("");
00150             ofn.nMaxFile = NMAXFILE;    
00151             ofn.lpstrFilter = _T("Text (*.txt)\0*.txt\0");
00152             ofn.lpstrTitle = _T("Save File As");
00153             ofn.Flags = OFN_HIDEREADONLY; 
00154             ofn.lpstrDefExt = _T("txt");
00155 
00156             if( GetSaveFileName( (LPOPENFILENAME)&ofn ) )
00157             {
00158                 fichier = CreateFile( ofn.lpstrFile, GENERIC_WRITE,
00159                                       FILE_SHARE_READ|FILE_SHARE_WRITE,
00160                                       NULL, CREATE_ALWAYS,
00161                                       FILE_ATTRIBUTE_NORMAL, NULL );
00162 
00163                 if( fichier != INVALID_HANDLE_VALUE )
00164                 {
00165                     int n;
00166 
00167                     //SetFilePointer( fichier, 0, NULL, FILE_END );
00168                     for( n = 0; n < ListView_GetItemCount( hListView ); n++ )
00169                     {
00170                         ListView_GetItemText( hListView, n, 0, psz_text,
00171                                               TEXTMAXBUF );
00172                         string text_out = (string)_TOMB(psz_text) + "\n";
00173                         WriteFile( fichier, text_out.c_str(), text_out.size(),
00174                                    (LPDWORD)&i_dummy, NULL );
00175                     }
00176                     FlushFileBuffers( fichier );
00177                     CloseHandle(fichier);
00178                 }
00179             }
00180             break;
00181 
00182         default:
00183             break;
00184         }
00185 
00186     default:
00187         break;
00188     }
00189 
00190     return DefWindowProc( hwnd, msg, wp, lp );
00191 }
00192 
00193 void Messages::UpdateLog()
00194 {
00195     msg_subscription_t *p_sub = p_intf->p_sys->p_sub;
00196     string debug;
00197     int i_start, i_stop;
00198 
00199     vlc_mutex_lock( p_sub->p_lock );
00200     i_stop = *p_sub->pi_stop;
00201     vlc_mutex_unlock( p_sub->p_lock );
00202 
00203     if( p_sub->i_start != i_stop )
00204     {
00205         for( i_start = p_sub->i_start; i_start != i_stop;
00206              i_start = (i_start+1) % VLC_MSG_QSIZE )
00207         {
00208             switch( p_sub->p_msg[i_start].i_type )
00209             {
00210             case VLC_MSG_ERR:
00211             case VLC_MSG_INFO:
00212                 if( p_intf->p_libvlc->i_verbose < 0 ) continue;
00213                 break;
00214             case VLC_MSG_WARN:
00215                 if( p_intf->p_libvlc->i_verbose < 1 ) continue;
00216                 break;
00217             case VLC_MSG_DBG:
00218                 if( p_intf->p_libvlc->i_verbose < 2 ) continue;
00219                 break;
00220             }
00221 
00222             /* Append all messages to log window */
00223             debug = p_sub->p_msg[i_start].psz_module;
00224         
00225             switch( p_sub->p_msg[i_start].i_type )
00226             {
00227             case VLC_MSG_INFO: debug += ": "; break;
00228             case VLC_MSG_ERR: debug += " error: "; break;
00229             case VLC_MSG_WARN: debug += " warning: "; break;
00230             default: debug += " debug: "; break;
00231             }
00232 
00233             /* Add message */
00234             debug += p_sub->p_msg[i_start].psz_msg;
00235 
00236             LVITEM lv;
00237             lv.mask = LVIF_TEXT;
00238             lv.pszText = TEXT("");
00239             lv.cchTextMax = 1;
00240             lv.iSubItem = 0;
00241             lv.iItem = ListView_GetItemCount( hListView );
00242             ListView_InsertItem( hListView, &lv );
00243             ListView_SetItemText( hListView, lv.iItem, 0,
00244                                   (TCHAR *)_FROMMB(debug.c_str()) );
00245         }
00246 
00247         vlc_mutex_lock( p_sub->p_lock );
00248         p_sub->i_start = i_start;
00249         vlc_mutex_unlock( p_sub->p_lock );
00250     }
00251 }

Generated on Tue Dec 20 10:14:45 2005 for vlc-0.8.4a by  doxygen 1.4.2