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