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