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