1 #ifndef MSP_GLTK_DIALOG_H_
2 #define MSP_GLTK_DIALOG_H_
4 #include "mspgltk_api.h"
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 hide itself.
16 class MSPGLTK_API Dialog: public Panel
19 class MSPGLTK_API Loader: public DataFile::DerivedObjectLoader<Dialog, Panel::Loader>
22 Loader(Dialog &, WidgetMap &);
25 void action_button(const std::string &, int);
28 sigc::signal<void, int> signal_response;
30 const char *get_class() const override { return "dialog"; }
32 /** Adds an action button to the dialog. Pressing the button will invoke
33 response handlers and delete the dialog. */
34 void add_button(Button &, int);
36 void add_button(std::unique_ptr<Button>, int);
38 Button &add_button(const std::string &, int);
40 /** Sets the modality of the dialog. When modal, the user can't navigate
41 away from the dialog. */
45 void connect_button(Button &, int);
48 /** Called when an action button is pressed. */
49 virtual void on_response(int) { }
54 A dialog which automatically deletes itself after being responded to.
57 class MSPGLTK_API AutoDialog: public D
64 StaleChecker(AutoDialog &d): dialog(&d) { }
65 ~StaleChecker() { if(dialog->stale) delete dialog; }
70 template<typename... Args>
71 AutoDialog(Args &&... args): D(std::forward<Args>(args)...) { }
74 // Ensure that AutoDialog is always created with new.
75 template<typename... Args>
76 static AutoDialog *create(Args &&... args) { return new AutoDialog(std::forward<Args>(args)...); }
78 void button_release(int x, int y, unsigned b) override { StaleChecker sc(*this); D::button_release(x, y, b); }
79 bool key_release(unsigned k, unsigned m) override { StaleChecker sc(*this); return D::key_release(k, m); }
80 bool navigate(Navigation n) override { StaleChecker sc(*this); return D::navigate(n); }
83 void on_response(int c) override { D::on_response(c); stale = true; }