]>
Commit | Line | Data |
---|---|---|
1c4293cb VZ |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: src/propgrid/propgrid.cpp | |
3 | // Purpose: wxPropertyGrid | |
4 | // Author: Jaakko Salli | |
5 | // Modified by: | |
6 | // Created: 2004-09-25 | |
ea5af9c5 | 7 | // RCS-ID: $Id$ |
1c4293cb VZ |
8 | // Copyright: (c) Jaakko Salli |
9 | // Licence: wxWindows license | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // For compilers that support precompilation, includes "wx/wx.h". | |
13 | #include "wx/wxprec.h" | |
14 | ||
15 | #ifdef __BORLANDC__ | |
16 | #pragma hdrstop | |
17 | #endif | |
18 | ||
f4bc1aa2 JS |
19 | #if wxUSE_PROPGRID |
20 | ||
1c4293cb VZ |
21 | #ifndef WX_PRECOMP |
22 | #include "wx/defs.h" | |
23 | #include "wx/object.h" | |
24 | #include "wx/hash.h" | |
25 | #include "wx/string.h" | |
26 | #include "wx/log.h" | |
27 | #include "wx/event.h" | |
28 | #include "wx/window.h" | |
29 | #include "wx/panel.h" | |
30 | #include "wx/dc.h" | |
31 | #include "wx/dcmemory.h" | |
32 | #include "wx/button.h" | |
33 | #include "wx/pen.h" | |
34 | #include "wx/brush.h" | |
35 | #include "wx/cursor.h" | |
36 | #include "wx/dialog.h" | |
37 | #include "wx/settings.h" | |
38 | #include "wx/msgdlg.h" | |
39 | #include "wx/choice.h" | |
40 | #include "wx/stattext.h" | |
41 | #include "wx/scrolwin.h" | |
42 | #include "wx/dirdlg.h" | |
1c4293cb VZ |
43 | #include "wx/sizer.h" |
44 | #include "wx/textdlg.h" | |
45 | #include "wx/filedlg.h" | |
46 | #include "wx/statusbr.h" | |
47 | #include "wx/intl.h" | |
48 | #include "wx/frame.h" | |
49 | #endif | |
50 | ||
51 | ||
52 | // This define is necessary to prevent macro clearing | |
53 | #define __wxPG_SOURCE_FILE__ | |
54 | ||
3b211af1 SC |
55 | #include "wx/propgrid/propgrid.h" |
56 | #include "wx/propgrid/editors.h" | |
1c4293cb VZ |
57 | |
58 | #if wxPG_USE_RENDERER_NATIVE | |
3b211af1 | 59 | #include "wx/renderer.h" |
1c4293cb VZ |
60 | #endif |
61 | ||
3b211af1 | 62 | #include "wx/odcombo.h" |
1c4293cb VZ |
63 | |
64 | #include "wx/timer.h" | |
65 | #include "wx/dcbuffer.h" | |
1c4293cb VZ |
66 | |
67 | #ifdef __WXMSW__ | |
3b211af1 | 68 | #include "wx/msw/private.h" |
1c4293cb VZ |
69 | #endif |
70 | ||
1c4293cb VZ |
71 | // Two pics for the expand / collapse buttons. |
72 | // Files are not supplied with this project (since it is | |
73 | // recommended to use either custom or native rendering). | |
74 | // If you want them, get wxTreeMultiCtrl by Jorgen Bodde, | |
75 | // and copy xpm files from archive to wxPropertyGrid src directory | |
76 | // (and also comment/undef wxPG_ICON_WIDTH in propGrid.h | |
77 | // and set wxPG_USE_RENDERER_NATIVE to 0). | |
78 | #ifndef wxPG_ICON_WIDTH | |
79 | #if defined(__WXMAC__) | |
80 | #include "mac_collapse.xpm" | |
81 | #include "mac_expand.xpm" | |
82 | #elif defined(__WXGTK__) | |
83 | #include "linux_collapse.xpm" | |
84 | #include "linux_expand.xpm" | |
85 | #else | |
86 | #include "default_collapse.xpm" | |
87 | #include "default_expand.xpm" | |
88 | #endif | |
89 | #endif | |
90 | ||
91 | ||
92 | //#define wxPG_TEXT_INDENT 4 // For the wxComboControl | |
b7bc9d80 | 93 | //#define wxPG_ALLOW_CLIPPING 1 // If 1, GetUpdateRegion() in OnPaint event handler is not ignored |
1c4293cb VZ |
94 | #define wxPG_GUTTER_DIV 3 // gutter is max(iconwidth/gutter_div,gutter_min) |
95 | #define wxPG_GUTTER_MIN 3 // gutter before and after image of [+] or [-] | |
96 | #define wxPG_YSPACING_MIN 1 | |
97 | #define wxPG_DEFAULT_VSPACING 2 // This matches .NET propertygrid's value, | |
98 | // but causes normal combobox to spill out under MSW | |
99 | ||
b7bc9d80 | 100 | //#define wxPG_OPTIMAL_WIDTH 200 // Arbitrary |
1c4293cb | 101 | |
b7bc9d80 | 102 | //#define wxPG_MIN_SCROLLBAR_WIDTH 10 // Smallest scrollbar width on any platform |
1c4293cb VZ |
103 | // Must be larger than largest control border |
104 | // width * 2. | |
105 | ||
106 | ||
107 | #define wxPG_DEFAULT_CURSOR wxNullCursor | |
108 | ||
109 | ||
110 | //#define wxPG_NAT_CHOICE_BORDER_ANY 0 | |
111 | ||
b7bc9d80 | 112 | //#define wxPG_HIDER_BUTTON_HEIGHT 25 |
1c4293cb VZ |
113 | |
114 | #define wxPG_PIXELS_PER_UNIT m_lineHeight | |
115 | ||
116 | #ifdef wxPG_ICON_WIDTH | |
117 | #define m_iconHeight m_iconWidth | |
118 | #endif | |
119 | ||
b7bc9d80 | 120 | //#define wxPG_TOOLTIP_DELAY 1000 |
1c4293cb VZ |
121 | |
122 | // ----------------------------------------------------------------------- | |
123 | ||
124 | #if wxUSE_INTL | |
125 | void wxPropertyGrid::AutoGetTranslation ( bool enable ) | |
126 | { | |
127 | wxPGGlobalVars->m_autoGetTranslation = enable; | |
128 | } | |
129 | #else | |
130 | void wxPropertyGrid::AutoGetTranslation ( bool ) { } | |
131 | #endif | |
132 | ||
133 | // ----------------------------------------------------------------------- | |
134 | ||
23318a53 | 135 | const char wxPropertyGridNameStr[] = "wxPropertyGrid"; |
1c4293cb VZ |
136 | |
137 | // ----------------------------------------------------------------------- | |
138 | // Statics in one class for easy destruction. | |
1c4293cb VZ |
139 | // ----------------------------------------------------------------------- |
140 | ||
3b211af1 | 141 | #include "wx/module.h" |
1c4293cb VZ |
142 | |
143 | class wxPGGlobalVarsClassManager : public wxModule | |
144 | { | |
145 | DECLARE_DYNAMIC_CLASS(wxPGGlobalVarsClassManager) | |
146 | public: | |
147 | wxPGGlobalVarsClassManager() {} | |
148 | virtual bool OnInit() { wxPGGlobalVars = new wxPGGlobalVarsClass(); return true; } | |
149 | virtual void OnExit() { delete wxPGGlobalVars; wxPGGlobalVars = NULL; } | |
150 | }; | |
151 | ||
152 | IMPLEMENT_DYNAMIC_CLASS(wxPGGlobalVarsClassManager, wxModule) | |
153 | ||
1c4293cb | 154 | |
b512ed93 JS |
155 | // When wxPG is loaded dynamically after the application is already running |
156 | // then the built-in module system won't pick this one up. Add it manually. | |
157 | void wxPGInitResourceModule() | |
158 | { | |
159 | wxModule* module = new wxPGGlobalVarsClassManager; | |
160 | module->Init(); | |
161 | wxModule::RegisterModule(module); | |
162 | } | |
163 | ||
d3b9f782 | 164 | wxPGGlobalVarsClass* wxPGGlobalVars = NULL; |
1c4293cb VZ |
165 | |
166 | ||
167 | wxPGGlobalVarsClass::wxPGGlobalVarsClass() | |
168 | { | |
169 | wxPGProperty::sm_wxPG_LABEL = new wxString(wxPG_LABEL_STRING); | |
170 | ||
171 | m_boolChoices.Add(_("False")); | |
172 | m_boolChoices.Add(_("True")); | |
173 | ||
d3b9f782 | 174 | m_fontFamilyChoices = NULL; |
1c4293cb VZ |
175 | |
176 | m_defaultRenderer = new wxPGDefaultRenderer(); | |
177 | ||
178 | m_autoGetTranslation = false; | |
179 | ||
180 | m_offline = 0; | |
181 | ||
182 | m_extraStyle = 0; | |
183 | ||
184 | wxVariant v; | |
185 | ||
657a8a35 | 186 | // Prepare some shared variants |
1c4293cb VZ |
187 | m_vEmptyString = wxString(); |
188 | m_vZero = (long) 0; | |
189 | m_vMinusOne = (long) -1; | |
190 | m_vTrue = true; | |
191 | m_vFalse = false; | |
192 | ||
193 | // Prepare cached string constants | |
0372d42e JS |
194 | m_strstring = wxS("string"); |
195 | m_strlong = wxS("long"); | |
196 | m_strbool = wxS("bool"); | |
197 | m_strlist = wxS("list"); | |
0ce8e27f | 198 | m_strDefaultValue = wxS("DefaultValue"); |
1c4293cb VZ |
199 | m_strMin = wxS("Min"); |
200 | m_strMax = wxS("Max"); | |
201 | m_strUnits = wxS("Units"); | |
202 | m_strInlineHelp = wxS("InlineHelp"); | |
203 | ||
1c4293cb | 204 | m_warnings = 0; |
1c4293cb VZ |
205 | } |
206 | ||
207 | ||
208 | wxPGGlobalVarsClass::~wxPGGlobalVarsClass() | |
209 | { | |
210 | size_t i; | |
211 | ||
212 | delete m_defaultRenderer; | |
213 | ||
214 | // This will always have one ref | |
215 | delete m_fontFamilyChoices; | |
216 | ||
217 | #if wxUSE_VALIDATORS | |
218 | for ( i=0; i<m_arrValidators.size(); i++ ) | |
219 | delete ((wxValidator*)m_arrValidators[i]); | |
220 | #endif | |
221 | ||
222 | // | |
223 | // Destroy value type class instances. | |
224 | wxPGHashMapS2P::iterator vt_it; | |
225 | ||
226 | // Destroy editor class instances. | |
227 | // iterate over all the elements in the class | |
228 | for( vt_it = m_mapEditorClasses.begin(); vt_it != m_mapEditorClasses.end(); ++vt_it ) | |
229 | { | |
230 | delete ((wxPGEditor*)vt_it->second); | |
231 | } | |
232 | ||
233 | delete wxPGProperty::sm_wxPG_LABEL; | |
234 | } | |
235 | ||
c8074be0 JS |
236 | void wxPropertyGridInitGlobalsIfNeeded() |
237 | { | |
238 | } | |
239 | ||
1c4293cb VZ |
240 | // ----------------------------------------------------------------------- |
241 | // wxPGCanvas | |
242 | // ----------------------------------------------------------------------- | |
243 | ||
244 | // | |
245 | // wxPGCanvas acts as a graphics sub-window of the | |
246 | // wxScrolledWindow that wxPropertyGrid is. | |
247 | // | |
248 | class wxPGCanvas : public wxPanel | |
249 | { | |
250 | public: | |
251 | wxPGCanvas() : wxPanel() | |
252 | { | |
253 | } | |
254 | virtual ~wxPGCanvas() { } | |
255 | ||
256 | protected: | |
257 | void OnMouseMove( wxMouseEvent &event ) | |
258 | { | |
259 | wxPropertyGrid* pg = wxStaticCast(GetParent(), wxPropertyGrid); | |
260 | pg->OnMouseMove( event ); | |
261 | } | |
262 | ||
263 | void OnMouseClick( wxMouseEvent &event ) | |
264 | { | |
265 | wxPropertyGrid* pg = wxStaticCast(GetParent(), wxPropertyGrid); | |
266 | pg->OnMouseClick( event ); | |
267 | } | |
268 | ||
269 | void OnMouseUp( wxMouseEvent &event ) | |
270 | { | |
271 | wxPropertyGrid* pg = wxStaticCast(GetParent(), wxPropertyGrid); | |
272 | pg->OnMouseUp( event ); | |
273 | } | |
274 | ||
275 | void OnMouseRightClick( wxMouseEvent &event ) | |
276 | { | |
277 | wxPropertyGrid* pg = wxStaticCast(GetParent(), wxPropertyGrid); | |
278 | pg->OnMouseRightClick( event ); | |
279 | } | |
280 | ||
281 | void OnMouseDoubleClick( wxMouseEvent &event ) | |
282 | { | |
283 | wxPropertyGrid* pg = wxStaticCast(GetParent(), wxPropertyGrid); | |
284 | pg->OnMouseDoubleClick( event ); | |
285 | } | |
286 | ||
287 | void OnKey( wxKeyEvent& event ) | |
288 | { | |
289 | wxPropertyGrid* pg = wxStaticCast(GetParent(), wxPropertyGrid); | |
290 | pg->OnKey( event ); | |
291 | } | |
292 | ||
1c4293cb | 293 | void OnPaint( wxPaintEvent& event ); |
23318a53 | 294 | |
7a809222 RR |
295 | // Always be focussable, even with child windows |
296 | virtual void SetCanFocus(bool WXUNUSED(canFocus)) | |
297 | { wxPanel::SetCanFocus(true); } | |
23318a53 | 298 | |
7a809222 | 299 | |
1c4293cb VZ |
300 | private: |
301 | DECLARE_EVENT_TABLE() | |
1e6935a6 | 302 | DECLARE_ABSTRACT_CLASS(wxPGCanvas) |
1c4293cb VZ |
303 | }; |
304 | ||
305 | ||
1e6935a6 RR |
306 | IMPLEMENT_ABSTRACT_CLASS(wxPGCanvas,wxPanel) |
307 | ||
1c4293cb VZ |
308 | BEGIN_EVENT_TABLE(wxPGCanvas, wxPanel) |
309 | EVT_MOTION(wxPGCanvas::OnMouseMove) | |
310 | EVT_PAINT(wxPGCanvas::OnPaint) | |
311 | EVT_LEFT_DOWN(wxPGCanvas::OnMouseClick) | |
312 | EVT_LEFT_UP(wxPGCanvas::OnMouseUp) | |
313 | EVT_RIGHT_UP(wxPGCanvas::OnMouseRightClick) | |
314 | EVT_LEFT_DCLICK(wxPGCanvas::OnMouseDoubleClick) | |
315 | EVT_KEY_DOWN(wxPGCanvas::OnKey) | |
1c4293cb VZ |
316 | END_EVENT_TABLE() |
317 | ||
318 | ||
319 | void wxPGCanvas::OnPaint( wxPaintEvent& WXUNUSED(event) ) | |
320 | { | |
321 | wxPropertyGrid* pg = wxStaticCast(GetParent(), wxPropertyGrid); | |
322 | wxASSERT( pg->IsKindOf(CLASSINFO(wxPropertyGrid)) ); | |
323 | ||
324 | wxPaintDC dc(this); | |
325 | ||
326 | // Don't paint after destruction has begun | |
327 | if ( !(pg->GetInternalFlags() & wxPG_FL_INITIALIZED) ) | |
328 | return; | |
329 | ||
330 | // Update everything inside the box | |
331 | wxRect r = GetUpdateRegion().GetBox(); | |
58fbf261 JS |
332 | |
333 | // FIXME: This is just a workaround for a bug that causes splitters not | |
334 | // to paint when other windows are being dragged over the grid. | |
335 | wxRect fullRect = GetRect(); | |
336 | r.x = fullRect.x; | |
337 | r.width = fullRect.width; | |
1c4293cb VZ |
338 | |
339 | // Repaint this rectangle | |
340 | pg->DrawItems( dc, r.y, r.y + r.height, &r ); | |
341 | ||
342 | // We assume that the size set when grid is shown | |
343 | // is what is desired. | |
344 | pg->SetInternalFlag(wxPG_FL_GOOD_SIZE_SET); | |
345 | } | |
346 | ||
347 | // ----------------------------------------------------------------------- | |
348 | // wxPropertyGrid | |
349 | // ----------------------------------------------------------------------- | |
350 | ||
351 | IMPLEMENT_DYNAMIC_CLASS(wxPropertyGrid, wxScrolledWindow) | |
352 | ||
353 | BEGIN_EVENT_TABLE(wxPropertyGrid, wxScrolledWindow) | |
354 | EVT_IDLE(wxPropertyGrid::OnIdle) | |
355 | EVT_MOTION(wxPropertyGrid::OnMouseMoveBottom) | |
356 | EVT_PAINT(wxPropertyGrid::OnPaint) | |
357 | EVT_SIZE(wxPropertyGrid::OnResize) | |
358 | EVT_ENTER_WINDOW(wxPropertyGrid::OnMouseEntry) | |
359 | EVT_LEAVE_WINDOW(wxPropertyGrid::OnMouseEntry) | |
360 | EVT_MOUSE_CAPTURE_CHANGED(wxPropertyGrid::OnCaptureChange) | |
361 | EVT_SCROLLWIN(wxPropertyGrid::OnScrollEvent) | |
362 | EVT_CHILD_FOCUS(wxPropertyGrid::OnChildFocusEvent) | |
363 | EVT_SET_FOCUS(wxPropertyGrid::OnFocusEvent) | |
364 | EVT_KILL_FOCUS(wxPropertyGrid::OnFocusEvent) | |
1c4293cb VZ |
365 | EVT_SYS_COLOUR_CHANGED(wxPropertyGrid::OnSysColourChanged) |
366 | END_EVENT_TABLE() | |
367 | ||
368 | ||
369 | // ----------------------------------------------------------------------- | |
370 | ||
371 | wxPropertyGrid::wxPropertyGrid() | |
372 | : wxScrolledWindow() | |
373 | { | |
374 | Init1(); | |
375 | } | |
376 | ||
377 | // ----------------------------------------------------------------------- | |
378 | ||
379 | wxPropertyGrid::wxPropertyGrid( wxWindow *parent, | |
380 | wxWindowID id, | |
381 | const wxPoint& pos, | |
382 | const wxSize& size, | |
383 | long style, | |
23318a53 | 384 | const wxString& name ) |
1c4293cb VZ |
385 | : wxScrolledWindow() |
386 | { | |
387 | Init1(); | |
388 | Create(parent,id,pos,size,style,name); | |
389 | } | |
390 | ||
391 | // ----------------------------------------------------------------------- | |
392 | ||
393 | bool wxPropertyGrid::Create( wxWindow *parent, | |
394 | wxWindowID id, | |
395 | const wxPoint& pos, | |
396 | const wxSize& size, | |
397 | long style, | |
23318a53 | 398 | const wxString& name ) |
1c4293cb VZ |
399 | { |
400 | ||
401 | if ( !(style&wxBORDER_MASK) ) | |
402 | style |= wxSIMPLE_BORDER; | |
403 | ||
404 | style |= wxVSCROLL; | |
405 | ||
68f9e025 JS |
406 | // Filter out wxTAB_TRAVERSAL - we will handle TABs manually |
407 | style &= ~(wxTAB_TRAVERSAL); | |
408 | style |= wxWANTS_CHARS; | |
1c4293cb VZ |
409 | |
410 | wxScrolledWindow::Create(parent,id,pos,size,style,name); | |
411 | ||
412 | Init2(); | |
413 | ||
414 | return true; | |
415 | } | |
416 | ||
417 | // ----------------------------------------------------------------------- | |
418 | ||
419 | // | |
420 | // Initialize values to defaults | |
421 | // | |
422 | void wxPropertyGrid::Init1() | |
423 | { | |
1c4293cb VZ |
424 | // Register editor classes, if necessary. |
425 | if ( wxPGGlobalVars->m_mapEditorClasses.empty() ) | |
c8074be0 | 426 | wxPropertyGrid::RegisterDefaultEditors(); |
1c4293cb VZ |
427 | |
428 | m_iFlags = 0; | |
d3b9f782 VZ |
429 | m_pState = NULL; |
430 | m_wndEditor = m_wndEditor2 = NULL; | |
431 | m_selected = NULL; | |
1c4293cb | 432 | m_selColumn = -1; |
d3b9f782 | 433 | m_propHover = NULL; |
1c4293cb | 434 | m_eventObject = this; |
d3b9f782 | 435 | m_curFocused = NULL; |
43396981 | 436 | m_sortFunction = NULL; |
1c4293cb VZ |
437 | m_inDoPropertyChanged = 0; |
438 | m_inCommitChangesFromEditor = 0; | |
439 | m_inDoSelectProperty = 0; | |
440 | m_permanentValidationFailureBehavior = wxPG_VFB_DEFAULT; | |
441 | m_dragStatus = 0; | |
442 | m_mouseSide = 16; | |
443 | m_editorFocused = 0; | |
444 | ||
445 | // Set default keys | |
446 | AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY, WXK_RIGHT ); | |
447 | AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY, WXK_DOWN ); | |
448 | AddActionTrigger( wxPG_ACTION_PREV_PROPERTY, WXK_LEFT ); | |
449 | AddActionTrigger( wxPG_ACTION_PREV_PROPERTY, WXK_UP ); | |
450 | AddActionTrigger( wxPG_ACTION_EXPAND_PROPERTY, WXK_RIGHT); | |
451 | AddActionTrigger( wxPG_ACTION_COLLAPSE_PROPERTY, WXK_LEFT); | |
452 | AddActionTrigger( wxPG_ACTION_CANCEL_EDIT, WXK_ESCAPE ); | |
1766bf34 | 453 | AddActionTrigger( wxPG_ACTION_PRESS_BUTTON, WXK_DOWN, wxMOD_ALT ); |
cfb97361 | 454 | AddActionTrigger( wxPG_ACTION_PRESS_BUTTON, WXK_F4 ); |
1c4293cb VZ |
455 | |
456 | m_coloursCustomized = 0; | |
457 | m_frozen = 0; | |
458 | ||
459 | m_canvas = NULL; | |
460 | ||
461 | #if wxPG_DOUBLE_BUFFER | |
d3b9f782 | 462 | m_doubleBuffer = NULL; |
1c4293cb VZ |
463 | #endif |
464 | ||
1c4293cb | 465 | #ifndef wxPG_ICON_WIDTH |
657a8a35 VZ |
466 | m_expandbmp = NULL; |
467 | m_collbmp = NULL; | |
468 | m_iconWidth = 11; | |
469 | m_iconHeight = 11; | |
1c4293cb VZ |
470 | #else |
471 | m_iconWidth = wxPG_ICON_WIDTH; | |
472 | #endif | |
473 | ||
474 | m_prevVY = -1; | |
475 | ||
476 | m_gutterWidth = wxPG_GUTTER_MIN; | |
477 | m_subgroup_extramargin = 10; | |
478 | ||
479 | m_lineHeight = 0; | |
480 | ||
481 | m_width = m_height = 0; | |
482 | ||
1c4293cb VZ |
483 | m_commonValues.push_back(new wxPGCommonValue(_("Unspecified"), wxPGGlobalVars->m_defaultRenderer) ); |
484 | m_cvUnspecified = 0; | |
485 | ||
486 | m_chgInfo_changedProperty = NULL; | |
487 | } | |
488 | ||
489 | // ----------------------------------------------------------------------- | |
490 | ||
491 | // | |
492 | // Initialize after parent etc. set | |
493 | // | |
494 | void wxPropertyGrid::Init2() | |
495 | { | |
496 | wxASSERT( !(m_iFlags & wxPG_FL_INITIALIZED ) ); | |
497 | ||
498 | #ifdef __WXMAC__ | |
499 | // Smaller controls on Mac | |
500 | SetWindowVariant(wxWINDOW_VARIANT_SMALL); | |
23318a53 | 501 | #endif |
1c4293cb VZ |
502 | |
503 | // Now create state, if one didn't exist already | |
504 | // (wxPropertyGridManager might have created it for us). | |
505 | if ( !m_pState ) | |
506 | { | |
507 | m_pState = CreateState(); | |
508 | m_pState->m_pPropGrid = this; | |
509 | m_iFlags |= wxPG_FL_CREATEDSTATE; | |
510 | } | |
511 | ||
512 | if ( !(m_windowStyle & wxPG_SPLITTER_AUTO_CENTER) ) | |
513 | m_iFlags |= wxPG_FL_DONT_CENTER_SPLITTER; | |
514 | ||
515 | if ( m_windowStyle & wxPG_HIDE_CATEGORIES ) | |
516 | { | |
517 | m_pState->InitNonCatMode(); | |
518 | ||
519 | m_pState->m_properties = m_pState->m_abcArray; | |
520 | } | |
521 | ||
522 | GetClientSize(&m_width,&m_height); | |
523 | ||
524 | #ifndef wxPG_ICON_WIDTH | |
525 | // create two bitmap nodes for drawing | |
657a8a35 VZ |
526 | m_expandbmp = new wxBitmap(expand_xpm); |
527 | m_collbmp = new wxBitmap(collapse_xpm); | |
1c4293cb | 528 | |
657a8a35 | 529 | // calculate average font height for bitmap centering |
1c4293cb | 530 | |
657a8a35 VZ |
531 | m_iconWidth = m_expandbmp->GetWidth(); |
532 | m_iconHeight = m_expandbmp->GetHeight(); | |
1c4293cb VZ |
533 | #endif |
534 | ||
535 | m_curcursor = wxCURSOR_ARROW; | |
536 | m_cursorSizeWE = new wxCursor( wxCURSOR_SIZEWE ); | |
537 | ||
657a8a35 | 538 | // adjust bitmap icon y position so they are centered |
1c4293cb VZ |
539 | m_vspacing = wxPG_DEFAULT_VSPACING; |
540 | ||
2197ec80 | 541 | CalculateFontAndBitmapStuff( wxPG_DEFAULT_VSPACING ); |
1c4293cb | 542 | |
d7e2b522 JS |
543 | // Allocate cell datas indirectly by calling setter |
544 | m_propertyDefaultCell.SetBgCol(*wxBLACK); | |
545 | m_categoryDefaultCell.SetBgCol(*wxBLACK); | |
1c4293cb VZ |
546 | |
547 | RegainColours(); | |
548 | ||
549 | // This helps with flicker | |
550 | SetBackgroundStyle( wxBG_STYLE_CUSTOM ); | |
551 | ||
27c1f235 JS |
552 | // Hook the top-level parent |
553 | m_tlp = NULL; | |
554 | OnTLPChanging(NULL); | |
1c4293cb | 555 | |
657a8a35 | 556 | // set virtual size to this window size |
1c4293cb | 557 | wxSize wndsize = GetSize(); |
657a8a35 | 558 | SetVirtualSize(wndsize.GetWidth(), wndsize.GetWidth()); |
1c4293cb VZ |
559 | |
560 | m_timeCreated = ::wxGetLocalTimeMillis(); | |
561 | ||
562 | m_canvas = new wxPGCanvas(); | |
563 | m_canvas->Create(this, 1, wxPoint(0, 0), GetClientSize(), | |
68f9e025 | 564 | wxWANTS_CHARS | wxCLIP_CHILDREN); |
1c4293cb VZ |
565 | m_canvas->SetBackgroundStyle( wxBG_STYLE_CUSTOM ); |
566 | ||
567 | m_iFlags |= wxPG_FL_INITIALIZED; | |
568 | ||
569 | m_ncWidth = wndsize.GetWidth(); | |
570 | ||
571 | // Need to call OnResize handler or size given in constructor/Create | |
572 | // will never work. | |
573 | wxSizeEvent sizeEvent(wndsize,0); | |
574 | OnResize(sizeEvent); | |
575 | } | |
576 | ||
577 | // ----------------------------------------------------------------------- | |
578 | ||
579 | wxPropertyGrid::~wxPropertyGrid() | |
580 | { | |
581 | size_t i; | |
582 | ||
583 | DoSelectProperty(NULL); | |
584 | ||
585 | // This should do prevent things from going too badly wrong | |
586 | m_iFlags &= ~(wxPG_FL_INITIALIZED); | |
587 | ||
588 | if ( m_iFlags & wxPG_FL_MOUSE_CAPTURED ) | |
589 | m_canvas->ReleaseMouse(); | |
590 | ||
27c1f235 JS |
591 | // Do TLP check, recommend use of OnTLPChanging() |
592 | wxWindow* tlp = ::wxGetTopLevelParent(this); | |
593 | if ( tlp == m_tlp ) | |
594 | { | |
595 | m_tlp->Disconnect( wxEVT_CLOSE_WINDOW, | |
596 | wxCloseEventHandler(wxPropertyGrid::OnTLPClose), | |
597 | NULL, this ); | |
598 | } | |
599 | else if ( tlp ) | |
600 | { | |
601 | wxLogError("Top-level parent of wxPropertyGrid has changed. " | |
602 | "Consider calling wxPropertyGrid::OnTLPChanging() " | |
603 | "when appropriate."); | |
604 | } | |
1c4293cb | 605 | |
4b6a582b VZ |
606 | wxASSERT_MSG( !IsEditorsValueModified(), |
607 | wxS("Most recent change in property editor was lost!!! ") | |
608 | wxS("(if you don't want this to happen, close your frames ") | |
609 | wxS("and dialogs using Close(false).)") ); | |
1c4293cb VZ |
610 | |
611 | #if wxPG_DOUBLE_BUFFER | |
612 | if ( m_doubleBuffer ) | |
613 | delete m_doubleBuffer; | |
614 | #endif | |
615 | ||
d3b9f782 | 616 | //m_selected = NULL; |
1c4293cb VZ |
617 | |
618 | if ( m_iFlags & wxPG_FL_CREATEDSTATE ) | |
619 | delete m_pState; | |
620 | ||
621 | delete m_cursorSizeWE; | |
622 | ||
623 | #ifndef wxPG_ICON_WIDTH | |
657a8a35 VZ |
624 | delete m_expandbmp; |
625 | delete m_collbmp; | |
1c4293cb VZ |
626 | #endif |
627 | ||
1c4293cb VZ |
628 | // Delete common value records |
629 | for ( i=0; i<m_commonValues.size(); i++ ) | |
630 | { | |
631 | delete GetCommonValue(i); | |
632 | } | |
633 | } | |
634 | ||
635 | // ----------------------------------------------------------------------- | |
636 | ||
637 | bool wxPropertyGrid::Destroy() | |
638 | { | |
639 | if ( m_iFlags & wxPG_FL_MOUSE_CAPTURED ) | |
640 | m_canvas->ReleaseMouse(); | |
641 | ||
642 | return wxScrolledWindow::Destroy(); | |
643 | } | |
644 | ||
645 | // ----------------------------------------------------------------------- | |
646 | ||
647 | wxPropertyGridPageState* wxPropertyGrid::CreateState() const | |
648 | { | |
649 | return new wxPropertyGridPageState(); | |
650 | } | |
651 | ||
652 | // ----------------------------------------------------------------------- | |
653 | // wxPropertyGrid overridden wxWindow methods | |
654 | // ----------------------------------------------------------------------- | |
655 | ||
656 | void wxPropertyGrid::SetWindowStyleFlag( long style ) | |
657 | { | |
658 | long old_style = m_windowStyle; | |
659 | ||
660 | if ( m_iFlags & wxPG_FL_INITIALIZED ) | |
661 | { | |
662 | wxASSERT( m_pState ); | |
663 | ||
664 | if ( !(style & wxPG_HIDE_CATEGORIES) && (old_style & wxPG_HIDE_CATEGORIES) ) | |
665 | { | |
666 | // Enable categories | |
667 | EnableCategories( true ); | |
668 | } | |
669 | else if ( (style & wxPG_HIDE_CATEGORIES) && !(old_style & wxPG_HIDE_CATEGORIES) ) | |
670 | { | |
671 | // Disable categories | |
672 | EnableCategories( false ); | |
673 | } | |
674 | if ( !(old_style & wxPG_AUTO_SORT) && (style & wxPG_AUTO_SORT) ) | |
675 | { | |
676 | // | |
677 | // Autosort enabled | |
678 | // | |
679 | if ( !m_frozen ) | |
680 | PrepareAfterItemsAdded(); | |
681 | else | |
682 | m_pState->m_itemsAdded = 1; | |
683 | } | |
684 | #if wxPG_SUPPORT_TOOLTIPS | |
685 | if ( !(old_style & wxPG_TOOLTIPS) && (style & wxPG_TOOLTIPS) ) | |
686 | { | |
687 | // | |
688 | // Tooltips enabled | |
689 | // | |
690 | /* | |
691 | wxToolTip* tooltip = new wxToolTip ( wxEmptyString ); | |
692 | SetToolTip ( tooltip ); | |
693 | tooltip->SetDelay ( wxPG_TOOLTIP_DELAY ); | |
694 | */ | |
695 | } | |
696 | else if ( (old_style & wxPG_TOOLTIPS) && !(style & wxPG_TOOLTIPS) ) | |
697 | { | |
698 | // | |
699 | // Tooltips disabled | |
700 | // | |
d3b9f782 | 701 | m_canvas->SetToolTip( NULL ); |
1c4293cb VZ |
702 | } |
703 | #endif | |
704 | } | |
705 | ||
706 | wxScrolledWindow::SetWindowStyleFlag ( style ); | |
707 | ||
708 | if ( m_iFlags & wxPG_FL_INITIALIZED ) | |
709 | { | |
710 | if ( (old_style & wxPG_HIDE_MARGIN) != (style & wxPG_HIDE_MARGIN) ) | |
711 | { | |
712 | CalculateFontAndBitmapStuff( m_vspacing ); | |
713 | Refresh(); | |
714 | } | |
715 | } | |
716 | } | |
717 | ||
718 | // ----------------------------------------------------------------------- | |
719 | ||
720 | void wxPropertyGrid::Freeze() | |
721 | { | |
722 | if ( !m_frozen ) | |
723 | { | |
724 | wxScrolledWindow::Freeze(); | |
725 | } | |
726 | m_frozen++; | |
727 | } | |
728 | ||
729 | // ----------------------------------------------------------------------- | |
730 | ||
731 | void wxPropertyGrid::Thaw() | |
732 | { | |
733 | m_frozen--; | |
734 | ||
735 | if ( !m_frozen ) | |
736 | { | |
737 | wxScrolledWindow::Thaw(); | |
738 | RecalculateVirtualSize(); | |
739 | #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT | |
740 | m_canvas->Refresh(); | |
741 | #endif | |
742 | ||
743 | // Force property re-selection | |
744 | if ( m_selected ) | |
745 | DoSelectProperty(m_selected, wxPG_SEL_FORCE); | |
746 | } | |
747 | } | |
748 | ||
749 | // ----------------------------------------------------------------------- | |
750 | ||
751 | void wxPropertyGrid::SetExtraStyle( long exStyle ) | |
752 | { | |
753 | if ( exStyle & wxPG_EX_NATIVE_DOUBLE_BUFFERING ) | |
754 | { | |
755 | #if defined(__WXMSW__) | |
756 | ||
757 | /* | |
758 | // Don't use WS_EX_COMPOSITED just now. | |
759 | HWND hWnd; | |
760 | ||
761 | if ( m_iFlags & wxPG_FL_IN_MANAGER ) | |
762 | hWnd = (HWND)GetParent()->GetHWND(); | |
763 | else | |
764 | hWnd = (HWND)GetHWND(); | |
765 | ||
766 | ::SetWindowLong( hWnd, GWL_EXSTYLE, | |
767 | ::GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_COMPOSITED ); | |
768 | */ | |
769 | ||
770 | //#elif defined(__WXGTK20__) | |
771 | #endif | |
772 | // Only apply wxPG_EX_NATIVE_DOUBLE_BUFFERING if the window | |
773 | // truly was double-buffered. | |
774 | if ( !this->IsDoubleBuffered() ) | |
775 | { | |
776 | exStyle &= ~(wxPG_EX_NATIVE_DOUBLE_BUFFERING); | |
777 | } | |
778 | else | |
779 | { | |
780 | #if wxPG_DOUBLE_BUFFER | |
781 | delete m_doubleBuffer; | |
782 | m_doubleBuffer = NULL; | |
783 | #endif | |
784 | } | |
785 | } | |
786 | ||
787 | wxScrolledWindow::SetExtraStyle( exStyle ); | |
788 | ||
789 | if ( exStyle & wxPG_EX_INIT_NOCAT ) | |
790 | m_pState->InitNonCatMode(); | |
791 | ||
792 | if ( exStyle & wxPG_EX_HELP_AS_TOOLTIPS ) | |
793 | m_windowStyle |= wxPG_TOOLTIPS; | |
794 | ||
795 | // Set global style | |
796 | wxPGGlobalVars->m_extraStyle = exStyle; | |
797 | } | |
798 | ||
799 | // ----------------------------------------------------------------------- | |
800 | ||
801 | // returns the best acceptable minimal size | |
802 | wxSize wxPropertyGrid::DoGetBestSize() const | |
803 | { | |
916533c0 | 804 | int lineHeight = wxMax(15, m_lineHeight); |
1c4293cb | 805 | |
916533c0 VZ |
806 | // don't make the grid too tall (limit height to 10 items) but don't |
807 | // make it too small neither | |
808 | int numLines = wxMin | |
809 | ( | |
810 | wxMax(m_pState->m_properties->GetChildCount(), 3), | |
811 | 10 | |
812 | ); | |
813 | ||
814 | const wxSize sz = wxSize(60, lineHeight*numLines + 40); | |
1c4293cb VZ |
815 | CacheBestSize(sz); |
816 | return sz; | |
817 | } | |
818 | ||
27c1f235 JS |
819 | // ----------------------------------------------------------------------- |
820 | ||
821 | void wxPropertyGrid::OnTLPChanging( wxWindow* newTLP ) | |
822 | { | |
823 | // | |
824 | // Parent changed so let's redetermine and re-hook the | |
825 | // correct top-level window. | |
826 | if ( m_tlp ) | |
827 | { | |
828 | wxASSERT_MSG( m_tlp == ::wxGetTopLevelParent(this), | |
829 | "You must call OnTLPChanging() before the " | |
830 | "top-level parent has changed."); | |
831 | ||
832 | m_tlp->Disconnect( wxEVT_CLOSE_WINDOW, | |
833 | wxCloseEventHandler(wxPropertyGrid::OnTLPClose), | |
834 | NULL, this ); | |
835 | } | |
836 | ||
837 | if ( !newTLP ) | |
838 | newTLP = ::wxGetTopLevelParent(this); | |
839 | ||
840 | m_tlp = newTLP; | |
841 | m_tlp->Connect( wxEVT_CLOSE_WINDOW, | |
842 | wxCloseEventHandler(wxPropertyGrid::OnTLPClose), | |
843 | NULL, this ); | |
844 | } | |
845 | ||
846 | // ----------------------------------------------------------------------- | |
847 | ||
848 | void wxPropertyGrid::OnTLPClose( wxCloseEvent& event ) | |
849 | { | |
850 | // ClearSelection forces value validation/commit. | |
851 | if ( event.CanVeto() && !ClearSelection() ) | |
852 | { | |
853 | event.Veto(); | |
854 | return; | |
855 | } | |
856 | ||
857 | event.Skip(); | |
858 | } | |
859 | ||
860 | // ----------------------------------------------------------------------- | |
861 | ||
862 | bool wxPropertyGrid::Reparent( wxWindowBase *newParent ) | |
863 | { | |
864 | OnTLPChanging((wxWindow*)newParent); | |
865 | ||
866 | bool res = wxScrolledWindow::Reparent(newParent); | |
867 | ||
868 | return res; | |
869 | } | |
870 | ||
1c4293cb VZ |
871 | // ----------------------------------------------------------------------- |
872 | // wxPropertyGrid Font and Colour Methods | |
873 | // ----------------------------------------------------------------------- | |
874 | ||
875 | void wxPropertyGrid::CalculateFontAndBitmapStuff( int vspacing ) | |
876 | { | |
657a8a35 | 877 | int x = 0, y = 0; |
1c4293cb VZ |
878 | |
879 | m_captionFont = wxScrolledWindow::GetFont(); | |
880 | ||
657a8a35 | 881 | GetTextExtent(wxS("jG"), &x, &y, 0, 0, &m_captionFont); |
1c4293cb | 882 | m_subgroup_extramargin = x + (x/2); |
657a8a35 | 883 | m_fontHeight = y; |
1c4293cb VZ |
884 | |
885 | #if wxPG_USE_RENDERER_NATIVE | |
886 | m_iconWidth = wxPG_ICON_WIDTH; | |
887 | #elif wxPG_ICON_WIDTH | |
888 | // scale icon | |
889 | m_iconWidth = (m_fontHeight * wxPG_ICON_WIDTH) / 13; | |
890 | if ( m_iconWidth < 5 ) m_iconWidth = 5; | |
891 | else if ( !(m_iconWidth & 0x01) ) m_iconWidth++; // must be odd | |
892 | ||
893 | #endif | |
894 | ||
895 | m_gutterWidth = m_iconWidth / wxPG_GUTTER_DIV; | |
896 | if ( m_gutterWidth < wxPG_GUTTER_MIN ) | |
897 | m_gutterWidth = wxPG_GUTTER_MIN; | |
898 | ||
899 | int vdiv = 6; | |
900 | if ( vspacing <= 1 ) vdiv = 12; | |
901 | else if ( vspacing >= 3 ) vdiv = 3; | |
902 | ||
903 | m_spacingy = m_fontHeight / vdiv; | |
904 | if ( m_spacingy < wxPG_YSPACING_MIN ) | |
905 | m_spacingy = wxPG_YSPACING_MIN; | |
906 | ||
907 | m_marginWidth = 0; | |
908 | if ( !(m_windowStyle & wxPG_HIDE_MARGIN) ) | |
909 | m_marginWidth = m_gutterWidth*2 + m_iconWidth; | |
910 | ||
911 | m_captionFont.SetWeight(wxBOLD); | |
657a8a35 | 912 | GetTextExtent(wxS("jG"), &x, &y, 0, 0, &m_captionFont); |
1c4293cb VZ |
913 | |
914 | m_lineHeight = m_fontHeight+(2*m_spacingy)+1; | |
1c4293cb VZ |
915 | |
916 | // button spacing | |
917 | m_buttonSpacingY = (m_lineHeight - m_iconHeight) / 2; | |
918 | if ( m_buttonSpacingY < 0 ) m_buttonSpacingY = 0; | |
919 | ||
920 | if ( m_pState ) | |
921 | m_pState->CalculateFontAndBitmapStuff(vspacing); | |
922 | ||
923 | if ( m_iFlags & wxPG_FL_INITIALIZED ) | |
924 | RecalculateVirtualSize(); | |
925 | ||
926 | InvalidateBestSize(); | |
927 | } | |
928 | ||
929 | // ----------------------------------------------------------------------- | |
930 | ||
931 | void wxPropertyGrid::OnSysColourChanged( wxSysColourChangedEvent &WXUNUSED(event) ) | |
932 | { | |
933 | RegainColours(); | |
934 | Refresh(); | |
935 | } | |
936 | ||
937 | // ----------------------------------------------------------------------- | |
938 | ||
939 | static wxColour wxPGAdjustColour(const wxColour& src, int ra, | |
940 | int ga = 1000, int ba = 1000, | |
941 | bool forceDifferent = false) | |
942 | { | |
943 | if ( ga >= 1000 ) | |
944 | ga = ra; | |
945 | if ( ba >= 1000 ) | |
946 | ba = ra; | |
947 | ||
948 | // Recursion guard (allow 2 max) | |
949 | static int isinside = 0; | |
950 | isinside++; | |
951 | wxCHECK_MSG( isinside < 3, | |
952 | *wxBLACK, | |
953 | wxT("wxPGAdjustColour should not be recursively called more than once") ); | |
954 | ||
955 | wxColour dst; | |
956 | ||
957 | int r = src.Red(); | |
958 | int g = src.Green(); | |
959 | int b = src.Blue(); | |
960 | int r2 = r + ra; | |
961 | if ( r2>255 ) r2 = 255; | |
962 | else if ( r2<0) r2 = 0; | |
963 | int g2 = g + ga; | |
964 | if ( g2>255 ) g2 = 255; | |
965 | else if ( g2<0) g2 = 0; | |
966 | int b2 = b + ba; | |
967 | if ( b2>255 ) b2 = 255; | |
968 | else if ( b2<0) b2 = 0; | |
969 | ||
970 | // Make sure they are somewhat different | |
971 | if ( forceDifferent && (abs((r+g+b)-(r2+g2+b2)) < abs(ra/2)) ) | |
972 | dst = wxPGAdjustColour(src,-(ra*2)); | |
973 | else | |
974 | dst = wxColour(r2,g2,b2); | |
975 | ||
976 | // Recursion guard (allow 2 max) | |
977 | isinside--; | |
978 | ||
979 | return dst; | |
980 | } | |
981 | ||
982 | ||
983 | static int wxPGGetColAvg( const wxColour& col ) | |
984 | { | |
985 | return (col.Red() + col.Green() + col.Blue()) / 3; | |
986 | } | |
987 | ||
988 | ||
989 | void wxPropertyGrid::RegainColours() | |
990 | { | |
1c4293cb VZ |
991 | if ( !(m_coloursCustomized & 0x0002) ) |
992 | { | |
993 | wxColour col = wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ); | |
994 | ||
995 | // Make sure colour is dark enough | |
996 | #ifdef __WXGTK__ | |
997 | int colDec = wxPGGetColAvg(col) - 230; | |
998 | #else | |
999 | int colDec = wxPGGetColAvg(col) - 200; | |
1000 | #endif | |
1001 | if ( colDec > 0 ) | |
1002 | m_colCapBack = wxPGAdjustColour(col,-colDec); | |
1003 | else | |
1004 | m_colCapBack = col; | |
d7e2b522 | 1005 | m_categoryDefaultCell.GetData()->SetBgCol(m_colCapBack); |
1c4293cb VZ |
1006 | } |
1007 | ||
1008 | if ( !(m_coloursCustomized & 0x0001) ) | |
1009 | m_colMargin = m_colCapBack; | |
1010 | ||
1011 | if ( !(m_coloursCustomized & 0x0004) ) | |
1012 | { | |
1013 | #ifdef __WXGTK__ | |
1014 | int colDec = -90; | |
1015 | #else | |
1016 | int colDec = -72; | |
1017 | #endif | |
1018 | wxColour capForeCol = wxPGAdjustColour(m_colCapBack,colDec,5000,5000,true); | |
1019 | m_colCapFore = capForeCol; | |
d7e2b522 | 1020 | m_categoryDefaultCell.GetData()->SetFgCol(capForeCol); |
1c4293cb VZ |
1021 | } |
1022 | ||
1023 | if ( !(m_coloursCustomized & 0x0008) ) | |
1024 | { | |
1025 | wxColour bgCol = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ); | |
1026 | m_colPropBack = bgCol; | |
d7e2b522 | 1027 | m_propertyDefaultCell.GetData()->SetBgCol(bgCol); |
1c4293cb VZ |
1028 | } |
1029 | ||
1030 | if ( !(m_coloursCustomized & 0x0010) ) | |
1031 | { | |
1032 | wxColour fgCol = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT ); | |
1033 | m_colPropFore = fgCol; | |
d7e2b522 | 1034 | m_propertyDefaultCell.GetData()->SetFgCol(fgCol); |
1c4293cb VZ |
1035 | } |
1036 | ||
1037 | if ( !(m_coloursCustomized & 0x0020) ) | |
1038 | m_colSelBack = wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT ); | |
1039 | ||
1040 | if ( !(m_coloursCustomized & 0x0040) ) | |
1041 | m_colSelFore = wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT ); | |
1042 | ||
1043 | if ( !(m_coloursCustomized & 0x0080) ) | |
1044 | m_colLine = m_colCapBack; | |
1045 | ||
1046 | if ( !(m_coloursCustomized & 0x0100) ) | |
1047 | m_colDisPropFore = m_colCapFore; | |
1048 | ||
1049 | m_colEmptySpace = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOW ); | |
1050 | } | |
1051 | ||
1052 | // ----------------------------------------------------------------------- | |
1053 | ||
1054 | void wxPropertyGrid::ResetColours() | |
1055 | { | |
1056 | m_coloursCustomized = 0; | |
1057 | ||
1058 | RegainColours(); | |
1059 | ||
1060 | Refresh(); | |
1061 | } | |
1062 | ||
1063 | // ----------------------------------------------------------------------- | |
1064 | ||
1065 | bool wxPropertyGrid::SetFont( const wxFont& font ) | |
1066 | { | |
1067 | // Must disable active editor. | |
1621f192 | 1068 | ClearSelection(false); |
1c4293cb | 1069 | |
1c4293cb | 1070 | bool res = wxScrolledWindow::SetFont( font ); |
8d5b63cc | 1071 | if ( res && GetParent()) // may not have been Create()ed yet |
1c4293cb VZ |
1072 | { |
1073 | CalculateFontAndBitmapStuff( m_vspacing ); | |
1c4293cb VZ |
1074 | Refresh(); |
1075 | } | |
1076 | ||
1077 | return res; | |
1c4293cb VZ |
1078 | } |
1079 | ||
1080 | // ----------------------------------------------------------------------- | |
1081 | ||
1082 | void wxPropertyGrid::SetLineColour( const wxColour& col ) | |
1083 | { | |
1084 | m_colLine = col; | |
1085 | m_coloursCustomized |= 0x80; | |
1086 | Refresh(); | |
1087 | } | |
1088 | ||
1089 | // ----------------------------------------------------------------------- | |
1090 | ||
1091 | void wxPropertyGrid::SetMarginColour( const wxColour& col ) | |
1092 | { | |
1093 | m_colMargin = col; | |
1094 | m_coloursCustomized |= 0x01; | |
1095 | Refresh(); | |
1096 | } | |
1097 | ||
1098 | // ----------------------------------------------------------------------- | |
1099 | ||
1100 | void wxPropertyGrid::SetCellBackgroundColour( const wxColour& col ) | |
1101 | { | |
1102 | m_colPropBack = col; | |
1103 | m_coloursCustomized |= 0x08; | |
1104 | ||
d7e2b522 | 1105 | m_propertyDefaultCell.GetData()->SetBgCol(col); |
1c4293cb VZ |
1106 | |
1107 | Refresh(); | |
1108 | } | |
1109 | ||
1110 | // ----------------------------------------------------------------------- | |
1111 | ||
1112 | void wxPropertyGrid::SetCellTextColour( const wxColour& col ) | |
1113 | { | |
1114 | m_colPropFore = col; | |
1115 | m_coloursCustomized |= 0x10; | |
1116 | ||
d7e2b522 | 1117 | m_propertyDefaultCell.GetData()->SetFgCol(col); |
1c4293cb VZ |
1118 | |
1119 | Refresh(); | |
1120 | } | |
1121 | ||
1122 | // ----------------------------------------------------------------------- | |
1123 | ||
1124 | void wxPropertyGrid::SetEmptySpaceColour( const wxColour& col ) | |
1125 | { | |
1126 | m_colEmptySpace = col; | |
1127 | ||
1128 | Refresh(); | |
1129 | } | |
1130 | ||
1131 | // ----------------------------------------------------------------------- | |
1132 | ||
1133 | void wxPropertyGrid::SetCellDisabledTextColour( const wxColour& col ) | |
1134 | { | |
1135 | m_colDisPropFore = col; | |
1136 | m_coloursCustomized |= 0x100; | |
1137 | Refresh(); | |
1138 | } | |
1139 | ||
1140 | // ----------------------------------------------------------------------- | |
1141 | ||
1142 | void wxPropertyGrid::SetSelectionBackgroundColour( const wxColour& col ) | |
1143 | { | |
1144 | m_colSelBack = col; | |
1145 | m_coloursCustomized |= 0x20; | |
1146 | Refresh(); | |
1147 | } | |
1148 | ||
1149 | // ----------------------------------------------------------------------- | |
1150 | ||
1151 | void wxPropertyGrid::SetSelectionTextColour( const wxColour& col ) | |
1152 | { | |
1153 | m_colSelFore = col; | |
1154 | m_coloursCustomized |= 0x40; | |
1155 | Refresh(); | |
1156 | } | |
1157 | ||
1158 | // ----------------------------------------------------------------------- | |
1159 | ||
1160 | void wxPropertyGrid::SetCaptionBackgroundColour( const wxColour& col ) | |
1161 | { | |
1162 | m_colCapBack = col; | |
1163 | m_coloursCustomized |= 0x02; | |
d7e2b522 JS |
1164 | |
1165 | m_categoryDefaultCell.GetData()->SetBgCol(col); | |
1166 | ||
1c4293cb VZ |
1167 | Refresh(); |
1168 | } | |
1169 | ||
1170 | // ----------------------------------------------------------------------- | |
1171 | ||
1172 | void wxPropertyGrid::SetCaptionTextColour( const wxColour& col ) | |
1173 | { | |
1174 | m_colCapFore = col; | |
1175 | m_coloursCustomized |= 0x04; | |
1176 | ||
d7e2b522 | 1177 | m_categoryDefaultCell.GetData()->SetFgCol(col); |
1c4293cb VZ |
1178 | |
1179 | Refresh(); | |
1180 | } | |
1181 | ||
1c4293cb VZ |
1182 | // ----------------------------------------------------------------------- |
1183 | // wxPropertyGrid property adding and removal | |
1184 | // ----------------------------------------------------------------------- | |
1185 | ||
1186 | void wxPropertyGrid::PrepareAfterItemsAdded() | |
1187 | { | |
1188 | if ( !m_pState || !m_pState->m_itemsAdded ) return; | |
1189 | ||
1190 | m_pState->m_itemsAdded = 0; | |
1191 | ||
1192 | if ( m_windowStyle & wxPG_AUTO_SORT ) | |
0eb877f2 | 1193 | Sort(wxPG_SORT_TOP_LEVEL_ONLY); |
1c4293cb VZ |
1194 | |
1195 | RecalculateVirtualSize(); | |
1196 | } | |
1197 | ||
1c4293cb VZ |
1198 | // ----------------------------------------------------------------------- |
1199 | // wxPropertyGrid property operations | |
1200 | // ----------------------------------------------------------------------- | |
1201 | ||
1c4293cb VZ |
1202 | bool wxPropertyGrid::EnsureVisible( wxPGPropArg id ) |
1203 | { | |
1204 | wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false) | |
1205 | ||
1206 | Update(); | |
1207 | ||
1208 | bool changed = false; | |
1209 | ||
1210 | // Is it inside collapsed section? | |
1211 | if ( !p->IsVisible() ) | |
1212 | { | |
1213 | // expand parents | |
1214 | wxPGProperty* parent = p->GetParent(); | |
1215 | wxPGProperty* grandparent = parent->GetParent(); | |
1216 | ||
1217 | if ( grandparent && grandparent != m_pState->m_properties ) | |
1218 | Expand( grandparent ); | |
1219 | ||
1220 | Expand( parent ); | |
1221 | changed = true; | |
1222 | } | |
1223 | ||
1224 | // Need to scroll? | |
1225 | int vx, vy; | |
1226 | GetViewStart(&vx,&vy); | |
1227 | vy*=wxPG_PIXELS_PER_UNIT; | |
1228 | ||
1229 | int y = p->GetY(); | |
1230 | ||
1231 | if ( y < vy ) | |
1232 | { | |
1233 | Scroll(vx, y/wxPG_PIXELS_PER_UNIT ); | |
1234 | m_iFlags |= wxPG_FL_SCROLLED; | |
1235 | changed = true; | |
1236 | } | |
1237 | else if ( (y+m_lineHeight) > (vy+m_height) ) | |
1238 | { | |
1239 | Scroll(vx, (y-m_height+(m_lineHeight*2))/wxPG_PIXELS_PER_UNIT ); | |
1240 | m_iFlags |= wxPG_FL_SCROLLED; | |
1241 | changed = true; | |
1242 | } | |
1243 | ||
1244 | if ( changed ) | |
1245 | DrawItems( p, p ); | |
1246 | ||
1247 | return changed; | |
1248 | } | |
1249 | ||
1250 | // ----------------------------------------------------------------------- | |
1251 | // wxPropertyGrid helper methods called by properties | |
1252 | // ----------------------------------------------------------------------- | |
1253 | ||
1254 | // Control font changer helper. | |
1255 | void wxPropertyGrid::SetCurControlBoldFont() | |
1256 | { | |
1257 | wxASSERT( m_wndEditor ); | |
1258 | m_wndEditor->SetFont( m_captionFont ); | |
1259 | } | |
1260 | ||
1261 | // ----------------------------------------------------------------------- | |
1262 | ||
1263 | wxPoint wxPropertyGrid::GetGoodEditorDialogPosition( wxPGProperty* p, | |
1264 | const wxSize& sz ) | |
1265 | { | |
1266 | #if wxPG_SMALL_SCREEN | |
1267 | // On small-screen devices, always show dialogs with default position and size. | |
1268 | return wxDefaultPosition; | |
1269 | #else | |
1270 | int splitterX = GetSplitterPosition(); | |
1271 | int x = splitterX; | |
1272 | int y = p->GetY(); | |
1273 | ||
1274 | wxCHECK_MSG( y >= 0, wxPoint(-1,-1), wxT("invalid y?") ); | |
1275 | ||
1276 | ImprovedClientToScreen( &x, &y ); | |
1277 | ||
1278 | int sw = wxSystemSettings::GetMetric( ::wxSYS_SCREEN_X ); | |
1279 | int sh = wxSystemSettings::GetMetric( ::wxSYS_SCREEN_Y ); | |
1280 | ||
1281 | int new_x; | |
1282 | int new_y; | |
1283 | ||
1284 | if ( x > (sw/2) ) | |
1285 | // left | |
1286 | new_x = x + (m_width-splitterX) - sz.x; | |
1287 | else | |
1288 | // right | |
1289 | new_x = x; | |
1290 | ||
1291 | if ( y > (sh/2) ) | |
1292 | // above | |
1293 | new_y = y - sz.y; | |
1294 | else | |
1295 | // below | |
1296 | new_y = y + m_lineHeight; | |
1297 | ||
1298 | return wxPoint(new_x,new_y); | |
1299 | #endif | |
1300 | } | |
1301 | ||
1302 | // ----------------------------------------------------------------------- | |
1303 | ||
1304 | wxString& wxPropertyGrid::ExpandEscapeSequences( wxString& dst_str, wxString& src_str ) | |
1305 | { | |
1306 | if ( src_str.length() == 0 ) | |
1307 | { | |
1308 | dst_str = src_str; | |
1309 | return src_str; | |
1310 | } | |
1311 | ||
1312 | bool prev_is_slash = false; | |
1313 | ||
1314 | wxString::const_iterator i = src_str.begin(); | |
1315 | ||
1316 | dst_str.clear(); | |
1317 | ||
b7bc9d80 | 1318 | for ( ; i != src_str.end(); ++i ) |
1c4293cb VZ |
1319 | { |
1320 | wxUniChar a = *i; | |
1321 | ||
1322 | if ( a != wxS('\\') ) | |
1323 | { | |
1324 | if ( !prev_is_slash ) | |
1325 | { | |
1326 | dst_str << a; | |
1327 | } | |
1328 | else | |
1329 | { | |
1330 | if ( a == wxS('n') ) | |
1331 | { | |
1332 | #ifdef __WXMSW__ | |
1333 | dst_str << wxS('\n'); | |
1334 | #else | |
1335 | dst_str << wxS('\n'); | |
1336 | #endif | |
1337 | } | |
1338 | else if ( a == wxS('t') ) | |
1339 | dst_str << wxS('\t'); | |
1340 | else | |
1341 | dst_str << a; | |
1342 | } | |
1343 | prev_is_slash = false; | |
1344 | } | |
1345 | else | |
1346 | { | |
1347 | if ( prev_is_slash ) | |
1348 | { | |
1349 | dst_str << wxS('\\'); | |
1350 | prev_is_slash = false; | |
1351 | } | |
1352 | else | |
1353 | { | |
1354 | prev_is_slash = true; | |
1355 | } | |
1356 | } | |
1357 | } | |
1358 | return dst_str; | |
1359 | } | |
1360 | ||
1361 | // ----------------------------------------------------------------------- | |
1362 | ||
1363 | wxString& wxPropertyGrid::CreateEscapeSequences( wxString& dst_str, wxString& src_str ) | |
1364 | { | |
1365 | if ( src_str.length() == 0 ) | |
1366 | { | |
1367 | dst_str = src_str; | |
1368 | return src_str; | |
1369 | } | |
1370 | ||
1371 | wxString::const_iterator i = src_str.begin(); | |
1372 | wxUniChar prev_a = wxS('\0'); | |
1373 | ||
1374 | dst_str.clear(); | |
1375 | ||
b7bc9d80 | 1376 | for ( ; i != src_str.end(); ++i ) |
1c4293cb VZ |
1377 | { |
1378 | wxChar a = *i; | |
1379 | ||
1380 | if ( a >= wxS(' ') ) | |
1381 | { | |
1382 | // This surely is not something that requires an escape sequence. | |
1383 | dst_str << a; | |
1384 | } | |
1385 | else | |
1386 | { | |
1387 | // This might need... | |
1388 | if ( a == wxS('\r') ) | |
1389 | { | |
1390 | // DOS style line end. | |
1391 | // Already taken care below | |
1392 | } | |
1393 | else if ( a == wxS('\n') ) | |
1394 | // UNIX style line end. | |
1395 | dst_str << wxS("\\n"); | |
1396 | else if ( a == wxS('\t') ) | |
1397 | // Tab. | |
1398 | dst_str << wxS('\t'); | |
1399 | else | |
1400 | { | |
1401 | //wxLogDebug(wxT("WARNING: Could not create escape sequence for character #%i"),(int)a); | |
1402 | dst_str << a; | |
1403 | } | |
1404 | } | |
1405 | ||
1406 | prev_a = a; | |
1407 | } | |
1408 | return dst_str; | |
1409 | } | |
1410 | ||
1411 | // ----------------------------------------------------------------------- | |
1412 | ||
1413 | wxPGProperty* wxPropertyGrid::DoGetItemAtY( int y ) const | |
1414 | { | |
1415 | // Outside? | |
1416 | if ( y < 0 ) | |
d3b9f782 | 1417 | return NULL; |
1c4293cb VZ |
1418 | |
1419 | unsigned int a = 0; | |
1420 | return m_pState->m_properties->GetItemAtY(y, m_lineHeight, &a); | |
1421 | } | |
1422 | ||
1423 | // ----------------------------------------------------------------------- | |
1424 | // wxPropertyGrid graphics related methods | |
1425 | // ----------------------------------------------------------------------- | |
1426 | ||
1427 | void wxPropertyGrid::OnPaint( wxPaintEvent& WXUNUSED(event) ) | |
1428 | { | |
1429 | wxPaintDC dc(this); | |
1430 | ||
1431 | // Update everything inside the box | |
1432 | wxRect r = GetUpdateRegion().GetBox(); | |
1433 | ||
1434 | dc.SetPen(m_colEmptySpace); | |
1435 | dc.SetBrush(m_colEmptySpace); | |
1436 | dc.DrawRectangle(r); | |
1437 | } | |
1438 | ||
1439 | // ----------------------------------------------------------------------- | |
1440 | ||
1441 | void wxPropertyGrid::DrawExpanderButton( wxDC& dc, const wxRect& rect, | |
1442 | wxPGProperty* property ) const | |
1443 | { | |
1444 | // Prepare rectangle to be used | |
1445 | wxRect r(rect); | |
1446 | r.x += m_gutterWidth; r.y += m_buttonSpacingY; | |
1447 | r.width = m_iconWidth; r.height = m_iconHeight; | |
1448 | ||
1449 | #if (wxPG_USE_RENDERER_NATIVE) | |
1450 | // | |
1451 | #elif wxPG_ICON_WIDTH | |
1452 | // Drawing expand/collapse button manually | |
1453 | dc.SetPen(m_colPropFore); | |
1454 | if ( property->IsCategory() ) | |
1455 | dc.SetBrush(*wxTRANSPARENT_BRUSH); | |
1456 | else | |
1457 | dc.SetBrush(m_colPropBack); | |
1458 | ||
1459 | dc.DrawRectangle( r ); | |
1460 | int _y = r.y+(m_iconWidth/2); | |
1461 | dc.DrawLine(r.x+2,_y,r.x+m_iconWidth-2,_y); | |
1462 | #else | |
1463 | wxBitmap* bmp; | |
1464 | #endif | |
1465 | ||
1466 | if ( property->IsExpanded() ) | |
1467 | { | |
1468 | // wxRenderer functions are non-mutating in nature, so it | |
1469 | // should be safe to cast "const wxPropertyGrid*" to "wxWindow*". | |
1470 | // Hopefully this does not cause problems. | |
1471 | #if (wxPG_USE_RENDERER_NATIVE) | |
1472 | wxRendererNative::Get().DrawTreeItemButton( | |
1473 | (wxWindow*)this, | |
1474 | dc, | |
1475 | r, | |
1476 | wxCONTROL_EXPANDED | |
1477 | ); | |
1478 | #elif wxPG_ICON_WIDTH | |
1479 | // | |
1480 | #else | |
1481 | bmp = m_collbmp; | |
1482 | #endif | |
1483 | ||
1484 | } | |
1485 | else | |
1486 | { | |
1487 | #if (wxPG_USE_RENDERER_NATIVE) | |
1488 | wxRendererNative::Get().DrawTreeItemButton( | |
1489 | (wxWindow*)this, | |
1490 | dc, | |
1491 | r, | |
1492 | 0 | |
1493 | ); | |
1494 | #elif wxPG_ICON_WIDTH | |
1495 | int _x = r.x+(m_iconWidth/2); | |
1496 | dc.DrawLine(_x,r.y+2,_x,r.y+m_iconWidth-2); | |
1497 | #else | |
1498 | bmp = m_expandbmp; | |
1499 | #endif | |
1500 | } | |
1501 | ||
1502 | #if (wxPG_USE_RENDERER_NATIVE) | |
1503 | // | |
1504 | #elif wxPG_ICON_WIDTH | |
1505 | // | |
1506 | #else | |
1507 | dc.DrawBitmap( *bmp, r.x, r.y, true ); | |
1508 | #endif | |
1509 | } | |
1510 | ||
1511 | // ----------------------------------------------------------------------- | |
1512 | ||
1513 | // | |
1514 | // This is the one called by OnPaint event handler and others. | |
1515 | // topy and bottomy are already unscrolled (ie. physical) | |
1516 | // | |
1517 | void wxPropertyGrid::DrawItems( wxDC& dc, | |
1518 | unsigned int topy, | |
1519 | unsigned int bottomy, | |
1520 | const wxRect* clipRect ) | |
1521 | { | |
1522 | if ( m_frozen || m_height < 1 || bottomy < topy || !m_pState ) return; | |
1523 | ||
1524 | m_pState->EnsureVirtualHeight(); | |
1525 | ||
1526 | wxRect tempClipRect; | |
1527 | if ( !clipRect ) | |
1528 | { | |
1529 | tempClipRect = wxRect(0,topy,m_pState->m_width,bottomy); | |
1530 | clipRect = &tempClipRect; | |
1531 | } | |
1532 | ||
1533 | // items added check | |
1534 | if ( m_pState->m_itemsAdded ) PrepareAfterItemsAdded(); | |
1535 | ||
1536 | int paintFinishY = 0; | |
1537 | ||
1538 | if ( m_pState->m_properties->GetChildCount() > 0 ) | |
1539 | { | |
1540 | wxDC* dcPtr = &dc; | |
1541 | bool isBuffered = false; | |
1542 | ||
1543 | #if wxPG_DOUBLE_BUFFER | |
1544 | wxMemoryDC* bufferDC = NULL; | |
1545 | ||
1546 | if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING) ) | |
1547 | { | |
1548 | if ( !m_doubleBuffer ) | |
1549 | { | |
1550 | paintFinishY = clipRect->y; | |
1551 | dcPtr = NULL; | |
1552 | } | |
1553 | else | |
1554 | { | |
1555 | bufferDC = new wxMemoryDC(); | |
1556 | ||
1557 | // If nothing was changed, then just copy from double-buffer | |
1558 | bufferDC->SelectObject( *m_doubleBuffer ); | |
1559 | dcPtr = bufferDC; | |
1560 | ||
1561 | isBuffered = true; | |
1562 | } | |
1563 | } | |
1564 | #endif | |
1565 | ||
1566 | if ( dcPtr ) | |
1567 | { | |
1568 | dc.SetClippingRegion( *clipRect ); | |
bcf324be | 1569 | paintFinishY = DoDrawItems( *dcPtr, clipRect, isBuffered ); |
1c4293cb VZ |
1570 | } |
1571 | ||
1572 | #if wxPG_DOUBLE_BUFFER | |
1573 | if ( bufferDC ) | |
1574 | { | |
1575 | dc.Blit( clipRect->x, clipRect->y, clipRect->width, clipRect->height, | |
1576 | bufferDC, 0, 0, wxCOPY ); | |
1577 | dc.DestroyClippingRegion(); // Is this really necessary? | |
1578 | delete bufferDC; | |
1579 | } | |
1580 | #endif | |
1581 | } | |
1582 | ||
1583 | // Clear area beyond bottomY? | |
1584 | if ( paintFinishY < (clipRect->y+clipRect->height) ) | |
1585 | { | |
1586 | dc.SetPen(m_colEmptySpace); | |
1587 | dc.SetBrush(m_colEmptySpace); | |
1588 | dc.DrawRectangle( 0, paintFinishY, m_width, (clipRect->y+clipRect->height) ); | |
1589 | } | |
1590 | } | |
1591 | ||
1592 | // ----------------------------------------------------------------------- | |
1593 | ||
1594 | int wxPropertyGrid::DoDrawItems( wxDC& dc, | |
1c4293cb VZ |
1595 | const wxRect* clipRect, |
1596 | bool isBuffered ) const | |
1597 | { | |
bcf324be JS |
1598 | const wxPGProperty* firstItem; |
1599 | const wxPGProperty* lastItem; | |
1c4293cb | 1600 | |
bcf324be JS |
1601 | firstItem = DoGetItemAtY(clipRect->y); |
1602 | lastItem = DoGetItemAtY(clipRect->y+clipRect->height-1); | |
1c4293cb VZ |
1603 | |
1604 | if ( !lastItem ) | |
bcf324be | 1605 | lastItem = GetLastItem( wxPG_ITERATE_VISIBLE ); |
1c4293cb VZ |
1606 | |
1607 | if ( m_frozen || m_height < 1 || firstItem == NULL ) | |
1608 | return clipRect->y; | |
1609 | ||
1610 | wxCHECK_MSG( !m_pState->m_itemsAdded, clipRect->y, wxT("no items added") ); | |
1611 | wxASSERT( m_pState->m_properties->GetChildCount() ); | |
1612 | ||
1613 | int lh = m_lineHeight; | |
1614 | ||
1615 | int firstItemTopY; | |
1616 | int lastItemBottomY; | |
1617 | ||
1618 | firstItemTopY = clipRect->y; | |
1619 | lastItemBottomY = clipRect->y + clipRect->height; | |
1620 | ||
1621 | // Align y coordinates to item boundaries | |
1622 | firstItemTopY -= firstItemTopY % lh; | |
1623 | lastItemBottomY += lh - (lastItemBottomY % lh); | |
1624 | lastItemBottomY -= 1; | |
1625 | ||
1626 | // Entire range outside scrolled, visible area? | |
1627 | if ( firstItemTopY >= (int)m_pState->GetVirtualHeight() || lastItemBottomY <= 0 ) | |
1628 | return clipRect->y; | |
1629 | ||
1630 | wxCHECK_MSG( firstItemTopY < lastItemBottomY, clipRect->y, wxT("invalid y values") ); | |
1631 | ||
1632 | ||
1633 | /* | |
1634 | wxLogDebug(wxT(" -> DoDrawItems ( \"%s\" -> \"%s\", height=%i (ch=%i), clipRect = 0x%lX )"), | |
1635 | firstItem->GetLabel().c_str(), | |
1636 | lastItem->GetLabel().c_str(), | |
1637 | (int)(lastItemBottomY - firstItemTopY), | |
1638 | (int)m_height, | |
1639 | (unsigned long)clipRect ); | |
1640 | */ | |
1641 | ||
1642 | wxRect r; | |
1643 | ||
1644 | long windowStyle = m_windowStyle; | |
1645 | ||
1646 | int xRelMod = 0; | |
1647 | int yRelMod = 0; | |
1648 | ||
1649 | // | |
1650 | // With wxPG_DOUBLE_BUFFER, do double buffering | |
1651 | // - buffer's y = 0, so align cliprect and coordinates to that | |
1652 | // | |
1653 | #if wxPG_DOUBLE_BUFFER | |
1654 | ||
1655 | wxRect cr2; | |
1656 | ||
1657 | if ( isBuffered ) | |
1658 | { | |
1659 | xRelMod = clipRect->x; | |
1660 | yRelMod = clipRect->y; | |
1661 | ||
1662 | // | |
1663 | // clipRect conversion | |
b7bc9d80 PC |
1664 | cr2 = *clipRect; |
1665 | cr2.x -= xRelMod; | |
1666 | cr2.y -= yRelMod; | |
1667 | clipRect = &cr2; | |
1c4293cb VZ |
1668 | firstItemTopY -= yRelMod; |
1669 | lastItemBottomY -= yRelMod; | |
1670 | } | |
1671 | #else | |
1672 | wxUnusedVar(isBuffered); | |
1673 | #endif | |
1674 | ||
1675 | int x = m_marginWidth - xRelMod; | |
1676 | ||
2197ec80 | 1677 | wxFont normalFont = GetFont(); |
1c4293cb | 1678 | |
b7bc9d80 | 1679 | bool reallyFocused = (m_iFlags & wxPG_FL_FOCUSED) != 0; |
1c4293cb VZ |
1680 | |
1681 | bool isEnabled = IsEnabled(); | |
1682 | ||
1683 | // | |
1684 | // Prepare some pens and brushes that are often changed to. | |
1685 | // | |
1686 | ||
1687 | wxBrush marginBrush(m_colMargin); | |
1688 | wxPen marginPen(m_colMargin); | |
1689 | wxBrush capbgbrush(m_colCapBack,wxSOLID); | |
1690 | wxPen linepen(m_colLine,1,wxSOLID); | |
1691 | ||
1692 | // pen that has same colour as text | |
1693 | wxPen outlinepen(m_colPropFore,1,wxSOLID); | |
1694 | ||
1695 | // | |
1696 | // Clear margin with background colour | |
1697 | // | |
1698 | dc.SetBrush( marginBrush ); | |
1699 | if ( !(windowStyle & wxPG_HIDE_MARGIN) ) | |
1700 | { | |
1701 | dc.SetPen( *wxTRANSPARENT_PEN ); | |
1702 | dc.DrawRectangle(-1-xRelMod,firstItemTopY-1,x+2,lastItemBottomY-firstItemTopY+2); | |
1703 | } | |
1704 | ||
1705 | const wxPGProperty* selected = m_selected; | |
1706 | const wxPropertyGridPageState* state = m_pState; | |
1707 | ||
1708 | #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT | |
1709 | bool wasSelectedPainted = false; | |
1710 | #endif | |
1711 | ||
1712 | // TODO: Only render columns that are within clipping region. | |
1713 | ||
2197ec80 | 1714 | dc.SetFont(normalFont); |
1c4293cb VZ |
1715 | |
1716 | wxPropertyGridConstIterator it( state, wxPG_ITERATE_VISIBLE, firstItem ); | |
1717 | int endScanBottomY = lastItemBottomY + lh; | |
1718 | int y = firstItemTopY; | |
23b4f320 JS |
1719 | |
1720 | // | |
1721 | // Pregenerate list of visible properties. | |
1722 | wxArrayPGProperty visPropArray; | |
1723 | visPropArray.reserve((m_height/m_lineHeight)+6); | |
1c4293cb VZ |
1724 | |
1725 | for ( ; !it.AtEnd(); it.Next() ) | |
1726 | { | |
1727 | const wxPGProperty* p = *it; | |
1728 | ||
1729 | if ( !p->HasFlag(wxPG_PROP_HIDDEN) ) | |
1730 | { | |
23b4f320 | 1731 | visPropArray.push_back((wxPGProperty*)p); |
1c4293cb VZ |
1732 | |
1733 | if ( y > endScanBottomY ) | |
1734 | break; | |
1735 | ||
1736 | y += lh; | |
1737 | } | |
1738 | } | |
1739 | ||
23b4f320 JS |
1740 | visPropArray.push_back(NULL); |
1741 | ||
1742 | wxPGProperty* nextP = visPropArray[0]; | |
1c4293cb VZ |
1743 | |
1744 | int gridWidth = state->m_width; | |
1745 | ||
1746 | y = firstItemTopY; | |
23b4f320 JS |
1747 | for ( unsigned int arrInd=1; |
1748 | nextP && y <= lastItemBottomY; | |
1c4293cb VZ |
1749 | arrInd++ ) |
1750 | { | |
23b4f320 JS |
1751 | wxPGProperty* p = nextP; |
1752 | nextP = visPropArray[arrInd]; | |
1c4293cb VZ |
1753 | |
1754 | int rowHeight = m_fontHeight+(m_spacingy*2)+1; | |
1755 | int textMarginHere = x; | |
d7e2b522 | 1756 | int renderFlags = 0; |
1c4293cb VZ |
1757 | |
1758 | int greyDepth = m_marginWidth; | |
1759 | if ( !(windowStyle & wxPG_HIDE_CATEGORIES) ) | |
1760 | greyDepth = (((int)p->m_depthBgCol)-1) * m_subgroup_extramargin + m_marginWidth; | |
1761 | ||
1762 | int greyDepthX = greyDepth - xRelMod; | |
1763 | ||
1764 | // Use basic depth if in non-categoric mode and parent is base array. | |
1765 | if ( !(windowStyle & wxPG_HIDE_CATEGORIES) || p->GetParent() != m_pState->m_properties ) | |
1766 | { | |
1767 | textMarginHere += ((unsigned int)((p->m_depth-1)*m_subgroup_extramargin)); | |
1768 | } | |
1769 | ||
1770 | // Paint margin area | |
1771 | dc.SetBrush(marginBrush); | |
1772 | dc.SetPen(marginPen); | |
1773 | dc.DrawRectangle( -xRelMod, y, greyDepth, lh ); | |
1774 | ||
1775 | dc.SetPen( linepen ); | |
1776 | ||
1777 | int y2 = y + lh; | |
1778 | ||
1779 | // Margin Edge | |
1780 | dc.DrawLine( greyDepthX, y, greyDepthX, y2 ); | |
1781 | ||
1782 | // Splitters | |
1783 | unsigned int si; | |
1784 | int sx = x; | |
1785 | ||
1786 | for ( si=0; si<state->m_colWidths.size(); si++ ) | |
1787 | { | |
1788 | sx += state->m_colWidths[si]; | |
1789 | dc.DrawLine( sx, y, sx, y2 ); | |
1790 | } | |
1791 | ||
1792 | // Horizontal Line, below | |
1793 | // (not if both this and next is category caption) | |
1794 | if ( p->IsCategory() && | |
1795 | nextP && nextP->IsCategory() ) | |
1796 | dc.SetPen(m_colCapBack); | |
1797 | ||
1798 | dc.DrawLine( greyDepthX, y2-1, gridWidth-xRelMod, y2-1 ); | |
1799 | ||
d7e2b522 JS |
1800 | // |
1801 | // Need to override row colours? | |
1c4293cb | 1802 | wxColour rowFgCol; |
d7e2b522 | 1803 | wxColour rowBgCol; |
1c4293cb | 1804 | |
d7e2b522 | 1805 | if ( p != selected ) |
1c4293cb VZ |
1806 | { |
1807 | // Disabled may get different colour. | |
1808 | if ( !p->IsEnabled() ) | |
d7e2b522 JS |
1809 | { |
1810 | renderFlags |= wxPGCellRenderer::Disabled | | |
1811 | wxPGCellRenderer::DontUseCellFgCol; | |
1c4293cb | 1812 | rowFgCol = m_colDisPropFore; |
d7e2b522 | 1813 | } |
1c4293cb VZ |
1814 | } |
1815 | else | |
1816 | { | |
b7bc9d80 | 1817 | renderFlags |= wxPGCellRenderer::Selected; |
d7e2b522 | 1818 | |
b7bc9d80 PC |
1819 | if ( !p->IsCategory() ) |
1820 | { | |
d7e2b522 JS |
1821 | renderFlags |= wxPGCellRenderer::DontUseCellFgCol | |
1822 | wxPGCellRenderer::DontUseCellBgCol; | |
1823 | ||
1824 | #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT | |
1825 | wasSelectedPainted = true; | |
1826 | #endif | |
1827 | ||
1828 | // Selected gets different colour. | |
1829 | if ( reallyFocused ) | |
1830 | { | |
1831 | rowFgCol = m_colSelFore; | |
1832 | rowBgCol = m_colSelBack; | |
1833 | } | |
1834 | else if ( isEnabled ) | |
1835 | { | |
1836 | rowFgCol = m_colPropFore; | |
1837 | rowBgCol = m_colMargin; | |
1838 | } | |
1839 | else | |
1840 | { | |
1841 | rowFgCol = m_colDisPropFore; | |
1842 | rowBgCol = m_colSelBack; | |
1843 | } | |
1c4293cb | 1844 | } |
d7e2b522 JS |
1845 | } |
1846 | ||
1847 | wxBrush rowBgBrush; | |
1848 | ||
1849 | if ( rowBgCol.IsOk() ) | |
1850 | rowBgBrush = wxBrush(rowBgCol); | |
1851 | ||
1852 | if ( HasInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL) ) | |
1853 | renderFlags = renderFlags & ~wxPGCellRenderer::DontUseCellColours; | |
1854 | ||
1855 | // | |
1856 | // Fill additional margin area with background colour of first cell | |
1857 | if ( greyDepthX < textMarginHere ) | |
1858 | { | |
1859 | if ( !(renderFlags & wxPGCellRenderer::DontUseCellBgCol) ) | |
1c4293cb | 1860 | { |
d7e2b522 JS |
1861 | wxPGCell& cell = p->GetCell(0); |
1862 | rowBgCol = cell.GetBgCol(); | |
1863 | rowBgBrush = wxBrush(rowBgCol); | |
1c4293cb | 1864 | } |
d7e2b522 JS |
1865 | dc.SetBrush(rowBgBrush); |
1866 | dc.SetPen(rowBgCol); | |
1867 | dc.DrawRectangle(greyDepthX+1, y, | |
1868 | textMarginHere-greyDepthX, lh-1); | |
1c4293cb VZ |
1869 | } |
1870 | ||
1871 | bool fontChanged = false; | |
1872 | ||
d7e2b522 | 1873 | // Expander button rectangle |
1c4293cb VZ |
1874 | wxRect butRect( ((p->m_depth - 1) * m_subgroup_extramargin) - xRelMod, |
1875 | y, | |
1876 | m_marginWidth, | |
1877 | lh ); | |
1878 | ||
1879 | if ( p->IsCategory() ) | |
1880 | { | |
d7e2b522 | 1881 | // Captions have their cell areas merged as one |
1c4293cb VZ |
1882 | dc.SetFont(m_captionFont); |
1883 | fontChanged = true; | |
1884 | wxRect cellRect(greyDepthX, y, gridWidth - greyDepth + 2, rowHeight-1 ); | |
1885 | ||
d7e2b522 JS |
1886 | if ( renderFlags & wxPGCellRenderer::DontUseCellBgCol ) |
1887 | { | |
1888 | dc.SetBrush(rowBgBrush); | |
1889 | dc.SetPen(rowBgCol); | |
1890 | } | |
1c4293cb | 1891 | |
d7e2b522 JS |
1892 | if ( renderFlags & wxPGCellRenderer::DontUseCellFgCol ) |
1893 | { | |
1894 | dc.SetTextForeground(rowFgCol); | |
1895 | } | |
1c4293cb | 1896 | |
1c4293cb VZ |
1897 | wxPGCellRenderer* renderer = p->GetCellRenderer(0); |
1898 | renderer->Render( dc, cellRect, this, p, 0, -1, renderFlags ); | |
1899 | ||
1900 | // Tree Item Button | |
1901 | if ( !HasFlag(wxPG_HIDE_MARGIN) && p->HasVisibleChildren() ) | |
1902 | DrawExpanderButton( dc, butRect, p ); | |
1903 | } | |
1904 | else | |
1905 | { | |
1906 | if ( p->m_flags & wxPG_PROP_MODIFIED && (windowStyle & wxPG_BOLD_MODIFIED) ) | |
1907 | { | |
1908 | dc.SetFont(m_captionFont); | |
1909 | fontChanged = true; | |
1910 | } | |
1911 | ||
1912 | unsigned int ci; | |
1913 | int cellX = x + 1; | |
9667d393 JS |
1914 | int nextCellWidth = state->m_colWidths[0] - |
1915 | (greyDepthX - m_marginWidth); | |
1c4293cb VZ |
1916 | wxRect cellRect(greyDepthX+1, y, 0, rowHeight-1); |
1917 | int textXAdd = textMarginHere - greyDepthX; | |
1918 | ||
1919 | for ( ci=0; ci<state->m_colWidths.size(); ci++ ) | |
1920 | { | |
1921 | cellRect.width = nextCellWidth - 1; | |
1922 | ||
1923 | bool ctrlCell = false; | |
d7e2b522 JS |
1924 | int cellRenderFlags = renderFlags; |
1925 | ||
1926 | // Tree Item Button | |
1927 | if ( ci == 0 && !HasFlag(wxPG_HIDE_MARGIN) && p->HasVisibleChildren() ) | |
1928 | DrawExpanderButton( dc, butRect, p ); | |
1c4293cb VZ |
1929 | |
1930 | // Background | |
1931 | if ( p == selected && m_wndEditor && ci == 1 ) | |
1932 | { | |
1933 | wxColour editorBgCol = GetEditorControl()->GetBackgroundColour(); | |
1934 | dc.SetBrush(editorBgCol); | |
1935 | dc.SetPen(editorBgCol); | |
1936 | dc.SetTextForeground(m_colPropFore); | |
d7e2b522 | 1937 | dc.DrawRectangle(cellRect); |
1c4293cb VZ |
1938 | |
1939 | if ( m_dragStatus == 0 && !(m_iFlags & wxPG_FL_CUR_USES_CUSTOM_IMAGE) ) | |
1940 | ctrlCell = true; | |
1941 | } | |
1942 | else | |
1943 | { | |
d7e2b522 JS |
1944 | if ( renderFlags & wxPGCellRenderer::DontUseCellBgCol ) |
1945 | { | |
1946 | dc.SetBrush(rowBgBrush); | |
1947 | dc.SetPen(rowBgCol); | |
1948 | } | |
1c4293cb | 1949 | |
d7e2b522 JS |
1950 | if ( renderFlags & wxPGCellRenderer::DontUseCellFgCol ) |
1951 | { | |
1952 | dc.SetTextForeground(rowFgCol); | |
1953 | } | |
1954 | } | |
1c4293cb VZ |
1955 | |
1956 | dc.SetClippingRegion(cellRect); | |
1957 | ||
1958 | cellRect.x += textXAdd; | |
1959 | cellRect.width -= textXAdd; | |
1960 | ||
1961 | // Foreground | |
1962 | if ( !ctrlCell ) | |
1963 | { | |
1964 | wxPGCellRenderer* renderer; | |
1965 | int cmnVal = p->GetCommonValue(); | |
1966 | if ( cmnVal == -1 || ci != 1 ) | |
1967 | { | |
1968 | renderer = p->GetCellRenderer(ci); | |
d7e2b522 JS |
1969 | renderer->Render( dc, cellRect, this, p, ci, -1, |
1970 | cellRenderFlags ); | |
1c4293cb VZ |
1971 | } |
1972 | else | |
1973 | { | |
1974 | renderer = GetCommonValue(cmnVal)->GetRenderer(); | |
d7e2b522 JS |
1975 | renderer->Render( dc, cellRect, this, p, ci, -1, |
1976 | cellRenderFlags ); | |
1c4293cb VZ |
1977 | } |
1978 | } | |
1979 | ||
1980 | cellX += state->m_colWidths[ci]; | |
1981 | if ( ci < (state->m_colWidths.size()-1) ) | |
1982 | nextCellWidth = state->m_colWidths[ci+1]; | |
23318a53 | 1983 | cellRect.x = cellX; |
1c4293cb VZ |
1984 | dc.DestroyClippingRegion(); // Is this really necessary? |
1985 | textXAdd = 0; | |
1986 | } | |
1987 | } | |
1988 | ||
1989 | if ( fontChanged ) | |
2197ec80 | 1990 | dc.SetFont(normalFont); |
1c4293cb VZ |
1991 | |
1992 | y += rowHeight; | |
1993 | } | |
1994 | ||
1995 | // Refresh editor controls (seems not needed on msw) | |
1996 | // NOTE: This code is mandatory for GTK! | |
1997 | #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT | |
1998 | if ( wasSelectedPainted ) | |
1999 | { | |
2000 | if ( m_wndEditor ) | |
2001 | m_wndEditor->Refresh(); | |
2002 | if ( m_wndEditor2 ) | |
2003 | m_wndEditor2->Refresh(); | |
2004 | } | |
2005 | #endif | |
2006 | ||
2007 | return y + yRelMod; | |
2008 | } | |
2009 | ||
2010 | // ----------------------------------------------------------------------- | |
2011 | ||
2012 | wxRect wxPropertyGrid::GetPropertyRect( const wxPGProperty* p1, const wxPGProperty* p2 ) const | |
2013 | { | |
2014 | wxRect r; | |
2015 | ||
2016 | if ( m_width < 10 || m_height < 10 || | |
2017 | !m_pState->m_properties->GetChildCount() || | |
d3b9f782 | 2018 | p1 == NULL ) |
1c4293cb VZ |
2019 | return wxRect(0,0,0,0); |
2020 | ||
2021 | int vy = 0; | |
2022 | ||
2023 | // | |
2024 | // Return rect which encloses the given property range | |
2025 | ||
2026 | int visTop = p1->GetY(); | |
2027 | int visBottom; | |
2028 | if ( p2 ) | |
2029 | visBottom = p2->GetY() + m_lineHeight; | |
2030 | else | |
2031 | visBottom = m_height + visTop; | |
2032 | ||
2033 | // If seleced property is inside the range, we'll extend the range to include | |
2034 | // control's size. | |
2035 | wxPGProperty* selected = m_selected; | |
2036 | if ( selected ) | |
2037 | { | |
2038 | int selectedY = selected->GetY(); | |
2039 | if ( selectedY >= visTop && selectedY < visBottom ) | |
2040 | { | |
2041 | wxWindow* editor = GetEditorControl(); | |
2042 | if ( editor ) | |
2043 | { | |
2044 | int visBottom2 = selectedY + editor->GetSize().y; | |
2045 | if ( visBottom2 > visBottom ) | |
2046 | visBottom = visBottom2; | |
2047 | } | |
2048 | } | |
2049 | } | |
2050 | ||
2051 | return wxRect(0,visTop-vy,m_pState->m_width,visBottom-visTop); | |
2052 | } | |
2053 | ||
2054 | // ----------------------------------------------------------------------- | |
2055 | ||
2056 | void wxPropertyGrid::DrawItems( const wxPGProperty* p1, const wxPGProperty* p2 ) | |
2057 | { | |
2058 | if ( m_frozen ) | |
2059 | return; | |
2060 | ||
2061 | if ( m_pState->m_itemsAdded ) | |
2062 | PrepareAfterItemsAdded(); | |
2063 | ||
2064 | wxRect r = GetPropertyRect(p1, p2); | |
2065 | if ( r.width > 0 ) | |
2066 | { | |
2067 | m_canvas->RefreshRect(r); | |
2068 | } | |
2069 | } | |
2070 | ||
2071 | // ----------------------------------------------------------------------- | |
2072 | ||
2073 | void wxPropertyGrid::RefreshProperty( wxPGProperty* p ) | |
2074 | { | |
2075 | if ( p == m_selected ) | |
2076 | DoSelectProperty(p, wxPG_SEL_FORCE); | |
2077 | ||
2078 | DrawItemAndChildren(p); | |
2079 | } | |
2080 | ||
2081 | // ----------------------------------------------------------------------- | |
2082 | ||
2083 | void wxPropertyGrid::DrawItemAndValueRelated( wxPGProperty* p ) | |
2084 | { | |
2085 | if ( m_frozen ) | |
2086 | return; | |
2087 | ||
2088 | // Draw item, children, and parent too, if it is not category | |
2089 | wxPGProperty* parent = p->GetParent(); | |
2090 | ||
2091 | while ( parent && | |
2092 | !parent->IsCategory() && | |
2093 | parent->GetParent() ) | |
2094 | { | |
2095 | DrawItem(parent); | |
2096 | parent = parent->GetParent(); | |
2097 | } | |
2098 | ||
2099 | DrawItemAndChildren(p); | |
2100 | } | |
2101 | ||
2102 | void wxPropertyGrid::DrawItemAndChildren( wxPGProperty* p ) | |
2103 | { | |
2104 | wxCHECK_RET( p, wxT("invalid property id") ); | |
2105 | ||
2106 | // Do not draw if in non-visible page | |
2107 | if ( p->GetParentState() != m_pState ) | |
2108 | return; | |
2109 | ||
2110 | // do not draw a single item if multiple pending | |
2111 | if ( m_pState->m_itemsAdded || m_frozen ) | |
2112 | return; | |
2113 | ||
1c4293cb VZ |
2114 | // Update child control. |
2115 | if ( m_selected && m_selected->GetParent() == p ) | |
a6353fe8 | 2116 | RefreshEditor(); |
1c4293cb VZ |
2117 | |
2118 | const wxPGProperty* lastDrawn = p->GetLastVisibleSubItem(); | |
2119 | ||
2120 | DrawItems(p, lastDrawn); | |
2121 | } | |
2122 | ||
2123 | // ----------------------------------------------------------------------- | |
2124 | ||
2125 | void wxPropertyGrid::Refresh( bool WXUNUSED(eraseBackground), | |
2126 | const wxRect *rect ) | |
2127 | { | |
2128 | PrepareAfterItemsAdded(); | |
2129 | ||
2130 | wxWindow::Refresh(false); | |
2131 | if ( m_canvas ) | |
2132 | // TODO: Coordinate translation | |
2133 | m_canvas->Refresh(false, rect); | |
2134 | ||
2135 | #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT | |
2136 | // I think this really helps only GTK+1.2 | |
2137 | if ( m_wndEditor ) m_wndEditor->Refresh(); | |
2138 | if ( m_wndEditor2 ) m_wndEditor2->Refresh(); | |
2139 | #endif | |
2140 | } | |
2141 | ||
2142 | // ----------------------------------------------------------------------- | |
2143 | // wxPropertyGrid global operations | |
2144 | // ----------------------------------------------------------------------- | |
2145 | ||
2146 | void wxPropertyGrid::Clear() | |
2147 | { | |
1c4293cb VZ |
2148 | m_pState->DoClear(); |
2149 | ||
2150 | m_propHover = NULL; | |
2151 | ||
2152 | m_prevVY = 0; | |
2153 | ||
2154 | RecalculateVirtualSize(); | |
2155 | ||
2156 | // Need to clear some area at the end | |
2157 | if ( !m_frozen ) | |
2158 | RefreshRect(wxRect(0, 0, m_width, m_height)); | |
2159 | } | |
2160 | ||
2161 | // ----------------------------------------------------------------------- | |
2162 | ||
2163 | bool wxPropertyGrid::EnableCategories( bool enable ) | |
2164 | { | |
1621f192 | 2165 | ClearSelection(false); |
1c4293cb VZ |
2166 | |
2167 | if ( enable ) | |
2168 | { | |
2169 | // | |
2170 | // Enable categories | |
2171 | // | |
2172 | ||
2173 | m_windowStyle &= ~(wxPG_HIDE_CATEGORIES); | |
2174 | } | |
2175 | else | |
2176 | { | |
2177 | // | |
2178 | // Disable categories | |
2179 | // | |
2180 | m_windowStyle |= wxPG_HIDE_CATEGORIES; | |
2181 | } | |
2182 | ||
2183 | if ( !m_pState->EnableCategories(enable) ) | |
2184 | return false; | |
2185 | ||
2186 | if ( !m_frozen ) | |
2187 | { | |
2188 | if ( m_windowStyle & wxPG_AUTO_SORT ) | |
2189 | { | |
2190 | m_pState->m_itemsAdded = 1; // force | |
2191 | PrepareAfterItemsAdded(); | |
2192 | } | |
2193 | } | |
2194 | else | |
2195 | m_pState->m_itemsAdded = 1; | |
2196 | ||
2197 | // No need for RecalculateVirtualSize() here - it is already called in | |
2198 | // wxPropertyGridPageState method above. | |
2199 | ||
2200 | Refresh(); | |
2201 | ||
2202 | return true; | |
2203 | } | |
2204 | ||
2205 | // ----------------------------------------------------------------------- | |
2206 | ||
2207 | void wxPropertyGrid::SwitchState( wxPropertyGridPageState* pNewState ) | |
2208 | { | |
2209 | wxASSERT( pNewState ); | |
2210 | wxASSERT( pNewState->GetGrid() ); | |
2211 | ||
2212 | if ( pNewState == m_pState ) | |
2213 | return; | |
2214 | ||
2215 | wxPGProperty* oldSelection = m_selected; | |
2216 | ||
1621f192 | 2217 | ClearSelection(false); |
1c4293cb VZ |
2218 | |
2219 | m_pState->m_selected = oldSelection; | |
2220 | ||
2221 | bool orig_mode = m_pState->IsInNonCatMode(); | |
2222 | bool new_state_mode = pNewState->IsInNonCatMode(); | |
2223 | ||
2224 | m_pState = pNewState; | |
2225 | ||
2226 | // Validate width | |
2227 | int pgWidth = GetClientSize().x; | |
2228 | if ( HasVirtualWidth() ) | |
2229 | { | |
2230 | int minWidth = pgWidth; | |
2231 | if ( pNewState->m_width < minWidth ) | |
2232 | { | |
2233 | pNewState->m_width = minWidth; | |
2234 | pNewState->CheckColumnWidths(); | |
2235 | } | |
2236 | } | |
2237 | else | |
2238 | { | |
2239 | // | |
2240 | // Just in case, fully re-center splitter | |
2241 | if ( HasFlag( wxPG_SPLITTER_AUTO_CENTER ) ) | |
2242 | pNewState->m_fSplitterX = -1.0; | |
2243 | ||
2244 | pNewState->OnClientWidthChange( pgWidth, pgWidth - pNewState->m_width ); | |
2245 | } | |
2246 | ||
d3b9f782 | 2247 | m_propHover = NULL; |
1c4293cb VZ |
2248 | |
2249 | // If necessary, convert state to correct mode. | |
2250 | if ( orig_mode != new_state_mode ) | |
2251 | { | |
2252 | // This should refresh as well. | |
2253 | EnableCategories( orig_mode?false:true ); | |
2254 | } | |
2255 | else if ( !m_frozen ) | |
2256 | { | |
2257 | // Refresh, if not frozen. | |
0eb877f2 | 2258 | m_pState->PrepareAfterItemsAdded(); |
1c4293cb VZ |
2259 | |
2260 | // Reselect | |
2261 | if ( m_pState->m_selected ) | |
2262 | DoSelectProperty( m_pState->m_selected ); | |
2263 | ||
2264 | RecalculateVirtualSize(0); | |
2265 | Refresh(); | |
2266 | } | |
2267 | else | |
2268 | m_pState->m_itemsAdded = 1; | |
2269 | } | |
2270 | ||
2271 | // ----------------------------------------------------------------------- | |
2272 | ||
1c4293cb VZ |
2273 | // Call to SetSplitterPosition will always disable splitter auto-centering |
2274 | // if parent window is shown. | |
2275 | void wxPropertyGrid::DoSetSplitterPosition_( int newxpos, bool refresh, int splitterIndex, bool allPages ) | |
2276 | { | |
2277 | if ( ( newxpos < wxPG_DRAG_MARGIN ) ) | |
2278 | return; | |
2279 | ||
2280 | wxPropertyGridPageState* state = m_pState; | |
2281 | ||
2282 | state->DoSetSplitterPosition( newxpos, splitterIndex, allPages ); | |
2283 | ||
2284 | if ( refresh ) | |
2285 | { | |
2286 | if ( m_selected ) | |
2287 | CorrectEditorWidgetSizeX(); | |
2288 | ||
2289 | Refresh(); | |
2290 | } | |
2291 | } | |
2292 | ||
2293 | // ----------------------------------------------------------------------- | |
2294 | ||
2295 | void wxPropertyGrid::CenterSplitter( bool enableAutoCentering ) | |
2296 | { | |
2297 | SetSplitterPosition( m_width/2, true ); | |
2298 | if ( enableAutoCentering && ( m_windowStyle & wxPG_SPLITTER_AUTO_CENTER ) ) | |
2299 | m_iFlags &= ~(wxPG_FL_DONT_CENTER_SPLITTER); | |
2300 | } | |
2301 | ||
2302 | // ----------------------------------------------------------------------- | |
2303 | // wxPropertyGrid item iteration (GetNextProperty etc.) methods | |
2304 | // ----------------------------------------------------------------------- | |
2305 | ||
2306 | // Returns nearest paint visible property (such that will be painted unless | |
2307 | // window is scrolled or resized). If given property is paint visible, then | |
2308 | // it itself will be returned | |
2309 | wxPGProperty* wxPropertyGrid::GetNearestPaintVisible( wxPGProperty* p ) const | |
2310 | { | |
2311 | int vx,vy1;// Top left corner of client | |
2312 | GetViewStart(&vx,&vy1); | |
2313 | vy1 *= wxPG_PIXELS_PER_UNIT; | |
2314 | ||
2315 | int vy2 = vy1 + m_height; | |
2316 | int propY = p->GetY2(m_lineHeight); | |
2317 | ||
2318 | if ( (propY + m_lineHeight) < vy1 ) | |
2319 | { | |
2320 | // Too high | |
2321 | return DoGetItemAtY( vy1 ); | |
2322 | } | |
2323 | else if ( propY > vy2 ) | |
2324 | { | |
2325 | // Too low | |
2326 | return DoGetItemAtY( vy2 ); | |
2327 | } | |
2328 | ||
2329 | // Itself paint visible | |
2330 | return p; | |
2331 | ||
2332 | } | |
2333 | ||
1c4293cb VZ |
2334 | // ----------------------------------------------------------------------- |
2335 | // Methods related to change in value, value modification and sending events | |
2336 | // ----------------------------------------------------------------------- | |
2337 | ||
2338 | // commits any changes in editor of selected property | |
2339 | // return true if validation did not fail | |
2340 | // flags are same as with DoSelectProperty | |
2341 | bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags ) | |
2342 | { | |
2343 | // Committing already? | |
2344 | if ( m_inCommitChangesFromEditor ) | |
2345 | return true; | |
2346 | ||
2347 | // Don't do this if already processing editor event. It might | |
2348 | // induce recursive dialogs and crap like that. | |
b0996c3d | 2349 | if ( m_iFlags & wxPG_FL_IN_HANDLECUSTOMEDITOREVENT ) |
1c4293cb VZ |
2350 | { |
2351 | if ( m_inDoPropertyChanged ) | |
2352 | return true; | |
2353 | ||
2354 | return false; | |
2355 | } | |
2356 | ||
2357 | if ( m_wndEditor && | |
2358 | IsEditorsValueModified() && | |
2359 | (m_iFlags & wxPG_FL_INITIALIZED) && | |
2360 | m_selected ) | |
2361 | { | |
2362 | m_inCommitChangesFromEditor = 1; | |
2363 | ||
2364 | wxVariant variant(m_selected->GetValueRef()); | |
2365 | bool valueIsPending = false; | |
2366 | ||
2367 | // JACS - necessary to avoid new focus being found spuriously within OnIdle | |
2368 | // due to another window getting focus | |
2369 | wxWindow* oldFocus = m_curFocused; | |
2370 | ||
2371 | bool validationFailure = false; | |
2372 | bool forceSuccess = (flags & (wxPG_SEL_NOVALIDATE|wxPG_SEL_FORCE)) ? true : false; | |
2373 | ||
2374 | m_chgInfo_changedProperty = NULL; | |
2375 | ||
2376 | // If truly modified, schedule value as pending. | |
2377 | if ( m_selected->GetEditorClass()->GetValueFromControl( variant, m_selected, GetEditorControl() ) ) | |
2378 | { | |
2379 | if ( DoEditorValidate() && | |
2380 | PerformValidation(m_selected, variant) ) | |
2381 | { | |
2382 | valueIsPending = true; | |
2383 | } | |
2384 | else | |
2385 | { | |
2386 | validationFailure = true; | |
2387 | } | |
2388 | } | |
2389 | else | |
2390 | { | |
2391 | EditorsValueWasNotModified(); | |
2392 | } | |
2393 | ||
2394 | bool res = true; | |
2395 | ||
2396 | m_inCommitChangesFromEditor = 0; | |
2397 | ||
2398 | if ( validationFailure && !forceSuccess ) | |
2399 | { | |
2400 | if (oldFocus) | |
2401 | { | |
2402 | oldFocus->SetFocus(); | |
2403 | m_curFocused = oldFocus; | |
2404 | } | |
2405 | ||
2406 | res = OnValidationFailure(m_selected, variant); | |
2407 | ||
2408 | // Now prevent further validation failure messages | |
2409 | if ( res ) | |
2410 | { | |
2411 | EditorsValueWasNotModified(); | |
2412 | OnValidationFailureReset(m_selected); | |
2413 | } | |
2414 | } | |
2415 | else if ( valueIsPending ) | |
2416 | { | |
2417 | DoPropertyChanged( m_selected, flags ); | |
2418 | EditorsValueWasNotModified(); | |
2419 | } | |
2420 | ||
2421 | return res; | |
2422 | } | |
2423 | ||
2424 | return true; | |
2425 | } | |
2426 | ||
2427 | // ----------------------------------------------------------------------- | |
2428 | ||
9b5bafcf JS |
2429 | bool wxPropertyGrid::PerformValidation( wxPGProperty* p, wxVariant& pendingValue, |
2430 | int flags ) | |
1c4293cb VZ |
2431 | { |
2432 | // | |
2433 | // Runs all validation functionality. | |
2434 | // Returns true if value passes all tests. | |
2435 | // | |
2436 | ||
2437 | m_validationInfo.m_failureBehavior = m_permanentValidationFailureBehavior; | |
2438 | ||
0372d42e | 2439 | if ( pendingValue.GetType() == wxPG_VARIANT_TYPE_LIST ) |
1c4293cb VZ |
2440 | { |
2441 | if ( !p->ValidateValue(pendingValue, m_validationInfo) ) | |
2442 | return false; | |
2443 | } | |
2444 | ||
2445 | // | |
2446 | // Adapt list to child values, if necessary | |
2447 | wxVariant listValue = pendingValue; | |
2448 | wxVariant* pPendingValue = &pendingValue; | |
2449 | wxVariant* pList = NULL; | |
2450 | ||
2451 | // If parent has wxPG_PROP_AGGREGATE flag, or uses composite | |
2452 | // string value, then we need treat as it was changed instead | |
2453 | // (or, in addition, as is the case with composite string parent). | |
2454 | // This includes creating list variant for child values. | |
2455 | ||
2456 | wxPGProperty* pwc = p->GetParent(); | |
2457 | wxPGProperty* changedProperty = p; | |
2458 | wxPGProperty* baseChangedProperty = changedProperty; | |
2459 | wxVariant bcpPendingList; | |
2460 | ||
2461 | listValue = pendingValue; | |
d665918b | 2462 | listValue.SetName(p->GetBaseName()); |
1c4293cb VZ |
2463 | |
2464 | while ( pwc && | |
2465 | (pwc->HasFlag(wxPG_PROP_AGGREGATE) || pwc->HasFlag(wxPG_PROP_COMPOSED_VALUE)) ) | |
2466 | { | |
2467 | wxVariantList tempList; | |
d665918b | 2468 | wxVariant lv(tempList, pwc->GetBaseName()); |
1c4293cb VZ |
2469 | lv.Append(listValue); |
2470 | listValue = lv; | |
2471 | pPendingValue = &listValue; | |
2472 | ||
2473 | if ( pwc->HasFlag(wxPG_PROP_AGGREGATE) ) | |
2474 | { | |
2475 | baseChangedProperty = pwc; | |
2476 | bcpPendingList = lv; | |
2477 | } | |
2478 | ||
2479 | changedProperty = pwc; | |
2480 | pwc = pwc->GetParent(); | |
2481 | } | |
2482 | ||
2483 | wxVariant value; | |
2484 | wxPGProperty* evtChangingProperty = changedProperty; | |
2485 | ||
0372d42e | 2486 | if ( pPendingValue->GetType() != wxPG_VARIANT_TYPE_LIST ) |
1c4293cb VZ |
2487 | { |
2488 | value = *pPendingValue; | |
2489 | } | |
2490 | else | |
2491 | { | |
2492 | // Convert list to child values | |
2493 | pList = pPendingValue; | |
2494 | changedProperty->AdaptListToValue( *pPendingValue, &value ); | |
2495 | } | |
2496 | ||
2497 | wxVariant evtChangingValue = value; | |
2498 | ||
9b5bafcf | 2499 | if ( flags & SendEvtChanging ) |
1c4293cb | 2500 | { |
9b5bafcf JS |
2501 | // FIXME: After proper ValueToString()s added, remove |
2502 | // this. It is just a temporary fix, as evt_changing | |
2503 | // will simply not work for wxPG_PROP_COMPOSED_VALUE | |
2504 | // (unless it is selected, and textctrl editor is open). | |
2505 | if ( changedProperty->HasFlag(wxPG_PROP_COMPOSED_VALUE) ) | |
1c4293cb | 2506 | { |
9b5bafcf JS |
2507 | evtChangingProperty = baseChangedProperty; |
2508 | if ( evtChangingProperty != p ) | |
2509 | { | |
2510 | evtChangingProperty->AdaptListToValue( bcpPendingList, &evtChangingValue ); | |
2511 | } | |
2512 | else | |
2513 | { | |
2514 | evtChangingValue = pendingValue; | |
2515 | } | |
1c4293cb | 2516 | } |
1c4293cb | 2517 | |
9b5bafcf | 2518 | if ( evtChangingProperty->HasFlag(wxPG_PROP_COMPOSED_VALUE) ) |
1c4293cb | 2519 | { |
9b5bafcf JS |
2520 | if ( changedProperty == m_selected ) |
2521 | { | |
2522 | wxWindow* editor = GetEditorControl(); | |
2523 | wxASSERT( editor->IsKindOf(CLASSINFO(wxTextCtrl)) ); | |
2524 | evtChangingValue = wxStaticCast(editor, wxTextCtrl)->GetValue(); | |
2525 | } | |
2526 | else | |
2527 | { | |
2528 | wxLogDebug(wxT("WARNING: wxEVT_PG_CHANGING is about to happen with old value.")); | |
2529 | } | |
1c4293cb VZ |
2530 | } |
2531 | } | |
2532 | ||
2533 | wxASSERT( m_chgInfo_changedProperty == NULL ); | |
2534 | m_chgInfo_changedProperty = changedProperty; | |
2535 | m_chgInfo_baseChangedProperty = baseChangedProperty; | |
2536 | m_chgInfo_pendingValue = value; | |
2537 | ||
2538 | if ( pList ) | |
2539 | m_chgInfo_valueList = *pList; | |
2540 | else | |
2541 | m_chgInfo_valueList.MakeNull(); | |
2542 | ||
2543 | // If changedProperty is not property which value was edited, | |
2544 | // then call wxPGProperty::ValidateValue() for that as well. | |
0372d42e | 2545 | if ( p != changedProperty && value.GetType() != wxPG_VARIANT_TYPE_LIST ) |
1c4293cb VZ |
2546 | { |
2547 | if ( !changedProperty->ValidateValue(value, m_validationInfo) ) | |
2548 | return false; | |
2549 | } | |
2550 | ||
9b5bafcf JS |
2551 | if ( flags & SendEvtChanging ) |
2552 | { | |
2553 | // SendEvent returns true if event was vetoed | |
2554 | if ( SendEvent( wxEVT_PG_CHANGING, evtChangingProperty, &evtChangingValue, 0 ) ) | |
2555 | return false; | |
2556 | } | |
2557 | ||
2558 | if ( flags & IsStandaloneValidation ) | |
2559 | { | |
2560 | // If called in 'generic' context, we need to reset | |
2561 | // m_chgInfo_changedProperty and write back translated value. | |
2562 | m_chgInfo_changedProperty = NULL; | |
2563 | pendingValue = value; | |
2564 | } | |
1c4293cb VZ |
2565 | |
2566 | return true; | |
2567 | } | |
2568 | ||
2569 | // ----------------------------------------------------------------------- | |
2570 | ||
2571 | void wxPropertyGrid::DoShowPropertyError( wxPGProperty* WXUNUSED(property), const wxString& msg ) | |
2572 | { | |
2573 | if ( !msg.length() ) | |
2574 | return; | |
2575 | ||
2576 | #if wxUSE_STATUSBAR | |
2577 | if ( !wxPGGlobalVars->m_offline ) | |
2578 | { | |
2579 | wxWindow* topWnd = ::wxGetTopLevelParent(this); | |
2580 | if ( topWnd ) | |
2581 | { | |
2582 | wxFrame* pFrame = wxDynamicCast(topWnd, wxFrame); | |
2583 | if ( pFrame ) | |
2584 | { | |
2585 | wxStatusBar* pStatusBar = pFrame->GetStatusBar(); | |
2586 | if ( pStatusBar ) | |
2587 | { | |
2588 | pStatusBar->SetStatusText(msg); | |
2589 | return; | |
2590 | } | |
2591 | } | |
2592 | } | |
2593 | } | |
2594 | #endif | |
2595 | ||
2596 | ::wxMessageBox(msg, _T("Property Error")); | |
2597 | } | |
2598 | ||
2599 | // ----------------------------------------------------------------------- | |
2600 | ||
d8812c6e JS |
2601 | bool wxPropertyGrid::OnValidationFailure( wxPGProperty* property, |
2602 | wxVariant& invalidValue ) | |
2603 | { | |
2604 | wxWindow* editor = GetEditorControl(); | |
2605 | ||
2606 | // First call property's handler | |
2607 | property->OnValidationFailure(invalidValue); | |
2608 | ||
2609 | bool res = DoOnValidationFailure(property, invalidValue); | |
2610 | ||
2611 | // | |
2612 | // For non-wxTextCtrl editors, we do need to revert the value | |
2613 | if ( !editor->IsKindOf(CLASSINFO(wxTextCtrl)) && | |
2614 | property == m_selected ) | |
2615 | { | |
2616 | property->GetEditorClass()->UpdateControl(property, editor); | |
2617 | } | |
2618 | ||
2619 | property->SetFlag(wxPG_PROP_INVALID_VALUE); | |
2620 | ||
2621 | return res; | |
2622 | } | |
2623 | ||
1c4293cb VZ |
2624 | bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty* property, wxVariant& WXUNUSED(invalidValue) ) |
2625 | { | |
2626 | int vfb = m_validationInfo.m_failureBehavior; | |
2627 | ||
2628 | if ( vfb & wxPG_VFB_BEEP ) | |
2629 | ::wxBell(); | |
2630 | ||
2631 | if ( (vfb & wxPG_VFB_MARK_CELL) && | |
2632 | !property->HasFlag(wxPG_PROP_INVALID_VALUE) ) | |
2633 | { | |
d7e2b522 | 2634 | unsigned int colCount = m_pState->GetColumnCount(); |
1c4293cb | 2635 | |
d7e2b522 JS |
2636 | // We need backup marked property's cells |
2637 | m_propCellsBackup = property->m_cells; | |
2638 | ||
2639 | wxColour vfbFg = *wxWHITE; | |
2640 | wxColour vfbBg = *wxRED; | |
2641 | ||
2642 | property->EnsureCells(colCount); | |
2643 | ||
2644 | for ( unsigned int i=0; i<colCount; i++ ) | |
1c4293cb | 2645 | { |
d7e2b522 JS |
2646 | wxPGCell& cell = property->m_cells[i]; |
2647 | cell.SetFgCol(vfbFg); | |
2648 | cell.SetBgCol(vfbBg); | |
2649 | } | |
1c4293cb | 2650 | |
d7e2b522 | 2651 | DrawItemAndChildren(property); |
1c4293cb | 2652 | |
d7e2b522 JS |
2653 | if ( property == m_selected ) |
2654 | { | |
2655 | SetInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL); | |
1c4293cb | 2656 | |
d7e2b522 JS |
2657 | wxWindow* editor = GetEditorControl(); |
2658 | if ( editor ) | |
2659 | { | |
2660 | editor->SetForegroundColour(vfbFg); | |
2661 | editor->SetBackgroundColour(vfbBg); | |
1c4293cb VZ |
2662 | } |
2663 | } | |
2664 | } | |
2665 | ||
2666 | if ( vfb & wxPG_VFB_SHOW_MESSAGE ) | |
2667 | { | |
2668 | wxString msg = m_validationInfo.m_failureMessage; | |
2669 | ||
2670 | if ( !msg.length() ) | |
2671 | msg = _T("You have entered invalid value. Press ESC to cancel editing."); | |
2672 | ||
2673 | DoShowPropertyError(property, msg); | |
2674 | } | |
2675 | ||
2676 | return (vfb & wxPG_VFB_STAY_IN_PROPERTY) ? false : true; | |
2677 | } | |
2678 | ||
2679 | // ----------------------------------------------------------------------- | |
2680 | ||
2681 | void wxPropertyGrid::DoOnValidationFailureReset( wxPGProperty* property ) | |
2682 | { | |
2683 | int vfb = m_validationInfo.m_failureBehavior; | |
2684 | ||
2685 | if ( vfb & wxPG_VFB_MARK_CELL ) | |
2686 | { | |
d7e2b522 JS |
2687 | // Revert cells |
2688 | property->m_cells = m_propCellsBackup; | |
1c4293cb VZ |
2689 | |
2690 | ClearInternalFlag(wxPG_FL_CELL_OVERRIDES_SEL); | |
2691 | ||
2692 | if ( property == m_selected && GetEditorControl() ) | |
2693 | { | |
2694 | // Calling this will recreate the control, thus resetting its colour | |
2695 | RefreshProperty(property); | |
2696 | } | |
2697 | else | |
2698 | { | |
2699 | DrawItemAndChildren(property); | |
2700 | } | |
2701 | } | |
2702 | } | |
2703 | ||
2704 | // ----------------------------------------------------------------------- | |
2705 | ||
2706 | // flags are same as with DoSelectProperty | |
2707 | bool wxPropertyGrid::DoPropertyChanged( wxPGProperty* p, unsigned int selFlags ) | |
2708 | { | |
2709 | if ( m_inDoPropertyChanged ) | |
2710 | return true; | |
2711 | ||
f9189014 JS |
2712 | wxWindow* editor = GetEditorControl(); |
2713 | ||
1c4293cb VZ |
2714 | m_pState->m_anyModified = 1; |
2715 | ||
2716 | m_inDoPropertyChanged = 1; | |
2717 | ||
2718 | // Maybe need to update control | |
2719 | wxASSERT( m_chgInfo_changedProperty != NULL ); | |
2720 | ||
2721 | // These values were calculated in PerformValidation() | |
2722 | wxPGProperty* changedProperty = m_chgInfo_changedProperty; | |
2723 | wxVariant value = m_chgInfo_pendingValue; | |
2724 | ||
2725 | wxPGProperty* topPaintedProperty = changedProperty; | |
2726 | ||
2727 | while ( !topPaintedProperty->IsCategory() && | |
2728 | !topPaintedProperty->IsRoot() ) | |
2729 | { | |
2730 | topPaintedProperty = topPaintedProperty->GetParent(); | |
2731 | } | |
2732 | ||
8f18b252 | 2733 | changedProperty->SetValue(value, &m_chgInfo_valueList, wxPG_SETVAL_BY_USER); |
1c4293cb VZ |
2734 | |
2735 | // Set as Modified (not if dragging just began) | |
2736 | if ( !(p->m_flags & wxPG_PROP_MODIFIED) ) | |
2737 | { | |
2738 | p->m_flags |= wxPG_PROP_MODIFIED; | |
2739 | if ( p == m_selected && (m_windowStyle & wxPG_BOLD_MODIFIED) ) | |
2740 | { | |
f9189014 | 2741 | if ( editor ) |
1c4293cb VZ |
2742 | SetCurControlBoldFont(); |
2743 | } | |
2744 | } | |
2745 | ||
2746 | wxPGProperty* pwc; | |
2747 | ||
2748 | // Propagate updates to parent(s) | |
2749 | pwc = p; | |
2750 | wxPGProperty* prevPwc = NULL; | |
2751 | ||
2752 | while ( prevPwc != topPaintedProperty ) | |
2753 | { | |
2754 | pwc->m_flags |= wxPG_PROP_MODIFIED; | |
2755 | ||
2756 | if ( pwc == m_selected && (m_windowStyle & wxPG_BOLD_MODIFIED) ) | |
2757 | { | |
f9189014 | 2758 | if ( editor ) |
1c4293cb VZ |
2759 | SetCurControlBoldFont(); |
2760 | } | |
2761 | ||
2762 | prevPwc = pwc; | |
2763 | pwc = pwc->GetParent(); | |
2764 | } | |
2765 | ||
2766 | // Draw the actual property | |
2767 | DrawItemAndChildren( topPaintedProperty ); | |
2768 | ||
2769 | // | |
2770 | // If value was set by wxPGProperty::OnEvent, then update the editor | |
2771 | // control. | |
2772 | if ( selFlags & wxPG_SEL_DIALOGVAL ) | |
2773 | { | |
a6353fe8 | 2774 | RefreshEditor(); |
1c4293cb VZ |
2775 | } |
2776 | else | |
2777 | { | |
2778 | #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT | |
2779 | if ( m_wndEditor ) m_wndEditor->Refresh(); | |
2780 | if ( m_wndEditor2 ) m_wndEditor2->Refresh(); | |
2781 | #endif | |
2782 | } | |
2783 | ||
2784 | // Sanity check | |
2785 | wxASSERT( !changedProperty->GetParent()->HasFlag(wxPG_PROP_AGGREGATE) ); | |
2786 | ||
2787 | // If top parent has composite string value, then send to child parents, | |
2788 | // starting from baseChangedProperty. | |
2789 | if ( changedProperty->HasFlag(wxPG_PROP_COMPOSED_VALUE) ) | |
2790 | { | |
2791 | pwc = m_chgInfo_baseChangedProperty; | |
2792 | ||
2793 | while ( pwc != changedProperty ) | |
2794 | { | |
2795 | SendEvent( wxEVT_PG_CHANGED, pwc, NULL, selFlags ); | |
2796 | pwc = pwc->GetParent(); | |
2797 | } | |
2798 | } | |
2799 | ||
2800 | SendEvent( wxEVT_PG_CHANGED, changedProperty, NULL, selFlags ); | |
2801 | ||
2802 | m_inDoPropertyChanged = 0; | |
2803 | ||
2804 | return true; | |
2805 | } | |
2806 | ||
2807 | // ----------------------------------------------------------------------- | |
2808 | ||
2809 | bool wxPropertyGrid::ChangePropertyValue( wxPGPropArg id, wxVariant newValue ) | |
2810 | { | |
2811 | wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false) | |
2812 | ||
2813 | m_chgInfo_changedProperty = NULL; | |
2814 | ||
2815 | if ( PerformValidation(p, newValue) ) | |
2816 | { | |
2817 | DoPropertyChanged(p); | |
2818 | return true; | |
2819 | } | |
2820 | else | |
2821 | { | |
2822 | OnValidationFailure(p, newValue); | |
2823 | } | |
2824 | ||
2825 | return false; | |
2826 | } | |
2827 | ||
2828 | // ----------------------------------------------------------------------- | |
9b5bafcf | 2829 | |
703ee9f5 | 2830 | wxVariant wxPropertyGrid::GetUncommittedPropertyValue() |
9b5bafcf JS |
2831 | { |
2832 | wxPGProperty* prop = GetSelectedProperty(); | |
2833 | ||
2834 | if ( !prop ) | |
2835 | return wxNullVariant; | |
2836 | ||
2837 | wxTextCtrl* tc = GetEditorTextCtrl(); | |
2838 | wxVariant value = prop->GetValue(); | |
2839 | ||
2840 | if ( !tc || !IsEditorsValueModified() ) | |
2841 | return value; | |
2842 | ||
2843 | if ( !prop->StringToValue(value, tc->GetValue()) ) | |
2844 | return value; | |
2845 | ||
2846 | if ( !PerformValidation(prop, value, IsStandaloneValidation) ) | |
2847 | return prop->GetValue(); | |
2848 | ||
2849 | return value; | |
2850 | } | |
2851 | ||
2852 | // ----------------------------------------------------------------------- | |
1c4293cb VZ |
2853 | |
2854 | // Runs wxValidator for the selected property | |
2855 | bool wxPropertyGrid::DoEditorValidate() | |
2856 | { | |
1c4293cb VZ |
2857 | return true; |
2858 | } | |
2859 | ||
2860 | // ----------------------------------------------------------------------- | |
2861 | ||
b0996c3d | 2862 | void wxPropertyGrid::HandleCustomEditorEvent( wxEvent &event ) |
1c4293cb VZ |
2863 | { |
2864 | wxPGProperty* selected = m_selected; | |
2865 | ||
1c4293cb VZ |
2866 | // Somehow, event is handled after property has been deselected. |
2867 | // Possibly, but very rare. | |
2868 | if ( !selected ) | |
2869 | return; | |
2870 | ||
b0996c3d | 2871 | if ( m_iFlags & wxPG_FL_IN_HANDLECUSTOMEDITOREVENT ) |
1c4293cb VZ |
2872 | return; |
2873 | ||
2874 | wxVariant pendingValue(selected->GetValueRef()); | |
2875 | wxWindow* wnd = GetEditorControl(); | |
6086bcc8 | 2876 | wxWindow* editorWnd = wxDynamicCast(event.GetEventObject(), wxWindow); |
1c4293cb VZ |
2877 | int selFlags = 0; |
2878 | bool wasUnspecified = selected->IsValueUnspecified(); | |
2879 | int usesAutoUnspecified = selected->UsesAutoUnspecified(); | |
1c4293cb VZ |
2880 | bool valueIsPending = false; |
2881 | ||
2882 | m_chgInfo_changedProperty = NULL; | |
2883 | ||
2884 | m_iFlags &= ~(wxPG_FL_VALIDATION_FAILED|wxPG_FL_VALUE_CHANGE_IN_EVENT); | |
2885 | ||
2886 | // | |
2887 | // Filter out excess wxTextCtrl modified events | |
2888 | if ( event.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED && | |
2889 | wnd && | |
2890 | wnd->IsKindOf(CLASSINFO(wxTextCtrl)) ) | |
2891 | { | |
2892 | wxTextCtrl* tc = (wxTextCtrl*) wnd; | |
2893 | ||
2894 | wxString newTcValue = tc->GetValue(); | |
2895 | if ( m_prevTcValue == newTcValue ) | |
2896 | return; | |
2897 | ||
2898 | m_prevTcValue = newTcValue; | |
2899 | } | |
2900 | ||
b0996c3d | 2901 | SetInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT); |
1c4293cb VZ |
2902 | |
2903 | bool validationFailure = false; | |
2904 | bool buttonWasHandled = false; | |
2905 | ||
2906 | // | |
2907 | // Try common button handling | |
2908 | if ( m_wndEditor2 && event.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED ) | |
2909 | { | |
2910 | wxPGEditorDialogAdapter* adapter = selected->GetEditorDialog(); | |
2911 | ||
2912 | if ( adapter ) | |
2913 | { | |
2914 | buttonWasHandled = true; | |
2915 | // Store as res2, as previously (and still currently alternatively) | |
2916 | // dialogs can be shown by handling wxEVT_COMMAND_BUTTON_CLICKED | |
2917 | // in wxPGProperty::OnEvent(). | |
2918 | adapter->ShowDialog( this, selected ); | |
2919 | delete adapter; | |
2920 | } | |
2921 | } | |
2922 | ||
7de050ad | 2923 | if ( !buttonWasHandled ) |
1c4293cb | 2924 | { |
6086bcc8 | 2925 | if ( wnd || m_wndEditor2 ) |
1c4293cb | 2926 | { |
7de050ad JS |
2927 | // First call editor class' event handler. |
2928 | const wxPGEditor* editor = selected->GetEditorClass(); | |
2929 | ||
6086bcc8 | 2930 | if ( editor->OnEvent( this, selected, editorWnd, event ) ) |
1c4293cb | 2931 | { |
7de050ad JS |
2932 | // If changes, validate them |
2933 | if ( DoEditorValidate() ) | |
2934 | { | |
6086bcc8 JS |
2935 | if ( editor->GetValueFromControl( pendingValue, |
2936 | m_selected, | |
2937 | wnd ) ) | |
7de050ad JS |
2938 | valueIsPending = true; |
2939 | } | |
2940 | else | |
2941 | { | |
2942 | validationFailure = true; | |
2943 | } | |
1c4293cb VZ |
2944 | } |
2945 | } | |
2946 | ||
2947 | // Then the property's custom handler (must be always called, unless | |
2948 | // validation failed). | |
2949 | if ( !validationFailure ) | |
6086bcc8 | 2950 | buttonWasHandled = selected->OnEvent( this, editorWnd, event ); |
1c4293cb VZ |
2951 | } |
2952 | ||
2953 | // SetValueInEvent(), as called in one of the functions referred above | |
2954 | // overrides editor's value. | |
2955 | if ( m_iFlags & wxPG_FL_VALUE_CHANGE_IN_EVENT ) | |
2956 | { | |
2957 | valueIsPending = true; | |
2958 | pendingValue = m_changeInEventValue; | |
2959 | selFlags |= wxPG_SEL_DIALOGVAL; | |
2960 | } | |
2961 | ||
2962 | if ( !validationFailure && valueIsPending ) | |
2963 | if ( !PerformValidation(m_selected, pendingValue) ) | |
2964 | validationFailure = true; | |
2965 | ||
a5d56762 | 2966 | if ( validationFailure) |
1c4293cb VZ |
2967 | { |
2968 | OnValidationFailure(selected, pendingValue); | |
2969 | } | |
2970 | else if ( valueIsPending ) | |
2971 | { | |
2972 | selFlags |= ( !wasUnspecified && selected->IsValueUnspecified() && usesAutoUnspecified ) ? wxPG_SEL_SETUNSPEC : 0; | |
2973 | ||
2974 | DoPropertyChanged(selected, selFlags); | |
2975 | EditorsValueWasNotModified(); | |
0d4884cb | 2976 | |
0d4884cb JS |
2977 | // Regardless of editor type, unfocus editor on |
2978 | // text-editing related enter press. | |
2979 | if ( event.GetEventType() == wxEVT_COMMAND_TEXT_ENTER ) | |
2980 | { | |
2981 | SetFocusOnCanvas(); | |
2982 | } | |
1c4293cb VZ |
2983 | } |
2984 | else | |
2985 | { | |
2986 | // No value after all | |
23318a53 | 2987 | |
a5d56762 RR |
2988 | // Regardless of editor type, unfocus editor on |
2989 | // text-editing related enter press. | |
2990 | if ( event.GetEventType() == wxEVT_COMMAND_TEXT_ENTER ) | |
2991 | { | |
2992 | SetFocusOnCanvas(); | |
2993 | } | |
1c4293cb VZ |
2994 | |
2995 | // Let unhandled button click events go to the parent | |
2996 | if ( !buttonWasHandled && event.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED ) | |
2997 | { | |
2998 | wxCommandEvent evt(wxEVT_COMMAND_BUTTON_CLICKED,GetId()); | |
2999 | GetEventHandler()->AddPendingEvent(evt); | |
3000 | } | |
3001 | } | |
3002 | ||
b0996c3d | 3003 | ClearInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT); |
1c4293cb VZ |
3004 | } |
3005 | ||
3006 | // ----------------------------------------------------------------------- | |
3007 | // wxPropertyGrid editor control helper methods | |
3008 | // ----------------------------------------------------------------------- | |
3009 | ||
3010 | wxRect wxPropertyGrid::GetEditorWidgetRect( wxPGProperty* p, int column ) const | |
3011 | { | |
3012 | int itemy = p->GetY2(m_lineHeight); | |
3013 | int vy = 0; | |
1c4293cb VZ |
3014 | int splitterX = m_pState->DoGetSplitterPosition(column-1); |
3015 | int colEnd = splitterX + m_pState->m_colWidths[column]; | |
4aee8334 | 3016 | int imageOffset = 0; |
1c4293cb VZ |
3017 | |
3018 | // TODO: If custom image detection changes from current, change this. | |
4aee8334 | 3019 | if ( m_iFlags & wxPG_FL_CUR_USES_CUSTOM_IMAGE ) |
1c4293cb VZ |
3020 | { |
3021 | //m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE; | |
4aee8334 JS |
3022 | int iw = p->OnMeasureImage().x; |
3023 | if ( iw < 1 ) | |
3024 | iw = wxPG_CUSTOM_IMAGE_WIDTH; | |
3025 | imageOffset = p->GetImageOffset(iw); | |
1c4293cb VZ |
3026 | } |
3027 | ||
3028 | return wxRect | |
3029 | ( | |
4aee8334 | 3030 | splitterX+imageOffset+wxPG_XBEFOREWIDGET+wxPG_CONTROL_MARGIN+1, |
1c4293cb | 3031 | itemy-vy, |
4aee8334 | 3032 | colEnd-splitterX-wxPG_XBEFOREWIDGET-wxPG_CONTROL_MARGIN-imageOffset-1, |
1c4293cb VZ |
3033 | m_lineHeight-1 |
3034 | ); | |
3035 | } | |
3036 | ||
3037 | // ----------------------------------------------------------------------- | |
3038 | ||
3039 | wxRect wxPropertyGrid::GetImageRect( wxPGProperty* p, int item ) const | |
3040 | { | |
3041 | wxSize sz = GetImageSize(p, item); | |
3042 | return wxRect(wxPG_CONTROL_MARGIN + wxCC_CUSTOM_IMAGE_MARGIN1, | |
3043 | wxPG_CUSTOM_IMAGE_SPACINGY, | |
3044 | sz.x, | |
3045 | sz.y); | |
3046 | } | |
3047 | ||
3048 | // return size of custom paint image | |
3049 | wxSize wxPropertyGrid::GetImageSize( wxPGProperty* p, int item ) const | |
3050 | { | |
3051 | // If called with NULL property, then return default image | |
3052 | // size for properties that use image. | |
3053 | if ( !p ) | |
3054 | return wxSize(wxPG_CUSTOM_IMAGE_WIDTH,wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight)); | |
3055 | ||
3056 | wxSize cis = p->OnMeasureImage(item); | |
3057 | ||
939d9364 | 3058 | int choiceCount = p->m_choices.GetCount(); |
1c4293cb VZ |
3059 | int comVals = p->GetDisplayedCommonValueCount(); |
3060 | if ( item >= choiceCount && comVals > 0 ) | |
3061 | { | |
3062 | unsigned int cvi = item-choiceCount; | |
3063 | cis = GetCommonValue(cvi)->GetRenderer()->GetImageSize(NULL, 1, cvi); | |
3064 | } | |
3065 | else if ( item >= 0 && choiceCount == 0 ) | |
3066 | return wxSize(0, 0); | |
3067 | ||
3068 | if ( cis.x < 0 ) | |
3069 | { | |
3070 | if ( cis.x <= -1 ) | |
3071 | cis.x = wxPG_CUSTOM_IMAGE_WIDTH; | |
3072 | } | |
3073 | if ( cis.y <= 0 ) | |
3074 | { | |
3075 | if ( cis.y >= -1 ) | |
3076 | cis.y = wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight); | |
3077 | else | |
3078 | cis.y = -cis.y; | |
3079 | } | |
3080 | return cis; | |
3081 | } | |
3082 | ||
3083 | // ----------------------------------------------------------------------- | |
3084 | ||
3085 | // takes scrolling into account | |
3086 | void wxPropertyGrid::ImprovedClientToScreen( int* px, int* py ) | |
3087 | { | |
3088 | int vx, vy; | |
3089 | GetViewStart(&vx,&vy); | |
3090 | vy*=wxPG_PIXELS_PER_UNIT; | |
3091 | vx*=wxPG_PIXELS_PER_UNIT; | |
3092 | *px -= vx; | |
3093 | *py -= vy; | |
3094 | ClientToScreen( px, py ); | |
3095 | } | |
3096 | ||
3097 | // ----------------------------------------------------------------------- | |
3098 | ||
3099 | wxPropertyGridHitTestResult wxPropertyGrid::HitTest( const wxPoint& pt ) const | |
3100 | { | |
3101 | wxPoint pt2; | |
3102 | GetViewStart(&pt2.x,&pt2.y); | |
3103 | pt2.x *= wxPG_PIXELS_PER_UNIT; | |
3104 | pt2.y *= wxPG_PIXELS_PER_UNIT; | |
3105 | pt2.x += pt.x; | |
3106 | pt2.y += pt.y; | |
3107 | ||
3108 | return m_pState->HitTest(pt2); | |
3109 | } | |
3110 | ||
3111 | // ----------------------------------------------------------------------- | |
3112 | ||
3113 | // custom set cursor | |
3114 | void wxPropertyGrid::CustomSetCursor( int type, bool override ) | |
3115 | { | |
3116 | if ( type == m_curcursor && !override ) return; | |
3117 | ||
3118 | wxCursor* cursor = &wxPG_DEFAULT_CURSOR; | |
3119 | ||
3120 | if ( type == wxCURSOR_SIZEWE ) | |
3121 | cursor = m_cursorSizeWE; | |
3122 | ||
3123 | m_canvas->SetCursor( *cursor ); | |
3124 | ||
3125 | m_curcursor = type; | |
3126 | } | |
3127 | ||
3128 | // ----------------------------------------------------------------------- | |
b0996c3d | 3129 | // wxPropertyGrid property selection, editor creation |
1c4293cb VZ |
3130 | // ----------------------------------------------------------------------- |
3131 | ||
b0996c3d JS |
3132 | // |
3133 | // This class forwards events from property editor controls to wxPropertyGrid. | |
3134 | class wxPropertyGridEditorEventForwarder : public wxEvtHandler | |
3135 | { | |
3136 | public: | |
3137 | wxPropertyGridEditorEventForwarder( wxPropertyGrid* propGrid ) | |
3138 | : wxEvtHandler(), m_propGrid(propGrid) | |
3139 | { | |
3140 | } | |
3141 | ||
3142 | virtual ~wxPropertyGridEditorEventForwarder() | |
3143 | { | |
3144 | } | |
3145 | ||
3146 | private: | |
3147 | bool ProcessEvent( wxEvent& event ) | |
3148 | { | |
3149 | // Always skip | |
3150 | event.Skip(); | |
3151 | ||
3152 | m_propGrid->HandleCustomEditorEvent(event); | |
3153 | ||
3154 | return wxEvtHandler::ProcessEvent(event); | |
3155 | } | |
3156 | ||
3157 | wxPropertyGrid* m_propGrid; | |
3158 | }; | |
3159 | ||
1c4293cb | 3160 | // Setups event handling for child control |
28fb19ef | 3161 | void wxPropertyGrid::SetupChildEventHandling( wxWindow* argWnd ) |
1c4293cb | 3162 | { |
28fb19ef JS |
3163 | wxWindowID id = argWnd->GetId(); |
3164 | ||
1c4293cb VZ |
3165 | if ( argWnd == m_wndEditor ) |
3166 | { | |
6d24f9a9 JS |
3167 | argWnd->Connect(id, wxEVT_MOTION, |
3168 | wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild), | |
3169 | NULL, this); | |
3170 | argWnd->Connect(id, wxEVT_LEFT_UP, | |
3171 | wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild), | |
3172 | NULL, this); | |
3173 | argWnd->Connect(id, wxEVT_LEFT_DOWN, | |
3174 | wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild), | |
3175 | NULL, this); | |
3176 | argWnd->Connect(id, wxEVT_RIGHT_UP, | |
3177 | wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild), | |
3178 | NULL, this); | |
3179 | argWnd->Connect(id, wxEVT_ENTER_WINDOW, | |
3180 | wxMouseEventHandler(wxPropertyGrid::OnMouseEntry), | |
3181 | NULL, this); | |
3182 | argWnd->Connect(id, wxEVT_LEAVE_WINDOW, | |
3183 | wxMouseEventHandler(wxPropertyGrid::OnMouseEntry), | |
3184 | NULL, this); | |
1c4293cb | 3185 | } |
2cbd2892 | 3186 | |
b0996c3d JS |
3187 | wxPropertyGridEditorEventForwarder* forwarder; |
3188 | forwarder = new wxPropertyGridEditorEventForwarder(this); | |
3189 | argWnd->PushEventHandler(forwarder); | |
3190 | ||
2cbd2892 JS |
3191 | argWnd->Connect(id, wxEVT_KEY_DOWN, |
3192 | wxCharEventHandler(wxPropertyGrid::OnChildKeyDown), | |
3193 | NULL, this); | |
1c4293cb VZ |
3194 | } |
3195 | ||
3196 | void wxPropertyGrid::FreeEditors() | |
3197 | { | |
d35947a2 JS |
3198 | // |
3199 | // Return focus back to canvas from children (this is required at least for | |
3200 | // GTK+, which, unlike Windows, clears focus when control is destroyed | |
3201 | // instead of moving it to closest parent). | |
3202 | wxWindow* focus = wxWindow::FindFocus(); | |
3203 | if ( focus ) | |
3204 | { | |
3205 | wxWindow* parent = focus->GetParent(); | |
3206 | while ( parent ) | |
3207 | { | |
3208 | if ( parent == m_canvas ) | |
3209 | { | |
3210 | SetFocusOnCanvas(); | |
3211 | break; | |
3212 | } | |
3213 | parent = parent->GetParent(); | |
3214 | } | |
3215 | } | |
3216 | ||
1c4293cb | 3217 | // Do not free editors immediately if processing events |
1c4293cb VZ |
3218 | if ( m_wndEditor2 ) |
3219 | { | |
17ba2086 | 3220 | wxEvtHandler* handler = m_wndEditor2->PopEventHandler(false); |
1c4293cb | 3221 | m_wndEditor2->Hide(); |
17ba2086 | 3222 | wxPendingDelete.Append( handler ); |
fe6ee7ec | 3223 | wxPendingDelete.Append( m_wndEditor2 ); |
d3b9f782 | 3224 | m_wndEditor2 = NULL; |
1c4293cb VZ |
3225 | } |
3226 | ||
3227 | if ( m_wndEditor ) | |
3228 | { | |
17ba2086 | 3229 | wxEvtHandler* handler = m_wndEditor->PopEventHandler(false); |
1c4293cb | 3230 | m_wndEditor->Hide(); |
17ba2086 | 3231 | wxPendingDelete.Append( handler ); |
fe6ee7ec | 3232 | wxPendingDelete.Append( m_wndEditor ); |
d3b9f782 | 3233 | m_wndEditor = NULL; |
1c4293cb VZ |
3234 | } |
3235 | } | |
3236 | ||
3237 | // Call with NULL to de-select property | |
3238 | bool wxPropertyGrid::DoSelectProperty( wxPGProperty* p, unsigned int flags ) | |
3239 | { | |
3240 | /* | |
3241 | if (p) | |
3242 | wxLogDebug(wxT("SelectProperty( %s (%s[%i]) )"),p->m_label.c_str(), | |
3243 | p->m_parent->m_label.c_str(),p->GetIndexInParent()); | |
3244 | else | |
3245 | wxLogDebug(wxT("SelectProperty( NULL, -1 )")); | |
3246 | */ | |
3247 | ||
3248 | if ( m_inDoSelectProperty ) | |
3249 | return true; | |
3250 | ||
3251 | m_inDoSelectProperty = 1; | |
3252 | ||
3253 | wxPGProperty* prev = m_selected; | |
3254 | ||
1c4293cb VZ |
3255 | if ( !m_pState ) |
3256 | { | |
3257 | m_inDoSelectProperty = 0; | |
3258 | return false; | |
3259 | } | |
3260 | ||
a5d56762 RR |
3261 | /* |
3262 | if (m_selected) | |
3263 | wxPrintf( "Selected %s\n", m_selected->GetClassInfo()->GetClassName() ); | |
3264 | else | |
3265 | wxPrintf( "None selected\n" ); | |
23318a53 | 3266 | |
a5d56762 RR |
3267 | if (p) |
3268 | wxPrintf( "P = %s\n", p->GetClassInfo()->GetClassName() ); | |
3269 | else | |
3270 | wxPrintf( "P = NULL\n" ); | |
3271 | */ | |
23318a53 | 3272 | |
1c4293cb VZ |
3273 | // If we are frozen, then just set the values. |
3274 | if ( m_frozen ) | |
3275 | { | |
3276 | m_iFlags &= ~(wxPG_FL_ABNORMAL_EDITOR); | |
3277 | m_editorFocused = 0; | |
3278 | m_selected = p; | |
3279 | m_selColumn = 1; | |
3280 | m_pState->m_selected = p; | |
3281 | ||
3282 | // If frozen, always free controls. But don't worry, as Thaw will | |
3283 | // recall SelectProperty to recreate them. | |
3284 | FreeEditors(); | |
3285 | ||
3286 | // Prevent any further selection measures in this call | |
d3b9f782 | 3287 | p = NULL; |
1c4293cb VZ |
3288 | } |
3289 | else | |
3290 | { | |
3291 | // Is it the same? | |
3292 | if ( m_selected == p && !(flags & wxPG_SEL_FORCE) ) | |
3293 | { | |
3294 | // Only set focus if not deselecting | |
3295 | if ( p ) | |
3296 | { | |
3297 | if ( flags & wxPG_SEL_FOCUS ) | |
3298 | { | |
3299 | if ( m_wndEditor ) | |
3300 | { | |
3301 | m_wndEditor->SetFocus(); | |
3302 | m_editorFocused = 1; | |
3303 | } | |
3304 | } | |
3305 | else | |
3306 | { | |
c29e714c | 3307 | SetFocusOnCanvas(); |
1c4293cb VZ |
3308 | } |
3309 | } | |
3310 | ||
3311 | m_inDoSelectProperty = 0; | |
3312 | return true; | |
3313 | } | |
3314 | ||
3315 | // | |
3316 | // First, deactivate previous | |
3317 | if ( m_selected ) | |
3318 | { | |
3319 | ||
3320 | OnValidationFailureReset(m_selected); | |
3321 | ||
3322 | // Must double-check if this is an selected in case of forceswitch | |
3323 | if ( p != prev ) | |
3324 | { | |
3325 | if ( !CommitChangesFromEditor(flags) ) | |
3326 | { | |
3327 | // Validation has failed, so we can't exit the previous editor | |
3328 | //::wxMessageBox(_("Please correct the value or press ESC to cancel the edit."), | |
3329 | // _("Invalid Value"),wxOK|wxICON_ERROR); | |
3330 | m_inDoSelectProperty = 0; | |
3331 | return false; | |
3332 | } | |
3333 | } | |
3334 | ||
3335 | FreeEditors(); | |
3336 | m_selColumn = -1; | |
3337 | ||
d3b9f782 VZ |
3338 | m_selected = NULL; |
3339 | m_pState->m_selected = NULL; | |
1c4293cb VZ |
3340 | |
3341 | // We need to always fully refresh the grid here | |
3342 | Refresh(false); | |
3343 | ||
3344 | m_iFlags &= ~(wxPG_FL_ABNORMAL_EDITOR); | |
3345 | EditorsValueWasNotModified(); | |
3346 | } | |
3347 | ||
3348 | SetInternalFlag(wxPG_FL_IN_SELECT_PROPERTY); | |
3349 | ||
3350 | // | |
3351 | // Then, activate the one given. | |
3352 | if ( p ) | |
3353 | { | |
3354 | int propY = p->GetY2(m_lineHeight); | |
3355 | ||
3356 | int splitterX = GetSplitterPosition(); | |
3357 | m_editorFocused = 0; | |
3358 | m_selected = p; | |
3359 | m_pState->m_selected = p; | |
3360 | m_iFlags |= wxPG_FL_PRIMARY_FILLS_ENTIRE; | |
3361 | if ( p != prev ) | |
3362 | m_iFlags &= ~(wxPG_FL_VALIDATION_FAILED); | |
3363 | ||
d3b9f782 | 3364 | wxASSERT( m_wndEditor == NULL ); |
1c4293cb | 3365 | |
1c4293cb VZ |
3366 | // |
3367 | // Only create editor for non-disabled non-caption | |
3368 | if ( !p->IsCategory() && !(p->m_flags & wxPG_PROP_DISABLED) ) | |
3369 | { | |
3370 | // do this for non-caption items | |
3371 | ||
3372 | m_selColumn = 1; | |
3373 | ||
3374 | // Do we need to paint the custom image, if any? | |
3375 | m_iFlags &= ~(wxPG_FL_CUR_USES_CUSTOM_IMAGE); | |
3376 | if ( (p->m_flags & wxPG_PROP_CUSTOMIMAGE) && | |
3377 | !p->GetEditorClass()->CanContainCustomImage() | |
3378 | ) | |
3379 | m_iFlags |= wxPG_FL_CUR_USES_CUSTOM_IMAGE; | |
3380 | ||
3381 | wxRect grect = GetEditorWidgetRect(p, m_selColumn); | |
3382 | wxPoint goodPos = grect.GetPosition(); | |
3383 | #if wxPG_CREATE_CONTROLS_HIDDEN | |
3384 | int coord_adjust = m_height - goodPos.y; | |
3385 | goodPos.y += coord_adjust; | |
3386 | #endif | |
3387 | ||
3388 | const wxPGEditor* editor = p->GetEditorClass(); | |
3389 | wxCHECK_MSG(editor, false, | |
3390 | wxT("NULL editor class not allowed")); | |
3391 | ||
3392 | m_iFlags &= ~wxPG_FL_FIXED_WIDTH_EDITOR; | |
3393 | ||
3394 | wxPGWindowList wndList = editor->CreateControls(this, | |
3395 | p, | |
3396 | goodPos, | |
3397 | grect.GetSize()); | |
3398 | ||
3399 | m_wndEditor = wndList.m_primary; | |
3400 | m_wndEditor2 = wndList.m_secondary; | |
0fd5c401 | 3401 | wxWindow* primaryCtrl = GetEditorControl(); |
1c4293cb | 3402 | |
14c14060 JS |
3403 | // |
3404 | // Essentially, primaryCtrl == m_wndEditor | |
3405 | // | |
3406 | ||
1c4293cb VZ |
3407 | // NOTE: It is allowed for m_wndEditor to be NULL - in this case |
3408 | // value is drawn as normal, and m_wndEditor2 is assumed | |
0fd5c401 | 3409 | // to be a right-aligned button that triggers a separate editorCtrl |
1c4293cb VZ |
3410 | // window. |
3411 | ||
3412 | if ( m_wndEditor ) | |
3413 | { | |
b0f0eda8 | 3414 | wxASSERT_MSG( m_wndEditor->GetParent() == GetPanel(), |
1c4293cb VZ |
3415 | wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") ); |
3416 | ||
3417 | // Set validator, if any | |
3418 | #if wxUSE_VALIDATORS | |
704ceca8 JS |
3419 | wxValidator* validator = p->GetValidator(); |
3420 | if ( validator ) | |
0fd5c401 | 3421 | primaryCtrl->SetValidator(*validator); |
1c4293cb VZ |
3422 | #endif |
3423 | ||
3424 | if ( m_wndEditor->GetSize().y > (m_lineHeight+6) ) | |
3425 | m_iFlags |= wxPG_FL_ABNORMAL_EDITOR; | |
3426 | ||
3427 | // If it has modified status, use bold font | |
3428 | // (must be done before capturing m_ctrlXAdjust) | |
3429 | if ( (p->m_flags & wxPG_PROP_MODIFIED) && (m_windowStyle & wxPG_BOLD_MODIFIED) ) | |
3430 | SetCurControlBoldFont(); | |
3431 | ||
3432 | // | |
3433 | // Fix TextCtrl indentation | |
3434 | #if defined(__WXMSW__) && !defined(__WXWINCE__) | |
3435 | wxTextCtrl* tc = NULL; | |
0fd5c401 JS |
3436 | if ( primaryCtrl->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox)) ) |
3437 | tc = ((wxOwnerDrawnComboBox*)primaryCtrl)->GetTextCtrl(); | |
1c4293cb | 3438 | else |
0fd5c401 | 3439 | tc = wxDynamicCast(primaryCtrl, wxTextCtrl); |
1c4293cb VZ |
3440 | if ( tc ) |
3441 | ::SendMessage(GetHwndOf(tc), EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(0, 0)); | |
3442 | #endif | |
3443 | ||
3444 | // Store x relative to splitter (we'll need it). | |
3445 | m_ctrlXAdjust = m_wndEditor->GetPosition().x - splitterX; | |
3446 | ||
3447 | // Check if background clear is not necessary | |
3448 | wxPoint pos = m_wndEditor->GetPosition(); | |
3449 | if ( pos.x > (splitterX+1) || pos.y > propY ) | |
3450 | { | |
3451 | m_iFlags &= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE); | |
3452 | } | |
3453 | ||
3454 | m_wndEditor->SetSizeHints(3, 3); | |
3455 | ||
3456 | #if wxPG_CREATE_CONTROLS_HIDDEN | |
3457 | m_wndEditor->Show(false); | |
3458 | m_wndEditor->Freeze(); | |
3459 | ||
3460 | goodPos = m_wndEditor->GetPosition(); | |
3461 | goodPos.y -= coord_adjust; | |
3462 | m_wndEditor->Move( goodPos ); | |
3463 | #endif | |
3464 | ||
28fb19ef | 3465 | SetupChildEventHandling(primaryCtrl); |
1c4293cb VZ |
3466 | |
3467 | // Focus and select all (wxTextCtrl, wxComboBox etc) | |
3468 | if ( flags & wxPG_SEL_FOCUS ) | |
3469 | { | |
3470 | primaryCtrl->SetFocus(); | |
3471 | ||
3472 | p->GetEditorClass()->OnFocus(p, primaryCtrl); | |
3473 | } | |
3474 | } | |
3475 | ||
3476 | if ( m_wndEditor2 ) | |
3477 | { | |
b0f0eda8 | 3478 | wxASSERT_MSG( m_wndEditor2->GetParent() == GetPanel(), |
1c4293cb VZ |
3479 | wxT("CreateControls must use result of wxPropertyGrid::GetPanel() as parent of controls.") ); |
3480 | ||
3481 | // Get proper id for wndSecondary | |
3482 | m_wndSecId = m_wndEditor2->GetId(); | |
3483 | wxWindowList children = m_wndEditor2->GetChildren(); | |
3484 | wxWindowList::iterator node = children.begin(); | |
3485 | if ( node != children.end() ) | |
3486 | m_wndSecId = ((wxWindow*)*node)->GetId(); | |
3487 | ||
3488 | m_wndEditor2->SetSizeHints(3,3); | |
3489 | ||
3490 | #if wxPG_CREATE_CONTROLS_HIDDEN | |
3491 | wxRect sec_rect = m_wndEditor2->GetRect(); | |
3492 | sec_rect.y -= coord_adjust; | |
3493 | ||
3494 | // Fine tuning required to fix "oversized" | |
3495 | // button disappearance bug. | |
3496 | if ( sec_rect.y < 0 ) | |
3497 | { | |
3498 | sec_rect.height += sec_rect.y; | |
3499 | sec_rect.y = 0; | |
3500 | } | |
3501 | m_wndEditor2->SetSize( sec_rect ); | |
3502 | #endif | |
3503 | m_wndEditor2->Show(); | |
3504 | ||
28fb19ef | 3505 | SetupChildEventHandling(m_wndEditor2); |
1c4293cb VZ |
3506 | |
3507 | // If no primary editor, focus to button to allow | |
3508 | // it to interprete ENTER etc. | |
3509 | // NOTE: Due to problems focusing away from it, this | |
3510 | // has been disabled. | |
3511 | /* | |
3512 | if ( (flags & wxPG_SEL_FOCUS) && !m_wndEditor ) | |
3513 | m_wndEditor2->SetFocus(); | |
3514 | */ | |
3515 | } | |
3516 | ||
3517 | if ( flags & wxPG_SEL_FOCUS ) | |
3518 | m_editorFocused = 1; | |
3519 | ||
3520 | } | |
3521 | else | |
3522 | { | |
c29e714c JS |
3523 | // Make sure focus is in grid canvas (important for wxGTK, at least) |
3524 | SetFocusOnCanvas(); | |
1c4293cb VZ |
3525 | } |
3526 | ||
3527 | EditorsValueWasNotModified(); | |
3528 | ||
3529 | // If it's inside collapsed section, expand parent, scroll, etc. | |
3530 | // Also, if it was partially visible, scroll it into view. | |
3531 | if ( !(flags & wxPG_SEL_NONVISIBLE) ) | |
3532 | EnsureVisible( p ); | |
3533 | ||
3534 | if ( m_wndEditor ) | |
3535 | { | |
3536 | #if wxPG_CREATE_CONTROLS_HIDDEN | |
3537 | m_wndEditor->Thaw(); | |
3538 | #endif | |
3539 | m_wndEditor->Show(true); | |
3540 | } | |
3541 | ||
3542 | DrawItems(p, p); | |
3543 | } | |
e213da24 JS |
3544 | else |
3545 | { | |
c29e714c JS |
3546 | // Make sure focus is in grid canvas |
3547 | SetFocusOnCanvas(); | |
e213da24 | 3548 | } |
1c4293cb VZ |
3549 | |
3550 | ClearInternalFlag(wxPG_FL_IN_SELECT_PROPERTY); | |
3551 | } | |
3552 | ||
3553 | #if wxUSE_STATUSBAR | |
3554 | ||
3555 | // | |
3556 | // Show help text in status bar. | |
3557 | // (if found and grid not embedded in manager with help box and | |
3558 | // style wxPG_EX_HELP_AS_TOOLTIPS is not used). | |
3559 | // | |
3560 | ||
3561 | if ( !(GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS) ) | |
3562 | { | |
d3b9f782 | 3563 | wxStatusBar* statusbar = NULL; |
1c4293cb VZ |
3564 | if ( !(m_iFlags & wxPG_FL_NOSTATUSBARHELP) ) |
3565 | { | |
3566 | wxFrame* frame = wxDynamicCast(::wxGetTopLevelParent(this),wxFrame); | |
3567 | if ( frame ) | |
3568 | statusbar = frame->GetStatusBar(); | |
3569 | } | |
3570 | ||
3571 | if ( statusbar ) | |
3572 | { | |
3573 | const wxString* pHelpString = (const wxString*) NULL; | |
3574 | ||
3575 | if ( p ) | |
3576 | { | |
3577 | pHelpString = &p->GetHelpString(); | |
3578 | if ( pHelpString->length() ) | |
3579 | { | |
3580 | // Set help box text. | |
3581 | statusbar->SetStatusText( *pHelpString ); | |
3582 | m_iFlags |= wxPG_FL_STRING_IN_STATUSBAR; | |
3583 | } | |
3584 | } | |
3585 | ||
3586 | if ( (!pHelpString || !pHelpString->length()) && | |
3587 | (m_iFlags & wxPG_FL_STRING_IN_STATUSBAR) ) | |
3588 | { | |
3589 | // Clear help box - but only if it was written | |
3590 | // by us at previous time. | |
3591 | statusbar->SetStatusText( m_emptyString ); | |
3592 | m_iFlags &= ~(wxPG_FL_STRING_IN_STATUSBAR); | |
3593 | } | |
3594 | } | |
3595 | } | |
3596 | #endif | |
3597 | ||
3598 | m_inDoSelectProperty = 0; | |
3599 | ||
3600 | // call wx event handler (here so that it also occurs on deselection) | |
3601 | SendEvent( wxEVT_PG_SELECTED, m_selected, NULL, flags ); | |
3602 | ||
3603 | return true; | |
3604 | } | |
3605 | ||
3606 | // ----------------------------------------------------------------------- | |
3607 | ||
3608 | bool wxPropertyGrid::UnfocusEditor() | |
3609 | { | |
3610 | if ( !m_selected || !m_wndEditor || m_frozen ) | |
3611 | return true; | |
3612 | ||
3613 | if ( !CommitChangesFromEditor(0) ) | |
3614 | return false; | |
3615 | ||
c29e714c | 3616 | SetFocusOnCanvas(); |
1c4293cb VZ |
3617 | DrawItem(m_selected); |
3618 | ||
3619 | return true; | |
3620 | } | |
3621 | ||
3622 | // ----------------------------------------------------------------------- | |
3623 | ||
f521bae6 JS |
3624 | void wxPropertyGrid::RefreshEditor() |
3625 | { | |
a6353fe8 JS |
3626 | wxPGProperty* p = m_selected; |
3627 | if ( !p ) | |
3628 | return; | |
3629 | ||
3630 | wxWindow* wnd = GetEditorControl(); | |
3631 | if ( !wnd ) | |
f521bae6 | 3632 | return; |
a6353fe8 JS |
3633 | |
3634 | // Set editor font boldness - must do this before | |
3635 | // calling UpdateControl(). | |
3636 | if ( HasFlag(wxPG_BOLD_MODIFIED) ) | |
3637 | { | |
3638 | if ( p->HasFlag(wxPG_PROP_MODIFIED) ) | |
3639 | wnd->SetFont(GetCaptionFont()); | |
3640 | else | |
3641 | wnd->SetFont(GetFont()); | |
3642 | } | |
3643 | ||
daeb4e4d JS |
3644 | const wxPGEditor* editorClass = p->GetEditorClass(); |
3645 | ||
3646 | editorClass->UpdateControl(p, wnd); | |
3647 | ||
3648 | if ( p->IsValueUnspecified() ) | |
3649 | editorClass ->SetValueToUnspecified(p, wnd); | |
f521bae6 JS |
3650 | } |
3651 | ||
3652 | // ----------------------------------------------------------------------- | |
3653 | ||
1c4293cb VZ |
3654 | // This method is not inline because it called dozens of times |
3655 | // (i.e. two-arg function calls create smaller code size). | |
3656 | bool wxPropertyGrid::DoClearSelection() | |
3657 | { | |
d3b9f782 | 3658 | return DoSelectProperty(NULL); |
1c4293cb VZ |
3659 | } |
3660 | ||
3661 | // ----------------------------------------------------------------------- | |
3662 | // wxPropertyGrid expand/collapse state | |
3663 | // ----------------------------------------------------------------------- | |
3664 | ||
3665 | bool wxPropertyGrid::DoCollapse( wxPGProperty* p, bool sendEvents ) | |
3666 | { | |
3667 | wxPGProperty* pwc = wxStaticCast(p, wxPGProperty); | |
3668 | ||
3669 | // If active editor was inside collapsed section, then disable it | |
1621f192 | 3670 | if ( m_selected && m_selected->IsSomeParent(p) ) |
1c4293cb | 3671 | { |
1621f192 | 3672 | ClearSelection(false); |
1c4293cb VZ |
3673 | } |
3674 | ||
3675 | // Store dont-center-splitter flag 'cause we need to temporarily set it | |
3676 | wxUint32 old_flag = m_iFlags & wxPG_FL_DONT_CENTER_SPLITTER; | |
3677 | m_iFlags |= wxPG_FL_DONT_CENTER_SPLITTER; | |
3678 | ||
3679 | bool res = m_pState->DoCollapse(pwc); | |
3680 | ||
3681 | if ( res ) | |
3682 | { | |
3683 | if ( sendEvents ) | |
3684 | SendEvent( wxEVT_PG_ITEM_COLLAPSED, p ); | |
3685 | ||
3686 | RecalculateVirtualSize(); | |
3687 | ||
3688 | // Redraw etc. only if collapsed was visible. | |
3689 | if (pwc->IsVisible() && | |
3690 | !m_frozen && | |
3691 | ( !pwc->IsCategory() || !(m_windowStyle & wxPG_HIDE_CATEGORIES) ) ) | |
3692 | { | |
3693 | // When item is collapsed so that scrollbar would move, | |
3694 | // graphics mess is about (unless we redraw everything). | |
3695 | Refresh(); | |
3696 | } | |
3697 | } | |
3698 | ||
3699 | // Clear dont-center-splitter flag if it wasn't set | |
ac576038 | 3700 | m_iFlags = (m_iFlags & ~wxPG_FL_DONT_CENTER_SPLITTER) | old_flag; |
1c4293cb VZ |
3701 | |
3702 | return res; | |
3703 | } | |
3704 | ||
3705 | // ----------------------------------------------------------------------- | |
3706 | ||
3707 | bool wxPropertyGrid::DoExpand( wxPGProperty* p, bool sendEvents ) | |
3708 | { | |
3709 | wxCHECK_MSG( p, false, wxT("invalid property id") ); | |
3710 | ||
3711 | wxPGProperty* pwc = (wxPGProperty*)p; | |
3712 | ||
3713 | // Store dont-center-splitter flag 'cause we need to temporarily set it | |
3714 | wxUint32 old_flag = m_iFlags & wxPG_FL_DONT_CENTER_SPLITTER; | |
3715 | m_iFlags |= wxPG_FL_DONT_CENTER_SPLITTER; | |
3716 | ||
3717 | bool res = m_pState->DoExpand(pwc); | |
3718 | ||
3719 | if ( res ) | |
3720 | { | |
3721 | if ( sendEvents ) | |
3722 | SendEvent( wxEVT_PG_ITEM_EXPANDED, p ); | |
3723 | ||
3724 | RecalculateVirtualSize(); | |
3725 | ||
3726 | // Redraw etc. only if expanded was visible. | |
3727 | if ( pwc->IsVisible() && !m_frozen && | |
3728 | ( !pwc->IsCategory() || !(m_windowStyle & wxPG_HIDE_CATEGORIES) ) | |
3729 | ) | |
3730 | { | |
3731 | // Redraw | |
3732 | #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT | |
3733 | Refresh(); | |
3734 | #else | |
3735 | DrawItems(pwc, NULL); | |
3736 | #endif | |
3737 | } | |
3738 | } | |
3739 | ||
3740 | // Clear dont-center-splitter flag if it wasn't set | |
b7bc9d80 | 3741 | m_iFlags = (m_iFlags & ~wxPG_FL_DONT_CENTER_SPLITTER) | old_flag; |
1c4293cb VZ |
3742 | |
3743 | return res; | |
3744 | } | |
3745 | ||
3746 | // ----------------------------------------------------------------------- | |
3747 | ||
3748 | bool wxPropertyGrid::DoHideProperty( wxPGProperty* p, bool hide, int flags ) | |
3749 | { | |
3750 | if ( m_frozen ) | |
3751 | return m_pState->DoHideProperty(p, hide, flags); | |
3752 | ||
3753 | if ( m_selected && | |
3754 | ( m_selected == p || m_selected->IsSomeParent(p) ) | |
3755 | ) | |
3756 | { | |
1621f192 | 3757 | ClearSelection(false); |
1c4293cb VZ |
3758 | } |
3759 | ||
3760 | m_pState->DoHideProperty(p, hide, flags); | |
3761 | ||
3762 | RecalculateVirtualSize(); | |
3763 | Refresh(); | |
3764 | ||
3765 | return true; | |
3766 | } | |
3767 | ||
3768 | ||
3769 | // ----------------------------------------------------------------------- | |
3770 | // wxPropertyGrid size related methods | |
3771 | // ----------------------------------------------------------------------- | |
3772 | ||
3773 | void wxPropertyGrid::RecalculateVirtualSize( int forceXPos ) | |
3774 | { | |
3775 | if ( (m_iFlags & wxPG_FL_RECALCULATING_VIRTUAL_SIZE) || m_frozen ) | |
3776 | return; | |
3777 | ||
3778 | // | |
3779 | // If virtual height was changed, then recalculate editor control position(s) | |
3780 | if ( m_pState->m_vhCalcPending ) | |
3781 | CorrectEditorWidgetPosY(); | |
3782 | ||
3783 | m_pState->EnsureVirtualHeight(); | |
3784 | ||
4b6a582b VZ |
3785 | wxASSERT_LEVEL_2_MSG( |
3786 | m_pState->GetVirtualHeight() == m_pState->GetActualVirtualHeight(), | |
3787 | "VirtualHeight and ActualVirtualHeight should match" | |
3788 | ); | |
1c4293cb VZ |
3789 | |
3790 | m_iFlags |= wxPG_FL_RECALCULATING_VIRTUAL_SIZE; | |
3791 | ||
3792 | int x = m_pState->m_width; | |
3793 | int y = m_pState->m_virtualHeight; | |
3794 | ||
3795 | int width, height; | |
3796 | GetClientSize(&width,&height); | |
3797 | ||
3798 | // Now adjust virtual size. | |
657a8a35 | 3799 | SetVirtualSize(x, y); |
1c4293cb VZ |
3800 | |
3801 | int xAmount = 0; | |
3802 | int xPos = 0; | |
3803 | ||
3804 | // | |
3805 | // Adjust scrollbars | |
3806 | if ( HasVirtualWidth() ) | |
3807 | { | |
3808 | xAmount = x/wxPG_PIXELS_PER_UNIT; | |
3809 | xPos = GetScrollPos( wxHORIZONTAL ); | |
3810 | } | |
3811 | ||
3812 | if ( forceXPos != -1 ) | |
3813 | xPos = forceXPos; | |
3814 | // xPos too high? | |
3815 | else if ( xPos > (xAmount-(width/wxPG_PIXELS_PER_UNIT)) ) | |
3816 | xPos = 0; | |
3817 | ||
bb2e05cf | 3818 | int yAmount = y / wxPG_PIXELS_PER_UNIT; |
1c4293cb VZ |
3819 | int yPos = GetScrollPos( wxVERTICAL ); |
3820 | ||
3821 | SetScrollbars( wxPG_PIXELS_PER_UNIT, wxPG_PIXELS_PER_UNIT, | |
3822 | xAmount, yAmount, xPos, yPos, true ); | |
3823 | ||
3824 | // Must re-get size now | |
3825 | GetClientSize(&width,&height); | |
3826 | ||
3827 | if ( !HasVirtualWidth() ) | |
3828 | { | |
3829 | m_pState->SetVirtualWidth(width); | |
3830 | x = width; | |
3831 | } | |
3832 | ||
3833 | m_width = width; | |
3834 | m_height = height; | |
3835 | ||
3836 | m_canvas->SetSize( x, y ); | |
3837 | ||
3838 | m_pState->CheckColumnWidths(); | |
3839 | ||
3840 | if ( m_selected ) | |
3841 | CorrectEditorWidgetSizeX(); | |
3842 | ||
3843 | m_iFlags &= ~wxPG_FL_RECALCULATING_VIRTUAL_SIZE; | |
3844 | } | |
3845 | ||
3846 | // ----------------------------------------------------------------------- | |
3847 | ||
3848 | void wxPropertyGrid::OnResize( wxSizeEvent& event ) | |
3849 | { | |
3850 | if ( !(m_iFlags & wxPG_FL_INITIALIZED) ) | |
3851 | return; | |
3852 | ||
3853 | int width, height; | |
3854 | GetClientSize(&width,&height); | |
3855 | ||
3856 | m_width = width; | |
3857 | m_height = height; | |
3858 | ||
1c4293cb VZ |
3859 | #if wxPG_DOUBLE_BUFFER |
3860 | if ( !(GetExtraStyle() & wxPG_EX_NATIVE_DOUBLE_BUFFERING) ) | |
3861 | { | |
3862 | int dblh = (m_lineHeight*2); | |
3863 | if ( !m_doubleBuffer ) | |
3864 | { | |
3865 | // Create double buffer bitmap to draw on, if none | |
3866 | int w = (width>250)?width:250; | |
3867 | int h = height + dblh; | |
3868 | h = (h>400)?h:400; | |
3869 | m_doubleBuffer = new wxBitmap( w, h ); | |
3870 | } | |
3871 | else | |
3872 | { | |
3873 | int w = m_doubleBuffer->GetWidth(); | |
3874 | int h = m_doubleBuffer->GetHeight(); | |
3875 | ||
3876 | // Double buffer must be large enough | |
3877 | if ( w < width || h < (height+dblh) ) | |
3878 | { | |
3879 | if ( w < width ) w = width; | |
3880 | if ( h < (height+dblh) ) h = height + dblh; | |
3881 | delete m_doubleBuffer; | |
3882 | m_doubleBuffer = new wxBitmap( w, h ); | |
3883 | } | |
3884 | } | |
3885 | } | |
3886 | ||
3887 | #endif | |
3888 | ||
3889 | m_pState->OnClientWidthChange( width, event.GetSize().x - m_ncWidth, true ); | |
3890 | m_ncWidth = event.GetSize().x; | |
3891 | ||
3892 | if ( !m_frozen ) | |
3893 | { | |
3894 | if ( m_pState->m_itemsAdded ) | |
3895 | PrepareAfterItemsAdded(); | |
3896 | else | |
3897 | // Without this, virtual size (atleast under wxGTK) will be skewed | |
3898 | RecalculateVirtualSize(); | |
3899 | ||
3900 | Refresh(); | |
3901 | } | |
3902 | } | |
3903 | ||
3904 | // ----------------------------------------------------------------------- | |
3905 | ||
3906 | void wxPropertyGrid::SetVirtualWidth( int width ) | |
3907 | { | |
3908 | if ( width == -1 ) | |
3909 | { | |
3910 | // Disable virtual width | |
3911 | width = GetClientSize().x; | |
3912 | ClearInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH); | |
3913 | } | |
3914 | else | |
3915 | { | |
3916 | // Enable virtual width | |
3917 | SetInternalFlag(wxPG_FL_HAS_VIRTUAL_WIDTH); | |
3918 | } | |
3919 | m_pState->SetVirtualWidth( width ); | |
3920 | } | |
3921 | ||
0ca422ef RR |
3922 | void wxPropertyGrid::SetFocusOnCanvas() |
3923 | { | |
3924 | m_canvas->SetFocusIgnoringChildren(); | |
3925 | m_editorFocused = 0; | |
3926 | } | |
3927 | ||
1c4293cb VZ |
3928 | // ----------------------------------------------------------------------- |
3929 | // wxPropertyGrid mouse event handling | |
3930 | // ----------------------------------------------------------------------- | |
3931 | ||
3932 | // selFlags uses same values DoSelectProperty's flags | |
3933 | // Returns true if event was vetoed. | |
3934 | bool wxPropertyGrid::SendEvent( int eventType, wxPGProperty* p, wxVariant* pValue, unsigned int WXUNUSED(selFlags) ) | |
3935 | { | |
3936 | // Send property grid event of specific type and with specific property | |
3937 | wxPropertyGridEvent evt( eventType, m_eventObject->GetId() ); | |
3938 | evt.SetPropertyGrid(this); | |
3939 | evt.SetEventObject(m_eventObject); | |
3940 | evt.SetProperty(p); | |
3941 | if ( pValue ) | |
3942 | { | |
3943 | evt.SetCanVeto(true); | |
3944 | evt.SetupValidationInfo(); | |
3945 | m_validationInfo.m_pValue = pValue; | |
3946 | } | |
3947 | wxEvtHandler* evtHandler = m_eventObject->GetEventHandler(); | |
3948 | ||
3949 | evtHandler->ProcessEvent(evt); | |
3950 | ||
3951 | return evt.WasVetoed(); | |
3952 | } | |
3953 | ||
3954 | // ----------------------------------------------------------------------- | |
3955 | ||
3956 | // Return false if should be skipped | |
3957 | bool wxPropertyGrid::HandleMouseClick( int x, unsigned int y, wxMouseEvent &event ) | |
3958 | { | |
3959 | bool res = true; | |
3960 | ||
3961 | // Need to set focus? | |
3962 | if ( !(m_iFlags & wxPG_FL_FOCUSED) ) | |
3963 | { | |
c29e714c | 3964 | SetFocusOnCanvas(); |
1c4293cb VZ |
3965 | } |
3966 | ||
3967 | wxPropertyGridPageState* state = m_pState; | |
3968 | int splitterHit; | |
3969 | int splitterHitOffset; | |
3970 | int columnHit = state->HitTestH( x, &splitterHit, &splitterHitOffset ); | |
3971 | ||
3972 | wxPGProperty* p = DoGetItemAtY(y); | |
3973 | ||
3974 | if ( p ) | |
3975 | { | |
3976 | int depth = (int)p->GetDepth() - 1; | |
3977 | ||
3978 | int marginEnds = m_marginWidth + ( depth * m_subgroup_extramargin ); | |
3979 | ||
3980 | if ( x >= marginEnds ) | |
3981 | { | |
3982 | // Outside margin. | |
3983 | ||
3984 | if ( p->IsCategory() ) | |
3985 | { | |
3986 | // This is category. | |
3987 | wxPropertyCategory* pwc = (wxPropertyCategory*)p; | |
3988 | ||
3989 | int textX = m_marginWidth + ((unsigned int)((pwc->m_depth-1)*m_subgroup_extramargin)); | |
3990 | ||
3991 | // Expand, collapse, activate etc. if click on text or left of splitter. | |
3992 | if ( x >= textX | |
3993 | && | |
3994 | ( x < (textX+pwc->GetTextExtent(this, m_captionFont)+(wxPG_CAPRECTXMARGIN*2)) || | |
3995 | columnHit == 0 | |
3996 | ) | |
3997 | ) | |
3998 | { | |
3999 | if ( !DoSelectProperty( p ) ) | |
4000 | return res; | |
4001 | ||
4002 | // On double-click, expand/collapse. | |
4003 | if ( event.ButtonDClick() && !(m_windowStyle & wxPG_HIDE_MARGIN) ) | |
4004 | { | |
4005 | if ( pwc->IsExpanded() ) DoCollapse( p, true ); | |
4006 | else DoExpand( p, true ); | |
4007 | } | |
4008 | } | |
4009 | } | |
4010 | else if ( splitterHit == -1 ) | |
4011 | { | |
4012 | // Click on value. | |
4013 | unsigned int selFlag = 0; | |
4014 | if ( columnHit == 1 ) | |
4015 | { | |
4016 | m_iFlags |= wxPG_FL_ACTIVATION_BY_CLICK; | |
4017 | selFlag = wxPG_SEL_FOCUS; | |
4018 | } | |
4019 | if ( !DoSelectProperty( p, selFlag ) ) | |
4020 | return res; | |
4021 | ||
4022 | m_iFlags &= ~(wxPG_FL_ACTIVATION_BY_CLICK); | |
4023 | ||
4024 | if ( p->GetChildCount() && !p->IsCategory() ) | |
4025 | // On double-click, expand/collapse. | |
4026 | if ( event.ButtonDClick() && !(m_windowStyle & wxPG_HIDE_MARGIN) ) | |
4027 | { | |
4028 | wxPGProperty* pwc = (wxPGProperty*)p; | |
4029 | if ( pwc->IsExpanded() ) DoCollapse( p, true ); | |
4030 | else DoExpand( p, true ); | |
4031 | } | |
4032 | ||
4033 | res = false; | |
4034 | } | |
4035 | else | |
4036 | { | |
4037 | // click on splitter | |
4038 | if ( !(m_windowStyle & wxPG_STATIC_SPLITTER) ) | |
4039 | { | |
4040 | if ( event.GetEventType() == wxEVT_LEFT_DCLICK ) | |
4041 | { | |
4042 | // Double-clicking the splitter causes auto-centering | |
4043 | CenterSplitter( true ); | |
4044 | } | |
4045 | else if ( m_dragStatus == 0 ) | |
4046 | { | |
4047 | // | |
4048 | // Begin draggin the splitter | |
4049 | // | |
4050 | if ( m_wndEditor ) | |
4051 | { | |
4052 | // Changes must be committed here or the | |
4053 | // value won't be drawn correctly | |
4054 | if ( !CommitChangesFromEditor() ) | |
4055 | return res; | |
4056 | ||
4057 | m_wndEditor->Show ( false ); | |
4058 | } | |
4059 | ||
4060 | if ( !(m_iFlags & wxPG_FL_MOUSE_CAPTURED) ) | |
4061 | { | |
4062 | m_canvas->CaptureMouse(); | |
4063 | m_iFlags |= wxPG_FL_MOUSE_CAPTURED; | |
4064 | } | |
4065 | ||
4066 | m_dragStatus = 1; | |
4067 | m_draggedSplitter = splitterHit; | |
4068 | m_dragOffset = splitterHitOffset; | |
4069 | ||
4070 | wxClientDC dc(m_canvas); | |
4071 | ||
4072 | #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT | |
4073 | // Fixes button disappearance bug | |
4074 | if ( m_wndEditor2 ) | |
4075 | m_wndEditor2->Show ( false ); | |
4076 | #endif | |
4077 | ||
4078 | m_startingSplitterX = x - splitterHitOffset; | |
4079 | } | |
4080 | } | |
4081 | } | |
4082 | } | |
4083 | else | |
4084 | { | |
4085 | // Click on margin. | |
4086 | if ( p->GetChildCount() ) | |
4087 | { | |
4088 | int nx = x + m_marginWidth - marginEnds; // Normalize x. | |
4089 | ||
4090 | if ( (nx >= m_gutterWidth && nx < (m_gutterWidth+m_iconWidth)) ) | |
4091 | { | |
4092 | int y2 = y % m_lineHeight; | |
4093 | if ( (y2 >= m_buttonSpacingY && y2 < (m_buttonSpacingY+m_iconHeight)) ) | |
4094 | { | |
4095 | // On click on expander button, expand/collapse | |
4096 | if ( ((wxPGProperty*)p)->IsExpanded() ) | |
4097 | DoCollapse( p, true ); | |
4098 | else | |
4099 | DoExpand( p, true ); | |
4100 | } | |
4101 | } | |
4102 | } | |
4103 | } | |
4104 | } | |
4105 | return res; | |
4106 | } | |
4107 | ||
4108 | // ----------------------------------------------------------------------- | |
4109 | ||
4110 | bool wxPropertyGrid::HandleMouseRightClick( int WXUNUSED(x), unsigned int WXUNUSED(y), | |
4111 | wxMouseEvent& WXUNUSED(event) ) | |
4112 | { | |
4113 | if ( m_propHover ) | |
4114 | { | |
4115 | // Select property here as well | |
4116 | wxPGProperty* p = m_propHover; | |
4117 | if ( p != m_selected ) | |
4118 | DoSelectProperty( p ); | |
4119 | ||
4120 | // Send right click event. | |
4121 | SendEvent( wxEVT_PG_RIGHT_CLICK, p ); | |
4122 | ||
4123 | return true; | |
4124 | } | |
4125 | return false; | |
4126 | } | |
4127 | ||
4128 | // ----------------------------------------------------------------------- | |
4129 | ||
4130 | bool wxPropertyGrid::HandleMouseDoubleClick( int WXUNUSED(x), unsigned int WXUNUSED(y), | |
4131 | wxMouseEvent& WXUNUSED(event) ) | |
4132 | { | |
4133 | if ( m_propHover ) | |
4134 | { | |
4135 | // Select property here as well | |
4136 | wxPGProperty* p = m_propHover; | |
4137 | ||
4138 | if ( p != m_selected ) | |
4139 | DoSelectProperty( p ); | |
4140 | ||
4141 | // Send double-click event. | |
4142 | SendEvent( wxEVT_PG_DOUBLE_CLICK, m_propHover ); | |
4143 | ||
4144 | return true; | |
4145 | } | |
4146 | return false; | |
4147 | } | |
4148 | ||
4149 | // ----------------------------------------------------------------------- | |
4150 | ||
4151 | #if wxPG_SUPPORT_TOOLTIPS | |
4152 | ||
4153 | void wxPropertyGrid::SetToolTip( const wxString& tipString ) | |
4154 | { | |
4155 | if ( tipString.length() ) | |
4156 | { | |
4157 | m_canvas->SetToolTip(tipString); | |
4158 | } | |
4159 | else | |
4160 | { | |
4161 | #if wxPG_ALLOW_EMPTY_TOOLTIPS | |
4162 | m_canvas->SetToolTip( m_emptyString ); | |
4163 | #else | |
4164 | m_canvas->SetToolTip( NULL ); | |
4165 | #endif | |
4166 | } | |
4167 | } | |
4168 | ||
4169 | #endif // #if wxPG_SUPPORT_TOOLTIPS | |
4170 | ||
4171 | // ----------------------------------------------------------------------- | |
4172 | ||
4173 | // Return false if should be skipped | |
4174 | bool wxPropertyGrid::HandleMouseMove( int x, unsigned int y, wxMouseEvent &event ) | |
4175 | { | |
4176 | // Safety check (needed because mouse capturing may | |
4177 | // otherwise freeze the control) | |
4178 | if ( m_dragStatus > 0 && !event.Dragging() ) | |
4179 | { | |
4180 | HandleMouseUp(x,y,event); | |
4181 | } | |
4182 | ||
4183 | wxPropertyGridPageState* state = m_pState; | |
4184 | int splitterHit; | |
4185 | int splitterHitOffset; | |
4186 | int columnHit = state->HitTestH( x, &splitterHit, &splitterHitOffset ); | |
4187 | int splitterX = x - splitterHitOffset; | |
4188 | ||
4189 | if ( m_dragStatus > 0 ) | |
4190 | { | |
4191 | if ( x > (m_marginWidth + wxPG_DRAG_MARGIN) && | |
4192 | x < (m_pState->m_width - wxPG_DRAG_MARGIN) ) | |
4193 | { | |
4194 | ||
4195 | int newSplitterX = x - m_dragOffset; | |
4196 | int splitterX = x - splitterHitOffset; | |
4197 | ||
4198 | // Splitter redraw required? | |
4199 | if ( newSplitterX != splitterX ) | |
4200 | { | |
4201 | // Move everything | |
4202 | SetInternalFlag(wxPG_FL_DONT_CENTER_SPLITTER); | |
4203 | state->DoSetSplitterPosition( newSplitterX, m_draggedSplitter, false ); | |
4204 | state->m_fSplitterX = (float) newSplitterX; | |
4205 | ||
4206 | if ( m_selected ) | |
4207 | CorrectEditorWidgetSizeX(); | |
4208 | ||
4209 | Update(); | |
4210 | Refresh(); | |
4211 | } | |
4212 | ||
4213 | m_dragStatus = 2; | |
4214 | } | |
4215 | ||
4216 | return false; | |
4217 | } | |
4218 | else | |
4219 | { | |
4220 | ||
4221 | int ih = m_lineHeight; | |
4222 | int sy = y; | |
4223 | ||
4224 | #if wxPG_SUPPORT_TOOLTIPS | |
4225 | wxPGProperty* prevHover = m_propHover; | |
4226 | unsigned char prevSide = m_mouseSide; | |
4227 | #endif | |
4228 | int curPropHoverY = y - (y % ih); | |
4229 | ||
4230 | // On which item it hovers | |
b7bc9d80 | 4231 | if ( !m_propHover |
1c4293cb | 4232 | || |
b7bc9d80 | 4233 | ( sy < m_propHoverY || sy >= (m_propHoverY+ih) ) |
1c4293cb VZ |
4234 | ) |
4235 | { | |
4236 | // Mouse moves on another property | |
4237 | ||
4238 | m_propHover = DoGetItemAtY(y); | |
4239 | m_propHoverY = curPropHoverY; | |
4240 | ||
4241 | // Send hover event | |
4242 | SendEvent( wxEVT_PG_HIGHLIGHTED, m_propHover ); | |
4243 | } | |
4244 | ||
4245 | #if wxPG_SUPPORT_TOOLTIPS | |
4246 | // Store which side we are on | |
4247 | m_mouseSide = 0; | |
4248 | if ( columnHit == 1 ) | |
4249 | m_mouseSide = 2; | |
4250 | else if ( columnHit == 0 ) | |
4251 | m_mouseSide = 1; | |
4252 | ||
4253 | // | |
4254 | // If tooltips are enabled, show label or value as a tip | |
4255 | // in case it doesn't otherwise show in full length. | |
4256 | // | |
4257 | if ( m_windowStyle & wxPG_TOOLTIPS ) | |
4258 | { | |
4259 | wxToolTip* tooltip = m_canvas->GetToolTip(); | |
4260 | ||
4261 | if ( m_propHover != prevHover || prevSide != m_mouseSide ) | |
4262 | { | |
4263 | if ( m_propHover && !m_propHover->IsCategory() ) | |
4264 | { | |
4265 | ||
4266 | if ( GetExtraStyle() & wxPG_EX_HELP_AS_TOOLTIPS ) | |
4267 | { | |
4268 | // Show help string as a tooltip | |
4269 | wxString tipString = m_propHover->GetHelpString(); | |
4270 | ||
4271 | SetToolTip(tipString); | |
4272 | } | |
4273 | else | |
4274 | { | |
4275 | // Show cropped value string as a tooltip | |
4276 | wxString tipString; | |
4277 | int space = 0; | |
4278 | ||
4279 | if ( m_mouseSide == 1 ) | |
4280 | { | |
4281 | tipString = m_propHover->m_label; | |
4282 | space = splitterX-m_marginWidth-3; | |
4283 | } | |
4284 | else if ( m_mouseSide == 2 ) | |
4285 | { | |
4286 | tipString = m_propHover->GetDisplayedString(); | |
4287 | ||
4288 | space = m_width - splitterX; | |
4289 | if ( m_propHover->m_flags & wxPG_PROP_CUSTOMIMAGE ) | |
4290 | space -= wxPG_CUSTOM_IMAGE_WIDTH + wxCC_CUSTOM_IMAGE_MARGIN1 + wxCC_CUSTOM_IMAGE_MARGIN2; | |
4291 | } | |
4292 | ||
4293 | if ( space ) | |
4294 | { | |
4295 | int tw, th; | |
657a8a35 | 4296 | GetTextExtent( tipString, &tw, &th, 0, 0 ); |
1c4293cb VZ |
4297 | if ( tw > space ) |
4298 | { | |
4299 | SetToolTip( tipString ); | |
4300 | } | |
4301 | } | |
4302 | else | |
4303 | { | |
4304 | if ( tooltip ) | |
4305 | { | |
4306 | #if wxPG_ALLOW_EMPTY_TOOLTIPS | |
4307 | m_canvas->SetToolTip( m_emptyString ); | |
4308 | #else | |
4309 | m_canvas->SetToolTip( NULL ); | |
4310 | #endif | |
4311 | } | |
4312 | } | |
4313 | ||
4314 | } | |
4315 | } | |
4316 | else | |
4317 | { | |
4318 | if ( tooltip ) | |
4319 | { | |
4320 | #if wxPG_ALLOW_EMPTY_TOOLTIPS | |
4321 | m_canvas->SetToolTip( m_emptyString ); | |
4322 | #else | |
4323 | m_canvas->SetToolTip( NULL ); | |
4324 | #endif | |
4325 | } | |
4326 | } | |
4327 | } | |
4328 | } | |
4329 | #endif | |
4330 | ||
4331 | if ( splitterHit == -1 || | |
4332 | !m_propHover || | |
4333 | HasFlag(wxPG_STATIC_SPLITTER) ) | |
4334 | { | |
4335 | // hovering on something else | |
4336 | if ( m_curcursor != wxCURSOR_ARROW ) | |
4337 | CustomSetCursor( wxCURSOR_ARROW ); | |
4338 | } | |
4339 | else | |
4340 | { | |
4341 | // Do not allow splitter cursor on caption items. | |
4342 | // (also not if we were dragging and its started | |
4343 | // outside the splitter region) | |
4344 | ||
b7bc9d80 | 4345 | if ( !m_propHover->IsCategory() && |
1c4293cb VZ |
4346 | !event.Dragging() ) |
4347 | { | |
4348 | ||
4349 | // hovering on splitter | |
4350 | ||
4351 | // NB: Condition disabled since MouseLeave event (from the editor control) cannot be | |
4352 | // reliably detected. | |
4353 | //if ( m_curcursor != wxCURSOR_SIZEWE ) | |
4354 | CustomSetCursor( wxCURSOR_SIZEWE, true ); | |
4355 | ||
4356 | return false; | |
4357 | } | |
4358 | else | |
4359 | { | |
4360 | // hovering on something else | |
4361 | if ( m_curcursor != wxCURSOR_ARROW ) | |
4362 | CustomSetCursor( wxCURSOR_ARROW ); | |
4363 | } | |
4364 | } | |
4365 | } | |
4366 | return true; | |
4367 | } | |
4368 | ||
4369 | // ----------------------------------------------------------------------- | |
4370 | ||
4371 | // Also handles Leaving event | |
4372 | bool wxPropertyGrid::HandleMouseUp( int x, unsigned int WXUNUSED(y), | |
4373 | wxMouseEvent &WXUNUSED(event) ) | |
4374 | { | |
4375 | wxPropertyGridPageState* state = m_pState; | |
4376 | bool res = false; | |
4377 | ||
4378 | int splitterHit; | |
4379 | int splitterHitOffset; | |
4380 | state->HitTestH( x, &splitterHit, &splitterHitOffset ); | |
4381 | ||
4382 | // No event type check - basicly calling this method should | |
4383 | // just stop dragging. | |
4384 | // Left up after dragged? | |
4385 | if ( m_dragStatus >= 1 ) | |
4386 | { | |
4387 | // | |
4388 | // End Splitter Dragging | |
4389 | // | |
4390 | // DO NOT ENABLE FOLLOWING LINE! | |
4391 | // (it is only here as a reminder to not to do it) | |
4392 | //splitterX = x; | |
4393 | ||
4394 | // Disable splitter auto-centering | |
4395 | m_iFlags |= wxPG_FL_DONT_CENTER_SPLITTER; | |
4396 | ||
4397 | // This is necessary to return cursor | |
4398 | if ( m_iFlags & wxPG_FL_MOUSE_CAPTURED ) | |
4399 | { | |
4400 | m_canvas->ReleaseMouse(); | |
4401 | m_iFlags &= ~(wxPG_FL_MOUSE_CAPTURED); | |
4402 | } | |
4403 | ||
4404 | // Set back the default cursor, if necessary | |
4405 | if ( splitterHit == -1 || | |
4406 | !m_propHover ) | |
4407 | { | |
4408 | CustomSetCursor( wxCURSOR_ARROW ); | |
4409 | } | |
4410 | ||
4411 | m_dragStatus = 0; | |
4412 | ||
4413 | // Control background needs to be cleared | |
4414 | if ( !(m_iFlags & wxPG_FL_PRIMARY_FILLS_ENTIRE) && m_selected ) | |
4415 | DrawItem( m_selected ); | |
4416 | ||
4417 | if ( m_wndEditor ) | |
4418 | { | |
4419 | m_wndEditor->Show ( true ); | |
4420 | } | |
4421 | ||
4422 | #if wxPG_REFRESH_CONTROLS_AFTER_REPAINT | |
4423 | // Fixes button disappearance bug | |
4424 | if ( m_wndEditor2 ) | |
4425 | m_wndEditor2->Show ( true ); | |
4426 | #endif | |
4427 | ||
4428 | // This clears the focus. | |
4429 | m_editorFocused = 0; | |
4430 | ||
4431 | } | |
4432 | return res; | |
4433 | } | |
4434 | ||
4435 | // ----------------------------------------------------------------------- | |
4436 | ||
4437 | bool wxPropertyGrid::OnMouseCommon( wxMouseEvent& event, int* px, int* py ) | |
4438 | { | |
4439 | int splitterX = GetSplitterPosition(); | |
4440 | ||
4441 | //int ux, uy; | |
4442 | //CalcUnscrolledPosition( event.m_x, event.m_y, &ux, &uy ); | |
4443 | int ux = event.m_x; | |
4444 | int uy = event.m_y; | |
4445 | ||
0fd5c401 | 4446 | wxWindow* wnd = GetEditorControl(); |
1c4293cb VZ |
4447 | |
4448 | // Hide popup on clicks | |
4449 | if ( event.GetEventType() != wxEVT_MOTION ) | |
4450 | if ( wnd && wnd->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox)) ) | |
4451 | { | |
0fd5c401 | 4452 | ((wxOwnerDrawnComboBox*)wnd)->HidePopup(); |
1c4293cb VZ |
4453 | } |
4454 | ||
4455 | wxRect r; | |
4456 | if ( wnd ) | |
4457 | r = wnd->GetRect(); | |
d3b9f782 | 4458 | if ( wnd == NULL || m_dragStatus || |
1c4293cb VZ |
4459 | ( |
4460 | ux <= (splitterX + wxPG_SPLITTERX_DETECTMARGIN2) || | |
4461 | ux >= (r.x+r.width) || | |
4462 | event.m_y < r.y || | |
4463 | event.m_y >= (r.y+r.height) | |
4464 | ) | |
4465 | ) | |
4466 | { | |
4467 | *px = ux; | |
4468 | *py = uy; | |
4469 | return true; | |
4470 | } | |
4471 | else | |
4472 | { | |
4473 | if ( m_curcursor != wxCURSOR_ARROW ) CustomSetCursor ( wxCURSOR_ARROW ); | |
4474 | } | |
4475 | return false; | |
4476 | } | |
4477 | ||
4478 | // ----------------------------------------------------------------------- | |
4479 | ||
4480 | void wxPropertyGrid::OnMouseClick( wxMouseEvent &event ) | |
4481 | { | |
4482 | int x, y; | |
4483 | if ( OnMouseCommon( event, &x, &y ) ) | |
4484 | { | |
4485 | HandleMouseClick(x,y,event); | |
4486 | } | |
4487 | event.Skip(); | |
4488 | } | |
4489 | ||
4490 | // ----------------------------------------------------------------------- | |
4491 | ||
4492 | void wxPropertyGrid::OnMouseRightClick( wxMouseEvent &event ) | |
4493 | { | |
4494 | int x, y; | |
4495 | CalcUnscrolledPosition( event.m_x, event.m_y, &x, &y ); | |
4496 | HandleMouseRightClick(x,y,event); | |
4497 | event.Skip(); | |
4498 | } | |
4499 | ||
4500 | // ----------------------------------------------------------------------- | |
4501 | ||
4502 | void wxPropertyGrid::OnMouseDoubleClick( wxMouseEvent &event ) | |
4503 | { | |
4504 | // Always run standard mouse-down handler as well | |
4505 | OnMouseClick(event); | |
4506 | ||
4507 | int x, y; | |
4508 | CalcUnscrolledPosition( event.m_x, event.m_y, &x, &y ); | |
4509 | HandleMouseDoubleClick(x,y,event); | |
4510 | event.Skip(); | |
4511 | } | |
4512 | ||
4513 | // ----------------------------------------------------------------------- | |
4514 | ||
4515 | void wxPropertyGrid::OnMouseMove( wxMouseEvent &event ) | |
4516 | { | |
4517 | int x, y; | |
4518 | if ( OnMouseCommon( event, &x, &y ) ) | |
4519 | { | |
4520 | HandleMouseMove(x,y,event); | |
4521 | } | |
4522 | event.Skip(); | |
4523 | } | |
4524 | ||
4525 | // ----------------------------------------------------------------------- | |
4526 | ||
4527 | void wxPropertyGrid::OnMouseMoveBottom( wxMouseEvent& WXUNUSED(event) ) | |
4528 | { | |
4529 | // Called when mouse moves in the empty space below the properties. | |
4530 | CustomSetCursor( wxCURSOR_ARROW ); | |
4531 | } | |
4532 | ||
4533 | // ----------------------------------------------------------------------- | |
4534 | ||
4535 | void wxPropertyGrid::OnMouseUp( wxMouseEvent &event ) | |
4536 | { | |
4537 | int x, y; | |
4538 | if ( OnMouseCommon( event, &x, &y ) ) | |
4539 | { | |
4540 | HandleMouseUp(x,y,event); | |
4541 | } | |
4542 | event.Skip(); | |
4543 | } | |
4544 | ||
4545 | // ----------------------------------------------------------------------- | |
4546 | ||
4547 | void wxPropertyGrid::OnMouseEntry( wxMouseEvent &event ) | |
4548 | { | |
4549 | // This may get called from child control as well, so event's | |
4550 | // mouse position cannot be relied on. | |
4551 | ||
4552 | if ( event.Entering() ) | |
4553 | { | |
4554 | if ( !(m_iFlags & wxPG_FL_MOUSE_INSIDE) ) | |
4555 | { | |
4556 | // TODO: Fix this (detect parent and only do | |
4557 | // cursor trick if it is a manager). | |
4558 | wxASSERT( GetParent() ); | |
4559 | GetParent()->SetCursor(wxNullCursor); | |
4560 | ||
4561 | m_iFlags |= wxPG_FL_MOUSE_INSIDE; | |
4562 | } | |
4563 | else | |
4564 | GetParent()->SetCursor(wxNullCursor); | |
4565 | } | |
4566 | else if ( event.Leaving() ) | |
4567 | { | |
4568 | // Without this, wxSpinCtrl editor will sometimes have wrong cursor | |
4569 | m_canvas->SetCursor( wxNullCursor ); | |
4570 | ||
4571 | // Get real cursor position | |
4572 | wxPoint pt = ScreenToClient(::wxGetMousePosition()); | |
4573 | ||
4574 | if ( ( pt.x <= 0 || pt.y <= 0 || pt.x >= m_width || pt.y >= m_height ) ) | |
4575 | { | |
4576 | { | |
4577 | if ( (m_iFlags & wxPG_FL_MOUSE_INSIDE) ) | |
4578 | { | |
4579 | m_iFlags &= ~(wxPG_FL_MOUSE_INSIDE); | |
4580 | } | |
4581 | ||
4582 | if ( m_dragStatus ) | |
4583 | wxPropertyGrid::HandleMouseUp ( -1, 10000, event ); | |
4584 | } | |
4585 | } | |
4586 | } | |
4587 | ||
4588 | event.Skip(); | |
4589 | } | |
4590 | ||
4591 | // ----------------------------------------------------------------------- | |
4592 | ||
4593 | // Common code used by various OnMouseXXXChild methods. | |
4594 | bool wxPropertyGrid::OnMouseChildCommon( wxMouseEvent &event, int* px, int *py ) | |
4595 | { | |
4596 | wxWindow* topCtrlWnd = (wxWindow*)event.GetEventObject(); | |
4597 | wxASSERT( topCtrlWnd ); | |
4598 | int x, y; | |
4599 | event.GetPosition(&x,&y); | |
4600 | ||
1c4293cb VZ |
4601 | int splitterX = GetSplitterPosition(); |
4602 | ||
4603 | wxRect r = topCtrlWnd->GetRect(); | |
4604 | if ( !m_dragStatus && | |
4605 | x > (splitterX-r.x+wxPG_SPLITTERX_DETECTMARGIN2) && | |
4606 | y >= 0 && y < r.height \ | |
4607 | ) | |
4608 | { | |
4609 | if ( m_curcursor != wxCURSOR_ARROW ) CustomSetCursor ( wxCURSOR_ARROW ); | |
4610 | event.Skip(); | |
4611 | } | |
4612 | else | |
4613 | { | |
4614 | CalcUnscrolledPosition( event.m_x + r.x, event.m_y + r.y, \ | |
4615 | px, py ); | |
4616 | return true; | |
4617 | } | |
4618 | return false; | |
4619 | } | |
4620 | ||
4621 | void wxPropertyGrid::OnMouseClickChild( wxMouseEvent &event ) | |
4622 | { | |
4623 | int x,y; | |
4624 | if ( OnMouseChildCommon(event,&x,&y) ) | |
4625 | { | |
4626 | bool res = HandleMouseClick(x,y,event); | |
4627 | if ( !res ) event.Skip(); | |
4628 | } | |
4629 | } | |
4630 | ||
4631 | void wxPropertyGrid::OnMouseRightClickChild( wxMouseEvent &event ) | |
4632 | { | |
4633 | int x,y; | |
4634 | wxASSERT( m_wndEditor ); | |
4635 | // These coords may not be exact (about +-2), | |
4636 | // but that should not matter (right click is about item, not position). | |
4637 | wxPoint pt = m_wndEditor->GetPosition(); | |
4638 | CalcUnscrolledPosition( event.m_x + pt.x, event.m_y + pt.y, &x, &y ); | |
4639 | wxASSERT( m_selected ); | |
4640 | m_propHover = m_selected; | |
4641 | bool res = HandleMouseRightClick(x,y,event); | |
4642 | if ( !res ) event.Skip(); | |
4643 | } | |
4644 | ||
4645 | void wxPropertyGrid::OnMouseMoveChild( wxMouseEvent &event ) | |
4646 | { | |
4647 | int x,y; | |
4648 | if ( OnMouseChildCommon(event,&x,&y) ) | |
4649 | { | |
4650 | bool res = HandleMouseMove(x,y,event); | |
4651 | if ( !res ) event.Skip(); | |
4652 | } | |
4653 | } | |
4654 | ||
4655 | void wxPropertyGrid::OnMouseUpChild( wxMouseEvent &event ) | |
4656 | { | |
4657 | int x,y; | |
4658 | if ( OnMouseChildCommon(event,&x,&y) ) | |
4659 | { | |
4660 | bool res = HandleMouseUp(x,y,event); | |
4661 | if ( !res ) event.Skip(); | |
4662 | } | |
4663 | } | |
4664 | ||
4665 | // ----------------------------------------------------------------------- | |
4666 | // wxPropertyGrid keyboard event handling | |
4667 | // ----------------------------------------------------------------------- | |
4668 | ||
1c4293cb VZ |
4669 | int wxPropertyGrid::KeyEventToActions(wxKeyEvent &event, int* pSecond) const |
4670 | { | |
4671 | // Translates wxKeyEvent to wxPG_ACTION_XXX | |
4672 | ||
4673 | int keycode = event.GetKeyCode(); | |
4674 | int modifiers = event.GetModifiers(); | |
4675 | ||
4676 | wxASSERT( !(modifiers&~(0xFFFF)) ); | |
4677 | ||
4678 | int hashMapKey = (keycode & 0xFFFF) | ((modifiers & 0xFFFF) << 16); | |
4679 | ||
4680 | wxPGHashMapI2I::const_iterator it = m_actionTriggers.find(hashMapKey); | |
4681 | ||
4682 | if ( it == m_actionTriggers.end() ) | |
4683 | return 0; | |
4684 | ||
4685 | if ( pSecond ) | |
4686 | { | |
4687 | int second = (it->second>>16) & 0xFFFF; | |
4688 | *pSecond = second; | |
4689 | } | |
4690 | ||
4691 | return (it->second & 0xFFFF); | |
4692 | } | |
4693 | ||
4694 | void wxPropertyGrid::AddActionTrigger( int action, int keycode, int modifiers ) | |
4695 | { | |
4696 | wxASSERT( !(modifiers&~(0xFFFF)) ); | |
4697 | ||
4698 | int hashMapKey = (keycode & 0xFFFF) | ((modifiers & 0xFFFF) << 16); | |
4699 | ||
4700 | wxPGHashMapI2I::iterator it = m_actionTriggers.find(hashMapKey); | |
4701 | ||
4702 | if ( it != m_actionTriggers.end() ) | |
4703 | { | |
4704 | // This key combination is already used | |
4705 | ||
4706 | // Can add secondary? | |
4707 | wxASSERT_MSG( !(it->second&~(0xFFFF)), | |
4708 | wxT("You can only add up to two separate actions per key combination.") ); | |
4709 | ||
4710 | action = it->second | (action<<16); | |
4711 | } | |
4712 | ||
4713 | m_actionTriggers[hashMapKey] = action; | |
4714 | } | |
4715 | ||
4716 | void wxPropertyGrid::ClearActionTriggers( int action ) | |
4717 | { | |
4718 | wxPGHashMapI2I::iterator it; | |
4719 | ||
b7bc9d80 | 4720 | for ( it = m_actionTriggers.begin(); it != m_actionTriggers.end(); ++it ) |
1c4293cb VZ |
4721 | { |
4722 | if ( it->second == action ) | |
4723 | { | |
4724 | m_actionTriggers.erase(it); | |
4725 | } | |
4726 | } | |
4727 | } | |
4728 | ||
68f9e025 | 4729 | void wxPropertyGrid::HandleKeyEvent( wxKeyEvent &event, bool fromChild ) |
1c4293cb VZ |
4730 | { |
4731 | // | |
4732 | // Handles key event when editor control is not focused. | |
4733 | // | |
4734 | ||
b7bc9d80 | 4735 | wxCHECK2(!m_frozen, return); |
1c4293cb VZ |
4736 | |
4737 | // Travelsal between items, collapsing/expanding, etc. | |
4738 | int keycode = event.GetKeyCode(); | |
68f9e025 | 4739 | bool editorFocused = IsEditorFocused(); |
1c4293cb VZ |
4740 | |
4741 | if ( keycode == WXK_TAB ) | |
4742 | { | |
b50e81c6 JS |
4743 | wxWindow* mainControl; |
4744 | ||
4745 | if ( HasInternalFlag(wxPG_FL_IN_MANAGER) ) | |
4746 | mainControl = GetParent(); | |
4747 | else | |
4748 | mainControl = this; | |
4749 | ||
68f9e025 JS |
4750 | if ( !event.ShiftDown() ) |
4751 | { | |
4752 | if ( !editorFocused && m_wndEditor ) | |
b50e81c6 | 4753 | { |
68f9e025 | 4754 | DoSelectProperty( m_selected, wxPG_SEL_FOCUS ); |
b50e81c6 | 4755 | } |
68f9e025 | 4756 | else |
b50e81c6 JS |
4757 | { |
4758 | // Tab traversal workaround for platforms on which | |
4759 | // wxWindow::Navigate() may navigate into first child | |
4760 | // instead of next sibling. Does not work perfectly | |
4761 | // in every scenario (for instance, when property grid | |
4762 | // is either first or last control). | |
4763 | #if defined(__WXGTK__) | |
4764 | wxWindow* sibling = mainControl->GetNextSibling(); | |
4765 | if ( sibling ) | |
4766 | sibling->SetFocusFromKbd(); | |
4767 | #else | |
68f9e025 | 4768 | Navigate(wxNavigationKeyEvent::IsForward); |
b50e81c6 JS |
4769 | #endif |
4770 | } | |
68f9e025 JS |
4771 | } |
4772 | else | |
4773 | { | |
4774 | if ( editorFocused ) | |
b50e81c6 | 4775 | { |
68f9e025 | 4776 | UnfocusEditor(); |
b50e81c6 | 4777 | } |
68f9e025 | 4778 | else |
b50e81c6 JS |
4779 | { |
4780 | #if defined(__WXGTK__) | |
4781 | wxWindow* sibling = mainControl->GetPrevSibling(); | |
4782 | if ( sibling ) | |
4783 | sibling->SetFocusFromKbd(); | |
4784 | #else | |
68f9e025 | 4785 | Navigate(wxNavigationKeyEvent::IsBackward); |
b50e81c6 JS |
4786 | #endif |
4787 | } | |
68f9e025 JS |
4788 | } |
4789 | ||
1c4293cb VZ |
4790 | return; |
4791 | } | |
4792 | ||
4793 | // Ignore Alt and Control when they are down alone | |
4794 | if ( keycode == WXK_ALT || | |
4795 | keycode == WXK_CONTROL ) | |
4796 | { | |
4797 | event.Skip(); | |
4798 | return; | |
4799 | } | |
4800 | ||
4801 | int secondAction; | |
4802 | int action = KeyEventToActions(event, &secondAction); | |
4803 | ||
68f9e025 | 4804 | if ( editorFocused && action == wxPG_ACTION_CANCEL_EDIT ) |
1c4293cb | 4805 | { |
68f9e025 JS |
4806 | // |
4807 | // Esc cancels any changes | |
4808 | if ( IsEditorsValueModified() ) | |
4809 | { | |
4810 | EditorsValueWasNotModified(); | |
1c4293cb | 4811 | |
68f9e025 JS |
4812 | // Update the control as well |
4813 | m_selected->GetEditorClass()->SetControlStringValue( m_selected, | |
4814 | GetEditorControl(), | |
4815 | m_selected->GetDisplayedString() ); | |
4816 | } | |
4817 | ||
4818 | OnValidationFailureReset(m_selected); | |
4819 | ||
4820 | UnfocusEditor(); | |
4821 | return; | |
4822 | } | |
4823 | ||
4824 | // Except for TAB and ESC, handle child control events in child control | |
4825 | if ( fromChild ) | |
4d11369d | 4826 | { |
c12822fe JS |
4827 | // Only propagate event if it had modifiers |
4828 | if ( !event.HasModifiers() ) | |
4829 | { | |
4830 | event.StopPropagation(); | |
4831 | } | |
4d11369d | 4832 | event.Skip(); |
68f9e025 | 4833 | return; |
4d11369d JS |
4834 | } |
4835 | ||
4836 | bool wasHandled = false; | |
68f9e025 JS |
4837 | |
4838 | if ( m_selected ) | |
4839 | { | |
1c4293cb | 4840 | // Show dialog? |
1766bf34 | 4841 | if ( ButtonTriggerKeyTest(action, event) ) |
1c4293cb VZ |
4842 | return; |
4843 | ||
4844 | wxPGProperty* p = m_selected; | |
4845 | ||
174b59ac JS |
4846 | // Travel and expand/collapse |
4847 | int selectDir = -2; | |
4848 | ||
48f0334d | 4849 | if ( p->GetChildCount() ) |
1c4293cb | 4850 | { |
174b59ac JS |
4851 | if ( action == wxPG_ACTION_COLLAPSE_PROPERTY || secondAction == wxPG_ACTION_COLLAPSE_PROPERTY ) |
4852 | { | |
4853 | if ( (m_windowStyle & wxPG_HIDE_MARGIN) || Collapse(p) ) | |
4d11369d | 4854 | wasHandled = true; |
174b59ac JS |
4855 | } |
4856 | else if ( action == wxPG_ACTION_EXPAND_PROPERTY || secondAction == wxPG_ACTION_EXPAND_PROPERTY ) | |
4857 | { | |
4858 | if ( (m_windowStyle & wxPG_HIDE_MARGIN) || Expand(p) ) | |
4d11369d | 4859 | wasHandled = true; |
174b59ac | 4860 | } |
1c4293cb | 4861 | } |
1c4293cb | 4862 | |
4d11369d | 4863 | if ( !wasHandled ) |
174b59ac JS |
4864 | { |
4865 | if ( action == wxPG_ACTION_PREV_PROPERTY || secondAction == wxPG_ACTION_PREV_PROPERTY ) | |
1c4293cb | 4866 | { |
174b59ac | 4867 | selectDir = -1; |
1c4293cb | 4868 | } |
174b59ac | 4869 | else if ( action == wxPG_ACTION_NEXT_PROPERTY || secondAction == wxPG_ACTION_NEXT_PROPERTY ) |
1c4293cb | 4870 | { |
174b59ac | 4871 | selectDir = 1; |
1c4293cb | 4872 | } |
174b59ac JS |
4873 | } |
4874 | ||
4875 | if ( selectDir >= -1 ) | |
4876 | { | |
4877 | p = wxPropertyGridIterator::OneStep( m_pState, wxPG_ITERATE_VISIBLE, p, selectDir ); | |
4878 | if ( p ) | |
4879 | DoSelectProperty(p); | |
4d11369d | 4880 | wasHandled = true; |
1c4293cb VZ |
4881 | } |
4882 | } | |
4883 | else | |
4884 | { | |
4885 | // If nothing was selected, select the first item now | |
4886 | // (or navigate out of tab). | |
4887 | if ( action != wxPG_ACTION_CANCEL_EDIT && secondAction != wxPG_ACTION_CANCEL_EDIT ) | |
4888 | { | |
4889 | wxPGProperty* p = wxPropertyGridInterface::GetFirst(); | |
4890 | if ( p ) DoSelectProperty(p); | |
4d11369d | 4891 | wasHandled = true; |
1c4293cb VZ |
4892 | } |
4893 | } | |
4d11369d JS |
4894 | |
4895 | if ( !wasHandled ) | |
4896 | event.Skip(); | |
1c4293cb VZ |
4897 | } |
4898 | ||
4899 | // ----------------------------------------------------------------------- | |
4900 | ||
1c4293cb VZ |
4901 | void wxPropertyGrid::OnKey( wxKeyEvent &event ) |
4902 | { | |
c12822fe JS |
4903 | // If there was editor open and focused, then this event should not |
4904 | // really be processed here. | |
4905 | if ( IsEditorFocused() ) | |
4906 | { | |
4907 | // However, if event had modifiers, it is probably still best | |
4908 | // to skip it. | |
4909 | if ( event.HasModifiers() ) | |
4910 | event.Skip(); | |
4911 | else | |
4912 | event.StopPropagation(); | |
4913 | return; | |
4914 | } | |
4915 | ||
68f9e025 | 4916 | HandleKeyEvent(event, false); |
1c4293cb VZ |
4917 | } |
4918 | ||
4919 | // ----------------------------------------------------------------------- | |
4920 | ||
1766bf34 | 4921 | bool wxPropertyGrid::ButtonTriggerKeyTest( int action, wxKeyEvent& event ) |
1c4293cb | 4922 | { |
1766bf34 JS |
4923 | if ( action == -1 ) |
4924 | { | |
4925 | int secondAction; | |
4926 | action = KeyEventToActions(event, &secondAction); | |
4927 | } | |
1c4293cb VZ |
4928 | |
4929 | // Does the keycode trigger button? | |
1766bf34 JS |
4930 | if ( action == wxPG_ACTION_PRESS_BUTTON && |
4931 | m_wndEditor2 ) | |
1c4293cb | 4932 | { |
1766bf34 | 4933 | wxCommandEvent evt(wxEVT_COMMAND_BUTTON_CLICKED, m_wndEditor2->GetId()); |
1c4293cb VZ |
4934 | GetEventHandler()->AddPendingEvent(evt); |
4935 | return true; | |
4936 | } | |
4937 | ||
4938 | return false; | |
4939 | } | |
4940 | ||
4941 | // ----------------------------------------------------------------------- | |
4942 | ||
4943 | void wxPropertyGrid::OnChildKeyDown( wxKeyEvent &event ) | |
4944 | { | |
68f9e025 | 4945 | HandleKeyEvent(event, true); |
1c4293cb VZ |
4946 | } |
4947 | ||
4948 | // ----------------------------------------------------------------------- | |
4949 | // wxPropertyGrid miscellaneous event handling | |
4950 | // ----------------------------------------------------------------------- | |
4951 | ||
4952 | void wxPropertyGrid::OnIdle( wxIdleEvent& WXUNUSED(event) ) | |
4953 | { | |
4954 | // | |
4955 | // Check if the focus is in this control or one of its children | |
4956 | wxWindow* newFocused = wxWindow::FindFocus(); | |
4957 | ||
4958 | if ( newFocused != m_curFocused ) | |
4959 | HandleFocusChange( newFocused ); | |
4960 | } | |
4961 | ||
68f9e025 JS |
4962 | bool wxPropertyGrid::IsEditorFocused() const |
4963 | { | |
4964 | wxWindow* focus = wxWindow::FindFocus(); | |
4965 | ||
4966 | if ( focus == m_wndEditor || focus == m_wndEditor2 || | |
4967 | focus == GetEditorControl() ) | |
4968 | return true; | |
4969 | ||
4970 | return false; | |
4971 | } | |
4972 | ||
1c4293cb VZ |
4973 | // Called by focus event handlers. newFocused is the window that becomes focused. |
4974 | void wxPropertyGrid::HandleFocusChange( wxWindow* newFocused ) | |
4975 | { | |
4976 | unsigned int oldFlags = m_iFlags; | |
4977 | ||
4978 | m_iFlags &= ~(wxPG_FL_FOCUSED); | |
4979 | ||
4980 | wxWindow* parent = newFocused; | |
4981 | ||
4982 | // This must be one of nextFocus' parents. | |
4983 | while ( parent ) | |
4984 | { | |
4985 | // Use m_eventObject, which is either wxPropertyGrid or | |
4986 | // wxPropertyGridManager, as appropriate. | |
4987 | if ( parent == m_eventObject ) | |
4988 | { | |
4989 | m_iFlags |= wxPG_FL_FOCUSED; | |
4990 | break; | |
4991 | } | |
4992 | parent = parent->GetParent(); | |
4993 | } | |
4994 | ||
4995 | m_curFocused = newFocused; | |
4996 | ||
4997 | if ( (m_iFlags & wxPG_FL_FOCUSED) != | |
4998 | (oldFlags & wxPG_FL_FOCUSED) ) | |
4999 | { | |
1c4293cb VZ |
5000 | if ( !(m_iFlags & wxPG_FL_FOCUSED) ) |
5001 | { | |
1c4293cb VZ |
5002 | // Need to store changed value |
5003 | CommitChangesFromEditor(); | |
5004 | } | |
5005 | else | |
5006 | { | |
5007 | /* | |
5008 | // | |
5009 | // Preliminary code for tab-order respecting | |
5010 | // tab-traversal (but should be moved to | |
5011 | // OnNav handler) | |
5012 | // | |
5013 | wxWindow* prevFocus = event.GetWindow(); | |
5014 | wxWindow* useThis = this; | |
5015 | if ( m_iFlags & wxPG_FL_IN_MANAGER ) | |
5016 | useThis = GetParent(); | |
5017 | ||
5018 | if ( prevFocus && | |
5019 | prevFocus->GetParent() == useThis->GetParent() ) | |
5020 | { | |
5021 | wxList& children = useThis->GetParent()->GetChildren(); | |
5022 | ||
5023 | wxNode* node = children.Find(prevFocus); | |
5024 | ||
5025 | if ( node->GetNext() && | |
5026 | useThis == node->GetNext()->GetData() ) | |
5027 | DoSelectProperty(GetFirst()); | |
5028 | else if ( node->GetPrevious () && | |
5029 | useThis == node->GetPrevious()->GetData() ) | |
5030 | DoSelectProperty(GetLastProperty()); | |
5031 | ||
5032 | } | |
5033 | */ | |
1c4293cb VZ |
5034 | } |
5035 | ||
5036 | // Redraw selected | |
5037 | if ( m_selected && (m_iFlags & wxPG_FL_INITIALIZED) ) | |
5038 | DrawItem( m_selected ); | |
5039 | } | |
5040 | } | |
5041 | ||
5042 | void wxPropertyGrid::OnFocusEvent( wxFocusEvent& event ) | |
5043 | { | |
5044 | if ( event.GetEventType() == wxEVT_SET_FOCUS ) | |
5045 | HandleFocusChange((wxWindow*)event.GetEventObject()); | |
5046 | // Line changed to "else" when applying wxPropertyGrid patch #1675902 | |
5047 | //else if ( event.GetWindow() ) | |
5048 | else | |
5049 | HandleFocusChange(event.GetWindow()); | |
5050 | ||
5051 | event.Skip(); | |
5052 | } | |
5053 | ||
5054 | // ----------------------------------------------------------------------- | |
5055 | ||
5056 | void wxPropertyGrid::OnChildFocusEvent( wxChildFocusEvent& event ) | |
5057 | { | |
5058 | HandleFocusChange((wxWindow*)event.GetEventObject()); | |
8c5c56e2 | 5059 | event.Skip(); |
1c4293cb VZ |
5060 | } |
5061 | ||
5062 | // ----------------------------------------------------------------------- | |
5063 | ||
5064 | void wxPropertyGrid::OnScrollEvent( wxScrollWinEvent &event ) | |
5065 | { | |
5066 | m_iFlags |= wxPG_FL_SCROLLED; | |
5067 | ||
5068 | event.Skip(); | |
5069 | } | |
5070 | ||
5071 | // ----------------------------------------------------------------------- | |
5072 | ||
5073 | void wxPropertyGrid::OnCaptureChange( wxMouseCaptureChangedEvent& WXUNUSED(event) ) | |
5074 | { | |
5075 | if ( m_iFlags & wxPG_FL_MOUSE_CAPTURED ) | |
5076 | { | |
5077 | m_iFlags &= ~(wxPG_FL_MOUSE_CAPTURED); | |
5078 | } | |
5079 | } | |
5080 | ||
5081 | // ----------------------------------------------------------------------- | |
5082 | // Property editor related functions | |
5083 | // ----------------------------------------------------------------------- | |
5084 | ||
5085 | // noDefCheck = true prevents infinite recursion. | |
b7d19850 JS |
5086 | wxPGEditor* wxPropertyGrid::DoRegisterEditorClass( wxPGEditor* editorClass, |
5087 | const wxString& editorName, | |
5088 | bool noDefCheck ) | |
1c4293cb | 5089 | { |
7a344f1b | 5090 | wxASSERT( editorClass ); |
1c4293cb VZ |
5091 | |
5092 | if ( !noDefCheck && wxPGGlobalVars->m_mapEditorClasses.empty() ) | |
5093 | RegisterDefaultEditors(); | |
5094 | ||
b7d19850 JS |
5095 | wxString name = editorName; |
5096 | if ( name.length() == 0 ) | |
5097 | name = editorClass->GetName(); | |
614fbbad JS |
5098 | |
5099 | // Existing editor under this name? | |
5100 | wxPGHashMapS2P::iterator vt_it = wxPGGlobalVars->m_mapEditorClasses.find(name); | |
5101 | ||
5a45dd6f JS |
5102 | if ( vt_it != wxPGGlobalVars->m_mapEditorClasses.end() ) |
5103 | { | |
5104 | // If this name was already used, try class name. | |
5105 | name = editorClass->GetClassInfo()->GetClassName(); | |
5106 | vt_it = wxPGGlobalVars->m_mapEditorClasses.find(name); | |
5107 | } | |
5108 | ||
614fbbad JS |
5109 | wxCHECK_MSG( vt_it == wxPGGlobalVars->m_mapEditorClasses.end(), |
5110 | (wxPGEditor*) vt_it->second, | |
5111 | "Editor with given name was already registered" ); | |
5112 | ||
7a344f1b | 5113 | wxPGGlobalVars->m_mapEditorClasses[name] = (void*)editorClass; |
1c4293cb | 5114 | |
7a344f1b | 5115 | return editorClass; |
1c4293cb VZ |
5116 | } |
5117 | ||
52cefafe JS |
5118 | // Use this in RegisterDefaultEditors. |
5119 | #define wxPGRegisterDefaultEditorClass(EDITOR) \ | |
d3b9f782 | 5120 | if ( wxPGEditor_##EDITOR == NULL ) \ |
52cefafe JS |
5121 | { \ |
5122 | wxPGEditor_##EDITOR = wxPropertyGrid::RegisterEditorClass( \ | |
5123 | new wxPG##EDITOR##Editor, true ); \ | |
5124 | } | |
5125 | ||
1c4293cb VZ |
5126 | // Registers all default editor classes |
5127 | void wxPropertyGrid::RegisterDefaultEditors() | |
5128 | { | |
5129 | wxPGRegisterDefaultEditorClass( TextCtrl ); | |
5130 | wxPGRegisterDefaultEditorClass( Choice ); | |
5131 | wxPGRegisterDefaultEditorClass( ComboBox ); | |
5132 | wxPGRegisterDefaultEditorClass( TextCtrlAndButton ); | |
5133 | #if wxPG_INCLUDE_CHECKBOX | |
5134 | wxPGRegisterDefaultEditorClass( CheckBox ); | |
5135 | #endif | |
5136 | wxPGRegisterDefaultEditorClass( ChoiceAndButton ); | |
5137 | ||
5138 | // Register SpinCtrl etc. editors before use | |
5139 | RegisterAdditionalEditors(); | |
5140 | } | |
5141 | ||
5142 | // ----------------------------------------------------------------------- | |
5143 | // wxPGStringTokenizer | |
5144 | // Needed to handle C-style string lists (e.g. "str1" "str2") | |
5145 | // ----------------------------------------------------------------------- | |
5146 | ||
5147 | wxPGStringTokenizer::wxPGStringTokenizer( const wxString& str, wxChar delimeter ) | |
5148 | : m_str(&str), m_curPos(str.begin()), m_delimeter(delimeter) | |
5149 | { | |
5150 | } | |
5151 | ||
5152 | wxPGStringTokenizer::~wxPGStringTokenizer() | |
5153 | { | |
5154 | } | |
5155 | ||
5156 | bool wxPGStringTokenizer::HasMoreTokens() | |
5157 | { | |
5158 | const wxString& str = *m_str; | |
5159 | ||
5160 | wxString::const_iterator i = m_curPos; | |
5161 | ||
5162 | wxUniChar delim = m_delimeter; | |
5163 | wxUniChar a; | |
5164 | wxUniChar prev_a = wxT('\0'); | |
5165 | ||
5166 | bool inToken = false; | |
5167 | ||
5168 | while ( i != str.end() ) | |
5169 | { | |
5170 | a = *i; | |
5171 | ||
5172 | if ( !inToken ) | |
5173 | { | |
5174 | if ( a == delim ) | |
5175 | { | |
5176 | inToken = true; | |
5177 | m_readyToken.clear(); | |
5178 | } | |
5179 | } | |
5180 | else | |
5181 | { | |
5182 | if ( prev_a != wxT('\\') ) | |
5183 | { | |
5184 | if ( a != delim ) | |
5185 | { | |
5186 | if ( a != wxT('\\') ) | |
5187 | m_readyToken << a; | |
5188 | } | |
5189 | else | |
5190 | { | |
b7bc9d80 | 5191 | ++i; |
1c4293cb VZ |
5192 | m_curPos = i; |
5193 | return true; | |
5194 | } | |
5195 | prev_a = a; | |
5196 | } | |
5197 | else | |
5198 | { | |
5199 | m_readyToken << a; | |
5200 | prev_a = wxT('\0'); | |
5201 | } | |
5202 | } | |
b7bc9d80 | 5203 | ++i; |
1c4293cb VZ |
5204 | } |
5205 | ||
5206 | m_curPos = str.end(); | |
5207 | ||
5208 | if ( inToken ) | |
5209 | return true; | |
5210 | ||
5211 | return false; | |
5212 | } | |
5213 | ||
5214 | wxString wxPGStringTokenizer::GetNextToken() | |
5215 | { | |
5216 | return m_readyToken; | |
5217 | } | |
5218 | ||
5219 | // ----------------------------------------------------------------------- | |
5220 | // wxPGChoiceEntry | |
5221 | // ----------------------------------------------------------------------- | |
5222 | ||
5223 | wxPGChoiceEntry::wxPGChoiceEntry() | |
5224 | : wxPGCell(), m_value(wxPG_INVALID_VALUE) | |
5225 | { | |
5226 | } | |
5227 | ||
1c4293cb VZ |
5228 | // ----------------------------------------------------------------------- |
5229 | // wxPGChoicesData | |
5230 | // ----------------------------------------------------------------------- | |
5231 | ||
5232 | wxPGChoicesData::wxPGChoicesData() | |
5233 | { | |
1c4293cb VZ |
5234 | } |
5235 | ||
5236 | wxPGChoicesData::~wxPGChoicesData() | |
5237 | { | |
5238 | Clear(); | |
5239 | } | |
5240 | ||
5241 | void wxPGChoicesData::Clear() | |
5242 | { | |
f7a094e1 | 5243 | m_items.clear(); |
1c4293cb VZ |
5244 | } |
5245 | ||
5246 | void wxPGChoicesData::CopyDataFrom( wxPGChoicesData* data ) | |
5247 | { | |
5248 | wxASSERT( m_items.size() == 0 ); | |
5249 | ||
d7e2b522 JS |
5250 | m_items = data->m_items; |
5251 | } | |
1c4293cb | 5252 | |
d7e2b522 JS |
5253 | wxPGChoiceEntry& wxPGChoicesData::Insert( int index, |
5254 | const wxPGChoiceEntry& item ) | |
5255 | { | |
5256 | wxVector<wxPGChoiceEntry>::iterator it; | |
5257 | if ( index == -1 ) | |
5258 | { | |
5259 | it = m_items.end(); | |
5260 | index = (int) m_items.size(); | |
5261 | } | |
5262 | else | |
5263 | { | |
5264 | it = m_items.begin() + index; | |
5265 | } | |
5266 | ||
5267 | m_items.insert(it, item); | |
5268 | ||
5269 | wxPGChoiceEntry& ownEntry = m_items[index]; | |
5270 | ||
5271 | // Need to fix value? | |
5272 | if ( ownEntry.GetValue() == wxPG_INVALID_VALUE ) | |
5273 | ownEntry.SetValue(index); | |
5274 | ||
5275 | return ownEntry; | |
1c4293cb VZ |
5276 | } |
5277 | ||
1c4293cb VZ |
5278 | // ----------------------------------------------------------------------- |
5279 | // wxPropertyGridEvent | |
5280 | // ----------------------------------------------------------------------- | |
5281 | ||
5282 | IMPLEMENT_DYNAMIC_CLASS(wxPropertyGridEvent, wxCommandEvent) | |
5283 | ||
5284 | ||
9b11752c VZ |
5285 | wxDEFINE_EVENT( wxEVT_PG_SELECTED, wxPropertyGridEvent ); |
5286 | wxDEFINE_EVENT( wxEVT_PG_CHANGING, wxPropertyGridEvent ); | |
5287 | wxDEFINE_EVENT( wxEVT_PG_CHANGED, wxPropertyGridEvent ); | |
5288 | wxDEFINE_EVENT( wxEVT_PG_HIGHLIGHTED, wxPropertyGridEvent ); | |
5289 | wxDEFINE_EVENT( wxEVT_PG_RIGHT_CLICK, wxPropertyGridEvent ); | |
5290 | wxDEFINE_EVENT( wxEVT_PG_PAGE_CHANGED, wxPropertyGridEvent ); | |
5291 | wxDEFINE_EVENT( wxEVT_PG_ITEM_EXPANDED, wxPropertyGridEvent ); | |
5292 | wxDEFINE_EVENT( wxEVT_PG_ITEM_COLLAPSED, wxPropertyGridEvent ); | |
5293 | wxDEFINE_EVENT( wxEVT_PG_DOUBLE_CLICK, wxPropertyGridEvent ); | |
1c4293cb VZ |
5294 | |
5295 | ||
5296 | // ----------------------------------------------------------------------- | |
5297 | ||
5298 | void wxPropertyGridEvent::Init() | |
5299 | { | |
5300 | m_validationInfo = NULL; | |
5301 | m_canVeto = false; | |
5302 | m_wasVetoed = false; | |
5303 | } | |
5304 | ||
5305 | // ----------------------------------------------------------------------- | |
5306 | ||
5307 | wxPropertyGridEvent::wxPropertyGridEvent(wxEventType commandType, int id) | |
5308 | : wxCommandEvent(commandType,id) | |
5309 | { | |
5310 | m_property = NULL; | |
5311 | Init(); | |
5312 | } | |
5313 | ||
5314 | // ----------------------------------------------------------------------- | |
5315 | ||
5316 | wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent& event) | |
5317 | : wxCommandEvent(event) | |
5318 | { | |
5319 | m_eventType = event.GetEventType(); | |
5320 | m_eventObject = event.m_eventObject; | |
5321 | m_pg = event.m_pg; | |
5322 | m_property = event.m_property; | |
5323 | m_validationInfo = event.m_validationInfo; | |
5324 | m_canVeto = event.m_canVeto; | |
5325 | m_wasVetoed = event.m_wasVetoed; | |
5326 | } | |
5327 | ||
5328 | // ----------------------------------------------------------------------- | |
5329 | ||
5330 | wxPropertyGridEvent::~wxPropertyGridEvent() | |
5331 | { | |
5332 | } | |
5333 | ||
5334 | // ----------------------------------------------------------------------- | |
5335 | ||
5336 | wxEvent* wxPropertyGridEvent::Clone() const | |
5337 | { | |
5338 | return new wxPropertyGridEvent( *this ); | |
5339 | } | |
5340 | ||
1c4293cb VZ |
5341 | // ----------------------------------------------------------------------- |
5342 | // wxPropertyGridPopulator | |
5343 | // ----------------------------------------------------------------------- | |
5344 | ||
5345 | wxPropertyGridPopulator::wxPropertyGridPopulator() | |
5346 | { | |
5347 | m_state = NULL; | |
5348 | m_pg = NULL; | |
5349 | wxPGGlobalVars->m_offline++; | |
5350 | } | |
5351 | ||
5352 | // ----------------------------------------------------------------------- | |
5353 | ||
5354 | void wxPropertyGridPopulator::SetState( wxPropertyGridPageState* state ) | |
5355 | { | |
5356 | m_state = state; | |
5357 | m_propHierarchy.clear(); | |
5358 | } | |
5359 | ||
5360 | // ----------------------------------------------------------------------- | |
5361 | ||
5362 | void wxPropertyGridPopulator::SetGrid( wxPropertyGrid* pg ) | |
5363 | { | |
5364 | m_pg = pg; | |
5365 | pg->Freeze(); | |
5366 | } | |
5367 | ||
5368 | // ----------------------------------------------------------------------- | |
5369 | ||
5370 | wxPropertyGridPopulator::~wxPropertyGridPopulator() | |
5371 | { | |
5372 | // | |
5373 | // Free unused sets of choices | |
5374 | wxPGHashMapS2P::iterator it; | |
5375 | ||
5376 | for( it = m_dictIdChoices.begin(); it != m_dictIdChoices.end(); ++it ) | |
5377 | { | |
5378 | wxPGChoicesData* data = (wxPGChoicesData*) it->second; | |
5379 | data->DecRef(); | |
5380 | } | |
5381 | ||
5382 | if ( m_pg ) | |
5383 | { | |
5384 | m_pg->Thaw(); | |
5385 | m_pg->GetPanel()->Refresh(); | |
5386 | } | |
5387 | wxPGGlobalVars->m_offline--; | |
5388 | } | |
5389 | ||
5390 | // ----------------------------------------------------------------------- | |
5391 | ||
5392 | wxPGProperty* wxPropertyGridPopulator::Add( const wxString& propClass, | |
5393 | const wxString& propLabel, | |
5394 | const wxString& propName, | |
5395 | const wxString* propValue, | |
5396 | wxPGChoices* pChoices ) | |
5397 | { | |
5398 | wxClassInfo* classInfo = wxClassInfo::FindClass(propClass); | |
5399 | wxPGProperty* parent = GetCurParent(); | |
5400 | ||
5401 | if ( parent->HasFlag(wxPG_PROP_AGGREGATE) ) | |
5402 | { | |
5403 | ProcessError(wxString::Format(wxT("new children cannot be added to '%s'"),parent->GetName().c_str())); | |
5404 | return NULL; | |
5405 | } | |
5406 | ||
5407 | if ( !classInfo || !classInfo->IsKindOf(CLASSINFO(wxPGProperty)) ) | |
5408 | { | |
5409 | ProcessError(wxString::Format(wxT("'%s' is not valid property class"),propClass.c_str())); | |
5410 | return NULL; | |
5411 | } | |
5412 | ||
5413 | wxPGProperty* property = (wxPGProperty*) classInfo->CreateObject(); | |
5414 | ||
5415 | property->SetLabel(propLabel); | |
5416 | property->DoSetName(propName); | |
5417 | ||
5418 | if ( pChoices && pChoices->IsOk() ) | |
5419 | property->SetChoices(*pChoices); | |
5420 | ||
5421 | m_state->DoInsert(parent, -1, property); | |
5422 | ||
5423 | if ( propValue ) | |
f275b5db JS |
5424 | property->SetValueFromString( *propValue, wxPG_FULL_VALUE| |
5425 | wxPG_PROGRAMMATIC_VALUE ); | |
1c4293cb VZ |
5426 | |
5427 | return property; | |
5428 | } | |
5429 | ||
5430 | // ----------------------------------------------------------------------- | |
5431 | ||
5432 | void wxPropertyGridPopulator::AddChildren( wxPGProperty* property ) | |
5433 | { | |
5434 | m_propHierarchy.push_back(property); | |
5435 | DoScanForChildren(); | |
5436 | m_propHierarchy.pop_back(); | |
5437 | } | |
5438 | ||
5439 | // ----------------------------------------------------------------------- | |
5440 | ||
5441 | wxPGChoices wxPropertyGridPopulator::ParseChoices( const wxString& choicesString, | |
5442 | const wxString& idString ) | |
5443 | { | |
5444 | wxPGChoices choices; | |
5445 | ||
5446 | // Using id? | |
5447 | if ( choicesString[0] == wxT('@') ) | |
5448 | { | |
5449 | wxString ids = choicesString.substr(1); | |
5450 | wxPGHashMapS2P::iterator it = m_dictIdChoices.find(ids); | |
5451 | if ( it == m_dictIdChoices.end() ) | |
5452 | ProcessError(wxString::Format(wxT("No choices defined for id '%s'"),ids.c_str())); | |
5453 | else | |
5454 | choices.AssignData((wxPGChoicesData*)it->second); | |
5455 | } | |
5456 | else | |
5457 | { | |
5458 | bool found = false; | |
5459 | if ( idString.length() ) | |
5460 | { | |
5461 | wxPGHashMapS2P::iterator it = m_dictIdChoices.find(idString); | |
5462 | if ( it != m_dictIdChoices.end() ) | |
5463 | { | |
5464 | choices.AssignData((wxPGChoicesData*)it->second); | |
5465 | found = true; | |
5466 | } | |
5467 | } | |
5468 | ||
5469 | if ( !found ) | |
5470 | { | |
5471 | // Parse choices string | |
5472 | wxString::const_iterator it = choicesString.begin(); | |
5473 | wxString label; | |
5474 | wxString value; | |
5475 | int state = 0; | |
5476 | bool labelValid = false; | |
5477 | ||
b7bc9d80 | 5478 | for ( ; it != choicesString.end(); ++it ) |
1c4293cb VZ |
5479 | { |
5480 | wxChar c = *it; | |
5481 | ||
5482 | if ( state != 1 ) | |
5483 | { | |
5484 | if ( c == wxT('"') ) | |
5485 | { | |
5486 | if ( labelValid ) | |
5487 | { | |
5488 | long l; | |
5489 | if ( !value.ToLong(&l, 0) ) l = wxPG_INVALID_VALUE; | |
5490 | choices.Add(label, l); | |
5491 | } | |
5492 | labelValid = false; | |
5493 | //wxLogDebug(wxT("%s, %s"),label.c_str(),value.c_str()); | |
5494 | value.clear(); | |
5495 | label.clear(); | |
5496 | state = 1; | |
5497 | } | |
5498 | else if ( c == wxT('=') ) | |
5499 | { | |
5500 | if ( labelValid ) | |
5501 | { | |
5502 | state = 2; | |
5503 | } | |
5504 | } | |
5505 | else if ( state == 2 && (wxIsalnum(c) || c == wxT('x')) ) | |
5506 | { | |
5507 | value << c; | |
5508 | } | |
5509 | } | |
5510 | else | |
5511 | { | |
5512 | if ( c == wxT('"') ) | |
5513 | { | |
5514 | state = 0; | |
5515 | labelValid = true; | |
5516 | } | |
5517 | else | |
5518 | label << c; | |
5519 | } | |
5520 | } | |
5521 | ||
5522 | if ( labelValid ) | |
5523 | { | |
5524 | long l; | |
5525 | if ( !value.ToLong(&l, 0) ) l = wxPG_INVALID_VALUE; | |
5526 | choices.Add(label, l); | |
5527 | } | |
5528 | ||
5529 | if ( !choices.IsOk() ) | |
5530 | { | |
5531 | choices.EnsureData(); | |
5532 | } | |
5533 | ||
5534 | // Assign to id | |
5535 | if ( idString.length() ) | |
5536 | m_dictIdChoices[idString] = choices.GetData(); | |
5537 | } | |
5538 | } | |
5539 | ||
5540 | return choices; | |
5541 | } | |
5542 | ||
5543 | // ----------------------------------------------------------------------- | |
5544 | ||
5545 | bool wxPropertyGridPopulator::ToLongPCT( const wxString& s, long* pval, long max ) | |
5546 | { | |
5547 | if ( s.Last() == wxT('%') ) | |
5548 | { | |
5549 | wxString s2 = s.substr(0,s.length()-1); | |
5550 | long val; | |
5551 | if ( s2.ToLong(&val, 10) ) | |
5552 | { | |
5553 | *pval = (val*max)/100; | |
5554 | return true; | |
5555 | } | |
5556 | return false; | |
5557 | } | |
5558 | ||
5559 | return s.ToLong(pval, 10); | |
5560 | } | |
5561 | ||
5562 | // ----------------------------------------------------------------------- | |
5563 | ||
5564 | bool wxPropertyGridPopulator::AddAttribute( const wxString& name, | |
5565 | const wxString& type, | |
5566 | const wxString& value ) | |
5567 | { | |
5568 | int l = m_propHierarchy.size(); | |
5569 | if ( !l ) | |
5570 | return false; | |
5571 | ||
5572 | wxPGProperty* p = m_propHierarchy[l-1]; | |
5573 | wxString valuel = value.Lower(); | |
5574 | wxVariant variant; | |
5575 | ||
5576 | if ( type.length() == 0 ) | |
5577 | { | |
5578 | long v; | |
5579 | ||
5580 | // Auto-detect type | |
5581 | if ( valuel == wxT("true") || valuel == wxT("yes") || valuel == wxT("1") ) | |
5582 | variant = true; | |
5583 | else if ( valuel == wxT("false") || valuel == wxT("no") || valuel == wxT("0") ) | |
5584 | variant = false; | |
5585 | else if ( value.ToLong(&v, 0) ) | |
5586 | variant = v; | |
5587 | else | |
5588 | variant = value; | |
5589 | } | |
5590 | else | |
5591 | { | |
5592 | if ( type == wxT("string") ) | |
5593 | { | |
5594 | variant = value; | |
5595 | } | |
5596 | else if ( type == wxT("int") ) | |
5597 | { | |
5598 | long v = 0; | |
5599 | value.ToLong(&v, 0); | |
5600 | variant = v; | |
5601 | } | |
5602 | else if ( type == wxT("bool") ) | |
5603 | { | |
5604 | if ( valuel == wxT("true") || valuel == wxT("yes") || valuel == wxT("1") ) | |
5605 | variant = true; | |
5606 | else | |
5607 | variant = false; | |
5608 | } | |
5609 | else | |
5610 | { | |
5611 | ProcessError(wxString::Format(wxT("Invalid attribute type '%s'"),type.c_str())); | |
5612 | return false; | |
5613 | } | |
5614 | } | |
5615 | ||
5616 | p->SetAttribute( name, variant ); | |
5617 | ||
5618 | return true; | |
5619 | } | |
5620 | ||
5621 | // ----------------------------------------------------------------------- | |
5622 | ||
5623 | void wxPropertyGridPopulator::ProcessError( const wxString& msg ) | |
5624 | { | |
5625 | wxLogError(_("Error in resource: %s"),msg.c_str()); | |
5626 | } | |
5627 | ||
5628 | // ----------------------------------------------------------------------- | |
f4bc1aa2 JS |
5629 | |
5630 | #endif // wxUSE_PROPGRID |