Remove most using declarations from header files.
[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 #include <gtkmm/widget.h>
30 #include <gtkmm/style.h>
31 #ifndef GTK_NEW_TOOLTIP_API
32 #include <gtkmm/tooltips.h>
33 #endif
34 #include <gtkmm/textbuffer.h>
35 #include <gtkmm/main.h>
36 #include <gdkmm/color.h>
37 #include <pbd/abstract_ui.h>
38 #include <pbd/ringbufferNPT.h>
39  
40 #include <pbd/pool.h>
41 #include <pbd/error.h>
42 #include <pbd/receiver.h>
43
44 class Touchable;
45
46 namespace Gtkmm2ext {
47
48 class TextViewer;
49
50 extern BaseUI::RequestType ErrorMessage;
51 extern BaseUI::RequestType Quit;
52 extern BaseUI::RequestType CallSlot;
53 extern BaseUI::RequestType TouchDisplay;
54 extern BaseUI::RequestType StateChange;
55 extern BaseUI::RequestType SetTip;
56 extern BaseUI::RequestType AddIdle;
57 extern BaseUI::RequestType AddTimeout;
58
59 struct UIRequest : public BaseUI::BaseRequestObject {
60      
61      /* this once used anonymous unions to merge elements
62         that are never part of the same request. that makes
63         the creation of a legal copy constructor difficult
64         because of the semantics of the slot member.
65      */
66      
67     Touchable *display;
68     const char *msg;
69     Gtk::StateType new_state;
70     int (*function)(void *);
71     Gtk::Widget *widget;
72     Transmitter::Channel chn;
73     void *arg;
74     const char *msg2;
75     sigc::slot<void> slot;
76     
77     ~UIRequest () { 
78             if (type == ErrorMessage && msg) {
79                     /* msg was strdup()'ed */
80                     free ((char *)msg);
81             }
82     }
83  };
84
85 class UI : public Receiver, public AbstractUI<UIRequest>
86 {
87   public:
88         UI (std::string name, int *argc, char **argv[]);
89         virtual ~UI ();
90
91         static UI *instance() { return theGtkUI; }
92
93         /* receiver interface */
94
95         void receive (Transmitter::Channel, const char *);
96
97         /* Abstract UI interfaces */
98
99         bool caller_is_ui_thread ();
100
101         static pthread_t thread_id() { return gui_thread; }
102
103         /* Gtk-UI specific interfaces */
104
105         bool running ();
106         void quit    ();
107         void kill    ();
108         int  load_rcfile (std::string, bool themechange = false);
109         void run (Receiver &old_receiver);
110
111         void set_state (Gtk::Widget *w, Gtk::StateType state);
112         void popup_error (const char *text);
113         void flush_pending ();
114         void toggle_errors ();
115         void touch_display (Touchable *);
116         void set_tip (Gtk::Widget *w, const gchar *tip, const gchar *hlp);
117         void idle_add (int (*func)(void *), void *arg);
118
119         Gtk::Main& main() const { return *theMain; }
120
121         template<class T> static bool idle_delete (T *obj) { delete obj; return false; }
122         template<class T> static void delete_when_idle (T *obj) {
123                 Glib::signal_idle().connect (bind (slot (&UI::idle_delete<T>), obj));
124         }
125
126         Gdk::Color get_color (const std::string& prompt, bool& picked, const Gdk::Color *initial = 0);
127
128         /* starting is sent just before we enter the main loop,
129            stopping just after we return from it (at the top level)
130         */
131
132         sigc::signal<void> starting;
133         sigc::signal<void> stopping;
134
135         sigc::signal<void> theme_changed;
136
137         static bool just_hide_it (GdkEventAny *, Gtk::Window *);
138
139         static pthread_t the_gui_thread() { return gui_thread; }
140         
141   protected:
142         virtual void handle_fatal (const char *);
143         virtual void display_message (const char *prefix, gint prefix_len, 
144                                       Glib::RefPtr<Gtk::TextBuffer::Tag> ptag, 
145                                       Glib::RefPtr<Gtk::TextBuffer::Tag> mtag, 
146                                       const char *msg);
147
148   private:
149         static UI *theGtkUI;
150         static pthread_t gui_thread;
151         bool _active;
152         Gtk::Main *theMain;
153 #ifndef GTK_NEW_TOOLTIP_API
154         Gtk::Tooltips *tips;
155 #endif
156         TextViewer *errors;
157         Glib::RefPtr<Gtk::TextBuffer::Tag> error_ptag;
158         Glib::RefPtr<Gtk::TextBuffer::Tag> error_mtag;
159         Glib::RefPtr<Gtk::TextBuffer::Tag> fatal_ptag;
160         Glib::RefPtr<Gtk::TextBuffer::Tag> fatal_mtag;
161         Glib::RefPtr<Gtk::TextBuffer::Tag> info_ptag;
162         Glib::RefPtr<Gtk::TextBuffer::Tag> info_mtag;
163         Glib::RefPtr<Gtk::TextBuffer::Tag> warning_ptag;
164         Glib::RefPtr<Gtk::TextBuffer::Tag> warning_mtag;
165
166         static void signal_pipe_callback (void *, gint, GdkInputCondition);
167         void process_error_message (Transmitter::Channel, const char *);
168         void do_quit ();
169
170         void color_selection_done (bool status);
171         bool color_selection_deleted (GdkEventAny *);
172         bool color_picked;
173
174         void do_request (UIRequest*);
175 };
176
177 } /* namespace */
178
179 #endif /* __pbd_gtk_ui_h__ */