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