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