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