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