xref: /trunk/main/svx/source/sidebar/graphic/GraphicPropertyPanel.cxx (revision 8dcb2a100eb78f12871a9e67d867e1bc0c7bdb07)
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     maContext(),
89     mpBindings(pBindings)
90 {
91     Initialize();
92     FreeResource();
93 }
94 
95 //////////////////////////////////////////////////////////////////////////////
96 
97 GraphicPropertyPanel::~GraphicPropertyPanel()
98 {
99 }
100 
101 //////////////////////////////////////////////////////////////////////////////
102 
103 void GraphicPropertyPanel::Initialize()
104 {
105     mpMtrBrightness->SetModifyHdl( LINK( this, GraphicPropertyPanel, ModifyBrightnessHdl ) );
106     mpMtrBrightness->SetAccessibleName(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Brightness")));    //wj acc
107     mpMtrContrast->SetModifyHdl( LINK( this, GraphicPropertyPanel, ModifyContrastHdl ) );
108     mpMtrContrast->SetAccessibleName(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Contrast")));    //wj acc
109     mpMtrTrans->SetModifyHdl( LINK( this, GraphicPropertyPanel, ModifyTransHdl ) );
110     mpMtrTrans->SetAccessibleName(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Transparency")));   //wj acc
111 
112     mpLBColorMode->InsertEntry( msNormal, maImgNormal );
113     mpLBColorMode->InsertEntry( msGray, maImgGray );
114     mpLBColorMode->InsertEntry( msBW, maImgBW );
115     mpLBColorMode->InsertEntry( msWater, maImgWater );
116     mpLBColorMode->SetSelectHdl( LINK( this, GraphicPropertyPanel, ClickColorModeHdl ));
117     mpLBColorMode->SetAccessibleName(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Color mode")));  //wj acc
118 
119     mpMtrRed->SetModifyHdl( LINK( this, GraphicPropertyPanel, RedHdl ) );
120     mpMtrGreen->SetModifyHdl( LINK( this, GraphicPropertyPanel, GreenHdl ) );
121     mpMtrBlue->SetModifyHdl( LINK( this, GraphicPropertyPanel, BlueHdl ) );
122     mpMtrGamma->SetModifyHdl( LINK( this, GraphicPropertyPanel, GammaHdl ) );
123     mpMtrRed->SetAccessibleName(mpMtrRed->GetQuickHelpText());  //wj acc
124     mpMtrGreen->SetAccessibleName(mpMtrGreen->GetQuickHelpText());  //wj acc
125     mpMtrBlue->SetAccessibleName(mpMtrBlue->GetQuickHelpText());        //wj acc
126     mpMtrGamma->SetAccessibleName(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Gamma value")));    //wj acc
127 
128     mpMtrRed->SetAccessibleRelationLabeledBy(mpMtrRed.get());
129     mpMtrGreen->SetAccessibleRelationLabeledBy(mpMtrGreen.get());
130     mpMtrBlue->SetAccessibleRelationLabeledBy(mpMtrBlue.get());
131     mpMtrGamma->SetAccessibleRelationLabeledBy(mpMtrGamma.get());
132     mpMtrBrightness->SetAccessibleRelationLabeledBy(mpFtBrightness.get());  //7874
133     mpMtrContrast->SetAccessibleRelationLabeledBy(mpFtContrast.get());  //7874
134     mpMtrTrans->SetAccessibleRelationLabeledBy(mpFtTrans.get());    //7874
135     mpLBColorMode->SetAccessibleRelationLabeledBy(mpFtColorMode.get()); //7874
136 }
137 
138 //////////////////////////////////////////////////////////////////////////////
139 
140 IMPL_LINK( GraphicPropertyPanel, ModifyBrightnessHdl, void *, EMPTYARG )
141 {
142     sal_Int16 nBright = mpMtrBrightness->GetValue();
143     SfxInt16Item aBrightItem( SID_ATTR_GRAF_LUMINANCE, nBright );
144     GetBindings()->GetDispatcher()->Execute(
145         SID_ATTR_GRAF_LUMINANCE, SFX_CALLMODE_RECORD, &aBrightItem, 0L);
146     return 0L;
147 }
148 
149 //////////////////////////////////////////////////////////////////////////////
150 
151 IMPL_LINK( GraphicPropertyPanel, ModifyContrastHdl, void *, EMPTYARG )
152 {
153     sal_Int16 nContrast = mpMtrContrast->GetValue();
154     SfxInt16Item aContrastItem( SID_ATTR_GRAF_CONTRAST, nContrast );
155     GetBindings()->GetDispatcher()->Execute(
156         SID_ATTR_GRAF_CONTRAST, SFX_CALLMODE_RECORD, &aContrastItem, 0L);
157     return 0L;
158 }
159 
160 //////////////////////////////////////////////////////////////////////////////
161 
162 IMPL_LINK( GraphicPropertyPanel, ModifyTransHdl, void *, EMPTYARG )
163 {
164     sal_Int16 nTrans = mpMtrTrans->GetValue();
165     SfxInt16Item aTransItem( SID_ATTR_GRAF_TRANSPARENCE, nTrans );
166     GetBindings()->GetDispatcher()->Execute(
167         SID_ATTR_GRAF_TRANSPARENCE, SFX_CALLMODE_RECORD, &aTransItem, 0L);
168     return 0L;
169 }
170 
171 //////////////////////////////////////////////////////////////////////////////
172 
173 IMPL_LINK( GraphicPropertyPanel, ClickColorModeHdl, ToolBox *, pBox )
174 {
175     sal_Int16 nTrans = mpLBColorMode->GetSelectEntryPos();
176     SfxInt16Item aTransItem( SID_ATTR_GRAF_MODE, nTrans );
177     GetBindings()->GetDispatcher()->Execute(
178         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     sal_Int16 nRed = mpMtrRed->GetValue();
187     SfxInt16Item aRedItem( SID_ATTR_GRAF_RED, nRed );
188     GetBindings()->GetDispatcher()->Execute(
189         SID_ATTR_GRAF_RED, SFX_CALLMODE_RECORD, &aRedItem, 0L);
190     return 0L;
191 }
192 
193 //////////////////////////////////////////////////////////////////////////////
194 
195 IMPL_LINK( GraphicPropertyPanel, GreenHdl, void*, EMPTYARG )
196 {
197     sal_Int16 nGreen = mpMtrGreen->GetValue();
198     SfxInt16Item aGreenItem( SID_ATTR_GRAF_GREEN, nGreen );
199     GetBindings()->GetDispatcher()->Execute(
200         SID_ATTR_GRAF_GREEN, SFX_CALLMODE_RECORD, &aGreenItem, 0L);
201     return 0L;
202 }
203 
204 //////////////////////////////////////////////////////////////////////////////
205 
206 IMPL_LINK(GraphicPropertyPanel, BlueHdl, void *, EMPTYARG)
207 {
208     sal_Int16 nBlue = mpMtrBlue->GetValue();
209     SfxInt16Item aBlueItem( SID_ATTR_GRAF_BLUE, nBlue );
210     GetBindings()->GetDispatcher()->Execute(
211         SID_ATTR_GRAF_BLUE, SFX_CALLMODE_RECORD, &aBlueItem, 0L);
212     return 0L;
213 }
214 
215 //////////////////////////////////////////////////////////////////////////////
216 
217 IMPL_LINK(GraphicPropertyPanel, GammaHdl, void *, EMPTYARG)
218 {
219     sal_Int32 nGamma = mpMtrGamma->GetValue();
220     SfxInt32Item nGammaItem( SID_ATTR_GRAF_GAMMA, nGamma );
221     GetBindings()->GetDispatcher()->Execute(
222         SID_ATTR_GRAF_GAMMA, SFX_CALLMODE_RECORD, &nGammaItem, 0L);
223     return 0L;
224 }
225 
226 //////////////////////////////////////////////////////////////////////////////
227 
228 void GraphicPropertyPanel::SetupIcons(void)
229 {
230     if(Theme::GetBoolean(Theme::Bool_UseSymphonyIcons))
231     {
232         // todo
233     }
234     else
235     {
236         // todo
237     }
238 }
239 
240 //////////////////////////////////////////////////////////////////////////////
241 
242 GraphicPropertyPanel* GraphicPropertyPanel::Create (
243     Window* pParent,
244     const cssu::Reference<css::frame::XFrame>& rxFrame,
245     SfxBindings* pBindings)
246 {
247     if (pParent == NULL)
248         throw lang::IllegalArgumentException(A2S("no parent Window given to GraphicPropertyPanel::Create"), NULL, 0);
249     if ( ! rxFrame.is())
250         throw lang::IllegalArgumentException(A2S("no XFrame given to GraphicPropertyPanel::Create"), NULL, 1);
251     if (pBindings == NULL)
252         throw lang::IllegalArgumentException(A2S("no SfxBindings given to GraphicPropertyPanel::Create"), NULL, 2);
253 
254     return new GraphicPropertyPanel(
255         pParent,
256         rxFrame,
257         pBindings);
258 }
259 
260 //////////////////////////////////////////////////////////////////////////////
261 
262 void GraphicPropertyPanel::DataChanged(
263     const DataChangedEvent& rEvent)
264 {
265     (void)rEvent;
266 
267     SetupIcons();
268 }
269 
270 //////////////////////////////////////////////////////////////////////////////
271 
272 void GraphicPropertyPanel::HandleContextChange(
273     const ::sfx2::sidebar::EnumContext aContext)
274 {
275     if(maContext == aContext)
276     {
277         // Nothing to do.
278         return;
279     }
280 
281     maContext = aContext;
282 
283 
284 
285     // todo
286 }
287 
288 //////////////////////////////////////////////////////////////////////////////
289 
290 void GraphicPropertyPanel::NotifyItemUpdate(
291     sal_uInt16 nSID,
292     SfxItemState eState,
293     const SfxPoolItem* pState)
294 {
295     switch( nSID )
296     {
297     case SID_ATTR_GRAF_LUMINANCE:
298         if( eState >= SFX_ITEM_AVAILABLE)
299         {
300             mpMtrBrightness->Enable();
301             const SfxInt16Item* pItem = dynamic_cast< const SfxInt16Item* >(pState);
302 
303             if(pItem)
304             {
305                 sal_Int64 nBright = pItem->GetValue();
306                 mpMtrBrightness->SetValue(nBright);
307             }
308         }
309         else if( eState == SFX_ITEM_DISABLED )
310             mpMtrBrightness->Disable();
311         else
312         {
313             mpMtrBrightness->Enable();
314             mpMtrBrightness->SetText( String());
315         }
316         break;
317     case SID_ATTR_GRAF_CONTRAST:
318         if( eState >= SFX_ITEM_AVAILABLE)
319         {
320             mpMtrContrast->Enable();
321             const SfxInt16Item* pItem = dynamic_cast< const SfxInt16Item* >(pState);
322 
323             if(pItem)
324             {
325                 sal_Int64 nContrast = pItem->GetValue();
326                 mpMtrContrast->SetValue(nContrast);
327             }
328         }
329         else if( eState == SFX_ITEM_DISABLED )
330             mpMtrContrast->Disable();
331         else
332         {
333             mpMtrContrast->Enable();
334             mpMtrContrast->SetText( String());
335         }
336         break;
337     case SID_ATTR_GRAF_TRANSPARENCE:
338         if( eState >= SFX_ITEM_AVAILABLE)
339         {
340             mpMtrTrans->Enable();
341             const SfxUInt16Item* pItem = dynamic_cast< const SfxUInt16Item* >(pState);
342 
343             if(pItem)
344             {
345                 sal_Int64 nTrans = pItem->GetValue();
346                 mpMtrTrans->SetValue(nTrans);
347             }
348         }
349         else if( eState == SFX_ITEM_DISABLED )
350             mpMtrTrans->Disable();
351         else
352         {
353             mpMtrTrans->Enable();
354             mpMtrTrans->SetText( String());
355         }
356         break;
357     case SID_ATTR_GRAF_MODE:
358         if( eState >= SFX_ITEM_AVAILABLE)
359         {
360             mpLBColorMode->Enable();
361             const SfxUInt16Item* pItem = dynamic_cast< const SfxUInt16Item* >(pState);
362 
363             if(pItem)
364             {
365                 sal_Int64 nTrans = pItem->GetValue();
366                 mpLBColorMode->SelectEntryPos(nTrans);
367             }
368         }
369         else if( eState == SFX_ITEM_DISABLED )
370             mpLBColorMode->Disable();
371         else
372         {
373             mpLBColorMode->Enable();
374             mpLBColorMode->SetNoSelection();
375         }
376         break;
377     case SID_ATTR_GRAF_RED:
378         if( eState >= SFX_ITEM_AVAILABLE)
379         {
380             mpMtrRed->Enable();
381             const SfxInt16Item* pItem = dynamic_cast< const SfxInt16Item* >(pState);
382 
383             if(pItem)
384             {
385                 sal_Int64 nRed = pItem->GetValue();
386                 mpMtrRed->SetValue( nRed );
387             }
388         }
389         else if( eState == SFX_ITEM_DISABLED )
390             mpMtrRed->Disable();
391         else
392         {
393             mpMtrRed->Enable();
394             mpMtrRed->SetText( String());
395         }
396         break;
397     case SID_ATTR_GRAF_GREEN:
398         if( eState >= SFX_ITEM_AVAILABLE)
399         {
400             mpMtrGreen->Enable();
401             const SfxInt16Item* pItem = dynamic_cast< const SfxInt16Item* >(pState);
402 
403             if(pItem)
404             {
405                 sal_Int64 nGreen = pItem->GetValue();
406                 mpMtrGreen->SetValue( nGreen );
407             }
408         }
409         else if( eState == SFX_ITEM_DISABLED )
410             mpMtrGreen->Disable();
411         else
412         {
413             mpMtrGreen->Enable();
414             mpMtrGreen->SetText( String());
415         }
416         break;
417     case SID_ATTR_GRAF_BLUE:
418         if( eState >= SFX_ITEM_AVAILABLE)
419         {
420             mpMtrBlue->Enable();
421             const SfxInt16Item* pItem = dynamic_cast< const SfxInt16Item* >(pState);
422 
423             if(pItem)
424             {
425                 sal_Int64 nBlue = pItem->GetValue();
426                 mpMtrBlue->SetValue( nBlue );
427             }
428         }
429         else if( eState == SFX_ITEM_DISABLED )
430             mpMtrBlue->Disable();
431         else
432         {
433             mpMtrBlue->Enable();
434             mpMtrBlue->SetText( String());
435         }
436         break;
437     case SID_ATTR_GRAF_GAMMA:
438         if( eState >= SFX_ITEM_AVAILABLE)
439         {
440             mpMtrGamma->Enable();
441             const SfxUInt32Item* pItem = dynamic_cast< const SfxUInt32Item* >(pState);
442 
443             if(pItem)
444             {
445                 sal_Int64 nGamma = pItem->GetValue();
446                 mpMtrGamma->SetValue( nGamma );
447             }
448         }
449         else if( eState == SFX_ITEM_DISABLED )
450             mpMtrGamma->Disable();
451         else
452         {
453             mpMtrGamma->Enable();
454             mpMtrGamma->SetText( String());
455         }
456         break;
457     }
458 }
459 
460 //////////////////////////////////////////////////////////////////////////////
461 
462 SfxBindings* GraphicPropertyPanel::GetBindings()
463 {
464     return mpBindings;
465 }
466 
467 //////////////////////////////////////////////////////////////////////////////
468 // namespace close
469 
470 }} // end of namespace ::svx::sidebar
471 
472 //////////////////////////////////////////////////////////////////////////////
473 // eof
474