doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GEProperties.cpp
Go to the documentation of this file.
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 
34 #include "GEApp.h"
35 #include "GEProperties.h"
36 #include "GEWindowWrapper.h"
37 #include "GEStateModifier.h"
38 
39 /*
40 ================
41 rvGEProperties::rvGEProperties
42 
43 constructor
44 ================
45 */
47 {
48  mWrapper = NULL;
49  mWnd = NULL;
50  mWorkspace = NULL;
51 }
52 
53 /*
54 ================
55 rvGEProperties::Create
56 
57 Create the property window as a child of the given window
58 ================
59 */
60 bool rvGEProperties::Create ( HWND parent, bool visible )
61 {
62  WNDCLASSEX wndClass;
63  memset ( &wndClass, 0, sizeof(wndClass) );
64  wndClass.cbSize = sizeof(WNDCLASSEX);
65  wndClass.lpszClassName = "GUIEDITOR_PROPERTIES_CLASS";
66  wndClass.lpfnWndProc = WndProc;
67  wndClass.hbrBackground = (HBRUSH)GetSysColorBrush ( COLOR_3DFACE );
68  wndClass.hCursor = LoadCursor((HINSTANCE) NULL, IDC_ARROW);
69  wndClass.lpszMenuName = NULL;
70  wndClass.hInstance = win32.hInstance;
71  RegisterClassEx ( &wndClass );
72 
73  mWnd = CreateWindowEx ( WS_EX_TOOLWINDOW,
74  "GUIEDITOR_PROPERTIES_CLASS",
75  "Properties",
76  WS_SYSMENU|WS_THICKFRAME|WS_CAPTION|WS_POPUP|WS_OVERLAPPED|WS_BORDER|WS_CLIPSIBLINGS|WS_CHILD,
77  0, 0, 200,300,
78  parent,
79  NULL,
81  this );
82 
83  if ( !mWnd )
84  {
85  return false;
86  }
87 
88  if ( !gApp.GetOptions().GetWindowPlacement ( "properties", mWnd ) )
89  {
90  RECT rParent;
91  RECT rClient;
92 
93  GetWindowRect ( parent, &rParent );
94  GetWindowRect ( mWnd, &rClient );
95  SetWindowPos ( mWnd, NULL,
96  rParent.right - 10 - (rClient.right-rClient.left),
97  rParent.bottom - 10 - (rClient.bottom-rClient.top),
98  0,0,
99  SWP_NOZORDER|SWP_NOSIZE );
100  }
101 
102  Show ( visible );
103 
104  return true;
105 }
106 
107 /*
108 ================
109 rvGEProperties::Show
110 
111 Show/Hide the properties window
112 ================
113 */
114 void rvGEProperties::Show ( bool visible )
115 {
116  gApp.GetOptions().SetPropertiesVisible ( visible );
117  ShowWindow ( mWnd, visible?SW_SHOW:SW_HIDE );
118 }
119 
120 /*
121 ================
122 rvGEProperties::Update
123 
124 Update the properties in the window
125 ================
126 */
128 {
129  int i;
130 
131  if ( mWorkspace && mWorkspace->GetSelectionMgr ( ).Num ( ) == 1 )
132  {
134  }
135  else
136  {
137  mWrapper = NULL;
138  }
139 
140  ShowWindow ( mGrid.GetWindow ( ), mWrapper?SW_SHOW:SW_HIDE );
141 
142  mGrid.RemoveAllItems ( );
143 
144  if ( mWrapper )
145  {
146  for ( i = 0; i < (int)mWrapper->GetStateDict().GetNumKeyVals ( ); i ++ )
147  {
148  const idKeyValue* kv = mWrapper->GetStateDict().GetKeyVal ( i );
149  idStr temp;
150  temp = kv->GetValue();
151  temp.StripQuotes ( );
152  mGrid.AddItem ( kv->GetKey(), temp );
153  }
154  }
155 }
156 
157 /*
158 ================
159 rvGEProperties::AddModifier
160 
161 Add a state modifier for the given key / value pair
162 ================
163 */
164 bool rvGEProperties::AddModifier ( const char* name, const char* value )
165 {
166  idDict tempstate;
167  idStr tempvalue;
168 
169  tempvalue = value;
170  if ( !mWrapper->VerfiyStateKey ( name, tempvalue ) )
171  {
172  tempvalue = "\"";
173  tempvalue += value;
174  tempvalue += "\"";
175  if ( !mWrapper->VerfiyStateKey ( name, tempvalue ) )
176  {
177  gApp.MessageBox ( va("Invalid property value '%s' for property '%s'", value, name), MB_OK );
178  return false;
179  }
180  }
181 
182  tempstate = mWrapper->GetStateDict ( );
183 
184  tempstate.Set ( name, tempvalue );
185 
186  mWorkspace->GetModifierStack().Append ( new rvGEStateModifier ( "Property Change", mWrapper->GetWindow(), tempstate ) );
187  mWorkspace->SetModified ( true );
188  gApp.GetNavigator().Update ( );
189 
190  return true;
191 }
192 
193 /*
194 ================
195 rvGEProperties::WndProc
196 
197 Window Procedure for the properties window
198 ================
199 */
200 LRESULT CALLBACK rvGEProperties::WndProc ( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
201 {
202  rvGEProperties* kv = (rvGEProperties*) GetWindowLong ( hWnd, GWL_USERDATA );
203 
204  if ( kv && kv->mGrid.ReflectMessage ( hWnd, msg, wParam, lParam ) )
205  {
206  return 0;
207  }
208 
209  switch ( msg )
210  {
211  case WM_ACTIVATE:
212  common->ActivateTool( LOWORD( wParam ) != WA_INACTIVE );
213  break;
214 
215  case WM_NOTIFY:
216  {
217  NMHDR* hdr;
218  hdr = (NMHDR*)lParam;
219  if ( hdr->idFrom == 999 )
220  {
221  NMPROPGRID* nmpg = (NMPROPGRID*)hdr;
222  switch ( hdr->code )
223  {
224  case PGN_ITEMCHANGED:
225  return (int)kv->AddModifier ( nmpg->mName, nmpg->mValue );
226 /*
227  case NM_KEYDOWN:
228  {
229  NMKEY* nmkey = (NMKEY*)hdr;
230  if ( nmkey->nVKey == VK_DELETE )
231  {
232  int sel = kv->mGrid.GetCurSel ( );
233  if ( sel != -1 )
234  {
235  const char* prop;
236 
237  prop = kv->mGrid.GetItemName(sel);
238  if ( !idStr::Icmp ( prop, "rect" ) ||
239  !idStr::Icmp ( prop, "visible" ) ||
240  !idStr::Icmp ( prop, "name" ) )
241  {
242  MessageBeep ( MB_ICONASTERISK );
243  }
244  else
245  {
246  idDict tempstate;
247  tempstate = kv->mWrapper->GetStateDict ( );
248  tempstate.Delete ( prop );
249  kv->mWorkspace->GetModifierStack().Append ( new rvGEStateModifier ( "Property Change", kv->mWrapper->GetWindow(), tempstate ) );
250  kv->mWorkspace->SetModified ( true );
251  kv->mGrid.RemoveItem ( sel );
252  }
253  }
254  }
255  else
256  {
257  SendMessage ( gApp.GetMDIFrame(), WM_KEYDOWN, nmkey->nVKey, nmkey->uFlags );
258  }
259  break;
260  }
261 */
262  }
263  }
264  break;
265  }
266 
267  case WM_CREATE:
268  {
269  LPCREATESTRUCT cs;
270 
271  // Attach the class to the window first
272  cs = (LPCREATESTRUCT) lParam;
273  kv = (rvGEProperties*) cs->lpCreateParams;
274  SetWindowLong ( hWnd, GWL_USERDATA, (LONG)kv );
275 
276  kv->mGrid.Create ( hWnd, 999, PGS_ALLOWINSERT );
277 
278  kv->SetWorkspace ( NULL );
279  kv->Update ( );
280 
281  break;
282  }
283 
284  case WM_ERASEBKGND:
285  if ( kv->mWrapper )
286  {
287  return FALSE;
288  }
289  break;
290 
291  case WM_SIZE:
292  kv->mGrid.Move ( 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE );
293  break;
294 
295  case WM_CLOSE:
297  kv->Show ( false );
298  return 0;
299 
300  case WM_NCACTIVATE:
301  return gApp.ToolWindowActivate ( hWnd, msg, wParam, lParam );
302 
303  case WM_DESTROY:
304  gApp.GetOptions().SetWindowPlacement ( "properties", hWnd );
305  break;
306  }
307 
308  return DefWindowProc ( hWnd, msg, wParam, lParam );
309 }
310 
311 
const char * mName
Definition: PropertyGrid.h:41
GLsizei const GLfloat * value
Definition: glext.h:3614
CONST PIXELFORMATDESCRIPTOR UINT
Definition: win_qgl.cpp:47
const idStr & GetKey(void) const
Definition: Dict.h:52
idStr & StripQuotes(void)
Definition: Str.cpp:665
void SetWindowPlacement(const char *name, HWND hwnd)
Definition: GEOptions.h:288
rvGEWorkspace * mWorkspace
Definition: GEProperties.h:63
void Show(bool visibile)
void RemoveAllItems(void)
case const int
Definition: Callbacks.cpp:52
void Update(void)
rvGEWindowWrapper * mWrapper
Definition: GEProperties.h:62
HWND GetWindow(void)
Definition: PropertyGrid.h:107
void SetModified(bool mod)
bool GetWindowPlacement(const char *name, HWND hwnd)
Definition: GEOptions.h:293
void Move(int x, int y, int w, int h, BOOL redraw=FALSE)
void Set(const char *key, const char *value)
Definition: Dict.cpp:275
int i
Definition: process.py:33
idDict & GetStateDict(void)
const char * mValue
Definition: PropertyGrid.h:42
rvGEApp gApp
Definition: guied.cpp:41
bool Create(HWND parent, int id, int style=0)
void SetPropertiesVisible(bool vis)
Definition: GEOptions.h:196
int AddItem(const char *name, const char *value, EItemType type=PGIT_STRING)
rvGEModifierStack & GetModifierStack(void)
Definition: GEWorkspace.h:288
rvGEOptions & GetOptions(void)
Definition: GEApp.h:163
#define PGS_ALLOWINSERT
Definition: PropertyGrid.h:35
void Update(void)
idCommon * common
Definition: Common.cpp:206
bool AddModifier(const char *name, const char *value)
Definition: Dict.h:65
#define NULL
Definition: Lib.h:88
bool Create(HWND parent, bool visible)
#define PGN_ITEMCHANGED
Definition: PropertyGrid.h:32
bool VerfiyStateKey(const char *name, const char *value, idStr *result=NULL)
int MessageBox(const char *text, int flags)
Definition: GEApp.cpp:1380
const idStr & GetValue(void) const
Definition: Dict.h:53
bool ReflectMessage(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
rvGESelectionMgr & GetSelectionMgr(void)
Definition: GEWorkspace.h:293
void SetWorkspace(rvGEWorkspace *workspace)
Definition: GEProperties.h:71
int ToolWindowActivate(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: GEApp.cpp:1335
long LONG
rvGENavigator & GetNavigator(void)
Definition: GEApp.h:148
static rvGEWindowWrapper * GetWrapper(idWindow *window)
idWindow * GetWindow(void)
bool Append(rvGEModifier *modifier)
const GLcharARB * name
Definition: glext.h:3629
Definition: Str.h:116
static LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
rvPropertyGrid mGrid
Definition: GEProperties.h:61
#define FALSE
Definition: mprintf.c:70
const idKeyValue * GetKeyVal(int index) const
Definition: Dict.h:294
#define TRUE
Definition: mprintf.c:69
HINSTANCE hInstance
Definition: win_local.h:102
char * va(const char *fmt,...)
Definition: Str.cpp:1568
Win32Vars_t win32
Definition: win_main.cpp:65
int GetNumKeyVals(void) const
Definition: Dict.h:290
virtual void ActivateTool(bool active)=0