1 /**********************************************************************
2  *
3  *   FreeDoko a Doppelkopf-Game
4  *
5  *   Copyright (C) 2001 – 2018 by Diether Knof and Borg Enders
6  *
7  *   This program is free software; you can redistribute it and/or
8  *   modify it under the terms of the GNU General Public License as
9  *   published by the Free Software Foundation; either version 2 of
10  *   the License, or (at your option) any later version.
11  *
12  *   This program is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *   You can find this license in the file 'gpl.txt'.
17  *
18  *   You should have received a copy of the GNU General Public License
19  *   along with this program; if not, write to the Free Software
20  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21  *   MA  02111-1307  USA
22  *
23  *  Contact:
24  *    Diether Knof dknof@posteo.de
25  *
26  **********************************************************************/
27 
28 #include "constants.h"
29 
30 #ifdef USE_UI_GTKMM
31 
32 
33 #include "ui.h"
34 
35 #include <gtkmm/togglebutton.h>
36 #include <gtkmm/dialog.h>
37 namespace UI_GTKMM_NS {
38 
39 /** -> result
40  **
41  ** @param    color   the color
42  **
43  ** @return   the name of the color
44  **/
45 string
colorname(Gdk::RGBA const color)46   colorname(Gdk::RGBA const color)
47   {
48     ostringstream color_str;
49     color_str << '#' << std::setfill('0')
50       << std::hex << setw(4) << color.get_red_u()
51       << std::hex << setw(4) << color.get_green_u()
52       << std::hex << setw(4) << color.get_blue_u()
53       << std::ends;
54 
55     return color_str.str();
56   } // string colorname(Gdk::Colo color)
57 
58 /** -> result
59  **
60  ** @param    pixbuf      the pixbuf that is to be rotated
61  **
62  ** @return   the rotated pixbuf
63  **/
64 Glib::RefPtr<Gdk::Bitmap>
bitmap(Glib::RefPtr<Gdk::Pixbuf> const pixbuf)65   bitmap(Glib::RefPtr<Gdk::Pixbuf> const pixbuf)
66   {
67     Glib::RefPtr<Gdk::Pixmap> pixmap;
68     Glib::RefPtr<Gdk::Bitmap> bitmap;
69 
70 #ifdef OUTDATED
71     // todo: need replacement
72     pixbuf->render_pixmap_and_mask(pixmap, bitmap,
73                                    ALPHA_THRESHOLD);
74 #endif
75 
76     return bitmap;
77   } // Glib::RefPtr<Gdk::Bitmap> bitmap(Glib::RefPtr<Gdk::Pixbuf> pixbuf)
78 
79 /** toggles whether 'widget' is to be shown, depending on the state of
80  ** 'toggle_button'
81  **
82  ** @param    widget      widget to toggle the view of
83  ** @param    toggle_button   button with the state
84  **/
85 void
toggle_view(Gtk::Widget * const widget,Gtk::ToggleButton * const toggle_button)86   toggle_view(Gtk::Widget* const widget,
87               Gtk::ToggleButton* const toggle_button)
88   {
89     if (toggle_button->get_active()
90         && toggle_button->is_visible())
91       widget->show();
92     else
93       widget->hide();
94 
95     return ;
96   } // void toggle_view(Gtk::Widget* const widget, Gtk::ToggleButton* const toggle_button)
97 
98 /** sets the signal so that 'widget' is to be shown, depending on the state of
99  ** 'toggle_button'
100  **
101  ** @param    widget      widget to toggle the view of
102  ** @param    toggle_button   button with the state
103  **/
104 void
set_signal_toggle_view(Gtk::Widget * const widget,Gtk::ToggleButton * const toggle_button)105   set_signal_toggle_view(Gtk::Widget* const widget,
106                          Gtk::ToggleButton* const toggle_button)
107   {
108     toggle_button->signal_toggled().connect(sigc::bind<Gtk::Widget* const, Gtk::ToggleButton* const>(sigc::ptr_fun(&toggle_view), widget, toggle_button));
109 
110     toggle_button->signal_realize().connect(sigc::bind<Gtk::Widget* const, Gtk::ToggleButton* const>(sigc::ptr_fun(&toggle_view), widget, toggle_button));
111 
112     toggle_button->signal_show().connect(sigc::bind<Gtk::Widget* const, Gtk::ToggleButton* const>(sigc::ptr_fun(&toggle_view), widget, toggle_button));
113     toggle_button->signal_hide().connect(sigc::bind<Gtk::Widget* const, Gtk::ToggleButton* const>(sigc::ptr_fun(&toggle_view), widget, toggle_button));
114 
115     toggle_button->signal_unmap().connect(sigc::bind<Gtk::Widget* const, Gtk::ToggleButton* const>(sigc::ptr_fun(&toggle_view), widget, toggle_button));
116 
117     return ;
118   } // void set_signal_toggle_view(Gtk::Widget* const widget, Gtk::ToggleButton* const toggle_button)
119 
120 /** create a close button and pack it into the action area
121  **
122  ** @param    dialog   dialog to add the close button
123  **
124  ** @return   button
125  **/
126 Gtk::Button*
add_close_button(UI_GTKMM & ui,Gtk::Dialog & dialog)127   add_close_button(UI_GTKMM& ui, Gtk::Dialog& dialog)
128   {
129     auto close_button = Gtk::manage(new Gtk::Button(_("Button::close")));
130     close_button->set_image_from_icon_name("window-close");
131     close_button->set_always_show_image();
132     dialog.add_action_widget(*close_button, Gtk::RESPONSE_CLOSE);
133     close_button->signal_clicked().connect(sigc::mem_fun(dialog, &Gtk::Dialog::close));
134 
135     close_button->set_can_default();
136     close_button->grab_default();
137     close_button->grab_focus();
138     close_button->show();
139 
140     return close_button;
141   } // Gtk::Button* add_close_button(Gtk::Dialog& dialog)
142 } // namespace UI_GTKMM_NS
143 
144 #endif // #ifdef USE_UI_GTKMM
145