1 /*
2 * This file is part of wxSmith plugin for Code::Blocks Studio
3 * Copyright (C) 2006-2007 Bartlomiej Swiecki
4 *
5 * wxSmith is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * wxSmith is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with wxSmith. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * $Revision: 10771 $
19 * $Id: wxscustomeditorproperty.cpp 10771 2016-02-06 14:29:31Z mortenmacfly $
20 * $HeadURL: svn://svn.code.sf.net/p/codeblocks/code/branches/release-20.xx/src/plugins/contrib/wxSmith/properties/wxscustomeditorproperty.cpp $
21 */
22
23 #include "wxscustomeditorproperty.h"
24
25 #include <prep.h>
26
27 #include <wx/dialog.h>
28 #include <wx/bitmap.h>
29 #include <wx/propgrid/propgrid.h>
30 #if !wxCHECK_VERSION(3, 0, 0)
31 #include <wx/propgrid/propdev.h>
32 #endif
33 #include <wx/propgrid/advprops.h>
34 #include <wx/propgrid/manager.h>
35
36 namespace
37 {
38 class wxsCustomEditorPropertyPropClass: public wxCustomPropertyClass
39 {
40 public:
41 /** \brief Standard property editor */
wxsCustomEditorPropertyPropClass(const wxString & label,const wxString & name,wxsCustomEditorProperty * property,wxsPropertyContainer * object)42 wxsCustomEditorPropertyPropClass(
43 const wxString& label,
44 const wxString& name,
45 wxsCustomEditorProperty* property,
46 wxsPropertyContainer* object):
47 wxCustomPropertyClass(label,name),
48 Property(property),
49 Object(object)
50 {
51 SetEditor(wxPG_EDITOR(TextCtrlAndButton));
52 SetValue(Property->GetStr(Object));
53 }
54
OnEvent(wxPropertyGrid * propgrid,wxWindow * wnd_primary,wxEvent & event)55 virtual bool OnEvent(
56 wxPropertyGrid* propgrid,
57 wxWindow* wnd_primary,
58 wxEvent& event)
59 {
60 if ( event.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED )
61 {
62 if(Property->ShowEditor(Object))
63 {
64 SetValueInEvent (Property->GetStr(Object));
65 return true;
66 }
67 return false;
68 }
69 return wxCustomPropertyClass::OnEvent(propgrid,wnd_primary,event);
70 }
71
72 #if wxCHECK_VERSION(3, 0, 0)
ValueToString(cb_unused wxVariant & value,cb_unused int argFlags=0) const73 virtual wxString ValueToString(cb_unused wxVariant& value, cb_unused int argFlags = 0) const
74 #else
75 virtual wxString GetValueAsString( cb_unused int flags = 0 ) const
76 #endif
77 {
78 return Property->GetStr(Object);
79 }
80
81 /** \brief Pointer to wxsProperty which created this
82 *
83 * Pointer will be used to call ShowEditor
84 */
85 wxsCustomEditorProperty* Property;
86 wxsPropertyContainer* Object;
87 };
88 }
89
PGCreate(wxsPropertyContainer * Object,wxPropertyGridManager * Grid,wxPGId Parent)90 void wxsCustomEditorProperty::PGCreate(wxsPropertyContainer* Object,wxPropertyGridManager* Grid,wxPGId Parent)
91 {
92 wxPGId PGId = Grid->AppendIn(Parent,new wxsCustomEditorPropertyPropClass(GetPGName(),wxPG_LABEL,this,Object));
93 if ( !CanParseStr() )
94 {
95 Grid->LimitPropertyEditing(PGId);
96 }
97 PGRegister(Object,Grid,PGId);
98 }
99
PGRead(cb_unused wxsPropertyContainer * Object,wxPropertyGridManager * Grid,wxPGId PGId,cb_unused long Index)100 bool wxsCustomEditorProperty::PGRead(cb_unused wxsPropertyContainer* Object,
101 wxPropertyGridManager* Grid,
102 wxPGId PGId,cb_unused long Index)
103 {
104 return CanParseStr() && ParseStr(Object,Grid->GetPropertyValue(PGId).GetString());
105 }
106
PGWrite(cb_unused wxsPropertyContainer * Object,cb_unused wxPropertyGridManager * Grid,cb_unused wxPGId PGId,cb_unused long Index)107 bool wxsCustomEditorProperty::PGWrite(cb_unused wxsPropertyContainer* Object,
108 cb_unused wxPropertyGridManager* Grid,
109 cb_unused wxPGId PGId,cb_unused long Index)
110 {
111 return true;
112 }
113