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__
30 #include <gtkmm/widget.h>
31 #include <gtkmm/style.h>
32 #ifndef GTK_NEW_TOOLTIP_API
33 #include <gtkmm/tooltips.h>
35 #include <gtkmm/textbuffer.h>
36 #include <gtkmm/main.h>
37 #include <gdkmm/color.h>
38 #include <pbd/abstract_ui.h>
39 #include <pbd/ringbufferNPT.h>
42 #include <pbd/error.h>
43 #include <pbd/receiver.h>
54 extern BaseUI::RequestType ErrorMessage;
55 extern BaseUI::RequestType Quit;
56 extern BaseUI::RequestType CallSlot;
57 extern BaseUI::RequestType TouchDisplay;
58 extern BaseUI::RequestType StateChange;
59 extern BaseUI::RequestType SetTip;
60 extern BaseUI::RequestType AddIdle;
61 extern BaseUI::RequestType AddTimeout;
63 struct UIRequest : public BaseUI::BaseRequestObject {
65 /* this once used anonymous unions to merge elements
66 that are never part of the same request. that makes
67 the creation of a legal copy constructor difficult
68 because of the semantics of the slot member.
73 Gtk::StateType new_state;
74 int (*function)(void *);
76 Transmitter::Channel chn;
79 sigc::slot<void> slot;
82 if (type == ErrorMessage && msg) {
83 /* msg was strdup()'ed */
89 class UI : public Receiver, public AbstractUI<UIRequest>
92 UI (string name, int *argc, char **argv[]);
95 static UI *instance() { return theGtkUI; }
97 /* receiver interface */
99 void receive (Transmitter::Channel, const char *);
101 /* Abstract UI interfaces */
103 bool caller_is_ui_thread ();
105 static pthread_t thread_id() { return gui_thread; }
107 /* Gtk-UI specific interfaces */
112 int load_rcfile (string, bool themechange = false);
113 void run (Receiver &old_receiver);
115 void set_state (Gtk::Widget *w, Gtk::StateType state);
116 void popup_error (const char *text);
117 void flush_pending ();
118 void toggle_errors ();
119 void touch_display (Touchable *);
120 void set_tip (Gtk::Widget *w, const gchar *tip, const gchar *hlp);
121 void idle_add (int (*func)(void *), void *arg);
123 Gtk::Main& main() const { return *theMain; }
125 template<class T> static bool idle_delete (T *obj) { delete obj; return false; }
126 template<class T> static void delete_when_idle (T *obj) {
127 Glib::signal_idle().connect (bind (slot (&UI::idle_delete<T>), obj));
130 Gdk::Color get_color (const string& prompt, bool& picked, const Gdk::Color *initial = 0);
132 /* starting is sent just before we enter the main loop,
133 stopping just after we return from it (at the top level)
136 sigc::signal<void> starting;
137 sigc::signal<void> stopping;
139 sigc::signal<void> theme_changed;
141 static bool just_hide_it (GdkEventAny *, Gtk::Window *);
143 static pthread_t the_gui_thread() { return gui_thread; }
146 virtual void handle_fatal (const char *);
147 virtual void display_message (const char *prefix, gint prefix_len,
148 Glib::RefPtr<Gtk::TextBuffer::Tag> ptag,
149 Glib::RefPtr<Gtk::TextBuffer::Tag> mtag,
154 static pthread_t gui_thread;
157 #ifndef GTK_NEW_TOOLTIP_API
161 Glib::RefPtr<Gtk::TextBuffer::Tag> error_ptag;
162 Glib::RefPtr<Gtk::TextBuffer::Tag> error_mtag;
163 Glib::RefPtr<Gtk::TextBuffer::Tag> fatal_ptag;
164 Glib::RefPtr<Gtk::TextBuffer::Tag> fatal_mtag;
165 Glib::RefPtr<Gtk::TextBuffer::Tag> info_ptag;
166 Glib::RefPtr<Gtk::TextBuffer::Tag> info_mtag;
167 Glib::RefPtr<Gtk::TextBuffer::Tag> warning_ptag;
168 Glib::RefPtr<Gtk::TextBuffer::Tag> warning_mtag;
170 static void signal_pipe_callback (void *, gint, GdkInputCondition);
171 void process_error_message (Transmitter::Channel, const char *);
174 void color_selection_done (bool status);
175 bool color_selection_deleted (GdkEventAny *);
178 void do_request (UIRequest*);
183 #endif /* __pbd_gtk_ui_h__ */