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 <swmodule.hxx>
23 #include <gotodlg.hxx>
24 #include <sfx2/bindings.hxx>
25 #include <sfx2/viewfrm.hxx>
27 using namespace com::sun::star
;
29 SwGotoPageDlg::SwGotoPageDlg(weld::Window
* pParent
, SfxBindings
& rBindings
)
30 : GenericDialogController(pParent
, "modules/swriter/ui/gotopagedialog.ui", "GotoPageDialog")
31 , m_pCreateView(nullptr)
32 , m_rBindings(rBindings
)
34 , mxMtrPageCtrl(m_xBuilder
->weld_spin_button("page"))
35 , mxPageNumberLbl(m_xBuilder
->weld_label("page_count"))
37 sal_uInt16 nTotalPage
= GetPageInfo();
41 OUString sStr
= mxPageNumberLbl
->get_label();
42 mxPageNumberLbl
->set_label(sStr
.replaceFirst("$1", OUString::number(nTotalPage
)));
43 mnMaxPageCnt
= nTotalPage
;
45 mxMtrPageCtrl
->connect_changed(LINK(this, SwGotoPageDlg
, PageModifiedHdl
));
46 mxMtrPageCtrl
->set_position(-1);
47 mxMtrPageCtrl
->select_region(0, -1);
50 IMPL_LINK_NOARG(SwGotoPageDlg
, PageModifiedHdl
, weld::Entry
&, void)
52 if (mxMtrPageCtrl
->get_text().isEmpty())
55 int page_value
= mxMtrPageCtrl
->get_text().toInt32();
58 mxMtrPageCtrl
->set_value(1);
59 else if (page_value
> mnMaxPageCnt
)
60 mxMtrPageCtrl
->set_value(mnMaxPageCnt
);
62 mxMtrPageCtrl
->set_value(page_value
);
64 mxMtrPageCtrl
->set_position(-1);
67 SwView
* SwGotoPageDlg::GetCreateView() const
71 SwView
* pView
= SwModule::GetFirstView();
74 if (&pView
->GetViewFrame().GetBindings() == &m_rBindings
)
76 const_cast<SwGotoPageDlg
*>(this)->m_pCreateView
= pView
;
79 pView
= SwModule::GetNextView(pView
);
86 // If the page can be set here, the maximum is set.
88 sal_uInt16
SwGotoPageDlg::GetPageInfo()
90 SwView
* pView
= GetCreateView();
91 SwWrtShell
* pSh
= pView
? &pView
->GetWrtShell() : nullptr;
92 mxMtrPageCtrl
->set_value(1);
95 const sal_uInt16 nPageCnt
= pSh
->GetPageCnt();
96 sal_uInt16 nPhyPage
, nVirPage
;
97 pSh
->GetPageNum(nPhyPage
, nVirPage
);
98 mxMtrPageCtrl
->set_max(nPageCnt
);
99 mxMtrPageCtrl
->set_value(nPhyPage
);
105 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */