news download themes documentation links










LayerMenu.hh

00001 // LayerMenu.hh for Fluxbox - fluxbox toolkit
00002 // Copyright (c) 2003 Henrik Kinnunen (fluxgen at users.sourceforge.net)
00003 //                and Simon Bowden    (rathnor at users.sourceforge.net)
00004 //
00005 // Permission is hereby granted, free of charge, to any person obtaining a
00006 // copy of this software and associated documentation files (the "Software"),
00007 // to deal in the Software without restriction, including without limitation
00008 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
00009 // and/or sell copies of the Software, and to permit persons to whom the
00010 // Software is furnished to do so, subject to the following conditions:
00011 //
00012 // The above copyright notice and this permission notice shall be included in
00013 // all copies or substantial portions of the Software.
00014 //
00015 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00016 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00017 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
00018 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00019 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00020 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00021 // DEALINGS IN THE SOFTWARE.
00022 
00023 // $Id: LayerMenu.hh,v 1.7 2003/12/10 23:08:03 fluxgen Exp $
00024 
00025 #ifndef LAYERMENU_HH
00026 #define LAYERMENU_HH
00027 
00028 #include "MenuItem.hh"
00029 #include "FbMenu.hh"
00030 #include "RefCount.hh"
00031 #include "SimpleCommand.hh"
00032 
00033 #include "fluxbox.hh"
00034 
00035 // provides a generic way for giving an object a layer menu
00036 
00038 template <typename ItemType> 
00039 class LayerMenuItem : public FbTk::MenuItem {
00040 public:
00041     LayerMenuItem(const char *label, ItemType *object, int layernum,
00042                   FbTk::RefCount<FbTk::Command> &cmd):
00043         FbTk::MenuItem(label,cmd), m_object(object), m_layernum(layernum) {}
00044     LayerMenuItem(const char *label, ItemType *object, int layernum):
00045         FbTk::MenuItem(label), m_object(object), m_layernum(layernum) {}
00046 
00047     bool isEnabled() const { return m_object->layerItem().getLayerNum() != m_layernum; } ;
00048     void click(int button, int time) {
00049         m_object->moveToLayer(m_layernum);
00050         FbTk::MenuItem::click(button, time);
00051     }
00052     
00053 private:
00054     ItemType *m_object;
00055     int m_layernum;
00056 };
00057 
00058 
00060 template <typename ItemType>
00061 class LayerMenu : public FbMenu {
00062 public:
00063     LayerMenu(MenuTheme &tm, FbTk::ImageControl &imgctrl,
00064               FbTk::XLayer &layer, ItemType *item, bool save_rc);
00065 
00066 private:
00067     ItemType *m_object;
00068 };
00069 
00070 
00071 template <typename ItemType>
00072 LayerMenu<ItemType>::LayerMenu(MenuTheme &tm, FbTk::ImageControl &imgctrl,
00073                                FbTk::XLayer &layer, ItemType *item, bool save_rc):
00074     FbMenu(tm, imgctrl, layer), 
00075     m_object(item) 
00076 {
00077     
00078     Fluxbox *fluxbox = Fluxbox::instance();
00079     
00080     struct {
00081         int set;
00082         int base;
00083         const char *default_str;
00084                 int layernum;
00085     } layer_menuitems[]  = {
00086         //TODO: nls
00087         {0, 0, "Above Dock", fluxbox->getAboveDockLayer()},
00088         {0, 0, "Dock", fluxbox->getDockLayer()},
00089         {0, 0, "Top", fluxbox->getTopLayer()},
00090         {0, 0, "Normal", fluxbox->getNormalLayer()},
00091         {0, 0, "Bottom", fluxbox->getBottomLayer()},
00092         {0, 0, "Desktop", fluxbox->getDesktopLayer()},
00093     };
00094     
00095     FbTk::RefCount<FbTk::Command> saverc_cmd(new FbTk::SimpleCommand<Fluxbox>(
00096                                              *Fluxbox::instance(), 
00097                                              &Fluxbox::save_rc));
00098 
00099     for (size_t i=0; i < 6; ++i) {
00100         // TODO: fetch nls string
00101         if (save_rc) {    
00102             insert(new LayerMenuItem<ItemType>(layer_menuitems[i].default_str, 
00103                                                m_object, layer_menuitems[i].layernum, saverc_cmd));
00104         } else {
00105             insert(new LayerMenuItem<ItemType>(layer_menuitems[i].default_str, 
00106                                                m_object, layer_menuitems[i].layernum));               
00107         }
00108     }
00109     update();
00110 }
00111 
00112 #endif // LAYERMENU_HH

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