]> git.sesse.net Git - vlc/blob - modules/gui/wince/iteminfo.cpp
Remove stdio while we're at it.
[vlc] / modules / gui / wince / iteminfo.cpp
1 /*****************************************************************************
2  * iteminfo.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  * Event Table.
41  *****************************************************************************/
42
43 /*****************************************************************************
44  * Constructor.
45  *****************************************************************************/
46 ItemInfoDialog::ItemInfoDialog( intf_thread_t *p_intf, CBaseWindow *p_parent,
47                                 HINSTANCE h_inst,
48                                 playlist_item_t *_p_item )
49   :  CBaseWindow( p_intf, p_parent, h_inst )
50 {
51     /* Initializations */
52     p_item = _p_item;
53 }
54
55 /***********************************************************************
56
57 FUNCTION: 
58   WndProc
59
60 PURPOSE: 
61   Processes messages sent to the main window.
62   
63 ***********************************************************************/
64 LRESULT ItemInfoDialog::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
65 {
66     SHINITDLGINFO shidi;
67     SHMENUBARINFO mbi;
68     INITCOMMONCONTROLSEX iccex;
69     RECT rcClient;
70
71     switch( msg )
72     {
73     case WM_INITDIALOG: 
74         shidi.dwMask = SHIDIM_FLAGS;
75         shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN |
76             SHIDIF_FULLSCREENNOMENUBAR;//SHIDIF_SIZEDLGFULLSCREEN;
77         shidi.hDlg = hwnd;
78         SHInitDialog( &shidi );
79
80         //Create the menubar.
81         memset( &mbi, 0, sizeof (SHMENUBARINFO) );
82         mbi.cbSize     = sizeof (SHMENUBARINFO);
83         mbi.hwndParent = hwnd;
84         mbi.dwFlags    = SHCMBF_EMPTYBAR;
85         mbi.hInstRes   = hInst;
86
87         if( !SHCreateMenuBar(&mbi) )
88         {
89             MessageBox( hwnd, _T("SHCreateMenuBar Failed"), _T("Error"), MB_OK );
90             //return -1;
91         }
92
93         hwndCB = mbi.hwndMB;
94
95         // Get the client area rect to put the panels in
96         GetClientRect( hwnd, &rcClient );
97
98         /* URI Textbox */
99         uri_label = CreateWindow( _T("STATIC"), _T("URI:"),
100                         WS_CHILD | WS_VISIBLE | SS_RIGHT,
101                         0, 10, 60, 15, hwnd, NULL, hInst, NULL);
102
103         uri_text = CreateWindow( _T("EDIT"), _FROMMB(p_item->input.psz_uri),
104             WS_CHILD | WS_VISIBLE | WS_BORDER | SS_LEFT | ES_AUTOHSCROLL,
105             70, 10 - 3, rcClient.right - 70 - 10, 15 + 6, hwnd, 0, hInst, 0 );
106
107         /* Name Textbox */
108         name_label = CreateWindow( _T("STATIC"), _T("Name:"),
109                                    WS_CHILD | WS_VISIBLE | SS_RIGHT ,
110                                    0, 10 + 15 + 10, 60, 15,
111                                    hwnd, NULL, hInst, NULL);
112
113         name_text = CreateWindow( _T("EDIT"),
114             _FROMMB(p_item->input.psz_name),
115             WS_CHILD | WS_VISIBLE | WS_BORDER | SS_LEFT | ES_AUTOHSCROLL,
116             70, 10 + 15 + 10 - 3, rcClient.right - 70 - 10, 15 + 6,
117             hwnd, NULL, hInst, NULL);
118
119         /* CheckBox */
120         checkbox_label = CreateWindow( _T("STATIC"), _T("Item Enabled:"),
121             WS_CHILD | WS_VISIBLE | SS_RIGHT ,
122             rcClient.right - 15 - 10 - 90 - 10, 10 + 4*( 15 + 10 ) + 5, 90, 15,
123             hwnd, NULL, hInst, NULL );
124
125         enabled_checkbox = CreateWindow( _T("BUTTON"), _T("Item Enabled"),
126             WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
127             rcClient.right - 15 - 10, 10 + 4*( 15 + 10 ) + 5, 15, 15,
128             hwnd, NULL, hInst, NULL );
129
130         SendMessage( enabled_checkbox, BM_SETCHECK, 
131                      p_item->b_enabled ? BST_CHECKED : BST_UNCHECKED, 0 );
132
133         /* Treeview */
134         iccex.dwSize = sizeof( INITCOMMONCONTROLSEX );
135         iccex.dwICC = ICC_TREEVIEW_CLASSES;
136         InitCommonControlsEx( &iccex );
137
138         // Create the tree-view control.
139         info_tree = CreateWindowEx( 0, WC_TREEVIEW, NULL,
140             WS_VISIBLE | WS_CHILD | WS_BORDER | TVS_HASLINES |
141             TVS_LINESATROOT | TVS_HASBUTTONS,
142             0, rcClient.bottom/2, rcClient.right,
143             rcClient.bottom - rcClient.bottom/2 - MENU_HEIGHT + 2, // +2 to fix
144             hwnd, NULL, hInst, NULL );
145
146         UpdateInfo();
147         break;
148
149     case WM_CLOSE:
150         EndDialog( hwnd, LOWORD( wp ) );
151         break;
152
153     case WM_SETFOCUS:
154         SHSipPreference( hwnd, SIP_DOWN ); 
155         SHFullScreen( hwnd, SHFS_HIDESIPBUTTON );
156         break;
157
158     case WM_COMMAND:
159         if( LOWORD(wp) == IDOK )
160         {
161             OnOk();
162             EndDialog( hwnd, LOWORD( wp ) );
163         }
164         break;
165
166     default:
167         break;
168     }
169
170     return FALSE;
171 }
172
173 /*****************************************************************************
174  * Private methods.
175  *****************************************************************************/
176  void ItemInfoDialog::UpdateInfo()
177 {
178     TVITEM tvi = {0}; 
179     TVINSERTSTRUCT tvins = {0}; 
180     HTREEITEM hPrev = (HTREEITEM)TVI_FIRST; 
181     HTREEITEM hPrevRootItem = NULL; 
182     HTREEITEM hPrevLev2Item = NULL; 
183
184     tvi.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM; 
185
186     // Set the text of the item. 
187     tvi.pszText = _FROMMB(p_item->input.psz_name);
188     tvi.cchTextMax = _tcslen(tvi.pszText);
189
190     // Save the heading level in the item's application-defined data area 
191     tvi.lParam = (LPARAM)1; // root level
192     tvins.item = tvi; 
193     tvins.hInsertAfter = hPrev; 
194     tvins.hParent = TVI_ROOT; 
195
196     // Add the item to the tree-view control. 
197     hPrev = (HTREEITEM)TreeView_InsertItem( info_tree, &tvins );
198     hPrevRootItem = hPrev; 
199
200     /* Rebuild the tree */
201     vlc_mutex_lock( &p_item->input.lock );
202     for( int i = 0; i < p_item->input.i_categories; i++ )
203     {
204         info_category_t *p_cat = p_item->input.pp_categories[i];
205
206         // Set the text of the item. 
207         tvi.pszText = _FROMMB( p_item->input.psz_name );
208         tvi.cchTextMax = _tcslen( tvi.pszText );
209         
210         // Save the heading level in the item's application-defined data area
211         tvi.lParam = (LPARAM)2; // level 2
212         tvins.item = tvi; 
213         tvins.hInsertAfter = hPrev; 
214         tvins.hParent = hPrevRootItem;
215
216         // Add the item to the tree-view control. 
217         hPrev = (HTREEITEM)TreeView_InsertItem( info_tree, &tvins );
218
219         hPrevLev2Item = hPrev;
220
221         for( int j = 0; j < p_cat->i_infos; j++ )
222         {
223             info_t *p_info = p_cat->pp_infos[j];
224
225             // Set the text of the item. 
226             string szAnsi = (string)p_info->psz_name;
227             szAnsi += ": ";
228             szAnsi += p_info->psz_value;
229             tvi.pszText = (TCHAR *)_FROMMB( szAnsi.c_str() );
230             tvi.cchTextMax = _tcslen( tvi.pszText );
231             tvi.lParam = (LPARAM)3; // level 3
232             tvins.item = tvi; 
233             tvins.hInsertAfter = hPrev; 
234             tvins.hParent = hPrevLev2Item;
235     
236             // Add the item to the tree-view control. 
237             hPrev = (HTREEITEM)TreeView_InsertItem( info_tree, &tvins );
238         }
239
240         TreeView_Expand( info_tree, hPrevLev2Item,
241                          TVE_EXPANDPARTIAL |TVE_EXPAND );
242     }
243     vlc_mutex_unlock( &p_item->input.lock );
244
245     TreeView_Expand( info_tree, hPrevRootItem, TVE_EXPANDPARTIAL |TVE_EXPAND );
246 }
247
248 /*****************************************************************************
249  * Events methods.
250  *****************************************************************************/
251 void ItemInfoDialog::OnOk()
252 {
253     int b_state = VLC_FALSE;
254
255     vlc_mutex_lock( &p_item->input.lock );
256
257     TCHAR psz_name[MAX_PATH];
258     Edit_GetText( name_text, psz_name, MAX_PATH );
259     if( p_item->input.psz_name ) free( p_item->input.psz_name );
260     p_item->input.psz_name = strdup( _TOMB(psz_name) );
261
262     TCHAR psz_uri[MAX_PATH];
263     Edit_GetText( uri_text, psz_uri, MAX_PATH );
264     if( p_item->input.psz_uri ) free( p_item->input.psz_uri );
265     p_item->input.psz_uri = strdup( _TOMB(psz_uri) );
266
267     vlc_bool_t b_old_enabled = p_item->b_enabled;
268
269     playlist_t * p_playlist = (playlist_t *)
270         vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
271     if( p_playlist != NULL )
272     {
273         b_state = SendMessage( enabled_checkbox, BM_GETCHECK, 0, 0 );
274         if( b_old_enabled == VLC_FALSE && (b_state & BST_CHECKED) )
275             p_playlist->i_enabled ++;
276         else if( b_old_enabled == VLC_TRUE && (b_state & BST_UNCHECKED) )
277             p_playlist->i_enabled --;
278
279         vlc_object_release( p_playlist );
280     }
281
282     p_item->b_enabled = (b_state & BST_CHECKED) ? VLC_TRUE : VLC_FALSE ;
283
284     vlc_mutex_unlock( &p_item->input.lock );
285 }