[dasher: 7/217] Brought back composition app style, fixed problems with message handling before windows are created.



commit 55e709b8ba1aa2765ebec4c55d853b5868688dc0
Author: ipomoena <amajorek google com>
Date:   Wed Jul 8 21:43:39 2015 -0700

    Brought back composition app style, fixed problems with message handling before windows are created.
    
    Brought back composition app style.
    Fixed problems with message handling before windows are created.
    Removed many now redundant is-sub-control-created tests.
    Also more Win CE removal.

 Src/Win32/AppSettings.h    |    4 +-
 Src/Win32/Dasher.rc        |   78 +++++----
 Src/Win32/DasherWindow.cpp |  369 +++++++++++++++++++-------------------------
 Src/Win32/DasherWindow.h   |   18 +--
 4 files changed, 202 insertions(+), 267 deletions(-)
---
diff --git a/Src/Win32/AppSettings.h b/Src/Win32/AppSettings.h
index ffff633..5753a43 100644
--- a/Src/Win32/AppSettings.h
+++ b/Src/Win32/AppSettings.h
@@ -50,11 +50,11 @@ public:
   #ifndef _WIN32_WCE
   bool LoadSetting(const std::string & Key, LPWINDOWPLACEMENT pwp, int* psp);
   void SaveSetting(const std::string & Key, const LPWINDOWPLACEMENT pwp, int sp);
-
+  #endif
 
   void SetHwnd(HWND hWnd) {
     m_hWnd = hWnd;
-#endif
+
   };
 
   void SetDasher(Dasher::CDasher *pDasher) {
diff --git a/Src/Win32/Dasher.rc b/Src/Win32/Dasher.rc
index ddcb689..09d2f56 100644
--- a/Src/Win32/Dasher.rc
+++ b/Src/Win32/Dasher.rc
@@ -19,10 +19,8 @@
 // Neutral resources
 
 #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_NEU)
-#ifdef _WIN32
 LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
 #pragma code_page(1252)
-#endif //_WIN32
 
 /////////////////////////////////////////////////////////////////////////////
 //
@@ -36,13 +34,11 @@ IDB_COPY_ALL_LARGE_COLOR BITMAP                  "CopyAllLarge.bmp"
 
 
 /////////////////////////////////////////////////////////////////////////////
-// English (U.S.) resources
+// English (United States) resources
 
 #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
-#ifdef _WIN32
 LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
 #pragma code_page(1252)
-#endif //_WIN32
 
 #ifdef APSTUDIO_INVOKED
 /////////////////////////////////////////////////////////////////////////////
@@ -93,18 +89,31 @@ BEGIN
     CONTROL         "Language model adapts as you write",IDC_ADAPTIVE,"Button",BS_AUTOCHECKBOX | 
WS_TABSTOP,131,17,133,10
 END
 
-#endif    // English (U.S.) resources
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// DESIGNINFO
+//
+
+#ifdef APSTUDIO_INVOKED
+GUIDELINES DESIGNINFO
+BEGIN
+    "IDD_PROPPAGE_LARGE", DIALOG
+    BEGIN
+    END
+END
+#endif    // APSTUDIO_INVOKED
+
+#endif    // English (United States) resources
 /////////////////////////////////////////////////////////////////////////////
 
 
 /////////////////////////////////////////////////////////////////////////////
-// English (U.K.) resources
+// English (United Kingdom) resources
 
 #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENG)
-#ifdef _WIN32
 LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_UK
 #pragma code_page(1252)
-#endif //_WIN32
 
 #ifdef APSTUDIO_INVOKED
 /////////////////////////////////////////////////////////////////////////////
@@ -278,23 +287,23 @@ STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSM
 CAPTION "Dialog"
 FONT 8, "MS Shell Dlg", 400, 0, 0x1
 BEGIN
-    CONTROL         "Control mode",IDC_CONTROLMODE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,54,59,10
-    CONTROL         "Show toolbar",IDC_CHECK1,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,30,58,10
-    CONTROL         "Show speed control",IDC_CHECK2,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,42,79,10
-    CONTROL         "Timestamp new files",IDC_TIMESTAMP,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,18,80,8
-    CONTROL         "Stand-alone",IDC_STYLE_STANDALONE,"Button",BS_AUTORADIOBUTTON | WS_GROUP | 
WS_TABSTOP,201,91,55,10
-    CONTROL         "Composition",IDC_STYLE_COMPOSITION,"Button",BS_AUTORADIOBUTTON | NOT WS_VISIBLE | 
WS_TABSTOP,319,221,55,10
-    CONTROL         "Direct entry",IDC_STYLE_DIRECT,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,201,103,54,10
-    GROUPBOX        "Application Style:",IDC_STATIC,194,81,180,35
-    CONTROL         "Full screen",IDC_STYLE_FULL,"Button",BS_AUTORADIOBUTTON | NOT WS_VISIBLE | 
WS_TABSTOP,234,218,50,10
-    GROUPBOX        "Application Options:",IDC_STATIC,7,7,180,64
-    GROUPBOX        "Speech:",IDC_STATIC,194,7,180,39
-    GROUPBOX        "Editor Font:",IDC_STATIC,7,73,180,32
-    PUSHBUTTON      "Change Font",IDC_EFONT_BUTTON,14,84,166,14
-    CONTROL         "Speak on stop",IDC_CHECK3,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,201,18,99,10
-    CONTROL         "Speak on word breaks",IDC_CHECK4,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,201,29,90,10
-    GROUPBOX        "Clipboard:",IDC_STATIC,194,50,180,26
-    CONTROL         "Copy all on stop",IDC_COPYONSTOP,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,201,61,90,10
+    CONTROL         "Control mode",IDC_CONTROLMODE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,54,59,10
+    CONTROL         "Show toolbar",IDC_CHECK1,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,30,58,10
+    CONTROL         "Show speed control",IDC_CHECK2,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,42,79,10
+    CONTROL         "Timestamp new files",IDC_TIMESTAMP,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,18,80,8
+    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,66
+    GROUPBOX        "Speech:",IDC_STATIC,198,6,180,39
+    GROUPBOX        "Editor Font:",IDC_STATIC,6,78,180,30
+    PUSHBUTTON      "Change Font",IDC_EFONT_BUTTON,12,90,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
+    CONTROL         "Copy all on stop",IDC_COPYONSTOP,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,204,60,90,10
 END
 
 
@@ -304,7 +313,7 @@ END
 //
 
 #ifdef APSTUDIO_INVOKED
-GUIDELINES DESIGNINFO 
+GUIDELINES DESIGNINFO
 BEGIN
     IDD_ABOUTBOX, DIALOG
     BEGIN
@@ -400,7 +409,7 @@ IDI_DASHER              ICON                    "dasher.ico"
 // Menu
 //
 
-IDC_DASHER MENU 
+IDC_DASHER MENU
 BEGIN
     POPUP "&File"
     BEGIN
@@ -431,7 +440,6 @@ BEGIN
         MENUITEM "&Help Topics",                ID_HELP_CONTENTS
         MENUITEM SEPARATOR
         MENUITEM "&About Dasher",               IDM_ABOUT
-        // MENUITEM "Game Mode",                   ID_GAMEMODE
     END
 END
 
@@ -441,7 +449,7 @@ END
 // Accelerator
 //
 
-IDC_DASHER ACCELERATORS 
+IDC_DASHER ACCELERATORS
 BEGIN
     "/",            IDM_ABOUT,              ASCII,  ALT, NOINVERT
     "?",            IDM_ABOUT,              ASCII,  ALT, NOINVERT
@@ -501,7 +509,7 @@ END
 // String Table
 //
 
-STRINGTABLE 
+STRINGTABLE
 BEGIN
     IDS_APP_TITLE           "Dasher"
     IDS_BUTTON_PREFS_TITLE  "General"
@@ -513,7 +521,7 @@ BEGIN
     IDS_FILE_NEW            "New"
 END
 
-STRINGTABLE 
+STRINGTABLE
 BEGIN
     IDS_EDIT_CUT            "Cut"
     IDS_EDIT_COPY           "Copy"
@@ -530,7 +538,7 @@ BEGIN
     IDS_TYPE_Cyrillic       "Cyrillic"
 END
 
-STRINGTABLE 
+STRINGTABLE
 BEGIN
     IDS_TYPE_Greek          "Greek"
     IDS_TYPE_Hebrew         "Hebrew"
@@ -548,7 +556,7 @@ BEGIN
     IDS_ERR_ALPH_DESC       "Please provide a unique description for this alphabet."
 END
 
-STRINGTABLE 
+STRINGTABLE
 BEGIN
     IDS_PREFS_VIEW          "Appearance"
     IDS_QUERY_SAVE_CHANGES  "Would you like to save changes\nto the current file?"
@@ -565,7 +573,7 @@ BEGIN
     IDS_ERR_SOCKET_TITLE    "Dasher Socket Input error"
 END
 
-#endif    // English (U.K.) resources
+#endif    // English (United Kingdom) resources
 /////////////////////////////////////////////////////////////////////////////
 
 
diff --git a/Src/Win32/DasherWindow.cpp b/Src/Win32/DasherWindow.cpp
index 29eeba0..725f47c 100644
--- a/Src/Win32/DasherWindow.cpp
+++ b/Src/Win32/DasherWindow.cpp
@@ -24,18 +24,12 @@
 #include "../DasherCore/ControlManager.h"
 #include "DasherWindow.h"
 #include "Widgets/AboutBox.h"
-#ifndef _WIN32_WCE
 #include "Widgets/Prefs.h"
-#endif
 
 #include "Widgets/Toolbar.h"
 #include "WinCommon.h"
 
-#ifndef _WIN32_WCE
 #include <Htmlhelp.h>
-#include <Oleacc.h>
-//#include <guiddef.h>
-#endif
 
 using namespace Dasher;
 using namespace std;
@@ -47,28 +41,27 @@ using namespace std;
 // required, look in version control history (prior to May 2007).
 
 CDasherWindow::CDasherWindow() {
+  m_bFullyCreated = false;
+  m_pAppSettings = 0;
   m_pToolbar = 0;
   m_pEdit = 0;
   m_pSpeedAlphabetBar = 0;
   m_pSplitter = 0;
   m_pDasher = 0;
 
-  m_hIconSm = (HICON) LoadImage(WinHelper::hInstApp, (LPCTSTR) IDI_DASHER, IMAGE_ICON, 
GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR);
-  
+  m_hIconSm = (HICON)LoadImage(WinHelper::hInstApp, (LPCTSTR)IDI_DASHER, IMAGE_ICON, 
GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR);
+
   ATL::CWndClassInfo& wc = CDasherWindow::GetWndClassInfo();
-  wc.m_wc.hIcon = LoadIcon(WinHelper::hInstApp, (LPCTSTR) IDI_DASHER);
+  wc.m_wc.hIcon = LoadIcon(WinHelper::hInstApp, (LPCTSTR)IDI_DASHER);
   wc.m_wc.hCursor = LoadCursor(NULL, IDC_ARROW);
-  wc.m_wc.hbrBackground = (HBRUSH) (COLOR_WINDOW); 
- #ifndef _WIN32_WCE
- // wc.m_wc.lpszMenuName = (LPCTSTR) IDC_DASHER;
+  wc.m_wc.hbrBackground = (HBRUSH)(COLOR_WINDOW);
   wc.m_wc.hIconSm = m_hIconSm;
-#endif
 
-  m_hMenu = LoadMenu(WinHelper::hInstApp, (LPCTSTR) IDC_DASHER);
+  m_hMenu = LoadMenu(WinHelper::hInstApp, (LPCTSTR)IDC_DASHER);
 }
 
 HWND CDasherWindow::Create() {
-  hAccelTable = LoadAccelerators(WinHelper::hInstApp, (LPCTSTR) IDC_DASHER);
+  hAccelTable = LoadAccelerators(WinHelper::hInstApp, (LPCTSTR)IDC_DASHER);
 
   // Get window title from resource script
   Tstring WindowTitle;
@@ -79,40 +72,28 @@ HWND CDasherWindow::Create() {
 
   HWND hWnd;
 
-#ifndef _WIN32_WCE
-  if((iStyle == APP_STYLE_COMPOSE) || (iStyle == APP_STYLE_DIRECT)) {
-    hWnd = CWindowImpl<CDasherWindow >::Create(NULL, NULL, WindowTitle.c_str(), WS_OVERLAPPEDWINDOW | 
WS_CLIPCHILDREN,  WS_EX_NOACTIVATE | WS_EX_APPWINDOW | WS_EX_TOPMOST);
+  if ((iStyle == APP_STYLE_COMPOSE) || (iStyle == APP_STYLE_DIRECT)) {
+    hWnd = CWindowImpl<CDasherWindow >::Create(NULL, NULL, WindowTitle.c_str(), WS_OVERLAPPEDWINDOW | 
WS_CLIPCHILDREN, WS_EX_NOACTIVATE | WS_EX_APPWINDOW | WS_EX_TOPMOST);
     ::SetMenu(hWnd, NULL);
   }
   else {
     hWnd = CWindowImpl<CDasherWindow >::Create(NULL, NULL, WindowTitle.c_str(), WS_OVERLAPPEDWINDOW | 
WS_CLIPCHILDREN);
     ::SetMenu(hWnd, m_hMenu);
   }
-#else
-  hWnd = CWindowImpl<CDasherWindow, CWindow, CWinTraits<WS_CLIPCHILDREN | WS_CLIPSIBLINGS> >::Create(NULL);
-#endif
 
   // Create Widgets
   m_pEdit = new CEdit(m_pAppSettings);
   m_pEdit->Create(hWnd, m_pAppSettings->GetBoolParameter(APP_BP_TIME_STAMP));
   m_pEdit->SetFont(m_pAppSettings->GetStringParameter(APP_SP_EDIT_FONT), 
m_pAppSettings->GetLongParameter(APP_LP_EDIT_FONT_SIZE));
- 
+
   m_pDasher = new CDasher(hWnd, this, m_pEdit);
 
   // Create a CAppSettings
   m_pAppSettings->SetHwnd(hWnd);
   m_pAppSettings->SetDasher(m_pDasher);
 
-#ifdef PJC_EXPERIMENTAL
-  g_hWnd = m_pEdit->GetHwnd();
-#endif
-
   m_pToolbar = new CToolbar(hWnd, m_pAppSettings->GetBoolParameter(APP_BP_SHOW_TOOLBAR));
 
-#ifdef _WIN32_WCE
-  m_pToolbar->ShowToolbar(false);
-#endif
-
   // FIXME - the edit box really shouldn't need access to the interface, 
   // but at the moment it does, for training, blanking the display etc
 
@@ -122,10 +103,9 @@ HWND CDasherWindow::Create() {
   m_pSpeedAlphabetBar->Create(hWnd);
 
   m_pSplitter = new CSplitter(this, 100);
-  HWND hSplitter =  m_pSplitter->Create(hWnd);
-  
-  if (!hSplitter)
-         return 0;
+  m_pSplitter->Create(hWnd);
+
+  m_bFullyCreated = true;
 
   return hWnd;
 }
@@ -135,69 +115,60 @@ CDasherWindow::~CDasherWindow() {
   delete m_pEdit;
   delete m_pSplitter;
   delete m_pDasher;
+  delete m_pSpeedAlphabetBar;
   delete m_pAppSettings;
 
   DestroyIcon(m_hIconSm);
 }
 
 void CDasherWindow::Show(int nCmdShow) {
-  InvalidateRect(NULL, FALSE);
-  
-  if(!LoadWindowState())
+  if (!LoadWindowState())
     ShowWindow(nCmdShow);
 }
 
 void CDasherWindow::SaveWindowState() const {
-#ifndef _WIN32_WCE
   WINDOWPLACEMENT wp;
   wp.length = sizeof(WINDOWPLACEMENT);
-  
-  if(GetWindowPlacement(&wp)) {//function call succeeds
+
+  if (GetWindowPlacement(&wp)) {//function call succeeds
     m_pAppSettings->SaveSetting("WindowState", &wp, m_pSplitter->GetPos());
   }
-
-#endif
 }
 
 bool CDasherWindow::LoadWindowState() {
-#ifndef _WIN32_WCE
   WINDOWPLACEMENT wp;
-  int splitterPos= -1;
-  if(m_pAppSettings->LoadSetting("WindowState", &wp, &splitterPos)) {
-         if (splitterPos != -1) {
-                 m_pSplitter->SetPos(splitterPos);
-         }
-         if(SetWindowPlacement(&wp))
+  int splitterPos = -1;
+  if (m_pAppSettings->LoadSetting("WindowState", &wp, &splitterPos)) {
+    if (splitterPos != -1) {
+      m_pSplitter->SetPos(splitterPos);
+    }
+    if (SetWindowPlacement(&wp))
       return true;
   }
-#endif
   return false;
 }
 
 void CDasherWindow::HandleParameterChange(int iParameter) {
-  switch(iParameter) {
-#ifndef _WIN32_WCE
-   case APP_BP_SHOW_TOOLBAR:
-     m_pToolbar->ShowToolbar(m_pAppSettings->GetBoolParameter(APP_BP_SHOW_TOOLBAR));
-     break;
-#endif
-   case APP_LP_STYLE:
-     // TODO: No longer handled after startup?
-     Layout();
-     break;
-   case APP_BP_TIME_STAMP:
-     // TODO: reimplement
-     // m_pEdit->TimeStampNewFiles(m_pAppSettings->GetBoolParameter(APP_BP_TIME_STAMP));
-     break;
+  switch (iParameter) {
+  case APP_BP_SHOW_TOOLBAR:
+    m_pToolbar->ShowToolbar(m_pAppSettings->GetBoolParameter(APP_BP_SHOW_TOOLBAR));
+    break;
+  case APP_LP_STYLE:
+    Layout();
+    break;
+  case APP_BP_TIME_STAMP:
+    // TODO: reimplement
+    // m_pEdit->TimeStampNewFiles(m_pAppSettings->GetBoolParameter(APP_BP_TIME_STAMP));
+    break;
   case LP_MAX_BITRATE:
     // TODO: reimplement
     break;
-// XXXPW
+    // XXXPW
 #if 0
   case BP_GAME_MODE: {
-         int iNewState(m_pDasher->GetBoolParameter(BP_GAME_MODE) ? MF_CHECKED : MF_UNCHECKED);
-         DWORD iPrevState = CheckMenuItem(m_hMenu, ID_GAMEMODE, MF_BYCOMMAND | iNewState);
-         DASHER_ASSERT( iPrevState != -1 ); //-1 = item does not exist (i.e. params to previous incorrect!)
+    int iNewState(m_pDasher->GetBoolParameter(BP_GAME_MODE) ? MF_CHECKED : MF_UNCHECKED);
+    DWORD iPrevState = CheckMenuItem(m_hMenu, ID_GAMEMODE, MF_BYCOMMAND | iNewState);
+    DASHER_ASSERT(iPrevState != -1); //-1 = item does not exist (i.e. params to previous incorrect!)
   }
 #endif
   default:
@@ -206,17 +177,23 @@ void CDasherWindow::HandleParameterChange(int iParameter) {
 }
 
 LRESULT CDasherWindow::OnCommand(UINT message, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
+  if (!m_bFullyCreated)
+  {
+    bHandled = FALSE;
+    return 0;
+  }
+
   const int wmId = LOWORD(wParam); //command id
   const int wmEvent = HIWORD(wParam); //notification code: 1=from accelerator, 0=from menu
   //lParam is the HWND (window handle) of control sending message, 0 if not from control
 
   // Tell edit box if it has changed. It should know itself really, but this is easier
   // This shouldn't be here - it should be in the edit box class
-  if( m_pEdit && ((HWND) lParam == m_pEdit->GetHwnd()) && (HIWORD(wParam) == EN_CHANGE)) {
+  if (((HWND)lParam == m_pEdit->GetHwnd()) && (HIWORD(wParam) == EN_CHANGE)) {
     m_pEdit->SetDirty();
     return 0;
   }
-  
+
   // Parse the menu selections:
   // TODO: Put these into separate functions
   switch (wmId) {
@@ -225,23 +202,19 @@ LRESULT CDasherWindow::OnCommand(UINT message, WPARAM wParam, LPARAM lParam, BOO
     Aboutbox.DoModal(m_hWnd);
     return 0;
   }
-#ifndef _WIN32_WCE
   case ID_OPTIONS_PREFS: {
     CPrefs Prefs(m_hWnd, m_pDasher, m_pAppSettings);
     return 0;
   }
-#endif
-#ifndef _WIN32_WCE
   case ID_HELP_CONTENTS:
     HtmlHelp(m_hWnd, L"Dasher.chm", HH_DISPLAY_INDEX, NULL);
     return 0;
-#endif
-// XXXPW
+    // XXXPW
 #if 0
   case ID_GAMEMODE: {
-         unsigned int checkState(GetMenuState(m_hMenu, ID_GAMEMODE, MF_BYCOMMAND));
-         DASHER_ASSERT(checkState==-1); //"specified item does not exist" - presumably, params to above 
aren't right...
-         m_pDasher->SetBoolParameter(BP_GAME_MODE, (checkState & MF_CHECKED) ? false : true);
+    unsigned int checkState(GetMenuState(m_hMenu, ID_GAMEMODE, MF_BYCOMMAND));
+    DASHER_ASSERT(checkState == -1); //"specified item does not exist" - presumably, params to above aren't 
right...
+    m_pDasher->SetBoolParameter(BP_GAME_MODE, (checkState & MF_CHECKED) ? false : true);
     return 0;
   }
 #endif
@@ -249,100 +222,93 @@ LRESULT CDasherWindow::OnCommand(UINT message, WPARAM wParam, LPARAM lParam, BOO
     DestroyWindow();
     return 0;
   case ID_EDIT_SELECTALL:
-    if(m_pEdit)
-      m_pEdit->SelectAll();
+    m_pEdit->SelectAll();
     return 0;
   case ID_EDIT_CUT:
-    if(m_pEdit)
-      m_pEdit->Cut();
+    m_pEdit->Cut();
     return 0;
   case ID_EDIT_COPY:
-    if(m_pEdit)
-      m_pEdit->Copy();
+    m_pEdit->Copy();
     return 0;
   case ID_EDIT_COPY_ALL:
-    if(m_pDasher)
-               m_pDasher->CopyToClipboard(m_pDasher->GetAllContext());
+    m_pDasher->CopyToClipboard(m_pDasher->GetAllContext());
     return 0;
   case ID_EDIT_PASTE:
-    if(m_pEdit)
-      m_pEdit->Paste();
+    m_pEdit->Paste();
     return 0;
-  case ID_FILE_NEW:
-    if(m_pEdit)
-      m_pEdit->New();
+  case ID_FILE_NEW:{
+    m_pEdit->New();
     // Selecting file->new indicates a new trial to our user logging object
-    if (m_pDasher != NULL) {
-      CUserLogBase* pUserLog = m_pDasher->GetUserLogPtr();
-      if (pUserLog != NULL)
-       pUserLog->NewTrial();
-      
-      m_pDasher->SetBuffer(0);
-    }
+    CUserLogBase* pUserLog = m_pDasher->GetUserLogPtr();
+    if (pUserLog != NULL)
+      pUserLog->NewTrial();
+    m_pDasher->SetBuffer(0);
     return 0;
+  }
   case ID_FILE_OPEN:
-    if(m_pEdit)
-      m_pEdit->Open();
+    m_pEdit->Open();
     return 0;
   case ID_FILE_SAVE:
-    if(m_pEdit)
-      if(!m_pEdit->Save())
-       m_pEdit->SaveAs();
+    if (!m_pEdit->Save())
+      m_pEdit->SaveAs();
     return 0;
   case ID_FILE_SAVE_AS:
-    if(m_pEdit)
-      m_pEdit->SaveAs();
+    m_pEdit->SaveAs();
     return 0;
   case ID_IMPORT_TRAINFILE:
     m_pDasher->ImportTrainingText(m_pEdit->Import());
     return 0;
   default:
-    return DefWindowProc(message, wParam, lParam);
+    bHandled = FALSE;
+    return 0;
   }
- 
-  Layout();
-  return 0;
 }
 
 LRESULT CDasherWindow::OnDasherFocus(UINT message, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
-       ::SetFocus(m_pEdit->GetHwnd());
+  if (!m_bFullyCreated)
+  {
+    bHandled = FALSE;
+    return 0;
+  }
+
+  ::SetFocus(m_pEdit->GetHwnd());
 
   // TODO: Is this obsolete?
   HWND *pHwnd((HWND *)lParam);
   m_pEdit->SetKeyboardTarget(*pHwnd);
-       return 0;
+  return 0;
 }
 
 LRESULT CDasherWindow::OnDestroy(UINT message, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
+  m_bFullyCreated = false;
   PostQuitMessage(0);
-       return 0;
+  return 0;
 }
 
-#ifndef _WIN32_WCE
 LRESULT CDasherWindow::OnGetMinMaxInfo(UINT message, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
-       // not yet created
-       if (m_pToolbar == 0 || m_pSplitter == 0 || m_pSpeedAlphabetBar == 0)
-               return 0;
-
-       bHandled = TRUE;
-       LPPOINT lppt;
-    lppt = (LPPOINT) lParam;    // lParam points to array of POINTs
-    lppt[3].x = 100;            // Set minimum width (arbitrary)
-    // Set minimum height:
-    if(m_pAppSettings->GetBoolParameter(APP_BP_SHOW_TOOLBAR))
-      lppt[3].y = m_pToolbar->GetHeight() + m_pSplitter->GetPos()
-        + m_pSplitter->GetHeight() + m_pSpeedAlphabetBar->GetHeight() + GetSystemMetrics(SM_CYEDGE) * 10;
-    else
-      lppt[3].y = m_pSplitter->GetPos()
-        + m_pSplitter->GetHeight() + m_pSpeedAlphabetBar->GetHeight() + GetSystemMetrics(SM_CYEDGE) * 10;
-
-       return 0;
+  if (!m_bFullyCreated)
+  {
+    bHandled = FALSE;
+    return 0;
+  }
+
+  LPPOINT lppt;
+  lppt = (LPPOINT)lParam;    // lParam points to array of POINTs
+  lppt[3].x = 100;            // Set minimum width (arbitrary)
+  // Set minimum height:
+  if (m_pAppSettings->GetBoolParameter(APP_BP_SHOW_TOOLBAR))
+    lppt[3].y = m_pToolbar->GetHeight() + m_pSplitter->GetPos()
+    + m_pSplitter->GetHeight() + m_pSpeedAlphabetBar->GetHeight() + GetSystemMetrics(SM_CYEDGE) * 10;
+  else
+    lppt[3].y = m_pSplitter->GetPos()
+    + m_pSplitter->GetHeight() + m_pSpeedAlphabetBar->GetHeight() + GetSystemMetrics(SM_CYEDGE) * 10;
+
+  return 0;
 }
-#endif
 
 LRESULT CDasherWindow::OnInitMenuPopup(UINT message, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
-       WinMenu.SortOut((HMENU) wParam);
-       return 0;
+  WinMenu.SortOut((HMENU)wParam);
+  return 0;
 }
 
 LRESULT CDasherWindow::OnClose(UINT message, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
@@ -353,137 +319,114 @@ LRESULT CDasherWindow::OnClose(UINT message, WPARAM wParam, LPARAM lParam, BOOL&
 }
 
 LRESULT CDasherWindow::OnSize(UINT message, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
-  if(wParam == SIZE_MINIMIZED)
+  if (wParam == SIZE_MINIMIZED)
     return 0;
 
-  if(m_pToolbar)
-    m_pToolbar->Resize();
+  if (!m_bFullyCreated)
+    return 0;
 
+  m_pToolbar->Resize();
   Layout();
-  
   return 0;
 }
 
 
 LRESULT CDasherWindow::OnSetFocus(UINT message, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
+  if (!m_bFullyCreated)
+    return 0;
+
   m_pDasher->TakeFocus();
   return 0;
 }
 
 LRESULT CDasherWindow::OnOther(UINT message, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
-       // A switch statement would be preferable, except the message ids are
+  if (!m_bFullyCreated)
+    return 0;
+
+  // A switch statement would be preferable, except the message ids are
   // not constant-expressions since they are provided by the system at
   // runtime.
   if (message == WM_DASHER_FOCUS)
     return OnDasherFocus(message, wParam, lParam, bHandled);
   else if (message == DASHER_SHOW_PREFS) {
-#ifndef _WIN32_WCE
     CPrefs Prefs(m_hWnd, m_pDasher, m_pAppSettings);
-#endif
   }
-  
+
   return 0;
 }
 
 void CDasherWindow::Layout() {
+  if (!m_bFullyCreated)
+    return;
+
   int iStyle(m_pAppSettings->GetLongParameter(APP_LP_STYLE));
-  
+
   // Set up the window properties
-#ifndef _WIN32_WCE
-  if((iStyle == APP_STYLE_COMPOSE) || (iStyle == APP_STYLE_DIRECT)) {
+  if ((iStyle == APP_STYLE_COMPOSE) || (iStyle == APP_STYLE_DIRECT)) {
     SetWindowLong(GWL_EXSTYLE, GetWindowLong(GWL_EXSTYLE) | WS_EX_NOACTIVATE | WS_EX_APPWINDOW);
     SetWindowPos(HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
-       SetMenu(NULL);
+    SetMenu(NULL);
   }
   else {
     SetWindowLong(GWL_EXSTYLE, GetWindowLong(GWL_EXSTYLE) & !WS_EX_NOACTIVATE);
     SetWindowPos(HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
-       SetMenu(m_hMenu);
+    SetMenu(m_hMenu);
   }
-#endif
 
   // Now do the actual layout
-
-  bool bHorizontal(iStyle == APP_STYLE_COMPOSE); 
-  bool bShowEdit(iStyle != APP_STYLE_DIRECT);
-
-  // Get the width of the window
   RECT ClientRect;
-  GetClientRect( &ClientRect);
+  GetClientRect(&ClientRect);
   const int Width = ClientRect.right;
   const int Height = ClientRect.bottom;
 
-  // Get the height of the toolbar widget
-  int ToolbarHeight;
-  if(m_pToolbar && m_pAppSettings->GetBoolParameter(APP_BP_SHOW_TOOLBAR))
-    ToolbarHeight = m_pToolbar->GetHeight();
-  else
-    ToolbarHeight = 0;
+  int ToolbarHeight = m_pAppSettings->GetBoolParameter(APP_BP_SHOW_TOOLBAR) ? m_pToolbar->GetHeight() : 0;
 
-  // Get the height of the control bar at the bottom of the screen
-  int SpeedAlphabetHeight;
-  if(m_pSpeedAlphabetBar != 0)
-    SpeedAlphabetHeight = m_pSpeedAlphabetBar->GetHeight();
-  else
-    SpeedAlphabetHeight = 0;
+  int SpeedAlphabetHeight = m_pSpeedAlphabetBar->GetHeight();
+  m_pSpeedAlphabetBar->MoveWindow(0, Height - SpeedAlphabetHeight, Width, SpeedAlphabetHeight);
 
-  int MaxCanvas = Height - SpeedAlphabetHeight*2;
-  int CurY = ToolbarHeight;
+  int CanvasY = ToolbarHeight;
+  int CanvasHeight = Height - SpeedAlphabetHeight - CanvasY;
 
-  if(m_pSplitter) {
-    int SplitterPos = m_pSplitter->GetPos();
-    int SplitterHeight = m_pSplitter->GetHeight();
-    //SplitterPos = max(CurY + 2 * SplitterHeight, SplitterPos);
-    SplitterPos = max(CurY, SplitterPos);
-    SplitterPos = min(SplitterPos, MaxCanvas - 3 * SplitterHeight);
-    m_pSplitter->Move(SplitterPos, Width);
+  switch (iStyle)
+  {
+  case APP_STYLE_DIRECT:
+    m_pDasher->Move(0, CanvasY, Width, CanvasHeight);
+    m_pEdit->ShowWindow(SW_HIDE);
+    m_pSplitter->ShowWindow(SW_HIDE);
+    break;
 
-    if(bHorizontal) {
-      if(m_pDasher)
-        m_pDasher->Move(0, CurY, Width / 2, MaxCanvas - CurY);
+  case APP_STYLE_COMPOSE:
+    m_pDasher->Move(0, CanvasY, Width / 2, CanvasHeight);
+    m_pEdit->Move(Width / 2, CanvasY, Width - Width / 2, CanvasHeight);
+    m_pEdit->ShowWindow(SW_SHOW);
+    m_pSplitter->ShowWindow(SW_HIDE);
+    break;
 
-      if(m_pEdit)
-        m_pEdit->Move(Width / 2, CurY, Width / 2, MaxCanvas - CurY);
-    }
-    else {
-      if(bShowEdit) {
-        m_pEdit->ShowWindow(SW_SHOW);
-        m_pSplitter->ShowWindow(SW_SHOW);
-
-        if(m_pEdit)
-        {
-          //m_pEdit->Move(2, CurY+2, Width, SplitterPos - CurY-2);
-          m_pEdit->Move(0, CurY, Width, SplitterPos - CurY);
-        }
-
-        CurY = SplitterPos + SplitterHeight;
-      }
-      else {
-        m_pEdit->ShowWindow(SW_HIDE);
-        m_pSplitter->ShowWindow(SW_HIDE);
-      }
-
-      int CanvasHeight = Height - CurY - SpeedAlphabetHeight ;
-      //- GetSystemMetrics(SM_CYEDGE);
-      
-      // Put the DasherControl in the correct place...
-      if(m_pDasher)
-        m_pDasher->Move(0, CurY, Width, CanvasHeight-5);
-        //m_pDasher->Move(2, CurY+2, Width-4, CanvasHeight-2);
-      
-      // ...with the bottom bar just below it.
-      if(m_pSpeedAlphabetBar)
-        m_pSpeedAlphabetBar->MoveWindow(0, Height - SpeedAlphabetHeight, Width, SpeedAlphabetHeight);
-    }
+  default:
+    int SplitterHeight = m_pSplitter->GetHeight();
+    int MinEditHeight = 3 * SplitterHeight;
+    int MinDasherHeight = 3 * SplitterHeight;
+    int SplitterY = max(CanvasY + MinEditHeight, m_pSplitter->GetPos());
+    SplitterY = min(SplitterY, CanvasHeight - MinDasherHeight - SplitterHeight);
+    int EditHeight = SplitterY - CanvasY;
+    int DasherY = SplitterY + SplitterHeight;
+
+    m_pEdit->Move(0, CanvasY, Width, EditHeight);
+    m_pSplitter->Move(SplitterY, Width);
+    m_pDasher->Move(0, DasherY, Width, CanvasHeight - EditHeight - SplitterHeight);
+    m_pEdit->ShowWindow(SW_SHOW);
+    m_pSplitter->ShowWindow(SW_SHOW);
   }
 }
 
 void CDasherWindow::HandleWinEvent(HWINEVENTHOOK hWinEventHook, DWORD event, HWND hwnd, LONG idObject, LONG 
idChild, DWORD dwEventThread, DWORD dwmsEventTime) {
+  if (!m_bFullyCreated)
+    return;
+
   // Ignore events if not in direct mode
-  if(m_pAppSettings && (m_pAppSettings->GetLongParameter(APP_LP_STYLE) != APP_STYLE_DIRECT))
+  if (m_pAppSettings->GetLongParameter(APP_LP_STYLE) != APP_STYLE_DIRECT)
     return;
 
   // For now assume all events are focus changes, so reset the buffer
-  if(m_pDasher)
-    m_pDasher->SetBuffer(0);
+  m_pDasher->SetBuffer(0);
 }
diff --git a/Src/Win32/DasherWindow.h b/Src/Win32/DasherWindow.h
index 33b2469..979b038 100644
--- a/Src/Win32/DasherWindow.h
+++ b/Src/Win32/DasherWindow.h
@@ -29,20 +29,11 @@ namespace Dasher {
 // Abstract interfaces to the Dasher engine
 #include "../../DasherCore/DasherInterfaceBase.h"
 
-#ifdef _WIN32_WCE
-class CDasherWindow : 
-       public ATL::CWindowImpl<CDasherWindow, CWindow, CWinTraits< WS_CLIPCHILDREN | WS_CLIPSIBLINGS> >, 
-       public CSplitterOwner 
-{
-#else
 class CDasherWindow : 
        public ATL::CWindowImpl<CDasherWindow>, 
        public CSplitterOwner 
 {
-#endif
 public:
-//, CWindow, CFrameWinTraits>, 
-
        CDasherWindow();
        ~CDasherWindow();
 
@@ -53,9 +44,7 @@ public:
                MESSAGE_HANDLER(WM_COMMAND, OnCommand)
                MESSAGE_HANDLER(WM_CLOSE, OnClose)
                MESSAGE_HANDLER(WM_SIZE, OnSize)
-#ifndef _WIN32_WCE
                MESSAGE_HANDLER(WM_GETMINMAXINFO,OnGetMinMaxInfo)
-#endif
                MESSAGE_HANDLER(WM_INITMENUPOPUP,OnInitMenuPopup)
                MESSAGE_HANDLER(WM_SETFOCUS,OnSetFocus)
                MESSAGE_RANGE_HANDLER(0xC000,0xFFFF,OnOther)
@@ -63,9 +52,7 @@ public:
 
        LRESULT OnSetFocus(UINT message, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
        LRESULT OnInitMenuPopup(UINT message, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
-#ifndef _WIN32_WCE
        LRESULT OnGetMinMaxInfo(UINT message, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
-#endif
        LRESULT OnOther(UINT message, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
        LRESULT OnDasherFocus(UINT message, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
        LRESULT OnSize(UINT message, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
@@ -92,6 +79,7 @@ private:
        void SaveWindowState() const;
        bool LoadWindowState();
 
+  bool m_bFullyCreated;
        Dasher::CDasher *m_pDasher;
 
        HACCEL hAccelTable;
@@ -111,10 +99,6 @@ private:
 
        HMENU m_hMenu;
 
-       LPCWSTR AutoOffset;
-       LPCWSTR DialogCaption;
-       char tmpAutoOffset[25];
-
        // Misc window handling
        void Layout();
 };


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