]> icculus.org git repositories - icculus/iodoom3.git/blob - neo/tools/guied/GEItemPropsDlg.cpp
hello world
[icculus/iodoom3.git] / neo / tools / guied / GEItemPropsDlg.cpp
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 #include "../../idlib/precompiled.h"
30 #pragma hdrstop
31
32 #include "../../sys/win32/rc/guied_resource.h"
33 #include "../common/ColorButton.h"
34 #include "../common/MaskEdit.h"
35
36 #include "GEApp.h"
37 #include "GEItemPropsDlg.h"
38 #include "GEPropertyPage.h"
39
40 enum
41 {       
42         RVITEMPROPS_GENERAL = 0,
43         RVITEMPROPS_IMAGE,
44         RVITEMPROPS_TEXT,
45         RVITEMPROPS_KEYS,
46         
47         RVITEMPROPS_MAX
48 };      
49
50 class rvGEItemPropsImagePage : public rvGEPropertyPage 
51 {
52 public:
53
54         rvGEItemPropsImagePage ( idDict* dictValues );
55         
56         virtual bool    Init                    ( void );
57         virtual bool    SetActive               ( void );
58         virtual bool    KillActive              ( void );
59         virtual int             HandleMessage   ( UINT msg, WPARAM wParam, LPARAM lParam );
60
61 protected:
62
63         void                    UpdateCheckedStates             ( void );
64
65         idDict*         mDict;
66 };      
67
68 rvGEItemPropsImagePage::rvGEItemPropsImagePage ( idDict* dict )
69 {
70         mDict = dict;
71 }
72
73 /*
74 ================
75 rvGEItemPropsImagePage::Init
76
77 Subclass the custom controls on the page
78 ================
79 */
80 bool rvGEItemPropsImagePage::Init ( void )
81 {
82         NumberEdit_Attach ( GetDlgItem ( mPage, IDC_GUIED_ITEMMATSCALEX ) );
83         NumberEdit_Attach ( GetDlgItem ( mPage, IDC_GUIED_ITEMMATSCALEY ) );
84         NumberEdit_Attach ( GetDlgItem ( mPage, IDC_GUIED_ITEMBORDERSIZE ) );
85         
86         return true;
87 }
88
89 /*
90 ================
91 rvGEItemPropsImagePage::UpdateCheckedStates
92
93 Updates the enabled state of all the controls that are linked to a checkbox
94 ================
95 */
96 void rvGEItemPropsImagePage::UpdateCheckedStates ( void )
97 {
98         char temp[64];
99         bool state;
100         bool rstate;
101         idStr result;
102         bool  enable;
103
104         enable = !IsExpression ( mDict->GetString ( "backcolor", "1,1,1,1" ) );
105         EnableWindow ( GetDlgItem ( mPage, IDC_GUIED_USEBACKCOLOR ), enable );  
106
107         state = IsDlgButtonChecked ( mPage, IDC_GUIED_USEBACKCOLOR ) && IsWindowEnabled ( GetDlgItem ( mPage, IDC_GUIED_USEBACKCOLOR ) );
108         EnableWindow ( GetDlgItem ( mPage, IDC_GUIED_ITEMBACKCOLOR ), state );
109         EnableWindow ( GetDlgItem ( mPage, IDC_GUIED_ITEMBACKCOLORALPHA ), state );
110         
111         state = IsDlgButtonChecked ( mPage, IDC_GUIED_USEMATERIAL) != 0;
112         EnableWindow ( GetDlgItem ( mPage, IDC_GUIED_ITEMBACKGROUND ), state );
113         EnableWindow ( GetDlgItem ( mPage, IDC_GUIED_ITEMVARIABLEBACKGROUND ), state );
114         EnableWindow ( GetDlgItem ( mPage, IDC_GUIED_ITEMMATSCALEX ), state );
115         EnableWindow ( GetDlgItem ( mPage, IDC_GUIED_ITEMMATSCALEY ), state );
116         EnableWindow ( GetDlgItem ( mPage, IDC_GUIED_XSCALE_STATIC), state );
117         EnableWindow ( GetDlgItem ( mPage, IDC_GUIED_YSCALE_STATIC), state );
118
119         GetWindowText ( GetDlgItem ( mPage, IDC_GUIED_ITEMBORDERSIZE ), temp, 64 );
120         enable = !IsExpression ( mDict->GetString ( "bordersize", "0" ) );
121         EnableWindow ( GetDlgItem ( mPage, IDC_GUIED_ITEMBORDERSIZE ), enable );
122         
123         state = atol( temp ) ? true : false;
124         rstate = IsDlgButtonChecked ( mPage, IDC_GUIED_USEBORDERCOLOR ) != 0;
125         enable = !IsExpression ( mDict->GetString ( "bordercolor", "1,1,1,1" ) );
126         EnableWindow ( GetDlgItem ( mPage, IDC_GUIED_USEBORDERCOLOR ), state && enable );
127         EnableWindow ( GetDlgItem ( mPage, IDC_GUIED_USEBORDERMATERIAL ), state && enable);
128         EnableWindow ( GetDlgItem ( mPage, IDC_GUIED_ITEMBORDERCOLOR ), rstate && state && enable);
129         EnableWindow ( GetDlgItem ( mPage, IDC_GUIED_ITEMBORDERCOLORALPHA ), rstate && state && enable );
130         EnableWindow ( GetDlgItem ( mPage, IDC_GUIED_ITEMBORDERMATERIAL ), !rstate && state );
131
132         state = (state && !rstate) || IsDlgButtonChecked ( mPage, IDC_GUIED_USEMATERIAL);
133         enable = !IsExpression ( mDict->GetString ( "matcolor", "1,1,1,1" ) );
134         EnableWindow ( GetDlgItem ( mPage, IDC_GUIED_ITEMMATCOLORSTATIC ), state && enable );                                   
135         EnableWindow ( GetDlgItem ( mPage, IDC_GUIED_ITEMMATCOLOR ), state && enable );
136         EnableWindow ( GetDlgItem ( mPage, IDC_GUIED_ITEMMATCOLORALPHA ), state && enable );
137 }
138
139 /*
140 ================
141 rvGEItemPropsImagePage::HandleMessage
142
143 Handles messages for the text item properties page
144 ================
145 */
146 int rvGEItemPropsImagePage::HandleMessage ( UINT msg, WPARAM wParam, LPARAM lParam )
147 {
148         switch ( msg )
149         {       
150                 case WM_DRAWITEM:
151                         ColorButton_DrawItem ( GetDlgItem ( mPage, wParam ), (LPDRAWITEMSTRUCT)lParam );                        
152                         return TRUE;
153                         
154                 case WM_COMMAND:
155                         switch ( LOWORD(wParam) )
156                         {                       
157                                 case IDC_GUIED_ITEMBORDERSIZE:
158                                         if ( HIWORD(wParam) == EN_CHANGE )
159                                         {
160                                                 UpdateCheckedStates ( );
161                                         }
162                                         break;
163                                         
164                                 case IDC_GUIED_USEBORDERCOLOR:
165                                 case IDC_GUIED_USEBORDERMATERIAL:
166                                 case IDC_GUIED_USEBACKCOLOR:
167                                 case IDC_GUIED_USEMATERIAL:
168                                         UpdateCheckedStates ( );
169                                         break;
170
171                                 case IDC_GUIED_ITEMBACKCOLORALPHA:
172                                 case IDC_GUIED_ITEMMATCOLORALPHA:
173                                 case IDC_GUIED_ITEMBORDERCOLORALPHA:
174                                 {
175                                         AlphaButton_OpenPopup ( GetDlgItem ( mPage, LOWORD(wParam) ) );
176                                         break;
177                                 }
178                                         
179                                 case IDC_GUIED_ITEMBORDERCOLOR:
180                                 case IDC_GUIED_ITEMBACKCOLOR:
181                                 case IDC_GUIED_ITEMMATCOLOR:
182                                 {
183                                         CHOOSECOLOR col;
184                                         ZeroMemory ( &col, sizeof(col) );
185                                         col.lStructSize = sizeof(col);
186                                         col.lpCustColors = gApp.GetOptions().GetCustomColors ( );
187                                         col.hwndOwner = mPage;
188                                         col.hInstance = NULL;
189                                         col.Flags = CC_RGBINIT;
190                                         col.rgbResult = ColorButton_GetColor ( GetDlgItem ( mPage, LOWORD(wParam) ) );
191                                         if ( ChooseColor ( &col ) )
192                                         {
193                                                 ColorButton_SetColor ( GetDlgItem ( mPage, LOWORD(wParam) ), col.rgbResult );
194                                         }
195                                         break;
196                                 }
197                         }
198                         break;
199         }
200         
201         return rvGEPropertyPage::HandleMessage ( msg, wParam, lParam );
202 }
203
204 /*
205 ================
206 rvGEItemPropsImagePage::SetActive
207
208 Initializes the text properties page by copying data from the attached
209 window into the controls
210 ================
211 */
212 bool rvGEItemPropsImagePage::SetActive ( void )
213 {
214         gApp.GetOptions().SetLastOptionsPage ( RVITEMPROPS_IMAGE );
215         
216         ColorButton_SetColor ( GetDlgItem ( mPage, IDC_GUIED_ITEMBACKCOLOR ), mDict->GetString ( "backcolor", "1,1,1,1" ) );            
217         AlphaButton_SetColor ( GetDlgItem ( mPage, IDC_GUIED_ITEMBACKCOLORALPHA ), mDict->GetString ( "backcolor", "1,1,1,1" ) );               
218
219         ColorButton_SetColor ( GetDlgItem ( mPage, IDC_GUIED_ITEMMATCOLOR ), mDict->GetString ( "matcolor", "1,1,1,1" ) );              
220         AlphaButton_SetColor ( GetDlgItem ( mPage, IDC_GUIED_ITEMMATCOLORALPHA ), mDict->GetString ( "matcolor", "1,1,1,1" ) );                 
221
222         ColorButton_SetColor ( GetDlgItem ( mPage, IDC_GUIED_ITEMBORDERCOLOR ), mDict->GetString ( "bordercolor", "0,0,0,1" ) );                
223         AlphaButton_SetColor ( GetDlgItem ( mPage, IDC_GUIED_ITEMBORDERCOLORALPHA ), mDict->GetString ( "bordercolor", "0,0,0,1" ) );           
224         
225         SetWindowText ( GetDlgItem ( mPage, IDC_GUIED_ITEMBACKGROUND ), idStr(mDict->GetString ( "background", "" )).StripQuotes ( ) ); 
226         SetWindowText ( GetDlgItem ( mPage, IDC_GUIED_ITEMBORDERMATERIAL ), idStr(mDict->GetString ( "borderShader", "" )).StripQuotes ( ) );   
227         SetWindowText ( GetDlgItem ( mPage, IDC_GUIED_ITEMBORDERSIZE ), idStr(mDict->GetString ( "bordersize", "0" )).StripQuotes ( ) );        
228
229         SetWindowText ( GetDlgItem ( mPage, IDC_GUIED_ITEMMATSCALEX ), idStr(mDict->GetString ( "matscalex", "1" )).StripQuotes ( ) );  
230         SetWindowText ( GetDlgItem ( mPage, IDC_GUIED_ITEMMATSCALEY ), idStr(mDict->GetString ( "matscaley", "1" )).StripQuotes ( ) );  
231
232         CheckDlgButton ( mPage, IDC_GUIED_ITEMVARIABLEBACKGROUND, mDict->GetBool ( "variablebackground", "0" ) );
233
234         CheckDlgButton ( mPage, IDC_GUIED_USEMATERIAL, idStr(mDict->GetString ( "background", "" )).StripQuotes ( ).Length()?BST_CHECKED:BST_UNCHECKED );
235         CheckDlgButton ( mPage, IDC_GUIED_USEBACKCOLOR, idStr(mDict->GetString ( "backcolor", "" )).StripQuotes ( ).Length()?BST_CHECKED:BST_UNCHECKED );
236
237         CheckRadioButton ( mPage, IDC_GUIED_USEBORDERCOLOR, IDC_GUIED_USEBORDERMATERIAL,
238                                            idStr(mDict->GetString("borderShader","")).Length()?IDC_GUIED_USEBORDERMATERIAL:IDC_GUIED_USEBORDERCOLOR );
239
240         UpdateCheckedStates ( );
241
242         return true;
243 }
244
245 /*
246 ================
247 rvGEItemPropsImagePage::KillActive
248
249 Applys the settings currently stored in the property page back into the attached window
250 ================
251 */
252 bool rvGEItemPropsImagePage::KillActive ( void )
253 {
254         char    temp[1024];
255         bool    matcolor = false;
256         idStr   s;
257                 
258         if ( IsDlgButtonChecked ( mPage, IDC_GUIED_USEMATERIAL ) )
259         {
260                 float val;
261                 
262                 GetWindowText ( GetDlgItem(mPage,IDC_GUIED_ITEMBACKGROUND), temp, 1024 );
263                 s = "\"";
264                 s.Append(temp);
265                 s.Append("\"" );
266                 mDict->Set ( "background", s );
267                 matcolor = true;
268
269                 GetWindowText ( GetDlgItem ( mPage, IDC_GUIED_ITEMMATSCALEX ), temp, 1024 );
270                 val = atof(temp);
271                 if ( val >= 0.999f && val <= 1.001f )
272                 {
273                         mDict->Delete ( "matscalex" );
274                 }
275                 else
276                 {
277                         mDict->Set ( "matscalex", idStr::FloatArrayToString( &val, 1, 8 ) );
278                 }
279
280                 GetWindowText ( GetDlgItem ( mPage, IDC_GUIED_ITEMMATSCALEY ), temp, 1024 );
281                 val = atof(temp);
282                 if ( val >= 0.999f && val <= 1.001f )
283                 {
284                         mDict->Delete ( "matscaley" );
285                 }
286                 else
287                 {
288                         mDict->Set ( "matscaley", idStr::FloatArrayToString( &val, 1, 8 ) );
289                 }
290                 
291                 if ( IsDlgButtonChecked ( mPage, IDC_GUIED_ITEMVARIABLEBACKGROUND ) )
292                 {
293                         mDict->Set ( "variablebackground", "1" );
294                 }
295                 else
296                 {
297                         mDict->Delete ( "variablebackground" );
298                 }
299         }
300         else
301         {
302                 mDict->Delete ( "background" );
303                 mDict->Delete ( "variablebackground" );
304                 mDict->Delete ( "matscalex" );
305                 mDict->Delete ( "matscaley" );
306         }
307
308         if ( IsDlgButtonChecked ( mPage, IDC_GUIED_USEBACKCOLOR ) )
309         {
310                 if ( IsWindowEnabled ( GetDlgItem ( mPage, IDC_GUIED_ITEMBACKCOLOR ) ) )
311                 {
312                         COLORREF color = ColorButton_GetColor ( GetDlgItem ( mPage, IDC_GUIED_ITEMBACKCOLOR ) );
313                         COLORREF alpha = ColorButton_GetColor ( GetDlgItem ( mPage, IDC_GUIED_ITEMBACKCOLORALPHA ) );
314                         mDict->Set ( "backcolor", StringFromVec4 ( idVec4((float)GetRValue ( color ) / 255.0f, (float)GetGValue ( color ) / 255.0f, (float)GetBValue ( color ) / 255.0f, (float)GetRValue(alpha )/255.0f ) ) ); 
315                 }
316         }
317         else
318         {
319                 mDict->Delete ( "backcolor" );
320         }
321
322         GetWindowText ( GetDlgItem ( mPage, IDC_GUIED_ITEMBORDERSIZE ), temp, 1024 );
323         if ( atoi ( temp ) )
324         {
325                 if ( IsWindowEnabled ( GetDlgItem ( mPage, IDC_GUIED_ITEMBORDERSIZE) ) ) 
326                 {
327                         mDict->Set ( "bordersize", va("%d", atoi(temp) ) );
328                 }
329
330                 if ( IsDlgButtonChecked ( mPage, IDC_GUIED_USEBORDERCOLOR ) )
331                 {
332                         if ( IsWindowEnabled ( GetDlgItem ( mPage, IDC_GUIED_ITEMBORDERCOLOR ) ) ) 
333                         {
334                                 COLORREF color = ColorButton_GetColor ( GetDlgItem ( mPage, IDC_GUIED_ITEMBORDERCOLOR ) );
335                                 COLORREF alpha = ColorButton_GetColor ( GetDlgItem ( mPage, IDC_GUIED_ITEMBORDERCOLORALPHA ) );
336                                 mDict->Set ( "bordercolor", StringFromVec4 ( idVec4((float)GetRValue ( color ) / 255.0f, (float)GetGValue ( color ) / 255.0f, (float)GetBValue ( color ) / 255.0f, (float)GetRValue(alpha )/255.0f ) ) );       
337                         }
338                         mDict->Delete ( "borderShader" );
339                 }
340                 else
341                 {
342                         GetWindowText ( GetDlgItem ( mPage, IDC_GUIED_ITEMBORDERMATERIAL ), temp, 1024 );
343                         s = "\"";
344                         s.Append(temp);
345                         s.Append("\"" );
346                         mDict->Set ( "borderShader", s );
347                         mDict->Delete ( "bordercolor" );
348                         matcolor = true;
349                 }
350         }
351         else
352         {
353                 mDict->Delete ( "bordersize" );
354                 mDict->Delete ( "bordercolor" );
355                 mDict->Delete ( "borderShader" );
356         }
357
358         if ( matcolor )
359         {
360                 if ( IsWindowEnabled ( GetDlgItem ( mPage, IDC_GUIED_ITEMMATCOLOR ) ) )
361                 {
362                         COLORREF color = ColorButton_GetColor ( GetDlgItem ( mPage, IDC_GUIED_ITEMMATCOLOR ) );
363                         COLORREF alpha = ColorButton_GetColor ( GetDlgItem ( mPage, IDC_GUIED_ITEMMATCOLORALPHA ) );
364                         mDict->Set ( "matcolor", StringFromVec4 ( idVec4((float)GetRValue ( color ) / 255.0f, (float)GetGValue ( color ) / 255.0f, (float)GetBValue ( color ) / 255.0f, (float)GetRValue(alpha )/255.0f ) ) );  
365                 }
366         }
367         else
368         {
369                 mDict->Delete ( "matcolor" );
370         }
371                 
372         return true;
373 }
374
375 class rvGEItemPropsTextPage : public rvGEPropertyPage 
376 {
377 public:
378
379         rvGEItemPropsTextPage ( idDict* dictValues );
380         
381         virtual bool    Init                    ( void );
382         virtual bool    SetActive               ( void );
383         virtual bool    KillActive              ( void );
384         virtual int             HandleMessage   ( UINT msg, WPARAM wParam, LPARAM lParam );
385
386 protected:
387
388         void                    UpdateCheckedStates             ( void );
389         
390         idDict*         mDict;
391 };      
392
393 rvGEItemPropsTextPage::rvGEItemPropsTextPage ( idDict* dict )
394 {
395         mDict = dict;
396 }
397
398 /*
399 ================
400 rvGEItemPropsTextPage::Init
401
402 Subclass the custom controls on the page
403 ================
404 */
405 bool rvGEItemPropsTextPage::Init ( void )
406 {
407         NumberEdit_Attach ( GetDlgItem ( mPage, IDC_GUIED_ITEMTEXTSCALE ) );
408         NumberEdit_Attach ( GetDlgItem ( mPage, IDC_GUIED_ITEMTEXTALIGNX ) );
409         NumberEdit_Attach ( GetDlgItem ( mPage, IDC_GUIED_ITEMTEXTALIGNY ) );
410
411         SendMessage ( GetDlgItem ( mPage, IDC_GUIED_ITEMTEXTALIGN ), CB_ADDSTRING, 0, (LPARAM)"Left" );
412         SendMessage ( GetDlgItem ( mPage, IDC_GUIED_ITEMTEXTALIGN ), CB_ADDSTRING, 0, (LPARAM)"Center" );
413         SendMessage ( GetDlgItem ( mPage, IDC_GUIED_ITEMTEXTALIGN ), CB_ADDSTRING, 0, (LPARAM)"Right" );
414
415         SendMessage ( GetDlgItem ( mPage, IDC_GUIED_ITEMTEXTFONT ), CB_ADDSTRING, 0, (LONG)"<default>" );
416         
417         idFileList *folders;
418         int               i;
419         
420         folders = fileSystem->ListFiles( "fonts", "/" );
421         
422         for ( i = 0; i < folders->GetNumFiles(); i++ ) {
423                 if ( folders->GetFile(i)[0] == '.' ) {
424                         continue;
425                 }
426                 
427                 SendMessage ( GetDlgItem ( mPage, IDC_GUIED_ITEMTEXTFONT ), CB_ADDSTRING, 0, (LONG)folders->GetFile(i) );
428         }
429
430         fileSystem->FreeFileList( folders );
431
432         return true;
433 }
434
435 /*
436 ================
437 rvGEItemPropsTextPage::UpdateCheckedStates
438
439 Updates the enabled state of all the controls that are linked to a checkbox
440 ================
441 */
442 void rvGEItemPropsTextPage::UpdateCheckedStates ( void )
443 {
444         bool    state;
445         idStr   result;
446         bool    enable;
447
448         state = IsDlgButtonChecked ( mPage, IDC_GUIED_USETEXT ) != 0;
449         enable = !IsExpression ( mDict->GetString ( "forecolor", "1,1,1,1" ) );
450
451         EnableWindow ( GetDlgItem ( mPage, IDC_GUIED_ITEMFORECOLOR ), state && enable );
452         EnableWindow ( GetDlgItem ( mPage, IDC_GUIED_ITEMFORECOLORALPHA ), state && enable );
453
454         EnableWindow ( GetDlgItem ( mPage, IDC_GUIED_ITEMTEXT ), state );
455         EnableWindow ( GetDlgItem ( mPage, IDC_GUIED_ITEMTEXTSCALE ), state );
456         EnableWindow ( GetDlgItem ( mPage, IDC_GUIED_ITEMTEXTSCALE ), state );
457         EnableWindow ( GetDlgItem ( mPage, IDC_GUIED_ITEMTEXTALIGN ), state );
458         EnableWindow ( GetDlgItem ( mPage, IDC_GUIED_ITEMTEXTALIGNX ), state );
459         EnableWindow ( GetDlgItem ( mPage, IDC_GUIED_ITEMTEXTALIGNY ), state );
460         EnableWindow ( GetDlgItem ( mPage, IDC_GUIED_ITEMTEXTFONT), state );
461         EnableWindow ( GetDlgItem ( mPage, IDC_GUIED_ITEMTEXTNOWRAP), state );
462
463         EnableWindow ( GetDlgItem ( mPage, IDC_GUIED_STATIC_ALIGNMENT ), state );
464         EnableWindow ( GetDlgItem ( mPage, IDC_GUIED_STATIC_X ), state );
465         EnableWindow ( GetDlgItem ( mPage, IDC_GUIED_STATIC_Y ), state );
466         EnableWindow ( GetDlgItem ( mPage, IDC_GUIED_STATIC_SCALE ), state );
467         EnableWindow ( GetDlgItem ( mPage, IDC_GUIED_STATIC_COLOR ), state );
468         EnableWindow ( GetDlgItem ( mPage, IDC_GUIED_STATIC_FONT), state );
469 }
470
471 /*
472 ================
473 rvGEItemPropsTextPage::HandleMessage
474
475 Handles messages for the text item properties page
476 ================
477 */
478 int rvGEItemPropsTextPage::HandleMessage ( UINT msg, WPARAM wParam, LPARAM lParam )
479 {
480         switch ( msg )
481         {       
482                 case WM_DRAWITEM:
483                         ColorButton_DrawItem ( GetDlgItem ( mPage, wParam ), (LPDRAWITEMSTRUCT)lParam );                        
484                         return TRUE;
485                         
486                 case WM_COMMAND:
487                         switch ( LOWORD(wParam) )
488                         {                       
489                                 case IDC_GUIED_ITEMTEXTFONT:
490                                         break;
491                                 
492                                 case IDC_GUIED_USETEXT:
493                                         UpdateCheckedStates ( );
494                                         break;
495
496                                 case IDC_GUIED_ITEMFORECOLORALPHA:
497                                         AlphaButton_OpenPopup ( GetDlgItem ( mPage, LOWORD(wParam) ) );
498                                         break;
499                                         
500                                 case IDC_GUIED_ITEMFORECOLOR:
501                                 {
502                                         CHOOSECOLOR col;
503                                         ZeroMemory ( &col, sizeof(col) );
504                                         col.lStructSize = sizeof(col);
505                                         col.lpCustColors = gApp.GetOptions().GetCustomColors ( );
506                                         col.hwndOwner = mPage;
507                                         col.hInstance = NULL;
508                                         col.Flags = CC_RGBINIT;
509                                         col.rgbResult = ColorButton_GetColor ( GetDlgItem ( mPage, LOWORD(wParam) ) );
510                                         if ( ChooseColor ( &col ) )
511                                         {
512                                                 ColorButton_SetColor ( GetDlgItem ( mPage, LOWORD(wParam) ), col.rgbResult );
513                                         }
514                                         break;
515                                 }
516                         }
517                         break;
518         }
519         
520         return rvGEPropertyPage::HandleMessage ( msg, wParam, lParam );
521 }
522
523 /*
524 ================
525 rvGEItemPropsTextPage::SetActive
526
527 Initializes the text properties page by copying data from the attached
528 window into the controls
529 ================
530 */
531 bool rvGEItemPropsTextPage::SetActive ( void )
532 {
533         gApp.GetOptions().SetLastOptionsPage ( RVITEMPROPS_TEXT );
534
535         ColorButton_SetColor ( GetDlgItem ( mPage, IDC_GUIED_ITEMFORECOLOR ), mDict->GetString ( "forecolor", "1,1,1,1" ) );            
536         AlphaButton_SetColor ( GetDlgItem ( mPage, IDC_GUIED_ITEMFORECOLORALPHA ), mDict->GetString ( "forecolor", "1,1,1,1" ) );               
537
538         SetWindowText ( GetDlgItem ( mPage, IDC_GUIED_ITEMTEXT ), idStr(mDict->GetString ( "text", "" )).StripQuotes ( ) );     
539         SetWindowText ( GetDlgItem ( mPage, IDC_GUIED_ITEMTEXTSCALE ), mDict->GetString ( "textscale", "1.0" ) );
540         SetWindowText ( GetDlgItem ( mPage, IDC_GUIED_ITEMTEXTALIGNX ), mDict->GetString ( "textalignx", "0" ) );
541         SetWindowText ( GetDlgItem ( mPage, IDC_GUIED_ITEMTEXTALIGNY ), mDict->GetString ( "textaligny", "0" ) );
542
543         SendMessage ( GetDlgItem ( mPage, IDC_GUIED_ITEMTEXTALIGN ), CB_SETCURSEL, atoi(mDict->GetString("textalign", "0")), 0 );
544
545         // Figure out which font to select
546         idStr font = mDict->GetString ( "font", "" );
547         int   fontSel;
548         font.StripQuotes ( );
549         font.StripPath ( );
550         fontSel = SendMessage ( GetDlgItem ( mPage, IDC_GUIED_ITEMTEXTFONT ), CB_FINDSTRING, -1, (LONG)font.c_str () );
551         SendMessage ( GetDlgItem ( mPage, IDC_GUIED_ITEMTEXTFONT ), CB_SETCURSEL, 0, 0 );
552         SendMessage ( GetDlgItem ( mPage, IDC_GUIED_ITEMTEXTFONT ), CB_SETCURSEL, fontSel==-1?0:fontSel, 0 );
553
554         CheckDlgButton ( mPage, IDC_GUIED_USETEXT, idStr(mDict->GetString ( "text", "" )).Length()?BST_CHECKED:BST_UNCHECKED );
555         CheckDlgButton ( mPage, IDC_GUIED_ITEMTEXTNOWRAP, atoi(idStr(mDict->GetString ( "nowrap", "0" )).StripQuotes())?BST_CHECKED:BST_UNCHECKED );
556
557         UpdateCheckedStates ( );
558
559         return true;
560 }
561
562 /*
563 ================
564 rvGEItemPropsTextPage::KillActive
565
566 Applys the settings currently stored in the property page back into the attached window
567 ================
568 */
569 bool rvGEItemPropsTextPage::KillActive ( void )
570 {
571         idStr   s;
572         char    temp[1024];
573         int             i;
574         float   f;
575                 
576         if ( IsDlgButtonChecked ( mPage, IDC_GUIED_USETEXT ) )
577         {
578                 if ( IsWindowEnabled ( GetDlgItem ( mPage, IDC_GUIED_ITEMFORECOLOR ) ) )
579                 {
580                         COLORREF color = ColorButton_GetColor ( GetDlgItem ( mPage, IDC_GUIED_ITEMFORECOLOR ) );
581                         COLORREF alpha = ColorButton_GetColor ( GetDlgItem ( mPage, IDC_GUIED_ITEMFORECOLORALPHA ) );
582                         mDict->Set ( "forecolor", StringFromVec4 ( idVec4((float)GetRValue ( color ) / 255.0f, (float)GetGValue ( color ) / 255.0f, (float)GetBValue ( color ) / 255.0f, (float)GetRValue(alpha )/255.0f ) ) ); 
583                 }
584
585                 GetWindowText ( GetDlgItem(mPage,IDC_GUIED_ITEMTEXT), temp, 1024 );
586                 s = "\"";
587                 s.Append(temp);
588                 s.Append("\"" );
589                 mDict->Set ( "text", s );
590
591                 GetWindowText ( GetDlgItem(mPage,IDC_GUIED_ITEMTEXTSCALE), temp, 1024 );
592                 f = atof( temp );
593                 mDict->Set ( "textscale", idStr::FloatArrayToString( &f, 1, 8 ) );
594
595                 i = SendMessage ( GetDlgItem ( mPage, IDC_GUIED_ITEMTEXTALIGN ), CB_GETCURSEL, 0, 0 );
596                 s = va("%d", i );
597                 if ( i != 0 )
598                 {
599                         mDict->Set ( "textalign", s );
600                 }
601                 else
602                 {
603                         mDict->Delete ( "textalign" );
604                 }
605
606                 GetWindowText ( GetDlgItem(mPage,IDC_GUIED_ITEMTEXTALIGNX), temp, 1024 );
607                 i = atoi(temp);
608                 if ( i )
609                 {
610                         mDict->Set ( "textalignx", va("%d", i ) );
611                 }
612                 else
613                 {
614                         mDict->Delete ( "textalignx" );
615                 }
616                 
617                 GetWindowText ( GetDlgItem(mPage,IDC_GUIED_ITEMTEXTALIGNY), temp, 1024 );
618                 i = atoi(temp);
619                 if ( i )
620                 {
621                         mDict->Set ( "textaligny", va("%d", i ) );
622                 }
623                 else
624                 {
625                         mDict->Delete ( "textaligny" );
626                 }
627                 
628                 int fontSel = SendMessage ( GetDlgItem ( mPage, IDC_GUIED_ITEMTEXTFONT ), CB_GETCURSEL, 0, 0 );
629                 if ( fontSel == 0 )
630                 {
631                         mDict->Delete ( "font" );
632                 }
633                 else
634                 {
635                         char fontName[MAX_PATH];
636                         SendMessage ( GetDlgItem ( mPage, IDC_GUIED_ITEMTEXTFONT ), CB_GETLBTEXT, fontSel, (LONG)fontName );
637                         mDict->Set ( "font", idStr("\"fonts/") + idStr(fontName) + idStr("\"" ) );                      
638                 }
639                 
640                 if ( IsDlgButtonChecked ( mPage, IDC_GUIED_ITEMTEXTNOWRAP ) )
641                 {
642                         mDict->Set ( "nowrap", "1" );
643                 }
644                 else
645                 {
646                         mDict->Delete ( "nowrap" );
647                 }
648         }
649         else
650         {
651                 mDict->Delete ( "text" );
652                 mDict->Delete ( "textscale" );
653                 mDict->Delete ( "textalign" );
654                 mDict->Delete ( "textalignx" );
655                 mDict->Delete ( "textaligny" );
656                 mDict->Delete ( "forecolor" );
657                 mDict->Delete ( "font" );
658         }
659
660         return true;
661 }
662
663 class rvGEItemPropsKeysPage : public rvGEPropertyPage 
664 {
665 public:
666
667         rvGEItemPropsKeysPage ( idDict* dictValues, rvGEWindowWrapper* wrapper );
668         
669         virtual bool    Init                    ( void );
670         virtual bool    SetActive               ( void );
671         virtual int             HandleMessage   ( UINT msg, WPARAM wParam, LPARAM lParam );
672
673 protected:
674
675         idDict*                         mDict;
676         rvGEWindowWrapper*      mWrapper;
677 };      
678         
679 rvGEItemPropsKeysPage::rvGEItemPropsKeysPage ( idDict* dict, rvGEWindowWrapper* wrapper )
680 {
681         mDict = dict;
682         mWrapper = wrapper;
683 }
684
685 INT_PTR CALLBACK ModifyItemKeyDlg_WndProc ( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
686 {
687         switch ( msg )
688         {
689                 case WM_INITDIALOG:
690                 {
691                         const idKeyValue* keyValue = (const idKeyValue*) lParam;
692                         MaskEdit_Attach ( GetDlgItem ( hwnd, IDC_GUIED_ITEMKEY ), " \t\r\n" );
693                         SetWindowText ( GetDlgItem ( hwnd, IDC_GUIED_ITEMVALUE ), idStr(keyValue->GetValue()).StripQuotes ( ) );
694                         if ( idStr::Icmp ( keyValue->GetKey(), "guied_temp" ) )
695                         {
696                                 if ( !idStr::Icmp ( keyValue->GetKey(), "name" ) || !idStr::Icmp ( keyValue->GetKey(), "rect" ) )
697                                 {
698                                         // Dont allow editing the name keyname 
699                                         EnableWindow ( GetDlgItem ( hwnd, IDC_GUIED_ITEMKEY ), FALSE );
700                                 }
701
702                                 SetWindowText ( GetDlgItem ( hwnd, IDC_GUIED_ITEMKEY ), keyValue->GetKey() );
703                                 SetFocus ( GetDlgItem ( hwnd, IDC_GUIED_ITEMVALUE ) );
704                                 SendMessage( GetDlgItem ( hwnd, IDC_GUIED_ITEMVALUE ), EM_SETSEL, 0, -1 ); 
705                                 
706                                 SetWindowText ( hwnd, "New Item Key" );
707                         }
708                         
709                         SetWindowLong ( hwnd, GWL_USERDATA, lParam );
710                         return FALSE;
711                 }
712         
713                 case WM_COMMAND:
714                         switch ( LOWORD(wParam) )
715                         {
716                                 case IDOK:
717                                 {
718                                         char key[1024];
719                                         char value[1024];
720                                         
721                                         const idKeyValue* keyValue = (const idKeyValue*) GetWindowLong ( hwnd, GWL_USERDATA );
722                                         
723                                         GetWindowText ( GetDlgItem ( hwnd, IDC_GUIED_ITEMKEY ), key, 1024 );
724                                         GetWindowText ( GetDlgItem ( hwnd, IDC_GUIED_ITEMVALUE ), value, 1024 );
725
726                                         if ( strlen ( key ) < 1 )
727                                         {
728                                                 gApp.MessageBox ( va("Invalid key name '%s'", key), MB_OK|MB_ICONERROR );                                                               
729                                         }
730                                         else
731                                         {
732                                                 // FIXME: MrE may never change key value pairs directly!
733                                                 //keyValue->GetKey() = key;
734                                                 //keyValue->GetValue = value;
735
736                                                 EndDialog ( hwnd, 1);
737                                         }
738                                         break;
739                                 }
740                                         
741                                 case IDCANCEL:
742                                         EndDialog ( hwnd, 0 );
743                                         break;
744                         }
745                         break;
746         }
747
748         return FALSE;
749 }
750
751 int rvGEItemPropsKeysPage::HandleMessage ( UINT msg, WPARAM wParam, LPARAM lParam )
752 {
753         switch ( msg )
754         {
755                 case WM_NOTIFY:
756                 {
757                         NMHDR* nm = (NMHDR*) lParam;
758                         
759                         // There are a few protected keys that need to dissallow deleting so 
760                         // check to see if the newly selected key is one of them and if so then
761                         // disable the delete button
762                         if ( nm->code == LVN_ITEMCHANGED )
763                         {
764                                 NMLISTVIEW* nmlv = (NMLISTVIEW*) nm;
765                                 if ( nmlv->uNewState & LVIS_SELECTED )
766                                 {
767                                         const idKeyValue* keyValue = (idKeyValue*) nmlv->lParam;
768                                         assert( keyValue );
769
770                                         if ( !idStr::Icmp ( keyValue->GetKey(), "name" ) || !idStr::Icmp ( keyValue->GetKey(), "rect" ) )
771                                         {
772                                                 EnableWindow ( GetDlgItem ( mPage, IDC_GUIED_DELETEKEY ), FALSE );
773                                         }
774                                         else
775                                         {
776                                                 EnableWindow ( GetDlgItem ( mPage, IDC_GUIED_DELETEKEY ), TRUE );
777                                         }
778                                 }
779                         }
780                         break;
781                 }
782                 
783                 case WM_COMMAND:
784                         switch ( LOWORD(wParam) )
785                         {
786                                 case IDC_GUIED_ADDKEY:
787                                 {
788                                         HWND list = GetDlgItem ( mPage, IDC_GUIED_ITEMKEYS );
789                                         mDict->Set( "guied_temp", "" );
790                                         const idKeyValue* key = mDict->FindKey ( "guied_temp" );
791                                         
792                                         idStr old = key->GetValue();
793                                         while ( 1 )
794                                         {                                       
795                                                 if ( DialogBoxParam ( gApp.GetInstance (), MAKEINTRESOURCE(IDD_GUIED_ITEMKEY), mPage, ModifyItemKeyDlg_WndProc, (LPARAM)key ) )
796                                                 {
797                                                         idStr finalValue;                                               
798
799                                                         finalValue = key->GetValue();
800                                                         if ( !mWrapper->VerfiyStateKey ( key->GetKey(), finalValue ) )
801                                                         {
802                                                                 finalValue = "\"";
803                                                                 finalValue += key->GetValue();
804                                                                 finalValue += "\"";
805                                                                 if ( !mWrapper->VerfiyStateKey ( key->GetKey(), finalValue ) )
806                                                                 {
807                                                                         gApp.MessageBox ( va("Invalid property value '%s' for property '%s'", key->GetValue().c_str(), key->GetKey().c_str()), MB_OK|MB_ICONERROR );
808                                                                         continue;
809                                                                 }
810                                                         }
811
812                                                         mDict->Set( key->GetKey(), finalValue );
813
814                                                         LVITEM          item;
815                                                         ZeroMemory ( &item, sizeof(item) );
816                                                         item.mask = LVIF_TEXT|LVIF_PARAM;
817                                                         item.iItem = ListView_GetItemCount ( list );
818                                                         item.pszText = (LPSTR)key->GetKey().c_str ( );
819                                                         item.lParam = (LONG) key;
820                                                         int index = ListView_InsertItem ( list, &item );
821                                                 
822                                                         finalValue.StripQuotes ( );
823                                                         ListView_SetItemText ( list, index, 1, (LPSTR)finalValue.c_str ( ) );
824                                                         
825                                                         break;
826                                                 }
827                                                 else
828                                                 {
829                                                         mDict->Delete ( "guied_temp" );
830                                                         break;
831                                                 }
832                                         }
833                                         break;
834                                 }
835
836                                 case IDC_GUIED_EDITKEY:
837                                 {
838                                         HWND list = GetDlgItem ( mPage, IDC_GUIED_ITEMKEYS );
839                                         int index = ListView_GetNextItem ( list, -1, LVNI_SELECTED );
840                                         if ( index != -1 )
841                                         {
842                                                 LVITEM item;
843                                                 item.iItem = index;
844                                                 item.mask = LVIF_PARAM;
845                                                 ListView_GetItem ( list, &item );
846                                                 const idKeyValue* key = (const idKeyValue*)item.lParam;
847                                                 assert ( key );
848
849                                                 while ( 1 )
850                                                 {
851                                                         if ( DialogBoxParam ( gApp.GetInstance (), MAKEINTRESOURCE(IDD_GUIED_ITEMKEY), mPage, ModifyItemKeyDlg_WndProc, (LPARAM)key ) )
852                                                         {
853                                                                 idStr finalValue;                                               
854                                                         
855                                                                 finalValue = key->GetValue();
856                                                                 if ( !mWrapper->VerfiyStateKey ( key->GetKey(), finalValue ) )
857                                                                 {
858                                                                         finalValue = "\"";
859                                                                         finalValue += key->GetValue();
860                                                                         finalValue += "\"";
861                                                                         if ( !mWrapper->VerfiyStateKey ( key->GetKey(), finalValue ) )
862                                                                         {
863                                                                                 gApp.MessageBox ( va("Invalid property value '%s' for property '%s'", key->GetValue().c_str(), key->GetKey().c_str()), MB_OK|MB_ICONERROR );
864                                                                                 continue;
865                                                                         }
866                                                                 }
867
868                                                                 // FIXME: MrE is this the right thing todo?
869                                                                 mDict->Set( key->GetKey(), finalValue );
870                                                                 //key->GetValue() = finalValue;
871
872                                                                 ListView_SetItemText ( list, index, 0, (LPSTR)key->GetKey().c_str() );
873
874                                                                 finalValue.StripQuotes ( );
875                                                                 ListView_SetItemText ( list, index, 1, (LPSTR)finalValue.c_str() );                                                     
876                                                                 break;
877                                                         }
878                                                 }                                               
879                                         }
880                                         break;
881                                 }
882                                 
883                                 case IDC_GUIED_DELETEKEY:
884                                 {
885                                         HWND list = GetDlgItem ( mPage, IDC_GUIED_ITEMKEYS );
886                                         int index = ListView_GetNextItem ( list, -1, LVNI_SELECTED );
887                                         if ( index != -1 )
888                                         {
889                                                 LVITEM item;
890                                                 item.iItem = index;
891                                                 item.mask = LVIF_PARAM;
892                                                 ListView_GetItem ( list, &item );
893                                                 const idKeyValue* key = (const idKeyValue*)item.lParam;
894                                                 assert ( key );
895                                                 
896                                                 mDict->Delete ( key->GetKey() );
897                                                 
898                                                 ListView_DeleteItem ( list, index );
899                                         }                                       
900                                         break;
901                                 }
902                         }
903                         break;          
904         }
905         
906         return rvGEPropertyPage::HandleMessage ( msg, wParam, lParam );
907 }
908
909 /*
910 ================
911 rvGEItemPropsKeysPage::Init
912
913 Called when the advanced page is first initialized.  Setup the extended
914 control styles and add the key/value columns
915 ================
916 */
917 bool rvGEItemPropsKeysPage::Init ( void )
918 {
919         HWND    list;
920         RECT    rWindow;
921
922         // Get the list control
923         list = GetDlgItem ( mPage, IDC_GUIED_ITEMKEYS );
924         assert ( list );
925
926         GetClientRect ( list, &rWindow );
927
928         // Set the full row select for better visual appearance
929         ListView_SetExtendedListViewStyle ( list, LVS_EX_FULLROWSELECT );
930
931         // Add the key column
932         LVCOLUMN col;
933         col.mask = LVCF_TEXT|LVCF_WIDTH;
934         col.cx = .3 * (rWindow.right - rWindow.left);
935         col.pszText = "Key";
936         ListView_InsertColumn ( list, 0, &col );
937
938         // Add the value column
939         col.pszText = "Value";
940         col.cx = (rWindow.right - rWindow.left) - col.cx;
941         ListView_InsertColumn ( list, 1, &col );
942         
943         return true;
944 }
945
946 /*
947 ================
948 rvGEItemPropsKeysPage::SetActive
949
950 Called when the advanced page is made active and will add an entry to
951 the keys list view for each key in the properties dictionary
952 ================
953 */
954 bool rvGEItemPropsKeysPage::SetActive ( void )
955 {
956         int             i;
957         HWND    list;
958
959         gApp.GetOptions().SetLastOptionsPage ( RVITEMPROPS_KEYS );
960
961         // Get listview control
962         list = GetDlgItem ( mPage, IDC_GUIED_ITEMKEYS );
963         assert ( list );
964
965         // Delete anything already in there
966         ListView_DeleteAllItems ( list );
967
968         // Add each key in the properties dictionary
969         for ( i = 0; i < mDict->GetNumKeyVals(); i ++ )
970         {
971                 const idKeyValue* key = mDict->GetKeyVal ( i ); 
972                 assert ( key );         
973                                 
974                 // Add the item
975                 LVITEM item;
976                 ZeroMemory ( &item, sizeof(item) );
977                 item.mask = LVIF_TEXT|LVIF_PARAM;
978                 item.iItem = ListView_GetItemCount ( list );
979                 item.pszText = (LPSTR)key->GetKey().c_str ( );
980                 item.lParam = (LONG) key;
981                 int index = ListView_InsertItem ( list, &item );
982                 
983                 idStr value;
984                 value = key->GetValue();                
985                 value.StripQuotes ( );
986                 ListView_SetItemText ( list, index, 1, (LPSTR)value.c_str() );
987         }               
988
989         return true;
990 }
991         
992 class rvGEItemPropsGeneralPage : public rvGEPropertyPage
993 {
994 public:
995
996         rvGEItemPropsGeneralPage ( idDict* dict, rvGEWindowWrapper::EWindowType type );
997         
998         virtual bool    SetActive               ( void );
999         virtual bool    KillActive              ( void );
1000         virtual bool    Init                    ( void );
1001         virtual int             HandleMessage   ( UINT msg, WPARAM wParam, LPARAM lParam );
1002         
1003 protected:
1004
1005         void                    UpdateCheckedStates             ( void );
1006
1007         idDict* mDict;
1008         idStr   mType;
1009 };
1010
1011 rvGEItemPropsGeneralPage::rvGEItemPropsGeneralPage ( idDict* dict, rvGEWindowWrapper::EWindowType type )
1012 {
1013         mDict = dict;
1014         mType = rvGEWindowWrapper::WindowTypeToString ( type );
1015 }
1016
1017 /*
1018 ================
1019 rvGEItemPropsGeneralPage::UpdateCheckedStates
1020
1021 Updates the enabled state of all the controls that are linked to a checkbox
1022 ================
1023 */
1024 void rvGEItemPropsGeneralPage::UpdateCheckedStates ( void )
1025 {
1026 }
1027
1028 /*
1029 ================
1030 rvGEItemPropsGeneralPage::HandleMessage
1031
1032 Handles messages for the general item properties page
1033 ================
1034 */
1035 int rvGEItemPropsGeneralPage::HandleMessage ( UINT msg, WPARAM wParam, LPARAM lParam )
1036 {
1037 /*                      
1038         switch ( msg )
1039         {       
1040                 case WM_COMMAND:
1041                         switch ( LOWORD(wParam) )
1042                         {
1043                         }
1044                         break;
1045         }
1046 */
1047         
1048         return rvGEPropertyPage::HandleMessage ( msg, wParam, lParam );
1049 }
1050
1051 /*
1052 ================
1053 rvGEItemPropsGeneralPage::Init
1054
1055 Subclass the custom controls on the page
1056 ================
1057 */
1058 bool rvGEItemPropsGeneralPage::Init ( void )
1059 {
1060         MaskEdit_Attach ( GetDlgItem ( mPage, IDC_GUIED_ITEMNAME ), " \t\n\r" );
1061                 
1062         return true;
1063 }
1064
1065 /*
1066 ================
1067 rvGEItemPropsGeneralPage::SetActive
1068
1069 Initializes the general properties page by copying data from the attached
1070 window into the controls
1071 ================
1072 */
1073 bool rvGEItemPropsGeneralPage::SetActive ( void )
1074 {
1075         bool  enable;
1076         idStr result;
1077         
1078         gApp.GetOptions().SetLastOptionsPage ( RVITEMPROPS_GENERAL );
1079
1080         SetWindowText ( GetDlgItem ( mPage, IDC_GUIED_ITEMNAME ), idStr(mDict->GetString ( "name", "unnamed" )).StripQuotes ( ) );      
1081
1082         enable = !IsExpression ( mDict->GetString ( "visible", "1" ) );
1083         CheckDlgButton ( mPage, IDC_GUIED_ITEMVISIBLE, atol(idStr(mDict->GetString ( "visible", "1" )).StripQuotes ( ))?BST_CHECKED:BST_UNCHECKED );
1084         EnableWindow ( GetDlgItem ( mPage, IDC_GUIED_ITEMVISIBLE ), enable );
1085
1086         enable = !IsExpression ( mDict->GetString ( "notime", "0" ) );
1087         CheckDlgButton ( mPage, IDC_GUIED_ITEMNOTIME, atol(idStr(mDict->GetString ( "notime", "0" )).StripQuotes ( ))?BST_CHECKED:BST_UNCHECKED );
1088         EnableWindow ( GetDlgItem ( mPage, IDC_GUIED_ITEMNOTIME ), enable );
1089
1090         enable = !IsExpression ( mDict->GetString ( "noevents", "0" ) );
1091         CheckDlgButton ( mPage, IDC_GUIED_ITEMNOEVENTS, atol(idStr(mDict->GetString ( "noevents", "0" )).StripQuotes ( ))?BST_CHECKED:BST_UNCHECKED );
1092         EnableWindow ( GetDlgItem ( mPage, IDC_GUIED_ITEMNOEVENTS ), enable );
1093
1094         enable = !IsExpression ( mDict->GetString ( "noclip", "0" ) );
1095         CheckDlgButton ( mPage, IDC_GUIED_ITEMNOCLIP, atol(idStr(mDict->GetString ( "noclip", "0" )).StripQuotes ( ))?BST_CHECKED:BST_UNCHECKED );
1096         EnableWindow ( GetDlgItem ( mPage, IDC_GUIED_ITEMNOCLIP ), enable );
1097
1098         enable = !IsExpression ( mDict->GetString ( "nocursor", "0" ) );
1099         EnableWindow ( GetDlgItem ( mPage, IDC_GUIED_ITEMNOCURSOR  ), enable );
1100         CheckDlgButton ( mPage, IDC_GUIED_ITEMNOCURSOR, atol(idStr(mDict->GetString ( "nocursor", "0" )).StripQuotes ( ))?BST_CHECKED:BST_UNCHECKED );
1101
1102         SetWindowText ( GetDlgItem ( mPage, IDC_GUIED_TYPE ), mType );
1103                 
1104         UpdateCheckedStates ( );
1105
1106         return true;
1107 }
1108
1109
1110 /*
1111 ================
1112 rvGEItemPropsGeneralPage::KillActive
1113
1114 Applys the settings currently stored in the property page back into the attached window
1115 ================
1116 */
1117 bool rvGEItemPropsGeneralPage::KillActive ( void )
1118 {
1119         char temp[1024];
1120                 
1121         GetWindowText ( GetDlgItem(mPage,IDC_GUIED_ITEMNAME), temp, 1024 );     
1122         mDict->Set ( "name", temp );
1123
1124         if ( IsWindowEnabled ( GetDlgItem ( mPage, IDC_GUIED_ITEMVISIBLE ) ) )
1125         {
1126                 if ( IsDlgButtonChecked ( mPage, IDC_GUIED_ITEMVISIBLE ) )
1127                 {       
1128                         mDict->Set ( "visible" , "1" );
1129                 }
1130                 else
1131                 {
1132                         mDict->Set ( "visible" , "0" );
1133                 }
1134         }
1135
1136         if ( IsWindowEnabled ( GetDlgItem ( mPage, IDC_GUIED_ITEMNOTIME ) ) )
1137         {
1138                 if ( IsDlgButtonChecked ( mPage, IDC_GUIED_ITEMNOTIME ) )
1139                 {       
1140                         mDict->Set ( "notime" , "1" );
1141                 }
1142                 else
1143                 {
1144                         mDict->Delete ( "notime" );
1145                 }
1146         }
1147                 
1148         if ( IsWindowEnabled ( GetDlgItem ( mPage, IDC_GUIED_ITEMNOEVENTS ) ) )
1149         {
1150                 if ( IsDlgButtonChecked ( mPage, IDC_GUIED_ITEMNOEVENTS ) )
1151                 {       
1152                         mDict->Set ( "noevents" , "1" );
1153                 }
1154                 else
1155                 {
1156                         mDict->Delete ( "noevents" );
1157                 }
1158         }
1159
1160         if ( IsWindowEnabled ( GetDlgItem ( mPage, IDC_GUIED_ITEMNOCLIP ) ) )
1161         {
1162                 if ( IsDlgButtonChecked ( mPage, IDC_GUIED_ITEMNOCLIP ) )
1163                 {       
1164                         mDict->Set ( "noclip" , "1" );
1165                 }
1166                 else
1167                 {
1168                         mDict->Delete ( "noclip" );
1169                 }
1170         }
1171
1172         if ( IsWindowEnabled ( GetDlgItem ( mPage, IDC_GUIED_ITEMNOCURSOR ) ) )
1173         {
1174                 if ( IsDlgButtonChecked ( mPage, IDC_GUIED_ITEMNOCURSOR ) )
1175                 {       
1176                         mDict->Set ( "nocursor" , "1" );
1177                 }
1178                 else
1179                 {
1180                         mDict->Delete ( "nocursor" );
1181                 }
1182         }
1183
1184         return true;
1185 }
1186
1187 /*
1188 ================
1189 GEItemPropsDlg_DoModal
1190
1191 Starts the item properties dialog
1192 ================
1193 */
1194 bool GEItemPropsDlg_DoModal ( HWND parent, idWindow* window, idDict& dict )
1195 {
1196         PROPSHEETHEADER         propsh;
1197         PROPSHEETPAGE           propsp[4];
1198         rvGEWindowWrapper*      wrapper;
1199         bool                            result;
1200         
1201         wrapper = rvGEWindowWrapper::GetWrapper ( window );
1202         assert ( wrapper );
1203                 
1204         // Start the destination dictionary with the values in the window dictionary
1205         dict.Clear ( );
1206         dict.Copy ( wrapper->GetStateDict ( ));
1207         
1208         propsp[RVITEMPROPS_GENERAL].dwSize              = sizeof(PROPSHEETPAGE);
1209         propsp[RVITEMPROPS_GENERAL].dwFlags             = PSP_USETITLE;
1210         propsp[RVITEMPROPS_GENERAL].hInstance   = win32.hInstance;
1211         propsp[RVITEMPROPS_GENERAL].pszTemplate = MAKEINTRESOURCE(IDD_GUIED_ITEMPROPS_GENERAL);
1212         propsp[RVITEMPROPS_GENERAL].pfnDlgProc  = rvGEPropertyPage::WndProc;
1213         propsp[RVITEMPROPS_GENERAL].pszTitle    = "General";
1214         propsp[RVITEMPROPS_GENERAL].lParam              = (LONG)new rvGEItemPropsGeneralPage ( &dict, wrapper->GetWindowType ( ) );
1215
1216         propsp[RVITEMPROPS_IMAGE].dwSize                = sizeof(PROPSHEETPAGE);
1217         propsp[RVITEMPROPS_IMAGE].dwFlags               = PSP_USETITLE;
1218         propsp[RVITEMPROPS_IMAGE].hInstance             = win32.hInstance;
1219         propsp[RVITEMPROPS_IMAGE].pszTemplate   = MAKEINTRESOURCE(IDD_GUIED_ITEMPROPS_IMAGE);
1220         propsp[RVITEMPROPS_IMAGE].pfnDlgProc    = rvGEPropertyPage::WndProc;
1221         propsp[RVITEMPROPS_IMAGE].pszTitle              = "Image";
1222         propsp[RVITEMPROPS_IMAGE].lParam                = (LONG)new rvGEItemPropsImagePage ( &dict );;
1223
1224         propsp[RVITEMPROPS_TEXT].dwSize                 = sizeof(PROPSHEETPAGE);
1225         propsp[RVITEMPROPS_TEXT].dwFlags                = PSP_USETITLE;
1226         propsp[RVITEMPROPS_TEXT].hInstance              = win32.hInstance;
1227         propsp[RVITEMPROPS_TEXT].pszTemplate    = MAKEINTRESOURCE(IDD_GUIED_ITEMPROPS_TEXT);
1228         propsp[RVITEMPROPS_TEXT].pfnDlgProc             = rvGEPropertyPage::WndProc;
1229         propsp[RVITEMPROPS_TEXT].pszTitle               = "Text";
1230         propsp[RVITEMPROPS_TEXT].lParam                 = (LONG)new rvGEItemPropsTextPage ( &dict );;
1231
1232         propsp[RVITEMPROPS_KEYS].dwSize                 = sizeof(PROPSHEETPAGE);
1233         propsp[RVITEMPROPS_KEYS].dwFlags                = PSP_USETITLE;
1234         propsp[RVITEMPROPS_KEYS].hInstance              = win32.hInstance;
1235         propsp[RVITEMPROPS_KEYS].pszTemplate    = MAKEINTRESOURCE(IDD_GUIED_ITEMPROPS_KEYS);
1236         propsp[RVITEMPROPS_KEYS].pfnDlgProc             = rvGEPropertyPage::WndProc;
1237         propsp[RVITEMPROPS_KEYS].pszTitle               = "Keys";
1238         propsp[RVITEMPROPS_KEYS].lParam                 = (LONG)new rvGEItemPropsKeysPage ( &dict, wrapper );
1239
1240         propsh.dwSize                   = sizeof(PROPSHEETHEADER);
1241         propsh.nStartPage               = gApp.GetOptions().GetLastOptionsPage ( );
1242         propsh.dwFlags                  = PSH_PROPSHEETPAGE|PSH_NOAPPLYNOW|PSH_NOCONTEXTHELP; 
1243         propsh.hwndParent               = parent; 
1244         propsh.pszCaption               = "Item Properties";
1245         propsh.nPages                   = RVITEMPROPS_MAX;
1246         propsh.ppsp                             = (LPCPROPSHEETPAGE)&propsp;
1247         
1248         // Bring up the item properties dialog now
1249         result = PropertySheet ( &propsh ) != NULL;
1250         
1251         // Cleanup
1252         delete (rvGEItemPropsGeneralPage*) propsp[0].lParam;
1253         delete (rvGEItemPropsImagePage*) propsp[1].lParam;
1254         delete (rvGEItemPropsTextPage*) propsp[2].lParam;
1255         delete (rvGEItemPropsKeysPage*) propsp[3].lParam;
1256         
1257         return result;
1258 }
1259