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