1b9e67834SAndre Fischer /**************************************************************
2*6469a737Smseidel  *
3b9e67834SAndre Fischer  * Licensed to the Apache Software Foundation (ASF) under one
4b9e67834SAndre Fischer  * or more contributor license agreements.  See the NOTICE file
5b9e67834SAndre Fischer  * distributed with this work for additional information
6b9e67834SAndre Fischer  * regarding copyright ownership.  The ASF licenses this file
7b9e67834SAndre Fischer  * to you under the Apache License, Version 2.0 (the
8b9e67834SAndre Fischer  * "License"); you may not use this file except in compliance
9b9e67834SAndre Fischer  * with the License.  You may obtain a copy of the License at
10*6469a737Smseidel  *
11b9e67834SAndre Fischer  *   http://www.apache.org/licenses/LICENSE-2.0
12*6469a737Smseidel  *
13b9e67834SAndre Fischer  * Unless required by applicable law or agreed to in writing,
14b9e67834SAndre Fischer  * software distributed under the License is distributed on an
15b9e67834SAndre Fischer  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16b9e67834SAndre Fischer  * KIND, either express or implied.  See the License for the
17b9e67834SAndre Fischer  * specific language governing permissions and limitations
18b9e67834SAndre Fischer  * under the License.
19*6469a737Smseidel  *
20b9e67834SAndre Fischer  *************************************************************/
21b9e67834SAndre Fischer 
22*6469a737Smseidel 
23*6469a737Smseidel 
24b9e67834SAndre Fischer #include "precompiled_svx.hxx"
25d4aefcaeSZheng Fan #include "TextUnderlineControl.hxx"
26d4aefcaeSZheng Fan #include "TextPropertyPanel.hrc"
27d29c2fc2SAndre Fischer #include <sfx2/sidebar/ResourceDefinitions.hrc>
28d4aefcaeSZheng Fan #include <svx/dialogs.hrc>
29d4aefcaeSZheng Fan #include <svx/dialmgr.hxx>
30d4aefcaeSZheng Fan #include <unotools/viewoptions.hxx>
31d4aefcaeSZheng Fan #include <editeng/kernitem.hxx>
32d4aefcaeSZheng Fan #include <sfx2/bindings.hxx>
33d4aefcaeSZheng Fan #include <sfx2/dispatch.hxx>
34d4aefcaeSZheng Fan #include <sfx2/sidebar/Theme.hxx>
35d4aefcaeSZheng Fan #include <editeng/udlnitem.hxx>
36d4aefcaeSZheng Fan 
37d4aefcaeSZheng Fan namespace svx { namespace sidebar {
38d4aefcaeSZheng Fan 
TextUnderlineControl(Window * pParent,svx::sidebar::TextPropertyPanel & rPanel,SfxBindings * pBindings)3945da7d5eSAndre Fischer TextUnderlineControl::TextUnderlineControl (
40*6469a737Smseidel 	Window* pParent,
41*6469a737Smseidel 	svx::sidebar::TextPropertyPanel& rPanel,
42*6469a737Smseidel 	SfxBindings* pBindings)
43d4aefcaeSZheng Fan :	svx::sidebar::PopupControl( pParent,SVX_RES(RID_POPUPPANEL_TEXTPAGE_UNDERLINE))
44d4aefcaeSZheng Fan ,	mrTextPropertyPanel(rPanel)
4545da7d5eSAndre Fischer ,	mpBindings(pBindings)
46b9e67834SAndre Fischer ,	maVSUnderline( this, SVX_RES(VS_UNDERLINE))
47d4aefcaeSZheng Fan ,	maPBOptions	(this, SVX_RES(PB_OPTIONS) )
48b9e67834SAndre Fischer 
49b9e67834SAndre Fischer ,	maIMGSingle		(SVX_RES(IMG_SINGLE))
50b9e67834SAndre Fischer ,	maIMGDouble		(SVX_RES(IMG_DOUBLE))
51b9e67834SAndre Fischer ,	maIMGBold		(SVX_RES(IMG_BOLD2))
52b9e67834SAndre Fischer ,	maIMGDot		(SVX_RES(IMG_DOT))
53b9e67834SAndre Fischer ,	maIMGDotBold	(SVX_RES(IMG_DOT_BOLD))
54b9e67834SAndre Fischer ,	maIMGDash		(SVX_RES(IMG_DASH))
55b9e67834SAndre Fischer ,	maIMGDashLong	(SVX_RES(IMG_DASH_LONG))
56b9e67834SAndre Fischer ,	maIMGDashDot	(SVX_RES(IMG_DASH_DOT))
57b9e67834SAndre Fischer ,	maIMGDashDotDot	(SVX_RES(IMG_DASH_DOT_DOT))
58b9e67834SAndre Fischer ,	maIMGWave		(SVX_RES(IMG_WAVE))
59b9e67834SAndre Fischer 
60b9e67834SAndre Fischer // high contrast
61b9e67834SAndre Fischer ,	maIMGSingleH	(SVX_RES(IMG_SINGLE_H))
62b9e67834SAndre Fischer ,	maIMGDoubleH	(SVX_RES(IMG_DOUBLE_H))
63b9e67834SAndre Fischer ,	maIMGBoldH		(SVX_RES(IMG_BOLD2_H))
64b9e67834SAndre Fischer ,	maIMGDotH		(SVX_RES(IMG_DOT_H))
65b9e67834SAndre Fischer ,	maIMGDotBoldH	(SVX_RES(IMG_DOT_BOLD_H))
66b9e67834SAndre Fischer ,	maIMGDashH		(SVX_RES(IMG_DASH_H))
67b9e67834SAndre Fischer ,	maIMGDashLongH	(SVX_RES(IMG_DASH_LONG_H))
68b9e67834SAndre Fischer ,	maIMGDashDotH	(SVX_RES(IMG_DASH_DOT_H))
69b9e67834SAndre Fischer ,	maIMGDashDotDotH(SVX_RES(IMG_DASH_DOT_DOT_H))
70b9e67834SAndre Fischer ,	maIMGWaveH		(SVX_RES(IMG_WAVE_H))
71b9e67834SAndre Fischer 
72b9e67834SAndre Fischer ,	maIMGSingleSel		(SVX_RES(IMG_SINGLE_SEL))
73b9e67834SAndre Fischer ,	maIMGDoubleSel		(SVX_RES(IMG_DOUBLE_SEL))
74b9e67834SAndre Fischer ,	maIMGBoldSel		(SVX_RES(IMG_BOLD2_SEL))
75b9e67834SAndre Fischer ,	maIMGDotSel			(SVX_RES(IMG_DOT_SEL))
76b9e67834SAndre Fischer ,	maIMGDotBoldSel		(SVX_RES(IMG_DOT_BOLD_SEL))
77b9e67834SAndre Fischer ,	maIMGDashSel		(SVX_RES(IMG_DASH_SEL))
78b9e67834SAndre Fischer ,	maIMGDashLongSel	(SVX_RES(IMG_DASH_LONG_SEL))
79b9e67834SAndre Fischer ,	maIMGDashDotSel		(SVX_RES(IMG_DASH_DOT_SEL))
80b9e67834SAndre Fischer ,	maIMGDashDotDotSel	(SVX_RES(IMG_DASH_DOT_DOT_SEL))
81b9e67834SAndre Fischer ,	maIMGWaveSel		(SVX_RES(IMG_WAVE_SEL))
82b9e67834SAndre Fischer 
83b9e67834SAndre Fischer {
84b9e67834SAndre Fischer 	initial();
85b9e67834SAndre Fischer 	FreeResource();
86b9e67834SAndre Fischer }
87b9e67834SAndre Fischer 
initial()88d4aefcaeSZheng Fan void TextUnderlineControl::initial()
89b9e67834SAndre Fischer {
90*6469a737Smseidel 	maVSUnderline.SetColor(GetSettings().GetStyleSettings().GetHighContrastMode()?
91*6469a737Smseidel 		GetSettings().GetStyleSettings().GetMenuColor():
92*6469a737Smseidel 		sfx2::sidebar::Theme::GetColor( sfx2::sidebar::Theme::Paint_PanelBackground ));
93*6469a737Smseidel 	maVSUnderline.SetBackground(GetSettings().GetStyleSettings().GetHighContrastMode()?
94*6469a737Smseidel 		GetSettings().GetStyleSettings().GetMenuColor():
95*6469a737Smseidel 		sfx2::sidebar::Theme::GetColor( sfx2::sidebar::Theme::Paint_PanelBackground ));
96b9e67834SAndre Fischer 
97*6469a737Smseidel 	Link aLink = LINK( this, TextUnderlineControl, PBClickHdl ) ;
98*6469a737Smseidel 	maPBOptions.SetClickHdl(aLink);
99b9e67834SAndre Fischer 
100*6469a737Smseidel 	maVSUnderline.SetStyle( maVSUnderline.GetStyle()| WB_3DLOOK | WB_NO_DIRECTSELECT );
101b9e67834SAndre Fischer 
102*6469a737Smseidel 	// 'none' item
103*6469a737Smseidel 	maVSUnderline.SetStyle( maVSUnderline.GetStyle()| WB_NONEFIELD | WB_MENUSTYLEVALUESET );
104*6469a737Smseidel 	maVSUnderline.SetText( String(SVX_RES(STR_WITHOUT) ) );
105b9e67834SAndre Fischer 
106*6469a737Smseidel 	maVSUnderline.InsertItem(1, maIMGSingle ,String(SVX_RES(STR_SINGLE)));
107*6469a737Smseidel 	maVSUnderline.SetItemData(1, (void*)(sal_uInt64)UNDERLINE_SINGLE);
108b9e67834SAndre Fischer 
109*6469a737Smseidel 	maVSUnderline.InsertItem(2, maIMGDouble ,String(SVX_RES(STR_DOUBLE)));
110*6469a737Smseidel 	maVSUnderline.SetItemData(2, (void*)(sal_uInt64)UNDERLINE_DOUBLE);
111b9e67834SAndre Fischer 
112*6469a737Smseidel 	maVSUnderline.InsertItem(3, maIMGBold, String(SVX_RES(STR_BOLD)));
113*6469a737Smseidel 	maVSUnderline.SetItemData(3,(void*)(sal_uInt64)UNDERLINE_BOLD);
114b9e67834SAndre Fischer 
115*6469a737Smseidel 	maVSUnderline.InsertItem(4, maIMGDot, String(SVX_RES(STR_DOT)));
116*6469a737Smseidel 	maVSUnderline.SetItemData(4,(void*)(sal_uInt64)UNDERLINE_DOTTED);
117b9e67834SAndre Fischer 
118*6469a737Smseidel 	maVSUnderline.InsertItem(5, maIMGDotBold, String(SVX_RES(STR_DOT_BOLD)));
119*6469a737Smseidel 	maVSUnderline.SetItemData(5,(void*)(sal_uInt64)UNDERLINE_BOLDDOTTED);
120b9e67834SAndre Fischer 
121*6469a737Smseidel 	maVSUnderline.InsertItem(6, maIMGDash, String(SVX_RES(STR_DASH)));
122*6469a737Smseidel 	maVSUnderline.SetItemData(6,(void*)(sal_uInt64)UNDERLINE_DASH);
123b9e67834SAndre Fischer 
124*6469a737Smseidel 	maVSUnderline.InsertItem(7, maIMGDashLong,String(SVX_RES(STR_DASH_LONG)));
125*6469a737Smseidel 	maVSUnderline.SetItemData(7,(void*)(sal_uInt64)UNDERLINE_LONGDASH);
126b9e67834SAndre Fischer 
127*6469a737Smseidel 	maVSUnderline.InsertItem(8, maIMGDashDot, String(SVX_RES(STR_DASH_DOT)));
128*6469a737Smseidel 	maVSUnderline.SetItemData(8,(void*)(sal_uInt64)UNDERLINE_DASHDOT);
129b9e67834SAndre Fischer 
130*6469a737Smseidel 	maVSUnderline.InsertItem(9, maIMGDashDotDot, String(SVX_RES(STR_DASH_DOT_DOT)));
131*6469a737Smseidel 	maVSUnderline.SetItemData(9,(void*)(sal_uInt64)UNDERLINE_DASHDOTDOT);
132b9e67834SAndre Fischer 
133*6469a737Smseidel 	maVSUnderline.InsertItem(10, maIMGWave, String(SVX_RES(STR_WAVE)));
134*6469a737Smseidel 	maVSUnderline.SetItemData(10,(void*)(sal_uInt64)UNDERLINE_WAVE);
135a3586beeSOliver-Rainer Wittmann 
136*6469a737Smseidel 	maVSUnderline.SetColCount( 1 );
137*6469a737Smseidel 	aLink = LINK( this, TextUnderlineControl, VSSelectHdl ) ;
138*6469a737Smseidel 	maVSUnderline.SetSelectHdl(aLink);
139b9e67834SAndre Fischer 
140*6469a737Smseidel 	maVSUnderline.StartSelection();
141*6469a737Smseidel 	maVSUnderline.Show();
142b9e67834SAndre Fischer }
143b9e67834SAndre Fischer 
144900fdb6dSOliver-Rainer Wittmann 
Rearrange(FontUnderline eLine)145d4aefcaeSZheng Fan void TextUnderlineControl::Rearrange(FontUnderline eLine)
146b9e67834SAndre Fischer {
147b9e67834SAndre Fischer 	// high contrast
148*6469a737Smseidel 	maVSUnderline.SetItemImage(1, GetDisplayBackground().GetColor().IsDark()? maIMGSingleH :maIMGSingle);
149*6469a737Smseidel 	maVSUnderline.SetItemImage(2, GetDisplayBackground().GetColor().IsDark()? maIMGDoubleH : maIMGDouble );
150b9e67834SAndre Fischer 	maVSUnderline.SetItemImage(3, GetDisplayBackground().GetColor().IsDark()? maIMGBoldH : maIMGBold);
151b9e67834SAndre Fischer 	maVSUnderline.SetItemImage(4, GetDisplayBackground().GetColor().IsDark()? maIMGDotH : maIMGDot);
152b9e67834SAndre Fischer 	maVSUnderline.SetItemImage(5, GetDisplayBackground().GetColor().IsDark()? maIMGDotBoldH :maIMGDotBold);
153*6469a737Smseidel 	maVSUnderline.SetItemImage(6, GetDisplayBackground().GetColor().IsDark()? maIMGDashH :maIMGDash);
154b9e67834SAndre Fischer 	maVSUnderline.SetItemImage(7, GetDisplayBackground().GetColor().IsDark()? maIMGDashLongH : maIMGDashLong);
155*6469a737Smseidel 	maVSUnderline.SetItemImage(8, GetDisplayBackground().GetColor().IsDark()? maIMGDashDotH : maIMGDashDot);
156b9e67834SAndre Fischer 	maVSUnderline.SetItemImage(9, GetDisplayBackground().GetColor().IsDark()? maIMGDashDotDotH : maIMGDashDotDot);
157b9e67834SAndre Fischer 	maVSUnderline.SetItemImage(10, GetDisplayBackground().GetColor().IsDark()? maIMGWaveH : maIMGWave);
158b9e67834SAndre Fischer 
159*6469a737Smseidel 	switch(eLine)
160*6469a737Smseidel 	{
161*6469a737Smseidel 	case UNDERLINE_SINGLE:
162*6469a737Smseidel 		maVSUnderline.SetItemImage(1, maIMGSingleSel);
163*6469a737Smseidel 		maVSUnderline.SelectItem(1);
164*6469a737Smseidel 		maVSUnderline.GrabFocus();
165*6469a737Smseidel 		break;
166*6469a737Smseidel 	case UNDERLINE_DOUBLE:
167*6469a737Smseidel 		maVSUnderline.SetItemImage(2, maIMGDoubleSel);
168*6469a737Smseidel 		maVSUnderline.SelectItem(2);
169*6469a737Smseidel 		maVSUnderline.GrabFocus();
170*6469a737Smseidel 		break;
171*6469a737Smseidel 	case UNDERLINE_BOLD:
172*6469a737Smseidel 		maVSUnderline.SetItemImage(3, maIMGBoldSel);
173*6469a737Smseidel 		maVSUnderline.SelectItem(3);
174*6469a737Smseidel 		maVSUnderline.GrabFocus();
175*6469a737Smseidel 		break;
176*6469a737Smseidel 	case UNDERLINE_DOTTED:
177*6469a737Smseidel 		maVSUnderline.SetItemImage(4, maIMGDotSel);
178*6469a737Smseidel 		maVSUnderline.SelectItem(4);
179*6469a737Smseidel 		maVSUnderline.GrabFocus();
180*6469a737Smseidel 		break;
181*6469a737Smseidel 	case UNDERLINE_BOLDDOTTED:
182*6469a737Smseidel 		maVSUnderline.SetItemImage(5, maIMGDotBoldSel);
183*6469a737Smseidel 		maVSUnderline.SelectItem(5);
184*6469a737Smseidel 		maVSUnderline.GrabFocus();
185*6469a737Smseidel 		break;
186*6469a737Smseidel 	case UNDERLINE_DASH:
187*6469a737Smseidel 		maVSUnderline.SetItemImage(6, maIMGDashSel);
188*6469a737Smseidel 		maVSUnderline.SelectItem(6);
189*6469a737Smseidel 		maVSUnderline.GrabFocus();
190*6469a737Smseidel 		break;
191*6469a737Smseidel 	case UNDERLINE_LONGDASH:
192*6469a737Smseidel 		maVSUnderline.SetItemImage(7, maIMGDashLongSel);
193*6469a737Smseidel 		maVSUnderline.SelectItem(7);
194*6469a737Smseidel 		maVSUnderline.GrabFocus();
195*6469a737Smseidel 		break;
196*6469a737Smseidel 	case UNDERLINE_DASHDOT:
197*6469a737Smseidel 		maVSUnderline.SetItemImage(8, maIMGDashDotSel);
198*6469a737Smseidel 		maVSUnderline.SelectItem(8);
199*6469a737Smseidel 		maVSUnderline.GrabFocus();
200*6469a737Smseidel 		break;
201*6469a737Smseidel 	case UNDERLINE_DASHDOTDOT:
202*6469a737Smseidel 		maVSUnderline.SetItemImage(9, maIMGDashDotDotSel);
203*6469a737Smseidel 		maVSUnderline.SelectItem(9);
204*6469a737Smseidel 		maVSUnderline.GrabFocus();
205*6469a737Smseidel 		break;
206*6469a737Smseidel 	case UNDERLINE_WAVE:
207*6469a737Smseidel 		maVSUnderline.SetItemImage(10, maIMGWaveSel);
208*6469a737Smseidel 		maVSUnderline.SelectItem(10);
209*6469a737Smseidel 		maVSUnderline.GrabFocus();
210*6469a737Smseidel 		break;
211*6469a737Smseidel 	case UNDERLINE_NONE:
212*6469a737Smseidel 		maVSUnderline.SelectItem(0);
213*6469a737Smseidel 		maVSUnderline.GrabFocus();
214*6469a737Smseidel 		break;
215*6469a737Smseidel 	default:
216*6469a737Smseidel 		maVSUnderline.SelectItem(1);
217*6469a737Smseidel 		maVSUnderline.SetNoSelection();
218*6469a737Smseidel 		maPBOptions.GrabFocus();
219*6469a737Smseidel 	}
220*6469a737Smseidel 	maVSUnderline.StartSelection();
221b9e67834SAndre Fischer }
222900fdb6dSOliver-Rainer Wittmann 
223900fdb6dSOliver-Rainer Wittmann 
IMPL_LINK(TextUnderlineControl,VSSelectHdl,void *,pControl)224d4aefcaeSZheng Fan IMPL_LINK(TextUnderlineControl, VSSelectHdl, void *, pControl)
225b9e67834SAndre Fischer {
226*6469a737Smseidel 	if ( pControl == &maVSUnderline )
227*6469a737Smseidel 	{
228*6469a737Smseidel 		const sal_uInt16 iPos = maVSUnderline.GetSelectItemId();
229*6469a737Smseidel 		const FontUnderline eUnderline = ( iPos == 0 )
230*6469a737Smseidel 										 ? UNDERLINE_NONE
231*6469a737Smseidel 										 : (FontUnderline)(sal_uInt64)maVSUnderline.GetItemData( iPos );
232b9e67834SAndre Fischer 
233*6469a737Smseidel 		SvxUnderlineItem aLineItem(eUnderline, SID_ATTR_CHAR_UNDERLINE);
234b9e67834SAndre Fischer 
235*6469a737Smseidel 		aLineItem.SetColor(mrTextPropertyPanel.GetUnderlineColor());
236*6469a737Smseidel 		mpBindings->GetDispatcher()->Execute(SID_ATTR_CHAR_UNDERLINE, SFX_CALLMODE_RECORD, &aLineItem, 0L);
237b9e67834SAndre Fischer 
238*6469a737Smseidel 		mrTextPropertyPanel.SetUnderline(eUnderline);
239b9e67834SAndre Fischer 
240*6469a737Smseidel 		mrTextPropertyPanel.EndUnderlinePopupMode();
241*6469a737Smseidel 	}
242*6469a737Smseidel 	return( 0L );
243b9e67834SAndre Fischer }
244b9e67834SAndre Fischer 
IMPL_LINK(TextUnderlineControl,PBClickHdl,PushButton *,pPBtn)245d4aefcaeSZheng Fan IMPL_LINK(TextUnderlineControl, PBClickHdl, PushButton *, pPBtn)
246b9e67834SAndre Fischer {
247*6469a737Smseidel 	if(pPBtn == &maPBOptions)
248b9e67834SAndre Fischer 	{
249b9e67834SAndre Fischer 		if (mpBindings)
250b9e67834SAndre Fischer 		{
251b9e67834SAndre Fischer 			SfxDispatcher* pDisp = mpBindings->GetDispatcher();
252b9e67834SAndre Fischer 			pDisp->Execute( SID_CHAR_DLG_EFFECT, SFX_CALLMODE_ASYNCHRON );
253b9e67834SAndre Fischer 		}
254d4aefcaeSZheng Fan 		mrTextPropertyPanel.EndUnderlinePopupMode();
255b9e67834SAndre Fischer 	}
256b9e67834SAndre Fischer 	return 0;
257b9e67834SAndre Fischer }
258b9e67834SAndre Fischer 
259d4aefcaeSZheng Fan }}
260