2 ===========================================================================
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
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.
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.
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/>.
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.
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.
26 ===========================================================================
29 #include "../../idlib/precompiled.h"
32 #include "../../sys/win32/rc/guied_resource.h"
35 #include "GEProperties.h"
36 #include "GEWindowWrapper.h"
37 #include "GEStateModifier.h"
41 rvGEProperties::rvGEProperties
46 rvGEProperties::rvGEProperties( void )
55 rvGEProperties::Create
57 Create the property window as a child of the given window
60 bool rvGEProperties::Create ( HWND parent, bool visible )
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 );
73 mWnd = CreateWindowEx ( WS_EX_TOOLWINDOW,
74 "GUIEDITOR_PROPERTIES_CLASS",
76 WS_SYSMENU|WS_THICKFRAME|WS_CAPTION|WS_POPUP|WS_OVERLAPPED|WS_BORDER|WS_CLIPSIBLINGS|WS_CHILD,
88 if ( !gApp.GetOptions().GetWindowPlacement ( "properties", mWnd ) )
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),
99 SWP_NOZORDER|SWP_NOSIZE );
111 Show/Hide the properties window
114 void rvGEProperties::Show ( bool visible )
116 gApp.GetOptions().SetPropertiesVisible ( visible );
117 ShowWindow ( mWnd, visible?SW_SHOW:SW_HIDE );
122 rvGEProperties::Update
124 Update the properties in the window
127 void rvGEProperties::Update ( void )
131 if ( mWorkspace && mWorkspace->GetSelectionMgr ( ).Num ( ) == 1 )
133 mWrapper = rvGEWindowWrapper::GetWrapper ( mWorkspace->GetSelectionMgr()[0] );
140 ShowWindow ( mGrid.GetWindow ( ), mWrapper?SW_SHOW:SW_HIDE );
142 mGrid.RemoveAllItems ( );
146 for ( i = 0; i < (int)mWrapper->GetStateDict().GetNumKeyVals ( ); i ++ )
148 const idKeyValue* kv = mWrapper->GetStateDict().GetKeyVal ( i );
150 temp = kv->GetValue();
151 temp.StripQuotes ( );
152 mGrid.AddItem ( kv->GetKey(), temp );
159 rvGEProperties::AddModifier
161 Add a state modifier for the given key / value pair
164 bool rvGEProperties::AddModifier ( const char* name, const char* value )
170 if ( !mWrapper->VerfiyStateKey ( name, tempvalue ) )
175 if ( !mWrapper->VerfiyStateKey ( name, tempvalue ) )
177 gApp.MessageBox ( va("Invalid property value '%s' for property '%s'", value, name), MB_OK );
182 tempstate = mWrapper->GetStateDict ( );
184 tempstate.Set ( name, tempvalue );
186 mWorkspace->GetModifierStack().Append ( new rvGEStateModifier ( "Property Change", mWrapper->GetWindow(), tempstate ) );
187 mWorkspace->SetModified ( true );
188 gApp.GetNavigator().Update ( );
195 rvGEProperties::WndProc
197 Window Procedure for the properties window
200 LRESULT CALLBACK rvGEProperties::WndProc ( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
202 rvGEProperties* kv = (rvGEProperties*) GetWindowLong ( hWnd, GWL_USERDATA );
204 if ( kv && kv->mGrid.ReflectMessage ( hWnd, msg, wParam, lParam ) )
212 common->ActivateTool( LOWORD( wParam ) != WA_INACTIVE );
218 hdr = (NMHDR*)lParam;
219 if ( hdr->idFrom == 999 )
221 NMPROPGRID* nmpg = (NMPROPGRID*)hdr;
224 case PGN_ITEMCHANGED:
225 return (int)kv->AddModifier ( nmpg->mName, nmpg->mValue );
229 NMKEY* nmkey = (NMKEY*)hdr;
230 if ( nmkey->nVKey == VK_DELETE )
232 int sel = kv->mGrid.GetCurSel ( );
237 prop = kv->mGrid.GetItemName(sel);
238 if ( !idStr::Icmp ( prop, "rect" ) ||
239 !idStr::Icmp ( prop, "visible" ) ||
240 !idStr::Icmp ( prop, "name" ) )
242 MessageBeep ( MB_ICONASTERISK );
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 );
257 SendMessage ( gApp.GetMDIFrame(), WM_KEYDOWN, nmkey->nVKey, nmkey->uFlags );
271 // Attach the class to the window first
272 cs = (LPCREATESTRUCT) lParam;
273 kv = (rvGEProperties*) cs->lpCreateParams;
274 SetWindowLong ( hWnd, GWL_USERDATA, (LONG)kv );
276 kv->mGrid.Create ( hWnd, 999, PGS_ALLOWINSERT );
278 kv->SetWorkspace ( NULL );
292 kv->mGrid.Move ( 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE );
296 gApp.GetOptions().SetPropertiesVisible ( false );
301 return gApp.ToolWindowActivate ( hWnd, msg, wParam, lParam );
304 gApp.GetOptions().SetWindowPlacement ( "properties", hWnd );
308 return DefWindowProc ( hWnd, msg, wParam, lParam );