update credits
[LibreOffice.git] / svx / source / sidebar / graphic / GraphicPropertyPanel.cxx
blob04bdbf5d6add119e35879766fe33952e2764af7f
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 <sfx2/sidebar/ResourceDefinitions.hrc>
19 #include <sfx2/sidebar/Theme.hxx>
20 #include <sfx2/sidebar/ControlFactory.hxx>
21 #include <GraphicPropertyPanel.hxx>
22 #include <GraphicPropertyPanel.hrc>
23 #include <svx/dialogs.hrc>
24 #include <svx/dialmgr.hxx>
25 #include <vcl/field.hxx>
26 #include <vcl/lstbox.hxx>
27 #include <svl/intitem.hxx>
28 #include <sfx2/bindings.hxx>
29 #include <sfx2/dispatch.hxx>
30 #include "svx/dialogs.hrc"
32 using namespace css;
33 using namespace cssu;
34 using ::sfx2::sidebar::Theme;
36 #define A2S(pString) (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(pString)))
38 //////////////////////////////////////////////////////////////////////////////
39 // namespace open
41 namespace svx { namespace sidebar {
43 //////////////////////////////////////////////////////////////////////////////
45 GraphicPropertyPanel::GraphicPropertyPanel(
46 Window* pParent,
47 const cssu::Reference<css::frame::XFrame>& rxFrame,
48 SfxBindings* pBindings)
49 : Control(
50 pParent,
51 SVX_RES(RID_SIDEBAR_GRAPHIC_PANEL)),
52 mpFtBrightness(new FixedText(this, SVX_RES(FT_BRIGHTNESS))),
53 mpMtrBrightness(new MetricField(this, SVX_RES(MTR_BRIGHTNESS))),
54 mpFtContrast(new FixedText(this, SVX_RES(FT_CONTRAST))),
55 mpMtrContrast(new MetricField(this, SVX_RES(MTR_CONTRAST))),
56 mpFtColorMode(new FixedText(this, SVX_RES(FT_COLOR_MODE))),
57 mpLBColorMode(new ListBox(this, SVX_RES(LB_COLOR_MODE))),
58 mpFtTrans(new FixedText(this, SVX_RES(FT_TRANSPARENT))),
59 mpMtrTrans(new MetricField(this, SVX_RES(MTR_TRANSPARENT))),
60 mpMtrRed(new MetricField(this, SVX_RES(MF_RED))),
61 mpMtrGreen(new MetricField(this, SVX_RES(MF_GREEN))),
62 mpMtrBlue(new MetricField(this, SVX_RES(MF_BLUE))),
63 mpMtrGamma(new MetricField(this, SVX_RES(MF_GAMMA))),
64 maBrightControl(SID_ATTR_GRAF_LUMINANCE, *pBindings, *this),
65 maContrastControl(SID_ATTR_GRAF_CONTRAST, *pBindings, *this),
66 maTransparenceControl(SID_ATTR_GRAF_TRANSPARENCE, *pBindings, *this),
67 maRedControl(SID_ATTR_GRAF_RED, *pBindings, *this),
68 maGreenControl(SID_ATTR_GRAF_GREEN, *pBindings, *this),
69 maBlueControl(SID_ATTR_GRAF_BLUE, *pBindings, *this),
70 maGammaControl(SID_ATTR_GRAF_GAMMA, *pBindings, *this),
71 maModeControl(SID_ATTR_GRAF_MODE, *pBindings, *this),
72 maImgRed(this, SVX_RES(IMG_RED)),
73 maImgGreen(this, SVX_RES(IMG_GREEN)),
74 maImgBlue(this, SVX_RES(IMG_BLUE)),
75 maImgGamma(this, SVX_RES(IMG_GAMMA)),
76 mxFrame(rxFrame),
77 mpBindings(pBindings)
79 Initialize();
80 FreeResource();
83 //////////////////////////////////////////////////////////////////////////////
85 GraphicPropertyPanel::~GraphicPropertyPanel()
89 //////////////////////////////////////////////////////////////////////////////
91 void GraphicPropertyPanel::Initialize()
93 mpFtBrightness->SetBackground(Wallpaper());
94 mpFtContrast->SetBackground(Wallpaper());
95 mpFtColorMode->SetBackground(Wallpaper());
96 mpFtTrans->SetBackground(Wallpaper());
98 mpMtrBrightness->SetModifyHdl( LINK( this, GraphicPropertyPanel, ModifyBrightnessHdl ) );
99 mpMtrBrightness->SetAccessibleName(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Brightness")));
100 mpMtrContrast->SetModifyHdl( LINK( this, GraphicPropertyPanel, ModifyContrastHdl ) );
101 mpMtrContrast->SetAccessibleName(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Contrast")));
102 mpMtrTrans->SetModifyHdl( LINK( this, GraphicPropertyPanel, ModifyTransHdl ) );
103 mpMtrTrans->SetAccessibleName(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Transparency")));
105 mpLBColorMode->InsertEntry(String(SVX_RES(RID_SVXSTR_GRAFMODE_STANDARD)));
106 mpLBColorMode->InsertEntry(String(SVX_RES(RID_SVXSTR_GRAFMODE_GREYS)));
107 mpLBColorMode->InsertEntry(String(SVX_RES(RID_SVXSTR_GRAFMODE_MONO)));
108 mpLBColorMode->InsertEntry(String(SVX_RES(RID_SVXSTR_GRAFMODE_WATERMARK)));
109 mpLBColorMode->SetSelectHdl( LINK( this, GraphicPropertyPanel, ClickColorModeHdl ));
110 mpLBColorMode->SetAccessibleName(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Color mode")));
112 mpMtrRed->SetModifyHdl( LINK( this, GraphicPropertyPanel, RedHdl ) );
113 mpMtrGreen->SetModifyHdl( LINK( this, GraphicPropertyPanel, GreenHdl ) );
114 mpMtrBlue->SetModifyHdl( LINK( this, GraphicPropertyPanel, BlueHdl ) );
115 mpMtrGamma->SetModifyHdl( LINK( this, GraphicPropertyPanel, GammaHdl ) );
116 mpMtrRed->SetAccessibleName(mpMtrRed->GetQuickHelpText());
117 mpMtrGreen->SetAccessibleName(mpMtrGreen->GetQuickHelpText());
118 mpMtrBlue->SetAccessibleName(mpMtrBlue->GetQuickHelpText());
119 mpMtrGamma->SetAccessibleName(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Gamma value")));
121 mpMtrRed->SetAccessibleRelationLabeledBy(mpMtrRed.get());
122 mpMtrGreen->SetAccessibleRelationLabeledBy(mpMtrGreen.get());
123 mpMtrBlue->SetAccessibleRelationLabeledBy(mpMtrBlue.get());
124 mpMtrGamma->SetAccessibleRelationLabeledBy(mpMtrGamma.get());
125 mpMtrBrightness->SetAccessibleRelationLabeledBy(mpFtBrightness.get());
126 mpMtrContrast->SetAccessibleRelationLabeledBy(mpFtContrast.get());
127 mpMtrTrans->SetAccessibleRelationLabeledBy(mpFtTrans.get());
128 mpLBColorMode->SetAccessibleRelationLabeledBy(mpFtColorMode.get());
130 // Fix left position of some controls that may be wrong due to
131 // rounding errors.
132 const sal_Int32 nRight0 (mpLBColorMode->GetPosPixel().X() + mpLBColorMode->GetSizePixel().Width());
133 const sal_Int32 nRight1 (mpMtrTrans->GetPosPixel().X() + mpMtrTrans->GetSizePixel().Width());
134 mpMtrRed->SetPosPixel(Point(
135 nRight0 - mpMtrRed->GetSizePixel().Width(),
136 mpMtrRed->GetPosPixel().Y()));
137 mpMtrBlue->SetPosPixel(Point(
138 nRight0 - mpMtrBlue->GetSizePixel().Width(),
139 mpMtrBlue->GetPosPixel().Y()));
140 mpMtrGreen->SetPosPixel(Point(
141 nRight1 - mpMtrGreen->GetSizePixel().Width(),
142 mpMtrGreen->GetPosPixel().Y()));
143 mpMtrGamma->SetPosPixel(Point(
144 nRight1 - mpMtrGamma->GetSizePixel().Width(),
145 mpMtrGamma->GetPosPixel().Y()));
151 //////////////////////////////////////////////////////////////////////////////
153 IMPL_LINK( GraphicPropertyPanel, ModifyBrightnessHdl, void *, EMPTYARG )
155 const sal_Int16 nBright = mpMtrBrightness->GetValue();
156 const SfxInt16Item aBrightItem( SID_ATTR_GRAF_LUMINANCE, nBright );
157 GetBindings()->GetDispatcher()->Execute(SID_ATTR_GRAF_LUMINANCE, SFX_CALLMODE_RECORD, &aBrightItem, 0L);
158 return 0L;
161 //////////////////////////////////////////////////////////////////////////////
163 IMPL_LINK( GraphicPropertyPanel, ModifyContrastHdl, void *, EMPTYARG )
165 const sal_Int16 nContrast = mpMtrContrast->GetValue();
166 const SfxInt16Item aContrastItem( SID_ATTR_GRAF_CONTRAST, nContrast );
167 GetBindings()->GetDispatcher()->Execute(SID_ATTR_GRAF_CONTRAST, SFX_CALLMODE_RECORD, &aContrastItem, 0L);
168 return 0L;
171 //////////////////////////////////////////////////////////////////////////////
173 IMPL_LINK( GraphicPropertyPanel, ModifyTransHdl, void *, EMPTYARG )
175 const sal_Int16 nTrans = mpMtrTrans->GetValue();
176 const SfxInt16Item aTransItem( SID_ATTR_GRAF_TRANSPARENCE, nTrans );
177 GetBindings()->GetDispatcher()->Execute(SID_ATTR_GRAF_TRANSPARENCE, SFX_CALLMODE_RECORD, &aTransItem, 0L);
178 return 0L;
181 //////////////////////////////////////////////////////////////////////////////
183 IMPL_LINK_NOARG( GraphicPropertyPanel, ClickColorModeHdl )
185 const sal_Int16 nTrans = mpLBColorMode->GetSelectEntryPos();
186 const SfxInt16Item aTransItem( SID_ATTR_GRAF_MODE, nTrans );
187 GetBindings()->GetDispatcher()->Execute(SID_ATTR_GRAF_MODE, SFX_CALLMODE_RECORD, &aTransItem, 0L);
188 return 0L;
191 //////////////////////////////////////////////////////////////////////////////
193 IMPL_LINK( GraphicPropertyPanel, RedHdl, void*, EMPTYARG )
195 const sal_Int16 nRed = mpMtrRed->GetValue();
196 const SfxInt16Item aRedItem( SID_ATTR_GRAF_RED, nRed );
197 GetBindings()->GetDispatcher()->Execute(SID_ATTR_GRAF_RED, SFX_CALLMODE_RECORD, &aRedItem, 0L);
198 return 0L;
201 //////////////////////////////////////////////////////////////////////////////
203 IMPL_LINK( GraphicPropertyPanel, GreenHdl, void*, EMPTYARG )
205 const sal_Int16 nGreen = mpMtrGreen->GetValue();
206 const SfxInt16Item aGreenItem( SID_ATTR_GRAF_GREEN, nGreen );
207 GetBindings()->GetDispatcher()->Execute(SID_ATTR_GRAF_GREEN, SFX_CALLMODE_RECORD, &aGreenItem, 0L);
208 return 0L;
211 //////////////////////////////////////////////////////////////////////////////
213 IMPL_LINK(GraphicPropertyPanel, BlueHdl, void *, EMPTYARG)
215 const sal_Int16 nBlue = mpMtrBlue->GetValue();
216 const SfxInt16Item aBlueItem( SID_ATTR_GRAF_BLUE, nBlue );
217 GetBindings()->GetDispatcher()->Execute(SID_ATTR_GRAF_BLUE, SFX_CALLMODE_RECORD, &aBlueItem, 0L);
218 return 0L;
221 //////////////////////////////////////////////////////////////////////////////
223 IMPL_LINK(GraphicPropertyPanel, GammaHdl, void *, EMPTYARG)
225 const sal_Int32 nGamma = mpMtrGamma->GetValue();
226 const SfxInt32Item nGammaItem( SID_ATTR_GRAF_GAMMA, nGamma );
227 GetBindings()->GetDispatcher()->Execute(SID_ATTR_GRAF_GAMMA, SFX_CALLMODE_RECORD, &nGammaItem, 0L);
228 return 0L;
231 //////////////////////////////////////////////////////////////////////////////
233 void GraphicPropertyPanel::SetupIcons(void)
235 if(Theme::GetBoolean(Theme::Bool_UseSymphonyIcons))
237 // todo
239 else
241 // todo
245 //////////////////////////////////////////////////////////////////////////////
247 GraphicPropertyPanel* GraphicPropertyPanel::Create (
248 Window* pParent,
249 const cssu::Reference<css::frame::XFrame>& rxFrame,
250 SfxBindings* pBindings)
252 if (pParent == NULL)
253 throw lang::IllegalArgumentException(A2S("no parent Window given to GraphicPropertyPanel::Create"), NULL, 0);
254 if ( ! rxFrame.is())
255 throw lang::IllegalArgumentException(A2S("no XFrame given to GraphicPropertyPanel::Create"), NULL, 1);
256 if (pBindings == NULL)
257 throw lang::IllegalArgumentException(A2S("no SfxBindings given to GraphicPropertyPanel::Create"), NULL, 2);
259 return new GraphicPropertyPanel(
260 pParent,
261 rxFrame,
262 pBindings);
265 //////////////////////////////////////////////////////////////////////////////
267 void GraphicPropertyPanel::DataChanged(
268 const DataChangedEvent& rEvent)
270 (void)rEvent;
272 SetupIcons();
275 //////////////////////////////////////////////////////////////////////////////
277 void GraphicPropertyPanel::NotifyItemUpdate(
278 sal_uInt16 nSID,
279 SfxItemState eState,
280 const SfxPoolItem* pState,
281 const bool bIsEnabled)
283 (void)bIsEnabled;
285 switch( nSID )
287 case SID_ATTR_GRAF_LUMINANCE:
289 if(eState >= SFX_ITEM_AVAILABLE)
291 mpMtrBrightness->Enable();
292 const SfxInt16Item* pItem = dynamic_cast< const SfxInt16Item* >(pState);
294 if(pItem)
296 const sal_Int64 nBright = pItem->GetValue();
297 mpMtrBrightness->SetValue(nBright);
300 else if(SFX_ITEM_DISABLED == eState)
302 mpMtrBrightness->Disable();
304 else
306 mpMtrBrightness->Enable();
307 mpMtrBrightness->SetText(String());
309 break;
311 case SID_ATTR_GRAF_CONTRAST:
313 if(eState >= SFX_ITEM_AVAILABLE)
315 mpMtrContrast->Enable();
316 const SfxInt16Item* pItem = dynamic_cast< const SfxInt16Item* >(pState);
318 if(pItem)
320 const sal_Int64 nContrast = pItem->GetValue();
321 mpMtrContrast->SetValue(nContrast);
324 else if(SFX_ITEM_DISABLED == eState)
326 mpMtrContrast->Disable();
328 else
330 mpMtrContrast->Enable();
331 mpMtrContrast->SetText(String());
333 break;
335 case SID_ATTR_GRAF_TRANSPARENCE:
337 if(eState >= SFX_ITEM_AVAILABLE)
339 mpMtrTrans->Enable();
340 const SfxUInt16Item* pItem = dynamic_cast< const SfxUInt16Item* >(pState);
342 if(pItem)
344 const sal_Int64 nTrans = pItem->GetValue();
345 mpMtrTrans->SetValue(nTrans);
348 else if(SFX_ITEM_DISABLED == eState)
350 mpMtrTrans->Disable();
352 else
354 mpMtrTrans->Enable();
355 mpMtrTrans->SetText(String());
357 break;
359 case SID_ATTR_GRAF_MODE:
361 if(eState >= SFX_ITEM_AVAILABLE)
363 mpLBColorMode->Enable();
364 const SfxUInt16Item* pItem = dynamic_cast< const SfxUInt16Item* >(pState);
366 if(pItem)
368 const sal_Int64 nTrans = pItem->GetValue();
369 mpLBColorMode->SelectEntryPos(nTrans);
372 else if(SFX_ITEM_DISABLED == eState)
374 mpLBColorMode->Disable();
376 else
378 mpLBColorMode->Enable();
379 mpLBColorMode->SetNoSelection();
381 break;
383 case SID_ATTR_GRAF_RED:
385 if(eState >= SFX_ITEM_AVAILABLE)
387 mpMtrRed->Enable();
388 const SfxInt16Item* pItem = dynamic_cast< const SfxInt16Item* >(pState);
390 if(pItem)
392 const sal_Int64 nRed = pItem->GetValue();
393 mpMtrRed->SetValue( nRed );
396 else if(SFX_ITEM_DISABLED == eState)
398 mpMtrRed->Disable();
400 else
402 mpMtrRed->Enable();
403 mpMtrRed->SetText(String());
405 break;
407 case SID_ATTR_GRAF_GREEN:
409 if(eState >= SFX_ITEM_AVAILABLE)
411 mpMtrGreen->Enable();
412 const SfxInt16Item* pItem = dynamic_cast< const SfxInt16Item* >(pState);
414 if(pItem)
416 const sal_Int64 nGreen = pItem->GetValue();
417 mpMtrGreen->SetValue( nGreen );
420 else if(SFX_ITEM_DISABLED == eState)
422 mpMtrGreen->Disable();
424 else
426 mpMtrGreen->Enable();
427 mpMtrGreen->SetText(String());
429 break;
431 case SID_ATTR_GRAF_BLUE:
433 if(eState >= SFX_ITEM_AVAILABLE)
435 mpMtrBlue->Enable();
436 const SfxInt16Item* pItem = dynamic_cast< const SfxInt16Item* >(pState);
438 if(pItem)
440 const sal_Int64 nBlue = pItem->GetValue();
441 mpMtrBlue->SetValue( nBlue );
444 else if(SFX_ITEM_DISABLED == eState)
446 mpMtrBlue->Disable();
448 else
450 mpMtrBlue->Enable();
451 mpMtrBlue->SetText(String());
453 break;
455 case SID_ATTR_GRAF_GAMMA:
457 if(eState >= SFX_ITEM_AVAILABLE)
459 mpMtrGamma->Enable();
460 const SfxUInt32Item* pItem = dynamic_cast< const SfxUInt32Item* >(pState);
462 if(pItem)
464 const sal_Int64 nGamma = pItem->GetValue();
465 mpMtrGamma->SetValue( nGamma );
468 else if(SFX_ITEM_DISABLED == eState)
470 mpMtrGamma->Disable();
472 else
474 mpMtrGamma->Enable();
475 mpMtrGamma->SetText(String());
477 break;
485 //////////////////////////////////////////////////////////////////////////////
487 SfxBindings* GraphicPropertyPanel::GetBindings()
489 return mpBindings;
492 //////////////////////////////////////////////////////////////////////////////
493 // namespace close
495 }} // end of namespace ::svx::sidebar
497 //////////////////////////////////////////////////////////////////////////////
498 // eof