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