For wxTextCtrl editor, set the bold font before margins are set up or it will not...
[wxWidgets.git] / src / propgrid / editors.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/propgrid/editors.cpp
3 // Purpose: wxPropertyGrid editors
4 // Author: Jaakko Salli
5 // Modified by:
6 // Created: 2007-04-14
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/dcclient.h"
32 #include "wx/dcmemory.h"
33 #include "wx/button.h"
34 #include "wx/pen.h"
35 #include "wx/brush.h"
36 #include "wx/cursor.h"
37 #include "wx/dialog.h"
38 #include "wx/settings.h"
39 #include "wx/msgdlg.h"
40 #include "wx/choice.h"
41 #include "wx/stattext.h"
42 #include "wx/scrolwin.h"
43 #include "wx/dirdlg.h"
44 #include "wx/sizer.h"
45 #include "wx/textdlg.h"
46 #include "wx/filedlg.h"
47 #include "wx/statusbr.h"
48 #include "wx/intl.h"
49 #include "wx/frame.h"
50 #endif
51
52
53 #include "wx/timer.h"
54 #include "wx/dcbuffer.h"
55 #include "wx/bmpbuttn.h"
56
57
58 // This define is necessary to prevent macro clearing
59 #define __wxPG_SOURCE_FILE__
60
61 #include "wx/propgrid/propgrid.h"
62 #include "wx/propgrid/editors.h"
63 #include "wx/propgrid/props.h"
64
65 #if wxPG_USE_RENDERER_NATIVE
66 #include "wx/renderer.h"
67 #endif
68
69 // How many pixels between textctrl and button
70 #ifdef __WXMAC__
71 #define wxPG_TEXTCTRL_AND_BUTTON_SPACING 4
72 #else
73 #define wxPG_TEXTCTRL_AND_BUTTON_SPACING 2
74 #endif
75
76 #define wxPG_BUTTON_SIZEDEC 0
77
78 #include "wx/odcombo.h"
79
80 // -----------------------------------------------------------------------
81
82 #if defined(__WXMSW__)
83 // tested
84 #define wxPG_NAT_BUTTON_BORDER_ANY 1
85 #define wxPG_NAT_BUTTON_BORDER_X 1
86 #define wxPG_NAT_BUTTON_BORDER_Y 1
87
88 #define wxPG_CHECKMARK_XADJ 1
89 #define wxPG_CHECKMARK_YADJ (-1)
90 #define wxPG_CHECKMARK_WADJ 0
91 #define wxPG_CHECKMARK_HADJ 0
92 #define wxPG_CHECKMARK_DEFLATE 0
93
94 #define wxPG_TEXTCTRLYADJUST (m_spacingy+0)
95
96 #elif defined(__WXGTK__)
97 // tested
98 #define wxPG_CHECKMARK_XADJ 0
99 #define wxPG_CHECKMARK_YADJ 0
100 #define wxPG_CHECKMARK_WADJ (-1)
101 #define wxPG_CHECKMARK_HADJ (-1)
102 #define wxPG_CHECKMARK_DEFLATE 3
103
104 #define wxPG_NAT_BUTTON_BORDER_ANY 1
105 #define wxPG_NAT_BUTTON_BORDER_X 1
106 #define wxPG_NAT_BUTTON_BORDER_Y 1
107
108 #define wxPG_TEXTCTRLYADJUST 0
109
110 #elif defined(__WXMAC__)
111 // *not* tested
112 #define wxPG_CHECKMARK_XADJ 0
113 #define wxPG_CHECKMARK_YADJ 0
114 #define wxPG_CHECKMARK_WADJ 0
115 #define wxPG_CHECKMARK_HADJ 0
116 #define wxPG_CHECKMARK_DEFLATE 0
117
118 #define wxPG_NAT_BUTTON_BORDER_ANY 0
119 #define wxPG_NAT_BUTTON_BORDER_X 0
120 #define wxPG_NAT_BUTTON_BORDER_Y 0
121
122 #define wxPG_TEXTCTRLYADJUST 0
123
124 #else
125 // defaults
126 #define wxPG_CHECKMARK_XADJ 0
127 #define wxPG_CHECKMARK_YADJ 0
128 #define wxPG_CHECKMARK_WADJ 0
129 #define wxPG_CHECKMARK_HADJ 0
130 #define wxPG_CHECKMARK_DEFLATE 0
131
132 #define wxPG_NAT_BUTTON_BORDER_ANY 0
133 #define wxPG_NAT_BUTTON_BORDER_X 0
134 #define wxPG_NAT_BUTTON_BORDER_Y 0
135
136 #define wxPG_TEXTCTRLYADJUST 0
137
138 #endif
139
140 // for odcombo
141 #ifdef __WXMAC__
142 #define wxPG_CHOICEXADJUST -3 // required because wxComboCtrl reserves 3pixels for wxTextCtrl's focus ring
143 #define wxPG_CHOICEYADJUST -3
144 #else
145 #define wxPG_CHOICEXADJUST 0
146 #define wxPG_CHOICEYADJUST 0
147 #endif
148
149 // Number added to image width for SetCustomPaintWidth
150 #define ODCB_CUST_PAINT_MARGIN 6
151
152 // Milliseconds to wait for two mouse-ups after focus inorder
153 // to trigger a double-click.
154 #define DOUBLE_CLICK_CONVERSION_TRESHOLD 500
155
156 // -----------------------------------------------------------------------
157 // wxPGEditor
158 // -----------------------------------------------------------------------
159
160 IMPLEMENT_ABSTRACT_CLASS(wxPGEditor, wxObject)
161
162
163 wxPGEditor::~wxPGEditor()
164 {
165 }
166
167 wxString wxPGEditor::GetName() const
168 {
169 return GetClassInfo()->GetClassName();
170 }
171
172 void wxPGEditor::DrawValue( wxDC& dc, const wxRect& rect,
173 wxPGProperty* WXUNUSED(property),
174 const wxString& text ) const
175 {
176 dc.DrawText( text, rect.x+wxPG_XBEFORETEXT, rect.y );
177 }
178
179 bool wxPGEditor::GetValueFromControl( wxVariant&, wxPGProperty*, wxWindow* ) const
180 {
181 return false;
182 }
183
184 void wxPGEditor::SetControlStringValue( wxPGProperty* WXUNUSED(property), wxWindow*, const wxString& ) const
185 {
186 }
187
188
189 void wxPGEditor::SetControlIntValue( wxPGProperty* WXUNUSED(property), wxWindow*, int ) const
190 {
191 }
192
193
194 int wxPGEditor::InsertItem( wxWindow*, const wxString&, int ) const
195 {
196 return -1;
197 }
198
199
200 void wxPGEditor::DeleteItem( wxWindow*, int ) const
201 {
202 return;
203 }
204
205
206 void wxPGEditor::OnFocus( wxPGProperty*, wxWindow* ) const
207 {
208 }
209
210 void wxPGEditor::SetControlAppearance( wxPropertyGrid* pg,
211 wxPGProperty* property,
212 wxWindow* ctrl,
213 const wxPGCell& cell,
214 const wxPGCell& oCell,
215 bool unspecified ) const
216 {
217 // Get old editor appearance
218 wxTextCtrl* tc = NULL;
219 wxComboCtrl* cb = NULL;
220 if ( ctrl->IsKindOf(CLASSINFO(wxTextCtrl)) )
221 {
222 tc = (wxTextCtrl*) ctrl;
223 }
224 else
225 {
226 if ( ctrl->IsKindOf(CLASSINFO(wxComboCtrl)) )
227 {
228 cb = (wxComboCtrl*) ctrl;
229 tc = cb->GetTextCtrl();
230 }
231 }
232
233 if ( tc || cb )
234 {
235 wxString tcText;
236 bool changeText = false;
237
238 if ( cell.HasText() && !pg->IsEditorFocused() )
239 {
240 tcText = cell.GetText();
241 changeText = true;
242 }
243 else if ( oCell.HasText() )
244 {
245 tcText = property->GetValueAsString(
246 property->HasFlag(wxPG_PROP_READONLY)?0:wxPG_EDITABLE_VALUE);
247 changeText = true;
248 }
249
250 if ( changeText )
251 {
252 // This prevents value from being modified
253 if ( tc )
254 {
255 pg->SetupTextCtrlValue(tcText);
256 tc->SetValue(tcText);
257 }
258 else
259 {
260 cb->SetText(tcText);
261 }
262 }
263 }
264
265 // Do not make the mistake of calling GetClassDefaultAttributes()
266 // here. It is static, while GetDefaultAttributes() is virtual
267 // and the correct one to use.
268 wxVisualAttributes vattrs = ctrl->GetDefaultAttributes();
269
270 // Foreground colour
271 const wxColour& fgCol = cell.GetFgCol();
272 if ( fgCol.IsOk() )
273 {
274 ctrl->SetForegroundColour(fgCol);
275 }
276 else if ( oCell.GetFgCol().IsOk() )
277 {
278 ctrl->SetForegroundColour(vattrs.colFg);
279 }
280
281 // Background colour
282 const wxColour& bgCol = cell.GetBgCol();
283 if ( bgCol.IsOk() )
284 {
285 ctrl->SetBackgroundColour(bgCol);
286 }
287 else if ( oCell.GetBgCol().IsOk() )
288 {
289 ctrl->SetBackgroundColour(vattrs.colBg);
290 }
291
292 // Font
293 const wxFont& font = cell.GetFont();
294 if ( font.IsOk() )
295 {
296 ctrl->SetFont(font);
297 }
298 else if ( oCell.GetFont().IsOk() )
299 {
300 ctrl->SetFont(vattrs.font);
301 }
302
303 // Also call the old SetValueToUnspecified()
304 if ( unspecified )
305 SetValueToUnspecified(property, ctrl);
306 }
307
308 void wxPGEditor::SetValueToUnspecified( wxPGProperty* WXUNUSED(property),
309 wxWindow* WXUNUSED(ctrl) ) const
310 {
311 }
312
313 bool wxPGEditor::CanContainCustomImage() const
314 {
315 return false;
316 }
317
318 // -----------------------------------------------------------------------
319 // wxPGTextCtrlEditor
320 // -----------------------------------------------------------------------
321
322 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(TextCtrl,wxPGTextCtrlEditor,wxPGEditor)
323
324
325 wxPGWindowList wxPGTextCtrlEditor::CreateControls( wxPropertyGrid* propGrid,
326 wxPGProperty* property,
327 const wxPoint& pos,
328 const wxSize& sz ) const
329 {
330 wxString text;
331
332 //
333 // If has children, and limited editing is specified, then don't create.
334 if ( (property->GetFlags() & wxPG_PROP_NOEDITOR) &&
335 property->GetChildCount() )
336 return NULL;
337
338 int argFlags = 0;
339 if ( !property->HasFlag(wxPG_PROP_READONLY) &&
340 !property->IsValueUnspecified() )
341 argFlags |= wxPG_EDITABLE_VALUE;
342 text = property->GetValueAsString(argFlags);
343
344 int flags = 0;
345 if ( (property->GetFlags() & wxPG_PROP_PASSWORD) &&
346 property->IsKindOf(CLASSINFO(wxStringProperty)) )
347 flags |= wxTE_PASSWORD;
348
349 wxWindow* wnd = propGrid->GenerateEditorTextCtrl(pos,sz,text,NULL,flags,
350 property->GetMaxLength());
351
352 return wnd;
353 }
354
355 #if 0
356 void wxPGTextCtrlEditor::DrawValue( wxDC& dc, wxPGProperty* property, const wxRect& rect ) const
357 {
358 if ( !property->IsValueUnspecified() )
359 {
360 wxString drawStr = property->GetDisplayedString();
361
362 // Code below should no longer be needed, as the obfuscation
363 // is now done in GetValueAsString.
364 /*if ( (property->GetFlags() & wxPG_PROP_PASSWORD) &&
365 property->IsKindOf(WX_PG_CLASSINFO(wxStringProperty)) )
366 {
367 size_t a = drawStr.length();
368 drawStr.Empty();
369 drawStr.Append(wxS('*'),a);
370 }*/
371 dc.DrawText( drawStr, rect.x+wxPG_XBEFORETEXT, rect.y );
372 }
373 }
374 #endif
375
376 void wxPGTextCtrlEditor::UpdateControl( wxPGProperty* property, wxWindow* ctrl ) const
377 {
378 wxTextCtrl* tc = wxDynamicCast(ctrl, wxTextCtrl);
379 if (!tc) return;
380
381 wxString s;
382
383 if ( tc->HasFlag(wxTE_PASSWORD) )
384 s = property->GetValueAsString(wxPG_FULL_VALUE);
385 else
386 s = property->GetDisplayedString();
387
388 wxPropertyGrid* pg = property->GetGrid();
389
390 pg->SetupTextCtrlValue(s);
391 tc->SetValue(s);
392
393 //
394 // Fix indentation, just in case (change in font boldness is one good
395 // reason).
396 tc->SetMargins(0);
397 }
398
399 // Provided so that, for example, ComboBox editor can use the same code
400 // (multiple inheritance would get way too messy).
401 bool wxPGTextCtrlEditor::OnTextCtrlEvent( wxPropertyGrid* propGrid,
402 wxPGProperty* WXUNUSED(property),
403 wxWindow* ctrl,
404 wxEvent& event )
405 {
406 if ( !ctrl )
407 return false;
408
409 if ( event.GetEventType() == wxEVT_COMMAND_TEXT_ENTER )
410 {
411 if ( propGrid->IsEditorsValueModified() )
412 {
413 return true;
414 }
415 }
416 else if ( event.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED )
417 {
418 //
419 // Pass this event outside wxPropertyGrid so that,
420 // if necessary, program can tell when user is editing
421 // a textctrl.
422 // FIXME: Is it safe to change event id in the middle of event
423 // processing (seems to work, but...)?
424 event.Skip();
425 event.SetId(propGrid->GetId());
426
427 propGrid->EditorsValueWasModified();
428 }
429 return false;
430 }
431
432
433 bool wxPGTextCtrlEditor::OnEvent( wxPropertyGrid* propGrid,
434 wxPGProperty* property,
435 wxWindow* ctrl,
436 wxEvent& event ) const
437 {
438 return wxPGTextCtrlEditor::OnTextCtrlEvent(propGrid,property,ctrl,event);
439 }
440
441
442 bool wxPGTextCtrlEditor::GetTextCtrlValueFromControl( wxVariant& variant, wxPGProperty* property, wxWindow* ctrl )
443 {
444 wxTextCtrl* tc = wxStaticCast(ctrl, wxTextCtrl);
445 wxString textVal = tc->GetValue();
446
447 if ( property->UsesAutoUnspecified() && !textVal.length() )
448 {
449 variant.MakeNull();
450 return true;
451 }
452
453 bool res = property->StringToValue(variant, textVal, wxPG_EDITABLE_VALUE);
454
455 // Changing unspecified always causes event (returning
456 // true here should be enough to trigger it).
457 // TODO: Move to propgrid.cpp
458 if ( !res && variant.IsNull() )
459 res = true;
460
461 return res;
462 }
463
464
465 bool wxPGTextCtrlEditor::GetValueFromControl( wxVariant& variant, wxPGProperty* property, wxWindow* ctrl ) const
466 {
467 return wxPGTextCtrlEditor::GetTextCtrlValueFromControl(variant, property, ctrl);
468 }
469
470
471 void wxPGTextCtrlEditor::SetControlStringValue( wxPGProperty* property, wxWindow* ctrl, const wxString& txt ) const
472 {
473 wxTextCtrl* tc = wxStaticCast(ctrl, wxTextCtrl);
474
475 wxPropertyGrid* pg = property->GetGrid();
476 wxASSERT(pg); // Really, property grid should exist if editor does
477 if ( pg )
478 {
479 pg->SetupTextCtrlValue(txt);
480 tc->SetValue(txt);
481 }
482 }
483
484
485 void wxPGTextCtrlEditor_OnFocus( wxPGProperty* property,
486 wxTextCtrl* tc )
487 {
488 // Make sure there is correct text (instead of unspecified value
489 // indicator or hint text)
490 int flags = property->HasFlag(wxPG_PROP_READONLY) ?
491 0 : wxPG_EDITABLE_VALUE;
492 wxString correctText = property->GetValueAsString(flags);
493
494 if ( tc->GetValue() != correctText )
495 {
496 property->GetGrid()->SetupTextCtrlValue(correctText);
497 tc->SetValue(correctText);
498 }
499
500 tc->SetSelection(-1,-1);
501 }
502
503 void wxPGTextCtrlEditor::OnFocus( wxPGProperty* property,
504 wxWindow* wnd ) const
505 {
506 wxTextCtrl* tc = wxStaticCast(wnd, wxTextCtrl);
507 wxPGTextCtrlEditor_OnFocus(property, tc);
508 }
509
510 wxPGTextCtrlEditor::~wxPGTextCtrlEditor() { }
511
512
513 // -----------------------------------------------------------------------
514 // wxPGChoiceEditor
515 // -----------------------------------------------------------------------
516
517
518 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(Choice,wxPGChoiceEditor,wxPGEditor)
519
520
521 // This is a special enhanced double-click processor class.
522 // In essence, it allows for double-clicks for which the
523 // first click "created" the control.
524 class wxPGDoubleClickProcessor : public wxEvtHandler
525 {
526 public:
527
528 wxPGDoubleClickProcessor( wxOwnerDrawnComboBox* combo, wxPGProperty* property )
529 : wxEvtHandler()
530 {
531 m_timeLastMouseUp = 0;
532 m_combo = combo;
533 m_property = property;
534 m_downReceived = false;
535 }
536
537 protected:
538
539 void OnMouseEvent( wxMouseEvent& event )
540 {
541 wxLongLong t = ::wxGetLocalTimeMillis();
542 int evtType = event.GetEventType();
543
544 if ( m_property->HasFlag(wxPG_PROP_USE_DCC) &&
545 m_property->IsKindOf(CLASSINFO(wxBoolProperty)) &&
546 !m_combo->IsPopupShown() )
547 {
548 // Just check that it is in the text area
549 wxPoint pt = event.GetPosition();
550 if ( m_combo->GetTextRect().Contains(pt) )
551 {
552 if ( evtType == wxEVT_LEFT_DOWN )
553 {
554 // Set value to avoid up-events without corresponding downs
555 m_downReceived = true;
556 }
557 else if ( evtType == wxEVT_LEFT_DCLICK )
558 {
559 // We'll make our own double-clicks
560 event.SetEventType(0);
561 return;
562 }
563 else if ( evtType == wxEVT_LEFT_UP )
564 {
565 if ( m_downReceived || m_timeLastMouseUp == 1 )
566 {
567 wxLongLong timeFromLastUp = (t-m_timeLastMouseUp);
568
569 if ( timeFromLastUp < DOUBLE_CLICK_CONVERSION_TRESHOLD )
570 {
571 event.SetEventType(wxEVT_LEFT_DCLICK);
572 m_timeLastMouseUp = 1;
573 }
574 else
575 {
576 m_timeLastMouseUp = t;
577 }
578 }
579 }
580 }
581 }
582
583 event.Skip();
584 }
585
586 void OnSetFocus( wxFocusEvent& event )
587 {
588 m_timeLastMouseUp = ::wxGetLocalTimeMillis();
589 event.Skip();
590 }
591
592 private:
593 wxLongLong m_timeLastMouseUp;
594 wxOwnerDrawnComboBox* m_combo;
595 wxPGProperty* m_property; // Selected property
596 bool m_downReceived;
597
598 DECLARE_EVENT_TABLE()
599 };
600
601 BEGIN_EVENT_TABLE(wxPGDoubleClickProcessor, wxEvtHandler)
602 EVT_MOUSE_EVENTS(wxPGDoubleClickProcessor::OnMouseEvent)
603 EVT_SET_FOCUS(wxPGDoubleClickProcessor::OnSetFocus)
604 END_EVENT_TABLE()
605
606
607
608 class wxPGComboBox : public wxOwnerDrawnComboBox
609 {
610 public:
611
612 wxPGComboBox()
613 : wxOwnerDrawnComboBox()
614 {
615 m_dclickProcessor = NULL;
616 m_sizeEventCalled = false;
617 }
618
619 ~wxPGComboBox()
620 {
621 if ( m_dclickProcessor )
622 {
623 RemoveEventHandler(m_dclickProcessor);
624 delete m_dclickProcessor;
625 }
626 }
627
628 bool Create(wxWindow *parent,
629 wxWindowID id,
630 const wxString& value,
631 const wxPoint& pos,
632 const wxSize& size,
633 const wxArrayString& choices,
634 long style = 0,
635 const wxValidator& validator = wxDefaultValidator,
636 const wxString& name = wxS("wxOwnerDrawnComboBox"))
637 {
638 if ( !wxOwnerDrawnComboBox::Create( parent,
639 id,
640 value,
641 pos,
642 size,
643 choices,
644 style,
645 validator,
646 name ) )
647 return false;
648
649 m_dclickProcessor = new
650 wxPGDoubleClickProcessor( this, GetGrid()->GetSelection() );
651
652 PushEventHandler(m_dclickProcessor);
653
654 return true;
655 }
656
657 virtual void OnDrawItem( wxDC& dc,
658 const wxRect& rect,
659 int item,
660 int flags ) const
661 {
662 wxPropertyGrid* pg = GetGrid();
663
664 // Handle hint text via super class
665 if ( (flags & wxODCB_PAINTING_CONTROL) &&
666 ShouldUseHintText(flags) )
667 {
668 wxOwnerDrawnComboBox::OnDrawItem(dc, rect, item, flags);
669 }
670 else
671 {
672 pg->OnComboItemPaint( this, item, &dc, (wxRect&)rect, flags );
673 }
674 }
675
676 virtual wxCoord OnMeasureItem( size_t item ) const
677 {
678 wxPropertyGrid* pg = GetGrid();
679 wxRect rect;
680 rect.x = -1;
681 rect.width = 0;
682 pg->OnComboItemPaint( this, item, NULL, rect, 0 );
683 return rect.height;
684 }
685
686 wxPropertyGrid* GetGrid() const
687 {
688 wxPropertyGrid* pg = wxDynamicCast(GetParent(),
689 wxPropertyGrid);
690 wxASSERT(pg);
691 return pg;
692 }
693
694 virtual wxCoord OnMeasureItemWidth( size_t item ) const
695 {
696 wxPropertyGrid* pg = GetGrid();
697 wxRect rect;
698 rect.x = -1;
699 rect.width = -1;
700 pg->OnComboItemPaint( this, item, NULL, rect, 0 );
701 return rect.width;
702 }
703
704 virtual void PositionTextCtrl( int textCtrlXAdjust,
705 int WXUNUSED(textCtrlYAdjust) )
706 {
707 wxPropertyGrid* pg = GetGrid();
708 #ifdef wxPG_TEXTCTRLXADJUST
709 textCtrlXAdjust = wxPG_TEXTCTRLXADJUST -
710 (wxPG_XBEFOREWIDGET+wxPG_CONTROL_MARGIN+1) - 1,
711 #endif
712 wxOwnerDrawnComboBox::PositionTextCtrl(
713 textCtrlXAdjust,
714 pg->GetSpacingY() + 2
715 );
716 }
717
718 private:
719 wxPGDoubleClickProcessor* m_dclickProcessor;
720 bool m_sizeEventCalled;
721 };
722
723
724 void wxPropertyGrid::OnComboItemPaint( const wxPGComboBox* pCb,
725 int item,
726 wxDC* pDc,
727 wxRect& rect,
728 int flags )
729 {
730 // Sanity check
731 wxASSERT( IsKindOf(CLASSINFO(wxPropertyGrid)) );
732
733 wxPGProperty* p = GetSelection();
734 wxString text;
735
736 const wxPGChoices& choices = p->GetChoices();
737 const wxPGCommonValue* comVal = NULL;
738 int comVals = p->GetDisplayedCommonValueCount();
739 int comValIndex = -1;
740
741 int choiceCount = 0;
742 if ( choices.IsOk() )
743 choiceCount = choices.GetCount();
744
745 if ( item >= choiceCount && comVals > 0 )
746 {
747 comValIndex = item - choiceCount;
748 comVal = GetCommonValue(comValIndex);
749 if ( !p->IsValueUnspecified() )
750 text = comVal->GetLabel();
751 }
752 else
753 {
754 if ( !(flags & wxODCB_PAINTING_CONTROL) )
755 {
756 text = pCb->GetString(item);
757 }
758 else
759 {
760 if ( !p->IsValueUnspecified() )
761 text = p->GetValueAsString(0);
762 }
763 }
764
765 if ( item < 0 )
766 return;
767
768 wxSize cis;
769
770 const wxBitmap* itemBitmap = NULL;
771
772 if ( item >= 0 && choices.IsOk() && choices.Item(item).GetBitmap().Ok() && comValIndex == -1 )
773 itemBitmap = &choices.Item(item).GetBitmap();
774
775 //
776 // Decide what custom image size to use
777 if ( itemBitmap )
778 {
779 cis.x = itemBitmap->GetWidth();
780 cis.y = itemBitmap->GetHeight();
781 }
782 else
783 {
784 cis = GetImageSize(p, item);
785 }
786
787 if ( rect.x < 0 )
788 {
789 // Default measure behaviour (no flexible, custom paint image only)
790 if ( rect.width < 0 )
791 {
792 wxCoord x, y;
793 pCb->GetTextExtent(text, &x, &y, 0, 0);
794 rect.width = cis.x + wxCC_CUSTOM_IMAGE_MARGIN1 + wxCC_CUSTOM_IMAGE_MARGIN2 + 9 + x;
795 }
796
797 rect.height = cis.y + 2;
798 return;
799 }
800
801 wxPGPaintData paintdata;
802 paintdata.m_parent = NULL;
803 paintdata.m_choiceItem = item;
804
805 // This is by the current (1.0.0b) spec - if painting control, item is -1
806 if ( (flags & wxODCB_PAINTING_CONTROL) )
807 paintdata.m_choiceItem = -1;
808
809 if ( pDc )
810 pDc->SetBrush(*wxWHITE_BRUSH);
811
812 wxPGCellRenderer* renderer = NULL;
813 const wxPGChoiceEntry* cell = NULL;
814
815 if ( rect.x >= 0 )
816 {
817 //
818 // DrawItem call
819 wxDC& dc = *pDc;
820
821 wxPoint pt(rect.x + wxPG_CONTROL_MARGIN - wxPG_CHOICEXADJUST - 1,
822 rect.y + 1);
823
824 int renderFlags = wxPGCellRenderer::DontUseCellColours;
825 bool useCustomPaintProcedure;
826
827 // If custom image had some size, we will start from the assumption
828 // that custom paint procedure is required
829 if ( cis.x > 0 )
830 useCustomPaintProcedure = true;
831 else
832 useCustomPaintProcedure = false;
833
834 if ( flags & wxODCB_PAINTING_SELECTED )
835 renderFlags |= wxPGCellRenderer::Selected;
836
837 if ( flags & wxODCB_PAINTING_CONTROL )
838 {
839 renderFlags |= wxPGCellRenderer::Control;
840
841 // If wxPG_PROP_CUSTOMIMAGE was set, then that means any custom
842 // image will not appear on the control row (it may be too
843 // large to fit, for instance). Also do not draw custom image
844 // if no choice was selected.
845 if ( !p->HasFlag(wxPG_PROP_CUSTOMIMAGE) || item < 0 )
846 useCustomPaintProcedure = false;
847 }
848 else
849 {
850 renderFlags |= wxPGCellRenderer::ChoicePopup;
851
852 // For consistency, always use normal font when drawing drop down
853 // items
854 dc.SetFont(GetFont());
855 }
856
857 // If not drawing a selected popup item, then give property's
858 // m_valueBitmap a chance.
859 if ( p->m_valueBitmap && item != pCb->GetSelection() )
860 useCustomPaintProcedure = false;
861 // If current choice had a bitmap set by the application, then
862 // use it instead of any custom paint procedure.
863 else if ( itemBitmap )
864 useCustomPaintProcedure = false;
865
866 if ( useCustomPaintProcedure )
867 {
868 pt.x += wxCC_CUSTOM_IMAGE_MARGIN1;
869 wxRect r(pt.x,pt.y,cis.x,cis.y);
870
871 if ( flags & wxODCB_PAINTING_CONTROL )
872 {
873 //r.width = cis.x;
874 r.height = wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight);
875 }
876
877 paintdata.m_drawnWidth = r.width;
878
879 dc.SetPen(m_colPropFore);
880 if ( comValIndex >= 0 )
881 {
882 const wxPGCommonValue* cv = GetCommonValue(comValIndex);
883 wxPGCellRenderer* renderer = cv->GetRenderer();
884 r.width = rect.width;
885 renderer->Render( dc, r, this, p, m_selColumn, comValIndex, renderFlags );
886 return;
887 }
888 else if ( item >= 0 )
889 {
890 p->OnCustomPaint( dc, r, paintdata );
891 }
892 else
893 {
894 dc.DrawRectangle( r );
895 }
896
897 pt.x += paintdata.m_drawnWidth + wxCC_CUSTOM_IMAGE_MARGIN2 - 1;
898 }
899 else
900 {
901 // TODO: This aligns text so that it seems to be horizontally
902 // on the same line as property values. Not really
903 // sure if its needed, but seems to not cause any harm.
904 pt.x -= 1;
905
906 if ( item < 0 && (flags & wxODCB_PAINTING_CONTROL) )
907 item = pCb->GetSelection();
908
909 if ( choices.IsOk() && item >= 0 && comValIndex < 0 )
910 {
911 cell = &choices.Item(item);
912 renderer = wxPGGlobalVars->m_defaultRenderer;
913 int imageOffset = renderer->PreDrawCell(dc, rect, *cell,
914 renderFlags );
915 if ( imageOffset )
916 imageOffset += wxCC_CUSTOM_IMAGE_MARGIN1 +
917 wxCC_CUSTOM_IMAGE_MARGIN2;
918 pt.x += imageOffset;
919 }
920 }
921
922 //
923 // Draw text
924 //
925
926 pt.y += (rect.height-m_fontHeight)/2 - 1;
927
928 pt.x += 1;
929
930 dc.DrawText( text, pt.x + wxPG_XBEFORETEXT, pt.y );
931
932 if ( renderer )
933 renderer->PostDrawCell(dc, this, *cell, renderFlags);
934 }
935 else
936 {
937 //
938 // MeasureItem call
939 wxDC& dc = *pDc;
940
941 p->OnCustomPaint( dc, rect, paintdata );
942 rect.height = paintdata.m_drawnHeight + 2;
943 rect.width = cis.x + wxCC_CUSTOM_IMAGE_MARGIN1 + wxCC_CUSTOM_IMAGE_MARGIN2 + 9;
944 }
945 }
946
947 bool wxPGChoiceEditor_SetCustomPaintWidth( wxPropertyGrid* propGrid, wxPGComboBox* cb, int cmnVal )
948 {
949 wxPGProperty* property = propGrid->GetSelectedProperty();
950 wxASSERT( property );
951
952 wxSize imageSize;
953 bool res;
954
955 // TODO: Do this always when cell has custom text.
956 if ( property->IsValueUnspecified() )
957 {
958 cb->SetCustomPaintWidth( 0 );
959 return true;
960 }
961
962 if ( cmnVal >= 0 )
963 {
964 // Yes, a common value is being selected
965 property->SetCommonValue( cmnVal );
966 imageSize = propGrid->GetCommonValue(cmnVal)->
967 GetRenderer()->GetImageSize(property, 1, cmnVal);
968 res = false;
969 }
970 else
971 {
972 imageSize = propGrid->GetImageSize(property, -1);
973 res = true;
974 }
975
976 if ( imageSize.x )
977 imageSize.x += ODCB_CUST_PAINT_MARGIN;
978 cb->SetCustomPaintWidth( imageSize.x );
979
980 return res;
981 }
982
983 // CreateControls calls this with CB_READONLY in extraStyle
984 wxWindow* wxPGChoiceEditor::CreateControlsBase( wxPropertyGrid* propGrid,
985 wxPGProperty* property,
986 const wxPoint& pos,
987 const wxSize& sz,
988 long extraStyle ) const
989 {
990 // Since it is not possible (yet) to create a read-only combo box in
991 // the same sense that wxTextCtrl is read-only, simply do not create
992 // the control in this case.
993 if ( property->HasFlag(wxPG_PROP_READONLY) )
994 return NULL;
995
996 const wxPGChoices& choices = property->GetChoices();
997 wxString defString;
998 int index = property->GetChoiceSelection();
999
1000 int argFlags = 0;
1001 if ( !property->HasFlag(wxPG_PROP_READONLY) &&
1002 !property->IsValueUnspecified() )
1003 argFlags |= wxPG_EDITABLE_VALUE;
1004 defString = property->GetValueAsString(argFlags);
1005
1006 wxArrayString labels = choices.GetLabels();
1007
1008 wxPGComboBox* cb;
1009
1010 wxPoint po(pos);
1011 wxSize si(sz);
1012 po.y += wxPG_CHOICEYADJUST;
1013 si.y -= (wxPG_CHOICEYADJUST*2);
1014
1015 po.x += wxPG_CHOICEXADJUST;
1016 si.x -= wxPG_CHOICEXADJUST;
1017 wxWindow* ctrlParent = propGrid->GetPanel();
1018
1019 int odcbFlags = extraStyle | wxBORDER_NONE | wxTE_PROCESS_ENTER;
1020
1021 if ( (property->GetFlags() & wxPG_PROP_USE_DCC) &&
1022 (property->IsKindOf(CLASSINFO(wxBoolProperty)) ) )
1023 odcbFlags |= wxODCB_DCLICK_CYCLES;
1024
1025 //
1026 // If common value specified, use appropriate index
1027 unsigned int cmnVals = property->GetDisplayedCommonValueCount();
1028 if ( cmnVals )
1029 {
1030 if ( !property->IsValueUnspecified() )
1031 {
1032 int cmnVal = property->GetCommonValue();
1033 if ( cmnVal >= 0 )
1034 {
1035 index = labels.size() + cmnVal;
1036 }
1037 }
1038
1039 unsigned int i;
1040 for ( i=0; i<cmnVals; i++ )
1041 labels.Add(propGrid->GetCommonValueLabel(i));
1042 }
1043
1044 cb = new wxPGComboBox();
1045 #ifdef __WXMSW__
1046 cb->Hide();
1047 #endif
1048 cb->Create(ctrlParent,
1049 wxPG_SUBID1,
1050 wxString(),
1051 po,
1052 si,
1053 labels,
1054 odcbFlags);
1055
1056 cb->SetButtonPosition(si.y,0,wxRIGHT);
1057 cb->SetMargins(wxPG_XBEFORETEXT-1);
1058
1059 // Set hint text
1060 cb->SetHint(property->GetHintText());
1061
1062 wxPGChoiceEditor_SetCustomPaintWidth( propGrid, cb,
1063 property->GetCommonValue() );
1064
1065 if ( index >= 0 && index < (int)cb->GetCount() )
1066 {
1067 cb->SetSelection( index );
1068 if ( defString.length() )
1069 cb->SetText( defString );
1070 }
1071 else if ( !(extraStyle & wxCB_READONLY) && defString.length() )
1072 {
1073 propGrid->SetupTextCtrlValue(defString);
1074 cb->SetValue( defString );
1075 }
1076 else
1077 {
1078 cb->SetSelection( -1 );
1079 }
1080
1081 #ifdef __WXMSW__
1082 cb->Show();
1083 #endif
1084
1085 return (wxWindow*) cb;
1086 }
1087
1088
1089 void wxPGChoiceEditor::UpdateControl( wxPGProperty* property, wxWindow* ctrl ) const
1090 {
1091 wxASSERT( ctrl );
1092 wxOwnerDrawnComboBox* cb = (wxOwnerDrawnComboBox*)ctrl;
1093 wxASSERT( cb->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox)));
1094 int ind = property->GetChoiceSelection();
1095 cb->SetSelection(ind);
1096 }
1097
1098 wxPGWindowList wxPGChoiceEditor::CreateControls( wxPropertyGrid* propGrid, wxPGProperty* property,
1099 const wxPoint& pos, const wxSize& sz ) const
1100 {
1101 return CreateControlsBase(propGrid,property,pos,sz,wxCB_READONLY);
1102 }
1103
1104
1105 int wxPGChoiceEditor::InsertItem( wxWindow* ctrl, const wxString& label, int index ) const
1106 {
1107 wxASSERT( ctrl );
1108 wxOwnerDrawnComboBox* cb = (wxOwnerDrawnComboBox*)ctrl;
1109 wxASSERT( cb->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox)));
1110
1111 if (index < 0)
1112 index = cb->GetCount();
1113
1114 return cb->Insert(label,index);
1115 }
1116
1117
1118 void wxPGChoiceEditor::DeleteItem( wxWindow* ctrl, int index ) const
1119 {
1120 wxASSERT( ctrl );
1121 wxOwnerDrawnComboBox* cb = (wxOwnerDrawnComboBox*)ctrl;
1122 wxASSERT( cb->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox)));
1123
1124 cb->Delete(index);
1125 }
1126
1127 bool wxPGChoiceEditor::OnEvent( wxPropertyGrid* propGrid, wxPGProperty* property,
1128 wxWindow* ctrl, wxEvent& event ) const
1129 {
1130 if ( event.GetEventType() == wxEVT_COMMAND_COMBOBOX_SELECTED )
1131 {
1132 wxPGComboBox* cb = (wxPGComboBox*)ctrl;
1133 int index = cb->GetSelection();
1134 int cmnValIndex = -1;
1135 int cmnVals = property->GetDisplayedCommonValueCount();
1136 int items = cb->GetCount();
1137
1138 if ( index >= (items-cmnVals) )
1139 {
1140 // Yes, a common value is being selected
1141 cmnValIndex = index - (items-cmnVals);
1142 property->SetCommonValue( cmnValIndex );
1143
1144 // Truly set value to unspecified?
1145 if ( propGrid->GetUnspecifiedCommonValue() == cmnValIndex )
1146 {
1147 if ( !property->IsValueUnspecified() )
1148 propGrid->SetInternalFlag(wxPG_FL_VALUE_CHANGE_IN_EVENT);
1149 property->SetValueToUnspecified();
1150 if ( !cb->HasFlag(wxCB_READONLY) )
1151 {
1152 wxString unspecValueText;
1153 unspecValueText = propGrid->GetUnspecifiedValueText();
1154 propGrid->SetupTextCtrlValue(unspecValueText);
1155 cb->GetTextCtrl()->SetValue(unspecValueText);
1156 }
1157 return false;
1158 }
1159 }
1160 return wxPGChoiceEditor_SetCustomPaintWidth( propGrid, cb, cmnValIndex );
1161 }
1162 return false;
1163 }
1164
1165
1166 bool wxPGChoiceEditor::GetValueFromControl( wxVariant& variant, wxPGProperty* property, wxWindow* ctrl ) const
1167 {
1168 wxOwnerDrawnComboBox* cb = (wxOwnerDrawnComboBox*)ctrl;
1169
1170 int index = cb->GetSelection();
1171
1172 if ( index != property->GetChoiceSelection() ||
1173 // Changing unspecified always causes event (returning
1174 // true here should be enough to trigger it).
1175 property->IsValueUnspecified()
1176 )
1177 {
1178 return property->IntToValue( variant, index, 0 );
1179 }
1180 return false;
1181 }
1182
1183
1184 void wxPGChoiceEditor::SetControlStringValue( wxPGProperty* property,
1185 wxWindow* ctrl,
1186 const wxString& txt ) const
1187 {
1188 wxOwnerDrawnComboBox* cb = (wxOwnerDrawnComboBox*)ctrl;
1189 wxASSERT( cb );
1190 property->GetGrid()->SetupTextCtrlValue(txt);
1191 cb->SetValue(txt);
1192 }
1193
1194
1195 void wxPGChoiceEditor::SetControlIntValue( wxPGProperty* WXUNUSED(property), wxWindow* ctrl, int value ) const
1196 {
1197 wxOwnerDrawnComboBox* cb = (wxOwnerDrawnComboBox*)ctrl;
1198 wxASSERT( cb );
1199 cb->SetSelection(value);
1200 }
1201
1202
1203 void wxPGChoiceEditor::SetValueToUnspecified( wxPGProperty* WXUNUSED(property),
1204 wxWindow* ctrl ) const
1205 {
1206 wxOwnerDrawnComboBox* cb = (wxOwnerDrawnComboBox*)ctrl;
1207
1208 if ( cb->HasFlag(wxCB_READONLY) )
1209 cb->SetSelection(-1);
1210 }
1211
1212
1213 bool wxPGChoiceEditor::CanContainCustomImage() const
1214 {
1215 return true;
1216 }
1217
1218
1219 wxPGChoiceEditor::~wxPGChoiceEditor() { }
1220
1221
1222 // -----------------------------------------------------------------------
1223 // wxPGComboBoxEditor
1224 // -----------------------------------------------------------------------
1225
1226
1227 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(ComboBox,
1228 wxPGComboBoxEditor,
1229 wxPGChoiceEditor)
1230
1231
1232 void wxPGComboBoxEditor::UpdateControl( wxPGProperty* property, wxWindow* ctrl ) const
1233 {
1234 wxOwnerDrawnComboBox* cb = (wxOwnerDrawnComboBox*)ctrl;
1235 wxString s = property->GetValueAsString(wxPG_EDITABLE_VALUE);
1236 property->GetGrid()->SetupTextCtrlValue(s);
1237 cb->SetValue(s);
1238
1239 // TODO: If string matches any selection, then select that.
1240 }
1241
1242
1243 wxPGWindowList wxPGComboBoxEditor::CreateControls( wxPropertyGrid* propGrid,
1244 wxPGProperty* property,
1245 const wxPoint& pos,
1246 const wxSize& sz ) const
1247 {
1248 return CreateControlsBase(propGrid,property,pos,sz,0);
1249 }
1250
1251
1252 bool wxPGComboBoxEditor::OnEvent( wxPropertyGrid* propGrid,
1253 wxPGProperty* property,
1254 wxWindow* ctrl,
1255 wxEvent& event ) const
1256 {
1257 wxOwnerDrawnComboBox* cb = NULL;
1258 wxWindow* textCtrl = NULL;
1259
1260 if ( ctrl )
1261 {
1262 cb = (wxOwnerDrawnComboBox*)ctrl;
1263 textCtrl = cb->GetTextCtrl();
1264 }
1265
1266 if ( wxPGTextCtrlEditor::OnTextCtrlEvent(propGrid,property,textCtrl,event) )
1267 return true;
1268
1269 return wxPGChoiceEditor::OnEvent(propGrid,property,ctrl,event);
1270 }
1271
1272
1273 bool wxPGComboBoxEditor::GetValueFromControl( wxVariant& variant, wxPGProperty* property, wxWindow* ctrl ) const
1274 {
1275 wxOwnerDrawnComboBox* cb = (wxOwnerDrawnComboBox*)ctrl;
1276 wxString textVal = cb->GetValue();
1277
1278 if ( property->UsesAutoUnspecified() && !textVal.length() )
1279 {
1280 variant.MakeNull();
1281 return true;
1282 }
1283
1284 bool res = property->StringToValue(variant, textVal, wxPG_EDITABLE_VALUE);
1285
1286 // Changing unspecified always causes event (returning
1287 // true here should be enough to trigger it).
1288 if ( !res && variant.IsNull() )
1289 res = true;
1290
1291 return res;
1292 }
1293
1294
1295 void wxPGComboBoxEditor::OnFocus( wxPGProperty* property,
1296 wxWindow* ctrl ) const
1297 {
1298 wxOwnerDrawnComboBox* cb = (wxOwnerDrawnComboBox*)ctrl;
1299 wxPGTextCtrlEditor_OnFocus(property, cb->GetTextCtrl());
1300 }
1301
1302
1303 wxPGComboBoxEditor::~wxPGComboBoxEditor() { }
1304
1305
1306 // -----------------------------------------------------------------------
1307 // wxPGChoiceAndButtonEditor
1308 // -----------------------------------------------------------------------
1309
1310
1311 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(ChoiceAndButton,
1312 wxPGChoiceAndButtonEditor,
1313 wxPGChoiceEditor)
1314
1315
1316 wxPGWindowList wxPGChoiceAndButtonEditor::CreateControls( wxPropertyGrid* propGrid,
1317 wxPGProperty* property,
1318 const wxPoint& pos,
1319 const wxSize& sz ) const
1320 {
1321 // Use one two units smaller to match size of the combo's dropbutton.
1322 // (normally a bigger button is used because it looks better)
1323 int bt_wid = sz.y;
1324 bt_wid -= 2;
1325 wxSize bt_sz(bt_wid,bt_wid);
1326
1327 // Position of button.
1328 wxPoint bt_pos(pos.x+sz.x-bt_sz.x,pos.y);
1329 #ifdef __WXMAC__
1330 bt_pos.y -= 1;
1331 #else
1332 bt_pos.y += 1;
1333 #endif
1334
1335 wxWindow* bt = propGrid->GenerateEditorButton( bt_pos, bt_sz );
1336
1337 // Size of choice.
1338 wxSize ch_sz(sz.x-bt->GetSize().x,sz.y);
1339
1340 #ifdef __WXMAC__
1341 ch_sz.x -= wxPG_TEXTCTRL_AND_BUTTON_SPACING;
1342 #endif
1343
1344 wxWindow* ch = wxPGEditor_Choice->CreateControls(propGrid,property,
1345 pos,ch_sz).m_primary;
1346
1347 #ifdef __WXMSW__
1348 bt->Show();
1349 #endif
1350
1351 return wxPGWindowList(ch, bt);
1352 }
1353
1354
1355 wxPGChoiceAndButtonEditor::~wxPGChoiceAndButtonEditor() { }
1356
1357
1358 // -----------------------------------------------------------------------
1359 // wxPGTextCtrlAndButtonEditor
1360 // -----------------------------------------------------------------------
1361
1362 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(TextCtrlAndButton,
1363 wxPGTextCtrlAndButtonEditor,
1364 wxPGTextCtrlEditor)
1365
1366
1367 wxPGWindowList wxPGTextCtrlAndButtonEditor::CreateControls( wxPropertyGrid* propGrid,
1368 wxPGProperty* property,
1369 const wxPoint& pos,
1370 const wxSize& sz ) const
1371 {
1372 wxWindow* wnd2;
1373 wxWindow* wnd = propGrid->GenerateEditorTextCtrlAndButton( pos, sz, &wnd2,
1374 property->GetFlags() & wxPG_PROP_NOEDITOR, property);
1375
1376 return wxPGWindowList(wnd, wnd2);
1377 }
1378
1379
1380 wxPGTextCtrlAndButtonEditor::~wxPGTextCtrlAndButtonEditor() { }
1381
1382
1383 // -----------------------------------------------------------------------
1384 // wxPGCheckBoxEditor
1385 // -----------------------------------------------------------------------
1386
1387 #if wxPG_INCLUDE_CHECKBOX
1388
1389 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(CheckBox,
1390 wxPGCheckBoxEditor,
1391 wxPGEditor)
1392
1393
1394 // Check box state flags
1395 enum
1396 {
1397 wxSCB_STATE_UNCHECKED = 0,
1398 wxSCB_STATE_CHECKED = 1,
1399 wxSCB_STATE_BOLD = 2,
1400 wxSCB_STATE_UNSPECIFIED = 4
1401 };
1402
1403 const int wxSCB_SETVALUE_CYCLE = 2;
1404
1405
1406 static void DrawSimpleCheckBox( wxDC& dc, const wxRect& rect, int box_hei,
1407 int state )
1408 {
1409 // Box rectangle.
1410 wxRect r(rect.x+wxPG_XBEFORETEXT,rect.y+((rect.height-box_hei)/2),
1411 box_hei,box_hei);
1412 wxColour useCol = dc.GetTextForeground();
1413
1414 if ( state & wxSCB_STATE_UNSPECIFIED )
1415 {
1416 useCol = wxColour(220, 220, 220);
1417 }
1418
1419 // Draw check mark first because it is likely to overdraw the
1420 // surrounding rectangle.
1421 if ( state & wxSCB_STATE_CHECKED )
1422 {
1423 wxRect r2(r.x+wxPG_CHECKMARK_XADJ,
1424 r.y+wxPG_CHECKMARK_YADJ,
1425 r.width+wxPG_CHECKMARK_WADJ,
1426 r.height+wxPG_CHECKMARK_HADJ);
1427 #if wxPG_CHECKMARK_DEFLATE
1428 r2.Deflate(wxPG_CHECKMARK_DEFLATE);
1429 #endif
1430 dc.DrawCheckMark(r2);
1431
1432 // This would draw a simple cross check mark.
1433 // dc.DrawLine(r.x,r.y,r.x+r.width-1,r.y+r.height-1);
1434 // dc.DrawLine(r.x,r.y+r.height-1,r.x+r.width-1,r.y);
1435 }
1436
1437 if ( !(state & wxSCB_STATE_BOLD) )
1438 {
1439 // Pen for thin rectangle.
1440 dc.SetPen(useCol);
1441 }
1442 else
1443 {
1444 // Pen for bold rectangle.
1445 wxPen linepen(useCol,2,wxSOLID);
1446 linepen.SetJoin(wxJOIN_MITER); // This prevents round edges.
1447 dc.SetPen(linepen);
1448 r.x++;
1449 r.y++;
1450 r.width--;
1451 r.height--;
1452 }
1453
1454 dc.SetBrush(*wxTRANSPARENT_BRUSH);
1455
1456 dc.DrawRectangle(r);
1457 dc.SetPen(*wxTRANSPARENT_PEN);
1458 }
1459
1460 //
1461 // Real simple custom-drawn checkbox-without-label class.
1462 //
1463 class wxSimpleCheckBox : public wxControl
1464 {
1465 public:
1466
1467 void SetValue( int value );
1468
1469 wxSimpleCheckBox( wxWindow* parent,
1470 wxWindowID id,
1471 const wxPoint& pos = wxDefaultPosition,
1472 const wxSize& size = wxDefaultSize )
1473 : wxControl(parent,id,pos,size,wxBORDER_NONE|wxWANTS_CHARS)
1474 {
1475 // Due to SetOwnFont stuff necessary for GTK+ 1.2, we need to have this
1476 SetFont( parent->GetFont() );
1477
1478 m_state = 0;
1479 m_boxHeight = 12;
1480
1481 SetBackgroundStyle( wxBG_STYLE_CUSTOM );
1482 }
1483
1484 virtual ~wxSimpleCheckBox();
1485
1486 int m_state;
1487 int m_boxHeight;
1488
1489 private:
1490 void OnPaint( wxPaintEvent& event );
1491 void OnLeftClick( wxMouseEvent& event );
1492 void OnKeyDown( wxKeyEvent& event );
1493
1494 void OnResize( wxSizeEvent& event )
1495 {
1496 Refresh();
1497 event.Skip();
1498 }
1499
1500 static wxBitmap* ms_doubleBuffer;
1501
1502 DECLARE_EVENT_TABLE()
1503 };
1504
1505 BEGIN_EVENT_TABLE(wxSimpleCheckBox, wxControl)
1506 EVT_PAINT(wxSimpleCheckBox::OnPaint)
1507 EVT_LEFT_DOWN(wxSimpleCheckBox::OnLeftClick)
1508 EVT_LEFT_DCLICK(wxSimpleCheckBox::OnLeftClick)
1509 EVT_KEY_DOWN(wxSimpleCheckBox::OnKeyDown)
1510 EVT_SIZE(wxSimpleCheckBox::OnResize)
1511 END_EVENT_TABLE()
1512
1513 wxSimpleCheckBox::~wxSimpleCheckBox()
1514 {
1515 delete ms_doubleBuffer;
1516 ms_doubleBuffer = NULL;
1517 }
1518
1519 wxBitmap* wxSimpleCheckBox::ms_doubleBuffer = NULL;
1520
1521 void wxSimpleCheckBox::OnPaint( wxPaintEvent& WXUNUSED(event) )
1522 {
1523 wxSize clientSize = GetClientSize();
1524 wxAutoBufferedPaintDC dc(this);
1525
1526 dc.Clear();
1527 wxRect rect(0,0,clientSize.x,clientSize.y);
1528 rect.y += 1;
1529 rect.width += 1;
1530
1531 wxColour bgcol = GetBackgroundColour();
1532 dc.SetBrush( bgcol );
1533 dc.SetPen( bgcol );
1534 dc.DrawRectangle( rect );
1535
1536 dc.SetTextForeground(GetForegroundColour());
1537
1538 int state = m_state;
1539 if ( !(state & wxSCB_STATE_UNSPECIFIED) &&
1540 GetFont().GetWeight() == wxBOLD )
1541 state |= wxSCB_STATE_BOLD;
1542
1543 DrawSimpleCheckBox(dc, rect, m_boxHeight, state);
1544 }
1545
1546 void wxSimpleCheckBox::OnLeftClick( wxMouseEvent& event )
1547 {
1548 if ( (event.m_x > (wxPG_XBEFORETEXT-2)) &&
1549 (event.m_x <= (wxPG_XBEFORETEXT-2+m_boxHeight)) )
1550 {
1551 SetValue(wxSCB_SETVALUE_CYCLE);
1552 }
1553 }
1554
1555 void wxSimpleCheckBox::OnKeyDown( wxKeyEvent& event )
1556 {
1557 if ( event.GetKeyCode() == WXK_SPACE )
1558 {
1559 SetValue(wxSCB_SETVALUE_CYCLE);
1560 }
1561 }
1562
1563 void wxSimpleCheckBox::SetValue( int value )
1564 {
1565 if ( value == wxSCB_SETVALUE_CYCLE )
1566 {
1567 if ( m_state & wxSCB_STATE_CHECKED )
1568 m_state &= ~wxSCB_STATE_CHECKED;
1569 else
1570 m_state |= wxSCB_STATE_CHECKED;
1571 }
1572 else
1573 {
1574 m_state = value;
1575 }
1576 Refresh();
1577
1578 wxCommandEvent evt(wxEVT_COMMAND_CHECKBOX_CLICKED,GetParent()->GetId());
1579
1580 wxPropertyGrid* propGrid = (wxPropertyGrid*) GetParent();
1581 wxASSERT( propGrid->IsKindOf(CLASSINFO(wxPropertyGrid)) );
1582 propGrid->HandleCustomEditorEvent(evt);
1583 }
1584
1585 wxPGWindowList wxPGCheckBoxEditor::CreateControls( wxPropertyGrid* propGrid,
1586 wxPGProperty* property,
1587 const wxPoint& pos,
1588 const wxSize& size ) const
1589 {
1590 if ( property->HasFlag(wxPG_PROP_READONLY) )
1591 return NULL;
1592
1593 wxPoint pt = pos;
1594 pt.x -= wxPG_XBEFOREWIDGET;
1595 wxSize sz = size;
1596 sz.x = propGrid->GetFontHeight() + (wxPG_XBEFOREWIDGET*2) + 4;
1597
1598 wxSimpleCheckBox* cb = new wxSimpleCheckBox(propGrid->GetPanel(),
1599 wxPG_SUBID1, pt, sz);
1600
1601 cb->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
1602
1603 UpdateControl(property, cb);
1604
1605 if ( !property->IsValueUnspecified() )
1606 {
1607 // If mouse cursor was on the item, toggle the value now.
1608 if ( propGrid->GetInternalFlags() & wxPG_FL_ACTIVATION_BY_CLICK )
1609 {
1610 wxPoint pt = cb->ScreenToClient(::wxGetMousePosition());
1611 if ( pt.x <= (wxPG_XBEFORETEXT-2+cb->m_boxHeight) )
1612 {
1613 if ( cb->m_state & wxSCB_STATE_CHECKED )
1614 cb->m_state &= ~wxSCB_STATE_CHECKED;
1615 else
1616 cb->m_state |= wxSCB_STATE_CHECKED;
1617
1618 // Makes sure wxPG_EVT_CHANGING etc. is sent for this initial
1619 // click
1620 propGrid->ChangePropertyValue(property,
1621 wxPGVariant_Bool(cb->m_state));
1622 }
1623 }
1624 }
1625
1626 propGrid->SetInternalFlag( wxPG_FL_FIXED_WIDTH_EDITOR );
1627
1628 return cb;
1629 }
1630
1631 void wxPGCheckBoxEditor::DrawValue( wxDC& dc, const wxRect& rect,
1632 wxPGProperty* property,
1633 const wxString& WXUNUSED(text) ) const
1634 {
1635 int state = wxSCB_STATE_UNCHECKED;
1636
1637 if ( !property->IsValueUnspecified() )
1638 {
1639 state = property->GetChoiceSelection();
1640 if ( dc.GetFont().GetWeight() == wxBOLD )
1641 state |= wxSCB_STATE_BOLD;
1642 }
1643 else
1644 {
1645 state |= wxSCB_STATE_UNSPECIFIED;
1646 }
1647
1648 DrawSimpleCheckBox(dc, rect, dc.GetCharHeight(), state);
1649 }
1650
1651 void wxPGCheckBoxEditor::UpdateControl( wxPGProperty* property,
1652 wxWindow* ctrl ) const
1653 {
1654 wxSimpleCheckBox* cb = (wxSimpleCheckBox*) ctrl;
1655 wxASSERT( cb );
1656
1657 if ( !property->IsValueUnspecified() )
1658 cb->m_state = property->GetChoiceSelection();
1659 else
1660 cb->m_state = wxSCB_STATE_UNSPECIFIED;
1661
1662 wxPropertyGrid* propGrid = property->GetGrid();
1663 cb->m_boxHeight = propGrid->GetFontHeight();
1664
1665 cb->Refresh();
1666 }
1667
1668 bool wxPGCheckBoxEditor::OnEvent( wxPropertyGrid* WXUNUSED(propGrid), wxPGProperty* WXUNUSED(property),
1669 wxWindow* WXUNUSED(ctrl), wxEvent& event ) const
1670 {
1671 if ( event.GetEventType() == wxEVT_COMMAND_CHECKBOX_CLICKED )
1672 {
1673 return true;
1674 }
1675 return false;
1676 }
1677
1678
1679 bool wxPGCheckBoxEditor::GetValueFromControl( wxVariant& variant, wxPGProperty* property, wxWindow* ctrl ) const
1680 {
1681 wxSimpleCheckBox* cb = (wxSimpleCheckBox*)ctrl;
1682
1683 int index = cb->m_state;
1684
1685 if ( index != property->GetChoiceSelection() ||
1686 // Changing unspecified always causes event (returning
1687 // true here should be enough to trigger it).
1688 property->IsValueUnspecified()
1689 )
1690 {
1691 return property->IntToValue(variant, index, 0);
1692 }
1693 return false;
1694 }
1695
1696
1697 void wxPGCheckBoxEditor::SetControlIntValue( wxPGProperty* WXUNUSED(property), wxWindow* ctrl, int value ) const
1698 {
1699 if ( value != 0 ) value = 1;
1700 ((wxSimpleCheckBox*)ctrl)->m_state = value;
1701 ctrl->Refresh();
1702 }
1703
1704
1705 void wxPGCheckBoxEditor::SetValueToUnspecified( wxPGProperty* WXUNUSED(property), wxWindow* ctrl ) const
1706 {
1707 ((wxSimpleCheckBox*)ctrl)->m_state = wxSCB_STATE_UNSPECIFIED;
1708 ctrl->Refresh();
1709 }
1710
1711
1712 wxPGCheckBoxEditor::~wxPGCheckBoxEditor() { }
1713
1714
1715 #endif // wxPG_INCLUDE_CHECKBOX
1716
1717 // -----------------------------------------------------------------------
1718
1719 wxWindow* wxPropertyGrid::GetEditorControl() const
1720 {
1721 wxWindow* ctrl = m_wndEditor;
1722
1723 if ( !ctrl )
1724 return ctrl;
1725
1726 return ctrl;
1727 }
1728
1729 // -----------------------------------------------------------------------
1730
1731 void wxPropertyGrid::CorrectEditorWidgetSizeX()
1732 {
1733 int secWid = 0;
1734
1735 // Use fixed selColumn 1 for main editor widgets
1736 int newSplitterx = m_pState->DoGetSplitterPosition(0);
1737 int newWidth = newSplitterx + m_pState->m_colWidths[1];
1738
1739 if ( m_wndEditor2 )
1740 {
1741 // if width change occurred, move secondary wnd by that amount
1742 wxRect r = m_wndEditor2->GetRect();
1743 secWid = r.width;
1744 r.x = newWidth - secWid;
1745
1746 m_wndEditor2->SetSize( r );
1747
1748 // if primary is textctrl, then we have to add some extra space
1749 #ifdef __WXMAC__
1750 if ( m_wndEditor )
1751 #else
1752 if ( m_wndEditor && m_wndEditor->IsKindOf(CLASSINFO(wxTextCtrl)) )
1753 #endif
1754 secWid += wxPG_TEXTCTRL_AND_BUTTON_SPACING;
1755 }
1756
1757 if ( m_wndEditor )
1758 {
1759 wxRect r = m_wndEditor->GetRect();
1760
1761 r.x = newSplitterx+m_ctrlXAdjust;
1762
1763 if ( !(m_iFlags & wxPG_FL_FIXED_WIDTH_EDITOR) )
1764 r.width = newWidth - r.x - secWid;
1765
1766 m_wndEditor->SetSize(r);
1767 }
1768
1769 if ( m_wndEditor2 )
1770 m_wndEditor2->Refresh();
1771 }
1772
1773 // -----------------------------------------------------------------------
1774
1775 void wxPropertyGrid::CorrectEditorWidgetPosY()
1776 {
1777 wxPGProperty* selected = GetSelection();
1778
1779 if ( selected )
1780 {
1781 if ( m_labelEditor )
1782 {
1783 wxRect r = GetEditorWidgetRect(selected, m_selColumn);
1784 wxPoint pos = m_labelEditor->GetPosition();
1785
1786 // Calculate y offset
1787 int offset = pos.y % m_lineHeight;
1788
1789 m_labelEditor->Move(pos.x, r.y + offset);
1790 }
1791
1792 if ( m_wndEditor || m_wndEditor2 )
1793 {
1794 wxRect r = GetEditorWidgetRect(selected, 1);
1795
1796 if ( m_wndEditor )
1797 {
1798 wxPoint pos = m_wndEditor->GetPosition();
1799
1800 // Calculate y offset
1801 int offset = pos.y % m_lineHeight;
1802
1803 m_wndEditor->Move(pos.x, r.y + offset);
1804 }
1805
1806 if ( m_wndEditor2 )
1807 {
1808 wxPoint pos = m_wndEditor2->GetPosition();
1809
1810 m_wndEditor2->Move(pos.x, r.y);
1811 }
1812 }
1813 }
1814 }
1815
1816 // -----------------------------------------------------------------------
1817
1818 // Fixes position of wxTextCtrl-like control (wxSpinCtrl usually
1819 // fits into that category as well).
1820 void wxPropertyGrid::FixPosForTextCtrl( wxWindow* ctrl,
1821 unsigned int WXUNUSED(forColumn),
1822 const wxPoint& offset )
1823 {
1824 // Center the control vertically
1825 wxRect finalPos = ctrl->GetRect();
1826 int y_adj = (m_lineHeight - finalPos.height)/2 + wxPG_TEXTCTRLYADJUST;
1827
1828 // Prevent over-sized control
1829 int sz_dec = (y_adj + finalPos.height) - m_lineHeight;
1830 if ( sz_dec < 0 ) sz_dec = 0;
1831
1832 finalPos.y += y_adj;
1833 finalPos.height -= (y_adj+sz_dec);
1834
1835 #ifndef wxPG_TEXTCTRLXADJUST
1836 int textCtrlXAdjust = wxPG_XBEFORETEXT - 1;
1837
1838 wxTextCtrl* tc = static_cast<wxTextCtrl*>(ctrl);
1839 tc->SetMargins(0);
1840 #else
1841 int textCtrlXAdjust = wxPG_TEXTCTRLXADJUST;
1842 #endif
1843
1844 finalPos.x += textCtrlXAdjust;
1845 finalPos.width -= textCtrlXAdjust;
1846
1847 finalPos.x += offset.x;
1848 finalPos.y += offset.y;
1849
1850 ctrl->SetSize(finalPos);
1851 }
1852
1853 // -----------------------------------------------------------------------
1854
1855 wxWindow* wxPropertyGrid::GenerateEditorTextCtrl( const wxPoint& pos,
1856 const wxSize& sz,
1857 const wxString& value,
1858 wxWindow* secondary,
1859 int extraStyle,
1860 int maxLen,
1861 unsigned int forColumn )
1862 {
1863 wxWindowID id = wxPG_SUBID1;
1864 wxPGProperty* prop = GetSelection();
1865 wxASSERT(prop);
1866
1867 int tcFlags = wxTE_PROCESS_ENTER | extraStyle;
1868
1869 if ( prop->HasFlag(wxPG_PROP_READONLY) && forColumn == 1 )
1870 tcFlags |= wxTE_READONLY;
1871
1872 wxPoint p(pos.x,pos.y);
1873 wxSize s(sz.x,sz.y);
1874
1875 // Need to reduce width of text control on Mac
1876 #if defined(__WXMAC__)
1877 s.x -= 8;
1878 #endif
1879
1880 // For label editors, trim the size to allow better splitter grabbing
1881 if ( forColumn != 1 )
1882 s.x -= 2;
1883
1884 // Take button into acccount
1885 if ( secondary )
1886 {
1887 s.x -= (secondary->GetSize().x + wxPG_TEXTCTRL_AND_BUTTON_SPACING);
1888 m_iFlags &= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE);
1889 }
1890
1891 // If the height is significantly higher, then use border, and fill the rect exactly.
1892 bool hasSpecialSize = false;
1893
1894 if ( (sz.y - m_lineHeight) > 5 )
1895 hasSpecialSize = true;
1896
1897 wxWindow* ctrlParent = GetPanel();
1898
1899 if ( !hasSpecialSize )
1900 tcFlags |= wxBORDER_NONE;
1901
1902 wxTextCtrl* tc = new wxTextCtrl();
1903
1904 #if defined(__WXMSW__)
1905 tc->Hide();
1906 #endif
1907 SetupTextCtrlValue(value);
1908 tc->Create(ctrlParent,id,value, p, s,tcFlags);
1909
1910 #if defined(__WXMSW__)
1911 // On Windows, we need to override read-only text ctrl's background
1912 // colour to white. One problem with native 'grey' background is that
1913 // tc->GetBackgroundColour() doesn't seem to return correct value
1914 // for it.
1915 if ( tcFlags & wxTE_READONLY )
1916 {
1917 wxVisualAttributes vattrs = tc->GetDefaultAttributes();
1918 tc->SetBackgroundColour(vattrs.colBg);
1919 }
1920 #endif
1921
1922 // This code is repeated from DoSelectProperty(). However, font boldness
1923 // must be set before margin is set up below in FixPosForTextCtrl().
1924 if ( forColumn == 1 &&
1925 prop->HasFlag(wxPG_PROP_MODIFIED) &&
1926 HasFlag(wxPG_BOLD_MODIFIED) )
1927 tc->SetFont( m_captionFont );
1928
1929 // Center the control vertically
1930 if ( !hasSpecialSize )
1931 FixPosForTextCtrl(tc, forColumn);
1932
1933 if ( forColumn != 1 )
1934 {
1935 tc->SetBackgroundColour(m_colSelBack);
1936 tc->SetForegroundColour(m_colSelFore);
1937 }
1938
1939 #ifdef __WXMSW__
1940 tc->Show();
1941 if ( secondary )
1942 secondary->Show();
1943 #endif
1944
1945 // Set maximum length
1946 if ( maxLen > 0 )
1947 tc->SetMaxLength( maxLen );
1948
1949 wxVariant attrVal = prop->GetAttribute(wxPG_ATTR_AUTOCOMPLETE);
1950 if ( !attrVal.IsNull() )
1951 {
1952 wxASSERT(attrVal.GetType() == wxS("arrstring"));
1953 tc->AutoComplete(attrVal.GetArrayString());
1954 }
1955
1956 // Set hint text
1957 tc->SetHint(prop->GetHintText());
1958
1959 return tc;
1960 }
1961
1962 // -----------------------------------------------------------------------
1963
1964 wxWindow* wxPropertyGrid::GenerateEditorButton( const wxPoint& pos, const wxSize& sz )
1965 {
1966 wxWindowID id = wxPG_SUBID2;
1967 wxPGProperty* selected = GetSelection();
1968 wxASSERT(selected);
1969
1970 #ifdef __WXMAC__
1971 // Decorations are chunky on Mac, and we can't make the button square, so
1972 // do things a bit differently on this platform.
1973
1974 wxPoint p(pos.x+sz.x,
1975 pos.y+wxPG_BUTTON_SIZEDEC-wxPG_NAT_BUTTON_BORDER_Y);
1976 wxSize s(25, -1);
1977
1978 wxButton* but = new wxButton();
1979 but->Create(GetPanel(),id,wxS("..."),p,s,wxWANTS_CHARS);
1980
1981 // Now that we know the size, move to the correct position
1982 p.x = pos.x + sz.x - but->GetSize().x - 2;
1983 but->Move(p);
1984
1985 #else
1986 wxSize s(sz.y-(wxPG_BUTTON_SIZEDEC*2)+(wxPG_NAT_BUTTON_BORDER_Y*2),
1987 sz.y-(wxPG_BUTTON_SIZEDEC*2)+(wxPG_NAT_BUTTON_BORDER_Y*2));
1988
1989 // Reduce button width to lineheight
1990 if ( s.x > m_lineHeight )
1991 s.x = m_lineHeight;
1992
1993 #ifdef __WXGTK__
1994 // On wxGTK, take fixed button margins into account
1995 if ( s.x < 25 )
1996 s.x = 25;
1997 #endif
1998
1999 wxPoint p(pos.x+sz.x-s.x,
2000 pos.y+wxPG_BUTTON_SIZEDEC-wxPG_NAT_BUTTON_BORDER_Y);
2001
2002 wxButton* but = new wxButton();
2003 #ifdef __WXMSW__
2004 but->Hide();
2005 #endif
2006 but->Create(GetPanel(),id,wxS("..."),p,s,wxWANTS_CHARS);
2007
2008 #ifdef __WXGTK__
2009 wxFont font = GetFont();
2010 font.SetPointSize(font.GetPointSize()-2);
2011 but->SetFont(font);
2012 #else
2013 but->SetFont(GetFont());
2014 #endif
2015 #endif
2016
2017 if ( selected->HasFlag(wxPG_PROP_READONLY) )
2018 but->Disable();
2019
2020 return but;
2021 }
2022
2023 // -----------------------------------------------------------------------
2024
2025 wxWindow* wxPropertyGrid::GenerateEditorTextCtrlAndButton( const wxPoint& pos,
2026 const wxSize& sz,
2027 wxWindow** psecondary,
2028 int limitedEditing,
2029 wxPGProperty* property )
2030 {
2031 wxButton* but = (wxButton*)GenerateEditorButton(pos,sz);
2032 *psecondary = (wxWindow*)but;
2033
2034 if ( limitedEditing )
2035 {
2036 #ifdef __WXMSW__
2037 // There is button Show in GenerateEditorTextCtrl as well
2038 but->Show();
2039 #endif
2040 return NULL;
2041 }
2042
2043 wxString text;
2044
2045 if ( !property->IsValueUnspecified() )
2046 text = property->GetValueAsString(property->HasFlag(wxPG_PROP_READONLY)?0:wxPG_EDITABLE_VALUE);
2047
2048 return GenerateEditorTextCtrl(pos,sz,text,but,property->m_maxLen);
2049 }
2050
2051 // -----------------------------------------------------------------------
2052
2053 void wxPropertyGrid::SetEditorAppearance( const wxPGCell& cell,
2054 bool unspecified )
2055 {
2056 wxPGProperty* property = GetSelection();
2057 if ( !property )
2058 return;
2059 wxWindow* ctrl = GetEditorControl();
2060 if ( !ctrl )
2061 return;
2062
2063 property->GetEditorClass()->SetControlAppearance( this,
2064 property,
2065 ctrl,
2066 cell,
2067 m_editorAppearance,
2068 unspecified );
2069
2070 m_editorAppearance = cell;
2071 }
2072
2073 // -----------------------------------------------------------------------
2074
2075 wxTextCtrl* wxPropertyGrid::GetEditorTextCtrl() const
2076 {
2077 wxWindow* wnd = GetEditorControl();
2078
2079 if ( !wnd )
2080 return NULL;
2081
2082 if ( wnd->IsKindOf(CLASSINFO(wxTextCtrl)) )
2083 return wxStaticCast(wnd, wxTextCtrl);
2084
2085 if ( wnd->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox)) )
2086 {
2087 wxOwnerDrawnComboBox* cb = wxStaticCast(wnd, wxOwnerDrawnComboBox);
2088 return cb->GetTextCtrl();
2089 }
2090
2091 return NULL;
2092 }
2093
2094 // -----------------------------------------------------------------------
2095
2096 wxPGEditor* wxPropertyGridInterface::GetEditorByName( const wxString& editorName )
2097 {
2098 wxPGHashMapS2P::const_iterator it;
2099
2100 it = wxPGGlobalVars->m_mapEditorClasses.find(editorName);
2101 if ( it == wxPGGlobalVars->m_mapEditorClasses.end() )
2102 return NULL;
2103 return (wxPGEditor*) it->second;
2104 }
2105
2106 // -----------------------------------------------------------------------
2107 // wxPGEditorDialogAdapter
2108 // -----------------------------------------------------------------------
2109
2110 IMPLEMENT_ABSTRACT_CLASS(wxPGEditorDialogAdapter, wxObject)
2111
2112 bool wxPGEditorDialogAdapter::ShowDialog( wxPropertyGrid* propGrid, wxPGProperty* property )
2113 {
2114 if ( !propGrid->EditorValidate() )
2115 return false;
2116
2117 bool res = DoShowDialog( propGrid, property );
2118
2119 if ( res )
2120 {
2121 propGrid->ValueChangeInEvent( m_value );
2122 return true;
2123 }
2124
2125 return false;
2126 }
2127
2128 // -----------------------------------------------------------------------
2129 // wxPGMultiButton
2130 // -----------------------------------------------------------------------
2131
2132 wxPGMultiButton::wxPGMultiButton( wxPropertyGrid* pg, const wxSize& sz )
2133 : wxWindow( pg->GetPanel(), wxPG_SUBID2, wxPoint(-100,-100), wxSize(0, sz.y) ),
2134 m_fullEditorSize(sz), m_buttonsWidth(0)
2135 {
2136 SetBackgroundColour(pg->GetCellBackgroundColour());
2137 }
2138
2139 void wxPGMultiButton::Finalize( wxPropertyGrid* WXUNUSED(propGrid),
2140 const wxPoint& pos )
2141 {
2142 Move( pos.x + m_fullEditorSize.x - m_buttonsWidth, pos.y );
2143 }
2144
2145 int wxPGMultiButton::GenId( int id ) const
2146 {
2147 if ( id < -1 )
2148 {
2149 if ( m_buttons.size() )
2150 id = GetButton(m_buttons.size()-1)->GetId() + 1;
2151 else
2152 id = wxPG_SUBID2;
2153 }
2154 return id;
2155 }
2156
2157 #if wxUSE_BMPBUTTON
2158 void wxPGMultiButton::Add( const wxBitmap& bitmap, int id )
2159 {
2160 id = GenId(id);
2161 wxSize sz = GetSize();
2162 wxButton* button = new wxBitmapButton( this, id, bitmap,
2163 wxPoint(sz.x, 0),
2164 wxSize(sz.y, sz.y) );
2165 DoAddButton( button, sz );
2166 }
2167 #endif
2168
2169 void wxPGMultiButton::Add( const wxString& label, int id )
2170 {
2171 id = GenId(id);
2172 wxSize sz = GetSize();
2173 wxButton* button = new wxButton( this, id, label, wxPoint(sz.x, 0),
2174 wxSize(sz.y, sz.y) );
2175 DoAddButton( button, sz );
2176 }
2177
2178 void wxPGMultiButton::DoAddButton( wxWindow* button,
2179 const wxSize& sz )
2180 {
2181 m_buttons.push_back(button);
2182 int bw = button->GetSize().x;
2183 SetSize(wxSize(sz.x+bw,sz.y));
2184 m_buttonsWidth += bw;
2185 }
2186
2187 // -----------------------------------------------------------------------
2188
2189 #endif // wxUSE_PROPGRID