summaryrefslogtreecommitdiff
path: root/src/gui_gtk.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui_gtk.cc')
-rw-r--r--src/gui_gtk.cc71
1 files changed, 71 insertions, 0 deletions
diff --git a/src/gui_gtk.cc b/src/gui_gtk.cc
index 0c251a9..062ac4c 100644
--- a/src/gui_gtk.cc
+++ b/src/gui_gtk.cc
@@ -16,6 +16,7 @@
#include "gui_listmodel.hh"
#include "gui_main.hh"
#include "gui_menu.hh"
+#include "gui_message.hh"
#include "gui_statusbar.hh"
#include "gui_textwnd.hh"
#include "looper.hh"
@@ -1501,6 +1502,69 @@ private:
bool applied_;
};
+class GtkGuiMessage : public virtual GuiMessage, public GtkGuiWindow {
+public:
+ GtkGuiMessage(Type type, std::string const& title, std::string const& text)
+ : type_(type), title_(title), text_(text), dialog_(nullptr) {
+ }
+
+ ~GtkGuiMessage() override {
+ assert(!dialog_);
+ }
+
+ void set_title(std::string const& title) override {
+ title_ = title;
+ GtkGuiWindow::set_title(title);
+ }
+ std::string const& title() const override {
+ return title_;
+ }
+
+ void* impl() const override {
+ return dialog_;
+ }
+
+ void add_listener(GuiMessage::Listener* listener) override {
+ observers_.insert(listener);
+ }
+
+ void remove_listener(GuiMessage::Listener* listener) override {
+ observers_.erase(listener);
+ }
+
+ void show(GuiWindow* parent) override {
+ if (dialog_) {
+ assert(false);
+ return;
+ }
+ GtkMessageType type = GTK_MESSAGE_OTHER;
+ switch (type_) {
+ case ERROR:
+ type = GTK_MESSAGE_ERROR;
+ break;
+ case OTHER:
+ break;
+ }
+ dialog_ = gtk_message_dialog_new(
+ reinterpret_cast<GtkWindow*>(parent->impl()),
+ GTK_DIALOG_MODAL,
+ type,
+ GTK_BUTTONS_CLOSE,
+ "%s",
+ text_.c_str());
+ gtk_dialog_run(GTK_DIALOG(dialog_));
+ gtk_widget_destroy(dialog_);
+ dialog_ = nullptr;
+ }
+
+protected:
+ Type type_;
+ std::string title_;
+ std::string text_;
+ Observers<GuiMessage::Listener*> observers_;
+ GtkWidget* dialog_;
+};
+
class GtkGuiTextWindow : public virtual GuiTextWindow, public GtkGuiWindow {
public:
GtkGuiTextWindow(std::string const& title, uint32_t width, uint32_t height,
@@ -2140,6 +2204,13 @@ GuiFormApply* GuiFormApply::create(std::string const& title,
}
// static
+GuiMessage* GuiMessage::create(Type type,
+ std::string const& title,
+ std::string const& text) {
+ return new GtkGuiMessage(type, title, text);
+}
+
+// static
Looper* GuiMain::createLooper() {
return new GtkLooper();
}