1 /*
2  *  This file is part of RawTherapee.
3  *
4  *  Copyright (c) 2004-2010 Gabor Horvath <hgabor@rawtherapee.com>
5  *
6  *  RawTherapee 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  *  RawTherapee 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 RawTherapee.  If not, see <https://www.gnu.org/licenses/>.
18  *
19  *  Class created by Jean-Christophe FRISCH, aka 'Hombre'
20  */
21 #pragma once
22 
23 #include <vector>
24 
25 #include <glibmm/ustring.h>
26 
27 #include <sigc++/signal.h>
28 
29 namespace Gtk
30 {
31 
32 class Grid;
33 class Menu;
34 class Button;
35 class ImageMenuItem;
36 
37 }
38 
39 typedef struct _GdkEventButton GdkEventButton;
40 
41 class RTImage;
42 
43 class PopUpCommon
44 {
45 
46 public:
47     typedef sigc::signal<void, int> type_signal_changed;
48     typedef sigc::signal<void, int> type_signal_item_selected;
49     type_signal_changed signal_changed();
50     type_signal_item_selected signal_item_selected();
51     Gtk::Grid* buttonGroup;    // this is the widget to be packed
52 
53     explicit PopUpCommon (Gtk::Button* button, const Glib::ustring& label = "");
54     virtual ~PopUpCommon ();
55     bool addEntry (const Glib::ustring& fileName, const Glib::ustring& label);
56     int getEntryCount () const;
57     bool setSelected (int entryNum);
58     int  getSelected () const;
59     void setButtonHint();
60     void show ();
61     void set_tooltip_text (const Glib::ustring &text);
62     void setItemSensitivity (int i, bool isSensitive);
63 
64 private:
65     type_signal_changed messageChanged;
66     type_signal_item_selected messageItemSelected;
67 
68     std::vector<Glib::ustring> imageFilenames;
69     std::vector<const RTImage*> images;
70     Glib::ustring buttonHint;
71     RTImage* buttonImage;
72     Gtk::Grid* imageContainer;
73     Gtk::Menu* menu;
74     Gtk::Button* button;
75     int selected;
76     bool hasMenu;
77 
78     void showMenu(GdkEventButton* event);
79 
80 protected:
posToIndex(int p)81     virtual int posToIndex(int p) const { return p; }
indexToPos(int i)82     virtual int indexToPos(int i) const { return i; }
83 
84     void entrySelected (int i);
85 
86 };
87 
signal_changed()88 inline PopUpCommon::type_signal_changed PopUpCommon::signal_changed ()
89 {
90     return messageChanged;
91 }
92 
signal_item_selected()93 inline PopUpCommon::type_signal_item_selected PopUpCommon::signal_item_selected ()
94 {
95     return messageItemSelected;
96 }
97 
getEntryCount()98 inline int PopUpCommon::getEntryCount () const
99 {
100     return images.size();
101 }
102 
getSelected()103 inline int PopUpCommon::getSelected () const
104 {
105     return posToIndex(selected);
106 }
107