Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

preferences.cpp

00001 /*****************************************************************************
00002  * preferences.cpp : WinCE gui plugin for VLC
00003  *****************************************************************************
00004  * Copyright (C) 2000-2004 the VideoLAN team
00005  * $Id: preferences.cpp 11664 2005-07-09 06:17:09Z courmisch $
00006  *
00007  * Authors: Marodon Cedric <[email protected]>
00008  *          Gildas Bazin <[email protected]>
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00023  *****************************************************************************/
00024 
00025 /*****************************************************************************
00026  * Preamble
00027  *****************************************************************************/
00028 #include <stdlib.h>                                      /* malloc(), free() */
00029 #include <string.h>                                            /* strerror() */
00030 #include <stdio.h>
00031 #include <vlc/vlc.h>
00032 #include <vlc/intf.h>
00033 
00034 #include "wince.h"
00035 
00036 #include <winuser.h>
00037 #include <windows.h>
00038 #include <windowsx.h>
00039 #include <commctrl.h>
00040 #include <commdlg.h>
00041 
00042 #include <vlc_config_cat.h>
00043 
00044 #include "preferences_widgets.h"
00045 
00046 #define GENERAL_ID 1242
00047 #define PLUGIN_ID 1243
00048 #define CAPABILITY_ID 1244
00049 
00050 /*****************************************************************************
00051  * Event Table.
00052  *****************************************************************************/
00053 
00054 /* IDs for the controls and the menu commands */
00055 enum
00056 {
00057     Notebook_Event,
00058     MRL_Event,
00059     ResetAll_Event,
00060     Advanced_Event
00061 };
00062 
00063 /*****************************************************************************
00064  * Classes declarations.
00065  *****************************************************************************/
00066 class ConfigTreeData;
00067 class PrefsTreeCtrl
00068 {
00069 public:
00070 
00071     PrefsTreeCtrl() { }
00072     PrefsTreeCtrl( intf_thread_t *_p_intf, PrefsDialog *p_prefs_dialog,
00073                    HWND hwnd, HINSTANCE _hInst );
00074     virtual ~PrefsTreeCtrl();
00075 
00076     void ApplyChanges();
00077     /*void CleanChanges();*/
00078 
00079     void OnSelectTreeItem( LPNM_TREEVIEW pnmtv, HWND parent, HINSTANCE hInst );
00080         
00081     ConfigTreeData *FindModuleConfig( ConfigTreeData *config_data );
00082 
00083     HWND hwndTV;
00084 
00085 private:
00086     intf_thread_t *p_intf;
00087     PrefsDialog *p_prefs_dialog;
00088     vlc_bool_t b_advanced;
00089 
00090     HTREEITEM general_item;
00091     HTREEITEM plugins_item;
00092 };
00093 
00094 class PrefsPanel
00095 {
00096 public:
00097 
00098     PrefsPanel() { }
00099     PrefsPanel( HWND parent, HINSTANCE hInst, intf_thread_t *_p_intf,
00100                 PrefsDialog *, int i_object_id, char *, char * );
00101     virtual ~PrefsPanel() {}
00102 
00103     void Hide();
00104     void Show();
00105 
00106     HWND config_window;
00107 
00108     int oldvalue;
00109     int maxvalue;
00110 
00111     void ApplyChanges();
00112 
00113 private:
00114     intf_thread_t *p_intf;
00115     PrefsDialog *p_prefs_dialog;
00116 
00117     vlc_bool_t b_advanced;
00118 
00119     HWND label;
00120 
00121     vector<ConfigControl *> config_array;
00122 };
00123 
00124 class ConfigTreeData
00125 {
00126 public:
00127 
00128     ConfigTreeData() { b_submodule = 0; panel = NULL; psz_section = NULL;
00129                        psz_help = NULL; }
00130     virtual ~ConfigTreeData() { if( panel ) delete panel;
00131                                 if( psz_section) free(psz_section);
00132                                 if( psz_help) free(psz_help); }
00133 
00134     vlc_bool_t b_submodule;
00135 
00136     PrefsPanel *panel;
00137     int i_object_id;
00138     char *psz_section;
00139     char *psz_help;
00140 };
00141 
00142 /*****************************************************************************
00143  * Constructor.
00144  *****************************************************************************/
00145 PrefsDialog::PrefsDialog( intf_thread_t *p_intf, CBaseWindow *p_parent,
00146                           HINSTANCE h_inst )
00147   :  CBaseWindow( p_intf, p_parent, h_inst )
00148 {
00149     /* Initializations */
00150     prefs_tree = NULL;
00151 }
00152 
00153 /***********************************************************************
00154 
00155 FUNCTION: 
00156   WndProc
00157 
00158 PURPOSE: 
00159   Processes messages sent to the main window.
00160 
00161 ***********************************************************************/
00162 LRESULT PrefsDialog::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
00163 {
00164     SHINITDLGINFO shidi;
00165     SHMENUBARINFO mbi;
00166     RECT rcClient;
00167 
00168     switch( msg )
00169     {
00170     case WM_INITDIALOG:
00171         shidi.dwMask = SHIDIM_FLAGS;
00172         shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN |
00173             SHIDIF_FULLSCREENNOMENUBAR;//SHIDIF_SIZEDLGFULLSCREEN;
00174         shidi.hDlg = hwnd;
00175         SHInitDialog( &shidi );
00176 
00177         //Create the menubar
00178         memset( &mbi, 0, sizeof (SHMENUBARINFO) );
00179         mbi.cbSize     = sizeof (SHMENUBARINFO);
00180         mbi.hwndParent = hwnd;
00181         mbi.dwFlags    = SHCMBF_EMPTYBAR;
00182         mbi.hInstRes   = hInst;
00183 
00184         if( !SHCreateMenuBar(&mbi) )
00185         {
00186             MessageBox(hwnd, _T("SHCreateMenuBar Failed"), _T("Error"), MB_OK);
00187             //return -1;
00188         }
00189 
00190         hwndCB = mbi.hwndMB;
00191 
00192         // Get the client area rect to put the panels in
00193         GetClientRect(hwnd, &rcClient);
00194 
00195         /* Create the buttons */            
00196         advanced_checkbox =
00197             CreateWindow( _T("BUTTON"), _T("Advanced options"),
00198                         WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
00199                         5, 10, 15, 15, hwnd, NULL, hInst, NULL );
00200         SendMessage( advanced_checkbox, BM_SETCHECK, BST_UNCHECKED, 0 );
00201 
00202         advanced_label = CreateWindow( _T("STATIC"), _T("Advanced options"),
00203                         WS_CHILD | WS_VISIBLE | SS_LEFT,
00204                         5 + 15 + 5, 10, 110, 15,
00205                         hwnd, NULL, hInst, NULL);
00206 
00207         if( config_GetInt( p_intf, "advanced" ) )
00208         {
00209             SendMessage( advanced_checkbox, BM_SETCHECK, BST_CHECKED, 0 );
00210             /*dummy_event.SetInt(TRUE);
00211               OnAdvanced( dummy_event );*/
00212         }
00213 
00214         reset_button = CreateWindow( _T("BUTTON"), _T("Reset All"),
00215                         WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
00216                         rcClient.right - 5 - 80, 10 - 3, 80, 15 + 6,
00217                         hwnd, NULL, hInst, NULL );
00218 
00219         /* Create the preferences tree control */
00220         prefs_tree = new PrefsTreeCtrl( p_intf, this, hwnd, hInst );
00221 
00222         UpdateWindow( hwnd );
00223         break;
00224 
00225     case WM_CLOSE:
00226         EndDialog( hwnd, LOWORD( wp ) );
00227         break;
00228 
00229     case WM_SETFOCUS:
00230         SHFullScreen( hwnd, SHFS_SHOWSIPBUTTON );
00231         break;
00232 
00233     case WM_COMMAND:
00234         if( LOWORD(wp) == IDOK )
00235         {
00236             OnOk();
00237             EndDialog( hwnd, LOWORD( wp ) );
00238         }
00239         break;
00240 
00241     case WM_NOTIFY:
00242 
00243         if( lp && prefs_tree &&
00244             ((LPNMHDR)lp)->hwndFrom == prefs_tree->hwndTV &&
00245             ((LPNMHDR)lp)->code == TVN_SELCHANGED )
00246         {
00247             prefs_tree->OnSelectTreeItem( (NM_TREEVIEW FAR *)(LPNMHDR)lp,
00248                                           hwnd, hInst );
00249         }
00250         break;
00251 
00252     case WM_VSCROLL:
00253     {
00254         TVITEM tvi = {0};
00255         tvi.mask = TVIF_PARAM;
00256         tvi.hItem = TreeView_GetSelection( prefs_tree->hwndTV );
00257         if( !tvi.hItem ) break;
00258 
00259         if( !TreeView_GetItem( prefs_tree->hwndTV, &tvi ) ) break;
00260 
00261         ConfigTreeData *config_data =
00262             prefs_tree->FindModuleConfig( (ConfigTreeData *)tvi.lParam );
00263         if( config_data && hwnd == config_data->panel->config_window ) 
00264         {
00265             int dy;
00266             RECT rc;
00267             GetWindowRect( hwnd, &rc);
00268             int newvalue = config_data->panel->oldvalue;
00269             switch ( GET_WM_VSCROLL_CODE(wp,lp) ) 
00270             {
00271             case SB_BOTTOM       : newvalue = 0; break;
00272             case SB_TOP          : newvalue = config_data->panel->maxvalue; break;
00273             case SB_LINEDOWN     : newvalue += 10; break;
00274             case SB_PAGEDOWN     : newvalue += rc.bottom - rc.top - 25; break; // faux ! une page c'est la longueur réelle de notebook
00275             case SB_LINEUP       : newvalue -= 10; break;
00276             case SB_PAGEUP       : newvalue -= rc.bottom - rc.top - 25; break;
00277             case SB_THUMBPOSITION:
00278             case SB_THUMBTRACK   : newvalue = GET_WM_VSCROLL_POS(wp,lp); break;
00279             }
00280             newvalue = max(0,min(config_data->panel->maxvalue,newvalue));
00281             SetScrollPos( hwnd,SB_VERT,newvalue,TRUE);//SB_CTL si hwnd=hwndScrollBar, SB_VERT si window
00282             dy = config_data->panel->oldvalue - newvalue;
00283 
00284             ScrollWindowEx( hwnd, 0, dy, NULL, NULL, NULL, NULL, SW_SCROLLCHILDREN );
00285             UpdateWindow ( hwnd);
00286 
00287             config_data->panel->oldvalue = newvalue;                                
00288         }
00289         break;
00290     }
00291 
00292     default:
00293         break;
00294     }
00295 
00296     return FALSE;
00297 }
00298 
00299 /*****************************************************************************
00300  * Private methods.
00301  *****************************************************************************/
00302 
00303 /*****************************************************************************
00304  * Events methods.
00305  *****************************************************************************/
00306 void PrefsDialog::OnOk( void )
00307 {
00308     prefs_tree->ApplyChanges();
00309     config_SaveConfigFile( p_intf, NULL );
00310 }
00311 
00312 /*****************************************************************************
00313  * PrefsTreeCtrl class definition.
00314  *****************************************************************************/
00315 PrefsTreeCtrl::PrefsTreeCtrl( intf_thread_t *_p_intf,
00316                               PrefsDialog *_p_prefs_dialog, HWND hwnd,
00317                               HINSTANCE hInst )
00318 {
00319     vlc_list_t      *p_list;
00320     module_t        *p_module;
00321     module_config_t *p_item;
00322     int i_index;
00323 
00324     INITCOMMONCONTROLSEX iccex;
00325     RECT rcClient;
00326     TVITEM tvi = {0}; 
00327     TVINSERTSTRUCT tvins = {0}; 
00328     HTREEITEM hPrev;
00329 
00330     size_t i_capability_count = 0;
00331     size_t i_child_index;
00332 
00333     HTREEITEM capability_item;
00334 
00335     /* Initializations */
00336     p_intf = _p_intf;
00337     p_prefs_dialog = _p_prefs_dialog;
00338     b_advanced = VLC_FALSE;
00339 
00340     /* Create a tree view */
00341     // Initialize the INITCOMMONCONTROLSEX structure.
00342     iccex.dwSize = sizeof( INITCOMMONCONTROLSEX );
00343     iccex.dwICC = ICC_TREEVIEW_CLASSES;
00344 
00345     // Registers Statusbar control classes from the common control dll
00346     InitCommonControlsEx( &iccex );
00347 
00348     // Get the client area rect to put the tv in
00349     GetClientRect(hwnd, &rcClient);
00350 
00351     // Create the tree-view control.
00352     hwndTV = CreateWindowEx( 0, WC_TREEVIEW, NULL,
00353         WS_VISIBLE | WS_CHILD | WS_BORDER | TVS_HASLINES |
00354         TVS_LINESATROOT | TVS_HASBUTTONS,
00355         5, 10 + 2*(15 + 10) + 105 + 5, rcClient.right - 5 - 5, 6*15,
00356         hwnd, NULL, hInst, NULL );
00357 
00358     tvi.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM;
00359 
00360     /* List the plugins */
00361     p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
00362     if( !p_list ) return;
00363 
00364     /*
00365      * Build a tree of the main options
00366      */
00367     ConfigTreeData *config_data = new ConfigTreeData;
00368     config_data->i_object_id = GENERAL_ID;
00369     config_data->psz_help = strdup("nothing");//strdup( GENERAL_HELP );
00370     config_data->psz_section = strdup( GENERAL_TITLE );
00371     tvi.pszText = _T("General settings");
00372     tvi.cchTextMax = lstrlen(_T("General settings"));
00373     tvi.lParam = (long)config_data;
00374     tvins.item = tvi;
00375     tvins.hInsertAfter = TVI_FIRST;
00376     tvins.hParent = TVI_ROOT;
00377 
00378     // Add the item to the tree-view control.
00379     hPrev = (HTREEITEM) TreeView_InsertItem( hwndTV, &tvins);
00380     general_item = hPrev;
00381 
00382     for( i_index = 0; i_index < p_list->i_count; i_index++ )
00383     {
00384         p_module = (module_t *)p_list->p_values[i_index].p_object;
00385         if( !strcmp( p_module->psz_object_name, "main" ) )
00386             break;
00387     }
00388     if( i_index < p_list->i_count )
00389     {
00390         /* We found the main module */
00391 
00392         /* Enumerate config categories and store a reference so we can
00393          * generate their config panel them when it is asked by the user. */
00394         p_item = p_module->p_config;
00395 
00396         if( p_item ) do
00397         {
00398             switch( p_item->i_type )
00399             {
00400             case CONFIG_HINT_CATEGORY:
00401                 ConfigTreeData *config_data = new ConfigTreeData;
00402                 config_data->psz_section = strdup( p_item->psz_text );
00403                 if( p_item->psz_longtext )
00404                 {
00405                     config_data->psz_help =
00406                         strdup( p_item->psz_longtext );
00407                 }
00408                 else
00409                 {
00410                     config_data->psz_help = NULL;
00411                 }
00412                 config_data->i_object_id = p_module->i_object_id;
00413 
00414                 /* Add the category to the tree */
00415                 // Set the text of the item. 
00416                 tvi.pszText = _FROMMB(p_item->psz_text); 
00417                 tvi.cchTextMax = _tcslen(tvi.pszText);
00418                 tvi.lParam = (long)config_data;
00419                 tvins.item = tvi;
00420                 tvins.hInsertAfter = hPrev; 
00421                 tvins.hParent = general_item; //level 3
00422     
00423                 // Add the item to the tree-view control. 
00424                 hPrev = (HTREEITEM)TreeView_InsertItem( hwndTV, &tvins );
00425 
00426                 break;
00427             }
00428         }
00429         while( p_item->i_type != CONFIG_HINT_END && p_item++ );
00430 
00431         TreeView_SortChildren( hwndTV, general_item, 0 );
00432     }
00433         
00434     /*
00435      * Build a tree of all the plugins
00436      */
00437     config_data = new ConfigTreeData;
00438     config_data->i_object_id = PLUGIN_ID;
00439     config_data->psz_help = strdup("nothing");//strdup( PLUGIN_HELP );
00440     config_data->psz_section = strdup("nothing");//strdup( PLUGIN_TITLE );
00441     tvi.pszText = _T("Modules");
00442     tvi.cchTextMax = lstrlen(_T("Modules"));
00443     tvi.lParam = (long)config_data;
00444     tvins.item = tvi;
00445     tvins.hInsertAfter = TVI_LAST;
00446     tvins.hParent = TVI_ROOT;
00447 
00448     // Add the item to the tree-view control.
00449     hPrev = (HTREEITEM) TreeView_InsertItem( hwndTV, &tvins);
00450     plugins_item = hPrev;
00451 
00452     i_capability_count = 0;
00453     for( i_index = 0; i_index < p_list->i_count; i_index++ )
00454     {
00455         i_child_index = 0;
00456 
00457         p_module = (module_t *)p_list->p_values[i_index].p_object;
00458 
00459         /* Exclude the main module */
00460         if( !strcmp( p_module->psz_object_name, "main" ) )
00461             continue;
00462 
00463         /* Exclude empty plugins (submodules don't have config options, they
00464          * are stored in the parent module) */
00465         if( p_module->b_submodule )
00466             p_item = ((module_t *)p_module->p_parent)->p_config;
00467         else
00468             p_item = p_module->p_config;
00469 
00470         if( !p_item ) continue;
00471         do
00472         {
00473             if( p_item->i_type & CONFIG_ITEM )
00474                 break;
00475         }
00476         while( p_item->i_type != CONFIG_HINT_END && p_item++ );
00477         if( p_item->i_type == CONFIG_HINT_END ) continue;
00478 
00479         /* Find the capability child item */
00480         /*long cookie; size_t i_child_index;*/
00481         capability_item = TreeView_GetChild( hwndTV, plugins_item );
00482         while( capability_item != 0 )
00483         {
00484             TVITEM capability_tvi = {0};
00485             TCHAR psz_text[256];
00486             i_child_index++;
00487 
00488             capability_tvi.mask = TVIF_TEXT;
00489             capability_tvi.pszText = psz_text;
00490             capability_tvi.cchTextMax = 256;
00491             capability_tvi.hItem = capability_item;
00492             TreeView_GetItem( hwndTV, &capability_tvi );
00493             if( !strcmp( _TOMB(capability_tvi.pszText),
00494                          p_module->psz_capability ) ) break;
00495  
00496             capability_item =
00497                 TreeView_GetNextSibling( hwndTV, capability_item );
00498         }
00499 
00500         if( i_child_index == i_capability_count &&
00501             p_module->psz_capability && *p_module->psz_capability )
00502         {
00503             /* We didn't find it, add it */
00504             ConfigTreeData *config_data = new ConfigTreeData;
00505             config_data->psz_section =
00506                 strdup( GetCapabilityHelp( p_module->psz_capability , 1 ) );
00507             config_data->psz_help =
00508                 strdup( GetCapabilityHelp( p_module->psz_capability , 2 ) );
00509             config_data->i_object_id = CAPABILITY_ID;
00510             tvi.pszText = _FROMMB(p_module->psz_capability);
00511             tvi.cchTextMax = _tcslen(tvi.pszText);
00512             tvi.lParam = (long)config_data;
00513             tvins.item = tvi;
00514             tvins.hInsertAfter = plugins_item; 
00515             tvins.hParent = plugins_item;// level 3
00516 
00517             // Add the item to the tree-view control. 
00518             capability_item = (HTREEITEM) TreeView_InsertItem( hwndTV, &tvins);
00519 
00520             i_capability_count++;
00521         }
00522 
00523         /* Add the plugin to the tree */
00524         ConfigTreeData *config_data = new ConfigTreeData;
00525         config_data->b_submodule = p_module->b_submodule;
00526         config_data->i_object_id = p_module->b_submodule ?
00527             ((module_t *)p_module->p_parent)->i_object_id :
00528             p_module->i_object_id;
00529         config_data->psz_help = NULL;
00530         tvi.pszText = _FROMMB(p_module->psz_object_name);
00531         tvi.cchTextMax = _tcslen(tvi.pszText);
00532         tvi.lParam = (long)config_data;
00533         tvins.item = tvi;
00534         tvins.hInsertAfter = capability_item; 
00535         tvins.hParent = capability_item;// level 4
00536 
00537         // Add the item to the tree-view control. 
00538         TreeView_InsertItem( hwndTV, &tvins );
00539     }
00540 
00541     /* Sort all this mess */
00542     /*long cookie; size_t i_child_index;*/
00543     TreeView_SortChildren( hwndTV, plugins_item, 0 );
00544     capability_item = TreeView_GetChild( hwndTV, plugins_item );
00545     while( capability_item != 0 )
00546     {
00547         TreeView_SortChildren( hwndTV, capability_item, 0 );
00548         capability_item = TreeView_GetNextSibling( hwndTV, capability_item );
00549     }
00550 
00551     /* Clean-up everything */
00552     vlc_list_release( p_list );
00553 
00554     TreeView_Expand( hwndTV, general_item, TVE_EXPANDPARTIAL |TVE_EXPAND );
00555 }
00556 
00557 PrefsTreeCtrl::~PrefsTreeCtrl()
00558 {
00559 }
00560 
00561 void PrefsTreeCtrl::ApplyChanges()
00562 {
00563     /*long cookie, cookie2;*/
00564     ConfigTreeData *config_data;
00565 
00566     /* Apply changes to the main module */
00567     HTREEITEM item = TreeView_GetChild( hwndTV, general_item );
00568     while( item != 0 )
00569     {
00570         TVITEM tvi = {0};
00571         tvi.mask = TVIF_PARAM;
00572         tvi.hItem = item;
00573         TreeView_GetItem( hwndTV, &tvi );
00574         config_data = (ConfigTreeData *)tvi.lParam;
00575         if( config_data && config_data->panel )
00576         {
00577             config_data->panel->ApplyChanges();
00578         }
00579 
00580         item = TreeView_GetNextSibling( hwndTV, item );
00581     }
00582 
00583     /* Apply changes to the plugins */
00584     item = TreeView_GetChild( hwndTV, plugins_item );
00585     while( item != 0 )
00586     {
00587         HTREEITEM item2 = TreeView_GetChild( hwndTV, item );
00588         while( item2 != 0 )
00589         {       
00590             TVITEM tvi = {0};
00591             tvi.mask = TVIF_PARAM;
00592             tvi.hItem = item2;
00593             TreeView_GetItem( hwndTV, &tvi );
00594             config_data = (ConfigTreeData *)tvi.lParam;
00595             if( config_data && config_data->panel )
00596             {
00597                 config_data->panel->ApplyChanges();
00598             }
00599             item2 = TreeView_GetNextSibling( hwndTV, item2 );
00600         }
00601         item = TreeView_GetNextSibling( hwndTV, item );
00602     }
00603 }
00604 
00605 ConfigTreeData *PrefsTreeCtrl::FindModuleConfig( ConfigTreeData *config_data )
00606 {
00607     /* We need this complexity because submodules don't have their own config
00608      * options. They use the parent module ones. */
00609 
00610     if( !config_data || !config_data->b_submodule )
00611     {
00612         return config_data;
00613     }
00614 
00615     /*long cookie, cookie2;*/
00616     ConfigTreeData *config_new;
00617     HTREEITEM item = TreeView_GetChild( hwndTV, plugins_item );
00618     while( item != 0 )
00619     {
00620         HTREEITEM item2 = TreeView_GetChild( hwndTV, item );
00621         while( item2 != 0 )
00622         {       
00623             TVITEM tvi = {0};
00624             tvi.mask = TVIF_PARAM;
00625             tvi.hItem = item2;
00626             TreeView_GetItem( hwndTV, &tvi );
00627             config_new = (ConfigTreeData *)tvi.lParam;
00628             if( config_new && !config_new->b_submodule &&
00629                 config_new->i_object_id == config_data->i_object_id )
00630             {
00631                 return config_new;
00632             }
00633             item2 = TreeView_GetNextSibling( hwndTV, item2 );
00634         }
00635         item = TreeView_GetNextSibling( hwndTV, item );
00636     }
00637 
00638     /* Found nothing */
00639     return NULL;
00640 }
00641 
00642 void PrefsTreeCtrl::OnSelectTreeItem( LPNM_TREEVIEW pnmtv, HWND parent,
00643                                       HINSTANCE hInst )
00644 {
00645     ConfigTreeData *config_data = NULL;
00646 
00647     if( pnmtv->itemOld.hItem )
00648         config_data = FindModuleConfig( (ConfigTreeData *)pnmtv->itemOld.lParam );
00649 
00650     if( config_data && config_data->panel )
00651     {
00652         config_data->panel->Hide();
00653     }
00654 
00655     /* Don't use event.GetItem() because we also send fake events */
00656     TVITEM tvi = {0};
00657     tvi.mask = TVIF_PARAM;
00658     tvi.hItem = TreeView_GetSelection( hwndTV );
00659     TreeView_GetItem( hwndTV, &tvi );
00660     config_data = FindModuleConfig( (ConfigTreeData *)tvi.lParam );
00661     if( config_data )
00662     {
00663         if( !config_data->panel )
00664         {
00665             /* The panel hasn't been created yet. Let's do it. */
00666             config_data->panel =
00667                 new PrefsPanel( parent, hInst, p_intf, p_prefs_dialog,
00668                                 config_data->i_object_id,
00669                                 config_data->psz_section,
00670                                 config_data->psz_help );
00671         }
00672         else
00673         {
00674             config_data->panel->Show();
00675         }
00676     }
00677 }
00678 
00679 /*****************************************************************************
00680  * PrefsPanel class definition.
00681  *****************************************************************************/
00682 PrefsPanel::PrefsPanel( HWND parent, HINSTANCE hInst, intf_thread_t *_p_intf,
00683                         PrefsDialog *_p_prefs_dialog,
00684                         int i_object_id, char *psz_section, char *psz_help )
00685 {
00686     module_config_t *p_item;
00687     module_t *p_module = NULL;
00688 
00689     /* Initializations */
00690     p_intf = _p_intf;
00691     p_prefs_dialog = _p_prefs_dialog;
00692 
00693     b_advanced = VLC_TRUE;
00694 
00695     if( i_object_id == PLUGIN_ID || i_object_id == GENERAL_ID ||
00696         i_object_id == CAPABILITY_ID )
00697     {
00698         label = CreateWindow( _T("STATIC"), _FROMMB(psz_section),
00699                               WS_CHILD | WS_VISIBLE | SS_LEFT,
00700                               5, 10 + (15 + 10), 200, 15,
00701                               parent, NULL, hInst, NULL );
00702         config_window = NULL;
00703     }
00704     else
00705     {
00706         /* Get a pointer to the module */
00707         p_module = (module_t *)vlc_object_get( p_intf,  i_object_id );
00708         if( p_module->i_object_type != VLC_OBJECT_MODULE )
00709         {
00710             /* 0OOoo something went really bad */
00711             return;
00712         }
00713 
00714         /* Enumerate config options and add corresponding config boxes
00715          * (submodules don't have config options, they are stored in the
00716          *  parent module) */
00717         if( p_module->b_submodule )
00718             p_item = ((module_t *)p_module->p_parent)->p_config;
00719         else
00720             p_item = p_module->p_config;
00721 
00722         /* Find the category if it has been specified */
00723         if( psz_section && p_item->i_type == CONFIG_HINT_CATEGORY )
00724         {
00725             while( !(p_item->i_type == CONFIG_HINT_CATEGORY) ||
00726                    strcmp( psz_section, p_item->psz_text ) )
00727             {
00728                 if( p_item->i_type == CONFIG_HINT_END ) break;
00729                 p_item++;
00730             }
00731         }
00732 
00733         /* Add a head title to the panel */
00734         label = CreateWindow( _T("STATIC"), _FROMMB(psz_section ?
00735                         p_item->psz_text : p_module->psz_longname),
00736                         WS_CHILD | WS_VISIBLE | SS_LEFT,
00737                         5, 10 + (15 + 10), 250, 15,
00738                         parent, NULL, hInst, NULL );
00739 
00740         WNDCLASS wc;
00741         memset( &wc, 0, sizeof(wc) );
00742         wc.style          = CS_HREDRAW | CS_VREDRAW;
00743         wc.lpfnWndProc    = (WNDPROC) _p_prefs_dialog->BaseWndProc;
00744         wc.cbClsExtra     = 0;
00745         wc.cbWndExtra     = 0;
00746         wc.hInstance      = hInst;
00747         wc.hIcon          = 0;
00748         wc.hCursor        = 0;
00749         wc.hbrBackground  = (HBRUSH) GetStockObject(WHITE_BRUSH);
00750         wc.lpszMenuName   = 0;
00751         wc.lpszClassName  = _T("PrefsPanelClass");
00752         RegisterClass(&wc);
00753 
00754         RECT rc;
00755         GetWindowRect( parent, &rc);
00756         config_window = CreateWindow( _T("PrefsPanelClass"),
00757                         _T("config_window"),
00758                         WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_BORDER,
00759                         5, 10 + 2*(15 + 10), rc.right - 5 - 7, 105,
00760                         parent, NULL, hInst, (void *) _p_prefs_dialog );
00761 
00762         int y_pos = 5;
00763         if( p_item ) do
00764         {
00765             /* If a category has been specified, check we finished the job */
00766             if( psz_section && p_item->i_type == CONFIG_HINT_CATEGORY &&
00767                 strcmp( psz_section, p_item->psz_text ) )
00768                 break;
00769 
00770             ConfigControl *control =
00771                 CreateConfigControl( VLC_OBJECT(p_intf),
00772                                      p_item, config_window,
00773                                      hInst, &y_pos );
00774 
00775             /* Don't add items that were not recognized */
00776             if( control == NULL ) continue;
00777 
00778             /* Add the config data to our array so we can keep a trace of it */
00779             config_array.push_back( control );
00780         }
00781         while( p_item->i_type != CONFIG_HINT_END && p_item++ );
00782                 
00783         GetWindowRect( config_window, &rc);
00784         maxvalue = y_pos - (rc.bottom - rc.top) + 5;
00785         oldvalue = 0;
00786         SetScrollRange( config_window, SB_VERT, 0, maxvalue, TRUE );
00787     }
00788 }
00789 
00790 void PrefsPanel::Hide()
00791 {
00792     ShowWindow( label, SW_HIDE );
00793     if( config_window ) ShowWindow( config_window, SW_HIDE );
00794 }
00795 
00796 void PrefsPanel::Show()
00797 {
00798     ShowWindow( label, SW_SHOW );
00799     if( config_window ) ShowWindow( config_window, SW_SHOW );
00800 }
00801 
00802 void PrefsPanel::ApplyChanges()
00803 {
00804     vlc_value_t val;
00805 
00806     for( size_t i = 0; i < config_array.size(); i++ )
00807     {
00808         ConfigControl *control = config_array[i];
00809 
00810         switch( control->GetType() )
00811         {
00812         case CONFIG_ITEM_STRING:
00813         case CONFIG_ITEM_FILE:
00814         case CONFIG_ITEM_DIRECTORY:
00815         case CONFIG_ITEM_MODULE:
00816             config_PutPsz( p_intf, control->GetName(),
00817                            control->GetPszValue() );
00818             break;
00819         case CONFIG_ITEM_KEY:
00820             /* So you don't need to restart to have the changes take effect */
00821             val.i_int = control->GetIntValue();
00822             var_Set( p_intf->p_vlc, control->GetName(), val );
00823         case CONFIG_ITEM_INTEGER:
00824         case CONFIG_ITEM_BOOL:
00825             config_PutInt( p_intf, control->GetName(),
00826                            control->GetIntValue() );
00827             break;
00828         case CONFIG_ITEM_FLOAT:
00829             config_PutFloat( p_intf, control->GetName(),
00830                              control->GetFloatValue() );
00831             break;
00832         }
00833     }
00834 }

Generated on Tue Dec 20 10:14:45 2005 for vlc-0.8.4a by  doxygen 1.4.2