1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // wxFormBuilder - A Visual Dialog Editor for wxWidgets.
4 // Copyright (C) 2005 José Antonio Hurtado
5 //
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19 //
20 // Written by
21 //   José Antonio Hurtado - joseantonio.hurtado@gmail.com
22 //   Juan Antonio Ortega  - jortegalalmolda@gmail.com
23 //
24 // Modified by
25 //   Andrea Zanellato - zanellato.andrea@gmail.com
26 //
27 ///////////////////////////////////////////////////////////////////////////////
28 
29 #ifndef __OBJ_INSPECT__
30 #define __OBJ_INSPECT__
31 
32 #if wxVERSION_NUMBER >= 2900 && !wxUSE_PROPGRID
33     #error "wxUSE_PROPGRID must be set to 1 in your wxWidgets library."
34 #endif
35 
36 #ifdef USE_FLATNOTEBOOK
37 #include <wx/wxFlatNotebook/wxFlatNotebook.h>
38 #else
39 #include <wx/aui/auibook.h>
40 #endif
41 
42 #if wxVERSION_NUMBER >= 2900
43     #include <wx/propgrid/property.h>
44 #endif
45 #include <wx/propgrid/manager.h>
46 #include "utils/wxfbdefs.h"
47 #include "model/objectbase.h"
48 
49 class wxFBEventHandlerEvent;
50 class wxFBPropertyEvent;
51 class wxFBObjectEvent;
52 class wxFBEvent;
53 
54 enum {
55     wxFB_OI_DEFAULT_STYLE,
56     wxFB_OI_MULTIPAGE_STYLE,
57     wxFB_OI_SINGLE_PAGE_STYLE
58 };
59 
60 class ObjectInspector : public wxPanel
61 {
62 private:
63     typedef std::map< wxPGProperty*, PProperty> ObjInspectorPropertyMap;
64     typedef std::map< wxPGProperty*, PEvent> ObjInspectorEventMap;
65 
66     ObjInspectorPropertyMap m_propMap;
67     ObjInspectorEventMap m_eventMap;
68 
69     PObjectBase m_currentSel;
70 
71 	//save the current selected property
72 	wxString m_strSelPropItem;
73 	wxString m_pageName;
74 
75 #ifdef USE_FLATNOTEBOOK
76     wxFlatNotebook* m_nb;
77     wxFlatNotebookImageList m_icons;
78 #else
79 	wxAuiNotebook* m_nb;
80 #endif
81 
82     wxPropertyGridManager* m_pg;
83     wxPropertyGridManager* m_eg;
84 
85     int m_style;
86 
87     int StringToBits( const wxString& strVal, wxPGChoices& constants );
88 
89     typedef std::map< wxString, bool > ExpandMap;
90     ExpandMap m_isExpanded;
91 
92     template < class ValueT >
CreateCategory(const wxString & name,PObjectBase obj,PObjectInfo obj_info,std::map<wxString,ValueT> & itemMap,bool addingEvents)93         void CreateCategory( const wxString& name, PObjectBase obj, PObjectInfo obj_info, std::map< wxString, ValueT >& itemMap, bool addingEvents )
94     {
95         // Get Category
96         PPropertyCategory category = obj_info->GetCategory();
97         if ( !category )
98         {
99             return;
100         }
101 
102         // Prevent page creation if there are no properties
103         if ( 0 == category->GetCategoryCount() && 0 == ( addingEvents ? category->GetEventCount() : category->GetPropertyCount() ) )
104         {
105             return;
106         }
107 
108         wxString pageName;
109 
110         if ( m_style == wxFB_OI_MULTIPAGE_STYLE )
111             pageName = name;
112         else
113             pageName = wxT("default");
114 
115 
116         wxPropertyGridManager* pg = ( addingEvents ? m_eg : m_pg );
117         int pageIndex = pg->GetPageByName( pageName );
118         if ( wxNOT_FOUND == pageIndex )
119         {
120             pg->AddPage( pageName, obj_info->GetSmallIconFile() );
121         }
122 
123         const wxString& catName = category->GetName();
124 
125         wxPGProperty* id = pg->Append( new wxPropertyCategory( catName ) );
126 
127         AddItems( name, obj, obj_info, category, itemMap );
128 
129         ExpandMap::iterator it = m_isExpanded.find(catName);
130         if (it != m_isExpanded.end())
131         {
132             if ( it->second )
133             {
134                 pg->Expand( id );
135             }
136             else
137             {
138                 pg->Collapse( id );
139             }
140         }
141 
142         pg->SetPropertyAttributeAll( wxPG_BOOL_USE_CHECKBOX, (long)1 );
143     }
144 
145     void AddItems( const wxString& name, PObjectBase obj, PObjectInfo obj_info, PPropertyCategory category, PropertyMap& map );
146     void AddItems( const wxString& name, PObjectBase obj, PObjectInfo obj_info, PPropertyCategory category, EventMap& map );
147     wxPGProperty* GetProperty( PProperty prop );
148 
149     void Create( bool force = false );
150 
151     void OnPropertyGridChanging( wxPropertyGridEvent& event );
152     void OnPropertyGridChanged( wxPropertyGridEvent& event );
153     void OnEventGridChanged( wxPropertyGridEvent& event );
154     void OnPropertyGridDblClick( wxPropertyGridEvent& event );
155     void OnEventGridDblClick( wxPropertyGridEvent& event );
156     void OnPropertyGridExpand( wxPropertyGridEvent& event );
157     void OnEventGridExpand( wxPropertyGridEvent& event );
158 	void OnPropertyGridItemSelected( wxPropertyGridEvent& event );
159     void OnReCreateGrid( wxCommandEvent& event );
160 	void OnBitmapPropertyChanged( wxCommandEvent& event );
161 
162 	void RestoreLastSelectedPropItem();
163 
164 	void ModifyProperty( PProperty prop, const wxString& str );
165 
166 #if wxVERSION_NUMBER >= 2900
167 	void OnChildFocus( wxChildFocusEvent& event );
168 #endif
169 
170 public:
171     ObjectInspector(wxWindow *parent, int id, int style = wxFB_OI_DEFAULT_STYLE);
172     ~ObjectInspector();
173 
174     void OnObjectSelected( wxFBObjectEvent& event );
175     void OnProjectRefresh( wxFBEvent& event );
176     void OnPropertyModified( wxFBPropertyEvent& event );
177     void OnEventHandlerModified( wxFBEventHandlerEvent& event );
178 
179     void AutoGenerateId( PObjectBase objectChanged, PProperty propChanged, wxString reason );
180     wxPropertyGridManager* CreatePropertyGridManager( wxWindow *parent, wxWindowID id );
181     void SavePosition();
182 
183     DECLARE_EVENT_TABLE()
184 };
185 
186 #endif //__OBJ_INSPECT__
187