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