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