crashtesting: assert on reimport of docx export of ooo102874-2.doc
[LibreOffice.git] / svx / source / sidebar / text / TextPropertyPanel.cxx
blob664772dbca0b32017df7aaeada6e22598be66d18
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 "TextPropertyPanel.hxx"
22 #include <com/sun/star/lang/IllegalArgumentException.hpp>
23 #include <comphelper/lok.hxx>
24 #include <sfx2/viewsh.hxx>
26 using namespace css;
28 namespace svx::sidebar {
30 std::unique_ptr<PanelLayout> TextPropertyPanel::Create (
31 weld::Widget* pParent,
32 const css::uno::Reference<css::frame::XFrame>& rxFrame)
34 if (pParent == nullptr)
35 throw lang::IllegalArgumentException(u"no parent Window given to TextPropertyPanel::Create"_ustr, nullptr, 0);
36 if ( ! rxFrame.is())
37 throw lang::IllegalArgumentException(u"no XFrame given to TextPropertyPanel::Create"_ustr, nullptr, 1);
39 return std::make_unique<TextPropertyPanel>(pParent, rxFrame);
42 TextPropertyPanel::TextPropertyPanel(weld::Widget* pParent, const css::uno::Reference<css::frame::XFrame>& rxFrame)
43 : PanelLayout(pParent, u"SidebarTextPanel"_ustr, u"svx/ui/sidebartextpanel.ui"_ustr)
44 , mxFont(m_xBuilder->weld_toolbar(u"font"_ustr))
45 , mxFontDispatch(new ToolbarUnoDispatcher(*mxFont, *m_xBuilder, rxFrame))
46 , mxFontHeight(m_xBuilder->weld_toolbar(u"fontheight"_ustr))
47 , mxFontHeightDispatch(new ToolbarUnoDispatcher(*mxFontHeight, *m_xBuilder, rxFrame))
48 , mxFontEffects(m_xBuilder->weld_toolbar(u"fonteffects"_ustr))
49 , mxFontEffectsDispatch(new ToolbarUnoDispatcher(*mxFontEffects, *m_xBuilder, rxFrame))
50 , mxFontAdjust(m_xBuilder->weld_toolbar(u"fontadjust"_ustr))
51 , mxFontAdjustDispatch(new ToolbarUnoDispatcher(*mxFontAdjust, *m_xBuilder, rxFrame))
52 , mxToolBoxFontColor(m_xBuilder->weld_toolbar(u"colorbar"_ustr))
53 , mxToolBoxFontColorDispatch(new ToolbarUnoDispatcher(*mxToolBoxFontColor, *m_xBuilder, rxFrame))
54 , mxToolBoxBackgroundColor(m_xBuilder->weld_toolbar(u"colorbar_background"_ustr))
55 , mxToolBoxBackgroundColorDispatch(new ToolbarUnoDispatcher(*mxToolBoxBackgroundColor, *m_xBuilder, rxFrame))
56 , mxResetBar(m_xBuilder->weld_toolbar(u"resetattr"_ustr))
57 , mxResetBarDispatch(new ToolbarUnoDispatcher(*mxResetBar, *m_xBuilder, rxFrame))
58 , mxDefaultBar(m_xBuilder->weld_toolbar(u"defaultattr"_ustr))
59 , mxDefaultBarDispatch(new ToolbarUnoDispatcher(*mxDefaultBar, *m_xBuilder, rxFrame))
60 , mxHyphenationBar(m_xBuilder->weld_toolbar(u"hyphenation"_ustr))
61 , mxHyphenationBarDispatch(new ToolbarUnoDispatcher(*mxHyphenationBar, *m_xBuilder, rxFrame))
62 , mxPositionBar(m_xBuilder->weld_toolbar(u"position"_ustr))
63 , mxPositionBarDispatch(new ToolbarUnoDispatcher(*mxPositionBar, *m_xBuilder, rxFrame))
64 , mxSpacingBar(m_xBuilder->weld_toolbar(u"spacingbar"_ustr))
65 , mxSpacingBarDispatch(new ToolbarUnoDispatcher(*mxSpacingBar, *m_xBuilder, rxFrame))
67 bool isMobilePhone = false;
68 const SfxViewShell* pViewShell = SfxViewShell::Current();
69 if (comphelper::LibreOfficeKit::isActive() &&
70 pViewShell && pViewShell->isLOKMobilePhone())
71 isMobilePhone = true;
72 mxSpacingBar->set_visible(!isMobilePhone);
75 TextPropertyPanel::~TextPropertyPanel()
77 mxResetBarDispatch.reset();
78 mxDefaultBarDispatch.reset();
79 mxHyphenationBarDispatch.reset();
80 mxPositionBarDispatch.reset();
81 mxSpacingBarDispatch.reset();
82 mxToolBoxFontColorDispatch.reset();
83 mxToolBoxBackgroundColorDispatch.reset();
84 mxFontAdjustDispatch.reset();
85 mxFontEffectsDispatch.reset();
86 mxFontHeightDispatch.reset();
87 mxFontDispatch.reset();
89 mxResetBar.reset();
90 mxDefaultBar.reset();
91 mxHyphenationBar.reset();
92 mxPositionBar.reset();
93 mxSpacingBar.reset();
94 mxToolBoxFontColor.reset();
95 mxToolBoxBackgroundColor.reset();
96 mxFontAdjust.reset();
97 mxFontEffects.reset();
98 mxFontHeight.reset();
99 mxFont.reset();
102 void TextPropertyPanel::HandleContextChange (
103 const vcl::EnumContext& rContext)
105 if (maContext == rContext)
106 return;
108 maContext = rContext;
110 bool bWriterText = false;
111 bool bDrawText = false;
112 bool bCalcText = false;
114 switch (maContext.GetCombinedContext_DI())
116 case CombinedEnumContext(Application::Calc, Context::DrawText):
117 case CombinedEnumContext(Application::WriterVariants, Context::DrawText):
118 case CombinedEnumContext(Application::WriterVariants, Context::Annotation):
119 case CombinedEnumContext(Application::DrawImpress, Context::DrawText):
120 case CombinedEnumContext(Application::DrawImpress, Context::Text):
121 case CombinedEnumContext(Application::DrawImpress, Context::Table):
122 case CombinedEnumContext(Application::DrawImpress, Context::OutlineText):
123 case CombinedEnumContext(Application::DrawImpress, Context::Draw):
124 case CombinedEnumContext(Application::DrawImpress, Context::TextObject):
125 case CombinedEnumContext(Application::DrawImpress, Context::Graphic):
126 bDrawText = true;
127 break;
129 case CombinedEnumContext(Application::WriterVariants, Context::Text):
130 case CombinedEnumContext(Application::WriterVariants, Context::Table):
131 bWriterText = true;
132 break;
134 case CombinedEnumContext(Application::Calc, Context::Text):
135 case CombinedEnumContext(Application::Calc, Context::Table):
136 case CombinedEnumContext(Application::Calc, Context::Cell):
137 case CombinedEnumContext(Application::Calc, Context::EditCell):
138 case CombinedEnumContext(Application::Calc, Context::Grid):
139 bCalcText = true;
140 break;
142 default:
143 break;
146 mxToolBoxBackgroundColor->set_visible(bWriterText || bDrawText);
147 mxResetBar->set_visible(bWriterText || bCalcText);
148 mxDefaultBar->set_visible(bDrawText);
149 mxHyphenationBar->set_visible(bWriterText);
150 mxSpacingBar->set_item_visible(".uno:NoBreak", bWriterText);
153 } // end of namespace svx::sidebar
155 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */