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