bump product version to 4.1.6.2
[LibreOffice.git] / svx / source / sidebar / line / LineWidthControl.cxx
blob66c0019f655ea167dc409a5a04f5e90a3a1392a2
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 #include "LineWidthControl.hxx"
19 #include "LinePropertyPanel.hrc"
20 #include "LinePropertyPanel.hxx"
22 #include <svx/dialogs.hrc>
23 #include <svx/dialmgr.hxx>
24 #include <sfx2/sidebar/ResourceDefinitions.hrc>
25 #include <comphelper/processfactory.hxx>
26 #include <vcl/svapp.hxx>
27 #include <unotools/viewoptions.hxx>
28 #include <svx/xlnwtit.hxx>
29 #include <sfx2/bindings.hxx>
30 #include <sfx2/dispatch.hxx>
31 #include "svx/sidebar/PopupContainer.hxx"
34 namespace svx { namespace sidebar {
36 LineWidthControl::LineWidthControl (
37 Window* pParent,
38 LinePropertyPanel& rPanel)
39 : svx::sidebar::PopupControl(pParent,SVX_RES(RID_POPUPPANEL_LINEPAGE_WIDTH)),
40 mrLinePropertyPanel(rPanel),
41 mpBindings(NULL),
42 maVSWidth( this, SVX_RES(VS_WIDTH)),
43 maFTCus( this, SVX_RES(FT_CUSTOME)),
44 maFTWidth( this, SVX_RES(FT_LINE_WIDTH)),
45 maMFWidth( this, SVX_RES(MF_WIDTH)),
46 meMapUnit(SFX_MAPUNIT_TWIP),
47 rStr(NULL),
48 mstrPT(SVX_RES(STR_PT)),
49 mnCustomWidth(0),
50 mbCustom(false),
51 mbColseByEdit(false),
52 mnTmpCusomWidth(0),
53 mbVSFocus(true),
54 maIMGCus(SVX_RES(IMG_WIDTH_CUSTOM)),
55 maIMGCusGray(SVX_RES(IMG_WIDTH_CUSTOM_GRAY))
57 Initialize();
58 FreeResource();
59 mpBindings = mrLinePropertyPanel.GetBindings();
65 LineWidthControl::~LineWidthControl (void)
67 delete[] rStr;
73 void LineWidthControl::Paint(const Rectangle& rect)
75 svx::sidebar::PopupControl::Paint(rect);
77 Color aOldLineColor = GetLineColor();
78 Color aOldFillColor = GetFillColor();
80 Point aPos( LogicToPixel( Point( CUSTOM_X, CUSTOM_Y), MAP_APPFONT ));
81 Size aSize( LogicToPixel( Size( CUSTOM_W, CUSTOM_H ), MAP_APPFONT ));
82 Rectangle aRect( aPos, aSize );
83 aRect.Left() -= 1;
84 aRect.Top() -= 1;
85 aRect.Right() += 1;
86 aRect.Bottom() += 1;
88 Color aLineColor(189,201,219);
89 if(!GetSettings().GetStyleSettings().GetHighContrastMode())
90 SetLineColor(aLineColor);
91 else
92 SetLineColor(GetSettings().GetStyleSettings().GetShadowColor());
93 SetFillColor(COL_TRANSPARENT);
94 DrawRect(aRect);
96 SetLineColor(aOldLineColor);
97 SetFillColor(aOldFillColor);
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());
113 else
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 XubString[9];
134 //modify,
135 rStr[0] = String("05", 2, RTL_TEXTENCODING_ASCII_US);
136 rStr[1] = String("08", 2, RTL_TEXTENCODING_ASCII_US);
137 rStr[2] = String("10", 2, RTL_TEXTENCODING_ASCII_US);
138 rStr[3] = String("15", 2, RTL_TEXTENCODING_ASCII_US);
139 rStr[4] = String("23", 2, RTL_TEXTENCODING_ASCII_US);
140 rStr[5] = String("30", 2, RTL_TEXTENCODING_ASCII_US);
141 rStr[6] = String("45", 2, RTL_TEXTENCODING_ASCII_US);
142 rStr[7] = String("60", 2, RTL_TEXTENCODING_ASCII_US);
143 rStr[8] = String( SVX_RES(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].Insert(cSep, 1);//Modify
151 rStr[i].Append(mstrPT);
153 //end
155 for(sal_uInt16 i = 1 ; i <= 9 ; i++)
157 maVSWidth.InsertItem(i);
158 maVSWidth.SetItemText(i, rStr[i-1]);
160 maVSWidth.SetUnit(rStr);
161 maVSWidth.SetItemData(1,(void*)5);
162 maVSWidth.SetItemData(2,(void*)8);
163 maVSWidth.SetItemData(3,(void*)10);
164 maVSWidth.SetItemData(4,(void*)15);
165 maVSWidth.SetItemData(5,(void*)23);
166 maVSWidth.SetItemData(6,(void*)30);
167 maVSWidth.SetItemData(7,(void*)45);
168 maVSWidth.SetItemData(8,(void*)60);
169 maVSWidth.SetImage(maIMGCusGray);
171 maVSWidth.SetSelItem(0);
172 Link aLink = LINK( this, LineWidthControl, VSSelectHdl ) ;
173 maVSWidth.SetSelectHdl(aLink);
174 aLink = LINK(this, LineWidthControl, MFModifyHdl);
175 maMFWidth.SetModifyHdl(aLink);
177 maVSWidth.StartSelection();
178 maVSWidth.Show();
184 void LineWidthControl::GetFocus()
186 if(!mbVSFocus)
187 maMFWidth.GrabFocus();
188 else
189 maVSWidth.GrabFocus();
195 ValueSet& LineWidthControl::GetValueSet()
197 return maVSWidth;
203 void LineWidthControl::SetWidthSelect( long lValue, bool bValuable, SfxMapUnit eMapUnit)
205 mbVSFocus = true;
206 maVSWidth.SetSelItem(0);
207 mbColseByEdit = false;
208 meMapUnit = eMapUnit;
209 SvtViewOptions aWinOpt( E_WINDOW, SIDEBAR_LINE_WIDTH_GLOBAL_VALUE );
210 if ( aWinOpt.Exists() )
212 ::com::sun::star::uno::Sequence < ::com::sun::star::beans::NamedValue > aSeq = aWinOpt.GetUserData();
213 ::rtl::OUString aTmp;
214 if ( aSeq.getLength())
215 aSeq[0].Value >>= aTmp;
217 String aWinData( aTmp );
218 mnCustomWidth = aWinData.ToInt32();
219 mbCustom = true;
220 maVSWidth.SetImage(maIMGCus);
221 maVSWidth.SetCusEnable(true);
223 String aStrTip( OUString::number( (double)mnCustomWidth / 10));
224 aStrTip.Append(mstrPT); //
225 maVSWidth.SetItemText(9, aStrTip);
227 else
229 mbCustom = false;
230 maVSWidth.SetImage(maIMGCusGray);
231 maVSWidth.SetCusEnable(false);
232 //modify
233 //String aStrTip(String(SVX_RES(STR_WIDTH_LAST_CUSTOM)));
234 //maVSWidth.SetItemText(9, aStrTip);
235 maVSWidth.SetItemText(9, rStr[8]);
238 if(bValuable)
240 sal_Int64 nVal = OutputDevice::LogicToLogic( lValue, (MapUnit)eMapUnit, MAP_100TH_MM );
241 nVal = maMFWidth.Normalize( nVal );
242 maMFWidth.SetValue( nVal, FUNIT_100TH_MM );
244 else
246 maMFWidth.SetText( String() );
249 MapUnit eOrgUnit = (MapUnit)eMapUnit;
250 MapUnit ePntUnit( MAP_TWIP );
251 lValue = LogicToLogic( lValue , eOrgUnit, ePntUnit );
253 XubString strCurrValue = maMFWidth.GetText();
254 sal_uInt16 i = 0;
255 for(; i < 8; i++)
256 if(strCurrValue == rStr[i])
258 maVSWidth.SetSelItem(i+1);
259 break;
261 if (i>=8)
263 mbVSFocus = false;
264 maVSWidth.SetSelItem(0);
266 maVSWidth.Format();
267 maVSWidth.StartSelection();
273 IMPL_LINK(LineWidthControl, VSSelectHdl, void *, pControl)
275 if(pControl == &maVSWidth)
277 sal_uInt16 iPos = maVSWidth.GetSelectItemId();
278 if(iPos >= 1 && iPos <= 8)
280 long nVal = LogicToLogic((long)(unsigned long)maVSWidth.GetItemData( iPos ) , MAP_POINT, (MapUnit)meMapUnit);
281 nVal = maMFWidth.Denormalize(nVal);
282 XLineWidthItem aWidthItem( nVal );
283 mpBindings->GetDispatcher()->Execute(SID_ATTR_LINE_WIDTH, SFX_CALLMODE_RECORD, &aWidthItem, 0L);
284 mrLinePropertyPanel.SetWidthIcon(iPos);
285 mrLinePropertyPanel.SetWidth(nVal);
286 mbColseByEdit = false;
287 mnTmpCusomWidth = 0;
289 else if(iPos == 9)
290 {//last custom
291 //modified
292 if(mbCustom)
294 long nVal = LogicToLogic(mnCustomWidth , MAP_POINT, (MapUnit)meMapUnit);
295 nVal = maMFWidth.Denormalize(nVal);
296 XLineWidthItem aWidthItem( nVal );
297 mpBindings->GetDispatcher()->Execute(SID_ATTR_LINE_WIDTH, SFX_CALLMODE_RECORD, &aWidthItem, 0L);
298 mrLinePropertyPanel.SetWidth(nVal);
299 mbColseByEdit = false;
300 mnTmpCusomWidth = 0;
302 else
304 maVSWidth.SetNoSelection(); //add , set no selection and keep the last select item
305 maVSWidth.Format();
306 Invalidate();
307 maVSWidth.StartSelection();
309 //modify end
311 if((iPos >= 1 && iPos <= 8) || (iPos == 9 && mbCustom)) //add
312 mrLinePropertyPanel.EndLineWidthPopupMode();
314 return( 0L );
320 IMPL_LINK(LineWidthControl, MFModifyHdl, void *, pControl)
322 if(pControl == &maMFWidth)
324 if(maVSWidth.GetSelItem())
326 maVSWidth.SetSelItem(0);
327 maVSWidth.Format();
328 Invalidate();
329 maVSWidth.StartSelection();
331 long nTmp = static_cast<long>(maMFWidth.GetValue());
332 long nVal = LogicToLogic( nTmp, MAP_POINT, (MapUnit)meMapUnit );
333 sal_Int32 nNewWidth = (short)maMFWidth.Denormalize( nVal );
334 XLineWidthItem aWidthItem(nNewWidth);
335 mpBindings->GetDispatcher()->Execute(SID_ATTR_LINE_WIDTH, SFX_CALLMODE_RECORD, &aWidthItem, 0L);
337 mbColseByEdit = true;
338 mnTmpCusomWidth = nTmp;
339 /*for(sal_uInt16 i = 0; i < 8; i++)
341 if(nTmp == (sal_Int32)maVSWidth.GetItemData(i))
343 mbColseByEdit = false;
344 break;
349 return( 0L );
355 bool LineWidthControl::IsCloseByEdit()
357 return mbColseByEdit;
363 long LineWidthControl::GetTmpCustomWidth()
365 return mnTmpCusomWidth;
370 } } // end of namespace svx::sidebar
372 // eof