1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 #include <sfx2/sidebar/propertypanel.hrc>
23 #include <sfx2/sidebar/Theme.hxx>
24 #include <sfx2/sidebar/ControlFactory.hxx>
25 #include <GraphicPropertyPanel.hxx>
26 #include <GraphicPropertyPanel.hrc>
27 #include <svx/dialogs.hrc>
28 #include <svx/dialmgr.hxx>
29 #include <vcl/field.hxx>
30 #include <vcl/lstbox.hxx>
31 #include <svl/intitem.hxx>
32 #include <sfx2/bindings.hxx>
33 #include <sfx2/dispatch.hxx>
34 
35 using namespace css;
36 using namespace cssu;
37 using ::sfx2::sidebar::Theme;
38 
39 #define A2S(pString) (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(pString)))
40 
41 //////////////////////////////////////////////////////////////////////////////
42 // namespace open
43 
44 namespace svx { namespace sidebar {
45 
46 //////////////////////////////////////////////////////////////////////////////
47 
48 GraphicPropertyPanel::GraphicPropertyPanel(
49     Window* pParent,
50     const cssu::Reference<css::frame::XFrame>& rxFrame,
51     SfxBindings* pBindings)
52 :   Control(
53         pParent,
54         SVX_RES(RID_SIDEBAR_GRAPHIC_PANEL)),
55     mpFtBrightness(new FixedText(this, SVX_RES(FT_BRIGHTNESS))),
56     mpMtrBrightness(new MetricField(this, SVX_RES(MTR_BRIGHTNESS))),
57     mpFtContrast(new FixedText(this, SVX_RES(FT_CONTRAST))),
58     mpMtrContrast(new MetricField(this, SVX_RES(MTR_CONTRAST))),
59     mpFtColorMode(new FixedText(this, SVX_RES(FT_COLOR_MODE))),
60     mpLBColorMode(new ListBox(this, SVX_RES(LB_COLOR_MODE))),
61     mpFtTrans(new FixedText(this, SVX_RES(FT_TRANSPARENT))),
62     mpMtrTrans(new MetricField(this, SVX_RES(MTR_TRANSPARENT))),
63     mpMtrRed(new MetricField(this, SVX_RES(MF_RED))),
64     mpMtrGreen(new MetricField(this, SVX_RES(MF_GREEN))),
65     mpMtrBlue(new MetricField(this, SVX_RES(MF_BLUE))),
66     mpMtrGamma(new MetricField(this, SVX_RES(MF_GAMMA))),
67     maBrightControl(SID_ATTR_GRAF_LUMINANCE, *pBindings, *this),
68     maContrastControl(SID_ATTR_GRAF_CONTRAST, *pBindings, *this),
69     maTransparenceControl(SID_ATTR_GRAF_TRANSPARENCE, *pBindings, *this),
70     maRedControl(SID_ATTR_GRAF_RED, *pBindings, *this),
71     maGreenControl(SID_ATTR_GRAF_GREEN, *pBindings, *this),
72     maBlueControl(SID_ATTR_GRAF_BLUE, *pBindings, *this),
73     maGammaControl(SID_ATTR_GRAF_GAMMA, *pBindings, *this),
74     maModeControl(SID_ATTR_GRAF_MODE, *pBindings, *this),
75     maImgNormal(SVX_RES(IMG_NORMAL)),
76     maImgBW(SVX_RES(IMG_BW)),
77     maImgGray(SVX_RES(IMG_GRAY)),
78     maImgWater(SVX_RES(IMG_WATER)),
79     maImgRed(this, SVX_RES(IMG_RED)),
80     maImgGreen(this, SVX_RES(IMG_GREEN)),
81     maImgBlue(this, SVX_RES(IMG_BLUE)),
82     maImgGamma(this, SVX_RES(IMG_GAMMA)),
83     msNormal(SVX_RES(STR_NORMAL)),
84     msBW(SVX_RES(STR_BW)),
85     msGray(SVX_RES(STR_GRAY)),
86     msWater(SVX_RES(STR_WATER)),
87     mxFrame(rxFrame),
88     mpBindings(pBindings)
89 {
90     Initialize();
91     FreeResource();
92 }
93 
94 //////////////////////////////////////////////////////////////////////////////
95 
96 GraphicPropertyPanel::~GraphicPropertyPanel()
97 {
98 }
99 
100 //////////////////////////////////////////////////////////////////////////////
101 
102 void GraphicPropertyPanel::Initialize()
103 {
104     mpFtBrightness->SetBackground(Wallpaper());
105     mpFtContrast->SetBackground(Wallpaper());
106     mpFtColorMode->SetBackground(Wallpaper());
107     mpFtTrans->SetBackground(Wallpaper());
108 
109     mpMtrBrightness->SetModifyHdl( LINK( this, GraphicPropertyPanel, ModifyBrightnessHdl ) );
110     mpMtrBrightness->SetAccessibleName(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Brightness")));	//wj acc
111     mpMtrContrast->SetModifyHdl( LINK( this, GraphicPropertyPanel, ModifyContrastHdl ) );
112     mpMtrContrast->SetAccessibleName(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Contrast")));	//wj acc
113     mpMtrTrans->SetModifyHdl( LINK( this, GraphicPropertyPanel, ModifyTransHdl ) );
114     mpMtrTrans->SetAccessibleName(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Transparency")));	//wj acc
115 
116     mpLBColorMode->InsertEntry( msNormal, maImgNormal );
117     mpLBColorMode->InsertEntry( msGray, maImgGray );
118     mpLBColorMode->InsertEntry( msBW, maImgBW );
119     mpLBColorMode->InsertEntry( msWater, maImgWater );
120     mpLBColorMode->SetSelectHdl( LINK( this, GraphicPropertyPanel, ClickColorModeHdl ));
121     mpLBColorMode->SetAccessibleName(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Color mode")));	//wj acc
122 
123     mpMtrRed->SetModifyHdl( LINK( this, GraphicPropertyPanel, RedHdl ) );
124     mpMtrGreen->SetModifyHdl( LINK( this, GraphicPropertyPanel, GreenHdl ) );
125     mpMtrBlue->SetModifyHdl( LINK( this, GraphicPropertyPanel, BlueHdl ) );
126     mpMtrGamma->SetModifyHdl( LINK( this, GraphicPropertyPanel, GammaHdl ) );
127     mpMtrRed->SetAccessibleName(mpMtrRed->GetQuickHelpText());	//wj acc
128     mpMtrGreen->SetAccessibleName(mpMtrGreen->GetQuickHelpText());	//wj acc
129     mpMtrBlue->SetAccessibleName(mpMtrBlue->GetQuickHelpText());		//wj acc
130     mpMtrGamma->SetAccessibleName(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Gamma value")));	//wj acc
131 
132     mpMtrRed->SetAccessibleRelationLabeledBy(mpMtrRed.get());
133     mpMtrGreen->SetAccessibleRelationLabeledBy(mpMtrGreen.get());
134     mpMtrBlue->SetAccessibleRelationLabeledBy(mpMtrBlue.get());
135     mpMtrGamma->SetAccessibleRelationLabeledBy(mpMtrGamma.get());
136     mpMtrBrightness->SetAccessibleRelationLabeledBy(mpFtBrightness.get());	//7874
137     mpMtrContrast->SetAccessibleRelationLabeledBy(mpFtContrast.get());	//7874
138     mpMtrTrans->SetAccessibleRelationLabeledBy(mpFtTrans.get());	//7874
139     mpLBColorMode->SetAccessibleRelationLabeledBy(mpFtColorMode.get());	//7874
140 }
141 
142 //////////////////////////////////////////////////////////////////////////////
143 
144 IMPL_LINK( GraphicPropertyPanel, ModifyBrightnessHdl, void *, EMPTYARG )
145 {
146     const sal_Int16 nBright = mpMtrBrightness->GetValue();
147     const SfxInt16Item aBrightItem( SID_ATTR_GRAF_LUMINANCE, nBright );
148     GetBindings()->GetDispatcher()->Execute(SID_ATTR_GRAF_LUMINANCE, SFX_CALLMODE_RECORD, &aBrightItem, 0L);
149     return 0L;
150 }
151 
152 //////////////////////////////////////////////////////////////////////////////
153 
154 IMPL_LINK( GraphicPropertyPanel, ModifyContrastHdl, void *, EMPTYARG )
155 {
156     const sal_Int16 nContrast = mpMtrContrast->GetValue();
157     const SfxInt16Item aContrastItem( SID_ATTR_GRAF_CONTRAST, nContrast );
158     GetBindings()->GetDispatcher()->Execute(SID_ATTR_GRAF_CONTRAST, SFX_CALLMODE_RECORD, &aContrastItem, 0L);
159     return 0L;
160 }
161 
162 //////////////////////////////////////////////////////////////////////////////
163 
164 IMPL_LINK( GraphicPropertyPanel, ModifyTransHdl, void *, EMPTYARG )
165 {
166     const sal_Int16 nTrans = mpMtrTrans->GetValue();
167     const SfxInt16Item aTransItem( SID_ATTR_GRAF_TRANSPARENCE, nTrans );
168     GetBindings()->GetDispatcher()->Execute(SID_ATTR_GRAF_TRANSPARENCE, SFX_CALLMODE_RECORD, &aTransItem, 0L);
169     return 0L;
170 }
171 
172 //////////////////////////////////////////////////////////////////////////////
173 
174 IMPL_LINK( GraphicPropertyPanel, ClickColorModeHdl, ToolBox *, /* pBox */)
175 {
176     const sal_Int16 nTrans = mpLBColorMode->GetSelectEntryPos();
177     const SfxInt16Item aTransItem( SID_ATTR_GRAF_MODE, nTrans );
178     GetBindings()->GetDispatcher()->Execute(SID_ATTR_GRAF_MODE, SFX_CALLMODE_RECORD, &aTransItem, 0L);
179     return 0L;
180 }
181 
182 //////////////////////////////////////////////////////////////////////////////
183 
184 IMPL_LINK( GraphicPropertyPanel, RedHdl, void*, EMPTYARG )
185 {
186     const sal_Int16 nRed = mpMtrRed->GetValue();
187     const SfxInt16Item aRedItem( SID_ATTR_GRAF_RED, nRed );
188     GetBindings()->GetDispatcher()->Execute(SID_ATTR_GRAF_RED, SFX_CALLMODE_RECORD, &aRedItem, 0L);
189     return 0L;
190 }
191 
192 //////////////////////////////////////////////////////////////////////////////
193 
194 IMPL_LINK( GraphicPropertyPanel, GreenHdl, void*, EMPTYARG )
195 {
196     const sal_Int16 nGreen = mpMtrGreen->GetValue();
197     const SfxInt16Item aGreenItem( SID_ATTR_GRAF_GREEN, nGreen );
198     GetBindings()->GetDispatcher()->Execute(SID_ATTR_GRAF_GREEN, SFX_CALLMODE_RECORD, &aGreenItem, 0L);
199     return 0L;
200 }
201 
202 //////////////////////////////////////////////////////////////////////////////
203 
204 IMPL_LINK(GraphicPropertyPanel, BlueHdl, void *, EMPTYARG)
205 {
206     const sal_Int16 nBlue = mpMtrBlue->GetValue();
207     const SfxInt16Item aBlueItem( SID_ATTR_GRAF_BLUE, nBlue );
208     GetBindings()->GetDispatcher()->Execute(SID_ATTR_GRAF_BLUE, SFX_CALLMODE_RECORD, &aBlueItem, 0L);
209     return 0L;
210 }
211 
212 //////////////////////////////////////////////////////////////////////////////
213 
214 IMPL_LINK(GraphicPropertyPanel, GammaHdl, void *, EMPTYARG)
215 {
216     const sal_Int32 nGamma = mpMtrGamma->GetValue();
217     const SfxInt32Item nGammaItem( SID_ATTR_GRAF_GAMMA, nGamma );
218     GetBindings()->GetDispatcher()->Execute(SID_ATTR_GRAF_GAMMA, SFX_CALLMODE_RECORD, &nGammaItem, 0L);
219     return 0L;
220 }
221 
222 //////////////////////////////////////////////////////////////////////////////
223 
224 void GraphicPropertyPanel::SetupIcons(void)
225 {
226     if(Theme::GetBoolean(Theme::Bool_UseSymphonyIcons))
227     {
228         // todo
229     }
230     else
231     {
232         // todo
233     }
234 }
235 
236 //////////////////////////////////////////////////////////////////////////////
237 
238 GraphicPropertyPanel* GraphicPropertyPanel::Create (
239     Window* pParent,
240     const cssu::Reference<css::frame::XFrame>& rxFrame,
241     SfxBindings* pBindings)
242 {
243     if (pParent == NULL)
244         throw lang::IllegalArgumentException(A2S("no parent Window given to GraphicPropertyPanel::Create"), NULL, 0);
245     if ( ! rxFrame.is())
246         throw lang::IllegalArgumentException(A2S("no XFrame given to GraphicPropertyPanel::Create"), NULL, 1);
247     if (pBindings == NULL)
248         throw lang::IllegalArgumentException(A2S("no SfxBindings given to GraphicPropertyPanel::Create"), NULL, 2);
249 
250     return new GraphicPropertyPanel(
251         pParent,
252         rxFrame,
253         pBindings);
254 }
255 
256 //////////////////////////////////////////////////////////////////////////////
257 
258 void GraphicPropertyPanel::DataChanged(
259     const DataChangedEvent& rEvent)
260 {
261     (void)rEvent;
262 
263     SetupIcons();
264 }
265 
266 //////////////////////////////////////////////////////////////////////////////
267 
268 void GraphicPropertyPanel::NotifyItemUpdate(
269     sal_uInt16 nSID,
270     SfxItemState eState,
271     const SfxPoolItem* pState,
272     const bool bIsEnabled)
273 {
274     (void)bIsEnabled;
275 
276     switch( nSID )
277     {
278         case SID_ATTR_GRAF_LUMINANCE:
279         {
280             if(eState >= SFX_ITEM_AVAILABLE)
281             {
282                 mpMtrBrightness->Enable();
283                 const SfxInt16Item* pItem = dynamic_cast< const SfxInt16Item* >(pState);
284 
285                 if(pItem)
286                 {
287                     const sal_Int64 nBright = pItem->GetValue();
288                     mpMtrBrightness->SetValue(nBright);
289                 }
290             }
291             else if(SFX_ITEM_DISABLED == eState)
292             {
293                 mpMtrBrightness->Disable();
294             }
295             else
296             {
297                 mpMtrBrightness->Enable();
298                 mpMtrBrightness->SetText(String());
299             }
300             break;
301         }
302         case SID_ATTR_GRAF_CONTRAST:
303         {
304             if(eState >= SFX_ITEM_AVAILABLE)
305             {
306                 mpMtrContrast->Enable();
307                 const SfxInt16Item* pItem = dynamic_cast< const SfxInt16Item* >(pState);
308 
309                 if(pItem)
310                 {
311                     const sal_Int64 nContrast = pItem->GetValue();
312                     mpMtrContrast->SetValue(nContrast);
313                 }
314             }
315             else if(SFX_ITEM_DISABLED == eState)
316             {
317                 mpMtrContrast->Disable();
318             }
319             else
320             {
321                 mpMtrContrast->Enable();
322                 mpMtrContrast->SetText(String());
323             }
324             break;
325         }
326         case SID_ATTR_GRAF_TRANSPARENCE:
327         {
328             if(eState >= SFX_ITEM_AVAILABLE)
329             {
330                 mpMtrTrans->Enable();
331                 const SfxUInt16Item* pItem = dynamic_cast< const SfxUInt16Item* >(pState);
332 
333                 if(pItem)
334                 {
335                     const sal_Int64 nTrans = pItem->GetValue();
336                     mpMtrTrans->SetValue(nTrans);
337                 }
338             }
339             else if(SFX_ITEM_DISABLED == eState)
340             {
341                 mpMtrTrans->Disable();
342             }
343             else
344             {
345                 mpMtrTrans->Enable();
346                 mpMtrTrans->SetText(String());
347             }
348             break;
349         }
350         case SID_ATTR_GRAF_MODE:
351         {
352             if(eState >= SFX_ITEM_AVAILABLE)
353             {
354                 mpLBColorMode->Enable();
355                 const SfxUInt16Item* pItem = dynamic_cast< const SfxUInt16Item* >(pState);
356 
357                 if(pItem)
358                 {
359                     const sal_Int64 nTrans = pItem->GetValue();
360                     mpLBColorMode->SelectEntryPos(nTrans);
361                 }
362             }
363             else if(SFX_ITEM_DISABLED == eState)
364             {
365                 mpLBColorMode->Disable();
366             }
367             else
368             {
369                 mpLBColorMode->Enable();
370                 mpLBColorMode->SetNoSelection();
371             }
372             break;
373         }
374         case SID_ATTR_GRAF_RED:
375         {
376             if(eState >= SFX_ITEM_AVAILABLE)
377             {
378                 mpMtrRed->Enable();
379                 const SfxInt16Item* pItem = dynamic_cast< const SfxInt16Item* >(pState);
380 
381                 if(pItem)
382                 {
383                     const sal_Int64 nRed = pItem->GetValue();
384                     mpMtrRed->SetValue( nRed );
385                 }
386             }
387             else if(SFX_ITEM_DISABLED == eState)
388             {
389                 mpMtrRed->Disable();
390             }
391             else
392             {
393                 mpMtrRed->Enable();
394                 mpMtrRed->SetText(String());
395             }
396             break;
397         }
398         case SID_ATTR_GRAF_GREEN:
399         {
400             if(eState >= SFX_ITEM_AVAILABLE)
401             {
402                 mpMtrGreen->Enable();
403                 const SfxInt16Item* pItem = dynamic_cast< const SfxInt16Item* >(pState);
404 
405                 if(pItem)
406                 {
407                     const sal_Int64 nGreen = pItem->GetValue();
408                     mpMtrGreen->SetValue( nGreen );
409                 }
410             }
411             else if(SFX_ITEM_DISABLED == eState)
412             {
413                 mpMtrGreen->Disable();
414             }
415             else
416             {
417                 mpMtrGreen->Enable();
418                 mpMtrGreen->SetText(String());
419             }
420             break;
421         }
422         case SID_ATTR_GRAF_BLUE:
423         {
424             if(eState >= SFX_ITEM_AVAILABLE)
425             {
426                 mpMtrBlue->Enable();
427                 const SfxInt16Item* pItem = dynamic_cast< const SfxInt16Item* >(pState);
428 
429                 if(pItem)
430                 {
431                     const sal_Int64 nBlue = pItem->GetValue();
432                     mpMtrBlue->SetValue( nBlue );
433                 }
434             }
435             else if(SFX_ITEM_DISABLED == eState)
436             {
437                 mpMtrBlue->Disable();
438             }
439             else
440             {
441                 mpMtrBlue->Enable();
442                 mpMtrBlue->SetText(String());
443             }
444             break;
445         }
446         case SID_ATTR_GRAF_GAMMA:
447         {
448             if(eState >= SFX_ITEM_AVAILABLE)
449             {
450                 mpMtrGamma->Enable();
451                 const SfxUInt32Item* pItem = dynamic_cast< const SfxUInt32Item* >(pState);
452 
453                 if(pItem)
454                 {
455                     const sal_Int64 nGamma = pItem->GetValue();
456                     mpMtrGamma->SetValue( nGamma );
457                 }
458             }
459             else if(SFX_ITEM_DISABLED == eState)
460             {
461                 mpMtrGamma->Disable();
462             }
463             else
464             {
465                 mpMtrGamma->Enable();
466                 mpMtrGamma->SetText(String());
467             }
468             break;
469         }
470     }
471 }
472 
473 
474 
475 
476 //////////////////////////////////////////////////////////////////////////////
477 
478 SfxBindings* GraphicPropertyPanel::GetBindings()
479 {
480     return mpBindings;
481 }
482 
483 //////////////////////////////////////////////////////////////////////////////
484 // namespace close
485 
486 }} // end of namespace ::svx::sidebar
487 
488 //////////////////////////////////////////////////////////////////////////////
489 // eof
490