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