globally remove all trailing whitespace from ardour code base.
[ardour.git] / libs / gtkmm2ext / gtkmm2ext / gtk_ui.h
1 /*
2     Copyright (C) 1999 Paul Barton-Davis
3
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.
8
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.
13
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.
17
18 */
19
20 #ifndef __pbd_gtk_ui_h__
21 #define __pbd_gtk_ui_h__
22
23 #include <string>
24 #include <map>
25
26 #include <stdint.h>
27 #include <setjmp.h>
28 #include <pthread.h>
29
30 #ifdef interface
31 #undef interface
32 #endif
33
34 #include <glibmm/thread.h>
35
36 #include <gtkmm/widget.h>
37 #include <gtkmm/style.h>
38 #ifndef GTK_NEW_TOOLTIP_API
39 #include <gtkmm/tooltips.h>
40 #endif
41 #include <gtkmm/textbuffer.h>
42 #include <gtkmm/main.h>
43 #include <gdkmm/color.h>
44
45 #ifndef ABSTRACT_UI_EXPORTS
46 #define ABSTRACT_UI_EXPORTS
47 #endif
48 #include "pbd/abstract_ui.h"
49 #include "pbd/ringbufferNPT.h"
50 #include "pbd/pool.h"
51 #include "pbd/error.h"
52 #include "pbd/receiver.h"
53
54 #include "gtkmm2ext/visibility.h"
55
56 class Touchable;
57
58 namespace Gtkmm2ext {
59
60 class TextViewer;
61
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;
70
71 struct LIBGTKMM2EXT_API UIRequest : public BaseUI::BaseRequestObject {
72
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.
77      */
78
79     Touchable *display;
80     const char *msg;
81     Gtk::StateType new_state;
82     int (*function)(void *);
83     Gtk::Widget *widget;
84     Transmitter::Channel chn;
85     void *arg;
86     const char *msg2;
87
88     UIRequest () {
89             type = NullMessage;
90     }
91
92     ~UIRequest () {
93             if (type == ErrorMessage && msg) {
94                     /* msg was strdup()'ed */
95                     free (const_cast<char *>(msg));
96             }
97     }
98 };
99
100 class LIBGTKMM2EXT_API UI : public AbstractUI<UIRequest>
101 {
102   private:
103         class MyReceiver : public Receiver {
104           public:
105                 MyReceiver (UI& ui) : _ui (ui) {}
106                 void receive (Transmitter::Channel chn, const char *msg) {
107                         _ui.receive (chn, msg);
108                 }
109           private:
110                 UI& _ui;
111         };
112
113         MyReceiver _receiver;
114
115   public:
116         UI (std::string name, int *argc, char **argv[]);
117         virtual ~UI ();
118
119         static UI *instance() { return theGtkUI; }
120
121         /* receiver interface */
122
123         void receive (Transmitter::Channel, const char *);
124
125         /* Abstract UI interfaces */
126
127         bool caller_is_ui_thread ();
128
129         /* Gtk-UI specific interfaces */
130
131         bool running ();
132         void quit    ();
133         int  load_rcfile (std::string, bool themechange = false);
134         void run (Receiver &old_receiver);
135
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 ();
140         void show_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);
147
148         Gtk::Main& main() const { return *theMain; }
149
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));
153         }
154
155         template<class T> void delete_in_self (T *obj) {
156                 call_slot (boost::bind (&UI::delete_in_self, this, obj));
157         }
158
159         Gdk::Color get_color (const std::string& prompt, bool& picked, const Gdk::Color *initial = 0);
160
161         /* starting is sent just before we enter the main loop,
162            stopping just after we return from it (at the top level)
163         */
164
165         virtual int starting() = 0;
166
167         sigc::signal<void> theme_changed;
168
169         static bool just_hide_it (GdkEventAny *, Gtk::Window *);
170         
171   protected:
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,
175                         const char *msg);
176
177   private:
178         static UI *theGtkUI;
179
180         bool _active;
181         Gtk::Main *theMain;
182 #ifndef GTK_NEW_TOOLTIP_API
183         Gtk::Tooltips *tips;
184 #endif
185         TextViewer *errors;
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;
194
195         static void signal_pipe_callback (void *, gint, GdkInputCondition);
196         void process_error_message (Transmitter::Channel, const char *);
197         void do_quit ();
198
199         Glib::Threads::Mutex   error_lock;
200         std::list<std::string> error_stack;
201
202         void color_selection_done (bool status);
203         bool color_selection_deleted (GdkEventAny *);
204         bool color_picked;
205
206         void do_request (UIRequest*);
207
208 };
209
210 } /* namespace */
211
212 #endif /* __pbd_gtk_ui_h__ */