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