and now without debug printf()
[ardour.git] / libs / gtkmm2ext / gtkmm2ext / utils.h
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 __gtkmm2ext_utils_h__
21 #define __gtkmm2ext_utils_h__
22
23 #include <vector>
24 #include <string>
25 #include <stdint.h>
26
27 #include <cairomm/cairomm.h>
28 #include <pangomm/fontdescription.h>
29
30 #include <gtkmm/container.h>
31 #include <gtkmm/filechooser.h>
32 #include <gtkmm/treeview.h>
33 #include <gdkmm/window.h> /* for WMDecoration */
34 #include <gdkmm/pixbuf.h>
35
36 #include "gtkmm2ext/visibility.h"
37
38 namespace Cairo {
39         class Context;
40 }
41
42 namespace Gtk {
43         class ComboBoxText;
44         class Widget;
45         class Window;
46         class Paned;
47         class Menu;
48 }
49
50 namespace Gtkmm2ext {
51         LIBGTKMM2EXT_API void init (const char*);
52
53         LIBGTKMM2EXT_API bool event_inside_widget_window (Gtk::Widget& widget, GdkEvent* ev);
54
55         LIBGTKMM2EXT_API std::string fit_to_pixels (const std::string&, int pixel_width, Pango::FontDescription& font, int& actual_width, bool with_ellipses = false);
56         LIBGTKMM2EXT_API std::pair<std::string, double> fit_to_pixels (cairo_t *, std::string, double);
57         LIBGTKMM2EXT_API int pixel_width (const std::string& str, const Pango::FontDescription& font);
58         LIBGTKMM2EXT_API void pixel_size (const std::string& str, const Pango::FontDescription& font, int& width, int& height);
59
60         LIBGTKMM2EXT_API void get_ink_pixel_size (Glib::RefPtr<Pango::Layout>,
61                                                   int& width, int& height);
62
63
64         LIBGTKMM2EXT_API void get_pixel_size (Glib::RefPtr<Pango::Layout>,
65                                               int& width, int& height);
66
67         LIBGTKMM2EXT_API void set_size_request_to_display_given_text (Gtk::Widget &w,
68                                                                       const gchar *text,
69                                                                       gint hpadding,
70                                                                       gint vpadding);
71
72         LIBGTKMM2EXT_API void set_size_request_to_display_given_text_width (Gtk::Widget& w,
73                                                                             const gchar* htext,
74                                                                             gint         hpadding,
75                                                                             gint         vpadding);
76
77         LIBGTKMM2EXT_API void set_height_request_to_display_any_text (Gtk::Widget& w, gint vpadding);
78
79         LIBGTKMM2EXT_API void set_size_request_to_display_given_text (Gtk::Widget &w,
80                                                                       std::string const & text,
81                                                                       gint hpadding,
82                                                                       gint vpadding);
83         LIBGTKMM2EXT_API void set_size_request_to_display_given_text (Gtk::Widget &w,
84                                                                       const std::vector<std::string>&,
85                                                                       gint hpadding,
86                                                                       gint vpadding);
87         LIBGTKMM2EXT_API void set_size_request_to_display_given_text (Gtk::Widget &w,
88                                                                       const std::vector<std::string>&,
89                                                                       const std::string& hpadding,
90                                                                       gint vpadding);
91
92
93         LIBGTKMM2EXT_API Glib::RefPtr<Gdk::Pixbuf> pixbuf_from_string (const std::string& name,
94                                                                        const Pango::FontDescription& font,
95                                                                        int clip_width,
96                                                                        int clip_height,
97                                                                        Gdk::Color fg);
98
99         LIBGTKMM2EXT_API void set_popdown_strings (Gtk::ComboBoxText&,
100                                   const std::vector<std::string>&);
101
102         LIBGTKMM2EXT_API void get_popdown_strings (Gtk::ComboBoxText&,
103                                   std::vector<std::string>&);
104
105         LIBGTKMM2EXT_API size_t get_popdown_string_count (Gtk::ComboBoxText&);
106
107         LIBGTKMM2EXT_API bool contains_value (Gtk::ComboBoxText&,
108                                   const std::string);
109
110         LIBGTKMM2EXT_API bool set_active_text_if_present (Gtk::ComboBoxText&,
111                                   const std::string);
112
113         template<class T> /*LIBGTKMM2EXT_API*/ void deferred_delete (void *ptr) {
114                 delete static_cast<T *> (ptr);
115         }
116
117         LIBGTKMM2EXT_API GdkWindow* get_paned_handle (Gtk::Paned& paned);
118         LIBGTKMM2EXT_API void set_decoration (Gtk::Window* win, Gdk::WMDecoration decor);
119         LIBGTKMM2EXT_API void set_treeview_header_as_default_label(Gtk::TreeViewColumn *c);
120         LIBGTKMM2EXT_API Glib::RefPtr<Gdk::Drawable> get_bogus_drawable();
121         LIBGTKMM2EXT_API void detach_menu (Gtk::Menu&);
122
123         LIBGTKMM2EXT_API Glib::RefPtr<Gdk::Window> window_to_draw_on (Gtk::Widget& w, Gtk::Widget** parent);
124
125         LIBGTKMM2EXT_API bool possibly_translate_keyval_to_make_legal_accelerator (uint32_t& keyval);
126         LIBGTKMM2EXT_API uint32_t possibly_translate_legal_accelerator_to_real_key (uint32_t keyval);
127
128         LIBGTKMM2EXT_API int physical_screen_height (Glib::RefPtr<Gdk::Window>);
129         LIBGTKMM2EXT_API int physical_screen_width (Glib::RefPtr<Gdk::Window>);
130
131         LIBGTKMM2EXT_API void container_clear (Gtk::Container&);
132
133         /* C++ API for rounded rectangles */
134
135         LIBGTKMM2EXT_API void rounded_rectangle (Cairo::RefPtr<Cairo::Context> context, double x, double y, double w, double h, double r=10);
136         LIBGTKMM2EXT_API void rounded_top_rectangle (Cairo::RefPtr<Cairo::Context> context, double x, double y, double w, double h, double r=10);
137         LIBGTKMM2EXT_API void rounded_top_left_rectangle (Cairo::RefPtr<Cairo::Context> context, double x, double y, double w, double h, double r=10);
138         LIBGTKMM2EXT_API void rounded_top_right_rectangle (Cairo::RefPtr<Cairo::Context> context, double x, double y, double w, double h, double r=10);
139         LIBGTKMM2EXT_API void rounded_top_half_rectangle (Cairo::RefPtr<Cairo::Context>, double x, double y, double w, double h, double r=10);
140         LIBGTKMM2EXT_API void rounded_bottom_half_rectangle (Cairo::RefPtr<Cairo::Context>, double x, double y, double w, double h, double r=10);
141         LIBGTKMM2EXT_API void rounded_right_half_rectangle (Cairo::RefPtr<Cairo::Context>, double x, double y, double w, double h, double r=10);
142         LIBGTKMM2EXT_API void rounded_left_half_rectangle (Cairo::RefPtr<Cairo::Context>, double x, double y, double w, double h, double r=10);
143
144         /* C API for rounded rectangles */
145
146         LIBGTKMM2EXT_API void rounded_rectangle (cairo_t*, double x, double y, double w, double h, double r=10);
147         LIBGTKMM2EXT_API void rounded_top_rectangle (cairo_t*, double x, double y, double w, double h, double r=10);
148         LIBGTKMM2EXT_API void rounded_top_left_rectangle (cairo_t*, double x, double y, double w, double h, double r=10);
149         LIBGTKMM2EXT_API void rounded_top_right_rectangle (cairo_t*, double x, double y, double w, double h, double r=10);
150         LIBGTKMM2EXT_API void rounded_top_half_rectangle (cairo_t*, double x, double y, double w, double h, double r=10);
151         LIBGTKMM2EXT_API void rounded_bottom_half_rectangle (cairo_t*, double x, double y, double w, double h, double r=10);
152         LIBGTKMM2EXT_API void rounded_right_half_rectangle (cairo_t*, double x, double y, double w, double h, double r=10);
153         LIBGTKMM2EXT_API void rounded_left_half_rectangle (cairo_t* cr, double x, double y, double w, double h, double r=10);
154
155         LIBGTKMM2EXT_API Gtk::Label* left_aligned_label (std::string const &);
156         LIBGTKMM2EXT_API Gtk::Label* right_aligned_label (std::string const &);
157
158         LIBGTKMM2EXT_API void set_no_tooltip_whatsoever (Gtk::Widget &);
159         LIBGTKMM2EXT_API void enable_tooltips ();
160         LIBGTKMM2EXT_API void disable_tooltips ();
161
162         LIBGTKMM2EXT_API void convert_bgra_to_rgba (guint8 const *, guint8 * dst, int, int);
163         LIBGTKMM2EXT_API const char* event_type_string (int event_type);
164
165         /* glibmm ustring workaround
166          *
167          * Glib::operator<<(std::ostream&, Glib::ustring const&) internally calls
168          * g_locale_from_utf8() which uses loadlocale which is not thread-safe on OSX
169          *
170          * use a std::string
171          */
172         LIBGTKMM2EXT_API std::string markup_escape_text (std::string const& s);
173
174         LIBGTKMM2EXT_API void add_volume_shortcuts (Gtk::FileChooser& c);
175 };
176
177 #endif /*  __gtkmm2ext_utils_h__ */