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