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