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