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: 8335 $
19 * $Id: wxsitemeditor.h 8335 2012-09-03 07:43:04Z ollydbg $
20 * $HeadURL: svn://svn.code.sf.net/p/codeblocks/code/branches/release-20.xx/src/plugins/contrib/wxSmith/wxwidgets/wxsitemeditor.h $
21 */
22 
23 #ifndef WXSITEMEDITOR_H
24 #define WXSITEMEDITOR_H
25 
26 #include "wxsitemres.h"
27 #include "../wxseditor.h"
28 
29 #include <wx/hashset.h>
30 #include <wx/notebook.h>
31 #include <wx/bmpbuttn.h>
32 #include <wx/sizer.h>
33 #include <wx/scrolwin.h>
34 
35 class wxsItemEditorContent;
36 class wxsItemResData;
37 class wxsToolSpace;
38 class wxsItemInfo;
39 class wxsItem;
40 
41 /** \brief This is root class for editing wxWidgets window resources
42  */
43 class wxsItemEditor : public wxsEditor
44 {
45     public:
46 
47         /** \brief Ctor */
48         wxsItemEditor(wxWindow* parent,wxsItemRes* ItemRes);
49 
50         /** \brief Dctor */
51         virtual ~wxsItemEditor();
52 
53         /** \brief Saving resource */
54         virtual bool Save();
55 
56         /** \brief Notifying that configuration has been changed */
57         static void ConfigChanged();
58 
59     protected:
60 
61         /** \brief Returns true if resource is modified, false otherwise */
62         virtual bool GetModified() const;
63 
64         /** \brief Checking if can Undo */
65         virtual bool CanUndo() const;
66 
67         /** \brief Checking if can Redo */
68         virtual bool CanRedo() const;
69 
70         /** \brief Checking if we can cut */
71         virtual bool HasSelection() const;
72 
73         /** \brief Checking if we can paste */
74         virtual bool CanPaste() const;
75 
76         /** \brief testing if current resource is read-only */
77         virtual bool IsReadOnly() const;
78 
79         /** \brief Undoing */
80         virtual void Undo();
81 
82         /** \brief Redoing */
83         virtual void Redo();
84 
85         /** \brief Cutting */
86         virtual void Cut();
87 
88         /** \brief Copying */
89         virtual void Copy();
90 
91         /** \brief Pasting */
92         virtual void Paste();
93 
94     private:
95 
96         WX_DECLARE_HASH_SET(wxsItemEditor*,wxPointerHash,wxPointerEqual,WindowSet);
97 
98         /* Event handlers */
99         void OnMouseClick(wxMouseEvent& event);
100         void OnButton(wxCommandEvent& event);
101         void OnInsPoint(wxCommandEvent& event);
102         void OnInsInto(wxCommandEvent& event);
103         void OnInsBefore(wxCommandEvent& event);
104         void OnInsAfter(wxCommandEvent& event);
105         void OnDelete(wxCommandEvent& event);
106         void OnPreview(wxCommandEvent& event);
107         void OnQuickProps(wxCommandEvent& event);
108         void OnKeyDown(wxKeyEvent& event);
109         void OnPopup(wxCommandEvent& event);
110 
111         void InitializeVisualStuff();
112         void InitializeResourceData();
113 
114         /** \brief Initializing editor images */
115         static void InitializeImages();
116 
117         /** \brief Building palette */
118         void BuildPalette(wxNotebook* Palette);
119 
GetItemRes()120         inline wxsItemRes* GetItemRes() { return (wxsItemRes*)GetResource(); }
GetWxsFileName()121         inline const wxString& GetWxsFileName() { return GetItemRes()->GetWxsFileName(); }
GetSrcFileName()122         inline const wxString& GetSrcFileName() { return GetItemRes()->GetSrcFileName(); }
GetHdrFileName()123         inline const wxString& GetHdrFileName() { return GetItemRes()->GetHdrFileName(); }
GetXrcFileName()124         inline const wxString& GetXrcFileName() { return GetItemRes()->GetXrcFileName(); }
125 
126         /** \brief Function inserting new item */
127         void InsertRequest(const wxString& Name);
128 
129         /** \brief Setting mask for insertion type */
130         void SetInsertionTypeMask(int Mask);
131 
132         /** \brief Setting new insertion type */
133         void SetInsertionType(int Type);
134 
135         /** \brief Rebuilding pictures on insertion type buttons */
136         void RebuildInsTypeIcons();
137 
138         /** \brief Rebuilding picture on Quick Props button */
139         void RebuildQuickPropsIcon();
140 
141         /** \brief Rebuilding all icons */
142         void RebuildIcons();
143 
144         /** \brief Building icon for one button */
145         void BuildInsTypeIcon(wxBitmapButton* Btn,const wxImage& Original,int ButtonType);
146 
147         /** \brief Opening or closing Quick Props panel */
148         void ToggleQuickPropsPanel(bool Open);
149 
150         /** \brief Refreshing content of Quick Props panel */
151         void RebuildQuickProps(wxsItem* Selection);
152 
153         /** \brief Rebuilding preview (and updating selection inside preview) */
154         void RebuildPreview();
155 
156         /** \brief Updating things related to current selection */
157         void UpdateSelection();
158 
159         /** \brief Updating editor's title applying asterisk before name of file when modified */
160         void UpdateModified();
161 
162         /** \brief Getting item which will be used as reference item when adding new
163          *         items
164          */
165         wxsItem* GetReferenceItem(int& InsertionType);
166 
167         /** \brief Starting sequence of adding new item when inserting by pointing with mouse */
168         void StartInsertPointSequence(const wxsItemInfo* Info);
169 
170         /** \brief Reloading images in all editors */
171         static void ReloadImages();
172 
173         /** \brief Causing editor's content to refresh */
174         static void RefreshContents();
175 
176         /** \brief Showing popup menu */
177         void ShowPopup(wxsItem* Item,wxMenu* Menu);
178 
179         wxsItemResData* m_Data;             ///< \brief Data management object
180 
181         wxsItemEditorContent* m_Content;    ///< \brief Window with content area
182         wxsToolSpace* m_ToolSpace;          ///< \brief Space for tools in resource
183         wxNotebook* m_WidgetsSet;           ///< \brief Notebook with all widgets inside
184         wxBoxSizer* m_VertSizer;            ///< \brief Root sizer of this editor
185         wxBoxSizer* m_HorizSizer;           ///< \brief Horizontal sizer managing items below palette
186         wxBoxSizer* m_QPSizer;              ///< \brief Sizer for quick properties
187         wxBoxSizer* m_OpsSizer;             ///< \brief Sizer for operations pane
188         wxScrolledWindow* m_QPArea;         ///< \brief Scrolled window containing all QuickProps sturr
189         wxBitmapButton* m_InsPointBtn;
190         wxBitmapButton* m_InsIntoBtn;
191         wxBitmapButton* m_InsBeforeBtn;
192         wxBitmapButton* m_InsAfterBtn;
193         wxBitmapButton* m_DelBtn;
194         wxBitmapButton* m_PreviewBtn;
195         wxBitmapButton* m_QuickPanelBtn;
196         wxWindow* m_TopPreview;             ///< \brief Top window of preview
197         wxPanel* m_PreviewBackground;       ///< \brief Background panel used as background for preview
198         int m_InsType;                      ///< \brief Current insertion type
199         int m_InsTypeMask;                  ///< \brief Current insertion type mask
200         bool m_QuickPropsOpen;              ///< \brief Set to true if quick properties panel is opened
201         wxsItem* m_PopupCaller;             ///< \brief Item which requested popup to be shown
202 
203         static wxImage m_InsPointImg;
204         static wxImage m_InsIntoImg;
205         static wxImage m_InsBeforeImg;
206         static wxImage m_InsAfterImg;
207         static wxImage m_DelImg;
208         static wxImage m_PreviewImg;
209         static wxImage m_QuickPropsImgOpen;
210         static wxImage m_QuickPropsImgClose;
211         static wxImage m_SelectedImg;
212         static WindowSet m_AllEditors;
213         static bool m_ImagesLoaded;
214 
215         static const int itPoint  = 0x01;
216         static const int itBefore = 0x02;
217         static const int itAfter  = 0x04;
218         static const int itInto   = 0x08;
219 
220         DECLARE_EVENT_TABLE()
221 
222         friend class wxsItemEditorContent;
223         friend class wxsItemResData;
224         friend class wxsItem;
225 };
226 
227 #endif
228