Ardour  8.12
gtk_ui.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1999-2015 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2005-2006 Taybin Rutkin <taybin@taybin.com>
4  * Copyright (C) 2007-2008 Doug McLain <doug@nostar.net>
5  * Copyright (C) 2007-2013 Tim Mayberry <mojofunk@gmail.com>
6  * Copyright (C) 2009-2010 David Robillard <d@drobilla.net>
7  * Copyright (C) 2014-2017 Robin Gareus <robin@gareus.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with this program; if not, write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23 
24 #ifndef __pbd_gtk_ui_h__
25 #define __pbd_gtk_ui_h__
26 
27 #include <string>
28 #include <map>
29 
30 #include <stdint.h>
31 #include <setjmp.h>
32 #include <pthread.h>
33 
34 #ifdef interface
35 #undef interface
36 #endif
37 
38 #include <glibmm/thread.h>
39 
40 #include <gtkmm/widget.h>
41 #include <gtkmm/style.h>
42 #ifndef GTK_NEW_TOOLTIP_API
43 #include <gtkmm/tooltips.h>
44 #endif
45 #include <gtkmm/textbuffer.h>
46 #include <gtkmm/main.h>
47 #include <gdkmm/color.h>
48 
49 #ifndef ABSTRACT_UI_EXPORTS
50 #define ABSTRACT_UI_EXPORTS
51 #endif
52 #include "pbd/abstract_ui.h"
53 #include "pbd/ringbufferNPT.h"
54 #include "pbd/pool.h"
55 #include "pbd/error.h"
56 #include "pbd/receiver.h"
57 
58 #include "gtkmm2ext/visibility.h"
59 
60 class Touchable;
61 
62 namespace Gtkmm2ext {
63 
64 class TextViewer;
65 class Bindings;
66 
75 
76 struct LIBGTKMM2EXT_API UIRequest : public BaseUI::BaseRequestObject {
77 
78  /* this once used anonymous unions to merge elements
79  that are never part of the same request. that makes
80  the creation of a legal copy constructor difficult
81  because of the semantics of the slot member.
82  */
83 
85  const char *msg;
87  int (*function)(void *);
90  void *arg;
91  const char *msg2;
92 
93  UIRequest () {
94  type = NullMessage;
95  }
96 
98  if (type == ErrorMessage && msg) {
99  /* msg was strdup()'ed */
100  free (const_cast<char *>(msg));
101  }
102  }
103 };
104 
105 class LIBGTKMM2EXT_API UI : public AbstractUI<UIRequest>
106 {
107 private:
108  class MyReceiver : public Receiver {
109  public:
110  MyReceiver (UI& ui) : _ui (ui) {}
111  void receive (Transmitter::Channel chn, const char *msg) {
112  _ui.receive (chn, msg);
113  }
114  private:
115  UI& _ui;
116  };
117 
119 
120 public:
121  UI (std::string, std::string, int *argc, char **argv[]);
122  virtual ~UI ();
123 
124  static UI *instance() { return theGtkUI; }
125 
126  /* receiver interface */
127 
128  void receive (Transmitter::Channel, const char *);
129 
130  /* Abstract UI interfaces */
131 
132  bool caller_is_ui_thread () const;
133 
134  /* Gtk-UI specific interfaces */
135 
136  bool running ();
137  void quit ();
138  int load_rcfile (std::string, bool themechange = false);
139  void run (Receiver &old_receiver);
140 
142  void popup_error (const std::string& text);
143  void flush_pending (float timeout = 0);
144  void toggle_errors ();
145  void show_errors ();
146  void dump_errors (std::ostream&, size_t limit = 0);
147  void clear_errors () { error_stack.clear (); }
149  void set_tip (Gtk::Widget &w, const gchar *tip);
150  void set_tip (Gtk::Widget &w, const std::string &tip);
151  void set_tip (Gtk::Widget *w, const gchar *tip, const gchar *hlp="");
152  void idle_add (int (*func)(void *), void *arg);
153 
154  Gtk::Main& main() const { return *theMain; }
155 
156  /* starting is sent just before we enter the main loop,
157  * stopping just after we return from it (at the top level)
158  */
159  virtual int starting() = 0;
160 
161  sigc::signal<void> theme_changed;
162 
164 
166 
167 protected:
168  virtual void handle_fatal (const char *);
169  virtual void display_message (const char *prefix, gint prefix_len,
170  Glib::RefPtr<Gtk::TextBuffer::Tag> ptag, Glib::RefPtr<Gtk::TextBuffer::Tag> mtag,
171  const char *msg);
172 
173 private:
174  static UI *theGtkUI;
175 
176  bool _active;
178 #ifndef GTK_NEW_TOOLTIP_API
180 #endif
182  Glib::RefPtr<Gtk::TextBuffer::Tag> fatal_ptag;
183  Glib::RefPtr<Gtk::TextBuffer::Tag> fatal_mtag;
184  Glib::RefPtr<Gtk::TextBuffer::Tag> error_ptag;
185  Glib::RefPtr<Gtk::TextBuffer::Tag> error_mtag;
186  Glib::RefPtr<Gtk::TextBuffer::Tag> warning_ptag;
187  Glib::RefPtr<Gtk::TextBuffer::Tag> warning_mtag;
188  Glib::RefPtr<Gtk::TextBuffer::Tag> info_ptag;
189  Glib::RefPtr<Gtk::TextBuffer::Tag> info_mtag;
190  Glib::RefPtr<Gtk::TextBuffer::Tag> debug_ptag;
191  Glib::RefPtr<Gtk::TextBuffer::Tag> debug_mtag;
192 
193  static void signal_pipe_callback (void *, gint, GdkInputCondition);
195  void do_quit ();
196 
197  Glib::Threads::Mutex error_lock;
198  std::list<std::string> error_stack;
199 
200  void color_selection_done (bool status);
203 
205 };
206 
207 } /* namespace */
208 
209 #endif /* __pbd_gtk_ui_h__ */
void receive(Transmitter::Channel chn, const char *msg)
Definition: gtk_ui.h:111
static bool just_hide_it(GdkEventAny *, Gtk::Window *)
bool color_selection_deleted(GdkEventAny *)
Glib::RefPtr< Gtk::TextBuffer::Tag > info_mtag
Definition: gtk_ui.h:189
Glib::RefPtr< Gtk::TextBuffer::Tag > fatal_ptag
Definition: gtk_ui.h:182
static UI * instance()
Definition: gtk_ui.h:124
UI(std::string, std::string, int *argc, char **argv[])
TextViewer * errors
Definition: gtk_ui.h:181
virtual void handle_fatal(const char *)
virtual void display_message(const char *prefix, gint prefix_len, Glib::RefPtr< Gtk::TextBuffer::Tag > ptag, Glib::RefPtr< Gtk::TextBuffer::Tag > mtag, const char *msg)
Glib::Threads::Mutex error_lock
Definition: gtk_ui.h:197
Glib::RefPtr< Gtk::TextBuffer::Tag > warning_ptag
Definition: gtk_ui.h:186
Gtkmm2ext::Bindings * global_bindings
Definition: gtk_ui.h:165
void idle_add(int(*func)(void *), void *arg)
Glib::RefPtr< Gtk::TextBuffer::Tag > error_ptag
Definition: gtk_ui.h:184
void set_tip(Gtk::Widget *w, const gchar *tip, const gchar *hlp="")
void clear_errors()
Definition: gtk_ui.h:147
Gtk::Main * theMain
Definition: gtk_ui.h:177
Glib::RefPtr< Gtk::TextBuffer::Tag > fatal_mtag
Definition: gtk_ui.h:183
virtual ~UI()
void process_error_message(Transmitter::Channel, const char *)
void run(Receiver &old_receiver)
void popup_error(const std::string &text)
void dump_errors(std::ostream &, size_t limit=0)
static void signal_pipe_callback(void *, gint, GdkInputCondition)
void flush_pending(float timeout=0)
sigc::signal< void > theme_changed
Definition: gtk_ui.h:161
Glib::RefPtr< Gtk::TextBuffer::Tag > error_mtag
Definition: gtk_ui.h:185
void receive(Transmitter::Channel, const char *)
MyReceiver _receiver
Definition: gtk_ui.h:118
Glib::RefPtr< Gtk::TextBuffer::Tag > warning_mtag
Definition: gtk_ui.h:187
virtual int starting()=0
Glib::RefPtr< Gtk::TextBuffer::Tag > debug_mtag
Definition: gtk_ui.h:191
bool color_picked
Definition: gtk_ui.h:202
static UI * theGtkUI
Definition: gtk_ui.h:174
int load_rcfile(std::string, bool themechange=false)
void set_tip(Gtk::Widget &w, const std::string &tip)
void color_selection_done(bool status)
std::list< std::string > error_stack
Definition: gtk_ui.h:198
void set_tip(Gtk::Widget &w, const gchar *tip)
bool _active
Definition: gtk_ui.h:176
Gtk::Tooltips * tips
Definition: gtk_ui.h:179
Glib::RefPtr< Gtk::TextBuffer::Tag > debug_ptag
Definition: gtk_ui.h:190
void set_state(Gtk::Widget *w, Gtk::StateType state)
Glib::RefPtr< Gtk::TextBuffer::Tag > info_ptag
Definition: gtk_ui.h:188
void show_errors()
Gtk::Main & main() const
Definition: gtk_ui.h:154
void touch_display(Touchable *)
void toggle_errors()
void do_request(UIRequest *)
bool caller_is_ui_thread() const
GdkInputCondition
Definition: gdktypes.h:156
#define LIBGTKMM2EXT_API
BaseUI::RequestType TouchDisplay
BaseUI::RequestType AddTimeout
BaseUI::RequestType StateChange
BaseUI::RequestType ErrorMessage
BaseUI::RequestType SetTip
BaseUI::RequestType CallSlot
BaseUI::RequestType AddIdle
BaseUI::RequestType NullMessage
DebugBits Bindings
const char * msg2
Definition: gtk_ui.h:91
Gtk::StateType new_state
Definition: gtk_ui.h:86
Transmitter::Channel chn
Definition: gtk_ui.h:89
Touchable * display
Definition: gtk_ui.h:84
const char * msg
Definition: gtk_ui.h:85
Gtk::Widget * widget
Definition: gtk_ui.h:88