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