ardour
gtk_ui.h
Go to the documentation of this file.
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 
70 
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 
80  const char *msg;
81  Gtk::StateType new_state;
82  int (*function)(void *);
83  Gtk::Widget *widget;
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 
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 touch_display (Touchable *);
142  void set_tip (Gtk::Widget &w, const gchar *tip);
143  void set_tip (Gtk::Widget &w, const std::string &tip);
144  void set_tip (Gtk::Widget *w, const gchar *tip, const gchar *hlp="");
145  void idle_add (int (*func)(void *), void *arg);
146 
147  Gtk::Main& main() const { return *theMain; }
148 
149  template<class T> static bool idle_delete (T *obj) { delete obj; return false; }
150  template<class T> static void delete_when_idle (T *obj) {
151  Glib::signal_idle().connect (bind (slot (&UI::idle_delete<T>), obj));
152  }
153 
154  template<class T> void delete_in_self (T *obj) {
155  call_slot (boost::bind (&UI::delete_in_self, this, obj));
156  }
157 
158  Gdk::Color get_color (const std::string& prompt, bool& picked, const Gdk::Color *initial = 0);
159 
160  /* starting is sent just before we enter the main loop,
161  stopping just after we return from it (at the top level)
162  */
163 
164  virtual int starting() = 0;
165 
166  sigc::signal<void> theme_changed;
167 
168  static bool just_hide_it (GdkEventAny *, Gtk::Window *);
169 
170  protected:
171  virtual void handle_fatal (const char *);
172  virtual void display_message (const char *prefix, gint prefix_len,
173  Glib::RefPtr<Gtk::TextBuffer::Tag> ptag, Glib::RefPtr<Gtk::TextBuffer::Tag> mtag,
174  const char *msg);
175 
176  private:
177  static UI *theGtkUI;
178 
179  bool _active;
180  Gtk::Main *theMain;
181 #ifndef GTK_NEW_TOOLTIP_API
182  Gtk::Tooltips *tips;
183 #endif
185  Glib::RefPtr<Gtk::TextBuffer::Tag> error_ptag;
186  Glib::RefPtr<Gtk::TextBuffer::Tag> error_mtag;
187  Glib::RefPtr<Gtk::TextBuffer::Tag> fatal_ptag;
188  Glib::RefPtr<Gtk::TextBuffer::Tag> fatal_mtag;
189  Glib::RefPtr<Gtk::TextBuffer::Tag> info_ptag;
190  Glib::RefPtr<Gtk::TextBuffer::Tag> info_mtag;
191  Glib::RefPtr<Gtk::TextBuffer::Tag> warning_ptag;
192  Glib::RefPtr<Gtk::TextBuffer::Tag> warning_mtag;
193 
194  static void signal_pipe_callback (void *, gint, GdkInputCondition);
195  void process_error_message (Transmitter::Channel, const char *);
196  void do_quit ();
197 
198  void color_selection_done (bool status);
199  bool color_selection_deleted (GdkEventAny *);
201 
202  void do_request (UIRequest*);
203 
204 };
205 
206 } /* namespace */
207 
208 #endif /* __pbd_gtk_ui_h__ */
TextViewer * errors
Definition: gtk_ui.h:184
static ARDOUR_UI * ui
Definition: main.cc:76
void receive(Transmitter::Channel chn, const char *msg)
Definition: gtk_ui.h:106
Glib::RefPtr< Gtk::TextBuffer::Tag > info_ptag
Definition: gtk_ui.h:189
static bool idle_delete(T *obj)
Definition: gtk_ui.h:149
Glib::RefPtr< Gtk::TextBuffer::Tag > warning_ptag
Definition: gtk_ui.h:191
BaseUI::RequestType AddIdle
Definition: gtk_ui.cc:63
Gtk::StateType new_state
Definition: gtk_ui.h:81
BaseUI::RequestType ErrorMessage
Definition: gtk_ui.cc:59
Glib::RefPtr< Gtk::TextBuffer::Tag > info_mtag
Definition: gtk_ui.h:190
LIBGTKMM2EXT_API
BaseUI::RequestType TouchDisplay
Definition: gtk_ui.cc:60
void delete_in_self(T *obj)
Definition: gtk_ui.h:154
BaseUI::RequestType SetTip
Definition: gtk_ui.cc:62
BaseUI::RequestType AddTimeout
Definition: gtk_ui.cc:64
const char * msg2
Definition: gtk_ui.h:86
BaseUI::RequestType StateChange
Definition: gtk_ui.cc:61
static UI * theGtkUI
Definition: gtk_ui.h:177
bool _active
Definition: gtk_ui.h:179
Gtk::Main & main() const
Definition: gtk_ui.h:147
Glib::RefPtr< Gtk::TextBuffer::Tag > fatal_mtag
Definition: gtk_ui.h:188
static UI * instance()
Definition: gtk_ui.h:119
Gtk::Tooltips * tips
Definition: gtk_ui.h:182
gint just_hide_it(GdkEventAny *, Gtk::Window *)
Definition: utils.cc:92
const char * msg
Definition: gtk_ui.h:80
Transmitter::Channel chn
Definition: gtk_ui.h:84
static void delete_when_idle(T *obj)
Definition: gtk_ui.h:150
Touchable * display
Definition: gtk_ui.h:79
sigc::signal< void > theme_changed
Definition: gtk_ui.h:166
Gtk::Main * theMain
Definition: gtk_ui.h:180
bool color_picked
Definition: gtk_ui.h:200
BaseUI::RequestType CallSlot
Glib::RefPtr< Gtk::TextBuffer::Tag > fatal_ptag
Definition: gtk_ui.h:187
Glib::RefPtr< Gtk::TextBuffer::Tag > error_ptag
Definition: gtk_ui.h:185
const char * name
Gtk::Widget * widget
Definition: gtk_ui.h:83
Glib::RefPtr< Gtk::TextBuffer::Tag > error_mtag
Definition: gtk_ui.h:186
BaseUI::RequestType NullMessage
Definition: gtk_ui.cc:58
Glib::RefPtr< Gtk::TextBuffer::Tag > warning_mtag
Definition: gtk_ui.h:192
MyReceiver _receiver
Definition: gtk_ui.h:113