1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/other-licenses/7zstub/src/Windows/Control/Dialog.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,145 @@ 1.4 +// Windows/Control/Dialog.cpp 1.5 + 1.6 +#include "StdAfx.h" 1.7 + 1.8 +#ifndef _UNICODE 1.9 +#include "Common/StringConvert.h" 1.10 +#endif 1.11 +#include "Windows/Control/Dialog.h" 1.12 + 1.13 +extern HINSTANCE g_hInstance; 1.14 +#ifndef _UNICODE 1.15 +extern bool g_IsNT; 1.16 +#endif 1.17 + 1.18 +namespace NWindows { 1.19 +namespace NControl { 1.20 + 1.21 +static INT_PTR APIENTRY DialogProcedure(HWND dialogHWND, UINT message, 1.22 + WPARAM wParam, LPARAM lParam) 1.23 +{ 1.24 + CWindow dialogTmp(dialogHWND); 1.25 + if (message == WM_INITDIALOG) 1.26 + dialogTmp.SetUserDataLongPtr(lParam); 1.27 + CDialog *dialog = (CDialog *)(dialogTmp.GetUserDataLongPtr()); 1.28 + if (dialog == NULL) 1.29 + return FALSE; 1.30 + if (message == WM_INITDIALOG) 1.31 + dialog->Attach(dialogHWND); 1.32 + 1.33 + return BoolToBOOL(dialog->OnMessage(message, wParam, lParam)); 1.34 +} 1.35 + 1.36 +bool CDialog::OnMessage(UINT message, WPARAM wParam, LPARAM lParam) 1.37 +{ 1.38 + switch (message) 1.39 + { 1.40 + case WM_INITDIALOG: 1.41 + return OnInit(); 1.42 + case WM_COMMAND: 1.43 + return OnCommand(wParam, lParam); 1.44 + case WM_NOTIFY: 1.45 + return OnNotify(wParam, (LPNMHDR) lParam); 1.46 + case WM_HELP: 1.47 + { 1.48 + OnHelp((LPHELPINFO)lParam); 1.49 + return true; 1.50 + } 1.51 + case WM_TIMER: 1.52 + { 1.53 + return OnTimer(wParam, lParam); 1.54 + } 1.55 + default: 1.56 + return false; 1.57 + } 1.58 +} 1.59 + 1.60 +bool CDialog::OnCommand(WPARAM wParam, LPARAM lParam) 1.61 +{ 1.62 + return OnCommand(HIWORD(wParam), LOWORD(wParam), lParam); 1.63 +} 1.64 + 1.65 +bool CDialog::OnCommand(int code, int itemID, LPARAM lParam) 1.66 +{ 1.67 + if (code == BN_CLICKED) 1.68 + return OnButtonClicked(itemID, (HWND)lParam); 1.69 + return false; 1.70 +} 1.71 + 1.72 +bool CDialog::OnButtonClicked(int buttonID, HWND buttonHWND) 1.73 +{ 1.74 + switch(buttonID) 1.75 + { 1.76 + case IDOK: 1.77 + OnOK(); 1.78 + break; 1.79 + case IDCANCEL: 1.80 + OnCancel(); 1.81 + break; 1.82 + case IDHELP: 1.83 + OnHelp(); 1.84 + break; 1.85 + default: 1.86 + return false; 1.87 + } 1.88 + return true; 1.89 +} 1.90 + 1.91 +bool CModelessDialog::Create(LPCTSTR templateName, HWND parentWindow) 1.92 +{ 1.93 + HWND aHWND = CreateDialogParam(g_hInstance, templateName, parentWindow, DialogProcedure, (LPARAM)this); 1.94 + if (aHWND == 0) 1.95 + return false; 1.96 + Attach(aHWND); 1.97 + return true; 1.98 +} 1.99 + 1.100 +INT_PTR CModalDialog::Create(LPCTSTR templateName, HWND parentWindow) 1.101 +{ 1.102 + return DialogBoxParam(g_hInstance, templateName, parentWindow, DialogProcedure, (LPARAM)this); 1.103 +} 1.104 + 1.105 +#ifndef _UNICODE 1.106 + 1.107 +bool CModelessDialog::Create(LPCWSTR templateName, HWND parentWindow) 1.108 +{ 1.109 + HWND aHWND; 1.110 + if (g_IsNT) 1.111 + aHWND = CreateDialogParamW(g_hInstance, templateName, parentWindow, DialogProcedure, (LPARAM)this); 1.112 + else 1.113 + { 1.114 + AString name; 1.115 + LPCSTR templateNameA; 1.116 + if (IS_INTRESOURCE(templateName)) 1.117 + templateNameA = (LPCSTR)templateName; 1.118 + else 1.119 + { 1.120 + name = GetSystemString(templateName); 1.121 + templateNameA = name; 1.122 + } 1.123 + aHWND = CreateDialogParamA(g_hInstance, templateNameA, parentWindow, DialogProcedure, (LPARAM)this); 1.124 + } 1.125 + if (aHWND == 0) 1.126 + return false; 1.127 + Attach(aHWND); 1.128 + return true; 1.129 +} 1.130 + 1.131 +INT_PTR CModalDialog::Create(LPCWSTR templateName, HWND parentWindow) 1.132 +{ 1.133 + if (g_IsNT) 1.134 + return DialogBoxParamW(g_hInstance, templateName, parentWindow, DialogProcedure, (LPARAM)this); 1.135 + AString name; 1.136 + LPCSTR templateNameA; 1.137 + if (IS_INTRESOURCE(templateName)) 1.138 + templateNameA = (LPCSTR)templateName; 1.139 + else 1.140 + { 1.141 + name = GetSystemString(templateName); 1.142 + templateNameA = name; 1.143 + } 1.144 + return DialogBoxParamA(g_hInstance, templateNameA, parentWindow, DialogProcedure, (LPARAM)this); 1.145 +} 1.146 +#endif 1.147 + 1.148 +}}