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