/src/libreoffice/sfx2/source/dialog/recfloat.cxx
Line | Count | Source |
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/Builder.hxx> |
26 | | #include <vcl/weld/Dialog.hxx> |
27 | | #include <vcl/weld/MessageDialog.hxx> |
28 | | #include <vcl/windowstate.hxx> |
29 | | |
30 | | #include <recfloat.hxx> |
31 | | #include <sfx2/strings.hrc> |
32 | | #include <sfx2/sfxresid.hxx> |
33 | | #include <sfx2/bindings.hxx> |
34 | | #include <sfx2/dispatch.hxx> |
35 | | #include <sfx2/sfxsids.hrc> |
36 | | #include <sfx2/viewfrm.hxx> |
37 | | #include <sfx2/viewsh.hxx> |
38 | | #include <svl/itemset.hxx> |
39 | | |
40 | | SFX_IMPL_MODELESSDIALOGCONTOLLER(SfxRecordingFloatWrapper_Impl, SID_RECORDING_FLOATWINDOW); |
41 | | |
42 | | SfxRecordingFloatWrapper_Impl::SfxRecordingFloatWrapper_Impl(vcl::Window* pParentWnd, |
43 | | sal_uInt16 nId, SfxBindings& rBindings, |
44 | | const SfxChildWinInfo& rInfo) |
45 | 0 | : SfxChildWindow(pParentWnd, nId) |
46 | 0 | , m_rBindings(rBindings) |
47 | 0 | { |
48 | 0 | SetController( |
49 | 0 | std::make_shared<SfxRecordingFloat_Impl>(m_rBindings, this, pParentWnd->GetFrameWeld())); |
50 | 0 | SetWantsFocus(false); |
51 | 0 | SfxRecordingFloat_Impl* pFloatDlg = static_cast<SfxRecordingFloat_Impl*>(GetController().get()); |
52 | |
|
53 | 0 | weld::Dialog* pDlg = pFloatDlg->getDialog(); |
54 | |
|
55 | 0 | SfxViewFrame* pFrame = rBindings.GetDispatcher_Impl()->GetFrame(); |
56 | 0 | vcl::Window* pEditWin = pFrame->GetViewShell()->GetWindow(); |
57 | |
|
58 | 0 | Point aPos = pEditWin->OutputToScreenPixel( pEditWin->GetPosPixel() ); |
59 | 0 | aPos.AdjustX(20); |
60 | 0 | aPos.AdjustY(10); |
61 | |
|
62 | 0 | vcl::WindowData aState; |
63 | 0 | aState.setMask(vcl::WindowDataMask::Pos); |
64 | 0 | aState.setPos(aPos); |
65 | 0 | pDlg->set_window_state(aState); |
66 | |
|
67 | 0 | pFloatDlg->Initialize(rInfo); |
68 | 0 | } |
69 | | |
70 | | SfxRecordingFloatWrapper_Impl::~SfxRecordingFloatWrapper_Impl() |
71 | 0 | { |
72 | 0 | SfxBoolItem aItem( FN_PARAM_1, true ); |
73 | 0 | css::uno::Reference<css::frame::XDispatchRecorder> xRecorder = m_rBindings.GetRecorder(); |
74 | 0 | if ( xRecorder.is() ) |
75 | 0 | m_rBindings.GetDispatcher()->ExecuteList(SID_STOP_RECORDING, SfxCallMode::SYNCHRON, |
76 | 0 | { &aItem }); |
77 | 0 | } |
78 | | |
79 | | bool SfxRecordingFloatWrapper_Impl::QueryClose() |
80 | 0 | { |
81 | | // asking for recorded macro should be replaced if index access is available! |
82 | 0 | bool bRet = true; |
83 | 0 | css::uno::Reference<css::frame::XDispatchRecorder> xRecorder = m_rBindings.GetRecorder(); |
84 | 0 | if ( xRecorder.is() && !xRecorder->getRecordedMacro().isEmpty() ) |
85 | 0 | { |
86 | 0 | SfxRecordingFloat_Impl* pFloatDlg = static_cast<SfxRecordingFloat_Impl*>(GetController().get()); |
87 | 0 | weld::Dialog* pDlg = pFloatDlg->getDialog(); |
88 | |
|
89 | 0 | std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(pDlg, |
90 | 0 | VclMessageType::Question, VclButtonsType::YesNo, |
91 | 0 | SfxResId(STR_MACRO_LOSS))); |
92 | 0 | xQueryBox->set_default_response(RET_NO); |
93 | |
|
94 | 0 | xQueryBox->set_title(SfxResId(STR_CANCEL_RECORDING)); |
95 | 0 | bRet = (xQueryBox->run() == RET_YES); |
96 | 0 | } |
97 | |
|
98 | 0 | return bRet; |
99 | 0 | } |
100 | | |
101 | | SfxRecordingFloat_Impl::SfxRecordingFloat_Impl(SfxBindings& rBindings, SfxChildWindow* pChildWin, |
102 | | weld::Window* pParent) |
103 | 0 | : SfxModelessDialogController(&rBindings, pChildWin, pParent, u"sfx/ui/floatingrecord.ui"_ustr, |
104 | 0 | u"FloatingRecord"_ustr) |
105 | 0 | , m_xToolbar(m_xBuilder->weld_toolbar(u"toolbar"_ustr)) |
106 | 0 | , m_xDispatcher(new ToolbarUnoDispatcher(*m_xToolbar, *m_xBuilder, rBindings.GetActiveFrame())) |
107 | 0 | , mnPostUserEventId(nullptr) |
108 | 0 | , m_bFirstActivate(true) |
109 | 0 | { |
110 | | // start recording |
111 | 0 | SfxBoolItem aItem( SID_RECORDMACRO, true ); |
112 | 0 | GetBindings().GetDispatcher()->ExecuteList(SID_RECORDMACRO, |
113 | 0 | SfxCallMode::SYNCHRON, { &aItem }); |
114 | 0 | } |
115 | | |
116 | | IMPL_LINK_NOARG(SfxRecordingFloat_Impl, PresentParentFrame, void*, void) |
117 | 0 | { |
118 | 0 | mnPostUserEventId = nullptr; |
119 | 0 | css::uno::Reference<css::awt::XTopWindow> xTopWindow(m_xDispatcher->GetFrame()->getContainerWindow(), css::uno::UNO_QUERY); |
120 | 0 | if (xTopWindow.is()) |
121 | 0 | xTopWindow->toFront(); |
122 | 0 | } |
123 | | |
124 | | void SfxRecordingFloat_Impl::Activate() |
125 | 0 | { |
126 | 0 | SfxModelessDialogController::Activate(); |
127 | 0 | if (!m_bFirstActivate) |
128 | 0 | return; |
129 | | // tdf#147782 retain focus in launching frame on the first activate on automatically gaining focus on getting launched |
130 | 0 | m_bFirstActivate = false; |
131 | 0 | mnPostUserEventId = Application::PostUserEvent(LINK(this, SfxRecordingFloat_Impl, PresentParentFrame)); |
132 | 0 | } |
133 | | |
134 | | SfxRecordingFloat_Impl::~SfxRecordingFloat_Impl() |
135 | 0 | { |
136 | 0 | if (mnPostUserEventId) |
137 | 0 | Application::RemoveUserEvent(mnPostUserEventId); |
138 | 0 | m_xDispatcher->dispose(); |
139 | 0 | } |
140 | | |
141 | | void SfxRecordingFloat_Impl::FillInfo( SfxChildWinInfo& rInfo ) const |
142 | 0 | { |
143 | 0 | SfxModelessDialogController::FillInfo( rInfo ); |
144 | 0 | rInfo.bVisible = false; |
145 | 0 | } |
146 | | |
147 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |