]> git.sesse.net Git - vlc/blobdiff - modules/gui/wince/preferences.cpp
* Makefile.am: backport of 11352.
[vlc] / modules / gui / wince / preferences.cpp
index 742cd0b9f59ccf0b17ddfa44d3e6c0e004002d18..492144706329023659086077f4e26a1760f200f1 100644 (file)
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
+#include <stdlib.h>                                      /* malloc(), free() */
+#include <string.h>                                            /* strerror() */
+#include <stdio.h>
 #include <vlc/vlc.h>
 #include <vlc/intf.h>
-#include <string.h>
 
-#include <string>
-#include <stdio.h>
-using namespace std; 
+#include "wince.h"
 
 #include <winuser.h>
 #include <windows.h>
 #include <windowsx.h>
 #include <commctrl.h>
-#include <aygshell.h>
-
 #include <commdlg.h>
 
 #include <vlc_config_cat.h>
 
-#include "wince.h"
 #include "preferences_widgets.h"
 
 #define GENERAL_ID 1242
@@ -72,7 +69,8 @@ class PrefsTreeCtrl
 public:
 
     PrefsTreeCtrl() { }
-    PrefsTreeCtrl( intf_thread_t *_p_intf, PrefsDialog *p_prefs_dialog, HWND hwnd, HINSTANCE _hInst );
+    PrefsTreeCtrl( intf_thread_t *_p_intf, PrefsDialog *p_prefs_dialog,
+                   HWND hwnd, HINSTANCE _hInst );
     virtual ~PrefsTreeCtrl();
 
     void ApplyChanges();
@@ -89,7 +87,6 @@ private:
     PrefsDialog *p_prefs_dialog;
     vlc_bool_t b_advanced;
 
-    HTREEITEM root_item;
     HTREEITEM general_item;
     HTREEITEM plugins_item;
 };
@@ -145,11 +142,11 @@ public:
 /*****************************************************************************
  * Constructor.
  *****************************************************************************/
-PrefsDialog::PrefsDialog( intf_thread_t *_p_intf, HINSTANCE _hInst )
+PrefsDialog::PrefsDialog( intf_thread_t *p_intf, CBaseWindow *p_parent,
+                          HINSTANCE h_inst )
+  :  CBaseWindow( p_intf, p_parent, h_inst )
 {
     /* Initializations */
-    p_intf = _p_intf;
-    hInst = _hInst;
     prefs_tree = NULL;
 }
 
@@ -160,22 +157,17 @@ FUNCTION:
 
 PURPOSE: 
   Processes messages sent to the main window.
-  
+
 ***********************************************************************/
-LRESULT PrefsDialog::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
-                              PBOOL pbProcessed  )
+LRESULT PrefsDialog::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
 {
     SHINITDLGINFO shidi;
     SHMENUBARINFO mbi;
     RECT rcClient;
 
-    LRESULT lResult = CBaseWindow::WndProc( hwnd, msg, wp, lp, pbProcessed );
-    BOOL bWasProcessed = *pbProcessed;
-    *pbProcessed = TRUE;
-
     switch( msg )
     {
-    case WM_INITDIALOG: 
+    case WM_INITDIALOG:
         shidi.dwMask = SHIDIM_FLAGS;
         shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN |
             SHIDIF_FULLSCREENNOMENUBAR;//SHIDIF_SIZEDLGFULLSCREEN;
@@ -186,14 +178,12 @@ LRESULT PrefsDialog::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
         memset( &mbi, 0, sizeof (SHMENUBARINFO) );
         mbi.cbSize     = sizeof (SHMENUBARINFO);
         mbi.hwndParent = hwnd;
-        mbi.nToolBarId = IDR_DUMMYMENU;
+        mbi.dwFlags    = SHCMBF_EMPTYBAR;
         mbi.hInstRes   = hInst;
-        mbi.nBmpId     = 0;
-        mbi.cBmpImages = 0;  
 
         if( !SHCreateMenuBar(&mbi) )
         {
-            MessageBox(hwnd, L"SHCreateMenuBar Failed", L"Error", MB_OK);
+            MessageBox(hwnd, _T("SHCreateMenuBar Failed"), _T("Error"), MB_OK);
             //return -1;
         }
 
@@ -202,7 +192,7 @@ LRESULT PrefsDialog::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
         // Get the client area rect to put the panels in
         GetClientRect(hwnd, &rcClient);
 
-        /* Create the buttons */                
+        /* Create the buttons */            
         advanced_checkbox =
             CreateWindow( _T("BUTTON"), _T("Advanced options"),
                         WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
@@ -230,41 +220,47 @@ LRESULT PrefsDialog::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
         prefs_tree = new PrefsTreeCtrl( p_intf, this, hwnd, hInst );
 
         UpdateWindow( hwnd );
-        return lResult;
+        break;
+
+    case WM_CLOSE:
+        EndDialog( hwnd, LOWORD( wp ) );
+        break;
+
+    case WM_SETFOCUS:
+        SHFullScreen( hwnd, SHFS_SHOWSIPBUTTON );
+        break;
 
     case WM_COMMAND:
         if( LOWORD(wp) == IDOK )
         {
             OnOk();
             EndDialog( hwnd, LOWORD( wp ) );
-            return TRUE;
         }
-        *pbProcessed = bWasProcessed;
-        lResult = FALSE;
-        return lResult;
+        break;
 
     case WM_NOTIFY:
 
-        if ( ( ((LPNMHDR)lp)->hwndFrom == prefs_tree->hwndTV ) &&
-             ( ((LPNMHDR)lp)->code == TVN_SELCHANGED  ) )
+        if( lp && prefs_tree &&
+            ((LPNMHDR)lp)->hwndFrom == prefs_tree->hwndTV &&
+            ((LPNMHDR)lp)->code == TVN_SELCHANGED )
         {
             prefs_tree->OnSelectTreeItem( (NM_TREEVIEW FAR *)(LPNMHDR)lp,
                                           hwnd, hInst );
-            return TRUE;
         }
-
-        *pbProcessed = bWasProcessed;
-        lResult = FALSE;
-        return lResult;
+        break;
 
     case WM_VSCROLL:
     {
         TVITEM tvi = {0};
         tvi.mask = TVIF_PARAM;
         tvi.hItem = TreeView_GetSelection( prefs_tree->hwndTV );
-        TreeView_GetItem( prefs_tree->hwndTV, &tvi );
-        ConfigTreeData *config_data = prefs_tree->FindModuleConfig( (ConfigTreeData *)tvi.lParam );
-        if ( hwnd == config_data->panel->config_window ) 
+       if( !tvi.hItem ) break;
+
+        if( !TreeView_GetItem( prefs_tree->hwndTV, &tvi ) ) break;
+
+        ConfigTreeData *config_data =
+            prefs_tree->FindModuleConfig( (ConfigTreeData *)tvi.lParam );
+        if( config_data && hwnd == config_data->panel->config_window ) 
         {
             int dy;
             RECT rc;
@@ -290,20 +286,14 @@ LRESULT PrefsDialog::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
 
             config_data->panel->oldvalue = newvalue;                                
         }
+        break;
     }
-    *pbProcessed = bWasProcessed;
-    lResult = FALSE;
-    return lResult;
 
     default:
-        // the message was not processed
-        // indicate if the base class handled it
-        *pbProcessed = bWasProcessed;
-        lResult = FALSE;
-        return lResult;
+        break;
     }
 
-    return lResult;
+    return FALSE;
 }
 
 /*****************************************************************************
@@ -333,11 +323,6 @@ PrefsTreeCtrl::PrefsTreeCtrl( intf_thread_t *_p_intf,
 
     INITCOMMONCONTROLSEX iccex;
     RECT rcClient;
-
-    int size;
-    char *szAnsi;
-    LPWSTR wUnicode;
-    BOOL bTemp;
     TVITEM tvi = {0}; 
     TVINSERTSTRUCT tvins = {0}; 
     HTREEITEM hPrev;
@@ -370,17 +355,7 @@ PrefsTreeCtrl::PrefsTreeCtrl( intf_thread_t *_p_intf,
         5, 10 + 2*(15 + 10) + 105 + 5, rcClient.right - 5 - 5, 6*15,
         hwnd, NULL, hInst, NULL );
 
-    tvi.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM; 
-    tvi.pszText = _T("root");
-    tvi.cchTextMax = lstrlen(_T("root"));
-    tvi.lParam = (LPARAM) 1; // root level
-    tvins.item = tvi;
-    tvins.hInsertAfter = TVI_FIRST; 
-    tvins.hParent = TVI_ROOT; 
-
-    // Add the item to the tree-view control. 
-    hPrev = (HTREEITEM) TreeView_InsertItem( hwndTV, &tvins );
-    root_item = hPrev;
+    tvi.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM;
 
     /* List the plugins */
     p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
@@ -395,10 +370,10 @@ PrefsTreeCtrl::PrefsTreeCtrl( intf_thread_t *_p_intf,
     config_data->psz_section = strdup( GENERAL_TITLE );
     tvi.pszText = _T("General settings");
     tvi.cchTextMax = lstrlen(_T("General settings"));
-    tvi.lParam = (long) config_data;
+    tvi.lParam = (long)config_data;
     tvins.item = tvi;
-    tvins.hInsertAfter = hPrev;
-    tvins.hParent = root_item; //level 2
+    tvins.hInsertAfter = TVI_FIRST;
+    tvins.hParent = TVI_ROOT;
 
     // Add the item to the tree-view control.
     hPrev = (HTREEITEM) TreeView_InsertItem( hwndTV, &tvins);
@@ -465,10 +440,10 @@ PrefsTreeCtrl::PrefsTreeCtrl( intf_thread_t *_p_intf,
     config_data->psz_section = strdup("nothing");//strdup( PLUGIN_TITLE );
     tvi.pszText = _T("Modules");
     tvi.cchTextMax = lstrlen(_T("Modules"));
-    tvi.lParam = (long) config_data;
+    tvi.lParam = (long)config_data;
     tvins.item = tvi;
-    tvins.hInsertAfter = hPrev;
-    tvins.hParent = root_item;// level 2
+    tvins.hInsertAfter = TVI_LAST;
+    tvins.hParent = TVI_ROOT;
 
     // Add the item to the tree-view control.
     hPrev = (HTREEITEM) TreeView_InsertItem( hwndTV, &tvins);
@@ -507,27 +482,19 @@ PrefsTreeCtrl::PrefsTreeCtrl( intf_thread_t *_p_intf,
         while( capability_item != 0 )
         {
             TVITEM capability_tvi = {0};
-
+            TCHAR psz_text[256];
             i_child_index++;
 
             capability_tvi.mask = TVIF_TEXT;
-            capability_tvi.pszText = new WCHAR[200];
-            capability_tvi.cchTextMax = 200;
+            capability_tvi.pszText = psz_text;
+            capability_tvi.cchTextMax = 256;
             capability_tvi.hItem = capability_item;
             TreeView_GetItem( hwndTV, &capability_tvi );
-            size = WideCharToMultiByte( CP_ACP, 0, capability_tvi.pszText, -1, NULL, 0, NULL, &bTemp );
-            szAnsi = new char[size];
-            WideCharToMultiByte( CP_ACP, 0, capability_tvi.pszText, -1, szAnsi, size, NULL, &bTemp );       
-            if( !strcmp( szAnsi, p_module->psz_capability ) )
-            {
-                free( szAnsi );
-                free( capability_tvi.pszText );
-                break;
-            }
-            free( szAnsi );
-            free( capability_tvi.pszText );
-
-            capability_item = TreeView_GetNextSibling( hwndTV, capability_item );
+            if( !strcmp( _TOMB(capability_tvi.pszText),
+                         p_module->psz_capability ) ) break;
+            capability_item =
+                TreeView_GetNextSibling( hwndTV, capability_item );
         }
 
         if( i_child_index == i_capability_count &&
@@ -542,7 +509,7 @@ PrefsTreeCtrl::PrefsTreeCtrl( intf_thread_t *_p_intf,
             config_data->i_object_id = CAPABILITY_ID;
             tvi.pszText = _FROMMB(p_module->psz_capability);
             tvi.cchTextMax = _tcslen(tvi.pszText);
-            tvi.lParam = (long) config_data;
+            tvi.lParam = (long)config_data;
             tvins.item = tvi;
             tvins.hInsertAfter = plugins_item; 
             tvins.hParent = plugins_item;// level 3
@@ -562,13 +529,13 @@ PrefsTreeCtrl::PrefsTreeCtrl( intf_thread_t *_p_intf,
         config_data->psz_help = NULL;
         tvi.pszText = _FROMMB(p_module->psz_object_name);
         tvi.cchTextMax = _tcslen(tvi.pszText);
-        tvi.lParam = (long) config_data;
+        tvi.lParam = (long)config_data;
         tvins.item = tvi;
         tvins.hInsertAfter = capability_item; 
         tvins.hParent = capability_item;// level 4
 
         // Add the item to the tree-view control. 
-        TreeView_InsertItem( hwndTV, &tvins);
+        TreeView_InsertItem( hwndTV, &tvins );
     }
 
     /* Sort all this mess */
@@ -584,7 +551,6 @@ PrefsTreeCtrl::PrefsTreeCtrl( intf_thread_t *_p_intf,
     /* Clean-up everything */
     vlc_list_release( p_list );
 
-    TreeView_Expand( hwndTV, root_item, TVE_EXPANDPARTIAL |TVE_EXPAND );
     TreeView_Expand( hwndTV, general_item, TVE_EXPANDPARTIAL |TVE_EXPAND );
 }
 
@@ -756,11 +722,10 @@ PrefsPanel::PrefsPanel( HWND parent, HINSTANCE hInst, intf_thread_t *_p_intf,
         /* Find the category if it has been specified */
         if( psz_section && p_item->i_type == CONFIG_HINT_CATEGORY )
         {
-            while( !p_item->i_type == CONFIG_HINT_CATEGORY ||
+            while( !(p_item->i_type == CONFIG_HINT_CATEGORY) ||
                    strcmp( psz_section, p_item->psz_text ) )
             {
-                if( p_item->i_type == CONFIG_HINT_END )
-                    break;
+                if( p_item->i_type == CONFIG_HINT_END ) break;
                 p_item++;
             }
         }