LCOV - code coverage report
Current view: top level - sc/source/ui/inc - checklistmenu.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 7 0.0 %
Date: 2012-08-25 Functions: 0 11 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 12 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*
       3                 :            :  * Version: MPL 1.1 / GPLv3+ / LGPLv3+
       4                 :            :  *
       5                 :            :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :            :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :            :  * the License or as specified alternatively below. You may obtain a copy of
       8                 :            :  * the License at http://www.mozilla.org/MPL/
       9                 :            :  *
      10                 :            :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :            :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :            :  * for the specific language governing rights and limitations under the
      13                 :            :  * License.
      14                 :            :  *
      15                 :            :  * Major Contributor(s):
      16                 :            :  *   Copyright (C) 2011 Kohei Yoshida <kohei.yoshida@suse.com>
      17                 :            :  *
      18                 :            :  * All Rights Reserved.
      19                 :            :  *
      20                 :            :  * For minor contributions see the git repository.
      21                 :            :  *
      22                 :            :  * Alternatively, the contents of this file may be used under the terms of
      23                 :            :  * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
      24                 :            :  * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
      25                 :            :  * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
      26                 :            :  * instead of those above.
      27                 :            :  */
      28                 :            : 
      29                 :            : #ifndef __SC_CHECKLISTMENU_HXX__
      30                 :            : #define __SC_CHECKLISTMENU_HXX__
      31                 :            : 
      32                 :            : #include "vcl/popupmenuwindow.hxx"
      33                 :            : #include "vcl/button.hxx"
      34                 :            : #include "vcl/scrbar.hxx"
      35                 :            : #include "vcl/timer.hxx"
      36                 :            : #include "svx/checklbx.hxx"
      37                 :            : 
      38                 :            : #include <boost/unordered_map.hpp>
      39                 :            : #include <boost/scoped_ptr.hpp>
      40                 :            : 
      41                 :            : namespace com { namespace sun { namespace star {
      42                 :            : 
      43                 :            :     namespace accessibility {
      44                 :            :         class XAccessible;
      45                 :            :     }
      46                 :            : 
      47                 :            : }}}
      48                 :            : 
      49                 :            : class ScDocument;
      50                 :            : class ScAccessibleFilterMenu;
      51                 :            : 
      52                 :            : class ScMenuFloatingWindow : public PopupMenuFloatingWindow
      53                 :            : {
      54                 :            : public:
      55                 :            :     static size_t MENU_NOT_SELECTED;
      56                 :            :     /**
      57                 :            :      * Action to perform when an event takes place.  Create a sub-class of
      58                 :            :      * this to implement the desired action.
      59                 :            :      */
      60                 :          0 :     class Action
      61                 :            :     {
      62                 :            :     public:
      63         [ #  # ]:          0 :         virtual ~Action() {}
      64                 :            :         virtual void execute() = 0;
      65                 :            :     };
      66                 :            : 
      67                 :            :     explicit ScMenuFloatingWindow(Window* pParent, ScDocument* pDoc, sal_uInt16 nMenuStackLevel = 0);
      68                 :            :     virtual ~ScMenuFloatingWindow();
      69                 :            : 
      70                 :            :     virtual void PopupModeEnd();
      71                 :            :     virtual void MouseMove(const MouseEvent& rMEvt);
      72                 :            :     virtual void MouseButtonDown(const MouseEvent& rMEvt);
      73                 :            :     virtual void MouseButtonUp(const MouseEvent& rMEvt);
      74                 :            :     virtual void KeyInput(const KeyEvent& rKEvt);
      75                 :            :     virtual void Paint(const Rectangle& rRect);
      76                 :            :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > CreateAccessible();
      77                 :            : 
      78                 :            :     void addMenuItem(const ::rtl::OUString& rText, bool bEnabled, Action* pAction);
      79                 :            :     void addSeparator();
      80                 :            : 
      81                 :            :     ScMenuFloatingWindow* addSubMenuItem(const ::rtl::OUString& rText, bool bEnabled);
      82                 :            :     void setSelectedMenuItem(size_t nPos, bool bSubMenuTimer, bool bEnsureSubMenu);
      83                 :            :     void selectMenuItem(size_t nPos, bool bSelected, bool bSubMenuTimer);
      84                 :            :     void clearSelectedMenuItem();
      85                 :            :     ScMenuFloatingWindow* getSubMenuWindow(size_t nPos) const;
      86                 :            :     bool isMenuItemSelected(size_t nPos) const;
      87                 :            :     size_t getSelectedMenuItem() const;
      88                 :            : 
      89                 :            :     void setName(const ::rtl::OUString& rName);
      90                 :            :     const ::rtl::OUString& getName() const;
      91                 :            : 
      92                 :            :     void executeMenuItem(size_t nPos);
      93                 :            :     void getMenuItemPosSize(size_t nPos, Point& rPos, Size& rSize) const;
      94                 :            :     ScMenuFloatingWindow* getParentMenuWindow() const;
      95                 :            : 
      96                 :            : protected:
      97                 :            :     virtual void handlePopupEnd();
      98                 :            : 
      99                 :            :     Size getMenuSize() const;
     100                 :            :     void drawMenuItem(size_t nPos);
     101                 :            :     void drawSeparator(size_t nPos);
     102                 :            :     void drawAllMenuItems();
     103                 :            :     const Font& getLabelFont() const;
     104                 :            : 
     105                 :            :     void queueLaunchSubMenu(size_t nPos, ScMenuFloatingWindow* pMenu);
     106                 :            :     void queueCloseSubMenu();
     107                 :            :     void launchSubMenu(bool bSetMenuPos);
     108                 :            :     void endSubMenu(ScMenuFloatingWindow* pSubMenu);
     109                 :            : 
     110                 :            :     void fillMenuItemsToAccessible(ScAccessibleFilterMenu* pAccMenu) const;
     111                 :            : 
     112                 :            :     ScDocument* getDoc();
     113                 :            : 
     114                 :            : protected:
     115                 :            :     ::com::sun::star::uno::Reference<
     116                 :            :         ::com::sun::star::accessibility::XAccessible > mxAccessible;
     117                 :            : 
     118                 :            : private:
     119                 :            :     struct SubMenuItemData;
     120                 :            :     void handleMenuTimeout(SubMenuItemData* pTimer);
     121                 :            : 
     122                 :            :     void resizeToFitMenuItems();
     123                 :            :     void highlightMenuItem(size_t nPos, bool bSelected);
     124                 :            : 
     125                 :            :     size_t getEnclosingMenuItem(const Point& rPos) const;
     126                 :            :     size_t getSubMenuPos(ScMenuFloatingWindow* pSubMenu);
     127                 :            : 
     128                 :            :     /**
     129                 :            :      * Fire a menu highlight event since the accessibility framework needs
     130                 :            :      * this to track focus on menu items.
     131                 :            :      */
     132                 :            :     void fireMenuHighlightedEvent();
     133                 :            : 
     134                 :            :     /**
     135                 :            :      * Make sure that the specified submenu is permanently up, the submenu
     136                 :            :      * close timer is not active, and the correct menu item associated with
     137                 :            :      * the submenu is highlighted.
     138                 :            :      */
     139                 :            :     void setSubMenuFocused(ScMenuFloatingWindow* pSubMenu);
     140                 :            : 
     141                 :            :     /**
     142                 :            :      * When a menu item of an invisible submenu is selected, we need to make
     143                 :            :      * sure that all its parent menu(s) are visible, with the right menu item
     144                 :            :      * highlighted in each of the parents.  Calling this method ensures it.
     145                 :            :      */
     146                 :            :     void ensureSubMenuVisible(ScMenuFloatingWindow* pSubMenu);
     147                 :            : 
     148                 :            :     /**
     149                 :            :      * Dismiss any visible child submenus when a menu item of a parent menu is
     150                 :            :      * selected.
     151                 :            :      */
     152                 :            :     void ensureSubMenuNotVisible();
     153                 :            : 
     154                 :            :     /**
     155                 :            :      * Dismiss all visible popup menus and set focus back to the application
     156                 :            :      * window.  This method is called e.g. when a menu action is fired.
     157                 :            :      */
     158                 :            :     void terminateAllPopupMenus();
     159                 :            : 
     160                 :            : private:
     161                 :            : 
     162 [ #  # ][ #  # ]:          0 :     struct MenuItemData
         [ #  # ][ #  # ]
     163                 :            :     {
     164                 :            :         ::rtl::OUString maText;
     165                 :            :         bool            mbEnabled:1;
     166                 :            :         bool            mbSeparator:1;
     167                 :            : 
     168                 :            :         ::boost::shared_ptr<Action> mpAction;
     169                 :            :         ::boost::shared_ptr<ScMenuFloatingWindow> mpSubMenuWin;
     170                 :            : 
     171                 :            :         MenuItemData();
     172                 :            :     };
     173                 :            : 
     174                 :            :     ::std::vector<MenuItemData>         maMenuItems;
     175                 :            : 
     176                 :          0 :     struct SubMenuItemData
     177                 :            :     {
     178                 :            :         Timer                   maTimer;
     179                 :            :         ScMenuFloatingWindow*   mpSubMenu;
     180                 :            :         size_t                  mnMenuPos;
     181                 :            : 
     182                 :            :         DECL_LINK( TimeoutHdl, void* );
     183                 :            : 
     184                 :            :         SubMenuItemData(ScMenuFloatingWindow* pParent);
     185                 :            :         void reset();
     186                 :            : 
     187                 :            :     private:
     188                 :            :         ScMenuFloatingWindow* mpParent;
     189                 :            :     };
     190                 :            :     SubMenuItemData   maOpenTimer;
     191                 :            :     SubMenuItemData   maCloseTimer;
     192                 :            : 
     193                 :            :     Font    maLabelFont;
     194                 :            : 
     195                 :            :     // Name of this menu window, taken from the menu item of the parent window
     196                 :            :     // that launches it (if this is a sub menu).  If this is a top-level menu
     197                 :            :     // window, then this name can be anything.
     198                 :            :     ::rtl::OUString maName;
     199                 :            : 
     200                 :            :     size_t  mnSelectedMenu;
     201                 :            :     size_t  mnClickedMenu;
     202                 :            : 
     203                 :            :     ScDocument* mpDoc;
     204                 :            : 
     205                 :            :     ScMenuFloatingWindow* mpParentMenu;
     206                 :            :     ScMenuFloatingWindow* mpActiveSubMenu;
     207                 :            : };
     208                 :            : 
     209                 :            : /**
     210                 :            :  * This class implements a popup window for field button, for quick access
     211                 :            :  * of hide-item list, and possibly more stuff related to field options.
     212                 :            :  */
     213                 :            : class ScCheckListMenuWindow : public ScMenuFloatingWindow
     214                 :            : {
     215                 :            : public:
     216                 :            :     typedef boost::unordered_map<rtl::OUString, bool, rtl::OUStringHash> ResultType;
     217                 :            : 
     218                 :            :     /**
     219                 :            :      * Extended data that the client code may need to store.  Create a
     220                 :            :      * sub-class of this and store data there.
     221                 :            :      */
     222                 :          0 :     struct ExtendedData {};
     223                 :            : 
     224                 :            :     /**
     225                 :            :      * Configuration options for this popup window.
     226                 :            :      */
     227                 :            :     struct Config
     228                 :            :     {
     229                 :            :         bool mbAllowEmptySet;
     230                 :            :         Config();
     231                 :            :     };
     232                 :            : 
     233                 :            :     explicit ScCheckListMenuWindow(Window* pParent, ScDocument* pDoc);
     234                 :            :     virtual ~ScCheckListMenuWindow();
     235                 :            : 
     236                 :            :     virtual void MouseMove(const MouseEvent& rMEvt);
     237                 :            :     virtual long Notify(NotifyEvent& rNEvt);
     238                 :            :     virtual void Paint(const Rectangle& rRect);
     239                 :            :     virtual Window* GetPreferredKeyInputWindow();
     240                 :            :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > CreateAccessible();
     241                 :            : 
     242                 :            :     void setMemberSize(size_t n);
     243                 :            :     void addMember(const ::rtl::OUString& rName, bool bVisible);
     244                 :            :     void initMembers();
     245                 :            :     void setConfig(const Config& rConfig);
     246                 :            : 
     247                 :            :     const Size& getWindowSize() const;
     248                 :            : 
     249                 :            :     bool isAllSelected() const;
     250                 :            :     void getResult(ResultType& rResult);
     251                 :            :     void launch(const Rectangle& rRect);
     252                 :            :     void close(bool bOK);
     253                 :            : 
     254                 :            :     /**
     255                 :            :      * Set auxiliary data that the client code might need.  Note that this
     256                 :            :      * popup window class manages its life time; no explicit deletion of the
     257                 :            :      * instance is needed in the client code.
     258                 :            :      */
     259                 :            :     void setExtendedData(ExtendedData* p);
     260                 :            : 
     261                 :            :     /**
     262                 :            :      * Get the store auxiliary data, or NULL if no such data is stored.
     263                 :            :      */
     264                 :            :     ExtendedData* getExtendedData();
     265                 :            : 
     266                 :            :     void setOKAction(Action* p);
     267                 :            :     void setPopupEndAction(Action* p);
     268                 :            : 
     269                 :            : protected:
     270                 :            :     virtual void handlePopupEnd();
     271                 :            : 
     272                 :            : private:
     273                 :          0 :     struct Member
     274                 :            :     {
     275                 :            :         ::rtl::OUString maName;
     276                 :            :         bool            mbVisible;
     277                 :            : 
     278                 :            :         Member();
     279                 :            :     };
     280                 :            : 
     281         [ #  # ]:          0 :     class CancelButton : public ::CancelButton
     282                 :            :     {
     283                 :            :     public:
     284                 :            :         CancelButton(ScCheckListMenuWindow* pParent);
     285                 :            : 
     286                 :            :         virtual void Click();
     287                 :            : 
     288                 :            :     private:
     289                 :            :         ScCheckListMenuWindow* mpParent;
     290                 :            :     };
     291                 :            : 
     292                 :            :     enum SectionType {
     293                 :            :         WHOLE,                // entire window
     294                 :            :         LISTBOX_AREA_OUTER,   // box enclosing the check box items.
     295                 :            :         LISTBOX_AREA_INNER,   // box enclosing the check box items.
     296                 :            :         SINGLE_BTN_AREA,      // box enclosing the single-action buttons.
     297                 :            :         CHECK_TOGGLE_ALL,     // check box for toggling all items.
     298                 :            :         BTN_SINGLE_SELECT,
     299                 :            :         BTN_SINGLE_UNSELECT,
     300                 :            :         BTN_OK,               // OK button
     301                 :            :         BTN_CANCEL,           // Cancel button
     302                 :            :     };
     303                 :            :     void getSectionPosSize(Point& rPos, Size& rSize, SectionType eType) const;
     304                 :            : 
     305                 :            :     /**
     306                 :            :      * Calculate the appropriate window size, the position and size of each
     307                 :            :      * control based on the menu items.
     308                 :            :      */
     309                 :            :     void packWindow();
     310                 :            :     void setAllMemberState(bool bSet);
     311                 :            :     void selectCurrentMemberOnly(bool bSet);
     312                 :            :     void cycleFocus(bool bReverse = false);
     313                 :            : 
     314                 :            :     DECL_LINK( ButtonHdl, Button* );
     315                 :            :     DECL_LINK( TriStateHdl, void* );
     316                 :            :     DECL_LINK( CheckHdl, SvTreeListBox* );
     317                 :            : 
     318                 :            : private:
     319                 :            :     SvxCheckListBox maChecks;
     320                 :            : 
     321                 :            :     TriStateBox     maChkToggleAll;
     322                 :            :     ImageButton     maBtnSelectSingle;
     323                 :            :     ImageButton     maBtnUnselectSingle;
     324                 :            : 
     325                 :            :     OKButton        maBtnOk;
     326                 :            :     CancelButton    maBtnCancel;
     327                 :            : 
     328                 :            :     ::std::vector<Window*>          maTabStopCtrls;
     329                 :            :     size_t                          mnCurTabStop;
     330                 :            : 
     331                 :            :     ::std::vector<Member>           maMembers;
     332                 :            :     boost::scoped_ptr<ExtendedData> mpExtendedData;
     333                 :            :     boost::scoped_ptr<Action>       mpOKAction;
     334                 :            :     boost::scoped_ptr<Action>       mpPopupEndAction;
     335                 :            : 
     336                 :            :     Config maConfig;
     337                 :            :     Size maWndSize;  /// whole window size.
     338                 :            :     Size maMenuSize; /// size of all menu items combined.
     339                 :            :     TriState mePrevToggleAllState;
     340                 :            : };
     341                 :            : 
     342                 :            : #endif
     343                 :            : 
     344                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10