1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
*/
#include <svx/ClassificationEditView.hxx>
#include <svx/ClassificationField.hxx>
#include <vcl/svapp.hxx>
#include <vcl/settings.hxx>
#include <svl/itemset.hxx>
#include <editeng/wghtitem.hxx>
#include <editeng/eeitem.hxx>
extern "C" SAL_DLLPUBLIC_EXPORT void makeClassificationEditView(VclPtr<vcl::Window> & rRet, VclPtr<vcl::Window> & pParent, VclBuilder::stringmap &)
{
rRet = VclPtr<svx::ClassificationEditView>::Create(pParent, WB_BORDER|WB_TABSTOP);
}
namespace svx {
ClassificationEditEngine::ClassificationEditEngine(SfxItemPool* pItemPool)
: EditEngine(pItemPool)
{}
OUString ClassificationEditEngine::CalcFieldValue(const SvxFieldItem& rField, sal_Int32 /*nPara*/,
sal_Int32 /*nPos*/, boost::optional<Color>& /*rTxtColor*/, boost::optional<Color>& /*rFldColor*/)
{
OUString aString;
const ClassificationField* pClassificationField = dynamic_cast<const ClassificationField*>(rField.GetField());
if (pClassificationField)
aString = pClassificationField->msDescription;
else
aString = "Unknown";
return aString;
}
ClassificationEditView::ClassificationEditView(vcl::Window* pParent, WinBits nBits)
: Control(pParent, nBits)
{
EnableRTL(false);
const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
Color aBgColor = rStyleSettings.GetWindowColor();
float fScaleFactor = GetDPIScaleFactor();
set_width_request(500 * fScaleFactor);
set_height_request(100 * fScaleFactor);
SetMapMode(MapMode(MapUnit::MapTwip));
SetPointer(PointerStyle::Text);
SetBackground(aBgColor);
Size aOutputSize(GetOutputSize());
Size aSize(aOutputSize);
aSize.setHeight( aSize.Height() * 4 );
pEdEngine.reset(new ClassificationEditEngine(EditEngine::CreatePool()));
pEdEngine->SetPaperSize( aSize );
pEdEngine->SetRefDevice( this );
pEdEngine->SetControlWord(pEdEngine->GetControlWord() | EEControlBits::MARKFIELDS);
pEdView.reset(new EditView(pEdEngine.get(), this));
pEdView->SetOutputArea(tools::Rectangle(Point(0,0), aOutputSize));
pEdView->SetBackgroundColor(aBgColor);
pEdEngine->InsertView(pEdView.get());
}
ClassificationEditView::~ClassificationEditView()
{
disposeOnce();
}
void ClassificationEditView::Resize()
{
Size aOutputSize(GetOutputSize());
Size aSize(aOutputSize);
aSize.setHeight( aSize.Height() * 4 );
pEdEngine->SetPaperSize(aSize);
pEdView->SetOutputArea(tools::Rectangle(Point(0,0), aOutputSize));
Control::Resize();
}
void ClassificationEditView::InsertField(const SvxFieldItem& rFieldItem)
{
pEdView->InsertField(rFieldItem);
pEdView->Invalidate();
}
void ClassificationEditView::InvertSelectionWeight()
{
ESelection aSelection = pEdView->GetSelection();
for (sal_Int32 nParagraph = aSelection.nStartPara; nParagraph <= aSelection.nEndPara; ++nParagraph)
{
FontWeight eFontWeight = WEIGHT_BOLD;
std::unique_ptr<SfxItemSet> pSet(new SfxItemSet(pEdEngine->GetParaAttribs(nParagraph)));
if (const SfxPoolItem* pItem = pSet->GetItem(EE_CHAR_WEIGHT, false))
{
const SvxWeightItem* pWeightItem = dynamic_cast<const SvxWeightItem*>(pItem);
if (pWeightItem && pWeightItem->GetWeight() == WEIGHT_BOLD)
eFontWeight = WEIGHT_NORMAL;
}
SvxWeightItem aWeight(eFontWeight, EE_CHAR_WEIGHT);
pSet->Put(aWeight);
pEdEngine->SetParaAttribs(nParagraph, *pSet);
}
pEdView->Invalidate();
}
void ClassificationEditView::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect)
{
const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
Color aBgColor = rStyleSettings.GetWindowColor();
pEdView->SetBackgroundColor(aBgColor);
SetBackground(aBgColor);
Control::Paint(rRenderContext, rRect);
pEdView->Paint(rRect);
if (HasFocus())
pEdView->ShowCursor();
}
void ClassificationEditView::MouseMove(const MouseEvent& rMEvt)
{
pEdView->MouseMove(rMEvt);
}
void ClassificationEditView::MouseButtonDown(const MouseEvent& rMEvt)
{
if (!HasFocus())
GrabFocus();
pEdView->MouseButtonDown(rMEvt);
}
void ClassificationEditView::MouseButtonUp(const MouseEvent& rMEvt)
{
pEdView->MouseButtonUp(rMEvt);
}
void ClassificationEditView::KeyInput(const KeyEvent& rKEvt)
{
sal_uInt16 nKey = rKEvt.GetKeyCode().GetModifier() + rKEvt.GetKeyCode().GetCode();
if (nKey == KEY_TAB || nKey == KEY_TAB + KEY_SHIFT)
{
Control::KeyInput( rKEvt );
}
else if (!pEdView->PostKeyEvent(rKEvt))
{
Control::KeyInput(rKEvt);
}
}
void ClassificationEditView::Command(const CommandEvent& rCEvt)
{
pEdView->Command(rCEvt);
}
void ClassificationEditView::GetFocus()
{
pEdView->ShowCursor();
Control::GetFocus();
}
} // end sfx2
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|