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