sprint 1-alpha
|
00001 /****************************************************************************** 00002 * GTL: GUI Template Library 00003 * A Cross Platform C++ Wrapper for Win32 users 00004 * Copyright (C) 2007-2011 Paolo Medici (www.pmx.it) 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with this library; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00019 * 00020 *******************************************************************************/ 00021 00022 #ifndef _SPRINT_DIALOG_H 00023 #define _SPRINT_DIALOG_H 00024 00028 #include <windows.h> 00029 #include <sprint/gtl/window.h> 00030 #include <sprint/log.h> 00031 00032 namespace sprint { 00033 namespace gtl { 00034 00037 template<class T> 00038 INT_PTR CALLBACK DlgProc( 00039 HWND hwndDlg, 00040 UINT uMsg, 00041 WPARAM wParam, 00042 LPARAM lParam 00043 ); 00044 00049 class CDialog: public CWindow { 00050 public: 00051 00052 typedef CDialog parent; 00053 00054 void OnInitDialog() { } 00055 void OnCommand(int cmd, int notify) { if(cmd==IDOK) ::EndDialog(m_hwnd, TRUE); } 00056 void OnNotify(const LPNMHDR nmhr) { } 00057 void OnClose(INT_PTR ret=0) { ::EndDialog(m_hwnd, ret); m_hwnd = NULL; } 00058 void OnDestroy() { m_hwnd = NULL; } 00059 00060 /* 00061 void OnMeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct) { } 00062 void OnDrawItem(const DRAWITEMSTRUCT & di) { } 00063 */ 00064 00066 template<class T> 00067 HWND ModelessTDialog(LPCTSTR lpTemplate, T * inst) 00068 { 00069 return ::CreateDialogParam(GetModuleHandle(NULL), lpTemplate, m_hwnd, &DlgProc<T>, reinterpret_cast<LPARAM>(inst) ); 00070 } 00071 00073 template<class T> 00074 INT_PTR ModalTDialog( 00075 LPCTSTR lpTemplate, 00076 const T & inst = T() ) 00077 { 00078 return ::DialogBoxParam(GetModuleHandle(NULL), lpTemplate, m_hwnd, &DlgProc<T>, reinterpret_cast<LPARAM>(&inst) ); 00079 } 00080 00082 inline 00083 INT_PTR CreateDialogBox(LPCTSTR lpTemplate) 00084 { 00085 return ModalTDialog(lpTemplate, *this); 00086 } 00087 00088 }; 00089 00090 00091 class CModelessDialog : public CDialog { 00092 public: 00093 00094 typedef CModelessDialog parent; 00095 00096 void OnCommand(int cmd, int notify) { if(cmd==IDOK) ::DestroyWindow(m_hwnd); } 00097 void OnClose() { ::DestroyWindow(m_hwnd); } 00098 00099 }; 00100 00102 template<class T> 00103 INT_PTR CALLBACK DlgProc( 00104 HWND hwndDlg, 00105 UINT uMsg, 00106 WPARAM wParam, 00107 LPARAM lParam 00108 ) 00109 { 00110 switch(uMsg) 00111 { 00112 case WM_INITDIALOG: 00113 SetWindowLong(hwndDlg, DWL_USER, lParam); 00114 reinterpret_cast<T*>(lParam)->SetHwnd(hwndDlg); 00115 reinterpret_cast<T*>(lParam)->OnInitDialog(); 00116 return TRUE; 00117 case WM_NOTIFY: 00118 reinterpret_cast<T*>(GetWindowLong(hwndDlg, DWL_USER))->OnNotify( reinterpret_cast<LPNMHDR>(lParam) ); 00119 return TRUE; 00120 case WM_COMMAND: 00121 reinterpret_cast<T*>(GetWindowLong(hwndDlg, DWL_USER))->OnCommand(LOWORD(wParam), HIWORD(wParam)); 00122 return TRUE; 00123 /* 00124 case WM_DRAWITEM: 00125 reinterpret_cast<T*>(GetWindowLong(hwndDlg, DWL_USER))->OnDrawItem(*(LPDRAWITEMSTRUCT)lParam ); 00126 return TRUE; 00127 case WM_MEASUREITEM: 00128 reinterpret_cast<T*>(GetWindowLong(hwndDlg, DWL_USER))->OnDrawItem( (LPMEASUREITEMSTRUCT)lParam ); 00129 return TRUE; 00130 */ 00131 case WM_CLOSE: 00132 reinterpret_cast<T*>(GetWindowLong(hwndDlg, DWL_USER))->OnClose(); 00133 return TRUE; 00134 case WM_DESTROY: 00135 reinterpret_cast<T*>(GetWindowLong(hwndDlg, DWL_USER))->OnDestroy(); 00136 return TRUE; 00137 00138 /* case WM_GETDLGCODE: 00139 return DLGC_WANTALLKEYS; */ 00140 default: 00141 return FALSE; 00142 } 00143 } 00144 00146 template<class T> 00147 INT_PTR TDialogBox(LPCTSTR lpTemplate, 00148 HWND hWndParent, 00149 const T & inst = T()) 00150 { 00151 return DialogBoxParam(GetModuleHandle(NULL), lpTemplate, hWndParent, &DlgProc<T>, reinterpret_cast<LPARAM>(&inst) ); 00152 } 00153 00155 template<class T> 00156 INT_PTR CreateTDialog(LPCTSTR lpTemplate, 00157 HWND hWndParent, 00158 T * inst) 00159 { 00160 return CreateDialogParam(GetModuleHandle(NULL), lpTemplate, hWndParent, &DlgProc<T>, reinterpret_cast<LPARAM>(&inst) ); 00161 } 00162 00163 } 00164 00165 } 00166 00167 #endif