Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 : #include "LineWidthControl.hxx"
20 : #include "LinePropertyPanel.hrc"
21 : #include "LinePropertyPanel.hxx"
22 :
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"
34 :
35 : namespace svx { namespace sidebar {
36 :
37 0 : LineWidthControl::LineWidthControl (
38 : vcl::Window* pParent,
39 : LinePropertyPanel& rPanel)
40 0 : : svx::sidebar::PopupControl(pParent,SVX_RES(RID_POPUPPANEL_LINEPAGE_WIDTH)),
41 : mrLinePropertyPanel(rPanel),
42 : mpBindings(NULL),
43 0 : maVSWidth(VclPtr<LineWidthValueSet>::Create(this, SVX_RES(VS_WIDTH))),
44 0 : maFTCus( VclPtr<FixedText>::Create(this, SVX_RES(FT_CUSTOME))),
45 0 : maFTWidth( VclPtr<FixedText>::Create(this, SVX_RES(FT_LINE_WIDTH))),
46 0 : maMFWidth( VclPtr<MetricField>::Create(this, SVX_RES(MF_WIDTH))),
47 : meMapUnit(SFX_MAPUNIT_TWIP),
48 : rStr(NULL),
49 0 : mstrPT(SVX_RESSTR(STR_PT)),
50 : mnCustomWidth(0),
51 : mbCustom(false),
52 : mbCloseByEdit(false),
53 : mnTmpCustomWidth(0),
54 : mbVSFocus(true),
55 0 : maIMGCus(SVX_RES(IMG_WIDTH_CUSTOM)),
56 0 : maIMGCusGray(SVX_RES(IMG_WIDTH_CUSTOM_GRAY))
57 : {
58 0 : Initialize();
59 0 : FreeResource();
60 0 : mpBindings = mrLinePropertyPanel.GetBindings();
61 0 : }
62 :
63 0 : LineWidthControl::~LineWidthControl()
64 : {
65 0 : disposeOnce();
66 0 : }
67 :
68 0 : void LineWidthControl::dispose()
69 : {
70 0 : delete[] rStr;
71 0 : maVSWidth.disposeAndClear();
72 0 : maFTCus.disposeAndClear();
73 0 : maFTWidth.disposeAndClear();
74 0 : maMFWidth.disposeAndClear();
75 0 : svx::sidebar::PopupControl::dispose();
76 0 : }
77 :
78 0 : void LineWidthControl::Paint(vcl::RenderContext& rRenderContext, const Rectangle& rect)
79 : {
80 0 : svx::sidebar::PopupControl::Paint(rRenderContext, rect);
81 :
82 0 : rRenderContext.Push(PushFlags::LINECOLOR | PushFlags::FILLCOLOR);
83 :
84 0 : Point aPos(rRenderContext.LogicToPixel(Point(CUSTOM_X, CUSTOM_Y), MAP_APPFONT));
85 0 : Size aSize(rRenderContext.LogicToPixel(Size(CUSTOM_W, CUSTOM_H), MAP_APPFONT));
86 0 : Rectangle aRect(aPos, aSize);
87 0 : aRect.Left() -= 1;
88 0 : aRect.Top() -= 1;
89 0 : aRect.Right() += 1;
90 0 : aRect.Bottom() += 1;
91 :
92 0 : Color aLineColor(189, 201, 219);
93 0 : if (!GetSettings().GetStyleSettings().GetHighContrastMode())
94 0 : rRenderContext.SetLineColor(aLineColor);
95 : else
96 0 : rRenderContext.SetLineColor(GetSettings().GetStyleSettings().GetShadowColor());
97 0 : rRenderContext.SetFillColor(COL_TRANSPARENT);
98 0 : rRenderContext.DrawRect(aRect);
99 :
100 0 : rRenderContext.Pop();
101 0 : }
102 :
103 0 : void LineWidthControl::Initialize()
104 : {
105 0 : maVSWidth->SetStyle( maVSWidth->GetStyle()| WB_3DLOOK | WB_NO_DIRECTSELECT );// WB_NAMEFIELD | WB_ITEMBORDER |WB_DOUBLEBORDER | WB_NONEFIELD |
106 : //for high contrast wj
107 0 : if(GetSettings().GetStyleSettings().GetHighContrastMode())
108 : {
109 0 : maVSWidth->SetColor(GetSettings().GetStyleSettings().GetMenuColor());
110 : // maBorder.SetBackground(GetSettings().GetStyleSettings().GetMenuColor());
111 0 : maFTWidth->SetBackground(GetSettings().GetStyleSettings().GetMenuColor());
112 : }
113 : else
114 : {
115 0 : maVSWidth->SetColor(COL_WHITE);
116 : // maBorder.SetBackground(Wallpaper(COL_WHITE));
117 0 : maFTWidth->SetBackground(Wallpaper(COL_WHITE));
118 : }
119 :
120 0 : sal_Int64 nFirst= maMFWidth->Denormalize( maMFWidth->GetFirst( FUNIT_TWIP ) );
121 0 : sal_Int64 nLast = maMFWidth->Denormalize( maMFWidth->GetLast( FUNIT_TWIP ) );
122 0 : sal_Int64 nMin = maMFWidth->Denormalize( maMFWidth->GetMin( FUNIT_TWIP ) );
123 0 : sal_Int64 nMax = maMFWidth->Denormalize( maMFWidth->GetMax( FUNIT_TWIP ) );
124 0 : maMFWidth->SetSpinSize( 10 );
125 0 : maMFWidth->SetUnit( FUNIT_POINT );
126 0 : if( maMFWidth->GetDecimalDigits() > 1 )
127 0 : maMFWidth->SetDecimalDigits( 1 );
128 0 : maMFWidth->SetFirst( maMFWidth->Normalize( nFirst ), FUNIT_TWIP );
129 0 : maMFWidth->SetLast( maMFWidth->Normalize( nLast ), FUNIT_TWIP );
130 0 : maMFWidth->SetMin( maMFWidth->Normalize( nMin ), FUNIT_TWIP );
131 0 : maMFWidth->SetMax( maMFWidth->Normalize( nMax ), FUNIT_TWIP );
132 :
133 0 : rStr = new OUString[9];
134 : //modify,
135 0 : rStr[0] = "0.5";
136 0 : rStr[1] = "0.8";
137 0 : rStr[2] = "1.0";
138 0 : rStr[3] = "1.5";
139 0 : rStr[4] = "2.3";
140 0 : rStr[5] = "3.0";
141 0 : rStr[6] = "4.5";
142 0 : rStr[7] = "6.0";
143 0 : rStr[8] = SVX_RESSTR(STR_WIDTH_LAST_CUSTOM);
144 :
145 0 : const LocaleDataWrapper& rLocaleWrapper( Application::GetSettings().GetLocaleDataWrapper() );
146 0 : const sal_Unicode cSep = rLocaleWrapper.getNumDecimalSep()[0];
147 :
148 0 : for(int i = 0; i <= 7 ; i++)
149 : {
150 0 : rStr[i] = rStr[i].replace('.', cSep);//Modify
151 0 : rStr[i] += " ";
152 0 : rStr[i] += mstrPT;
153 : }
154 : //end
155 :
156 0 : for(sal_uInt16 i = 1 ; i <= 9 ; i++)
157 : {
158 0 : maVSWidth->InsertItem(i);
159 0 : maVSWidth->SetItemText(i, rStr[i-1]);
160 : }
161 0 : maVSWidth->SetUnit(rStr);
162 0 : maVSWidth->SetItemData(1, reinterpret_cast<void*>(5));
163 0 : maVSWidth->SetItemData(2, reinterpret_cast<void*>(8));
164 0 : maVSWidth->SetItemData(3, reinterpret_cast<void*>(10));
165 0 : maVSWidth->SetItemData(4, reinterpret_cast<void*>(15));
166 0 : maVSWidth->SetItemData(5, reinterpret_cast<void*>(23));
167 0 : maVSWidth->SetItemData(6, reinterpret_cast<void*>(30));
168 0 : maVSWidth->SetItemData(7, reinterpret_cast<void*>(45));
169 0 : maVSWidth->SetItemData(8, reinterpret_cast<void*>(60));
170 0 : maVSWidth->SetImage(maIMGCusGray);
171 :
172 0 : maVSWidth->SetSelItem(0);
173 0 : Link<> aLink = LINK( this, LineWidthControl, VSSelectHdl ) ;
174 0 : maVSWidth->SetSelectHdl(aLink);
175 0 : aLink = LINK(this, LineWidthControl, MFModifyHdl);
176 0 : maMFWidth->SetModifyHdl(aLink);
177 :
178 0 : maVSWidth->StartSelection();
179 0 : maVSWidth->Show();
180 0 : }
181 :
182 :
183 :
184 :
185 0 : void LineWidthControl::GetFocus()
186 : {
187 0 : if(!mbVSFocus)
188 0 : maMFWidth->GrabFocus();
189 : else
190 0 : maVSWidth->GrabFocus();
191 0 : }
192 :
193 0 : void LineWidthControl::SetWidthSelect( long lValue, bool bValuable, SfxMapUnit eMapUnit)
194 : {
195 0 : mbVSFocus = true;
196 0 : maVSWidth->SetSelItem(0);
197 0 : mbCloseByEdit = false;
198 0 : meMapUnit = eMapUnit;
199 0 : SvtViewOptions aWinOpt( E_WINDOW, SIDEBAR_LINE_WIDTH_GLOBAL_VALUE );
200 0 : if (aWinOpt.Exists())
201 : {
202 0 : css::uno::Sequence <css::beans::NamedValue> aSeq = aWinOpt.GetUserData();
203 0 : OUString aTmp;
204 0 : if ( aSeq.getLength())
205 0 : aSeq[0].Value >>= aTmp;
206 :
207 0 : OUString aWinData( aTmp );
208 0 : mnCustomWidth = aWinData.toInt32();
209 0 : mbCustom = true;
210 0 : maVSWidth->SetImage(maIMGCus);
211 0 : maVSWidth->SetCusEnable(true);
212 :
213 0 : OUString aStrTip( OUString::number( (double)mnCustomWidth / 10));
214 0 : aStrTip += mstrPT;
215 0 : maVSWidth->SetItemText(9, aStrTip);
216 : }
217 : else
218 : {
219 0 : mbCustom = false;
220 0 : maVSWidth->SetImage(maIMGCusGray);
221 0 : maVSWidth->SetCusEnable(false);
222 : //modify
223 : //String aStrTip(String(SVX_RES(STR_WIDTH_LAST_CUSTOM)));
224 : //maVSWidth->SetItemText(9, aStrTip);
225 0 : maVSWidth->SetItemText(9, rStr[8]);
226 : }
227 :
228 0 : if (bValuable)
229 : {
230 0 : sal_Int64 nVal = OutputDevice::LogicToLogic(lValue, (MapUnit) eMapUnit, MAP_100TH_MM );
231 0 : nVal = maMFWidth->Normalize(nVal);
232 0 : maMFWidth->SetValue( nVal, FUNIT_100TH_MM );
233 : }
234 : else
235 : {
236 0 : maMFWidth->SetText( "" );
237 : }
238 :
239 0 : MapUnit eOrgUnit = (MapUnit)eMapUnit;
240 0 : MapUnit ePntUnit( MAP_TWIP );
241 0 : lValue = LogicToLogic( lValue , eOrgUnit, ePntUnit );
242 :
243 0 : OUString strCurrValue = maMFWidth->GetText();
244 0 : sal_uInt16 i = 0;
245 0 : for(; i < 8; i++)
246 : {
247 0 : if(strCurrValue == rStr[i])
248 : {
249 0 : maVSWidth->SetSelItem(i+1);
250 0 : break;
251 : }
252 : }
253 :
254 0 : if (i>=8)
255 : {
256 0 : mbVSFocus = false;
257 0 : maVSWidth->SetSelItem(0);
258 : }
259 0 : maVSWidth->SetFormat();
260 0 : maVSWidth->Invalidate();
261 0 : maVSWidth->StartSelection();
262 0 : }
263 :
264 0 : IMPL_LINK(LineWidthControl, VSSelectHdl, void *, pControl)
265 : {
266 0 : if (pControl == maVSWidth.get())
267 : {
268 0 : sal_uInt16 iPos = maVSWidth->GetSelectItemId();
269 0 : if (iPos >= 1 && iPos <= 8)
270 : {
271 0 : sal_IntPtr nVal = LogicToLogic(reinterpret_cast<sal_IntPtr>(maVSWidth->GetItemData( iPos )), MAP_POINT, (MapUnit)meMapUnit);
272 0 : nVal = maMFWidth->Denormalize(nVal);
273 0 : XLineWidthItem aWidthItem( nVal );
274 0 : mpBindings->GetDispatcher()->Execute(SID_ATTR_LINE_WIDTH, SfxCallMode::RECORD, &aWidthItem, 0L);
275 0 : mrLinePropertyPanel.SetWidthIcon(iPos);
276 0 : mrLinePropertyPanel.SetWidth(nVal);
277 0 : mbCloseByEdit = false;
278 0 : mnTmpCustomWidth = 0;
279 : }
280 0 : else if (iPos == 9)
281 : {//last custom
282 : //modified
283 0 : if (mbCustom)
284 : {
285 0 : long nVal = LogicToLogic(mnCustomWidth , MAP_POINT, (MapUnit)meMapUnit);
286 0 : nVal = maMFWidth->Denormalize(nVal);
287 0 : XLineWidthItem aWidthItem( nVal );
288 0 : mpBindings->GetDispatcher()->Execute(SID_ATTR_LINE_WIDTH, SfxCallMode::RECORD, &aWidthItem, 0L);
289 0 : mrLinePropertyPanel.SetWidth(nVal);
290 0 : mbCloseByEdit = false;
291 0 : mnTmpCustomWidth = 0;
292 : }
293 : else
294 : {
295 0 : maVSWidth->SetNoSelection(); //add , set no selection and keep the last select item
296 0 : maVSWidth->SetFormat();
297 0 : maVSWidth->Invalidate();
298 0 : Invalidate();
299 0 : maVSWidth->StartSelection();
300 : }
301 : //modify end
302 : }
303 0 : if ((iPos >= 1 && iPos <= 8) || (iPos == 9 && mbCustom)) //add
304 0 : mrLinePropertyPanel.EndLineWidthPopupMode();
305 : }
306 0 : return 0L;
307 : }
308 :
309 0 : IMPL_LINK(LineWidthControl, MFModifyHdl, void *, pControl)
310 : {
311 0 : if (pControl == maMFWidth.get())
312 : {
313 0 : if(maVSWidth->GetSelItem())
314 : {
315 0 : maVSWidth->SetSelItem(0);
316 0 : maVSWidth->SetFormat();
317 0 : maVSWidth->Invalidate();
318 0 : Invalidate();
319 0 : maVSWidth->StartSelection();
320 : }
321 0 : long nTmp = static_cast<long>(maMFWidth->GetValue());
322 0 : long nVal = LogicToLogic( nTmp, MAP_POINT, (MapUnit)meMapUnit );
323 0 : sal_Int32 nNewWidth = (short)maMFWidth->Denormalize( nVal );
324 0 : XLineWidthItem aWidthItem(nNewWidth);
325 0 : mpBindings->GetDispatcher()->Execute(SID_ATTR_LINE_WIDTH, SfxCallMode::RECORD, &aWidthItem, 0L);
326 :
327 0 : mbCloseByEdit = true;
328 0 : mnTmpCustomWidth = nTmp;
329 : }
330 0 : return 0L;
331 : }
332 :
333 390 : } } // end of namespace svx::sidebar
334 :
335 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|