Ardour  9.0-pre0-439-ga53b99b307
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 #pragma once
25 
26 #include <string>
27 #include <map>
28 
29 #include <stdint.h>
30 #include <setjmp.h>
31 #include <pthread.h>
32 
33 #ifdef interface
34 #undef interface
35 #endif
36 
37 #include <glibmm/thread.h>
38 
39 #include <gtkmm/widget.h>
40 #include <gtkmm/style.h>
41 #ifndef GTK_NEW_TOOLTIP_API
42 #include <gtkmm/tooltips.h>
43 #endif
44 #include <gtkmm/textbuffer.h>
45 #include <gtkmm/main.h>
46 #include <gdkmm/color.h>
47 
48 #ifndef ABSTRACT_UI_EXPORTS
49 #define ABSTRACT_UI_EXPORTS
50 #endif
51 #include "pbd/abstract_ui.h"
52 #include "pbd/ringbufferNPT.h"
53 #include "pbd/pool.h"
54 #include "pbd/error.h"
55 #include "pbd/receiver.h"
56 
57 #include "gtkmm2ext/visibility.h"
58 
59 class Touchable;
60 
61 namespace Gtkmm2ext {
62 
63 class TextViewer;
64 class Bindings;
65 
74 
75 struct LIBGTKMM2EXT_API UIRequest : public BaseUI::BaseRequestObject {
76 
77  /* this once used anonymous unions to merge elements
78  that are never part of the same request. that makes
79  the creation of a legal copy constructor difficult
80  because of the semantics of the slot member.
81  */
82 
84  const char *msg;
86  int (*function)(void *);
89  void *arg;
90  const char *msg2;
91 
92  UIRequest () {
93  type = NullMessage;
94  }
95 
97  if (type == ErrorMessage && msg) {
98  /* msg was strdup()'ed */
99  free (const_cast<char *>(msg));
100  }
101  }
102 };
103 
104 class LIBGTKMM2EXT_API UI : public AbstractUI<UIRequest>
105 {
106 private:
107  class MyReceiver : public Receiver {
108  public:
109  MyReceiver (UI& ui) : _ui (ui) {}
110  void receive (Transmitter::Channel chn, const char *msg) {
111  _ui.receive (chn, msg);
112  }
113  private:
114  UI& _ui;
115  };
116 
118 
119 public:
120  UI (std::string, std::string, int *argc, char **argv[]);
121  virtual ~UI ();
122 
123  static UI *instance() { return theGtkUI; }
124 
125  /* receiver interface */
126 
127  void receive (Transmitter::Channel, const char *);
128 
129  /* Abstract UI interfaces */
130 
131  bool caller_is_ui_thread () const;
132 
133  /* Gtk-UI specific interfaces */
134 
135  bool running ();
136  void quit ();
137  int load_rcfile (std::string, bool themechange = false);
138  void run (Receiver &old_receiver);
139 
141  void popup_error (const std::string& text);
142  void flush_pending (float timeout = 0);
143  void toggle_errors ();
144  void show_errors ();
145  void dump_errors (std::ostream&, size_t limit = 0);
146  void clear_errors () { error_stack.clear (); }
148  void set_tip (Gtk::Widget &w, const gchar *tip);
149  void set_tip (Gtk::Widget &w, const std::string &tip);
150  void set_tip (Gtk::Widget *w, const gchar *tip, const gchar *hlp="");
151  void idle_add (int (*func)(void *), void *arg);
152 
153  Gtk::Main& main() const { return *theMain; }
154 
155  /* starting is sent just before we enter the main loop,
156  * stopping just after we return from it (at the top level)
157  */
158  virtual int starting() = 0;
159 
160  sigc::signal<void> theme_changed;
161 
163 
165 
166 protected:
167  virtual void handle_fatal (const char *);
168  virtual void display_message (const char *prefix, gint prefix_len,
169  Glib::RefPtr<Gtk::TextBuffer::Tag> ptag, Glib::RefPtr<Gtk::TextBuffer::Tag> mtag,
170  const char *msg);
171 
172 private:
173  static UI *theGtkUI;
174 
175  bool _active;
177 #ifndef GTK_NEW_TOOLTIP_API
179 #endif
181  Glib::RefPtr<Gtk::TextBuffer::Tag> fatal_ptag;
182  Glib::RefPtr<Gtk::TextBuffer::Tag> fatal_mtag;
183  Glib::RefPtr<Gtk::TextBuffer::Tag> error_ptag;
184  Glib::RefPtr<Gtk::TextBuffer::Tag> error_mtag;
185  Glib::RefPtr<Gtk::TextBuffer::Tag> warning_ptag;
186  Glib::RefPtr<Gtk::TextBuffer::Tag> warning_mtag;
187  Glib::RefPtr<Gtk::TextBuffer::Tag> info_ptag;
188  Glib::RefPtr<Gtk::TextBuffer::Tag> info_mtag;
189  Glib::RefPtr<Gtk::TextBuffer::Tag> debug_ptag;
190  Glib::RefPtr<Gtk::TextBuffer::Tag> debug_mtag;
191 
192  static void signal_pipe_callback (void *, gint, GdkInputCondition);
194  void do_quit ();
195 
196  Glib::Threads::Mutex error_lock;
197  std::list<std::string> error_stack;
198 
199  void color_selection_done (bool status);
202 
204 };
205 
206 } /* namespace */
207 
void receive(Transmitter::Channel chn, const char *msg)
Definition: gtk_ui.h:110
static bool just_hide_it(GdkEventAny *, Gtk::Window *)
bool color_selection_deleted(GdkEventAny *)
Glib::RefPtr< Gtk::TextBuffer::Tag > info_mtag
Definition: gtk_ui.h:188
Glib::RefPtr< Gtk::TextBuffer::Tag > fatal_ptag
Definition: gtk_ui.h:181
static UI * instance()
Definition: gtk_ui.h:123
UI(std::string, std::string, int *argc, char **argv[])
TextViewer * errors
Definition: gtk_ui.h:180
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:196
Glib::RefPtr< Gtk::TextBuffer::Tag > warning_ptag
Definition: gtk_ui.h:185
Gtkmm2ext::Bindings * global_bindings
Definition: gtk_ui.h:164
void idle_add(int(*func)(void *), void *arg)
Glib::RefPtr< Gtk::TextBuffer::Tag > error_ptag
Definition: gtk_ui.h:183
void set_tip(Gtk::Widget *w, const gchar *tip, const gchar *hlp="")
void clear_errors()
Definition: gtk_ui.h:146
Gtk::Main * theMain
Definition: gtk_ui.h:176
Glib::RefPtr< Gtk::TextBuffer::Tag > fatal_mtag
Definition: gtk_ui.h:182
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:160
Glib::RefPtr< Gtk::TextBuffer::Tag > error_mtag
Definition: gtk_ui.h:184
void receive(Transmitter::Channel, const char *)
MyReceiver _receiver
Definition: gtk_ui.h:117
Glib::RefPtr< Gtk::TextBuffer::Tag > warning_mtag
Definition: gtk_ui.h:186
virtual int starting()=0
Glib::RefPtr< Gtk::TextBuffer::Tag > debug_mtag
Definition: gtk_ui.h:190
bool color_picked
Definition: gtk_ui.h:201
static UI * theGtkUI
Definition: gtk_ui.h:173
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:197
void set_tip(Gtk::Widget &w, const gchar *tip)
bool _active
Definition: gtk_ui.h:175
Gtk::Tooltips * tips
Definition: gtk_ui.h:178
Glib::RefPtr< Gtk::TextBuffer::Tag > debug_ptag
Definition: gtk_ui.h:189
void set_state(Gtk::Widget *w, Gtk::StateType state)
Glib::RefPtr< Gtk::TextBuffer::Tag > info_ptag
Definition: gtk_ui.h:187
void show_errors()
Gtk::Main & main() const
Definition: gtk_ui.h:153
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:90
Gtk::StateType new_state
Definition: gtk_ui.h:85
Transmitter::Channel chn
Definition: gtk_ui.h:88
Touchable * display
Definition: gtk_ui.h:83
const char * msg
Definition: gtk_ui.h:84
Gtk::Widget * widget
Definition: gtk_ui.h:87