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