]> git.tdb.fi Git - libs/gltk.git/blob - source/dialog.h
6f3556586939eeabf882a3661d8063d41dcd8d03
[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
24         private:
25                 void action_button(const std::string &, int);
26         };
27
28         sigc::signal<void, int> signal_response;
29
30 private:
31         bool stale = false;
32
33 public:
34         const char *get_class() const override { return "dialog"; }
35
36         /** Adds an action button to the dialog.  Pressing the button will invoke
37         response handlers and delete the dialog. */
38         void add_button(Button &, int);
39
40         /** Sets the modality of the dialog.  When modal, the user can't navigate
41         away from the dialog. */
42         void set_modal(bool);
43
44         void button_release(int, int, unsigned) override;
45         bool key_release(unsigned, unsigned) override;
46         bool navigate(Navigation) override;
47 protected:
48         void response(int);
49         void check_stale();
50
51         /** Called when an action button is pressed. */
52         virtual void on_response(int) { }
53 };
54
55 } // namespace GLtk
56 } // namespace Msp
57
58 #endif