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