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