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