]> git.saurik.com Git - wxWidgets.git/blame - utils/framelayout/samples/demo/settingsdlg.cpp
fixed bug with the caret positioning after SetValue() introduced by the last commit
[wxWidgets.git] / utils / framelayout / samples / demo / settingsdlg.cpp
CommitLineData
bd9396d5
HH
1/////////////////////////////////////////////////////////////////////////////
2// Name: settingsdlg.cpp
3// Purpose: Settings dialog for Frame Layout
4// Author: Aleksandras Gluchovas
5// Modified by:
6// Created: 05/11/98
7// RCS-ID: $Id$
8// Copyright: (c) Aleksandras Gluchovas
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "settingsdlg.cpp"
14#pragma interface "settingsdlg.cpp"
15#endif
16
17// For compilers that support precompilation, includes "wx/wx.h".
18#include "wx/wxprec.h"
19
20#ifdef __BORLANDC__
21#pragma hdrstop
22#endif
23
24#ifndef WX_PRECOMP
25#include "wx/wx.h"
26#endif
27
28#include <stdlib.h>
29#include "settingsdlg.h"
30
31/***** Implementation for class SettingsDlg *****/
32
33#define ID_NOTES ( wxEVT_FIRST + 1000 )
34#define ID_HINTANIM_CHECK ( ID_NOTES + 1 )
35#define ID_RTUPDATES_CHECK ( ID_NOTES + 2 )
36
37BEGIN_EVENT_TABLE( SettingsDlg, wxDialog )
38
39 EVT_BUTTON( wxID_APPLY, SettingsDlg::OnApply )
40 EVT_BUTTON( ID_NOTES, SettingsDlg::OnNotes )
41
42 EVT_CHECKBOX( ID_HINTANIM_CHECK, SettingsDlg::OnHintAnimCheck )
43 EVT_CHECKBOX( ID_RTUPDATES_CHECK, SettingsDlg::OnRTUpdatesCheck )
44
45END_EVENT_TABLE()
46
47SettingsDlg::SettingsDlg( wxWindow* pParent )
48
49 : wxDialog( pParent, -1, "Active Layout Settings...",
50 wxDefaultPosition,
51 wxSize( 325,585),
52 wxDIALOG_MODAL | wxCAPTION )
53{
54 int curY = 10;
55 int lMargin = 50;
56 int lBoxMargin = lMargin - 20;
57 int checkHeight = 20;
58 int labelHeight = 20;
59 int boxWidth = 260;
60 int interBoxGap = 10;
61 int lastItemGap = 10;
62
63 int topY = curY;
64
65 curY += labelHeight;
66
67 mpRTU_Check = new wxCheckBox( this, ID_RTUPDATES_CHECK,
68 "&Real-time updates",
69 wxPoint( lMargin, curY ) );
70
71 curY += checkHeight;
72
73 mpOPD_Check = new wxCheckBox( this, -1, "&Out of Pane drag",
74 wxPoint( lMargin, curY ) );
75
76 curY += checkHeight;
77
78 mpEDP_Check = new wxCheckBox( this, -1, "&Exact docking prediction",
79 wxPoint( lMargin, curY ) );
80
81 curY += checkHeight;
82
83 mpNDF_Check = new wxCheckBox( this, -1, "Non-destructive bar &friction",
84 wxPoint( lMargin, curY ) );
85
86 curY += checkHeight;
87
88 mpSPB_Check = new wxCheckBox( this, -1, "&Shaded pane borders",
89 wxPoint( lMargin, curY ) );
90
91 curY += checkHeight + lastItemGap;
92
93 wxStaticBox* pDNDBox = new wxStaticBox( this, -1, "Drag && Drop settings",
94 wxPoint( lBoxMargin, topY ),
95 wxSize( boxWidth, curY - topY ) );
96
97 curY += interBoxGap;
98
99 ////////////////////////////////////////////////////////////////////
100
101 topY = curY;
102
103 curY += labelHeight;
104
105 mpHAP_Check = new wxCheckBox( this, ID_HINTANIM_CHECK,
106 "&Hint-Rect animation plugin",
107 wxPoint( lMargin, curY ) );
108
109 curY += checkHeight;
110
111 mpGCU_Check = new wxCheckBox( this, -1, "\"Garbage collecting\" &Updates-Mgr.",
112 wxPoint( lMargin, curY ) );
113
114 curY += checkHeight;
115
116 mpAFP_Check = new wxCheckBox( this, -1, "&Antiflicker plugin",
117 wxPoint( lMargin, curY ) );
118
119 curY += checkHeight;
120
121 mpCSP_Check = new wxCheckBox( this, -1, "C&ustomization plugin",
122 wxPoint( lMargin, curY ) );
123
124 curY += checkHeight + lastItemGap;
125
126 wxStaticBox* pPBox = new wxStaticBox( this, -1, "Plugins",
127 wxPoint( lBoxMargin, topY ),
128 wxSize( boxWidth, curY - topY ) );
129
130 curY += interBoxGap;
131
132 ////////////////////////////////////////////////////////////////////
133
134 wxSize fieldSz( 30,20 );
135 int fieldHeight = 20;
136 int fieldCapMargin = lMargin + fieldSz.x + 5;
137 int fieldCapOfs = 4;
138
139 topY = curY;
140
141 curY += labelHeight;
142
143 mpRWInput = new wxTextCtrl ( this, -1, "",
144 wxPoint( lMargin, curY ),
145 fieldSz );
146
147 mpRWLabel = new wxStaticText ( this, -1, "Resizing sash width(height)",
148 wxPoint( fieldCapMargin, curY + fieldCapOfs ) );
149
150
151 curY += fieldHeight;
152
153 mpPTMInput = new wxTextCtrl ( this, -1, "",
154 wxPoint( lMargin, curY ),
155 fieldSz );
156
157 mpPTMLabel = new wxStaticText( this, -1, "Pene's top margin",
158 wxPoint( fieldCapMargin, curY + fieldCapOfs ) );
159
160
161 curY += fieldHeight;
162
163
164 mpPBMInput = new wxTextCtrl ( this, -1, "",
165 wxPoint( lMargin, curY ),
166 fieldSz );
167
168 mpPBMLabel = new wxStaticText( this, -1, "Pene's bottom margin",
169 wxPoint( fieldCapMargin, curY + fieldCapOfs ) );
170
171
172 curY += fieldHeight;
173
174
175 mpPLMInput = new wxTextCtrl ( this, -1, "",
176 wxPoint( lMargin, curY ),
177 fieldSz );
178
179 mpPLMLabel = new wxStaticText( this, -1, "Pane's left margin",
180 wxPoint( fieldCapMargin, curY + fieldCapOfs ) );
181
182
183 curY += fieldHeight;
184
185
186 mpPRMInput = new wxTextCtrl ( this, -1, "",
187 wxPoint( lMargin, curY ),
188 fieldSz );
189
190 mpPRMLabel = new wxStaticText( this, -1, "Pane's right margin",
191 wxPoint( fieldCapMargin, curY + fieldCapOfs ) );
192
193 curY += fieldHeight + lastItemGap;
194
195 wxStaticBox* pCPPBox = new wxStaticBox( this, -1, "Common Pane properties",
196 wxPoint( lBoxMargin, topY ),
197 wxSize( boxWidth, curY - topY ) );
198
199 curY += interBoxGap;
200
201 ////////////////////////////////////////////////////////////////////
202
203 topY = curY;
204
205 curY += labelHeight;
206
207 fieldSz.x = 65;
208 fieldCapMargin = lMargin + fieldSz.x + 10;
209
210 mpDCInput = new wxTextCtrl ( this, -1, "",
211 wxPoint( lMargin, curY ),
212 fieldSz );
213
214 mpDCLabel = new wxStaticText ( this, -1, "Dark Color (hex-RGB)",
215 wxPoint( fieldCapMargin, curY + fieldCapOfs ) );
216
217 curY += fieldHeight;
218
219 mpLCInput = new wxTextCtrl ( this, -1, "",
220 wxPoint( lMargin, curY ),
221 fieldSz );
222
223 mpLCLabel = new wxStaticText ( this, -1, "Light Color (hex-RGB)",
224 wxPoint( fieldCapMargin, curY + fieldCapOfs ) );
225
226 curY += fieldHeight;
227
228 mpGCInput = new wxTextCtrl ( this, -1, "",
229 wxPoint( lMargin, curY ),
230 fieldSz );
231
232 mpGCLabel = new wxStaticText ( this, -1, "Gray Color (hex-RGB)",
233 wxPoint( fieldCapMargin, curY + fieldCapOfs ) );
234
235 curY += fieldHeight;
236
237 mpBCInput = new wxTextCtrl ( this, -1, "",
238 wxPoint( lMargin, curY ),
239 fieldSz );
240
241 mpBCLabel = new wxStaticText ( this, -1, "Pane border Color (hex-RGB)",
242 wxPoint( fieldCapMargin, curY + fieldCapOfs ) );
243
244 curY += fieldHeight + lastItemGap;
245
246 wxStaticBox* pCSPBox = new wxStaticBox( this, -1, "Coluor sheme properties",
247 wxPoint( lBoxMargin, topY ),
248 wxSize( boxWidth, curY - topY ) );
249
250 curY += interBoxGap; /*button ofs*/;
251
252 ////////////////////////////////////////////////////////////////////////////////
253
254 int lBtnMargin = 35;
255 int btnGap = 20;
256 int btnHeight = 22;
257 int btnWidth = 70;
258
259 wxButton* mpApplyBtn = new wxButton( this, wxID_APPLY, "A&pply",
260 wxPoint( lBtnMargin, curY ),
261 wxSize( btnWidth, btnHeight ) );
262
263 wxButton* mpCancelBtn = new wxButton( this, wxID_CANCEL, "&Cancel",
264 wxPoint( lBtnMargin + btnWidth + btnGap, curY ),
265 wxSize( btnWidth, btnHeight ) );
266
267 wxButton* mpNotesBtn = new wxButton( this, ID_NOTES, "&Notes...",
268 wxPoint( lBtnMargin + 2*btnWidth + 2*btnGap, curY ),
269 wxSize( btnWidth, btnHeight ) );
270
271 mpApplyBtn->SetDefault();
272 mpApplyBtn->SetFocus();
273
274 Center( wxBOTH );
275}
276
277void SettingsDlg::ExchangeFields( bool toDialog )
278{
279 mToDlg = toDialog;
280
281 ExchgCheck( mpRTU_Check, mRealTimeUpdatesOn );
282 ExchgCheck( mpOPD_Check, mOutOfPaneDragOn );
283 ExchgCheck( mpEDP_Check, mExactDockingPredictionOn );
284 ExchgCheck( mpNDF_Check, mNonDestructFrictionOn );
285 ExchgCheck( mpSPB_Check, m3DShadesOn );
286
287 ExchgCheck( mpHAP_Check, mHintRectAnimationOn );
288 ExchgCheck( mpGCU_Check, mGCUpdatesMgrOn );
289 ExchgCheck( mpAFP_Check, mAntiflickerPluginOn );
290 ExchgCheck( mpCSP_Check, mCustomizationPluginOn );
291
292 ExchgIntField( mpRWInput, mSashWidth );
293 ExchgIntField( mpPTMInput, mTopMargin );
294 ExchgIntField( mpPBMInput, mBottomMargin );
295 ExchgIntField( mpPLMInput, mLeftMargin );
296 ExchgIntField( mpPRMInput, mRightMargin );
297
298 ExchgColourField( mpDCInput, mDarkCol );
299 ExchgColourField( mpLCInput, mLightCol );
300 ExchgColourField( mpGCInput, mGrayCol );
301 ExchgColourField( mpBCInput, mBorderCol );
302}
303
304void SettingsDlg::OnApply( wxCommandEvent& event )
305{
306 ExchangeFields( FALSE );
307 EndModal( wxID_APPLY );
308}
309
310void SettingsDlg::OnNotes( wxCommandEvent& event )
311{
312 wxMessageBox("Notes go here...(TBD)");
313}
314
315void SettingsDlg::OnRTUpdatesCheck( wxCommandEvent& event )
316{
317 if ( mpRTU_Check->GetValue() == TRUE )
318 {
319 // user probably wants to see how the real-time drag & drop
320 // works -- so we "let 'im know" that animation is N/A when
321 // real-time option is on
322
323 mpHAP_Check->SetValue(FALSE);
324 mpHAP_Check->Refresh();
325 }
326}
327
328void SettingsDlg::OnHintAnimCheck( wxCommandEvent& event )
329{
330 if ( mpHAP_Check->GetValue() == TRUE )
331 {
332 // user probably wants to see some animation effects,
333 // but he/she forgot to turn off "real-time updates"
334 // setting -- so we do it for you :-)
335
336 mpRTU_Check->SetValue(FALSE);
337 mpRTU_Check->Refresh();
338 }
339}
340
341void SettingsDlg::ExchgCheck( wxCheckBox* pChk, bool& value )
342{
343 if ( mToDlg ) pChk->SetValue( value );
344
345 else value = pChk->GetValue();
346}
347
348void SettingsDlg::ExchgIntField( wxTextCtrl* pFld, int& value )
349{
350 if ( mToDlg )
351 {
352 char buf[32];
353
354 sprintf( buf, "%d", value );
355 pFld->SetValue( buf );
356 }
357 else
358 {
359 wxString txt = pFld->GetLineText( 0 );
360 value = atoi( txt );
361 }
362}
363
364void SettingsDlg::ExchgColourField( wxTextCtrl* pFld, wxColour& value )
365{
366 int rgbVal;
367
368 if ( mToDlg )
369 {
370 rgbVal = ( value.Red() & 0x0000FF ) |
371 ( (value.Green() << 8 ) & 0x00FF00 ) |
372 ( (value.Blue() << 16 ) & 0xFF0000 );
373
374 char buf[32];
375
376 sprintf( buf, "0x%06X", rgbVal );
377
378 pFld->SetValue( buf );
379 }
380 else
381 {
382 wxString txt = pFld->GetLineText( 0 );
383
384 sscanf( txt, "0x%06X", &rgbVal );
385
386 value.Set( rgbVal & 0xFF,
387 ( rgbVal >> 8 ) & 0xFF,
388 ( rgbVal >> 16 ) & 0xFF );
389 }
390}
391
392bool SettingsDlg::TransferDataToWindow()
393{
394 ExchangeFields( TRUE );
395
396 return TRUE;
397}
398
399bool SettingsDlg::TransferDataFromWindow()
400{
401 ExchangeFields( FALSE );
402
403 return TRUE;
404}
405
406#include "controlbar.h"
407#include "rowlayoutpl.h"
408#include "antiflickpl.h"
409#include "bardragpl.h"
410#include "cbcustom.h"
411
412#include "gcupdatesmgr.h"
413#include "hintanimpl.h"
414
415void SettingsDlg::ReadLayoutSettings( wxFrameLayout& fl )
416{
417 cbDockPane& pane = *fl.GetPane( wxTOP );
418 cbCommonPaneProperties& props = pane.mProps;
419
420 mRealTimeUpdatesOn = props.mRealTimeUpdatesOn;
421 mOutOfPaneDragOn = props.mOutOfPaneDragOn;
422 mExactDockingPredictionOn = props.mExactDockPredictionOn;
423 mNonDestructFrictionOn = props.mNonDestructFirctionOn;
424 m3DShadesOn = props.mShow3DPaneBorderOn;
425
426 mHintRectAnimationOn = fl.FindPlugin( CLASSINFO( cbHintAnimationPlugin ) ) != NULL;
427 mAntiflickerPluginOn = fl.FindPlugin( CLASSINFO( cbAntiflickerPlugin ) ) != NULL;
428 mCustomizationPluginOn = fl.FindPlugin( CLASSINFO( cbSimpleCustomizationPlugin ) ) != NULL;
429 mGCUpdatesMgrOn = fl.GetUpdatesManager().GetClassInfo()
430 == CLASSINFO( cbGCUpdatesMgr );
431
432 mSashWidth = props.mResizeHandleSize;
433
434 mTopMargin = pane.mTopMargin;
435 mBottomMargin = pane.mBottomMargin;
436 mLeftMargin = pane.mLeftMargin;
437 mRightMargin = pane.mRightMargin;
438
439 mDarkCol = fl.mDarkPen.GetColour();
440 mLightCol = fl.mLightPen.GetColour();
441 mGrayCol = fl.mGrayPen.GetColour();
442 mBorderCol = fl.mBorderPen.GetColour();
443}
444
445void SettingsDlg::ApplyLayoutSettings( wxFrameLayout& fl )
446{
447 cbCommonPaneProperties props;
448
449 props.mRealTimeUpdatesOn = mRealTimeUpdatesOn;
450 props.mOutOfPaneDragOn = mOutOfPaneDragOn;
451 props.mExactDockPredictionOn = mExactDockingPredictionOn;
452 props.mNonDestructFirctionOn = mNonDestructFrictionOn;
453 props.mShow3DPaneBorderOn = m3DShadesOn;
454
455 props.mResizeHandleSize = mSashWidth;
456
457 fl.SetPaneProperties( props, wxALL_PANES );
458
459 if ( mHintRectAnimationOn ) fl.AddPlugin ( CLASSINFO( cbHintAnimationPlugin ) );
460 else fl.RemovePlugin( CLASSINFO( cbHintAnimationPlugin ) );
461
462 if ( mAntiflickerPluginOn ) fl.AddPlugin ( CLASSINFO( cbAntiflickerPlugin ) );
463 else fl.RemovePlugin( CLASSINFO( cbAntiflickerPlugin ) );
464
465 if ( mCustomizationPluginOn ) fl.AddPlugin ( CLASSINFO( cbSimpleCustomizationPlugin ) );
466 else fl.RemovePlugin( CLASSINFO( cbSimpleCustomizationPlugin ) );
467
468 // FOR NOW:: unfortunatelly, currently pane marin-information is currently
469 // placed into cbDockPane, instead of cbCommonPaneProperties
470
471 fl.SetMargins( mTopMargin, mBottomMargin,
472 mLeftMargin, mRightMargin, wxALL_PANES );
473
474 fl.mDarkPen.SetColour( mDarkCol );
475 fl.mLightPen.SetColour( mLightCol );
476 fl.mGrayPen.SetColour( mGrayCol );
477 fl.mBorderPen.SetColour( mBorderCol );
478
479 fl.RecalcLayout( TRUE );
480
481 // NOTE:: currently it's bit tricky changing updates-manager
482 // in future, updates-manager will become a normal plugin
483 // and more convenient methods (Add/FindPlugin) will be used
484
485 if ( mGCUpdatesMgrOn &&
486 fl.GetUpdatesManager().GetClassInfo() != CLASSINFO( cbGCUpdatesMgr )
487 )
488
489 fl.SetUpdatesManager( new cbGCUpdatesMgr( &fl ) );
490 else
491 if ( !mGCUpdatesMgrOn &&
492 fl.GetUpdatesManager().GetClassInfo() == CLASSINFO( cbGCUpdatesMgr )
493 )
494
495 fl.SetUpdatesManager( new cbSimpleUpdatesMgr( &fl ) );
496}