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