news download themes documentation links










WinButton.cc

00001 // WinButton.cc for Fluxbox Window Manager
00002 // Copyright (c) 2003 Henrik Kinnunen (fluxgen at users.sourceforge.net)
00003 //
00004 // Permission is hereby granted, free of charge, to any person obtaining a
00005 // copy of this software and associated documentation files (the "Software"),
00006 // to deal in the Software without restriction, including without limitation
00007 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
00008 // and/or sell copies of the Software, and to permit persons to whom the
00009 // Software is furnished to do so, subject to the following conditions:
00010 //
00011 // The above copyright notice and this permission notice shall be included in
00012 // all copies or substantial portions of the Software.
00013 //
00014 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
00017 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00018 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00019 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00020 // DEALINGS IN THE SOFTWARE.
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 // clear is used to force this to clear the window (e.g. called from clear())
00052 void WinButton::drawType(bool clear, bool no_trans) {
00053     bool used = false;
00054 
00055     // if it's odd and we're centring, we need to add one
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             // check focus 
00069             if (!m_listen_to.isFocused()) {
00070                 if (m_theme.maximizeUnfocusPixmap().pixmap().drawable() != 0) {
00071                     // not focused
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         // if no pixmap was used, use old style
00088         if (!used) {            
00089             if (gc() == 0) // must have valid graphic context
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                 // check focus 
00108                 if (!m_listen_to.isFocused()) {
00109                     if (m_theme.iconifyUnfocusPixmap().pixmap().drawable() != 0) {
00110                         // not focused
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) { // must have valid graphic context
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()) { // we're using the same pixmap for pressed as in not stuck
00139                 // check focus 
00140                 if (!m_listen_to.isFocused()) {
00141                     if ( m_theme.stuckUnfocusPixmap().pixmap().drawable() != 0) {
00142                         // not focused
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                     // focused
00150                     FbTk::FbWindow::setBackgroundPixmap(m_theme.
00151                                                         stuckPixmap().
00152                                                         pixmap().drawable());
00153                     used = true;
00154                 }
00155             }
00156         } else { // not stuck and pressed
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 { // not pressed
00165                 // check focus 
00166                 if (!m_listen_to.isFocused()) {
00167                     if (m_theme.stickUnfocusPixmap().pixmap().drawable() != 0) {
00168                         // not focused
00169                         FbTk::FbWindow::setBackgroundPixmap(m_theme.
00170                                                             stickUnfocusPixmap().
00171                                                             pixmap().drawable());
00172                         used = true;
00173                     }
00174                 } else if (m_theme.stickPixmap().pixmap().drawable()) { // focused
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             // width/4 != width/2, so we use /4*2 so that it's properly centred
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 { // not pressed
00211             // check focus 
00212             if (!m_listen_to.isFocused()) {
00213                 if (m_theme.closeUnfocusPixmap().pixmap().drawable() != 0) {
00214                     // not focused
00215                     FbTk::FbWindow::setBackgroundPixmap(m_theme.
00216                                                         closeUnfocusPixmap().
00217                                                         pixmap().drawable());
00218                     used = true;
00219                 }
00220             } else if (m_theme.closePixmap().pixmap().drawable() != 0) { // focused
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) { // must have valid graphic context
00233 
00234             drawLine(gc(), 
00235                      2, 2,
00236                      width() - 2, height() - 2);
00237             // I can't figure out why this second one needs a y offset of 1?????
00238             // but it does - at least on my box:
00239             //   XFree86 Version 4.2.1.1 (Debian 4.2.1-12.1 20031003005825)
00240             //   (protocol Version 11, revision 0, vendor release 6600)
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 { // not pressed
00257             // check focus 
00258             if (!m_listen_to.isFocused()) {
00259                 if ( m_theme.shadeUnfocusPixmap().pixmap().drawable() != 0) {
00260                     // not focused
00261                     FbTk::FbWindow::setBackgroundPixmap(m_theme.
00262                                                         shadeUnfocusPixmap().
00263                                                         pixmap().drawable());
00264                     used = true;
00265                 }
00266             } else if (m_theme.shadePixmap().pixmap().drawable() != 0) { // focused
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 }

Fluxbox CVS-Jan-2003




      



Got comments about the page? Send them to webmaster.
If you have general Fluxbox related questions ask them on our irc channel or mailing lists.

Show Source








Designed by aLEczapKA