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 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
|
/* -*- 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/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include "TextPropertyPanel.hrc"
#include "TextPropertyPanel.hxx"
#include <editeng/kernitem.hxx>
#include <editeng/udlnitem.hxx>
#include <rtl/ref.hxx>
#include <sfx2/dispatch.hxx>
#include <svtools/unitconv.hxx>
#include <vcl/toolbox.hxx>
#include "TextCharacterSpacingControl.hxx"
#include "TextCharacterSpacingPopup.hxx"
#include "TextUnderlineControl.hxx"
#include "TextUnderlinePopup.hxx"
#include <svx/sidebar/PopupContainer.hxx>
#include <boost/bind.hpp>
using namespace css;
using namespace cssu;
const char UNO_SPACING[] = ".uno:Spacing";
const char UNO_UNDERLINE[] = ".uno:Underline";
namespace svx { namespace sidebar {
PopupControl* TextPropertyPanel::CreateCharacterSpacingControl (PopupContainer* pParent)
{
return new TextCharacterSpacingControl(pParent, *this, mpBindings);
}
PopupControl* TextPropertyPanel::CreateUnderlinePopupControl (PopupContainer* pParent)
{
return new TextUnderlineControl(pParent, *this, mpBindings);
}
long TextPropertyPanel::GetSelFontSize()
{
long nH = 240;
SfxMapUnit eUnit = maSpacingControl.GetCoreMetric();
if (mpHeightItem)
nH = LogicToLogic( mpHeightItem->GetHeight(), (MapUnit)eUnit, MAP_TWIP );
return nH;
}
TextPropertyPanel* TextPropertyPanel::Create (
Window* pParent,
const cssu::Reference<css::frame::XFrame>& rxFrame,
SfxBindings* pBindings,
const ::sfx2::sidebar::EnumContext& rContext)
{
if (pParent == NULL)
throw lang::IllegalArgumentException("no parent Window given to TextPropertyPanel::Create", NULL, 0);
if ( ! rxFrame.is())
throw lang::IllegalArgumentException("no XFrame given to TextPropertyPanel::Create", NULL, 1);
if (pBindings == NULL)
throw lang::IllegalArgumentException("no SfxBindings given to TextPropertyPanel::Create", NULL, 2);
return new TextPropertyPanel(
pParent,
rxFrame,
pBindings,
rContext);
}
::sfx2::sidebar::ControllerItem& TextPropertyPanel::GetSpaceController()
{
return maSpacingControl;
}
TextPropertyPanel::TextPropertyPanel ( Window* pParent, const cssu::Reference<css::frame::XFrame>& rxFrame, SfxBindings* pBindings, const ::sfx2::sidebar::EnumContext& /*rContext*/ )
: PanelLayout(pParent, "SidebarTextPanel", "svx/ui/sidebartextpanel.ui", rxFrame),
maFontSizeControl (SID_ATTR_CHAR_FONTHEIGHT, *pBindings, *this, OUString("FontHeight"), rxFrame),
maUnderlineControl (SID_ATTR_CHAR_UNDERLINE, *pBindings, *this, OUString("Underline"), rxFrame),
maSpacingControl (SID_ATTR_CHAR_KERNING, *pBindings, *this, OUString("Spacing"), rxFrame),
maCharSpacePopup(this, ::boost::bind(&TextPropertyPanel::CreateCharacterSpacingControl, this, _1)),
maUnderlinePopup(this, ::boost::bind(&TextPropertyPanel::CreateUnderlinePopupControl, this, _1)),
maContext(),
mpBindings(pBindings)
{
get(mpToolBoxFont, "fonteffects");
get(mpToolBoxIncDec, "fontadjust");
get(mpToolBoxSpacing, "spacingbar");
get(mpToolBoxFontColorSw, "colorbar");
get(mpToolBoxFontColor, "colorsingle");
//toolbox
SetupToolboxItems();
InitToolBoxFont();
InitToolBoxSpacing();
//init state
mpHeightItem = NULL;
meUnderline = UNDERLINE_NONE;
meUnderlineColor = COL_AUTO;
mbKernAvailable = true;
mbKernLBAvailable = true;
mlKerning = 0;
}
TextPropertyPanel::~TextPropertyPanel (void)
{
}
void TextPropertyPanel::HandleContextChange (
const ::sfx2::sidebar::EnumContext aContext)
{
if (maContext == aContext)
return;
maContext = aContext;
mpToolBoxIncDec->Show(maContext.GetApplication_DI() != sfx2::sidebar::EnumContext::Application_Calc);
bool bWriterText = false;
switch (maContext.GetCombinedContext_DI())
{
case CombinedEnumContext(Application_Calc, Context_Cell):
case CombinedEnumContext(Application_Calc, Context_Pivot):
mpToolBoxSpacing->Disable();
break;
case CombinedEnumContext(Application_Calc, Context_EditCell):
case CombinedEnumContext(Application_Calc, Context_DrawText):
case CombinedEnumContext(Application_WriterVariants, Context_DrawText):
case CombinedEnumContext(Application_WriterVariants, Context_Annotation):
case CombinedEnumContext(Application_DrawImpress, Context_DrawText):
case CombinedEnumContext(Application_DrawImpress, Context_Text):
case CombinedEnumContext(Application_DrawImpress, Context_Table):
case CombinedEnumContext(Application_DrawImpress, Context_OutlineText):
case CombinedEnumContext(Application_DrawImpress, Context_Draw):
case CombinedEnumContext(Application_DrawImpress, Context_TextObject):
case CombinedEnumContext(Application_DrawImpress, Context_Graphic):
mpToolBoxSpacing->Enable();
break;
case CombinedEnumContext(Application_WriterVariants, Context_Text):
case CombinedEnumContext(Application_WriterVariants, Context_Table):
mpToolBoxSpacing->Enable();
bWriterText = true;
break;
default:
break;
}
mpToolBoxFontColor->Show(!bWriterText);
mpToolBoxFontColorSw->Show(bWriterText);
}
void TextPropertyPanel::DataChanged (const DataChangedEvent& /*rEvent*/)
{
SetupToolboxItems();
}
void TextPropertyPanel::EndSpacingPopupMode (void)
{
maCharSpacePopup.Hide();
}
void TextPropertyPanel::EndUnderlinePopupMode (void)
{
maUnderlinePopup.Hide();
}
void TextPropertyPanel::InitToolBoxFont()
{
Link aLink = LINK(this, TextPropertyPanel, UnderlineClickHdl);
mpToolBoxFont->SetDropdownClickHdl(aLink);
}
void TextPropertyPanel::InitToolBoxSpacing()
{
const sal_uInt16 nId = mpToolBoxSpacing->GetItemId(UNO_SPACING);
mpToolBoxSpacing->SetItemBits(nId, mpToolBoxSpacing->GetItemBits(nId) | TIB_DROPDOWNONLY);
Link aLink = LINK(this, TextPropertyPanel, SpacingClickHdl);
mpToolBoxSpacing->SetDropdownClickHdl ( aLink );
mpToolBoxSpacing->SetSelectHdl( aLink );
}
void TextPropertyPanel::SetupToolboxItems (void)
{
maUnderlineControl.SetupToolBoxItem(*mpToolBoxFont, mpToolBoxFont->GetItemId(UNO_UNDERLINE));
maSpacingControl.SetupToolBoxItem(*mpToolBoxSpacing, mpToolBoxSpacing->GetItemId(UNO_SPACING));
}
IMPL_LINK(TextPropertyPanel, UnderlineClickHdl, ToolBox*, pToolBox)
{
const sal_uInt16 nId = pToolBox->GetCurItemId();
const OUString aCommand(pToolBox->GetItemCommand(nId));
if (aCommand == UNO_UNDERLINE)
{
pToolBox->SetItemDown( nId, true );
maUnderlinePopup.Rearrange(meUnderline);
maUnderlinePopup.Show(*pToolBox);
}
return 0L;
}
IMPL_LINK(TextPropertyPanel, SpacingClickHdl, ToolBox*, pToolBox)
{
const sal_uInt16 nId = pToolBox->GetCurItemId();
const OUString aCommand(pToolBox->GetItemCommand(nId));
if (aCommand == UNO_SPACING)
{
pToolBox->SetItemDown( nId, true );
maCharSpacePopup.Rearrange(mbKernLBAvailable,mbKernAvailable,mlKerning);
maCharSpacePopup.Show(*pToolBox);
}
return 0L;
}
void TextPropertyPanel::NotifyItemUpdate (
const sal_uInt16 nSID,
const SfxItemState eState,
const SfxPoolItem* pState,
const bool bIsEnabled)
{
switch(nSID)
{
case SID_ATTR_CHAR_FONTHEIGHT:
{
if ( eState >= SFX_ITEM_DEFAULT && pState->ISA(SvxFontHeightItem) )
mpHeightItem = (SvxFontHeightItem*)pState;
else
mpHeightItem = NULL;
}
break;
case SID_ATTR_CHAR_UNDERLINE:
{
if( eState >= SFX_ITEM_DEFAULT && pState->ISA(SvxUnderlineItem) )
{
const SvxUnderlineItem* pItem = (const SvxUnderlineItem*)pState;
meUnderline = (FontUnderline)pItem->GetValue();
meUnderlineColor = pItem->GetColor();
}
else
meUnderline = UNDERLINE_NONE;
}
break;
case SID_ATTR_CHAR_KERNING:
{
if ( SFX_ITEM_AVAILABLE == eState )
{
mbKernLBAvailable = true;
if(pState->ISA(SvxKerningItem))
{
const SvxKerningItem* pKerningItem = (const SvxKerningItem*)pState;
mlKerning = (long)pKerningItem->GetValue();
mbKernAvailable = true;
}
else
{
mlKerning = 0;
mbKernAvailable =false;
}
}
else if (SFX_ITEM_DISABLED == eState)
{
mbKernLBAvailable = false;
mbKernAvailable = false;
mlKerning = 0;
}
else
{
mbKernLBAvailable = true;
mbKernAvailable = false;
mlKerning = 0;
}
mpToolBoxSpacing->Enable(bIsEnabled);
}
break;
}
}
Color& TextPropertyPanel::GetUnderlineColor()
{
return meUnderlineColor;
}
} } // end of namespace svx::sidebar
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|