other-licenses/7zstub/src/Windows/Control/Dialog.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 // Windows/Control/Dialog.cpp
     3 #include "StdAfx.h"
     5 #ifndef _UNICODE
     6 #include "Common/StringConvert.h"
     7 #endif
     8 #include "Windows/Control/Dialog.h"
    10 extern HINSTANCE g_hInstance;
    11 #ifndef _UNICODE
    12 extern bool g_IsNT;
    13 #endif
    15 namespace NWindows {
    16 namespace NControl {
    18 static INT_PTR APIENTRY DialogProcedure(HWND dialogHWND, UINT message, 
    19     WPARAM wParam, LPARAM lParam)
    20 {
    21   CWindow dialogTmp(dialogHWND);
    22   if (message == WM_INITDIALOG)
    23     dialogTmp.SetUserDataLongPtr(lParam);
    24   CDialog *dialog = (CDialog *)(dialogTmp.GetUserDataLongPtr());
    25   if (dialog == NULL)
    26     return FALSE;
    27   if (message == WM_INITDIALOG)
    28     dialog->Attach(dialogHWND);
    30   return BoolToBOOL(dialog->OnMessage(message, wParam, lParam));
    31 }
    33 bool CDialog::OnMessage(UINT message, WPARAM wParam, LPARAM lParam)
    34 {
    35   switch (message)
    36   {
    37     case WM_INITDIALOG:
    38       return OnInit();
    39     case WM_COMMAND:
    40       return OnCommand(wParam, lParam);
    41     case WM_NOTIFY:
    42       return OnNotify(wParam, (LPNMHDR) lParam);
    43     case WM_HELP:
    44       {
    45         OnHelp((LPHELPINFO)lParam);
    46         return true;
    47       }
    48     case WM_TIMER:
    49       {
    50         return OnTimer(wParam, lParam);
    51       }
    52     default:
    53       return false;
    54   }
    55 }
    57 bool CDialog::OnCommand(WPARAM wParam, LPARAM lParam) 
    58 { 
    59   return OnCommand(HIWORD(wParam), LOWORD(wParam), lParam);
    60 }
    62 bool CDialog::OnCommand(int code, int itemID, LPARAM lParam)
    63 {
    64   if (code == BN_CLICKED)
    65     return OnButtonClicked(itemID, (HWND)lParam);
    66   return false; 
    67 }
    69 bool CDialog::OnButtonClicked(int buttonID, HWND buttonHWND) 
    70 { 
    71   switch(buttonID)
    72   {
    73     case IDOK:
    74       OnOK();
    75       break;
    76     case IDCANCEL:
    77       OnCancel();
    78       break;
    79     case IDHELP:
    80       OnHelp();
    81       break;
    82     default:
    83       return false;
    84   }
    85   return true;
    86 }
    88 bool CModelessDialog::Create(LPCTSTR templateName, HWND parentWindow)
    89 { 
    90   HWND aHWND = CreateDialogParam(g_hInstance, templateName, parentWindow, DialogProcedure, (LPARAM)this);
    91   if (aHWND == 0)
    92     return false;
    93   Attach(aHWND);
    94   return true;
    95 }
    97 INT_PTR CModalDialog::Create(LPCTSTR templateName, HWND parentWindow)
    98 { 
    99   return DialogBoxParam(g_hInstance, templateName, parentWindow, DialogProcedure, (LPARAM)this);
   100 }
   102 #ifndef _UNICODE
   104 bool CModelessDialog::Create(LPCWSTR templateName, HWND parentWindow)
   105 { 
   106   HWND aHWND;
   107   if (g_IsNT)
   108     aHWND = CreateDialogParamW(g_hInstance, templateName, parentWindow, DialogProcedure, (LPARAM)this);
   109   else
   110   {
   111     AString name;
   112     LPCSTR templateNameA;
   113     if (IS_INTRESOURCE(templateName))
   114       templateNameA = (LPCSTR)templateName;
   115     else
   116     {
   117       name = GetSystemString(templateName);
   118       templateNameA = name;
   119     }
   120     aHWND = CreateDialogParamA(g_hInstance, templateNameA, parentWindow, DialogProcedure, (LPARAM)this);
   121   }
   122   if (aHWND == 0)
   123     return false;
   124   Attach(aHWND);
   125   return true;
   126 }
   128 INT_PTR CModalDialog::Create(LPCWSTR templateName, HWND parentWindow)
   129 { 
   130   if (g_IsNT)
   131     return DialogBoxParamW(g_hInstance, templateName, parentWindow, DialogProcedure, (LPARAM)this);
   132   AString name;
   133   LPCSTR templateNameA;
   134   if (IS_INTRESOURCE(templateName))
   135     templateNameA = (LPCSTR)templateName;
   136   else
   137   {
   138     name = GetSystemString(templateName);
   139     templateNameA = name;
   140   }
   141   return DialogBoxParamA(g_hInstance, templateNameA, parentWindow, DialogProcedure, (LPARAM)this);
   142 }
   143 #endif 
   145 }}

mercurial