]> icculus.org git repositories - icculus/iodoom3.git/blob - neo/tools/common/DialogHelpers.h
hello world
[icculus/iodoom3.git] / neo / tools / common / DialogHelpers.h
1 /*
2 ===========================================================================
3
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company. 
6
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).  
8
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code.  If not, see <http://www.gnu.org/licenses/>.
21
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code.  If not, please request a copy in writing from id Software at the address below.
23
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25
26 ===========================================================================
27 */
28
29 #ifndef DIALOGHELPERS_H_
30 #define DIALOGHELPERS_H_
31
32 class rvDialogItem
33 {
34 public:
35
36         HWND    mWindow;
37         int             mID;
38         
39         rvDialogItem ( int id ) { mID = id; }
40         
41         void Cache ( HWND parent )
42         {
43                 mWindow = GetDlgItem ( parent, mID );
44         }
45         
46         void Check ( bool checked )
47         {
48                 SendMessage ( mWindow, BM_SETCHECK, checked ? BST_CHECKED : BST_UNCHECKED, 0 );
49         }
50         
51         void Enable ( bool enable )
52         {
53                 EnableWindow ( mWindow, enable );
54         }
55         
56         bool IsChecked ( void )
57         {
58                 return SendMessage ( mWindow, BM_GETCHECK, 0, 0 ) == BST_CHECKED ? true : false;
59         }
60         
61         void SetText ( const char* text )
62         {
63                 SetWindowText ( mWindow, text );
64         }
65         
66         void GetText ( idStr& out )
67         {
68                 char text[4096];
69                 GetWindowText ( mWindow, text, 4095 );
70                 out = text;
71         }
72         
73         float GetFloat ( void )
74         {
75                 idStr text;
76                 GetText ( text );
77                 return atof( text );
78         }
79         
80         void SetFloat ( float f )
81         {
82                 SetText ( va("%g", f ) );
83         }
84         
85         operator HWND( void ) const { return mWindow; }
86 };
87
88 class rvDialogItemContainer
89 {
90 protected:
91         
92         void Cache ( HWND parent, int count )
93         {
94                 int                             i;
95                 unsigned char*  ptr;
96                 
97                 ptr = (unsigned char*)this;
98                 for ( i = 0; i < count; i ++, ptr += sizeof(rvDialogItem) )
99                 {
100                         ((rvDialogItem*)ptr)->Cache ( parent );                 
101                 }
102         }
103 };
104
105 #define DIALOGITEM_BEGIN(name)                                                                  \
106 class name : public rvDialogItemContainer                                               \
107 {                                                                                                                               \
108 public:                                                                                                                 \
109         name ( void ) { }                                                                                       \
110         name ( HWND hwnd ) { Cache ( hwnd ); }                                          \
111         void Cache ( HWND parent )                                                                      \
112         {                                                                                                                       \
113                 rvDialogItemContainer::Cache ( parent, sizeof(*this)/sizeof(rvDialogItem) );    \
114         }
115
116
117 #define DIALOGITEM(id,name)                                                                             \
118 class c##name : public rvDialogItem                                                             \
119 {                                                                                                                               \
120 public:                                                                                                                 \
121         c##name(int localid=id) : rvDialogItem ( localid ) { }          \
122 } name;                                                                                                                 
123
124 #define DIALOGITEM_END()                                                                                \
125 };
126
127
128 #endif // DIALOGHELPERS_H_