Merge branch 'master' into cairocanvas
[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/treeview.h>
32 #include <gdkmm/window.h> /* for WMDecoration */
33 #include <gdkmm/pixbuf.h>
34
35 namespace Cairo {
36         class Context;
37 }
38
39 namespace Gtk {
40         class ComboBoxText;
41         class Widget;
42         class Window;
43         class Paned;
44         class Menu;
45 }
46
47 namespace Gtkmm2ext {
48         void init (const char*);
49
50         std::string fit_to_pixels (const std::string&, int pixel_width, Pango::FontDescription& font, int& actual_width, bool with_ellipses = false);
51         std::pair<std::string, double> fit_to_pixels (cairo_t *, std::string, double);
52         int pixel_width (const std::string& str, Pango::FontDescription& font);
53
54         void get_ink_pixel_size (Glib::RefPtr<Pango::Layout>, 
55                                  int& width, int& height);
56
57         void set_size_request_to_display_given_text (Gtk::Widget &w,
58                                                      const gchar *text,
59                                                      gint hpadding,
60                                                      gint vpadding);
61
62         void set_size_request_to_display_given_text (Gtk::Widget &w,
63                                                      const std::vector<std::string>&,
64                                                      gint hpadding,
65                                                      gint vpadding);
66
67         Glib::RefPtr<Gdk::Pixbuf> pixbuf_from_string (const std::string& name, 
68                                                       const Pango::FontDescription& font, 
69                                                       int clip_width, 
70                                                       int clip_height, 
71                                                       Gdk::Color fg);
72
73         void set_popdown_strings (Gtk::ComboBoxText&, 
74                                   const std::vector<std::string>&);
75
76         template<class T> void deferred_delete (void *ptr) {
77                 delete static_cast<T *> (ptr);
78         }
79
80         GdkWindow* get_paned_handle (Gtk::Paned& paned);
81         void set_decoration (Gtk::Window* win, Gdk::WMDecoration decor);
82         void set_treeview_header_as_default_label(Gtk::TreeViewColumn *c);
83         Glib::RefPtr<Gdk::Drawable> get_bogus_drawable();
84         void detach_menu (Gtk::Menu&);
85
86         Glib::RefPtr<Gdk::Window> window_to_draw_on (Gtk::Widget& w, Gtk::Widget** parent);
87
88         bool possibly_translate_keyval_to_make_legal_accelerator (uint32_t& keyval);
89         uint32_t possibly_translate_legal_accelerator_to_real_key (uint32_t keyval);
90
91         int physical_screen_height (Glib::RefPtr<Gdk::Window>);
92         int physical_screen_width (Glib::RefPtr<Gdk::Window>);
93
94         void container_clear (Gtk::Container&);
95
96         /* C++ API for rounded rectangles */
97         
98         void rounded_rectangle (Cairo::RefPtr<Cairo::Context> context, double x, double y, double w, double h, double r=10);
99         void rounded_top_rectangle (Cairo::RefPtr<Cairo::Context> context, double x, double y, double w, double h, double r=10);
100         void rounded_top_left_rectangle (Cairo::RefPtr<Cairo::Context> context, double x, double y, double w, double h, double r=10);
101         void rounded_top_right_rectangle (Cairo::RefPtr<Cairo::Context> context, double x, double y, double w, double h, double r=10);
102         void rounded_top_half_rectangle (Cairo::RefPtr<Cairo::Context>, double x, double y, double w, double h, double r=10);
103         void rounded_bottom_half_rectangle (Cairo::RefPtr<Cairo::Context>, double x, double y, double w, double h, double r=10);
104         void rounded_right_half_rectangle (Cairo::RefPtr<Cairo::Context>, double x, double y, double w, double h, double r=10);
105
106         /* C API for rounded rectangles */
107
108         void rounded_rectangle (cairo_t*, double x, double y, double w, double h, double r=10);
109         void rounded_top_rectangle (cairo_t*, double x, double y, double w, double h, double r=10);
110         void rounded_top_left_rectangle (cairo_t*, double x, double y, double w, double h, double r=10);
111         void rounded_top_right_rectangle (cairo_t*, double x, double y, double w, double h, double r=10);
112         void rounded_top_half_rectangle (cairo_t*, double x, double y, double w, double h, double r=10);
113         void rounded_bottom_half_rectangle (cairo_t*, double x, double y, double w, double h, double r=10);
114         void rounded_right_half_rectangle (cairo_t*, double x, double y, double w, double h, double r=10);
115
116         Gtk::Label* left_aligned_label (std::string const &);
117
118         void set_no_tooltip_whatsoever (Gtk::Widget &);
119         void enable_tooltips ();
120         void disable_tooltips ();
121
122         void convert_bgra_to_rgba (guint8 const *, guint8 * dst, int, int);
123 };
124
125 #endif /*  __gtkmm2ext_utils_h__ */