/src/libreoffice/sc/source/ui/cctrl/SheetViewBox.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 | | |
10 | | #include <SheetViewBox.hxx> |
11 | | |
12 | | #include <sfx2/dispatch.hxx> |
13 | | #include <sfx2/viewfrm.hxx> |
14 | | #include <sfx2/viewsh.hxx> |
15 | | #include <svl/intitem.hxx> |
16 | | #include <svl/itemset.hxx> |
17 | | #include <vcl/weld/Builder.hxx> |
18 | | |
19 | | #include <globstr.hrc> |
20 | | #include <scresid.hxx> |
21 | | #include <sc.hrc> |
22 | | #include <docsh.hxx> |
23 | | #include <viewdata.hxx> |
24 | | |
25 | | #include <SheetViewManager.hxx> |
26 | | #include <SheetView.hxx> |
27 | | #include <SheetViewTypes.hxx> |
28 | | |
29 | | SheetViewBox::SheetViewBox(vcl::Window* pParent) |
30 | 0 | : InterimItemWindow(pParent, u"modules/scalc/ui/sheetviewbox.ui"_ustr, u"SheetViewBox"_ustr, |
31 | 0 | true, reinterpret_cast<sal_uInt64>(SfxViewShell::Current())) |
32 | 0 | , m_xWidget(m_xBuilder->weld_combo_box(u"sheetview_combobox"_ustr)) |
33 | 0 | { |
34 | 0 | m_xWidget->connect_changed(LINK(this, SheetViewBox, SelectHdl)); |
35 | 0 | m_xWidget->connect_key_press(LINK(this, SheetViewBox, KeyInputHdl)); |
36 | 0 | SetSizePixel(m_xWidget->get_preferred_size()); |
37 | 0 | } Unexecuted instantiation: SheetViewBox::SheetViewBox(vcl::Window*) Unexecuted instantiation: SheetViewBox::SheetViewBox(vcl::Window*) |
38 | | |
39 | | void SheetViewBox::dispose() |
40 | 0 | { |
41 | 0 | m_xWidget.reset(); |
42 | 0 | InterimItemWindow::dispose(); |
43 | 0 | } |
44 | | |
45 | 0 | SheetViewBox::~SheetViewBox() { disposeOnce(); } |
46 | | |
47 | | void SheetViewBox::GetFocus() |
48 | 0 | { |
49 | 0 | if (m_xWidget) |
50 | 0 | m_xWidget->grab_focus(); |
51 | 0 | InterimItemWindow::GetFocus(); |
52 | 0 | } |
53 | | |
54 | | void SheetViewBox::Update(sc::SheetViewID nSelectedID) |
55 | 0 | { |
56 | 0 | ScViewData* pViewData = ScDocShell::GetViewData(); |
57 | 0 | if (!pViewData) |
58 | 0 | return; |
59 | | |
60 | 0 | m_xWidget->clear(); |
61 | 0 | m_xWidget->freeze(); |
62 | |
|
63 | 0 | OUString sActiveID = OUString::number(sc::DefaultSheetViewID); |
64 | 0 | m_xWidget->append(sActiveID, sc::SheetViewManager::defaultViewName()); |
65 | |
|
66 | 0 | auto pSheetManager = pViewData->GetCurrentSheetViewManager(); |
67 | |
|
68 | 0 | if (pSheetManager) |
69 | 0 | { |
70 | 0 | sc::SheetViewID nSheetViewID = 0; |
71 | 0 | for (auto const& pSheetView : pSheetManager->getSheetViews()) |
72 | 0 | { |
73 | 0 | if (pSheetView) |
74 | 0 | { |
75 | 0 | OUString sID = OUString::number(nSheetViewID); |
76 | 0 | if (nSheetViewID == nSelectedID) |
77 | 0 | sActiveID = sID; |
78 | 0 | m_xWidget->append(sID, pSheetView->GetName()); |
79 | 0 | } |
80 | 0 | nSheetViewID++; |
81 | 0 | } |
82 | 0 | } |
83 | 0 | m_xWidget->thaw(); |
84 | |
|
85 | 0 | m_xWidget->set_active_id(sActiveID); |
86 | 0 | } |
87 | | |
88 | | IMPL_STATIC_LINK(SheetViewBox, SelectHdl, weld::ComboBox&, rComboBox, void) |
89 | 0 | { |
90 | 0 | auto* pViewFrame = SfxViewFrame::Current(); |
91 | 0 | if (!pViewFrame) |
92 | 0 | return; |
93 | | |
94 | 0 | SfxDispatcher* pDispatcher = pViewFrame->GetBindings().GetDispatcher(); |
95 | 0 | if (!pDispatcher) |
96 | 0 | return; |
97 | | |
98 | 0 | const OUString sValue = rComboBox.get_active_id(); |
99 | 0 | SfxInt32Item aItem(FID_CURRENT_SHEET_VIEW, sValue.toInt32()); |
100 | 0 | pDispatcher->ExecuteList(FID_CURRENT_SHEET_VIEW, SfxCallMode::RECORD, { &aItem }); |
101 | |
|
102 | 0 | pViewFrame->GetWindow().GrabFocus(); |
103 | 0 | } |
104 | | |
105 | 0 | IMPL_LINK(SheetViewBox, KeyInputHdl, const KeyEvent&, rKEvt, bool) { return ChildKeyInput(rKEvt); } |
106 | | |
107 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |