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