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