]> git.tdb.fi Git - libs/gltk.git/blob - source/dialog.h
e71222739cc415acf1876f3e1f3e60a560f11752
[libs/gltk.git] / source / dialog.h
1 #ifndef MSP_GLTK_DIALOG_H_
2 #define MSP_GLTK_DIALOG_H_
3
4 #include "mspgltk_api.h"
5 #include "panel.h"
6
7 namespace Msp {
8 namespace GLtk {
9
10 class Button;
11
12 /**
13 A Dialog is used for temporary interaction with the user.  When any of the
14 Dialog's action buttons are clicked, it will emit a signal and delete itself.
15 */
16 class MSPGLTK_API Dialog: public Panel
17 {
18 public:
19         class MSPGLTK_API Loader: public DataFile::DerivedObjectLoader<Dialog, Panel::Loader>
20         {
21         public:
22                 Loader(Dialog &, WidgetMap &);
23         private:
24                 void action_button(const std::string &, int);
25         };
26
27         sigc::signal<void, int> signal_response;
28
29 private:
30         bool stale = false;
31
32 public:
33         virtual const char *get_class() const { return "dialog"; }
34
35         /** Adds an action button to the dialog.  Pressing the button will invoke
36         response handlers and delete the dialog. */
37         void add_button(Button &, int);
38
39         /** Sets the modality of the dialog.  When modal, the user can't navigate
40         away from the dialog. */
41         void set_modal(bool);
42
43         virtual void button_release(int, int, unsigned);
44         virtual bool key_release(unsigned, unsigned);
45         virtual bool navigate(Navigation);
46 protected:
47         void response(int);
48         void check_stale();
49
50         /** Called when an action button is pressed. */
51         virtual void on_response(int) { }
52 };
53
54 } // namespace GLtk
55 } // namespace Msp
56
57 #endif