Proper check for rawzor libraries.
[rawtherapee-fixes.git] / rtgui / lwbuttonset.cc
blob4542b1806982f3a2b33d8d8974df88837abac790
1 /*
2 * This file is part of RawTherapee.
4 * Copyright (c) 2004-2010 Gabor Horvath <hgabor@rawtherapee.com>
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.
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.
16 * You should have received a copy of the GNU General Public License
17 * along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
19 #include <lwbuttonset.h>
21 LWButtonSet::LWButtonSet () : aw(0), ah(0) {
24 LWButtonSet::~LWButtonSet () {
26 for (int i=0; i<buttons.size(); i++)
27 delete buttons[i];
30 void LWButtonSet::add (LWButton* b) {
32 buttons.push_back (b);
35 void LWButtonSet::getMinimalDimensions (int& w, int& h) {
37 w=0; h=0;
38 for (int i=0; i<buttons.size(); i++) {
39 int bw, bh;
40 buttons[i]->getSize (bw, bh);
41 w+= bw;
42 if (bh>h)
43 h = bh;
47 int LWButtonSet::arrangeButtons (int x, int y, int w, int h) {
49 int mw, mh;
50 getMinimalDimensions (mw, mh);
52 if (w<0)
53 w = mw;
54 if (h<0)
55 h = mh;
57 int begx = x;
58 int endx = x+w-1;
59 for (int i=0; i<buttons.size(); i++) {
60 LWButton::Alignment halign, valign;
61 int bx, by, bw, bh;
62 buttons[i]->getSize (bw, bh);
63 buttons[i]->getAlignment (halign, valign);
64 if (halign == LWButton::Left) {
65 bx = begx;
66 begx += bw;
68 else if (halign == LWButton::Right) {
69 bx = endx-bw;
70 endx -= bw;
72 if (valign == LWButton::Top)
73 by = y;
74 else if (valign == LWButton::Bottom)
75 by = y+h-bh-1;
76 else if (valign == LWButton::Center)
77 by = y+(h-bh)/2;
78 buttons[i]->setPosition (bx, by);
80 aw = w;
81 ah = h;
82 ax = x;
83 ay = y;
86 void LWButtonSet::move (int nx, int ny) {
88 for (int i=0; i<buttons.size(); i++) {
89 int x, y;
90 buttons[i]->getPosition (x, y);
91 buttons[i]->setPosition (x+nx-ax, y+ny-ay);
94 ax = nx;
95 ay = ny;
98 void LWButtonSet::redraw (Cairo::RefPtr<Cairo::Context> context) {
100 for (int i=0; i<buttons.size(); i++)
101 buttons[i]->redraw (context);
104 bool LWButtonSet::motionNotify (int x, int y) {
106 bool res = false;
107 for (int i=0; i<buttons.size(); i++) {
108 bool handled = buttons[i]->motionNotify (x, y);
109 res = res || handled;
112 return res;
115 bool LWButtonSet::pressNotify (int x, int y) {
117 bool res = false;
118 for (int i=0; i<buttons.size(); i++) {
119 bool handled = buttons[i]->pressNotify (x, y);
120 res = res || handled;
122 return res;
125 bool LWButtonSet::releaseNotify (int x, int y) {
127 bool res = false;
128 for (int i=0; i<buttons.size(); i++) {
129 bool handled = buttons[i]->releaseNotify (x, y);
130 res = res || handled;
132 return res;
135 bool LWButtonSet::inside (int x, int y) {
137 for (int i=0; i<buttons.size(); i++)
138 if (buttons[i]->inside (x, y))
139 return true;
140 return false;
143 void LWButtonSet::setButtonListener (LWButtonListener* bl) {
145 for (int i=0; i<buttons.size(); i++)
146 buttons[i]->setButtonListener (bl);
149 void LWButtonSet::getAllocatedDimensions (int& w, int& h) {
151 w = aw;
152 h = ah;
155 void LWButtonSet::setColors (const Gdk::Color& bg, const Gdk::Color& fg) {
157 for (int i=0; i<buttons.size(); i++)
158 buttons[i]->setColors (bg, fg);
161 Glib::ustring LWButtonSet::getToolTip (int x, int y) {
163 for (int i=0; i<buttons.size(); i++) {
164 Glib::ustring ttip = buttons[i]->getToolTip (x, y);
165 if (ttip!="")
166 return ttip;
168 return "";