LibreOffice Module sfx2 (master) 1
recfloat.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <com/sun/star/awt/XTopWindow.hpp>
21#include <com/sun/star/frame/XDispatchRecorder.hpp>
22
23#include <svl/eitem.hxx>
24#include <vcl/svapp.hxx>
25#include <vcl/weld.hxx>
26#include <vcl/windowstate.hxx>
27
28#include <recfloat.hxx>
29#include <sfx2/strings.hrc>
30#include <sfx2/sfxresid.hxx>
31#include <sfx2/bindings.hxx>
32#include <sfx2/dispatch.hxx>
33#include <sfx2/sfxsids.hrc>
34#include <sfx2/viewfrm.hxx>
35#include <sfx2/viewsh.hxx>
36
38
40 sal_uInt16 nId,
41 SfxBindings* pBind,
42 SfxChildWinInfo const * pInfo)
43 : SfxChildWindow(pParentWnd, nId)
44 , pBindings(pBind)
45{
46 SetController(std::make_shared<SfxRecordingFloat_Impl>(pBindings, this, pParentWnd->GetFrameWeld()));
47 SetWantsFocus(false);
48 SfxRecordingFloat_Impl* pFloatDlg = static_cast<SfxRecordingFloat_Impl*>(GetController().get());
49
50 weld::Dialog* pDlg = pFloatDlg->getDialog();
51
52 SfxViewFrame *pFrame = pBind->GetDispatcher_Impl()->GetFrame();
53 vcl::Window* pEditWin = pFrame->GetViewShell()->GetWindow();
54
55 Point aPos = pEditWin->OutputToScreenPixel( pEditWin->GetPosPixel() );
56 aPos.AdjustX(20);
57 aPos.AdjustY(10);
58
59 vcl::WindowData aState;
61 aState.setPos(aPos);
62 pDlg->set_window_state(aState.toStr());
63
64 pFloatDlg->Initialize(pInfo);
65}
66
68{
69 SfxBoolItem aItem( FN_PARAM_1, true );
70 css::uno::Reference< css::frame::XDispatchRecorder > xRecorder = pBindings->GetRecorder();
71 if ( xRecorder.is() )
72 pBindings->GetDispatcher()->ExecuteList(SID_STOP_RECORDING,
73 SfxCallMode::SYNCHRON, { &aItem });
74}
75
77{
78 // asking for recorded macro should be replaced if index access is available!
79 bool bRet = true;
80 css::uno::Reference< css::frame::XDispatchRecorder > xRecorder = pBindings->GetRecorder();
81 if ( xRecorder.is() && !xRecorder->getRecordedMacro().isEmpty() )
82 {
83 SfxRecordingFloat_Impl* pFloatDlg = static_cast<SfxRecordingFloat_Impl*>(GetController().get());
84 weld::Dialog* pDlg = pFloatDlg->getDialog();
85
86 std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(pDlg,
87 VclMessageType::Question, VclButtonsType::YesNo,
88 SfxResId(STR_MACRO_LOSS)));
89 xQueryBox->set_default_response(RET_NO);
90
91 xQueryBox->set_title(SfxResId(STR_CANCEL_RECORDING));
92 bRet = (xQueryBox->run() == RET_YES);
93 }
94
95 return bRet;
96}
97
99 weld::Window* pParent)
100 : SfxModelessDialogController(pBind, pChildWin, pParent, "sfx/ui/floatingrecord.ui",
101 "FloatingRecord")
102 , m_xToolbar(m_xBuilder->weld_toolbar("toolbar"))
103 , m_xDispatcher(new ToolbarUnoDispatcher(*m_xToolbar, *m_xBuilder, pBind->GetActiveFrame()))
104 , mnPostUserEventId(nullptr)
105 , m_bFirstActivate(true)
106{
107 // start recording
108 SfxBoolItem aItem( SID_RECORDMACRO, true );
109 GetBindings().GetDispatcher()->ExecuteList(SID_RECORDMACRO,
110 SfxCallMode::SYNCHRON, { &aItem });
111}
112
113IMPL_LINK_NOARG(SfxRecordingFloat_Impl, PresentParentFrame, void*, void)
114{
115 mnPostUserEventId = nullptr;
116 css::uno::Reference<css::awt::XTopWindow> xTopWindow(m_xDispatcher->GetFrame()->getContainerWindow(), css::uno::UNO_QUERY);
117 if (xTopWindow.is())
118 xTopWindow->toFront();
119}
120
122{
124 if (!m_bFirstActivate)
125 return;
126 // tdf#147782 retain focus in launching frame on the first activate on automatically gaining focus on getting launched
127 m_bFirstActivate = false;
129}
130
132{
135 m_xDispatcher->dispose();
136}
137
139{
141 rInfo.bVisible = false;
142}
143
144/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static ImplSVEvent * PostUserEvent(const Link< void *, void > &rLink, void *pCaller=nullptr, bool bReferenceLink=false)
static void RemoveUserEvent(ImplSVEvent *nUserEvent)
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
tools::Long AdjustY(tools::Long nVertMove)
tools::Long AdjustX(tools::Long nHorzMove)
SAL_DLLPRIVATE SfxDispatcher * GetDispatcher_Impl()
Definition: bindings.hxx:180
SfxDispatcher * GetDispatcher() const
Definition: bindings.hxx:172
const css::uno::Reference< css::frame::XDispatchRecorder > & GetRecorder() const
Definition: bindings.cxx:1734
void SetController(std::shared_ptr< SfxDialogController > controller)
Definition: childwin.hxx:119
std::shared_ptr< SfxDialogController > & GetController()
Definition: childwin.hxx:121
void SetWantsFocus(bool)
Definition: childwin.cxx:441
const SfxPoolItem * ExecuteList(sal_uInt16 nSlot, SfxCallMode nCall, std::initializer_list< SfxPoolItem const * > args, std::initializer_list< SfxPoolItem const * > internalargs=std::initializer_list< SfxPoolItem const * >())
Method to execute a <SfxSlot>s over the Slot-Id.
Definition: dispatch.cxx:931
SfxViewFrame * GetFrame() const
Returns a pointer to the <SfxViewFrame> instance, which belongs to this SfxDispatcher.
Definition: dispatch.cxx:557
virtual void FillInfo(SfxChildWinInfo &) const
Definition: basedlgs.cxx:91
SfxBindings & GetBindings() const
Definition: basedlgs.hxx:82
void Initialize(SfxChildWinInfo const *pInfo)
Definition: basedlgs.cxx:56
virtual void Activate() override
Definition: basedlgs.cxx:119
SfxRecordingFloatWrapper_Impl(vcl::Window *pParent, sal_uInt16 nId, SfxBindings *pBindings, SfxChildWinInfo const *pInfo)
Definition: recfloat.cxx:39
virtual bool QueryClose() override
Definition: recfloat.cxx:76
virtual ~SfxRecordingFloatWrapper_Impl() override
Definition: recfloat.cxx:67
ImplSVEvent * mnPostUserEventId
Definition: recfloat.hxx:45
virtual void FillInfo(SfxChildWinInfo &rInfo) const override
Definition: recfloat.cxx:138
SfxRecordingFloat_Impl(SfxBindings *pBindings, SfxChildWindow *pChildWin, weld::Window *pParent)
Definition: recfloat.cxx:98
virtual void Activate() override
Definition: recfloat.cxx:121
std::unique_ptr< ToolbarUnoDispatcher > m_xDispatcher
Definition: recfloat.hxx:44
virtual ~SfxRecordingFloat_Impl() override
Definition: recfloat.cxx:131
SfxViewShell * GetViewShell() const
Returns the SfxViewShell in which they are located in the subshells.
Definition: shell.cxx:129
vcl::Window * GetWindow() const
Definition: viewsh.hxx:272
OUString toStr() const
void setMask(WindowDataMask nMask)
void setPos(const Point &aPos)
Point OutputToScreenPixel(const Point &rPos) const
virtual Point GetPosPixel() const
weld::Window * GetFrameWeld() const
virtual Dialog * getDialog() override
virtual void set_window_state(const OUString &rStr)=0
sal_Int16 nId
SFX_IMPL_MODELESSDIALOGCONTOLLER(SfxRecordingFloatWrapper_Impl, SID_RECORDING_FLOATWINDOW)
IMPL_LINK_NOARG(SfxRecordingFloat_Impl, PresentParentFrame, void *, void)
Definition: recfloat.cxx:113
OUString SfxResId(TranslateId aId)
Definition: sfxresid.cxx:22
RET_NO
RET_YES