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