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

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

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

mercurial