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