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