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