]> git.xonotic.org Git - xonotic/netradiant.git/blob - contrib/meshtex/GenericDialog.h
* added MeshTex plugin src to project (can't compile)
[xonotic/netradiant.git] / contrib / meshtex / GenericDialog.h
1 /**
2  * @file GenericDialog.h
3  * Declares the GenericDialog class.
4  * @ingroup generic-ui
5  */
6
7 /*
8  * Copyright 2012 Joel Baxter
9  *
10  * This file is part of MeshTex.
11  *
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.
16  *
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.
21  *
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/>.
24  */
25
26 #if !defined(INCLUDED_GENERICDIALOG_H)
27 #define INCLUDED_GENERICDIALOG_H
28
29 #include <string>
30 #include <gdk/gdk.h>
31 #include <glib.h>
32
33 #include "RefCounted.h"
34
35 #include "qerplugin.h"
36
37 /**
38  * Macro to get a handle on a widget inside the dialog by name.
39  *
40  * @param widgetName Name of the contained widget to find.
41  */
42 #define NamedWidget(widgetName) \
43    (gtk_object_get_data(GTK_OBJECT(_dialog), widgetName))
44
45 /**
46  * Macro to enable/disable a widget inside the dialog, selected by name.
47  *
48  * @param widgetName Name of the contained widget to enable/disable.
49  */
50 #define NamedToggleWidgetActive(widgetName) \
51    (GTK_TOGGLE_BUTTON(NamedWidget(widgetName))->active)
52
53 /**
54  * Macro to read text from a widget inside the dialog, selected by name.
55  *
56  * @param widgetName Name of the contained widget to read from.
57  */
58 #define NamedEntryWidgetText(widgetName) \
59    (gtk_entry_get_text(GTK_ENTRY(NamedWidget(widgetName))))
60
61 /**
62  * Framework for a basic dialog window with OK/Apply/Cancel actions.
63  *
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.
67  *
68  * @ingroup generic-ui
69  */
70 class GenericDialog : public RefCounted
71 {
72 protected: // protected methods
73
74    /// @name Lifecycle
75    //@{
76    GenericDialog(const std::string& key);
77    virtual ~GenericDialog();
78    //@}
79
80 private: // private methods
81
82    /// @name Unimplemented to prevent copy/assignment
83    //@{
84    GenericDialog(const GenericDialog&);
85    const GenericDialog& operator=(const GenericDialog&);
86    //@}
87
88 public: // public methods
89
90    /// @name Interrogation
91    //@{
92    const std::string& GetKey() const;
93    //@}
94    /// @name Window management
95    //@{
96    virtual void SetWindow(GtkWidget *window);
97    virtual void Raise();
98    virtual void Show(const std::string& triggerCommand);
99    virtual void Hide();
100    //@}
101    /// @name Callback implementation
102    //@{
103    virtual bool Apply();
104    virtual gint CloseEventCallback(GtkWidget *widget,
105                                    GdkEvent* event,
106                                    gpointer callbackID);
107    virtual void FinalizeCallback(GtkWidget *widget,
108                                  gpointer callbackID);
109    //@}
110    /// @name Callback creation
111    //@{
112    void CreateWindowCloseCallback();
113    void CreateOkButtonCallback(GtkWidget *button);
114    void CreateApplyButtonCallback(GtkWidget *button);
115    void CreateCancelButtonCallback(GtkWidget *button);
116    //@}
117
118 protected: // protected member vars
119
120    /**
121     * This dialog widget.
122     */
123    GtkWidget *_dialog;
124
125    /**
126     * Parent window.
127     */
128    GtkWidget *_window;
129
130    /**
131     * Unique key for this dialog.
132     */
133    const std::string _key;
134
135    /**
136     * Command token that most recently summoned this dialog.
137     */
138    std::string _triggerCommand;
139
140    /**
141     * Callback ID associated with an OK button; 0 if none.
142     */
143    gpointer _okCallbackID;
144
145    /**
146     * Callback ID associated with an Apply button; 0 if none.
147     */
148    gpointer _applyCallbackID;
149
150    /**
151     * Callback ID associated with a Cancel button; 0 if none.
152     */
153    gpointer _cancelCallbackID;
154 };
155
156 #endif // #if !defined(INCLUDED_GENERICDIALOG_H)