Ardour  9.0-pre0-582-g084a23a80d
libs/gtkmm2ext/gtkmm2ext/utils.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1999-2016 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2006-2008 Doug McLain <doug@nostar.net>
4  * Copyright (C) 2011-2015 David Robillard <d@drobilla.net>
5  * Copyright (C) 2012 Carl Hetherington <carl@carlh.net>
6  * Copyright (C) 2013-2014 John Emmas <john@creativepost.co.uk>
7  * Copyright (C) 2014-2019 Robin Gareus <robin@gareus.org>
8  * Copyright (C) 2016 Julien "_FrnchFrgg_" RIVAUD <frnchfrgg@free.fr>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License along
21  * with this program; if not, write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  */
24 
25 #ifndef __gtkmm2ext_utils_h__
26 #define __gtkmm2ext_utils_h__
27 
28 #include <vector>
29 #include <string>
30 #include <stdint.h>
31 
32 #include <cairomm/cairomm.h>
33 #include <pangomm/fontdescription.h>
34 
35 #include <gtkmm/container.h>
36 #include <gtkmm/filechooser.h>
37 #include <gtkmm/menu.h>
38 #include <gtkmm/treeview.h>
39 #include <gdkmm/window.h> /* for WMDecoration */
40 #include <gdkmm/pixbuf.h>
41 
42 #include "gtkmm2ext/visibility.h"
43 
44 namespace Cairo {
45  class Context;
46 }
47 
48 namespace Gtk {
49  class ComboBoxText;
50  class Widget;
51  class Window;
52  class Paned;
53  class Menu;
54 }
55 
56 namespace Gtkmm2ext {
57  LIBGTKMM2EXT_API void init (const char*);
58 
60 
61  LIBGTKMM2EXT_API std::string fit_to_pixels (const std::string&, int pixel_width, Pango::FontDescription& font, int& actual_width, bool with_ellipses = false);
62  LIBGTKMM2EXT_API std::pair<std::string, double> fit_to_pixels (cairo_t *, std::string, double);
63  LIBGTKMM2EXT_API int pixel_width (const std::string& str, const Pango::FontDescription& font);
64  LIBGTKMM2EXT_API void pixel_size (const std::string& str, const Pango::FontDescription& font, int& width, int& height);
65 
66  LIBGTKMM2EXT_API void get_ink_pixel_size (Glib::RefPtr<Pango::Layout>, int& width, int& height);
67  LIBGTKMM2EXT_API void get_ink_pixel_size_with_descent (Glib::RefPtr<Pango::Layout>, int& width, int& height, int& descent);
68 
70  std::string const& text,
71  gint hpadding,
72  gint vpadding);
73 
74 
75  LIBGTKMM2EXT_API Glib::RefPtr<Gdk::Pixbuf> pixbuf_from_string (const std::string& name,
76  const Pango::FontDescription& font,
77  int clip_width,
78  int clip_height,
79  Gdk::Color fg);
80 
82  Gtk::Widget* const anchor,
83  const std::string& selected,
84  guint button, guint32 time);
85 
87  const std::vector<std::string>&);
88 
90  std::vector<std::string>&);
91 
93 
95 
97 
98  template<class T> /*LIBGTKMM2EXT_API*/ void deferred_delete (void *ptr) {
99  delete static_cast<T *> (ptr);
100  }
101 
105  LIBGTKMM2EXT_API Glib::RefPtr<Gdk::Drawable> get_bogus_drawable();
107 
108  LIBGTKMM2EXT_API Glib::RefPtr<Gdk::Window> window_to_draw_on (Gtk::Widget& w, Gtk::Widget** parent);
109 
112 
113  LIBGTKMM2EXT_API int physical_screen_height (Glib::RefPtr<Gdk::Window>);
114  LIBGTKMM2EXT_API int physical_screen_width (Glib::RefPtr<Gdk::Window>);
115 
116  LIBGTKMM2EXT_API void container_clear (Gtk::Container&, bool and_delete = false);
117 
118  /* C++ API for rounded rectangles */
119 
120  LIBGTKMM2EXT_API void rectangle (Cairo::RefPtr<Cairo::Context> context, double x, double y, double w, double h, double r=10);
121  LIBGTKMM2EXT_API void rounded_rectangle (Cairo::RefPtr<Cairo::Context> context, double x, double y, double w, double h, double r=10);
122  LIBGTKMM2EXT_API void rounded_top_rectangle (Cairo::RefPtr<Cairo::Context> context, double x, double y, double w, double h, double r=10);
123  LIBGTKMM2EXT_API void rounded_top_left_rectangle (Cairo::RefPtr<Cairo::Context> context, double x, double y, double w, double h, double r=10);
124  LIBGTKMM2EXT_API void rounded_top_right_rectangle (Cairo::RefPtr<Cairo::Context> context, double x, double y, double w, double h, double r=10);
125  LIBGTKMM2EXT_API void rounded_top_half_rectangle (Cairo::RefPtr<Cairo::Context>, double x, double y, double w, double h, double r=10);
126  LIBGTKMM2EXT_API void rounded_bottom_half_rectangle (Cairo::RefPtr<Cairo::Context>, double x, double y, double w, double h, double r=10);
127  LIBGTKMM2EXT_API void rounded_right_half_rectangle (Cairo::RefPtr<Cairo::Context>, double x, double y, double w, double h, double r=10);
128  LIBGTKMM2EXT_API void rounded_left_half_rectangle (Cairo::RefPtr<Cairo::Context>, double x, double y, double w, double h, double r=10);
129 
130  /* C API for rounded rectangles */
131 
132  LIBGTKMM2EXT_API void rectangle (cairo_t*, double x, double y, double w, double h, double r=10);
133  LIBGTKMM2EXT_API void rounded_rectangle (cairo_t*, double x, double y, double w, double h, double r=10);
134  LIBGTKMM2EXT_API void rounded_top_rectangle (cairo_t*, double x, double y, double w, double h, double r=10);
135  LIBGTKMM2EXT_API void rounded_top_left_rectangle (cairo_t*, double x, double y, double w, double h, double r=10);
136  LIBGTKMM2EXT_API void rounded_top_right_rectangle (cairo_t*, double x, double y, double w, double h, double r=10);
137  LIBGTKMM2EXT_API void rounded_top_half_rectangle (cairo_t*, double x, double y, double w, double h, double r=10);
138  LIBGTKMM2EXT_API void rounded_bottom_half_rectangle (cairo_t*, double x, double y, double w, double h, double r=10);
139  LIBGTKMM2EXT_API void rounded_right_half_rectangle (cairo_t*, double x, double y, double w, double h, double r=10);
140  LIBGTKMM2EXT_API void rounded_left_half_rectangle (cairo_t* cr, double x, double y, double w, double h, double r=10);
141 
142  LIBGTKMM2EXT_API void add_reflection (cairo_t* cr, double w, double h);
143 
146 
150 
151  LIBGTKMM2EXT_API void convert_bgra_to_rgba (guint8 const *, guint8 * dst, int, int);
152  LIBGTKMM2EXT_API const char* event_type_string (int event_type);
153 
154  /* glibmm ustring workaround
155  *
156  * Glib::operator<<(std::ostream&, Glib::ustring const&) internally calls
157  * g_locale_from_utf8() which uses loadlocale which is not thread-safe on OSX
158  *
159  * use a std::string
160  */
161  LIBGTKMM2EXT_API std::string markup_escape_text (std::string const& s);
162 
164 
166  LIBGTKMM2EXT_API void paned_set_position_as_fraction (Gtk::Paned& paned, float fraction, bool h);
167 
168  LIBGTKMM2EXT_API std::string show_gdk_event_state (int state);
169 };
170 
171 #endif /* __gtkmm2ext_utils_h__ */
Definition: Window.h:41
GtkImageIconNameData name
Definition: gtkimage.h:6
#define LIBGTKMM2EXT_API
PBD::PropertyDescriptor< bool > selected
Definition: ardour_ui.h:188
void set_size_request_to_display_given_text(Gtk::Widget &w, std::string const &text, gint hpadding, gint vpadding)
const char * event_type_string(int event_type)
void enable_tooltips()
void rounded_top_left_rectangle(Cairo::RefPtr< Cairo::Context > context, double x, double y, double w, double h, double r=10)
void set_popdown_strings(Gtk::ComboBoxText &, const std::vector< std::string > &)
bool contains_value(Gtk::ComboBoxText &, const std::string)
void add_volume_shortcuts(Gtk::FileChooser &c)
Glib::RefPtr< Gdk::Window > window_to_draw_on(Gtk::Widget &w, Gtk::Widget **parent)
void get_ink_pixel_size_with_descent(Glib::RefPtr< Pango::Layout >, int &width, int &height, int &descent)
int physical_screen_width(Glib::RefPtr< Gdk::Window >)
void set_treeview_header_as_default_label(Gtk::TreeViewColumn *c)
int physical_screen_height(Glib::RefPtr< Gdk::Window >)
void set_no_tooltip_whatsoever(Gtk::Widget &)
Glib::RefPtr< Gdk::Pixbuf > pixbuf_from_string(const std::string &name, const Pango::FontDescription &font, int clip_width, int clip_height, Gdk::Color fg)
void paned_set_position_as_fraction(Gtk::Paned &paned, float fraction, bool h)
void init(const char *)
void rounded_top_right_rectangle(Cairo::RefPtr< Cairo::Context > context, double x, double y, double w, double h, double r=10)
void rounded_bottom_half_rectangle(Cairo::RefPtr< Cairo::Context >, double x, double y, double w, double h, double r=10)
void pixel_size(const std::string &str, const Pango::FontDescription &font, int &width, int &height)
uint32_t possibly_translate_legal_accelerator_to_real_key(uint32_t keyval)
bool event_inside_widget_window(Gtk::Widget &widget, GdkEvent *ev)
void rounded_right_half_rectangle(Cairo::RefPtr< Cairo::Context >, double x, double y, double w, double h, double r=10)
void rounded_rectangle(Cairo::RefPtr< Cairo::Context > context, double x, double y, double w, double h, double r=10)
void detach_menu(Gtk::Menu &)
std::string show_gdk_event_state(int state)
bool possibly_translate_keyval_to_make_legal_accelerator(uint32_t &keyval)
void disable_tooltips()
void rounded_left_half_rectangle(Cairo::RefPtr< Cairo::Context >, double x, double y, double w, double h, double r=10)
Glib::RefPtr< Gdk::Drawable > get_bogus_drawable()
Gtk::Label * left_aligned_label(std::string const &)
size_t get_popdown_string_count(Gtk::ComboBoxText &)
void convert_bgra_to_rgba(guint8 const *, guint8 *dst, int, int)
void set_decoration(Gtk::Window *win, Gdk::WMDecoration decor)
std::string fit_to_pixels(const std::string &, int pixel_width, Pango::FontDescription &font, int &actual_width, bool with_ellipses=false)
void rectangle(Cairo::RefPtr< Cairo::Context > context, double x, double y, double w, double h, double r=10)
void deferred_delete(void *ptr)
void get_ink_pixel_size(Glib::RefPtr< Pango::Layout >, int &width, int &height)
void get_popdown_strings(Gtk::ComboBoxText &, std::vector< std::string > &)
Gtk::Label * right_aligned_label(std::string const &)
GdkWindow * get_paned_handle(Gtk::Paned &paned)
void add_reflection(cairo_t *cr, double w, double h)
void rounded_top_half_rectangle(Cairo::RefPtr< Cairo::Context >, double x, double y, double w, double h, double r=10)
void anchored_menu_popup(Gtk::Menu *const menu, Gtk::Widget *const anchor, const std::string &selected, guint button, guint32 time)
void rounded_top_rectangle(Cairo::RefPtr< Cairo::Context > context, double x, double y, double w, double h, double r=10)
std::string markup_escape_text(std::string const &s)
float paned_position_as_fraction(Gtk::Paned &paned, bool h)
int pixel_width(const std::string &str, const Pango::FontDescription &font)
void container_clear(Gtk::Container &, bool and_delete=false)
bool set_active_text_if_present(Gtk::ComboBoxText &, const std::string)
gint height
Definition: xcursors.h:1
gint width
Definition: xcursors.h:1