Logo
  • Main Page
  • Related Pages
  • Modules
  • Classes
  • Files

mmsmenuwidget.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005-2007 Stefan Schwarzer, Jens Schneider,             *
00003  *                           Matthias Hardt, Guido Madaus                  *
00004  *                                                                         *
00005  *   Copyright (C) 2007-2008 BerLinux Solutions GbR                        *
00006  *                           Stefan Schwarzer & Guido Madaus               *
00007  *                                                                         *
00008  *   Copyright (C) 2009-2013 BerLinux Solutions GmbH                       *
00009  *                                                                         *
00010  *   Authors:                                                              *
00011  *      Stefan Schwarzer   <stefan.schwarzer@diskohq.org>,                 *
00012  *      Matthias Hardt     <matthias.hardt@diskohq.org>,                   *
00013  *      Jens Schneider     <jens.schneider@diskohq.org>,                   *
00014  *      Guido Madaus       <guido.madaus@diskohq.org>,                     *
00015  *      Patrick Helterhoff <patrick.helterhoff@diskohq.org>,               *
00016  *      René Bählkow       <rene.baehlkow@diskohq.org>                     *
00017  *                                                                         *
00018  *   This library is free software; you can redistribute it and/or         *
00019  *   modify it under the terms of the GNU Lesser General Public            *
00020  *   License version 2.1 as published by the Free Software Foundation.     *
00021  *                                                                         *
00022  *   This library is distributed in the hope that it will be useful,       *
00023  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00024  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00025  *   Lesser General Public License for more details.                       *
00026  *                                                                         *
00027  *   You should have received a copy of the GNU Lesser General Public      *
00028  *   License along with this library; if not, write to the                 *
00029  *   Free Software Foundation, Inc.,                                       *
00030  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
00031  **************************************************************************/
00032 
00033 #ifndef MMSMENUWIDGET_H_
00034 #define MMSMENUWIDGET_H_
00035 
00036 #include "mmsgui/mmswidget.h"
00037 
00038 //! current mode of the pulser
00039 typedef enum {
00040     //! scroll smooth to the bottom
00041     MMSMENUWIDGET_PULSER_MODE_SCROLL_DOWN = 0,
00042     //! scroll smooth to the top
00043     MMSMENUWIDGET_PULSER_MODE_SCROLL_UP,
00044     //! scroll smooth to the left
00045     MMSMENUWIDGET_PULSER_MODE_SCROLL_LEFT,
00046     //! scroll smooth to the right
00047     MMSMENUWIDGET_PULSER_MODE_SCROLL_RIGHT,
00048     //! move selection smooth to the bottom
00049     MMSMENUWIDGET_PULSER_MODE_MOVESEL_DOWN,
00050     //! move selection smooth to the top
00051     MMSMENUWIDGET_PULSER_MODE_MOVESEL_UP,
00052     //! move selection smooth to the left
00053     MMSMENUWIDGET_PULSER_MODE_MOVESEL_LEFT,
00054     //! move selection smooth to the right
00055     MMSMENUWIDGET_PULSER_MODE_MOVESEL_RIGHT
00056 } MMSMENUWIDGET_PULSER_MODE;
00057 
00058 //! With this class you can display a list of items.
00059 /*!
00060 The menu widget is focusable. So the user can scroll in it.
00061 Menu items are normal widgets. But the root widget of an menu item has to be a focusable widget.
00062 The root widget is normally a MMSButton widget.
00063 Please note that you can nesting all other widgets under the root widget of the menu item.
00064 So you can build complex menu items. But think about the performance if you work with menus
00065 with an high number of items.
00066 \author Jens Schneider
00067 */
00068 class MMSMenuWidget : public MMSWidget {
00069     private:
00070         typedef struct {
00071             string          name;
00072             class MMSWindow *window;
00073             MMSMenuWidget   *menu;
00074         } MMSMENUITEMINFOS;
00075 
00076         string              className;
00077         MMSMenuWidgetClass  *menuWidgetClass;
00078         MMSMenuWidgetClass  myMenuWidgetClass;
00079 
00080 
00081         MMSFBSurface    *selimage;
00082         MMSWidget       *itemTemplate;
00083 
00084         int             item_w;     /* width of an item */
00085         int             item_h;     /* height of an item */
00086         int             v_items;    /* number of visible vertical items */
00087         int             h_items;    /* number of visible horizontal items */
00088 
00089         //! x position of the selected item
00090         int             x;
00091         //! y position of the selected item
00092         int             y;
00093         //! scroll x-offset
00094         int             px;
00095         //! scroll y-offset
00096         int             py;
00097 
00098         bool            firstFocus;
00099         bool            firstSelection;
00100 
00101         bool            zoomsel;        /* should the selected item zoomed? */
00102         unsigned int    zoomselwidth;   /* this value will be added to item_w for the selected item */
00103         unsigned int    zoomselheight;  /* this value will be added to item_h for the selected item */
00104         int             zoomselshiftx;  /* x-move the unselected items around the selected item */
00105         int             zoomselshifty;  /* y-move the unselected items around the selected item */
00106 
00107         //! smooth scrolling mode
00108         MMSSEQUENCEMODE smooth_scrolling;
00109         int             scrolling_offset;
00110 
00111         //! smooth selection mode
00112         MMSSEQUENCEMODE smooth_selection;
00113         int             selection_offset_x;
00114         int             selection_offset_y;
00115 
00116         unsigned int    frame_delay;
00117         unsigned int    frame_delay_set;
00118 
00119         //! Pulser for e.g. fade/move animations
00120         MMSPulser               pulser;
00121 
00122         //! connection object for MMSPulser::onBeforeAnimation callback
00123         sigc::connection        onBeforeAnimation_connection;
00124 
00125         //! connection object for MMSPulser::onAnimation callback
00126         sigc::connection        onAnimation_connection;
00127 
00128         //! connection object for MMSPulser::onAfterAnimation callback
00129         sigc::connection        onAfterAnimation_connection;
00130 
00131         //! current pulser mode
00132         MMSMENUWIDGET_PULSER_MODE   pulser_mode;
00133 
00134         //! offset to calculate the animation
00135         double      anim_offset;
00136 
00137         //! number of menu items to jump over during the animation
00138         int         anim_jumpover;
00139 
00140         //! factor to calculate the animation
00141         double      anim_factor;
00142 
00143 
00144 
00145         MMSFBRectangle  virtualGeom;
00146 
00147         //! this will be used to show/hide the menu and its whole parent window(s)
00148         //! normally this is the same as widgets rootwindow, but it can also be the a parent from widgets rootwindow
00149         MMSWindow       *parent_window;
00150 
00151         //! represents additional informations for each menu item
00152         vector<MMSMENUITEMINFOS>    iteminfos;
00153 
00154         //! if != -1 then currently activated submenu is set
00155         int             curr_submenu;
00156 
00157         //! if a submenu does appear, we will save the parent menu here which will used to go back
00158         MMSMenuWidget   *parent_menu;
00159 
00160         //! if != -1 then the item with this id is set as go-back-item
00161         //! if the user enters this item, the parent menu (if does exist) will be shown
00162         int             back_item;
00163 
00164         bool create(MMSWindow *root, string className, MMSTheme *theme);
00165 
00166         bool init();
00167         bool release();
00168         void lock();
00169         void unlock();
00170 
00171         bool draw(bool *backgroundFilled = NULL);
00172 
00173         void add(MMSWidget *widget);
00174 
00175         void adjustVirtualRect();
00176 
00177         bool getConfig(bool *firstTime = NULL);
00178 
00179         void drawchildren(bool toRedrawOnly = false, bool *backgroundFilled = NULL, MMSFBRectangle *rect2update = NULL);
00180         void recalculateChildren();
00181 
00182         void initParentWindow(void);
00183         void setRootWindow(MMSWindow *root, MMSWindow *parentroot = NULL);
00184 
00185         void switchArrowWidgets();
00186         void setSliders();
00187 
00188         bool setSelected(unsigned int item, bool refresh, bool *changed, bool joined);
00189 
00190         void selectItem(MMSWidget *item, bool set, bool refresh = true, bool refreshall = false);
00191 
00192 
00193         bool onBeforeAnimation(MMSPulser *pulser);
00194         bool onAnimation(MMSPulser *pulser);
00195         void onAfterAnimation(MMSPulser *pulser);
00196 
00197         void startAnimation(MMSMENUWIDGET_PULSER_MODE pulser_mode, double anim_offset, int anim_jumpover);
00198 
00199 
00200         bool scrollDownEx(unsigned int count, bool refresh, bool test, bool leave_selection);
00201         bool scrollUpEx(unsigned int count, bool refresh, bool test, bool leave_selection);
00202         bool scrollRightEx(unsigned int count, bool refresh, bool test, bool leave_selection);
00203         bool scrollLeftEx(unsigned int count, bool refresh, bool test, bool leave_selection);
00204 
00205         void emitOnReturnForParents(MMSMenuWidget *orw);
00206         bool callOnReturn();
00207 
00208         bool switchToSubMenu();
00209         bool switchBackToParentMenu(MMSDIRECTION direction = MMSDIRECTION_NOTSET, bool closeall = false);
00210 
00211     public:
00212         MMSMenuWidget(MMSWindow *root, string className, MMSTheme *theme = NULL);
00213         ~MMSMenuWidget();
00214 
00215         MMSWidget *copyWidget();
00216 
00217         void setItemTemplate(MMSWidget *itemTemplate);
00218         MMSWidget *getItemTemplate();
00219 
00220         //! Create a new menu item and push it at a specific position of the list.
00221         /*!
00222         \param item         position of the new item in the list, default -1 means end of list
00223         \param itemWidget   if NULL    : the style of the new item is based on the itemTemplate
00224                             if not NULL: the already allocated widget will be used as the new item and should not deleted
00225         \return pointer of the new item widget
00226         */
00227         MMSWidget *newItem(int item = -1, MMSWidget *widget = NULL);
00228 
00229         //! Delete a menu item.
00230         /*!
00231         \param item  position of the item which is to be deleted
00232         */
00233         void deleteItem(unsigned int item);
00234 
00235         //! Clear the menu and deletes all items.
00236         void clear();
00237 
00238         void setFocus(bool set, bool refresh = true, MMSInputEvent *inputevent = NULL);
00239 
00240         bool setSelected(unsigned int item, bool refresh = true);
00241         unsigned int getSelected();
00242 
00243         MMSWidget *getItem(unsigned int item);
00244         MMSWidget *getSelectedItem();
00245 
00246         unsigned int getSize();
00247 
00248         unsigned int getVItems();
00249         unsigned int getHItems();
00250 
00251         bool scrollDown(unsigned int count = 1, bool refresh = true, bool test = false, bool leave_selection = false);
00252         bool scrollUp(unsigned int count = 1, bool refresh = true, bool test = false, bool leave_selection = false);
00253         bool scrollRight(unsigned int count = 1, bool refresh = true, bool test = false, bool leave_selection = false);
00254         bool scrollLeft(unsigned int count = 1, bool refresh = true, bool test = false, bool leave_selection = false);
00255         bool scrollTo(int posx, int posy, bool refresh = true, bool *changed = NULL,
00256                       MMSWIDGET_SCROLL_MODE mode = MMSWIDGET_SCROLL_MODE_SETSELECTED, MMSFBRectangle *inputrect = NULL);
00257 
00258         bool setSubMenuName(unsigned int item, const char *name);
00259         bool setSubMenuName(unsigned int item, string &name);
00260         bool setBackItem(unsigned int item);
00261 
00262         sigc::signal<void, MMSWidget*> *onSelectItem;
00263         sigc::signal<void, MMSWidget*> *onBeforeScroll;
00264 
00265     public:
00266         /* theme access methods */
00267         MMSTaffFile *getTAFF();
00268         string getItemWidth();
00269         string getItemHeight();
00270         unsigned int getItemHMargin();
00271         unsigned int getItemVMargin();
00272         unsigned int getCols();
00273         unsigned int getDimItems();
00274         int getFixedPos();
00275         bool getHLoop();
00276         bool getVLoop();
00277         unsigned int getTransItems();
00278         unsigned int getDimTop();
00279         unsigned int getDimBottom();
00280         unsigned int getDimLeft();
00281         unsigned int getDimRight();
00282         unsigned int getTransTop();
00283         unsigned int getTransBottom();
00284         unsigned int getTransLeft();
00285         unsigned int getTransRight();
00286         string getZoomSelWidth();
00287         string getZoomSelHeight();
00288         string getZoomSelShiftX();
00289         string getZoomSelShiftY();
00290         MMSSEQUENCEMODE getSmoothScrolling();
00291         string getParentWindow();
00292         bool getSelImagePath(string &selimagepath);
00293         bool getSelImageName(string &selimagename);
00294         MMSSEQUENCEMODE getSmoothSelection();
00295         unsigned int getSmoothDelay();
00296 
00297         void setItemWidth(string itemwidth, bool refresh = true);
00298         void setItemHeight(string itemheight, bool refresh = true);
00299         void setItemHMargin(unsigned int itemhmargin, bool refresh = true);
00300         void setItemVMargin(unsigned int itemvmargin, bool refresh = true);
00301         void setCols(unsigned int cols, bool refresh = true);
00302         void setDimItems(unsigned int dimitems, bool refresh = true);
00303         void setFixedPos(int fixedpos, bool refresh = true);
00304         void setHLoop(bool hloop);
00305         void setVLoop(bool vloop);
00306         void setTransItems(unsigned int transitems, bool refresh = true);
00307         void setDimTop(unsigned int dimtop, bool refresh = true);
00308         void setDimBottom(unsigned int dimbottom, bool refresh = true);
00309         void setDimLeft(unsigned int dimleft, bool refresh = true);
00310         void setDimRight(unsigned int dimright, bool refresh = true);
00311         void setTransTop(unsigned int transtop, bool refresh = true);
00312         void setTransBottom(unsigned int transbottom, bool refresh = true);
00313         void setTransLeft(unsigned int transleft, bool refresh = true);
00314         void setTransRight(unsigned int transright, bool refresh = true);
00315         void setZoomSelWidth(string zoomselwidth, bool refresh = true);
00316         void setZoomSelHeight(string zoomselheight, bool refresh = true);
00317         void setZoomSelShiftX(string zoomselshiftx, bool refresh = true);
00318         void setZoomSelShiftY(string zoomselshifty, bool refresh = true);
00319         void setSmoothScrolling(MMSSEQUENCEMODE seq_mode);
00320         void setParentWindow(string parentwindow);
00321         void setSelImagePath(string selimagepath, bool load = true, bool refresh = true);
00322         void setSelImageName(string selimagename, bool load = true, bool refresh = true);
00323         void setSmoothSelection(MMSSEQUENCEMODE seq_mode);
00324         void setSmoothDelay(unsigned int smoothdelay);
00325 
00326         void updateFromThemeClass(MMSMenuWidgetClass *themeClass);
00327 };
00328 
00329 #endif /*MMSMENUWIDGET_H_*/
00330 

Generated by doxygen