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