1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <Qt5Frame.hxx>
21 #include <Qt5Frame.moc>
23 #include <Qt5Data.hxx>
24 #include <Qt5DragAndDrop.hxx>
25 #include <Qt5Graphics.hxx>
26 #include <Qt5Instance.hxx>
27 #include <Qt5MainWindow.hxx>
28 #include <Qt5Menu.hxx>
29 #include <Qt5SvpGraphics.hxx>
30 #include <Qt5System.hxx>
31 #include <Qt5Tools.hxx>
32 #include <Qt5Transferable.hxx>
33 #include <Qt5Widget.hxx>
35 #include <QtCore/QMimeData>
36 #include <QtCore/QPoint>
37 #include <QtCore/QSize>
38 #include <QtCore/QThread>
39 #include <QtCore/QVersionNumber>
40 #include <QtGui/QDragMoveEvent>
41 #include <QtGui/QDropEvent>
42 #include <QtGui/QIcon>
43 #include <QtGui/QWindow>
44 #include <QtGui/QScreen>
45 #include <QtWidgets/QStyle>
46 #include <QtWidgets/QToolTip>
47 #include <QtWidgets/QApplication>
48 #include <QtWidgets/QDesktopWidget>
49 #include <QtWidgets/QMenuBar>
50 #include <QtWidgets/QMainWindow>
53 #include <QtX11Extras/QX11Info>
54 #include <xcb/xproto.h>
55 #if QT5_HAVE_XCB_ICCCM
56 #include <xcb/xcb_icccm.h>
60 #include <saldatabasic.hxx>
62 #include <vcl/layout.hxx>
63 #include <vcl/syswin.hxx>
65 #include <com/sun/star/datatransfer/dnd/DNDConstants.hpp>
68 #include <headless/svpgdi.hxx>
70 #if QT5_USING_X11 && QT5_HAVE_XCB_ICCCM
71 static bool g_bNeedsWmHintsWindowGroup
= true;
72 static xcb_atom_t g_aXcbClientLeaderAtom
= 0;
75 static void SvpDamageHandler(void* handle
, sal_Int32 nExtentsX
, sal_Int32 nExtentsY
,
76 sal_Int32 nExtentsWidth
, sal_Int32 nExtentsHeight
)
78 Qt5Frame
* pThis
= static_cast<Qt5Frame
*>(handle
);
79 pThis
->Damage(nExtentsX
, nExtentsY
, nExtentsWidth
, nExtentsHeight
);
84 sal_Int32
screenNumber(const QScreen
* pScreen
)
86 const QList
<QScreen
*> screens
= QApplication::screens();
88 sal_Int32 nScreen
= 0;
90 for (const QScreen
* pCurScreen
: screens
)
92 if (pScreen
== pCurScreen
)
100 return bFound
? nScreen
: -1;
104 Qt5Frame::Qt5Frame(Qt5Frame
* pParent
, SalFrameStyleFlags nStyle
, bool bUseCairo
)
105 : m_pTopLevel(nullptr)
106 , m_bUseCairo(bUseCairo
)
107 , m_pSvpGraphics(nullptr)
108 , m_bNullRegion(true)
109 , m_bGraphicsInUse(false)
110 , m_bGraphicsInvalid(false)
111 , m_ePointerStyle(PointerStyle::Arrow
)
112 , m_pDragSource(nullptr)
113 , m_pDropTarget(nullptr)
115 , m_bDefaultSize(true)
116 , m_bDefaultPos(true)
117 , m_bFullScreen(false)
118 , m_bFullScreenSpanAll(false)
120 Qt5Instance
* pInst
= static_cast<Qt5Instance
*>(GetSalData()->m_pInstance
);
121 pInst
->insertFrame(this);
123 m_aDamageHandler
.handle
= this;
124 m_aDamageHandler
.damaged
= ::SvpDamageHandler
;
126 if (nStyle
& SalFrameStyleFlags::DEFAULT
) // ensure default style
128 nStyle
|= SalFrameStyleFlags::MOVEABLE
| SalFrameStyleFlags::SIZEABLE
129 | SalFrameStyleFlags::CLOSEABLE
;
130 nStyle
&= ~SalFrameStyleFlags::FLOAT
;
136 Qt::WindowFlags aWinFlags
;
137 if (!(nStyle
& SalFrameStyleFlags::SYSTEMCHILD
))
139 if (nStyle
& SalFrameStyleFlags::INTRO
)
140 aWinFlags
|= Qt::SplashScreen
;
141 // floating toolbars are frameless tool windows
142 // + they must be able to receive keyboard focus
143 else if ((nStyle
& SalFrameStyleFlags::FLOAT
)
144 && (nStyle
& SalFrameStyleFlags::OWNERDRAWDECORATION
))
145 aWinFlags
|= Qt::Tool
| Qt::FramelessWindowHint
;
146 else if (nStyle
& (SalFrameStyleFlags::FLOAT
| SalFrameStyleFlags::TOOLTIP
))
147 aWinFlags
|= Qt::ToolTip
;
148 else if ((nStyle
& SalFrameStyleFlags::FLOAT
)
149 && !(nStyle
& SalFrameStyleFlags::OWNERDRAWDECORATION
))
150 aWinFlags
|= Qt::Popup
;
151 else if (nStyle
& SalFrameStyleFlags::TOOLWINDOW
)
152 aWinFlags
|= Qt::Tool
;
153 // top level windows can't be transient in Qt, so make them dialogs, if they have a parent. At least
154 // the plasma shell relies on this setting to skip dialogs in the window list. And Qt Xcb will just
155 // set transient for the types Dialog, Sheet, Tool, SplashScreen, ToolTip, Drawer and Popup.
156 else if (nStyle
& SalFrameStyleFlags::DIALOG
|| m_pParent
)
157 aWinFlags
|= Qt::Dialog
;
159 aWinFlags
|= Qt::Window
;
162 if (aWinFlags
== Qt::Window
)
164 m_pTopLevel
= new Qt5MainWindow(*this, aWinFlags
);
165 m_pQWidget
= new Qt5Widget(*this, aWinFlags
);
166 m_pTopLevel
->setCentralWidget(m_pQWidget
);
167 m_pTopLevel
->setFocusProxy(m_pQWidget
);
170 m_pQWidget
= new Qt5Widget(*this, aWinFlags
);
172 if (pParent
&& !(pParent
->m_nStyle
& SalFrameStyleFlags::PLUG
))
174 QWindow
* pParentWindow
= pParent
->GetQWidget()->window()->windowHandle();
175 QWindow
* pChildWindow
= asChild()->window()->windowHandle();
176 if (pParentWindow
&& pChildWindow
&& (pParentWindow
!= pChildWindow
))
177 pChildWindow
->setTransientParent(pParentWindow
);
180 // Calling 'QWidget::winId()' implicitly enables native windows to be used
181 // rather than "alien widgets" that are unknown to the windowing system,
182 // s. https://doc.qt.io/qt-5/qwidget.html#native-widgets-vs-alien-widgets
183 // Avoid this on Wayland due to problems with missing 'mouseMoveEvent's,
184 // s. tdf#122293/QTBUG-75766
185 const bool bWayland
= QGuiApplication::platformName() == "wayland";
187 m_aSystemData
.aWindow
= m_pQWidget
->winId();
190 // TODO implement as needed for Wayland,
191 // s.a. commit c0d4f3ad3307c which did this for gtk3
192 // QPlatformNativeInterface* native = QGuiApplication::platformNativeInterface();
193 // m_aSystemData.pDisplay = native->nativeResourceForWindow("display", nullptr);
194 // m_aSystemData.aWindow = reinterpret_cast<unsigned long>(
195 // native->nativeResourceForWindow("surface", m_pQWidget->windowHandle()));
198 m_aSystemData
.aShellWindow
= reinterpret_cast<sal_IntPtr
>(this);
199 //m_aSystemData.pSalFrame = this;
200 m_aSystemData
.pWidget
= m_pQWidget
;
201 //m_aSystemData.nScreen = m_nXScreen.getXScreen();
202 m_aSystemData
.toolkit
= SystemEnvData::Toolkit::Qt5
;
204 m_aSystemData
.platform
= SystemEnvData::Platform::Xcb
;
206 m_aSystemData
.platform
= SystemEnvData::Platform::Wayland
;
208 SetIcon(SV_ICON_ID_OFFICE
);
210 fixICCCMwindowGroup();
213 void Qt5Frame::fixICCCMwindowGroup()
215 #if QT5_USING_X11 && QT5_HAVE_XCB_ICCCM
216 // older Qt5 just sets WM_CLIENT_LEADER, but not the XCB_ICCCM_WM_HINT_WINDOW_GROUP
217 // see Qt commit 0de4b326d8 ("xcb: fix issue with dialogs hidden by other windows")
218 // or QTBUG-46626. So LO has to set this itself to help some WMs.
219 if (!g_bNeedsWmHintsWindowGroup
)
221 g_bNeedsWmHintsWindowGroup
= false;
223 if (QGuiApplication::platformName() != "xcb")
225 if (QVersionNumber::fromString(qVersion()) >= QVersionNumber(5, 12))
228 xcb_connection_t
* conn
= QX11Info::connection();
229 xcb_window_t win
= asChild()->winId();
231 xcb_icccm_wm_hints_t hints
;
233 xcb_get_property_cookie_t prop_cookie
= xcb_icccm_get_wm_hints_unchecked(conn
, win
);
234 if (!xcb_icccm_get_wm_hints_reply(conn
, prop_cookie
, &hints
, nullptr))
237 if (hints
.flags
& XCB_ICCCM_WM_HINT_WINDOW_GROUP
)
240 if (g_aXcbClientLeaderAtom
== 0)
242 const char* const leader_name
= "WM_CLIENT_LEADER\0";
243 xcb_intern_atom_cookie_t atom_cookie
244 = xcb_intern_atom(conn
, 1, strlen(leader_name
), leader_name
);
245 xcb_intern_atom_reply_t
* atom_reply
= xcb_intern_atom_reply(conn
, atom_cookie
, nullptr);
248 g_aXcbClientLeaderAtom
= atom_reply
->atom
;
252 g_bNeedsWmHintsWindowGroup
= true;
254 prop_cookie
= xcb_get_property(conn
, 0, win
, g_aXcbClientLeaderAtom
, XCB_ATOM_WINDOW
, 0, 1);
255 xcb_get_property_reply_t
* prop_reply
= xcb_get_property_reply(conn
, prop_cookie
, nullptr);
259 if (xcb_get_property_value_length(prop_reply
) != 4)
265 xcb_window_t leader
= *static_cast<xcb_window_t
*>(xcb_get_property_value(prop_reply
));
268 hints
.flags
|= XCB_ICCCM_WM_HINT_WINDOW_GROUP
;
269 hints
.window_group
= leader
;
270 xcb_icccm_set_wm_hints(conn
, win
, &hints
);
274 Qt5Frame::~Qt5Frame()
276 Qt5Instance
* pInst
= static_cast<Qt5Instance
*>(GetSalData()->m_pInstance
);
277 pInst
->eraseFrame(this);
279 m_aSystemData
.aShellWindow
= 0;
282 void Qt5Frame::Damage(sal_Int32 nExtentsX
, sal_Int32 nExtentsY
, sal_Int32 nExtentsWidth
,
283 sal_Int32 nExtentsHeight
) const
285 m_pQWidget
->update(nExtentsX
, nExtentsY
, nExtentsWidth
, nExtentsHeight
);
288 void Qt5Frame::TriggerPaintEvent()
290 QSize
aSize(m_pQWidget
->size());
291 SalPaintEvent
aPaintEvt(0, 0, aSize
.width(), aSize
.height(), true);
292 CallCallback(SalEvent::Paint
, &aPaintEvt
);
295 void Qt5Frame::TriggerPaintEvent(QRect aRect
)
297 SalPaintEvent
aPaintEvt(aRect
.x(), aRect
.y(), aRect
.width(), aRect
.height(), true);
298 CallCallback(SalEvent::Paint
, &aPaintEvt
);
301 void Qt5Frame::InitQt5SvpGraphics(Qt5SvpGraphics
* pQt5SvpGraphics
)
305 m_pSvpGraphics
= pQt5SvpGraphics
;
306 m_pSurface
.reset(cairo_image_surface_create(CAIRO_FORMAT_ARGB32
, width
, height
));
307 m_pSvpGraphics
->setSurface(m_pSurface
.get(), basegfx::B2IVector(width
, height
));
308 cairo_surface_set_user_data(m_pSurface
.get(), Qt5SvpGraphics::getDamageKey(), &m_aDamageHandler
,
312 SalGraphics
* Qt5Frame::AcquireGraphics()
314 if (m_bGraphicsInUse
)
317 m_bGraphicsInUse
= true;
321 if (!m_pOurSvpGraphics
.get() || m_bGraphicsInvalid
)
323 m_pOurSvpGraphics
.reset(new Qt5SvpGraphics(this));
324 InitQt5SvpGraphics(m_pOurSvpGraphics
.get());
325 m_bGraphicsInvalid
= false;
327 return m_pOurSvpGraphics
.get();
331 if (!m_pQt5Graphics
.get() || m_bGraphicsInvalid
)
333 m_pQt5Graphics
.reset(new Qt5Graphics(this));
334 m_pQImage
.reset(new QImage(m_pQWidget
->size(), Qt5_DefaultFormat32
));
335 m_pQImage
->fill(Qt::transparent
);
336 m_pQt5Graphics
->ChangeQImage(m_pQImage
.get());
337 m_bGraphicsInvalid
= false;
339 return m_pQt5Graphics
.get();
343 void Qt5Frame::ReleaseGraphics(SalGraphics
* pSalGraph
)
347 assert(pSalGraph
== m_pOurSvpGraphics
.get());
349 assert(pSalGraph
== m_pQt5Graphics
.get());
350 m_bGraphicsInUse
= false;
353 bool Qt5Frame::PostEvent(std::unique_ptr
<ImplSVEvent
> pData
)
355 Qt5Instance
* pInst
= static_cast<Qt5Instance
*>(GetSalData()->m_pInstance
);
356 pInst
->PostEvent(this, pData
.release(), SalEvent::UserEvent
);
360 QWidget
* Qt5Frame::asChild() const { return m_pTopLevel
? m_pTopLevel
: m_pQWidget
; }
362 bool Qt5Frame::isWindow() const { return asChild()->isWindow(); }
364 QWindow
* Qt5Frame::windowHandle() const
366 // set attribute 'Qt::WA_NativeWindow' first to make sure a window handle actually exists
367 QWidget
* pChild
= asChild();
368 pChild
->setAttribute(Qt::WA_NativeWindow
);
369 return pChild
->windowHandle();
372 QScreen
* Qt5Frame::screen() const
374 QWindow
* const pWindow
= windowHandle();
375 return pWindow
? pWindow
->screen() : nullptr;
378 bool Qt5Frame::isMinimized() const { return asChild()->isMinimized(); }
380 bool Qt5Frame::isMaximized() const { return asChild()->isMaximized(); }
382 void Qt5Frame::SetWindowStateImpl(Qt::WindowStates eState
)
384 return asChild()->setWindowState(eState
);
387 void Qt5Frame::SetTitle(const OUString
& rTitle
)
389 m_pQWidget
->window()->setWindowTitle(toQString(rTitle
));
392 void Qt5Frame::SetIcon(sal_uInt16 nIcon
)
395 & (SalFrameStyleFlags::PLUG
| SalFrameStyleFlags::SYSTEMCHILD
396 | SalFrameStyleFlags::FLOAT
| SalFrameStyleFlags::INTRO
397 | SalFrameStyleFlags::OWNERDRAWDECORATION
)
403 if (nIcon
== SV_ICON_ID_TEXT
)
404 appicon
= "libreoffice-writer";
405 else if (nIcon
== SV_ICON_ID_SPREADSHEET
)
406 appicon
= "libreoffice-calc";
407 else if (nIcon
== SV_ICON_ID_DRAWING
)
408 appicon
= "libreoffice-draw";
409 else if (nIcon
== SV_ICON_ID_PRESENTATION
)
410 appicon
= "libreoffice-impress";
411 else if (nIcon
== SV_ICON_ID_DATABASE
)
412 appicon
= "libreoffice-base";
413 else if (nIcon
== SV_ICON_ID_FORMULA
)
414 appicon
= "libreoffice-math";
416 appicon
= "libreoffice-startcenter";
418 QIcon aIcon
= QIcon::fromTheme(appicon
);
419 m_pQWidget
->window()->setWindowIcon(aIcon
);
422 void Qt5Frame::SetMenu(SalMenu
* pMenu
) { m_pSalMenu
= static_cast<Qt5Menu
*>(pMenu
); }
424 void Qt5Frame::DrawMenuBar() { /* not needed */}
426 void Qt5Frame::SetExtendedFrameStyle(SalExtStyle
/*nExtStyle*/) { /* not needed */}
428 void Qt5Frame::Show(bool bVisible
, bool /*bNoActivate*/)
435 auto* pSalInst(static_cast<Qt5Instance
*>(GetSalData()->m_pInstance
));
437 pSalInst
->RunInMainThread([this, bVisible
]() { asChild()->setVisible(bVisible
); });
440 void Qt5Frame::SetMinClientSize(long nWidth
, long nHeight
)
443 asChild()->setMinimumSize(nWidth
, nHeight
);
446 void Qt5Frame::SetMaxClientSize(long nWidth
, long nHeight
)
449 asChild()->setMaximumSize(nWidth
, nHeight
);
452 void Qt5Frame::SetDefaultPos()
460 QWidget
* const pWindow
= m_pParent
->GetQWidget()->window();
461 QWidget
* const pWidget
= asChild();
462 QPoint aPos
= pWindow
->rect().center() - pWidget
->rect().center();
463 SetPosSize(aPos
.x(), aPos
.y(), 0, 0, SAL_FRAME_POSSIZE_X
| SAL_FRAME_POSSIZE_Y
);
464 assert(!m_bDefaultPos
);
467 m_bDefaultPos
= false;
470 Size
Qt5Frame::CalcDefaultSize()
477 const QScreen
* pScreen
= screen();
478 aSize
= bestmaxFrameSizeForScreenSize(
479 toSize(pScreen
? pScreen
->size() : QApplication::desktop()->screenGeometry(0).size()));
483 if (!m_bFullScreenSpanAll
)
485 QApplication::desktop()->screenGeometry(maGeometry
.nDisplayScreenNumber
).size());
488 int nLeftScreen
= QApplication::desktop()->screenNumber(QPoint(0, 0));
489 aSize
= toSize(QApplication::screens()[nLeftScreen
]->availableVirtualGeometry().size());
496 void Qt5Frame::SetDefaultSize()
501 Size aDefSize
= CalcDefaultSize();
502 SetPosSize(0, 0, aDefSize
.Width(), aDefSize
.Height(),
503 SAL_FRAME_POSSIZE_WIDTH
| SAL_FRAME_POSSIZE_HEIGHT
);
504 assert(!m_bDefaultSize
);
507 void Qt5Frame::SetPosSize(long nX
, long nY
, long nWidth
, long nHeight
, sal_uInt16 nFlags
)
509 if (!isWindow() || isChild(true, false))
512 if (nFlags
& (SAL_FRAME_POSSIZE_WIDTH
| SAL_FRAME_POSSIZE_HEIGHT
))
514 if (isChild(false) || !m_pQWidget
->isMaximized())
516 if (!(nFlags
& SAL_FRAME_POSSIZE_WIDTH
))
517 nWidth
= maGeometry
.nWidth
;
518 else if (!(nFlags
& SAL_FRAME_POSSIZE_HEIGHT
))
519 nHeight
= maGeometry
.nHeight
;
521 if (nWidth
> 0 && nHeight
> 0)
523 m_bDefaultSize
= false;
524 if (m_nStyle
& SalFrameStyleFlags::SIZEABLE
)
525 asChild()->resize(nWidth
, nHeight
);
527 asChild()->setFixedSize(nWidth
, nHeight
);
530 // assume the resize happened
531 // needed for calculations and will eventually be corrected by events
533 maGeometry
.nWidth
= nWidth
;
535 maGeometry
.nHeight
= nHeight
;
539 if (nFlags
& (SAL_FRAME_POSSIZE_X
| SAL_FRAME_POSSIZE_Y
))
543 const SalFrameGeometry
& aParentGeometry
= m_pParent
->maGeometry
;
544 if (QGuiApplication::isRightToLeft())
545 nX
= aParentGeometry
.nX
+ aParentGeometry
.nWidth
- nX
- maGeometry
.nWidth
- 1;
547 nX
+= aParentGeometry
.nX
;
548 nY
+= aParentGeometry
.nY
;
550 Qt5MainWindow
* pTopLevel
= m_pParent
->GetTopLevelWindow();
551 if (pTopLevel
&& pTopLevel
->menuBar() && pTopLevel
->menuBar()->isVisible())
552 nY
+= pTopLevel
->menuBar()->geometry().height();
555 if (!(nFlags
& SAL_FRAME_POSSIZE_X
))
557 else if (!(nFlags
& SAL_FRAME_POSSIZE_Y
))
560 // assume the reposition happened
561 // needed for calculations and will eventually be corrected by events later
565 m_bDefaultPos
= false;
566 asChild()->move(nX
, nY
);
570 void Qt5Frame::GetClientSize(long& rWidth
, long& rHeight
)
572 rWidth
= m_pQWidget
->width();
573 rHeight
= m_pQWidget
->height();
576 void Qt5Frame::GetWorkArea(tools::Rectangle
& rRect
)
580 QScreen
* pScreen
= screen();
584 QSize aSize
= pScreen
->availableVirtualSize();
585 rRect
= tools::Rectangle(0, 0, aSize
.width(), aSize
.height());
588 SalFrame
* Qt5Frame::GetParent() const { return m_pParent
; }
590 void Qt5Frame::SetModal(bool bModal
)
594 auto* pSalInst(static_cast<Qt5Instance
*>(GetSalData()->m_pInstance
));
596 pSalInst
->RunInMainThread([this, bModal
]() {
598 QWidget
* const pChild
= asChild();
599 const bool bWasVisible
= pChild
->isVisible();
601 // modality change is only effective if the window is hidden
605 pChild
->setWindowModality(bModal
? Qt::WindowModal
: Qt::NonModal
);
613 bool Qt5Frame::GetModal() const { return isWindow() && windowHandle()->isModal(); }
615 void Qt5Frame::SetWindowState(const SalFrameState
* pState
)
617 if (!isWindow() || !pState
|| isChild(true, false))
620 const WindowStateMask nMaxGeometryMask
621 = WindowStateMask::X
| WindowStateMask::Y
| WindowStateMask::Width
| WindowStateMask::Height
622 | WindowStateMask::MaximizedX
| WindowStateMask::MaximizedY
623 | WindowStateMask::MaximizedWidth
| WindowStateMask::MaximizedHeight
;
625 if ((pState
->mnMask
& WindowStateMask::State
) && (pState
->mnState
& WindowStateState::Maximized
)
626 && !isMaximized() && (pState
->mnMask
& nMaxGeometryMask
) == nMaxGeometryMask
)
628 QWidget
* const pChild
= asChild();
629 pChild
->resize(pState
->mnWidth
, pState
->mnHeight
);
630 pChild
->move(pState
->mnX
, pState
->mnY
);
631 SetWindowStateImpl(Qt::WindowMaximized
);
633 else if (pState
->mnMask
634 & (WindowStateMask::X
| WindowStateMask::Y
| WindowStateMask::Width
635 | WindowStateMask::Height
))
637 sal_uInt16 nPosSizeFlags
= 0;
638 if (pState
->mnMask
& WindowStateMask::X
)
639 nPosSizeFlags
|= SAL_FRAME_POSSIZE_X
;
640 if (pState
->mnMask
& WindowStateMask::Y
)
641 nPosSizeFlags
|= SAL_FRAME_POSSIZE_Y
;
642 if (pState
->mnMask
& WindowStateMask::Width
)
643 nPosSizeFlags
|= SAL_FRAME_POSSIZE_WIDTH
;
644 if (pState
->mnMask
& WindowStateMask::Height
)
645 nPosSizeFlags
|= SAL_FRAME_POSSIZE_HEIGHT
;
646 SetPosSize(pState
->mnX
, pState
->mnY
, pState
->mnWidth
, pState
->mnHeight
, nPosSizeFlags
);
648 else if (pState
->mnMask
& WindowStateMask::State
&& !isChild())
650 if (pState
->mnState
& WindowStateState::Maximized
)
651 SetWindowStateImpl(Qt::WindowMaximized
);
652 else if (pState
->mnState
& WindowStateState::Minimized
)
653 SetWindowStateImpl(Qt::WindowMinimized
);
655 SetWindowStateImpl(Qt::WindowNoState
);
659 bool Qt5Frame::GetWindowState(SalFrameState
* pState
)
661 pState
->mnState
= WindowStateState::Normal
;
662 pState
->mnMask
= WindowStateMask::State
;
663 if (isMinimized() /*|| !windowHandle()*/)
664 pState
->mnState
|= WindowStateState::Minimized
;
665 else if (isMaximized())
667 pState
->mnState
|= WindowStateState::Maximized
;
671 // geometry() is the drawable area, which is wanted here
672 QRect rect
= asChild()->geometry();
673 pState
->mnX
= rect
.x();
674 pState
->mnY
= rect
.y();
675 pState
->mnWidth
= rect
.width();
676 pState
->mnHeight
= rect
.height();
677 // the menubar is drawn natively, adjust for that
678 if (maGeometry
.nTopDecoration
)
680 pState
->mnY
+= maGeometry
.nTopDecoration
;
681 pState
->mnHeight
-= maGeometry
.nTopDecoration
;
683 pState
->mnMask
|= WindowStateMask::X
| WindowStateMask::Y
| WindowStateMask::Width
684 | WindowStateMask::Height
;
690 void Qt5Frame::ShowFullScreen(bool bFullScreen
, sal_Int32 nScreen
)
692 // only top-level windows can go fullscreen
695 if (m_bFullScreen
== bFullScreen
)
698 m_bFullScreen
= bFullScreen
;
699 m_bFullScreenSpanAll
= m_bFullScreen
&& (nScreen
< 0);
701 // show it if it isn't shown yet
707 m_aRestoreGeometry
= m_pTopLevel
->geometry();
708 m_nRestoreScreen
= maGeometry
.nDisplayScreenNumber
;
709 SetScreenNumber(m_bFullScreenSpanAll
? m_nRestoreScreen
: nScreen
);
710 if (!m_bFullScreenSpanAll
)
711 windowHandle()->showFullScreen();
713 windowHandle()->showNormal();
717 SetScreenNumber(m_nRestoreScreen
);
718 windowHandle()->showNormal();
719 m_pTopLevel
->setGeometry(m_aRestoreGeometry
);
723 void Qt5Frame::StartPresentation(bool bStart
)
725 // meh - so there's no Qt platform independent solution
726 // https://forum.qt.io/topic/38504/solved-qdialog-in-fullscreen-disable-os-screensaver
728 boost::optional
<unsigned int> aRootWindow
;
729 boost::optional
<Display
*> aDisplay
;
731 if (QX11Info::isPlatformX11())
733 aRootWindow
= QX11Info::appRootWindow();
734 aDisplay
= QX11Info::display();
737 m_ScreenSaverInhibitor
.inhibit(bStart
, "presentation", QX11Info::isPlatformX11(), aRootWindow
,
744 void Qt5Frame::SetAlwaysOnTop(bool bOnTop
)
746 QWidget
* const pWidget
= asChild();
747 const Qt::WindowFlags flags
= pWidget
->windowFlags();
749 pWidget
->setWindowFlags(flags
| Qt::CustomizeWindowHint
| Qt::WindowStaysOnTopHint
);
751 pWidget
->setWindowFlags(flags
& ~(Qt::CustomizeWindowHint
| Qt::WindowStaysOnTopHint
));
754 void Qt5Frame::ToTop(SalFrameToTop nFlags
)
756 QWidget
* const pWidget
= asChild();
757 if (isWindow() && !(nFlags
& SalFrameToTop::GrabFocusOnly
))
759 if ((nFlags
& SalFrameToTop::RestoreWhenMin
) || (nFlags
& SalFrameToTop::ForegroundTask
))
760 pWidget
->activateWindow();
761 else if ((nFlags
& SalFrameToTop::GrabFocus
) || (nFlags
& SalFrameToTop::GrabFocusOnly
))
763 pWidget
->activateWindow();
768 void Qt5Frame::SetPointer(PointerStyle ePointerStyle
)
770 QWindow
* pWindow
= m_pQWidget
->window()->windowHandle();
773 if (ePointerStyle
== m_ePointerStyle
)
775 m_ePointerStyle
= ePointerStyle
;
777 pWindow
->setCursor(static_cast<Qt5Data
*>(GetSalData())->getCursor(ePointerStyle
));
780 void Qt5Frame::CaptureMouse(bool bMouse
)
782 static const char* pEnv
= getenv("SAL_NO_MOUSEGRABS");
787 m_pQWidget
->grabMouse();
789 m_pQWidget
->releaseMouse();
792 void Qt5Frame::SetPointerPos(long nX
, long nY
)
794 // some cursor already exists (and it has m_ePointerStyle shape)
795 // so here we just reposition it
796 QCursor::setPos(m_pQWidget
->mapToGlobal(QPoint(nX
, nY
)));
799 void Qt5Frame::Flush()
801 // was: QGuiApplication::sync();
802 // but FIXME it causes too many issues, figure out sth better
804 // unclear if we need to also flush cairo surface - gtk3 backend
805 // does not do it. QPainter in Qt5Widget::paintEvent() is
806 // destroyed, so that state should be safely flushed.
809 bool Qt5Frame::ShowTooltip(const OUString
& rText
, const tools::Rectangle
& rHelpArea
)
811 QRect
aHelpArea(toQRect(rHelpArea
));
812 if (QGuiApplication::isRightToLeft())
813 aHelpArea
.moveLeft(maGeometry
.nWidth
- aHelpArea
.width() - aHelpArea
.left() - 1);
814 QToolTip::showText(QCursor::pos(), toQString(rText
), m_pQWidget
, aHelpArea
);
818 void Qt5Frame::SetInputContext(SalInputContext
* pContext
)
823 if (!(pContext
->mnOptions
& InputContextFlags::Text
))
826 m_pQWidget
->setAttribute(Qt::WA_InputMethodEnabled
);
829 void Qt5Frame::EndExtTextInput(EndExtTextInputFlags
/*nFlags*/)
831 Qt5Widget
* pQt5Widget
= static_cast<Qt5Widget
*>(m_pQWidget
);
833 pQt5Widget
->endExtTextInput();
836 OUString
Qt5Frame::GetKeyName(sal_uInt16 nKeyCode
)
838 vcl::KeyCode
vclKeyCode(nKeyCode
);
839 int nCode
= vclKeyCode
.GetCode();
842 if (nCode
>= KEY_0
&& nCode
<= KEY_9
)
843 nRetCode
= (nCode
- KEY_0
) + Qt::Key_0
;
844 else if (nCode
>= KEY_A
&& nCode
<= KEY_Z
)
845 nRetCode
= (nCode
- KEY_A
) + Qt::Key_A
;
846 else if (nCode
>= KEY_F1
&& nCode
<= KEY_F26
)
847 nRetCode
= (nCode
- KEY_F1
) + Qt::Key_F1
;
853 nRetCode
= Qt::Key_Down
;
856 nRetCode
= Qt::Key_Up
;
859 nRetCode
= Qt::Key_Left
;
862 nRetCode
= Qt::Key_Right
;
865 nRetCode
= Qt::Key_Home
;
868 nRetCode
= Qt::Key_End
;
871 nRetCode
= Qt::Key_PageUp
;
874 nRetCode
= Qt::Key_PageDown
;
877 nRetCode
= Qt::Key_Return
;
880 nRetCode
= Qt::Key_Escape
;
883 nRetCode
= Qt::Key_Tab
;
886 nRetCode
= Qt::Key_Backspace
;
889 nRetCode
= Qt::Key_Space
;
892 nRetCode
= Qt::Key_Insert
;
895 nRetCode
= Qt::Key_Delete
;
898 nRetCode
= Qt::Key_Plus
;
901 nRetCode
= Qt::Key_Minus
;
904 nRetCode
= Qt::Key_Asterisk
;
907 nRetCode
= Qt::Key_Slash
;
910 nRetCode
= Qt::Key_Period
;
913 nRetCode
= Qt::Key_Comma
;
916 nRetCode
= Qt::Key_Less
;
919 nRetCode
= Qt::Key_Greater
;
922 nRetCode
= Qt::Key_Equal
;
925 nRetCode
= Qt::Key_Find
;
927 case KEY_CONTEXTMENU
:
928 nRetCode
= Qt::Key_Menu
;
931 nRetCode
= Qt::Key_Help
;
934 nRetCode
= Qt::Key_Undo
;
937 nRetCode
= Qt::Key_Redo
;
940 nRetCode
= Qt::Key_AsciiTilde
;
943 nRetCode
= Qt::Key_QuoteLeft
;
945 case KEY_BRACKETLEFT
:
946 nRetCode
= Qt::Key_BracketLeft
;
948 case KEY_BRACKETRIGHT
:
949 nRetCode
= Qt::Key_BracketRight
;
952 nRetCode
= Qt::Key_Semicolon
;
957 nRetCode
= Qt::Key_Copy
;
960 nRetCode
= Qt::Key_Cut
;
963 nRetCode
= Qt::Key_Paste
;
966 nRetCode
= Qt::Key_Open
;
971 if (vclKeyCode
.IsShift())
972 nRetCode
+= Qt::SHIFT
;
973 if (vclKeyCode
.IsMod1())
974 nRetCode
+= Qt::CTRL
;
975 if (vclKeyCode
.IsMod2())
978 QKeySequence
keySeq(nRetCode
);
979 OUString sKeyName
= toOUString(keySeq
.toString());
984 bool Qt5Frame::MapUnicodeToKeyCode(sal_Unicode
/*aUnicode*/, LanguageType
/*aLangType*/,
985 vcl::KeyCode
& /*rKeyCode*/)
991 LanguageType
Qt5Frame::GetInputLanguage()
994 return LANGUAGE_DONTKNOW
;
997 static Color
toColor(const QColor
& rColor
)
999 return Color(rColor
.red(), rColor
.green(), rColor
.blue());
1002 void Qt5Frame::UpdateSettings(AllSettings
& rSettings
)
1004 if (Qt5Data::noNativeControls())
1007 StyleSettings
style(rSettings
.GetStyleSettings());
1010 QPalette pal
= QApplication::palette();
1012 style
.SetToolbarIconSize(ToolbarIconSize::Large
);
1014 Color aFore
= toColor(pal
.color(QPalette::Active
, QPalette::WindowText
));
1015 Color aBack
= toColor(pal
.color(QPalette::Active
, QPalette::Window
));
1016 Color aText
= toColor(pal
.color(QPalette::Active
, QPalette::Text
));
1017 Color aBase
= toColor(pal
.color(QPalette::Active
, QPalette::Base
));
1018 Color aButn
= toColor(pal
.color(QPalette::Active
, QPalette::ButtonText
));
1019 Color aMid
= toColor(pal
.color(QPalette::Active
, QPalette::Mid
));
1020 Color aHigh
= toColor(pal
.color(QPalette::Active
, QPalette::Highlight
));
1021 Color aHighText
= toColor(pal
.color(QPalette::Active
, QPalette::HighlightedText
));
1022 Color aLink
= toColor(pal
.color(QPalette::Active
, QPalette::Link
));
1023 Color aVisitedLink
= toColor(pal
.color(QPalette::Active
, QPalette::LinkVisited
));
1025 style
.SetSkipDisabledInMenus(true);
1028 style
.SetRadioCheckTextColor(aFore
);
1029 style
.SetLabelTextColor(aFore
);
1030 style
.SetDialogTextColor(aFore
);
1031 style
.SetGroupTextColor(aFore
);
1034 style
.SetFieldTextColor(aText
);
1035 style
.SetFieldRolloverTextColor(aText
);
1036 style
.SetWindowTextColor(aText
);
1037 style
.SetToolTextColor(aText
);
1040 style
.SetFieldColor(aBase
);
1041 style
.SetWindowColor(aBase
);
1042 style
.SetActiveTabColor(aBase
);
1045 style
.SetButtonTextColor(aButn
);
1046 style
.SetDefaultActionButtonTextColor(aButn
);
1047 style
.SetActionButtonTextColor(aButn
);
1048 style
.SetActionButtonRolloverTextColor(aButn
);
1049 style
.SetButtonRolloverTextColor(aButn
);
1050 style
.SetButtonPressedRolloverTextColor(aButn
);
1053 style
.SetTabTextColor(aButn
);
1054 style
.SetTabRolloverTextColor(aButn
);
1055 style
.SetTabHighlightTextColor(aButn
);
1058 style
.SetDisableColor(toColor(pal
.color(QPalette::Disabled
, QPalette::WindowText
)));
1061 style
.BatchSetBackgrounds(aBack
);
1062 style
.SetInactiveTabColor(aBack
);
1065 style
.SetWorkspaceColor(aMid
);
1068 style
.SetHighlightColor(aHigh
);
1069 style
.SetHighlightTextColor(aHighText
);
1072 style
.SetLinkColor(aLink
);
1073 style
.SetVisitedLinkColor(aVisitedLink
);
1076 style
.SetHelpColor(toColor(QToolTip::palette().color(QPalette::Active
, QPalette::ToolTipBase
)));
1077 style
.SetHelpTextColor(
1078 toColor(QToolTip::palette().color(QPalette::Active
, QPalette::ToolTipText
)));
1080 const int flash_time
= QApplication::cursorFlashTime();
1081 style
.SetCursorBlinkTime(flash_time
!= 0 ? flash_time
/ 2 : STYLE_CURSOR_NOBLINKTIME
);
1084 std::unique_ptr
<QMenuBar
> pMenuBar
= std::make_unique
<QMenuBar
>();
1085 QPalette qMenuCG
= pMenuBar
->palette();
1087 // Menu text and background color, theme specific
1088 Color aMenuFore
= toColor(qMenuCG
.color(QPalette::WindowText
));
1089 Color aMenuBack
= toColor(qMenuCG
.color(QPalette::Window
));
1091 style
.SetMenuTextColor(aMenuFore
);
1092 style
.SetMenuBarTextColor(style
.GetPersonaMenuBarTextColor().get_value_or(aMenuFore
));
1093 style
.SetMenuColor(aMenuBack
);
1094 style
.SetMenuBarColor(aMenuBack
);
1095 style
.SetMenuHighlightColor(toColor(qMenuCG
.color(QPalette::Highlight
)));
1096 style
.SetMenuHighlightTextColor(toColor(qMenuCG
.color(QPalette::HighlightedText
)));
1098 // set special menubar highlight text color
1099 if (QApplication::style()->inherits("HighContrastStyle"))
1100 ImplGetSVData()->maNWFData
.maMenuBarHighlightTextColor
1101 = toColor(qMenuCG
.color(QPalette::HighlightedText
));
1103 ImplGetSVData()->maNWFData
.maMenuBarHighlightTextColor
= aMenuFore
;
1105 // set menubar rollover color
1106 if (pMenuBar
->style()->styleHint(QStyle::SH_MenuBar_MouseTracking
))
1108 style
.SetMenuBarRolloverColor(toColor(qMenuCG
.color(QPalette::Highlight
)));
1109 style
.SetMenuBarRolloverTextColor(ImplGetSVData()->maNWFData
.maMenuBarHighlightTextColor
);
1113 style
.SetMenuBarRolloverColor(aMenuBack
);
1114 style
.SetMenuBarRolloverTextColor(aMenuFore
);
1116 style
.SetMenuBarHighlightTextColor(style
.GetMenuHighlightTextColor());
1119 style
.SetScrollBarSize(QApplication::style()->pixelMetric(QStyle::PM_ScrollBarExtent
));
1120 style
.SetMinThumbSize(QApplication::style()->pixelMetric(QStyle::PM_ScrollBarSliderMin
));
1122 // These colors are used for the ruler text and marks
1123 style
.SetShadowColor(toColor(pal
.color(QPalette::Disabled
, QPalette::WindowText
)));
1124 style
.SetDarkShadowColor(toColor(pal
.color(QPalette::Inactive
, QPalette::WindowText
)));
1126 m_bGraphicsInvalid
= true;
1127 rSettings
.SetStyleSettings(style
);
1130 void Qt5Frame::Beep() { QApplication::beep(); }
1132 SalFrame::SalPointerState
Qt5Frame::GetPointerState()
1134 SalPointerState aState
;
1135 aState
.maPos
= toPoint(QCursor::pos());
1136 aState
.mnState
= GetMouseModCode(QGuiApplication::mouseButtons())
1137 | GetKeyModCode(QGuiApplication::keyboardModifiers());
1141 KeyIndicatorState
Qt5Frame::GetIndicatorState() { return KeyIndicatorState(); }
1143 void Qt5Frame::SimulateKeyPress(sal_uInt16 nKeyCode
)
1145 SAL_WARN("vcl.qt5", "missing simulate keypress " << nKeyCode
);
1148 void Qt5Frame::SetParent(SalFrame
* pNewParent
) { m_pParent
= static_cast<Qt5Frame
*>(pNewParent
); }
1150 bool Qt5Frame::SetPluginParent(SystemParentData
* /*pNewParent*/)
1152 //FIXME: no SetPluginParent impl. for qt5
1156 void Qt5Frame::ResetClipRegion() { m_bNullRegion
= true; }
1158 void Qt5Frame::BeginSetClipRegion(sal_uInt32
)
1160 m_aRegion
= QRegion(QRect(QPoint(0, 0), m_pQWidget
->size()));
1163 void Qt5Frame::UnionClipRegion(long nX
, long nY
, long nWidth
, long nHeight
)
1165 m_aRegion
= m_aRegion
.united(QRegion(nX
, nY
, nWidth
, nHeight
));
1168 void Qt5Frame::EndSetClipRegion() { m_bNullRegion
= false; }
1170 void Qt5Frame::SetScreenNumber(unsigned int nScreen
)
1174 QWindow
* const pWindow
= windowHandle();
1177 QList
<QScreen
*> screens
= QApplication::screens();
1178 if (static_cast<int>(nScreen
) < screens
.size() || m_bFullScreenSpanAll
)
1182 if (!m_bFullScreenSpanAll
)
1184 screenGeo
= QApplication::desktop()->screenGeometry(nScreen
);
1185 pWindow
->setScreen(QApplication::screens()[nScreen
]);
1187 else // special case: fullscreen over all available screens
1189 assert(m_bFullScreen
);
1191 int nLeftScreen
= QApplication::desktop()->screenNumber(QPoint(0, 0));
1192 // entire virtual desktop
1193 screenGeo
= QApplication::screens()[nLeftScreen
]->availableVirtualGeometry();
1194 pWindow
->setScreen(QApplication::screens()[nLeftScreen
]);
1195 pWindow
->setGeometry(screenGeo
);
1196 nScreen
= nLeftScreen
;
1199 // setScreen by itself has no effect, explicitly move the widget to
1201 asChild()->move(screenGeo
.topLeft());
1205 // index outta bounds, use primary screen
1206 QScreen
* primaryScreen
= QApplication::primaryScreen();
1207 pWindow
->setScreen(primaryScreen
);
1208 nScreen
= static_cast<sal_uInt32
>(screenNumber(primaryScreen
));
1211 maGeometry
.nDisplayScreenNumber
= nScreen
;
1216 void Qt5Frame::SetApplicationID(const OUString
& rWMClass
)
1219 if (QGuiApplication::platformName() != "xcb" || !m_pTopLevel
)
1222 OString aResClass
= OUStringToOString(rWMClass
, RTL_TEXTENCODING_ASCII_US
);
1223 const char* pResClass
1224 = !aResClass
.isEmpty() ? aResClass
.getStr() : SalGenericSystem::getFrameClassName();
1225 OString aResName
= SalGenericSystem::getFrameResName();
1227 // the WM_CLASS data consists of two concatenated cstrings, including the terminating '\0' chars
1228 const uint32_t data_len
= aResName
.getLength() + 1 + strlen(pResClass
) + 1;
1229 char* data
= new char[data_len
];
1230 memcpy(data
, aResName
.getStr(), aResName
.getLength() + 1);
1231 memcpy(data
+ aResName
.getLength() + 1, pResClass
, strlen(pResClass
) + 1);
1233 xcb_change_property(QX11Info::connection(), XCB_PROP_MODE_REPLACE
, m_pTopLevel
->winId(),
1234 XCB_ATOM_WM_CLASS
, XCB_ATOM_STRING
, 8, data_len
, data
);
1243 void Qt5Frame::registerDragSource(Qt5DragSource
* pDragSource
)
1245 assert(!m_pDragSource
);
1246 m_pDragSource
= pDragSource
;
1249 void Qt5Frame::deregisterDragSource(Qt5DragSource
const* pDragSource
)
1251 assert(m_pDragSource
== pDragSource
);
1253 m_pDragSource
= nullptr;
1256 void Qt5Frame::registerDropTarget(Qt5DropTarget
* pDropTarget
)
1258 assert(!m_pDropTarget
);
1259 m_pDropTarget
= pDropTarget
;
1260 m_pQWidget
->setAcceptDrops(true);
1263 void Qt5Frame::deregisterDropTarget(Qt5DropTarget
const* pDropTarget
)
1265 assert(m_pDropTarget
== pDropTarget
);
1267 m_pDropTarget
= nullptr;
1270 static css::uno::Reference
<css::datatransfer::XTransferable
>
1271 lcl_getXTransferable(const QMimeData
* pMimeData
)
1273 css::uno::Reference
<css::datatransfer::XTransferable
> xTransferable
;
1274 const Qt5MimeData
* pQt5MimeData
= dynamic_cast<const Qt5MimeData
*>(pMimeData
);
1276 xTransferable
= new Qt5DnDTransferable(pMimeData
);
1278 xTransferable
= pQt5MimeData
->xTransferable();
1279 return xTransferable
;
1282 static sal_Int8
lcl_getUserDropAction(const QDropEvent
* pEvent
, const sal_Int8 nSourceActions
,
1283 const QMimeData
* pMimeData
)
1285 // we completely ignore all proposals by the Qt event, as they don't
1286 // match at all with the preferred LO DnD actions.
1288 // check the key modifiers to detect a user-overridden DnD action
1289 const Qt::KeyboardModifiers eKeyMod
= pEvent
->keyboardModifiers();
1290 sal_Int8 nUserDropAction
= 0;
1291 if ((eKeyMod
& Qt::ShiftModifier
) && !(eKeyMod
& Qt::ControlModifier
))
1292 nUserDropAction
= css::datatransfer::dnd::DNDConstants::ACTION_MOVE
;
1293 else if ((eKeyMod
& Qt::ControlModifier
) && !(eKeyMod
& Qt::ShiftModifier
))
1294 nUserDropAction
= css::datatransfer::dnd::DNDConstants::ACTION_COPY
;
1295 else if ((eKeyMod
& Qt::ShiftModifier
) && (eKeyMod
& Qt::ControlModifier
))
1296 nUserDropAction
= css::datatransfer::dnd::DNDConstants::ACTION_LINK
;
1297 nUserDropAction
&= nSourceActions
;
1299 // select the default DnD action, if there isn't a user preference
1300 if (0 == nUserDropAction
)
1302 // default LO internal action is move, but default external action is copy
1303 nUserDropAction
= dynamic_cast<const Qt5MimeData
*>(pMimeData
)
1304 ? css::datatransfer::dnd::DNDConstants::ACTION_MOVE
1305 : css::datatransfer::dnd::DNDConstants::ACTION_COPY
;
1306 nUserDropAction
&= nSourceActions
;
1308 // if the default doesn't match any allowed source action, fall back to the
1309 // preferred of all allowed source actions
1310 if (0 == nUserDropAction
)
1311 nUserDropAction
= toVclDropAction(getPreferredDropAction(nSourceActions
));
1313 // this is "our" preference, but actually we would even prefer any default,
1315 nUserDropAction
|= css::datatransfer::dnd::DNDConstants::ACTION_DEFAULT
;
1317 return nUserDropAction
;
1320 void Qt5Frame::handleDragMove(QDragMoveEvent
* pEvent
)
1322 assert(m_pDropTarget
);
1324 // prepare our suggested drop action for the drop target
1325 const sal_Int8 nSourceActions
= toVclDropActions(pEvent
->possibleActions());
1326 const QMimeData
* pMimeData
= pEvent
->mimeData();
1327 const sal_Int8 nUserDropAction
= lcl_getUserDropAction(pEvent
, nSourceActions
, pMimeData
);
1329 css::datatransfer::dnd::DropTargetDragEnterEvent aEvent
;
1330 aEvent
.Source
= static_cast<css::datatransfer::dnd::XDropTarget
*>(m_pDropTarget
);
1331 aEvent
.Context
= static_cast<css::datatransfer::dnd::XDropTargetDragContext
*>(m_pDropTarget
);
1332 aEvent
.LocationX
= pEvent
->pos().x();
1333 aEvent
.LocationY
= pEvent
->pos().y();
1334 aEvent
.DropAction
= nUserDropAction
;
1335 aEvent
.SourceActions
= nSourceActions
;
1337 // ask the drop target to accept our drop action
1340 aEvent
.SupportedDataFlavors
= lcl_getXTransferable(pMimeData
)->getTransferDataFlavors();
1341 m_pDropTarget
->fire_dragEnter(aEvent
);
1345 m_pDropTarget
->fire_dragOver(aEvent
);
1347 // the drop target accepted our drop action => inform Qt
1348 if (m_pDropTarget
->proposedDropAction() != 0)
1350 pEvent
->setDropAction(getPreferredDropAction(m_pDropTarget
->proposedDropAction()));
1353 else // or maybe someone else likes it?
1357 void Qt5Frame::handleDrop(QDropEvent
* pEvent
)
1359 assert(m_pDropTarget
);
1361 // prepare our suggested drop action for the drop target
1362 const sal_Int8 nSourceActions
= toVclDropActions(pEvent
->possibleActions());
1363 const sal_Int8 nUserDropAction
1364 = lcl_getUserDropAction(pEvent
, nSourceActions
, pEvent
->mimeData());
1366 css::datatransfer::dnd::DropTargetDropEvent aEvent
;
1367 aEvent
.Source
= static_cast<css::datatransfer::dnd::XDropTarget
*>(m_pDropTarget
);
1368 aEvent
.Context
= static_cast<css::datatransfer::dnd::XDropTargetDropContext
*>(m_pDropTarget
);
1369 aEvent
.LocationX
= pEvent
->pos().x();
1370 aEvent
.LocationY
= pEvent
->pos().y();
1371 aEvent
.SourceActions
= nSourceActions
;
1372 aEvent
.DropAction
= nUserDropAction
;
1373 aEvent
.Transferable
= lcl_getXTransferable(pEvent
->mimeData());
1375 // ask the drop target to accept our drop action
1376 m_pDropTarget
->fire_drop(aEvent
);
1379 const bool bDropSuccessful
= m_pDropTarget
->dropSuccessful();
1380 const sal_Int8 nDropAction
= m_pDropTarget
->proposedDropAction();
1382 // inform the drag source of the drag-origin frame of the drop result
1383 if (pEvent
->source())
1385 Qt5Widget
* pWidget
= dynamic_cast<Qt5Widget
*>(pEvent
->source());
1386 assert(pWidget
); // AFAIK there shouldn't be any non-Qt5Widget as source in LO itself
1388 pWidget
->frame().m_pDragSource
->fire_dragEnd(nDropAction
, bDropSuccessful
);
1391 // the drop target accepted our drop action => inform Qt
1392 if (bDropSuccessful
)
1394 pEvent
->setDropAction(getPreferredDropAction(nDropAction
));
1397 else // or maybe someone else likes it?
1401 void Qt5Frame::handleDragLeave()
1403 css::datatransfer::dnd::DropTargetEvent aEvent
;
1404 aEvent
.Source
= static_cast<css::datatransfer::dnd::XDropTarget
*>(m_pDropTarget
);
1405 m_pDropTarget
->fire_dragExit(aEvent
);
1409 cairo_t
* Qt5Frame::getCairoContext() const
1411 cairo_t
* cr
= nullptr;
1414 cr
= cairo_create(m_pSurface
.get());
1420 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */