[dasher: 171/217] Win32 Added user facing preferrence to select control box layout file.



commit a45fd0e5111b987e1667eaca40eab01e4f8300b9
Author: Ada Majorek <amajorek google com>
Date:   Wed Jan 13 10:18:32 2016 -0800

    Win32 Added user facing preferrence to select control box layout file.

 Src/Win32/Dasher.rc                |   20 ++++++--
 Src/Win32/Widgets/AdvancedPage.cpp |   94 +++++++++++++++++++++--------------
 Src/Win32/Widgets/AdvancedPage.h   |    8 +---
 Src/Win32/resource.h               |    5 +-
 4 files changed, 76 insertions(+), 51 deletions(-)
---
diff --git a/Src/Win32/Dasher.rc b/Src/Win32/Dasher.rc
index acbccf8..bbd41c3 100644
--- a/Src/Win32/Dasher.rc
+++ b/Src/Win32/Dasher.rc
@@ -183,16 +183,17 @@ BEGIN
     CONTROL         "Confirm unsaved changes",IDC_CONFIRM_UNSAVED,"Button",BS_AUTOCHECKBOX | 
WS_TABSTOP,12,30,108,8
     CONTROL         "Show toolbar",IDC_CHECK1,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,42,58,10
     CONTROL         "Show statusbar",IDC_CHECK2,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,54,66,10
-    CONTROL         "Control mode",IDC_CONTROLMODE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,66,59,10
+    CONTROL         "Control mode",IDC_CONTROLMODE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,82,59,10
+    LISTBOX         IDC_CONTROLBOXES, 14, 92, 166, 132, LBS_SORT | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | 
WS_TABSTOP
     CONTROL         "Stand-alone",IDC_STYLE_STANDALONE,"Button",BS_AUTORADIOBUTTON | WS_GROUP | 
WS_TABSTOP,204,96,55,10
     CONTROL         "Composition",IDC_STYLE_COMPOSITION,"Button",BS_AUTORADIOBUTTON | 
WS_TABSTOP,204,120,55,10
     CONTROL         "Direct entry",IDC_STYLE_DIRECT,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,204,108,54,10
     GROUPBOX        "Application Style:",IDC_STATIC,198,84,180,63
     CONTROL         "Full screen",IDC_STYLE_FULL,"Button",BS_AUTORADIOBUTTON | NOT WS_VISIBLE | 
WS_TABSTOP,204,132,50,10
-    GROUPBOX        "Application Options:",IDC_STATIC,6,6,180,78
+    GROUPBOX        "Application Options:",IDC_STATIC,7,7,180,62
     GROUPBOX        "Speech:",IDC_STATIC,198,6,180,39
-    GROUPBOX        "Editor Font:",IDC_STATIC,6,90,180,30
-    PUSHBUTTON      "Change Font",IDC_EFONT_BUTTON,12,102,166,14
+    GROUPBOX        "Editor Font:",IDC_STATIC,194,154,180,30
+    PUSHBUTTON      "Change Font",IDC_EFONT_BUTTON,200,166,166,14
     CONTROL         "Speak on stop",IDC_CHECK3,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,204,18,99,10
     CONTROL         "Speak on word breaks",IDC_CHECK4,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,204,30,90,10
     GROUPBOX        "Clipboard:",IDC_STATIC,198,48,180,30
@@ -385,6 +386,17 @@ END
 
 /////////////////////////////////////////////////////////////////////////////
 //
+// AFX_DIALOG_LAYOUT
+//
+
+IDD_APPPAGE AFX_DIALOG_LAYOUT
+BEGIN
+    0
+END
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
 // String Table
 //
 
diff --git a/Src/Win32/Widgets/AdvancedPage.cpp b/Src/Win32/Widgets/AdvancedPage.cpp
index e8b64d5..6e00a0c 100644
--- a/Src/Win32/Widgets/AdvancedPage.cpp
+++ b/Src/Win32/Widgets/AdvancedPage.cpp
@@ -29,6 +29,7 @@ static char THIS_FILE[] = __FILE__;
 
 CAdvancedPage::CAdvancedPage(HWND Parent, CAppSettings *pAppSettings)
 :CPrefsPageBase(Parent, pAppSettings) {
+  pAppSettings->GetPermittedValues(SP_CONTROL_BOX_ID, m_ControlBoxItems);
 }
 
 struct menuentry {
@@ -48,17 +49,6 @@ static menuentry menutable[] = {
   {BP_COPY_ALL_ON_STOP, IDC_COPYONSTOP}
 };
 
-std::string CAdvancedPage::GetControlText(HWND Dialog, int ControlID) 
-{
-  HWND Control = GetDlgItem(Dialog, ControlID);
-  std::wstring str;
-  wincommon::GetWindowText( Control, str);
-
-  string ItemName;
-  WinUTF8::wstring_to_UTF8string(str, ItemName);
-  return ItemName;
-}
-
 void CAdvancedPage::PopulateList() {
   // Populate the controls in the dialogue box based on the relevent parameters
   for(int ii = 0; ii<sizeof(menutable)/sizeof(menuentry); ii++)
@@ -87,6 +77,26 @@ void CAdvancedPage::PopulateList() {
       break;
   }
 
+  HWND ListBox = GetDlgItem(m_hwnd, IDC_CONTROLBOXES);
+  auto CurrentControlBox = m_pAppSettings->GetStringParameter(SP_CONTROL_BOX_ID);
+  // Add each string to list box and index each one
+  bool SelectionSet = false;
+  for (auto i = 0; i < m_ControlBoxItems.size(); i++) {
+    Tstring Item;
+    WinUTF8::UTF8string_to_wstring(m_ControlBoxItems[i], Item);
+    if (Item.empty())
+      Item = L"<default>";
+    LRESULT Index = SendMessage(ListBox, LB_ADDSTRING, 0, (LPARAM)Item.c_str());
+    SendMessage(ListBox, LB_SETITEMDATA, Index, (LPARAM)i);
+    if (m_ControlBoxItems[i] == CurrentControlBox) {
+      SendMessage(ListBox, LB_SETCURSEL, Index, 0);
+      SelectionSet = true;
+    }
+  }
+  if (SelectionSet == false) {
+    SendMessage(ListBox, LB_SETCURSEL, 0, 0);
+    LRESULT CurrentIndex = SendMessage(ListBox, LB_GETITEMDATA, 0, 0);
+  }
 }
 
 bool CAdvancedPage::Apply() {
@@ -99,6 +109,12 @@ bool CAdvancedPage::Apply() {
   else if(SendMessage(GetDlgItem(m_hwnd, IDC_STYLE_FULL), BM_GETCHECK, 0, 0))
     m_pAppSettings->SetLongParameter(APP_LP_STYLE, 3);
 
+  HWND ListBox = GetDlgItem(m_hwnd, IDC_CONTROLBOXES);
+  LRESULT CurrentItem = SendMessage(ListBox, LB_GETCURSEL, 0, 0);
+  LRESULT CurrentIndex = SendMessage(ListBox, LB_GETITEMDATA, CurrentItem, 0);
+  auto CurrentControlBox = m_ControlBoxItems[CurrentIndex];
+  m_pAppSettings->SetStringParameter(SP_CONTROL_BOX_ID, CurrentControlBox);
+
   for(int ii = 0; ii<sizeof(menutable)/sizeof(menuentry); ii++) {
     m_pAppSettings->SetBoolParameter(menutable[ii].paramNum, SendMessage(GetDlgItem(m_hwnd, 
menutable[ii].idcNum), BM_GETCHECK, 0, 0) == BST_CHECKED );
   }
@@ -112,40 +128,42 @@ LRESULT CAdvancedPage::WndProc(HWND Window, UINT message, WPARAM wParam, LPARAM
   switch (message) {
 
   case WM_COMMAND:
-    if(HIWORD(wParam)==BN_CLICKED || HIWORD(wParam)==LBN_SELCHANGE) {
-      if(LOWORD(wParam) != 0 && m_hPropertySheet != 0 && m_hwnd != 0) {
+    if (HIWORD(wParam) == BN_CLICKED || HIWORD(wParam) == LBN_SELCHANGE) {
+      if (LOWORD(wParam) != 0 && m_hPropertySheet != 0 && m_hwnd != 0) {
         PropSheet_Changed(m_hPropertySheet, m_hwnd); // enables the 'Apply' button
-        // Behaviour isn't *perfect* since it activates the Apply button even if you, say,
-        // click 'new' alphabet then click Cancel when asked for a name.
+                                                     // Behaviour isn't *perfect* since it activates the 
Apply button even if you, say,
+                                                     // click 'new' alphabet then click Cancel when asked 
for a name.
       }
     }
     switch (LOWORD(wParam)) {
 
-  case IDC_EFONT_BUTTON:
-    // TODO: Put this in a function
-     {
-  CHOOSEFONT Data;
-    LOGFONT lf;
-    HFONT Font = (HFONT) GetStockObject(DEFAULT_GUI_FONT);
-    GetObject(Font, sizeof(LOGFONT), &lf);
-    Tstring tstrFaceName;
-    WinUTF8::UTF8string_to_wstring(m_pAppSettings->GetStringParameter(APP_SP_EDIT_FONT), tstrFaceName);
-    _tcscpy(lf.lfFaceName, tstrFaceName.c_str());
-    lf.lfHeight = m_pAppSettings->GetLongParameter(APP_LP_EDIT_FONT_SIZE);
-    Data.Flags = CF_INITTOLOGFONTSTRUCT | CF_SCREENFONTS;
-    Data.lStructSize = sizeof(CHOOSEFONT);
-    Data.hwndOwner = NULL;
-    Data.lpLogFont = &lf;
-    if(ChooseFont(&Data)) {
-      string FontName;
-      WinUTF8::wstring_to_UTF8string(lf.lfFaceName, FontName);
-      m_pAppSettings->SetStringParameter(APP_SP_EDIT_FONT, FontName);
-      m_pAppSettings->SetLongParameter(APP_LP_EDIT_FONT_SIZE, lf.lfHeight);
+    case IDC_EFONT_BUTTON:
+      // TODO: Put this in a function
+    {
+      CHOOSEFONT Data;
+      LOGFONT lf;
+      HFONT Font = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
+      GetObject(Font, sizeof(LOGFONT), &lf);
+      Tstring tstrFaceName;
+      WinUTF8::UTF8string_to_wstring(m_pAppSettings->GetStringParameter(APP_SP_EDIT_FONT), tstrFaceName);
+      _tcscpy(lf.lfFaceName, tstrFaceName.c_str());
+      lf.lfHeight = m_pAppSettings->GetLongParameter(APP_LP_EDIT_FONT_SIZE);
+      Data.Flags = CF_INITTOLOGFONTSTRUCT | CF_SCREENFONTS;
+      Data.lStructSize = sizeof(CHOOSEFONT);
+      Data.hwndOwner = NULL;
+      Data.lpLogFont = &lf;
+      if (ChooseFont(&Data)) {
+        string FontName;
+        WinUTF8::wstring_to_UTF8string(lf.lfFaceName, FontName);
+        m_pAppSettings->SetStringParameter(APP_SP_EDIT_FONT, FontName);
+        m_pAppSettings->SetLongParameter(APP_LP_EDIT_FONT_SIZE, lf.lfHeight);
+      }
     }
-  }
     break;
-
-      }
+    case IDC_CONTROLMODE:
+      EnableWindow(GetDlgItem(m_hwnd, IDC_CONTROLBOXES), SendMessage(GetDlgItem(m_hwnd, IDC_CONTROLMODE), 
BM_GETCHECK, 0, 0) == BST_CHECKED);
+      break;
+    }
   }
 
   return CPrefsPageBase::WndProc(Window, message, wParam, lParam);
diff --git a/Src/Win32/Widgets/AdvancedPage.h b/Src/Win32/Widgets/AdvancedPage.h
index c4bc170..b13194d 100644
--- a/Src/Win32/Widgets/AdvancedPage.h
+++ b/Src/Win32/Widgets/AdvancedPage.h
@@ -23,17 +23,11 @@ public:
 protected:
 private:
 
-  std::string GetControlText(HWND Dialog, int ControlID);
-
-
-  // Some status flags:
   void PopulateList();
-  void InitCustomBox();
-  bool UpdateInfo();
   bool Apply();
 
  TCHAR m_tcBuffer[1000];
-
+ std::vector<std::string> m_ControlBoxItems;
 };
 
 #endif  /* #ifndef __AlphabetBox_h__ */
diff --git a/Src/Win32/resource.h b/Src/Win32/resource.h
index dde5700..704b3c2 100644
--- a/Src/Win32/resource.h
+++ b/Src/Win32/resource.h
@@ -87,6 +87,7 @@
 #define IDC_FONT_VLARGE                 1155
 #define IDC_CHECK4                      1156
 #define IDC_CHECK5                      1157
+#define IDC_CONTROLBOXES                1160
 #define ID_EDIT_SELECTALL               32775
 #define ID_HELP_CONTENTS                32776
 #define ID_EDIT_COPY_ALL                32798
@@ -104,9 +105,9 @@
 // 
 #ifdef APSTUDIO_INVOKED
 #ifndef APSTUDIO_READONLY_SYMBOLS
-#define _APS_NEXT_RESOURCE_VALUE        181
+#define _APS_NEXT_RESOURCE_VALUE        182
 #define _APS_NEXT_COMMAND_VALUE         32820
-#define _APS_NEXT_CONTROL_VALUE         1160
+#define _APS_NEXT_CONTROL_VALUE         1161
 #define _APS_NEXT_SYMED_VALUE           110
 #endif
 #endif


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]