1 //////////////////////////////////////////////////////////////////////////
2 //
3 // pgAdmin III - PostgreSQL Tools
4 //
5 // Copyright (C) 2002 - 2016, The pgAdmin Development Team
6 // This software is released under the PostgreSQL Licence
7 //
8 // frmMain.h - The main form
9 //
10 //////////////////////////////////////////////////////////////////////////
11 
12 #ifndef FRMMAIN_H
13 #define FRMMAIN_H
14 
15 
16 // wxWindows headers
17 #include <wx/wx.h>
18 #include <wx/listctrl.h>
19 #include <wx/notebook.h>
20 
21 // wxAUI
22 #include <wx/aui/aui.h>
23 
24 #include "frm/frmQuery.h"
25 #include "dlg/dlgClasses.h"
26 #include "utils/factory.h"
27 
28 //
29 // This number MUST be incremented if changing any of the default perspectives
30 //
31 #define FRMMAIN_PERSPECTIVE_VER wxT("8418")
32 
33 #ifdef __WXMAC__
34 #define FRMMAIN_DEFAULT_PERSPECTIVE wxT("layout2|name=objectBrowser;caption=Object browser;state=16779260;dir=4;layer=1;row=0;pos=0;prop=100000;bestw=200;besth=450;minw=100;minh=200;maxw=-1;maxh=-1;floatx=236;floaty=222;floatw=-1;floath=-1|name=listViews;caption=Info pane;state=1020;dir=5;layer=0;row=0;pos=0;prop=100000;bestw=400;besth=200;minw=200;minh=100;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|name=sqlPane;caption=SQL pane;state=16779260;dir=3;layer=0;row=0;pos=0;prop=100000;bestw=400;besth=200;minw=200;minh=100;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|name=toolBar;caption=Tool bar;state=16788208;dir=1;layer=10;row=0;pos=0;prop=100000;bestw=520;besth=39;minw=-1;minh=-1;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|dock_size(5,0,0)=18|dock_size(3,0,0)=228|dock_size(1,10,0)=41|dock_size(4,1,0)=233|")
35 #else
36 #ifdef __WXGTK__
37 #define FRMMAIN_DEFAULT_PERSPECTIVE wxT("layout2|name=objectBrowser;caption=Object browser;state=16779260;dir=4;layer=1;row=0;pos=0;prop=100000;bestw=200;besth=450;minw=100;minh=200;maxw=-1;maxh=-1;floatx=236;floaty=222;floatw=-1;floath=-1|name=listViews;caption=Info pane;state=1020;dir=5;layer=0;row=0;pos=0;prop=100000;bestw=400;besth=200;minw=200;minh=100;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|name=sqlPane;caption=SQL pane;state=16779260;dir=3;layer=0;row=0;pos=0;prop=100000;bestw=400;besth=200;minw=200;minh=100;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|name=toolBar;caption=Tool bar;state=16788208;dir=1;layer=10;row=0;pos=0;prop=100000;bestw=586;besth=44;minw=-1;minh=-1;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|dock_size(5,0,0)=18|dock_size(3,0,0)=228|dock_size(1,10,0)=41|dock_size(4,1,0)=233|")
38 #else
39 #define FRMMAIN_DEFAULT_PERSPECTIVE wxT("layout2|name=objectBrowser;caption=Object browser;state=16779260;dir=4;layer=1;row=0;pos=0;prop=100000;bestw=200;besth=450;minw=100;minh=200;maxw=-1;maxh=-1;floatx=236;floaty=222;floatw=-1;floath=-1|name=listViews;caption=Info pane;state=1020;dir=5;layer=0;row=0;pos=0;prop=100000;bestw=400;besth=200;minw=200;minh=100;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|name=sqlPane;caption=SQL pane;state=16779260;dir=3;layer=0;row=0;pos=0;prop=100000;bestw=400;besth=200;minw=200;minh=100;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|name=toolBar;caption=Tool bar;state=16788208;dir=1;layer=10;row=0;pos=0;prop=100000;bestw=506;besth=39;minw=-1;minh=-1;maxw=-1;maxh=-1;floatx=-1;floaty=-1;floatw=-1;floath=-1|dock_size(5,0,0)=18|dock_size(3,0,0)=228|dock_size(1,10,0)=41|dock_size(4,1,0)=233|")
40 
41 #endif
42 #endif
43 class pgServer;
44 class pgServerCollection;
45 class ctlSQLBox;
46 class ctlTree;
47 class dlgProperty;
48 class serverCollection;
49 
50 class propertyFactory;
51 class pluginUtilityFactory;
52 class ctlMenuButton;
53 
54 // A plugin utility
55 typedef struct PluginUtility
56 {
57 	wxString title;
58 	wxString command;
59 	wxString description;
60 	wxString keyfile;
61 	wxString platform;
62 	wxArrayString server_types;
63 	bool database;
64 	wxArrayString applies_to;
65 	bool set_password;
66 	wxArrayString set_env;
67 } PluginUtility;
68 
69 
70 enum
71 {
72 	NBP_PROPERTIES = 0,
73 	NBP_STATISTICS,
74 	NBP_DEPENDENCIES,
75 	NBP_DEPENDENTS
76 };
77 
78 enum
79 {
80 	REFRESH_OBJECT_NONE = 0,
81 	REFRESH_OBJECT_ONLY,
82 	REFRESH_OBJECT_AND_CHILDREN
83 };
84 
85 #if defined(HAVE_OPENSSL_CRYPTO) || defined(HAVE_GCRYPT)
86 BEGIN_DECLARE_EVENT_TYPES()
87 extern const wxEventType SSH_TUNNEL_ERROR_EVENT;
END_DECLARE_EVENT_TYPES()88 END_DECLARE_EVENT_TYPES()
89 #endif
90 
91 // Class declarations
92 class frmMain : public pgFrame
93 {
94 public:
95 	frmMain(const wxString &title);
96 	~frmMain();
97 
98 	void OnAction(wxCommandEvent &ev);
99 	void OnReport(wxCommandEvent &ev);
100 	wxString GetHelpPage() const;
101 
102 	void StartMsg(const wxString &msg);
103 	void EndMsg(bool done = true);
104 	void SetStatusText(const wxString &msg);
105 	void SetCurrentObject(pgObject *data)
106 	{
107 		currentObject = data;
108 	}
109 	bool CheckAlive();
110 
111 	void execSelChange(wxTreeItemId item, bool currentNode);
112 	void Refresh(pgObject *data);
113 	void ExecDrop(bool cascaded);
114 	void ShowObjStatistics(pgObject *data, wxWindow *ctrl = NULL);
115 
116 	wxImageList *GetImageList()
117 	{
118 		return imageList;
119 	}
120 	ctlTree *GetBrowser()
121 	{
122 		return browser;
123 	}
124 	ctlSQLBox *GetSqlPane()
125 	{
126 		return sqlPane;
127 	}
128 	ctlListView *GetProperties()
129 	{
130 		return properties;
131 	}
132 	ctlListView *GetStatistics();
133 	ctlListView *GetDependencies();
134 	ctlListView *GetReferencedBy();
135 	void SelectStatisticsTab()
136 	{
137 		listViews->SetSelection(1);
138 	};
139 	void StoreServers();
140 	int ReconnectServer(pgServer *server, bool restore = true);
141 	void ReportConnError(pgServer *server);
142 	pgServerCollection *GetServerCollection()
143 	{
144 		return serversObj;
145 	}
146 	pgServer *ConnectToServer(const wxString &servername, bool restore = false);
147 
148 	void SetLastPluginUtility(pluginUtilityFactory *pluginFactory)
149 	{
150 		lastPluginUtility = pluginFactory;
151 	}
152 	pluginUtilityFactory *GetLastPluginUtility()
153 	{
154 		return lastPluginUtility;
155 	}
156 	wxMenu *GetPluginsMenu()
157 	{
158 		return pluginsMenu;
159 	}
160 
161 	wxString GetCurrentNodePath();
162 	bool SetCurrentNode(wxTreeItemId node, const wxString &path);
163 
164 	void UpdateAllRecentFiles();
165 	void UpdateAllFavouritesList();
166 	void UpdateAllMacrosList();
167 
168 	void SetItemBackgroundColour(wxTreeItemId item, wxColour colour);
169 	wxString GetNodePath(wxTreeItemId node);
170 	void ObjectBrowserRefreshing(bool refresh)
171 	{
172 		m_refreshing = refresh;
173 	}
174 
175 #if defined(HAVE_OPENSSL_CRYPTO) || defined(HAVE_GCRYPT)
176 	void OnSSHTunnelEvent(wxCommandEvent &event);
177 #endif
178 
179 private:
180 	wxAuiManager manager;
181 	ctlTree *browser;
182 	ctlListView *properties;
183 	ctlListView *statistics;
184 	ctlListView *dependents, *dependencies;
185 	ctlAuiNotebook *listViews;
186 	ctlSQLBox *sqlPane;
187 	wxMenu *newMenu, *debuggingMenu, *reportMenu, *toolsMenu, *pluginsMenu, *viewMenu,
188 	       *treeContextMenu, *newContextMenu, *slonyMenu, *scriptingMenu, *viewDataMenu;
189 	pgServerCollection *serversObj;
190 
191 	pluginUtilityFactory *lastPluginUtility;
192 	int pluginUtilityCount;
193 
194 	propertyFactory *propFactory;
195 	actionFactory *newMenuFactory;
196 	actionFactory *debuggingMenuFactory;
197 	actionFactory *reportMenuFactory;
198 	actionFactory *scriptingMenuFactory;
199 	actionFactory *viewdataMenuFactory;
200 
201 	wxStopWatch stopwatch;
202 	wxString timermsg;
203 	long msgLevel;
204 
205 	bool m_refreshing;
206 
207 	wxTreeItemId denyCollapseItem;
208 	pgObject *currentObject;
209 	wxControl *currentControl;
210 
211 	void OnChildFocus(wxChildFocusEvent &event);
212 	void OnEraseBackground(wxEraseEvent &event);
213 	void OnSize(wxSizeEvent &event);
214 	void OnSelectItem(wxListEvent &event);
215 
216 	void CreateMenus();
217 	void OnContents(wxCommandEvent &event);
218 	void OnExit(wxCommandEvent &event);
219 	void ViewData(bool filter = false);
220 	void OnSaveDefinition(wxCommandEvent &event);
221 	void OnToggleSqlPane(wxCommandEvent &event);
222 	void OnToggleObjectBrowser(wxCommandEvent &event);
223 	void OnToggleToolBar(wxCommandEvent &event);
224 	void OnDefaultView(wxCommandEvent &event);
225 	void OnAuiUpdate(wxAuiManagerEvent &event);
226 	void OnAuiNotebookPageClose(wxAuiNotebookEvent &event);
227 	void OnContextMenu(wxCommandEvent &event);
228 
229 	void OnPageChange(wxAuiNotebookEvent &event);
230 	void OnPropSelChanged(wxListEvent &event);
231 	void OnPropSelActivated(wxListEvent &event);
232 	void OnPropRightClick(wxListEvent &event);
233 	void OnTreeSelChanged(wxTreeEvent &event);
234 	void OnTreeKeyDown(wxTreeEvent &event);
235 	void OnSelActivated(wxTreeEvent &event);
236 	void OnSelRightClick(wxTreeEvent &event);
237 	void OnCollapse(wxTreeEvent &event);
238 	void OnExpand(wxTreeEvent &event);
239 	void OnClose(wxCloseEvent &event);
240 
241 	void OnNew(wxCommandEvent &event);
242 	void OnDelete(wxCommandEvent &ev);
243 	void OnCopy(wxCommandEvent &ev);
244 
245 	void OnCheckAlive(wxCommandEvent &event);
246 
247 	void OnPositionStc(wxStyledTextEvent &event);
248 
249 	void ResetLists();
250 	bool dropSingleObject(pgObject *data, bool updateFinal, bool cascaded);
251 	void doPopup(wxWindow *win, wxPoint point, pgObject *object);
252 	void setDisplay(pgObject *data, ctlListView *props = 0, ctlSQLBox *sqlbox = 0);
253 	void RetrieveServers();
254 	bool reportError(const wxString &error, const wxString &msgToIdentify, const wxString &hint);
255 	wxTreeItemId RestoreEnvironment(pgServer *server);
256 
257 	void GetExpandedChildNodes(wxTreeItemId node, wxArrayString &expandedNodes);
258 	void ExpandChildNodes(wxTreeItemId node, wxArrayString &expandedNodes);
259 
260 
261 	void PopulatePluginButtonMenu(wxCommandEvent &event);
262 
263 	// In plugins.cpp
264 	void LoadPluginUtilities();
265 	void AddPluginUtility(PluginUtility *util);
266 	void CreatePluginUtility(PluginUtility *util);
267 	void ClearPluginUtility(PluginUtility *util);
268 
269 	DECLARE_EVENT_TABLE()
270 };
271 
272 enum
273 {
274 	CTL_BROWSER = 301,
275 	CTL_NOTEBOOK,
276 	CTL_PROPVIEW,
277 	CTL_STATVIEW,
278 	CTL_DEPVIEW,
279 	CTL_REFVIEW,
280 	CTL_SQLPANE
281 };
282 
283 class contentsFactory : public actionFactory
284 {
285 public:
286 	contentsFactory(menuFactoryList *list, wxMenu *mnu, ctlMenuToolbar *toolbar);
287 	wxWindow *StartDialog(frmMain *form, pgObject *obj);
288 };
289 
290 
291 class pgsqlHelpFactory : public actionFactory
292 {
293 public:
294 	pgsqlHelpFactory(menuFactoryList *list, wxMenu *mnu, ctlMenuToolbar *toolbar, bool bigTool);
295 	wxWindow *StartDialog(frmMain *form, pgObject *obj);
296 };
297 
298 
299 class edbHelpFactory : public actionFactory
300 {
301 public:
302 	edbHelpFactory(menuFactoryList *list, wxMenu *mnu, ctlMenuToolbar *toolbar, bool bigTool);
303 	wxWindow *StartDialog(frmMain *form, pgObject *obj);
304 };
305 
306 class greenplumHelpFactory : public actionFactory
307 {
308 public:
309 	greenplumHelpFactory(menuFactoryList *list, wxMenu *mnu, ctlMenuToolbar *toolbar, bool bigTool);
310 	wxWindow *StartDialog(frmMain *form, pgObject *obj);
311 };
312 
313 class slonyHelpFactory : public actionFactory
314 {
315 public:
316 	slonyHelpFactory(menuFactoryList *list, wxMenu *mnu, ctlMenuToolbar *toolbar, bool bigTool);
317 	wxWindow *StartDialog(frmMain *form, pgObject *obj);
318 };
319 
320 
321 class faqFactory : public actionFactory
322 {
323 public:
324 	faqFactory(menuFactoryList *list, wxMenu *mnu, ctlMenuToolbar *toolbar);
325 	wxWindow *StartDialog(frmMain *form, pgObject *obj);
326 };
327 
328 
329 class bugReportFactory : public actionFactory
330 {
331 public:
332 	bugReportFactory(menuFactoryList *list, wxMenu *mnu, ctlMenuToolbar *toolbar);
333 	wxWindow *StartDialog(frmMain *form, pgObject *obj);
334 };
335 
336 class pluginUtilityFactory : public actionFactory
337 {
338 public:
339 	pluginUtilityFactory(menuFactoryList *list, wxMenu *menu, PluginUtility *util);
340 	wxWindow *StartDialog(frmMain *form, pgObject *obj);
341 	bool CheckEnable(pgObject *obj);
342 
343 private:
344 	bool HaveDatabase(pgObject *obj);
345 
346 	wxString title, command, description;
347 	bool database, set_password;
348 	wxArrayString applies_to, server_types, set_env;
349 };
350 
351 class pluginButtonMenuFactory : public actionFactory
352 {
353 public:
354 	pluginButtonMenuFactory(menuFactoryList *list, wxMenu *popupmenu, ctlMenuToolbar *toolbar, int pluginCount);
355 	wxWindow *StartDialog(frmMain *form, pgObject *obj);
356 	bool CheckEnable(pgObject *obj);
357 
358 private:
359 	ctlMenuButton *pulldownButton;
360 	bool enableButton;
361 };
362 
363 #endif
364