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