2 * @file GenericDialog.h
3 * Declares the GenericDialog class.
8 * Copyright 2012 Joel Baxter
10 * This file is part of MeshTex.
12 * MeshTex is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation, either version 2 of the License, or
15 * (at your option) any later version.
17 * MeshTex is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with MeshTex. If not, see <http://www.gnu.org/licenses/>.
26 #if !defined(INCLUDED_GENERICDIALOG_H)
27 #define INCLUDED_GENERICDIALOG_H
33 #include "RefCounted.h"
35 #include "qerplugin.h"
38 * Macro to get a handle on a widget inside the dialog by name.
40 * @param widgetName Name of the contained widget to find.
42 #define NamedWidget(widgetName) \
43 (gtk_object_get_data(GTK_OBJECT(_dialog), widgetName))
46 * Macro to enable/disable a widget inside the dialog, selected by name.
48 * @param widgetName Name of the contained widget to enable/disable.
50 #define NamedToggleWidgetActive(widgetName) \
51 (GTK_TOGGLE_BUTTON(NamedWidget(widgetName))->active)
54 * Macro to read text from a widget inside the dialog, selected by name.
56 * @param widgetName Name of the contained widget to read from.
58 #define NamedEntryWidgetText(widgetName) \
59 (gtk_entry_get_text(GTK_ENTRY(NamedWidget(widgetName))))
62 * Framework for a basic dialog window with OK/Apply/Cancel actions.
64 * A subclass should handle decorating/customizing the window, populating it
65 * with contained widgets, customizing the Apply logic, and registering the
66 * appropriate OK/Apply/Cancel buttons.
70 class GenericDialog : public RefCounted
72 protected: // protected methods
76 GenericDialog(const std::string& key);
77 virtual ~GenericDialog();
80 private: // private methods
82 /// @name Unimplemented to prevent copy/assignment
84 GenericDialog(const GenericDialog&);
85 const GenericDialog& operator=(const GenericDialog&);
88 public: // public methods
90 /// @name Interrogation
92 const std::string& GetKey() const;
94 /// @name Window management
96 virtual void SetWindow(GtkWidget *window);
98 virtual void Show(const std::string& triggerCommand);
101 /// @name Callback implementation
103 virtual bool Apply();
104 virtual gint CloseEventCallback(GtkWidget *widget,
106 gpointer callbackID);
107 virtual void FinalizeCallback(GtkWidget *widget,
108 gpointer callbackID);
110 /// @name Callback creation
112 void CreateWindowCloseCallback();
113 void CreateOkButtonCallback(GtkWidget *button);
114 void CreateApplyButtonCallback(GtkWidget *button);
115 void CreateCancelButtonCallback(GtkWidget *button);
118 protected: // protected member vars
121 * This dialog widget.
131 * Unique key for this dialog.
133 const std::string _key;
136 * Command token that most recently summoned this dialog.
138 std::string _triggerCommand;
141 * Callback ID associated with an OK button; 0 if none.
143 gpointer _okCallbackID;
146 * Callback ID associated with an Apply button; 0 if none.
148 gpointer _applyCallbackID;
151 * Callback ID associated with a Cancel button; 0 if none.
153 gpointer _cancelCallbackID;
156 #endif // #if !defined(INCLUDED_GENERICDIALOG_H)