1 // GtkUtil.hh --- Gtk utilities
2 //
3 // Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2011, 2012 Raymond Penners <raymond@dotsphinx.com>
4 // All rights reserved.
5 //
6 // This program is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 //
19 
20 #ifndef GTKUTIL_HH
21 #define GTKUTIL_HH
22 
23 #include <gtkmm/button.h>
24 #include <gtkmm/stockid.h>
25 #include <gtkmm/table.h>
26 #include <gtkmm/window.h>
27 #include <gtkmm/image.h>
28 #include <gtkmm/box.h>
29 #include <gtkmm/alignment.h>
30 #include <glibmm/quark.h>
31 #include <gtkmm/accelgroup.h>
32 
33 #include <string>
34 
35 #include "ICore.hh"
36 
37 class HeadInfo;
38 class EventImage;
39 
40 using namespace workrave;
41 
42 class GtkUtil
43 {
44 public:
45   static Gtk::Button *
46   create_custom_stock_button(const char *label_text,
47                              const Gtk::StockID& stock_id);
48 
49   static Gtk::Button *
50   create_image_button(const char *label_text, const char *image_file, bool label = true);
51 
52   static void
53   update_custom_stock_button(Gtk::Button *btn, const char *label_text,
54                              const Gtk::StockID& stock_id);
55 
56   static Gtk::Widget *
57   create_label_with_icon(std::string text, const char *icon);
58 
59   static Gtk::Label *
60   create_label(std::string text, bool bold);
61 
62   static Gtk::Widget *
63   create_label_with_tooltip(std::string text,
64                             std::string tooltip);
65 
66   static EventImage *
67   create_image_with_tooltip(std::string file,
68                             std::string tooltip);
69 
70   static Gtk::Widget *
71   create_label_for_break(workrave::BreakId id);
72 
73   static Glib::RefPtr<Gdk::Pixbuf>
74   flip_pixbuf(Glib::RefPtr<Gdk::Pixbuf> pixbuf, bool horizontal, bool vertical);
75 
76   static void
77   table_attach_aligned(Gtk::Table &table, Gtk::Widget &child,
78                        guint left_attach, guint top_attach, bool left);
79 
80   static void
81   table_attach_left_aligned(Gtk::Table &table, Gtk::Widget &child,
82                             guint left_attach, guint top_attach);
83 
84   static void
85   table_attach_right_aligned(Gtk::Table &table, Gtk::Widget &child,
86                              guint left_attach, guint top_attach);
87 
88   static void center_window(Gtk::Window &window, HeadInfo &head);
89 
90   static bool has_button_images();
91 
92   static void update_mnemonic(Gtk::Widget *widget, Glib::RefPtr<Gtk::AccelGroup>);
93 
94   static GtkWindow *get_visible_tooltip_window();
95 
96   static bool running_on_wayland();
97 
98   static void set_theme_fg_color(Gtk::Widget *widget);
99 
100 private:
101   static Glib::Quark *label_quark;
102 };
103 
104 #endif // GTKUTIL_HH
105