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 <sfx2/viewfrm.hxx>
21 #include <sfx2/dispatch.hxx>
22
23 #include <cmdid.h>
24 #include <swmodule.hxx>
25 #include <view.hxx>
26 #include <edtwin.hxx>
27
28 #include <syncbtn.hxx>
29 #include <swtypes.hxx>
30
SFX_IMPL_MODELESSDIALOGCONTOLLER(SwSyncChildWin,FN_SYNC_LABELS)31 SFX_IMPL_MODELESSDIALOGCONTOLLER(SwSyncChildWin, FN_SYNC_LABELS)
32
33 SwSyncChildWin::SwSyncChildWin(vcl::Window* _pParent,
34 sal_uInt16 nId,
35 SfxBindings* pBindings,
36 SfxChildWinInfo* pInfo)
37 : SfxChildWindow(_pParent, nId)
38 {
39 SetController(std::make_shared<SwSyncBtnDlg>(pBindings, this, _pParent->GetFrameWeld()));
40 SwSyncBtnDlg* pBtnDlg = static_cast<SwSyncBtnDlg*>(GetController().get());
41
42 if (!pInfo->aSize.Width() || !pInfo->aSize.Height())
43 {
44 weld::Dialog* pDlg = pBtnDlg->getDialog();
45 Point aPos;
46
47 SwView* pActiveView = ::GetActiveView();
48 if (pActiveView)
49 {
50 const SwEditWin &rEditWin = pActiveView->GetEditWin();
51 aPos = rEditWin.OutputToScreenPixel(Point(0, 0));
52 }
53 else
54 aPos = _pParent->OutputToScreenPixel(Point(0, 0));
55
56 WindowStateData aState;
57 aState.SetMask(WindowStateMask::Pos);
58 aState.SetX(aPos.X());
59 aState.SetY(aPos.Y());
60 pDlg->set_window_state(aState.ToStr());
61
62 pInfo->aPos = pDlg->get_position();
63 pInfo->aSize = pDlg->get_size();
64 }
65
66 pBtnDlg->Initialize(pInfo);
67 }
68
SwSyncBtnDlg(SfxBindings * pBindings,SfxChildWindow * pChild,weld::Window * pParent)69 SwSyncBtnDlg::SwSyncBtnDlg(SfxBindings* pBindings,
70 SfxChildWindow* pChild,
71 weld::Window *pParent)
72 : SfxModelessDialogController(pBindings, pChild, pParent, "modules/swriter/ui/floatingsync.ui", "FloatingSync")
73 , m_xSyncBtn(m_xBuilder->weld_button("sync"))
74 {
75 m_xSyncBtn->connect_clicked(LINK(this, SwSyncBtnDlg, BtnHdl));
76 }
77
~SwSyncBtnDlg()78 SwSyncBtnDlg::~SwSyncBtnDlg()
79 {
80 }
81
IMPL_STATIC_LINK_NOARG(SwSyncBtnDlg,BtnHdl,weld::Button &,void)82 IMPL_STATIC_LINK_NOARG(SwSyncBtnDlg, BtnHdl, weld::Button&, void)
83 {
84 SfxViewFrame::Current()->GetDispatcher()->Execute(FN_UPDATE_ALL_LINKS, SfxCallMode::ASYNCHRON);
85 }
86
87 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
88