]> git.sesse.net Git - vlc/blob - modules/gui/wince/fileinfo.cpp
* modules/gui/wince/*: New Windows CE interface by Cedric Marodon <cedric_marodon...
[vlc] / modules / gui / wince / fileinfo.cpp
1 /*****************************************************************************
2  * fileinfo.cpp : WinCE gui plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2000-2004 VideoLAN
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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
23  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #include <vlc/vlc.h>
29 #include <vlc/intf.h>
30 #include <string.h>
31
32 #include <string>
33 #include <stdio.h>
34 using namespace std; 
35
36 #include <winuser.h>
37 #include <windows.h>
38 #include <windowsx.h>
39 #include <commctrl.h>
40 #include <aygshell.h>
41
42 #include <commdlg.h>
43
44 #include "wince.h"
45
46 /*****************************************************************************
47  * Constructor.
48  *****************************************************************************/
49 FileInfo::FileInfo( intf_thread_t *_p_intf, HINSTANCE _hInst )
50 {
51     /* Initializations */
52     p_intf = _p_intf;
53     hInst = _hInst;
54     hwnd_fileinfo = hwndTV = NULL;
55 }
56
57 /***********************************************************************
58
59 FUNCTION: 
60   CreateTreeView
61
62 PURPOSE: 
63   Registers the TreeView control class and creates a TreeView.
64
65 ***********************************************************************/
66 BOOL FileInfo::CreateTreeView(HWND hwnd)
67 {
68     DWORD dwStyle;
69     RECT rect;
70
71     INITCOMMONCONTROLSEX iccex;
72     iccex.dwSize = sizeof( INITCOMMONCONTROLSEX );
73     iccex.dwICC = ICC_TREEVIEW_CLASSES;
74
75     // Registers Statusbar control classes from the common control dll
76     InitCommonControlsEx( &iccex );
77
78     // Get the coordinates of the parent window's client area
79     GetClientRect( hwnd, &rect );
80
81     // Assign the window styles for the tree view.
82     dwStyle = WS_VISIBLE | WS_CHILD | TVS_HASLINES | TVS_LINESATROOT | 
83                           TVS_HASBUTTONS;
84
85     // Create the tree-view control.
86     hwndTV = CreateWindowEx( 0, WC_TREEVIEW, NULL, dwStyle, 0, MENU_HEIGHT,
87                              rect.right-rect.left,
88                              rect.bottom-rect.top-MENU_HEIGHT,
89                              hwnd, NULL, hInst, NULL );
90
91     // Be sure that the tree view actually was created.
92     if( !hwndTV ) return FALSE;
93
94     UpdateFileInfo( hwndTV );
95
96     return TRUE;
97 }
98
99 /***********************************************************************
100
101 FUNCTION: 
102   UpdateFileInfo
103
104 PURPOSE: 
105   Update the TreeView with file information.
106
107 ***********************************************************************/
108 void FileInfo::UpdateFileInfo(HWND hwnd)
109 {
110     TVITEM tvi = {0}; 
111     TVINSERTSTRUCT tvins = {0}; 
112     HTREEITEM hPrev = (HTREEITEM)TVI_FIRST; 
113     HTREEITEM hPrevRootItem = NULL; 
114     HTREEITEM hPrevLev2Item = NULL; 
115
116     p_intf->p_sys->p_input = (input_thread_t *)
117         vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );
118
119     input_thread_t *p_input = p_intf->p_sys->p_input;
120
121     if( !p_input ) return;
122
123     tvi.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM; 
124
125     // Set the text of the item.
126     tvi.pszText = _FROMMB( p_input->input.p_item->psz_name );
127     tvi.cchTextMax = _tcslen( tvi.pszText );
128
129     // Save the heading level in the item's application-defined data area
130     tvi.lParam = (LPARAM)1;
131     tvins.item = tvi; 
132     //tvins.hInsertAfter = TVI_LAST;
133     tvins.hInsertAfter = hPrev; 
134     tvins.hParent = TVI_ROOT; 
135
136     // Add the item to the tree-view control. 
137     hPrev = (HTREEITEM)TreeView_InsertItem( hwnd, &tvins );
138
139     hPrevRootItem = hPrev; 
140
141     vlc_mutex_lock( &p_input->input.p_item->lock );
142     for( int i = 0; i < p_input->input.p_item->i_categories; i++ )
143     {
144         info_category_t *p_cat = p_input->input.p_item->pp_categories[i];
145
146         // Set the text of the item. 
147         tvi.pszText = _FROMMB( p_input->input.p_item->psz_name );
148         tvi.cchTextMax = _tcslen( tvi.pszText );
149         
150         // Save the heading level in the item's application-defined data area
151         tvi.lParam = (LPARAM)2; // level 2
152         tvins.item = tvi; 
153         tvins.hInsertAfter = hPrev; 
154         tvins.hParent = hPrevRootItem;
155
156         // Add the item to the tree-view control. 
157         hPrev = (HTREEITEM)TreeView_InsertItem( hwnd, &tvins );
158
159         hPrevLev2Item = hPrev;
160
161         for( int j = 0; j < p_cat->i_infos; j++ )
162         {
163             info_t *p_info = p_cat->pp_infos[j];
164
165             // Set the text of the item. 
166             string szAnsi = (string)p_info->psz_name;
167             szAnsi += ": ";
168             szAnsi += p_info->psz_value;
169             tvi.pszText = _FROMMB( szAnsi.c_str() );
170             tvi.cchTextMax = _tcslen( tvi.pszText );
171             tvi.lParam = (LPARAM)3; // level 3
172             tvins.item = tvi; 
173             tvins.hInsertAfter = hPrev; 
174             tvins.hParent = hPrevLev2Item;
175     
176             // Add the item to the tree-view control. 
177             hPrev = (HTREEITEM)TreeView_InsertItem( hwnd, &tvins );
178         }
179
180         TreeView_Expand( hwnd, hPrevLev2Item, TVE_EXPANDPARTIAL |TVE_EXPAND );
181     }
182     vlc_mutex_unlock( &p_input->input.p_item->lock );
183
184     TreeView_Expand( hwnd, hPrevRootItem, TVE_EXPANDPARTIAL |TVE_EXPAND );
185
186     return;
187 }
188
189 /***********************************************************************
190
191 FUNCTION: 
192   WndProc
193
194 PURPOSE: 
195   Processes messages sent to the main window.
196   
197 ***********************************************************************/
198 LRESULT FileInfo::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
199                            PBOOL pbProcessed  )
200 {
201     SHINITDLGINFO shidi;
202
203     LRESULT lResult = CBaseWindow::WndProc( hwnd, msg, wp, lp, pbProcessed );
204     BOOL bWasProcessed = *pbProcessed;
205     *pbProcessed = TRUE;
206
207     switch( msg )
208     {
209     case WM_INITDIALOG: 
210         shidi.dwMask = SHIDIM_FLAGS;
211         shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN |
212             SHIDIF_FULLSCREENNOMENUBAR;//SHIDIF_SIZEDLGFULLSCREEN;
213         shidi.hDlg = hwnd;
214         SHInitDialog( &shidi );
215         CreateTreeView( hwnd );
216         UpdateWindow( hwnd );
217         SHFullScreen( GetForegroundWindow(), SHFS_HIDESIPBUTTON );
218         return lResult;
219
220     case WM_COMMAND:
221         if ( LOWORD(wp) == IDOK )
222         {
223             EndDialog( hwnd, LOWORD( wp ) );
224             return TRUE;
225          }
226          *pbProcessed = bWasProcessed;
227          lResult = FALSE;
228          return lResult;
229
230     default:
231          // the message was not processed
232          // indicate if the base class handled it
233          *pbProcessed = bWasProcessed;
234          lResult = FALSE;
235          return lResult;
236     }
237
238     return lResult;
239 }