Debian Codegraph @

wxcrafter/src/wxguicraft_main_view.h

raw
1 #ifndef __main_panel__
2 #define __main_panel__
3
4 #include "aui_pane_info_list_view.h"
5 #include "clTreeCtrl.h"
6 #include "cl_command_event.h"
7 #include "events_database.h"
8 #include "gui.h"
9 #include "properties_sheet.h"
10 #include "sizer_flags_list_view.h"
11 #include "styles_sheet_list_view.h"
12 #include "wxc_edit_manager.h"
13 #include "wxc_project_metadata.h"
14 #include "wxc_widget.h"
15
16 #include <wx/aui/auibar.h>
17 #include <wx/treectrl.h>
18
19 class EventsEditorPane;
20 class EventsEditorDlg;
21 extern const wxEventType wxEVT_UPDATE_PREVIEW;
22 extern const wxEventType wxEVT_UPDATE_EVENTSEDITORPANE;
23 wxDECLARE_EVENT(wxEVT_EVENTS_PROPERTIES_UPDATED, wxCommandEvent);
24 wxDECLARE_EVENT(wxEVT_WXC_CMD_BATCH_GENERATE_CODE, wxCommandEvent);
25 extern const wxEventType wxEVT_PROPERTIES_MODIFIED;
26 extern const wxEventType wxEVT_PROJECT_METADATA_MODIFIED;
27 extern const wxEventType wxEVT_WXGUI_PROJECT_CLOSED;
28 extern const wxEventType wxEVT_WXGUI_PROJECT_LOADED;
29 extern const wxEventType wxEVT_WXGUI_PROJECT_SAVED;
30 extern const wxEventType wxEVT_CLOSE_PREVIEW;
31 extern const wxEventType wxEVT_PREVIEW_CLOSED;
32 extern const wxEventType wxEVT_PREVIEW_CTRL_SELECTED;
33 extern const wxEventType wxEVT_PREVIEW_BOOKPAGE_SELECTED;
34 extern const wxEventType wxEVT_PREVIEW_RIBBON_PAGE_SELECTED;
35 extern const wxEventType wxEVT_DESIGNER_DELETED;
36 extern const wxEventType wxEVT_REFRESH_DESIGNER;
37 extern const wxEventType wxEVT_REFRESH_PROPERTIES_VIEW;
38 extern const wxEventType wxEVT_WXC_PROJECT_LOADED;
39 extern const wxEventType wxEVT_WXC_SELECT_TREE_TLW;
40 extern const wxEventType wxEVT_WXC_CODE_PREVIEW_PAGE_CHANGED;
41
42 extern const wxEventType wxEVT_WXC_CMD_GENERATE_CODE;
43 extern const wxEventType wxEVT_WXC_OPEN_PROJECT;
44 extern const wxEventType wxEVT_WXC_SAVE_PROJECT;
45 extern const wxEventType wxEVT_WXC_CLOSE_PROJECT;
46 extern const wxEventType wxEVT_TREE_ITEM_SELECTED;
47 extern const wxEventType wxEVT_SHOW_CONTEXT_MENU;
48 extern const wxEventType wxEVT_DELETE_CONTROL;
49
50 class GUICraftItemData : public wxTreeItemData
51 {
52 public:
53 wxcWidget* m_wxcWidget;
54
55 GUICraftItemData(wxcWidget* w)
56 : m_wxcWidget(w)
57 {
58 }
59 virtual ~GUICraftItemData()
60 {
61 if(m_wxcWidget) {
62 delete m_wxcWidget;
63 m_wxcWidget = NULL;
64 }
65 }
66 };
67
68 class wxCrafterPlugin;
69 class GUICraftMainPanel : public GUICraftMainPanelBase
70 {
71 friend class PropertiesSheet;
72 friend class wxcEditManager;
73
74 PropertiesSheet* m_propertiesPage;
75 wxAuiToolBar* m_mainToolBar;
76 wxcWidget* m_clipboardItem;
77 wxTreeItemId m_draggedItem;
78 bool m_previewAlive;
79 clTreeCtrl* m_treeControls;
80 wxCrafterPlugin* m_plugin;
81 StylesSheetListView m_styles;
82 SizerFlagsListView m_sizerFlags;
83 AuiPaneInfoListView m_auiPaneInfo;
84
85 public:
86 enum { kGenCodeForPreview = 0x00000001, kGenCodeSelectionOnly = 0x00000002 };
87
88 static GUICraftMainPanel* m_MainPanel;
89 wxWindow* GetTopFrame() const;
90
91 bool IsPreviewAlive() const { return m_previewAlive; }
92
93 DesignerPanel* GetDesignerPanel() const { return m_dp; }
94
95 wxStyledTextCtrl* GetPreviewEditor() const;
96
97 protected:
98 virtual void OnSizerFlagsUpdateUI(wxUpdateUIEvent& event);
99 virtual void OnAuiPaneInfoChanged(wxPropertyGridEvent& event);
100 virtual void OnSizerFlagsChanged(wxPropertyGridEvent& event);
101 virtual void OnStylesChanged(wxPropertyGridEvent& event);
102 virtual void OnNewFormUI(wxUpdateUIEvent& event);
103 virtual void OnCppBookPageChanged(wxBookCtrlEvent& event);
104 virtual void OnPageChanged(wxBookCtrlEvent& event);
105
106 void DoDismissFindBar();
107 bool IsTreeViewSelected() const;
108 bool IsPropertyGridPropertySelected() const;
109 void DoSelectItemByName(const wxString& name, const wxString& parentTLW);
110 void DoRefresh(int eventType);
111 void DoUpdatePropertiesView();
112 void DoUpdateSizerFlags(wxcWidget* data);
113 void DoUpdateStyleFlags(wxcWidget* data);
114 void DoUpdatPropertiesFlags(wxcWidget* data);
115 void DoUnsetItemData(const wxTreeItemId& item);
116 void DoFindName(const wxTreeItemId& parent, const wxString& name, wxTreeItemId& item);
117 void DoInsertControl(wxcWidget* control, wxcWidget* parent, int insertType, int imgId);
118 void DoPasteOrDuplicate(wxcWidget* source, wxcWidget* target, bool duplicating);
119 void DoMoveToplevelWindow(wxcWidget* tlw, int direction);
120 size_t DoFindPropertiesPage(wxWindow* win);
121 void DoShowPropertiesPage(wxWindow* win, const wxString& text, bool show);
122 void DoUpdateCppPreview();
123
124 /**
125 * @brief check if we can place source inside target (or next to it)
126 */
127 bool DoCheckInsert(wxcWidget* source, wxcWidget* target) const;
128 wxTreeItemId DoGetTopLevelTreeItem() const;
129 void NotifyPreviewChanged(int eventType = wxEVT_UPDATE_PREVIEW);
130 wxString GetStyleFromGuiID(int guiId) const;
131
132 void Clear();
133 void DoBuildTree(wxTreeItemId& itemToSelect, wxcWidget* wrapper, const wxTreeItemId& parent,
134 const wxTreeItemId& beforeItem = wxTreeItemId(), bool insertBefore = true);
135 void ExpandToItem(const wxString& name, wxTreeItemId& searchFromItem); // Find and select the named item, starting
136 // looking from branch searchFromItem (in
137 // case of a name-clash)
138 wxTreeItemId DoFindBestSelection(const wxTreeItemId& item);
139 bool DoUpdateNotebookSelection(const wxTreeItemId& item);
140
141 void DoInsertBefore(const wxTreeItemId& sourceItem, const wxTreeItemId& targetItem,
142 wxcWidget* sourceItemData = NULL, bool insertBefore = true);
143 void DoAppendItem(const wxTreeItemId& sourceItem, const wxTreeItemId& targetItem, wxcWidget* sourceItemData = NULL);
144 void DoChangeOrInsertIntoSizer(int id);
145 wxArrayString GetCustomControlsUsed() const;
146 wxTreeItemId DoFindItemByWxcWidget(wxcWidget* widget, const wxTreeItemId& item) const;
147
148 /**
149 * @brief generate the code for the current project
150 * @param silent if set to true, disable all dialog messages
151 */
152 void DoGenerateCode(bool silent);
153
154 public:
155 GUICraftMainPanel(wxWindow* parent, wxCrafterPlugin* plugin, clTreeCtrl* treeView);
156 virtual ~GUICraftMainPanel();
157 /**
158 * @brief batch generate the code for a list of wxC files
159 * @param files
160 */
161 void BatchGenerate(const wxArrayString& files);
162
163 State::Ptr_t CurrentState();
164 GUICraftItemData* GetSelItemData();
165 wxcWidget* GetActiveWizardPage() const;
166 wxcWidget* GetActiveTopLevelWin() const;
167 wxcWidget* DoGetItemData(const wxTreeItemId& item) const;
168 bool GenerateCppOutput(wxString& cpp, wxString& header, wxArrayString& headers, wxStringMap_t& additionalFiles,
169 size_t flags = 0) const;
170 void GenerateXrcOutput(wxString& output, size_t flags = 0) const;
171 /**
172 * @brief save the tree to the file system
173 * @param filename
174 */
175 JSONElement ToJSON(const wxTreeItemId& fromItem = wxTreeItemId());
176 void LoadProject(const wxFileName& fn, const wxString& fileContent, bool lightLoad = false);
177
178 void OnMenu(wxTreeEvent& event);
179 void OnShowContextMenu(wxCommandEvent& e);
180 void AddCustomControl(int controlId);
181
182 DECLARE_EVENT_TABLE()
183 void OnRefreshPropertiesView(wxCommandEvent& e);
184 void OnSaveProject(wxCommandEvent& e);
185 void OnOpenProject(wxCommandEvent& e);
186 void OnCloseProject(wxCommandEvent& e);
187 void OnGenerateCode(wxCommandEvent& e);
188 void OnBatchGenerateCode(wxCommandEvent& e);
189 void OnGenerateCodeMenu(wxAuiToolBarEvent& e);
190 void OnCodeGenerationTypeChanged(wxCommandEvent& event);
191 void OnNewControl(wxCommandEvent& e);
192 void OnChangeSizerType(wxCommandEvent& e);
193 void OnInsertIntoSizer(wxCommandEvent& e);
194 void OnNewCustomControlMenu(wxCommandEvent& e);
195 void OnNewCustomControl(wxCommandEvent& e);
196 void OnItemSelected(wxTreeEvent& event);
197 void OnShowPreview(wxCommandEvent& e);
198 void OnGenerateCodeUI(wxUpdateUIEvent& e);
199 void OnSaveProjectUI(wxUpdateUIEvent& e);
200 void OnCancelPreviewUI(wxUpdateUIEvent& e);
201 void OnShowPreviewUI(wxUpdateUIEvent& e);
202 void OnCancelPreview(wxCommandEvent& e);
203 void OnSizerForTopLevelWinUI(wxUpdateUIEvent& e);
204 void OnItemRightClick(wxTreeEvent& event);
205 void OnStyleChanged(wxPropertyGridEvent& event);
206 void OnPropertyChanged(wxCommandEvent& e);
207 void OnSizerTool(wxCommandEvent& e);
208 void OnSetSizerProp1(wxCommandEvent& e);
209 void OnEventEditor(wxCommandEvent& e);
210 void OnEventEditorUI(wxUpdateUIEvent& e);
211 void OnEventEditorCommon(wxCommandEvent& e);
212 void OnSizerToolUI(wxUpdateUIEvent& e);
213 void OnSetSizerProp1UI(wxUpdateUIEvent& e);
214 void OnDelete(wxCommandEvent& e);
215 void OnDeleteUI(wxUpdateUIEvent& e);
216 void OnMoveItem(wxCommandEvent& e);
217 void OnMoveItemUI(wxUpdateUIEvent& e);
218 void OnMenuItemUI(wxUpdateUIEvent& e);
219 void OnPreviewItemSelected(wxCommandEvent& e);
220 void OnSelectToplevelItem(wxCommandEvent& e);
221 void OnBookPageSelected(wxCommandEvent& e);
222 void OnRibbonPageSelected(wxCommandEvent& e);
223 void OnPreviewClosed(wxCommandEvent& e);
224 void OnMenuItemClicked(wxCommandEvent& e);
225 void OnCut(wxCommandEvent& e);
226 void OnCopy(wxCommandEvent& e);
227 void OnPaste(wxCommandEvent& e);
228 void OnDuplicate(wxCommandEvent& e);
229 void OnRename(wxCommandEvent& event);
230 void OnUndo(wxCommandEvent& e);
231 void OnRedo(wxCommandEvent& e);
232 void OnRedoUI(wxUpdateUIEvent& e);
233 void OnUndoUI(wxUpdateUIEvent& e);
234 void OnLabelCurrentState(wxCommandEvent& e);
235 void OnEditMenuOpened(wxMenuEvent& event);
236 void OnLoadCurrentState(wxCommandEvent& e);
237 void OnBeginDrag(wxTreeEvent& event);
238 void OnEndDrag(wxTreeEvent& event);
239 void OnRefreshView(wxCommandEvent& e);
240 void OnBarItemSelected(wxCommandEvent& e);
241 void OnUpdatePreview(wxCommandEvent& e);
242 void OnFindBar(clFindEvent& e);
243 };
244
245 #endif // __main_panel__