2 Copyright (C) 1999 Paul Barton-Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #ifndef __pbd_gtk_ui_h__
21 #define __pbd_gtk_ui_h__
34 #include <glibmm/thread.h>
36 #include <gtkmm/widget.h>
37 #include <gtkmm/style.h>
38 #ifndef GTK_NEW_TOOLTIP_API
39 #include <gtkmm/tooltips.h>
41 #include <gtkmm/textbuffer.h>
42 #include <gtkmm/main.h>
43 #include <gdkmm/color.h>
45 #ifndef ABSTRACT_UI_EXPORTS
46 #define ABSTRACT_UI_EXPORTS
48 #include "pbd/abstract_ui.h"
49 #include "pbd/ringbufferNPT.h"
51 #include "pbd/error.h"
52 #include "pbd/receiver.h"
54 #include "gtkmm2ext/visibility.h"
62 extern BaseUI::RequestType NullMessage;
63 extern BaseUI::RequestType ErrorMessage;
64 extern BaseUI::RequestType CallSlot;
65 extern BaseUI::RequestType TouchDisplay;
66 extern BaseUI::RequestType StateChange;
67 extern BaseUI::RequestType SetTip;
68 extern BaseUI::RequestType AddIdle;
69 extern BaseUI::RequestType AddTimeout;
71 struct LIBGTKMM2EXT_API UIRequest : public BaseUI::BaseRequestObject {
73 /* this once used anonymous unions to merge elements
74 that are never part of the same request. that makes
75 the creation of a legal copy constructor difficult
76 because of the semantics of the slot member.
81 Gtk::StateType new_state;
82 int (*function)(void *);
84 Transmitter::Channel chn;
93 if (type == ErrorMessage && msg) {
94 /* msg was strdup()'ed */
95 free (const_cast<char *>(msg));
100 class LIBGTKMM2EXT_API UI : public AbstractUI<UIRequest>
103 class MyReceiver : public Receiver {
105 MyReceiver (UI& ui) : _ui (ui) {}
106 void receive (Transmitter::Channel chn, const char *msg) {
107 _ui.receive (chn, msg);
113 MyReceiver _receiver;
116 UI (std::string name, int *argc, char **argv[]);
119 static UI *instance() { return theGtkUI; }
121 /* receiver interface */
123 void receive (Transmitter::Channel, const char *);
125 /* Abstract UI interfaces */
127 bool caller_is_ui_thread ();
129 /* Gtk-UI specific interfaces */
133 int load_rcfile (std::string, bool themechange = false);
134 void run (Receiver &old_receiver);
136 void set_state (Gtk::Widget *w, Gtk::StateType state);
137 void popup_error (const std::string& text);
138 void flush_pending ();
139 void toggle_errors ();
141 void dump_errors (std::ostream&);
142 void touch_display (Touchable *);
143 void set_tip (Gtk::Widget &w, const gchar *tip);
144 void set_tip (Gtk::Widget &w, const std::string &tip);
145 void set_tip (Gtk::Widget *w, const gchar *tip, const gchar *hlp="");
146 void idle_add (int (*func)(void *), void *arg);
148 Gtk::Main& main() const { return *theMain; }
150 template<class T> static bool idle_delete (T *obj) { delete obj; return false; }
151 template<class T> static void delete_when_idle (T *obj) {
152 Glib::signal_idle().connect (bind (slot (&UI::idle_delete<T>), obj));
155 template<class T> void delete_in_self (T *obj) {
156 call_slot (boost::bind (&UI::delete_in_self, this, obj));
159 Gdk::Color get_color (const std::string& prompt, bool& picked, const Gdk::Color *initial = 0);
161 /* starting is sent just before we enter the main loop,
162 stopping just after we return from it (at the top level)
165 virtual int starting() = 0;
167 sigc::signal<void> theme_changed;
169 static bool just_hide_it (GdkEventAny *, Gtk::Window *);
172 virtual void handle_fatal (const char *);
173 virtual void display_message (const char *prefix, gint prefix_len,
174 Glib::RefPtr<Gtk::TextBuffer::Tag> ptag, Glib::RefPtr<Gtk::TextBuffer::Tag> mtag,
182 #ifndef GTK_NEW_TOOLTIP_API
186 Glib::RefPtr<Gtk::TextBuffer::Tag> error_ptag;
187 Glib::RefPtr<Gtk::TextBuffer::Tag> error_mtag;
188 Glib::RefPtr<Gtk::TextBuffer::Tag> fatal_ptag;
189 Glib::RefPtr<Gtk::TextBuffer::Tag> fatal_mtag;
190 Glib::RefPtr<Gtk::TextBuffer::Tag> info_ptag;
191 Glib::RefPtr<Gtk::TextBuffer::Tag> info_mtag;
192 Glib::RefPtr<Gtk::TextBuffer::Tag> warning_ptag;
193 Glib::RefPtr<Gtk::TextBuffer::Tag> warning_mtag;
195 static void signal_pipe_callback (void *, gint, GdkInputCondition);
196 void process_error_message (Transmitter::Channel, const char *);
199 Glib::Threads::Mutex error_lock;
200 std::list<std::string> error_stack;
202 void color_selection_done (bool status);
203 bool color_selection_deleted (GdkEventAny *);
206 void do_request (UIRequest*);
212 #endif /* __pbd_gtk_ui_h__ */