1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef INCLUDED_SC_SOURCE_UI_INC_CHECKLISTMENU_HXX
#define INCLUDED_SC_SOURCE_UI_INC_CHECKLISTMENU_HXX
#include <vcl/popupmenuwindow.hxx>
#include <vcl/button.hxx>
#include <vcl/edit.hxx>
#include <vcl/scrbar.hxx>
#include <vcl/timer.hxx>
#include <svx/checklbx.hxx>
#include <memory>
#include <unordered_map>
#include <map>
namespace com { namespace sun { namespace star {
namespace accessibility {
class XAccessible;
}
}}}
class ScDocument;
class ScAccessibleFilterMenu;
class ScMenuFloatingWindow : public PopupMenuFloatingWindow
{
public:
static size_t MENU_NOT_SELECTED;
/**
* Action to perform when an event takes place. Create a sub-class of
* this to implement the desired action.
*/
class Action
{
public:
virtual ~Action() {}
virtual void execute() = 0;
};
explicit ScMenuFloatingWindow(vcl::Window* pParent, ScDocument* pDoc, sal_uInt16 nMenuStackLevel = 0);
virtual ~ScMenuFloatingWindow();
void dispose() override;
virtual void PopupModeEnd() override;
virtual void MouseMove(const MouseEvent& rMEvt) override;
virtual void MouseButtonDown(const MouseEvent& rMEvt) override;
virtual void MouseButtonUp(const MouseEvent& rMEvt) override;
virtual void KeyInput(const KeyEvent& rKEvt) override;
virtual void Paint(vcl::RenderContext& rRenderContext, const Rectangle& rRect) override;
virtual css::uno::Reference<css::accessibility::XAccessible> CreateAccessible() override;
void addMenuItem(const OUString& rText, Action* pAction);
void addSeparator();
ScMenuFloatingWindow* addSubMenuItem(const OUString& rText, bool bEnabled);
void setSelectedMenuItem(size_t nPos, bool bSubMenuTimer, bool bEnsureSubMenu);
void selectMenuItem(size_t nPos, bool bSelected, bool bSubMenuTimer);
void clearSelectedMenuItem();
ScMenuFloatingWindow* getSubMenuWindow(size_t nPos) const;
bool isMenuItemSelected(size_t nPos) const;
size_t getSelectedMenuItem() const { return mnSelectedMenu;}
void setName(const OUString& rName);
const OUString& getName() const { return maName;}
void executeMenuItem(size_t nPos);
void getMenuItemPosSize(size_t nPos, Point& rPos, Size& rSize) const;
ScMenuFloatingWindow* getParentMenuWindow() const { return mpParentMenu;}
protected:
virtual void handlePopupEnd();
Size getMenuSize() const;
void drawMenuItem(vcl::RenderContext& rRenderContext, size_t nPos);
void drawSeparator(vcl::RenderContext& rRenderContext, size_t nPos);
void drawAllMenuItems(vcl::RenderContext& rRenderContext);
const vcl::Font& getLabelFont() const
{
return maLabelFont;
}
void queueLaunchSubMenu(size_t nPos, ScMenuFloatingWindow* pMenu);
void queueCloseSubMenu();
void launchSubMenu(bool bSetMenuPos);
void endSubMenu(ScMenuFloatingWindow* pSubMenu);
void fillMenuItemsToAccessible(ScAccessibleFilterMenu* pAccMenu) const;
ScDocument* getDoc() { return mpDoc;}
protected:
css::uno::Reference<css::accessibility::XAccessible> mxAccessible;
private:
struct SubMenuItemData;
void handleMenuTimeout(SubMenuItemData* pTimer);
void resizeToFitMenuItems();
void highlightMenuItem(vcl::RenderContext& rRenderContext, size_t nPos, bool bSelected);
size_t getEnclosingMenuItem(const Point& rPos) const;
size_t getSubMenuPos(ScMenuFloatingWindow* pSubMenu);
/**
* Fire a menu highlight event since the accessibility framework needs
* this to track focus on menu items.
*/
void fireMenuHighlightedEvent();
/**
* Make sure that the specified submenu is permanently up, the submenu
* close timer is not active, and the correct menu item associated with
* the submenu is highlighted.
*/
void setSubMenuFocused(ScMenuFloatingWindow* pSubMenu);
/**
* When a menu item of an invisible submenu is selected, we need to make
* sure that all its parent menu(s) are visible, with the right menu item
* highlighted in each of the parents. Calling this method ensures it.
*/
void ensureSubMenuVisible(ScMenuFloatingWindow* pSubMenu);
/**
* Dismiss any visible child submenus when a menu item of a parent menu is
* selected.
*/
void ensureSubMenuNotVisible();
/**
* Dismiss all visible popup menus and set focus back to the application
* window. This method is called e.g. when a menu action is fired.
*/
void terminateAllPopupMenus();
private:
struct MenuItemData
{
OUString maText;
bool mbEnabled:1;
bool mbSeparator:1;
std::shared_ptr<Action> mpAction;
VclPtr<ScMenuFloatingWindow> mpSubMenuWin;
MenuItemData();
};
std::vector<MenuItemData> maMenuItems;
struct SubMenuItemData
{
Timer maTimer;
VclPtr<ScMenuFloatingWindow> mpSubMenu;
size_t mnMenuPos;
DECL_LINK_TYPED( TimeoutHdl, Timer*, void );
SubMenuItemData(ScMenuFloatingWindow* pParent);
void reset();
private:
VclPtr<ScMenuFloatingWindow> mpParent;
};
SubMenuItemData maOpenTimer;
SubMenuItemData maCloseTimer;
vcl::Font maLabelFont;
// Name of this menu window, taken from the menu item of the parent window
// that launches it (if this is a sub menu). If this is a top-level menu
// window, then this name can be anything.
OUString maName;
size_t mnSelectedMenu;
size_t mnClickedMenu;
ScDocument* mpDoc;
VclPtr<ScMenuFloatingWindow> mpParentMenu;
};
class ScCheckListMenuWindow;
template <class T> struct VclPtr_hash;
template <> struct VclPtr_hash< VclPtr<vcl::Window> >
{
size_t operator()( const VclPtr<vcl::Window>& r ) const
{
return reinterpret_cast<size_t>(r.get());
}
};
class ScTabStops
{
private:
typedef std::unordered_map< VclPtr<vcl::Window>, size_t, VclPtr_hash<VclPtr<vcl::Window>> > ControlToPosMap;
VclPtr<ScCheckListMenuWindow> mpMenuWindow;
ControlToPosMap maControlToPos;
std::vector<VclPtr<vcl::Window>> maControls;
size_t mnCurTabStop;
public:
ScTabStops( ScCheckListMenuWindow* mpMenuWin );
~ScTabStops();
void AddTabStop( vcl::Window* pWin );
void SetTabStop( vcl::Window* pWin );
void CycleFocus( bool bReverse = false );
void clear();
};
struct ScCheckListMember;
class ScCheckListBox : public SvTreeListBox
{
SvLBoxButtonData* mpCheckButton;
ScTabStops* mpTabStops;
bool mbSeenMouseButtonDown;
void CountCheckedEntries( SvTreeListEntry* pParent, sal_uLong& nCount ) const;
void CheckAllChildren( SvTreeListEntry* pEntry, bool bCheck = true );
public:
ScCheckListBox( vcl::Window* pParent, WinBits nWinStyle = 0 );
virtual ~ScCheckListBox() { disposeOnce(); }
virtual void dispose() override { delete mpCheckButton; SvTreeListBox::dispose(); }
void Init();
void CheckEntry( const OUString& sName, SvTreeListEntry* pParent, bool bCheck = true );
void CheckEntry( SvTreeListEntry* pEntry, bool bCheck = true );
SvTreeListEntry* ShowCheckEntry( const OUString& sName, ScCheckListMember& rMember, bool bShow = true, bool bCheck = true );
bool IsChecked( const OUString& sName, SvTreeListEntry* pParent );
SvTreeListEntry* FindEntry( SvTreeListEntry* pParent, const OUString& sNode );
sal_uInt16 GetCheckedEntryCount() const;
void ExpandChildren( SvTreeListEntry* pParent );
virtual void KeyInput( const KeyEvent& rKEvt ) override;
virtual void MouseButtonDown(const MouseEvent& rMEvt) override;
virtual void MouseButtonUp(const MouseEvent& rMEvt) override;
void SetTabStopsContainer( ScTabStops* pTabStops ) { mpTabStops = pTabStops; }
};
class ScSearchEdit : public Edit
{
private:
ScTabStops* mpTabStops;
public:
ScSearchEdit(Window* pParent)
: Edit(pParent)
, mpTabStops(nullptr)
{
}
virtual ~ScSearchEdit() {}
virtual void MouseButtonDown( const MouseEvent& rMEvt ) override;
void SetTabStopsContainer( ScTabStops* pTabStops ) { mpTabStops = pTabStops; }
};
struct ScCheckListMember
{
enum DatePartType
{
YEAR,
MONTH,
DAY,
};
OUString maName; // node name
OUString maRealName;
bool mbVisible;
bool mbDate;
bool mbLeaf;
DatePartType meDatePartType;
// To store Year and Month if the member if DAY type
std::vector<OUString> maDateParts;
ScCheckListMember();
SvTreeListEntry* mpParent;
};
/**
* This class implements a popup window for field button, for quick access
* of hide-item list, and possibly more stuff related to field options.
*/
class ScCheckListMenuWindow : public ScMenuFloatingWindow
{
public:
typedef std::unordered_map<OUString, bool, OUStringHash> ResultType;
/**
* Extended data that the client code may need to store. Create a
* sub-class of this and store data there.
*/
struct ExtendedData {
virtual ~ExtendedData() {}
};
/**
* Configuration options for this popup window.
*/
struct Config
{
bool mbAllowEmptySet;
bool mbRTL;
Config();
};
explicit ScCheckListMenuWindow(vcl::Window* pParent, ScDocument* pDoc);
virtual ~ScCheckListMenuWindow();
virtual void dispose() override;
virtual void MouseMove(const MouseEvent& rMEvt) override;
virtual bool Notify(NotifyEvent& rNEvt) override;
virtual void Paint(vcl::RenderContext& rRenderContext, const Rectangle& rRect) override;
virtual css::uno::Reference< css::accessibility::XAccessible > CreateAccessible() override;
void setMemberSize(size_t n);
void addDateMember(const OUString& rName, double nVal, bool bVisible);
void addMember(const OUString& rName, bool bVisible);
void initMembers();
void setConfig(const Config& rConfig);
bool isAllSelected() const;
void getResult(ResultType& rResult);
void launch(const Rectangle& rRect);
void close(bool bOK);
/**
* Set auxiliary data that the client code might need. Note that this
* popup window class manages its life time; no explicit deletion of the
* instance is needed in the client code.
*/
void setExtendedData(ExtendedData* p);
/**
* Get the store auxiliary data, or NULL if no such data is stored.
*/
ExtendedData* getExtendedData();
void setOKAction(Action* p);
void setPopupEndAction(Action* p);
protected:
virtual void handlePopupEnd() override;
private:
class CancelButton : public ::CancelButton
{
public:
CancelButton(ScCheckListMenuWindow* pParent);
virtual ~CancelButton();
virtual void dispose() override;
virtual void Click() override;
private:
VclPtr<ScCheckListMenuWindow> mpParent;
};
enum SectionType {
WHOLE, // entire window
LISTBOX_AREA_OUTER, // box enclosing the check box items.
LISTBOX_AREA_INNER, // box enclosing the check box items.
SINGLE_BTN_AREA, // box enclosing the single-action buttons.
CHECK_TOGGLE_ALL, // check box for toggling all items.
BTN_SINGLE_SELECT,
BTN_SINGLE_UNSELECT,
BTN_OK, // OK button
BTN_CANCEL, // Cancel button
EDIT_SEARCH, // Search box
};
void getSectionPosSize(Point& rPos, Size& rSize, SectionType eType) const;
/**
* Calculate the appropriate window size, the position and size of each
* control based on the menu items.
*/
void packWindow();
void setAllMemberState(bool bSet);
void selectCurrentMemberOnly(bool bSet);
void updateMemberParents( SvTreeListEntry* pLeaf, size_t nIdx );
DECL_LINK_TYPED( ButtonHdl, Button*, void );
DECL_LINK_TYPED( TriStateHdl, Button*, void );
DECL_LINK_TYPED( CheckHdl, SvTreeListBox*, void );
DECL_LINK_TYPED( EdModifyHdl, Edit&, void );
private:
VclPtr<ScSearchEdit> maEdSearch;
VclPtr<ScCheckListBox> maChecks;
VclPtr<TriStateBox> maChkToggleAll;
VclPtr<ImageButton> maBtnSelectSingle;
VclPtr<ImageButton> maBtnUnselectSingle;
VclPtr<OKButton> maBtnOk;
VclPtr<CancelButton> maBtnCancel;
std::vector<ScCheckListMember> maMembers;
// For Dates
std::map<OUString, size_t> maYearMonthMap;
std::unique_ptr<ExtendedData> mpExtendedData;
std::unique_ptr<Action> mpOKAction;
std::unique_ptr<Action> mpPopupEndAction;
Config maConfig;
Size maWndSize; /// whole window size.
Size maMenuSize; /// size of all menu items combined.
TriState mePrevToggleAllState;
ScTabStops maTabStops;
};
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|