00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00023
00024 #include "WinButton.hh"
00025 #include "App.hh"
00026 #include "Window.hh"
00027 #include "WinButtonTheme.hh"
00028
00029 WinButton::WinButton(const FluxboxWindow &listen_to,
00030 WinButtonTheme &theme,
00031 Type buttontype, const FbTk::FbWindow &parent,
00032 int x, int y,
00033 unsigned int width, unsigned int height):
00034 FbTk::Button(parent, x, y, width, height),
00035 m_type(buttontype), m_listen_to(listen_to), m_theme(theme) {
00036
00037 theme.reconfigSig().attach(this);
00038 }
00039
00040 void WinButton::exposeEvent(XExposeEvent &event) {
00041 FbTk::Button::exposeEvent(event);
00042 drawType(false, false);
00043 }
00044
00045 void WinButton::buttonReleaseEvent(XButtonEvent &event) {
00046 FbTk::Button::buttonReleaseEvent(event);
00047 clear();
00048 updateTransparent();
00049 }
00050
00051
00052 void WinButton::drawType(bool clear, bool no_trans) {
00053 bool used = false;
00054
00055
00056 int oddW = width()%2;
00057 int oddH = height()%2;
00058
00059 switch (m_type) {
00060 case MAXIMIZE:
00061
00062 if (pressed() && m_theme.maximizePressedPixmap().pixmap().drawable() != 0) {
00063 FbTk::FbWindow::setBackgroundPixmap(m_theme.
00064 maximizePressedPixmap().
00065 pixmap().drawable());
00066 used = true;
00067 } else {
00068
00069 if (!m_listen_to.isFocused()) {
00070 if (m_theme.maximizeUnfocusPixmap().pixmap().drawable() != 0) {
00071
00072 FbTk::FbWindow::setBackgroundPixmap(m_theme.
00073 maximizeUnfocusPixmap().
00074 pixmap().drawable());
00075 used = true;
00076 }
00077 } else if (m_theme.maximizePixmap().pixmap().drawable() != 0) {
00078 FbTk::FbWindow::setBackgroundPixmap(m_theme.
00079 maximizePixmap().
00080 pixmap().drawable());
00081 used = true;
00082 }
00083 }
00084 if (used || clear)
00085 FbTk::FbWindow::clear();
00086
00087
00088 if (!used) {
00089 if (gc() == 0)
00090 return;
00091
00092 drawRectangle(gc(),
00093 2, 2, width() - 5, height() - 5);
00094 drawLine(gc(),
00095 2, 3, width() - 3, 3);
00096 }
00097 break;
00098 case MINIMIZE:
00099
00100 if (pressed() && m_theme.iconifyPressedPixmap().pixmap().drawable() != 0) {
00101 FbTk::FbWindow::setBackgroundPixmap(m_theme.
00102 iconifyPressedPixmap().
00103 pixmap().drawable());
00104 used = true;
00105 } else {
00106 if (m_theme.iconifyPixmap().pixmap().drawable()){
00107
00108 if (!m_listen_to.isFocused()) {
00109 if (m_theme.iconifyUnfocusPixmap().pixmap().drawable() != 0) {
00110
00111 FbTk::FbWindow::setBackgroundPixmap(m_theme.
00112 iconifyUnfocusPixmap().
00113 pixmap().drawable());
00114 used = true;
00115 }
00116 } else if (m_theme.iconifyPixmap().pixmap().drawable() != 0) {
00117 FbTk::FbWindow::setBackgroundPixmap(m_theme.
00118 iconifyPixmap().
00119 pixmap().drawable());
00120 used = true;
00121 }
00122 }
00123
00124 }
00125
00126 if (used || clear) {
00127 FbTk::FbWindow::clear();
00128 }
00129 if (!used && gc() != 0) {
00130 FbTk::FbWindow::drawRectangle(gc(),
00131 2, height() - 5, width() - 5, 2);
00132 }
00133 break;
00134 case STICK:
00135
00136 if (m_listen_to.isStuck() && !pressed()) {
00137 if ( m_theme.stuckPixmap().pixmap().drawable() &&
00138 ! pressed()) {
00139
00140 if (!m_listen_to.isFocused()) {
00141 if ( m_theme.stuckUnfocusPixmap().pixmap().drawable() != 0) {
00142
00143 FbTk::FbWindow::setBackgroundPixmap(m_theme.
00144 stuckUnfocusPixmap().
00145 pixmap().drawable());
00146 used = true;
00147 }
00148 } else if (m_theme.stuckPixmap().pixmap().drawable() != 0) {
00149
00150 FbTk::FbWindow::setBackgroundPixmap(m_theme.
00151 stuckPixmap().
00152 pixmap().drawable());
00153 used = true;
00154 }
00155 }
00156 } else {
00157 if (pressed()) {
00158 if (m_theme.stickPressedPixmap().pixmap().drawable() != 0) {
00159 FbTk::FbWindow::setBackgroundPixmap(m_theme.
00160 stickPressedPixmap().
00161 pixmap().drawable());
00162 used = true;
00163 }
00164 } else {
00165
00166 if (!m_listen_to.isFocused()) {
00167 if (m_theme.stickUnfocusPixmap().pixmap().drawable() != 0) {
00168
00169 FbTk::FbWindow::setBackgroundPixmap(m_theme.
00170 stickUnfocusPixmap().
00171 pixmap().drawable());
00172 used = true;
00173 }
00174 } else if (m_theme.stickPixmap().pixmap().drawable()) {
00175 FbTk::FbWindow::setBackgroundPixmap(m_theme.
00176 stickPixmap().
00177 pixmap().drawable());
00178 used = true;
00179 }
00180
00181 }
00182
00183 }
00184
00185 if (used || clear)
00186 FbTk::FbWindow::clear();
00187
00188 if (!used && gc() != 0) {
00189
00190 if (m_listen_to.isStuck()) {
00191 fillRectangle(gc(),
00192 width()/2 - width()/4, height()/2 - height()/4,
00193 width()/4*2 + oddW, height()/4*2 + oddH);
00194 } else {
00195 fillRectangle(gc(),
00196 width()/2 - width()/10, height()/2 - height()/10,
00197 width()/10*2 + oddW, height()/10*2 + oddH);
00198 }
00199 }
00200 break;
00201 case CLOSE:
00202
00203 if (pressed()) {
00204 if (m_theme.closePressedPixmap().pixmap().drawable()) {
00205 FbTk::FbWindow::setBackgroundPixmap(m_theme.
00206 closePressedPixmap().
00207 pixmap().drawable());
00208 used = true;
00209 }
00210 } else {
00211
00212 if (!m_listen_to.isFocused()) {
00213 if (m_theme.closeUnfocusPixmap().pixmap().drawable() != 0) {
00214
00215 FbTk::FbWindow::setBackgroundPixmap(m_theme.
00216 closeUnfocusPixmap().
00217 pixmap().drawable());
00218 used = true;
00219 }
00220 } else if (m_theme.closePixmap().pixmap().drawable() != 0) {
00221 FbTk::FbWindow::setBackgroundPixmap(m_theme.
00222 closePixmap().
00223 pixmap().drawable());
00224 used = true;
00225 }
00226 }
00227
00228
00229 if (used || clear)
00230 FbTk::FbWindow::clear();
00231
00232 if (!used && gc() != 0) {
00233
00234 drawLine(gc(),
00235 2, 2,
00236 width() - 2, height() - 2);
00237
00238
00239
00240
00241
00242 drawLine(gc(),
00243 2, height() - 3,
00244 width() - 2, 1);
00245 }
00246 break;
00247 case SHADE:
00248
00249 if (pressed()) {
00250 if (m_theme.shadePressedPixmap().pixmap().drawable()) {
00251 FbTk::FbWindow::setBackgroundPixmap(m_theme.
00252 shadePressedPixmap().
00253 pixmap().drawable());
00254 used = true;
00255 }
00256 } else {
00257
00258 if (!m_listen_to.isFocused()) {
00259 if ( m_theme.shadeUnfocusPixmap().pixmap().drawable() != 0) {
00260
00261 FbTk::FbWindow::setBackgroundPixmap(m_theme.
00262 shadeUnfocusPixmap().
00263 pixmap().drawable());
00264 used = true;
00265 }
00266 } else if (m_theme.shadePixmap().pixmap().drawable() != 0) {
00267 FbTk::FbWindow::setBackgroundPixmap(m_theme.
00268 shadePixmap().
00269 pixmap().drawable());
00270 used = true;
00271 }
00272 }
00273
00274 if (used || clear)
00275 FbTk::FbWindow::clear();
00276
00277 break;
00278 }
00279 if ((used || clear) && !no_trans)
00280 updateTransparent();
00281 }
00282
00283 void WinButton::clear() {
00284 drawType(true, true);
00285 }
00286
00287 void WinButton::update(FbTk::Subject *subj) {
00288 clear();
00289 }