afc828b983
... and renove the wrong framesize hack in the Qt backend
This wastes a few additional pixels in the frame backing store,
actually covered by the real native menu bar, to get rid of all
the hacks and eventually fix quite a bunch of bugs in Qt (and
maybe other backends).
This seems to work correct with Qt using either QPainter or Cairo
as the painting backend. It's much simpler then my previous failed
attempts to fix the Qt related bugs. I would like to convert every
implementation to my interpretation of the API (at least I now
documented the API). It looks like Win and Mac will just work,
because Win has no native menu bar and Mac uses a global menu,
so always returns the size of 0. And Gtk also seems to work, if
it also lies about the menu bar size being zero. That just seems
consequent, if the frame size is reduced by the menubar size.
This fixes at least:
tdf#64438 - Dockable panels in LibreOffice not dockable using KDE
Works.
tdf#130893 - XWindow::SetPosSize resizing based on
XWindow::GetPosSize shrinks the window
The document macro from tdf#130841 now doesn't resize the window.
This is just fixed for Qt.
tdf#134704 - KDE5 - unable to dock sidebar by dragging frame
not fixed, because the sidebar window is now a dialog, which is
not dockable. FWIW the same has happend the Navigator (F5), which
also renders it non-dockable. No idea, if this is intentional.
tdf#137471 - CMIS dialog advances beyond lower right corner of the
screen
So commit 3f8d3fd464
("tdf#137471 Qt
return frame pos + client area size") was really not enought as a
fix (at least it didn't break anything). The whole parent-based
repositioning is wrong and it really depends on the correct frame
size, so I'm keeping this as fixed by this patch.
Change-Id: I7faeace61b456c2b0f42c7a826f58018b70d46ae
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135082
Tested-by: Jenkins
Reviewed-by: Jan-Marek Glogowski <glogow@fbihome.de>
132 lines
5.1 KiB
C++
132 lines
5.1 KiB
C++
/* -*- 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/.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <salmenu.hxx>
|
|
|
|
#include <QtCore/QObject>
|
|
|
|
#include <memory>
|
|
|
|
class MenuItemList;
|
|
class QAbstractButton;
|
|
class QAction;
|
|
class QActionGroup;
|
|
class QButtonGroup;
|
|
class QMenu;
|
|
class QMenuBar;
|
|
class QPushButton;
|
|
class QtMenuItem;
|
|
class QtFrame;
|
|
|
|
/*
|
|
* QtMenu can represent
|
|
* (1) the top-level menu of a menubar, in which case 'mbMenuBar' is true and
|
|
* 'mpQMenuBar' refers to the corresponding QMenuBar
|
|
* (2) another kind of menu (like a PopupMenu), in which case the corresponding QMenu
|
|
* object is instantiated and owned by this QtMenu (held in 'mpOwnedQMenu').
|
|
* (3) a "submenu" in an existing menu (like (1)), in which case the corresponding
|
|
* QMenu object is owned by the corresponding QtMenuItem.
|
|
*
|
|
* For (2) and (3), member 'mpQMenu' points to the corresponding QMenu object.
|
|
*/
|
|
class QtMenu : public QObject, public SalMenu
|
|
{
|
|
Q_OBJECT
|
|
private:
|
|
std::vector<QtMenuItem*> maItems;
|
|
VclPtr<Menu> mpVCLMenu;
|
|
QtMenu* mpParentSalMenu;
|
|
QtFrame* mpFrame;
|
|
bool mbMenuBar;
|
|
QMenuBar* mpQMenuBar;
|
|
// self-created QMenu that this QtMenu represents, if applicable (s. comment for class)
|
|
std::unique_ptr<QMenu> mpOwnedQMenu;
|
|
// pointer to QMenu owned by the corresponding QtMenuItem or self (-> mpOwnedQMenu)
|
|
QMenu* mpQMenu;
|
|
QButtonGroup* m_pButtonGroup;
|
|
|
|
void DoFullMenuUpdate(Menu* pMenuBar);
|
|
static void NativeItemText(OUString& rItemText);
|
|
|
|
void InsertMenuItem(QtMenuItem* pSalMenuItem, unsigned nPos);
|
|
|
|
void ReinitializeActionGroup(unsigned nPos);
|
|
void ResetAllActionGroups();
|
|
void UpdateActionGroupItem(const QtMenuItem* pSalMenuItem);
|
|
bool validateQMenuBar() const;
|
|
QPushButton* ImplAddMenuBarButton(const QIcon& rIcon, const QString& rToolTip, int nId);
|
|
void ImplRemoveMenuBarButton(int nId);
|
|
void adjustButtonSizes();
|
|
|
|
public:
|
|
QtMenu(bool bMenuBar);
|
|
|
|
virtual bool HasNativeMenuBar() override;
|
|
virtual int GetMenuBarHeight() const override;
|
|
virtual void ShowMenuBar(bool bVisible) override;
|
|
|
|
virtual void InsertItem(SalMenuItem* pSalMenuItem, unsigned nPos) override;
|
|
virtual void RemoveItem(unsigned nPos) override;
|
|
virtual void SetSubMenu(SalMenuItem* pSalMenuItem, SalMenu* pSubMenu, unsigned nPos) override;
|
|
virtual void SetFrame(const SalFrame* pFrame) override;
|
|
const QtFrame* GetFrame() const;
|
|
virtual bool ShowNativePopupMenu(FloatingWindow* pWin, const tools::Rectangle& rRect,
|
|
FloatWinPopupFlags nFlags) override;
|
|
QtMenu* GetTopLevel();
|
|
virtual void SetItemBits(unsigned nPos, MenuItemBits nBits) override;
|
|
virtual void CheckItem(unsigned nPos, bool bCheck) override;
|
|
virtual void EnableItem(unsigned nPos, bool bEnable) override;
|
|
virtual void ShowItem(unsigned nPos, bool bShow) override;
|
|
virtual void SetItemText(unsigned nPos, SalMenuItem* pSalMenuItem,
|
|
const OUString& rText) override;
|
|
virtual void SetItemImage(unsigned nPos, SalMenuItem* pSalMenuItem,
|
|
const Image& rImage) override;
|
|
virtual void SetAccelerator(unsigned nPos, SalMenuItem* pSalMenuItem,
|
|
const vcl::KeyCode& rKeyCode, const OUString& rKeyName) override;
|
|
virtual void GetSystemMenuData(SystemMenuData* pData) override;
|
|
virtual void ShowCloseButton(bool bShow) override;
|
|
virtual bool AddMenuBarButton(const SalMenuButtonItem&) override;
|
|
virtual void RemoveMenuBarButton(sal_uInt16 nId) override;
|
|
virtual tools::Rectangle GetMenuBarButtonRectPixel(sal_uInt16 nId, SalFrame*) override;
|
|
|
|
void SetMenu(Menu* pMenu) { mpVCLMenu = pMenu; }
|
|
Menu* GetMenu() { return mpVCLMenu; }
|
|
unsigned GetItemCount() const { return maItems.size(); }
|
|
QtMenuItem* GetItemAtPos(unsigned nPos) { return maItems[nPos]; }
|
|
|
|
private slots:
|
|
static void slotMenuTriggered(QtMenuItem* pQItem);
|
|
static void slotMenuAboutToShow(QtMenuItem* pQItem);
|
|
static void slotMenuAboutToHide(QtMenuItem* pQItem);
|
|
void slotCloseDocument();
|
|
void slotMenuBarButtonClicked(QAbstractButton*);
|
|
};
|
|
|
|
class QtMenuItem : public SalMenuItem
|
|
{
|
|
public:
|
|
QtMenuItem(const SalItemParams*);
|
|
|
|
QAction* getAction() const;
|
|
|
|
QtMenu* mpParentMenu; // The menu into which this menu item is inserted
|
|
QtMenu* mpSubMenu; // Submenu of this item (if defined)
|
|
std::unique_ptr<QAction> mpAction; // action corresponding to this item
|
|
std::unique_ptr<QMenu> mpMenu; // menu corresponding to this item
|
|
std::shared_ptr<QActionGroup> mpActionGroup; // empty if it's a separator element
|
|
sal_uInt16 mnId; // Item ID
|
|
MenuItemType mnType; // Item type
|
|
bool mbVisible; // Item visibility.
|
|
bool mbEnabled; // Item active.
|
|
Image maImage; // Item image
|
|
};
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|