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