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 .
19 #include "LineWidthControl.hxx"
20 #include "LinePropertyPanel.hrc"
21 #include "LinePropertyPanel.hxx"
23 #include <svx/dialogs.hrc>
24 #include <svx/dialmgr.hxx>
25 #include <sfx2/sidebar/ResourceDefinitions.hrc>
26 #include <comphelper/processfactory.hxx>
27 #include <vcl/svapp.hxx>
28 #include <vcl/settings.hxx>
29 #include <unotools/viewoptions.hxx>
30 #include <svx/xlnwtit.hxx>
31 #include <sfx2/bindings.hxx>
32 #include <sfx2/dispatch.hxx>
33 #include "svx/sidebar/PopupContainer.hxx"
35 namespace svx
{ namespace sidebar
{
37 LineWidthControl::LineWidthControl (
39 LinePropertyPanel
& rPanel
)
40 : svx::sidebar::PopupControl(pParent
,SVX_RES(RID_POPUPPANEL_LINEPAGE_WIDTH
)),
41 mrLinePropertyPanel(rPanel
),
43 maVSWidth(VclPtr
<LineWidthValueSet
>::Create(this, SVX_RES(VS_WIDTH
))),
44 maFTCus( VclPtr
<FixedText
>::Create(this, SVX_RES(FT_CUSTOME
))),
45 maFTWidth( VclPtr
<FixedText
>::Create(this, SVX_RES(FT_LINE_WIDTH
))),
46 maMFWidth( VclPtr
<MetricField
>::Create(this, SVX_RES(MF_WIDTH
))),
47 meMapUnit(SFX_MAPUNIT_TWIP
),
49 mstrPT(SVX_RESSTR(STR_PT
)),
55 maIMGCus(SVX_RES(IMG_WIDTH_CUSTOM
)),
56 maIMGCusGray(SVX_RES(IMG_WIDTH_CUSTOM_GRAY
))
60 mpBindings
= mrLinePropertyPanel
.GetBindings();
63 LineWidthControl::~LineWidthControl()
68 void LineWidthControl::dispose()
71 maVSWidth
.disposeAndClear();
72 maFTCus
.disposeAndClear();
73 maFTWidth
.disposeAndClear();
74 maMFWidth
.disposeAndClear();
75 svx::sidebar::PopupControl::dispose();
78 void LineWidthControl::Paint(vcl::RenderContext
& rRenderContext
, const Rectangle
& rect
)
80 svx::sidebar::PopupControl::Paint(rRenderContext
, rect
);
82 rRenderContext
.Push(PushFlags::LINECOLOR
| PushFlags::FILLCOLOR
);
84 Point
aPos(rRenderContext
.LogicToPixel(Point(CUSTOM_X
, CUSTOM_Y
), MAP_APPFONT
));
85 Size
aSize(rRenderContext
.LogicToPixel(Size(CUSTOM_W
, CUSTOM_H
), MAP_APPFONT
));
86 Rectangle
aRect(aPos
, aSize
);
92 Color
aLineColor(189, 201, 219);
93 if (!GetSettings().GetStyleSettings().GetHighContrastMode())
94 rRenderContext
.SetLineColor(aLineColor
);
96 rRenderContext
.SetLineColor(GetSettings().GetStyleSettings().GetShadowColor());
97 rRenderContext
.SetFillColor(COL_TRANSPARENT
);
98 rRenderContext
.DrawRect(aRect
);
100 rRenderContext
.Pop();
103 void LineWidthControl::Initialize()
105 maVSWidth
->SetStyle( maVSWidth
->GetStyle()| WB_3DLOOK
| WB_NO_DIRECTSELECT
);// WB_NAMEFIELD | WB_ITEMBORDER |WB_DOUBLEBORDER | WB_NONEFIELD |
106 //for high contrast wj
107 if(GetSettings().GetStyleSettings().GetHighContrastMode())
109 maVSWidth
->SetColor(GetSettings().GetStyleSettings().GetMenuColor());
110 // maBorder.SetBackground(GetSettings().GetStyleSettings().GetMenuColor());
111 maFTWidth
->SetBackground(GetSettings().GetStyleSettings().GetMenuColor());
115 maVSWidth
->SetColor(COL_WHITE
);
116 // maBorder.SetBackground(Wallpaper(COL_WHITE));
117 maFTWidth
->SetBackground(Wallpaper(COL_WHITE
));
120 sal_Int64 nFirst
= maMFWidth
->Denormalize( maMFWidth
->GetFirst( FUNIT_TWIP
) );
121 sal_Int64 nLast
= maMFWidth
->Denormalize( maMFWidth
->GetLast( FUNIT_TWIP
) );
122 sal_Int64 nMin
= maMFWidth
->Denormalize( maMFWidth
->GetMin( FUNIT_TWIP
) );
123 sal_Int64 nMax
= maMFWidth
->Denormalize( maMFWidth
->GetMax( FUNIT_TWIP
) );
124 maMFWidth
->SetSpinSize( 10 );
125 maMFWidth
->SetUnit( FUNIT_POINT
);
126 if( maMFWidth
->GetDecimalDigits() > 1 )
127 maMFWidth
->SetDecimalDigits( 1 );
128 maMFWidth
->SetFirst( maMFWidth
->Normalize( nFirst
), FUNIT_TWIP
);
129 maMFWidth
->SetLast( maMFWidth
->Normalize( nLast
), FUNIT_TWIP
);
130 maMFWidth
->SetMin( maMFWidth
->Normalize( nMin
), FUNIT_TWIP
);
131 maMFWidth
->SetMax( maMFWidth
->Normalize( nMax
), FUNIT_TWIP
);
133 rStr
= new OUString
[9];
143 rStr
[8] = SVX_RESSTR(STR_WIDTH_LAST_CUSTOM
);
145 const LocaleDataWrapper
& rLocaleWrapper( Application::GetSettings().GetLocaleDataWrapper() );
146 const sal_Unicode cSep
= rLocaleWrapper
.getNumDecimalSep()[0];
148 for(int i
= 0; i
<= 7 ; i
++)
150 rStr
[i
] = rStr
[i
].replace('.', cSep
);//Modify
156 for(sal_uInt16 i
= 1 ; i
<= 9 ; i
++)
158 maVSWidth
->InsertItem(i
);
159 maVSWidth
->SetItemText(i
, rStr
[i
-1]);
161 maVSWidth
->SetUnit(rStr
);
162 maVSWidth
->SetItemData(1, reinterpret_cast<void*>(5));
163 maVSWidth
->SetItemData(2, reinterpret_cast<void*>(8));
164 maVSWidth
->SetItemData(3, reinterpret_cast<void*>(10));
165 maVSWidth
->SetItemData(4, reinterpret_cast<void*>(15));
166 maVSWidth
->SetItemData(5, reinterpret_cast<void*>(23));
167 maVSWidth
->SetItemData(6, reinterpret_cast<void*>(30));
168 maVSWidth
->SetItemData(7, reinterpret_cast<void*>(45));
169 maVSWidth
->SetItemData(8, reinterpret_cast<void*>(60));
170 maVSWidth
->SetImage(maIMGCusGray
);
172 maVSWidth
->SetSelItem(0);
173 Link
<> aLink
= LINK( this, LineWidthControl
, VSSelectHdl
) ;
174 maVSWidth
->SetSelectHdl(aLink
);
175 aLink
= LINK(this, LineWidthControl
, MFModifyHdl
);
176 maMFWidth
->SetModifyHdl(aLink
);
178 maVSWidth
->StartSelection();
185 void LineWidthControl::GetFocus()
187 if (!mbVSFocus
&& maMFWidth
)
188 maMFWidth
->GrabFocus();
190 maVSWidth
->GrabFocus();
193 void LineWidthControl::SetWidthSelect( long lValue
, bool bValuable
, SfxMapUnit eMapUnit
)
196 maVSWidth
->SetSelItem(0);
197 mbCloseByEdit
= false;
198 meMapUnit
= eMapUnit
;
199 SvtViewOptions
aWinOpt( E_WINDOW
, SIDEBAR_LINE_WIDTH_GLOBAL_VALUE
);
200 if (aWinOpt
.Exists())
202 css::uno::Sequence
<css::beans::NamedValue
> aSeq
= aWinOpt
.GetUserData();
204 if ( aSeq
.getLength())
205 aSeq
[0].Value
>>= aTmp
;
207 OUString
aWinData( aTmp
);
208 mnCustomWidth
= aWinData
.toInt32();
210 maVSWidth
->SetImage(maIMGCus
);
211 maVSWidth
->SetCusEnable(true);
213 OUString
aStrTip( OUString::number( (double)mnCustomWidth
/ 10));
215 maVSWidth
->SetItemText(9, aStrTip
);
220 maVSWidth
->SetImage(maIMGCusGray
);
221 maVSWidth
->SetCusEnable(false);
223 //String aStrTip(String(SVX_RES(STR_WIDTH_LAST_CUSTOM)));
224 //maVSWidth->SetItemText(9, aStrTip);
225 maVSWidth
->SetItemText(9, rStr
[8]);
230 sal_Int64 nVal
= OutputDevice::LogicToLogic(lValue
, (MapUnit
) eMapUnit
, MAP_100TH_MM
);
231 nVal
= maMFWidth
->Normalize(nVal
);
232 maMFWidth
->SetValue( nVal
, FUNIT_100TH_MM
);
236 maMFWidth
->SetText( "" );
239 MapUnit eOrgUnit
= (MapUnit
)eMapUnit
;
240 MapUnit
ePntUnit( MAP_TWIP
);
241 lValue
= LogicToLogic( lValue
, eOrgUnit
, ePntUnit
);
243 OUString strCurrValue
= maMFWidth
->GetText();
247 if(strCurrValue
== rStr
[i
])
249 maVSWidth
->SetSelItem(i
+1);
257 maVSWidth
->SetSelItem(0);
259 maVSWidth
->SetFormat();
260 maVSWidth
->Invalidate();
261 maVSWidth
->StartSelection();
264 IMPL_LINK(LineWidthControl
, VSSelectHdl
, void *, pControl
)
266 if (pControl
== maVSWidth
.get())
268 sal_uInt16 iPos
= maVSWidth
->GetSelectItemId();
269 if (iPos
>= 1 && iPos
<= 8)
271 sal_IntPtr nVal
= LogicToLogic(reinterpret_cast<sal_IntPtr
>(maVSWidth
->GetItemData( iPos
)), MAP_POINT
, (MapUnit
)meMapUnit
);
272 nVal
= maMFWidth
->Denormalize(nVal
);
273 XLineWidthItem
aWidthItem( nVal
);
274 mpBindings
->GetDispatcher()->Execute(SID_ATTR_LINE_WIDTH
, SfxCallMode::RECORD
, &aWidthItem
, 0L);
275 mrLinePropertyPanel
.SetWidthIcon(iPos
);
276 mrLinePropertyPanel
.SetWidth(nVal
);
277 mbCloseByEdit
= false;
278 mnTmpCustomWidth
= 0;
285 long nVal
= LogicToLogic(mnCustomWidth
, MAP_POINT
, (MapUnit
)meMapUnit
);
286 nVal
= maMFWidth
->Denormalize(nVal
);
287 XLineWidthItem
aWidthItem( nVal
);
288 mpBindings
->GetDispatcher()->Execute(SID_ATTR_LINE_WIDTH
, SfxCallMode::RECORD
, &aWidthItem
, 0L);
289 mrLinePropertyPanel
.SetWidth(nVal
);
290 mbCloseByEdit
= false;
291 mnTmpCustomWidth
= 0;
295 maVSWidth
->SetNoSelection(); //add , set no selection and keep the last select item
296 maVSWidth
->SetFormat();
297 maVSWidth
->Invalidate();
299 maVSWidth
->StartSelection();
303 if ((iPos
>= 1 && iPos
<= 8) || (iPos
== 9 && mbCustom
)) //add
304 mrLinePropertyPanel
.EndLineWidthPopupMode();
309 IMPL_LINK(LineWidthControl
, MFModifyHdl
, void *, pControl
)
311 if (pControl
== maMFWidth
.get())
313 if(maVSWidth
->GetSelItem())
315 maVSWidth
->SetSelItem(0);
316 maVSWidth
->SetFormat();
317 maVSWidth
->Invalidate();
319 maVSWidth
->StartSelection();
321 long nTmp
= static_cast<long>(maMFWidth
->GetValue());
322 long nVal
= LogicToLogic( nTmp
, MAP_POINT
, (MapUnit
)meMapUnit
);
323 sal_Int32 nNewWidth
= (short)maMFWidth
->Denormalize( nVal
);
324 XLineWidthItem
aWidthItem(nNewWidth
);
325 mpBindings
->GetDispatcher()->Execute(SID_ATTR_LINE_WIDTH
, SfxCallMode::RECORD
, &aWidthItem
, 0L);
327 mbCloseByEdit
= true;
328 mnTmpCustomWidth
= nTmp
;
333 } } // end of namespace svx::sidebar
335 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */