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 
23 
24 #include "precompiled_svx.hxx"
25 #include "TextUnderlineControl.hxx"
26 #include "TextPropertyPanel.hrc"
27 #include <sfx2/sidebar/ResourceDefinitions.hrc>
28 #include <svx/dialogs.hrc>
29 #include <svx/dialmgr.hxx>
30 #include <unotools/viewoptions.hxx>
31 #include <editeng/kernitem.hxx>
32 #include <sfx2/bindings.hxx>
33 #include <sfx2/dispatch.hxx>
34 #include <sfx2/sidebar/Theme.hxx>
35 #include <editeng/udlnitem.hxx>
36 
37 namespace svx { namespace sidebar {
38 
TextUnderlineControl(Window * pParent,svx::sidebar::TextPropertyPanel & rPanel,SfxBindings * pBindings)39 TextUnderlineControl::TextUnderlineControl (
40 	Window* pParent,
41 	svx::sidebar::TextPropertyPanel& rPanel,
42 	SfxBindings* pBindings)
43 :	svx::sidebar::PopupControl( pParent,SVX_RES(RID_POPUPPANEL_TEXTPAGE_UNDERLINE))
44 ,	mrTextPropertyPanel(rPanel)
45 ,	mpBindings(pBindings)
46 ,	maVSUnderline( this, SVX_RES(VS_UNDERLINE))
47 ,	maPBOptions	(this, SVX_RES(PB_OPTIONS) )
48 
49 ,	maIMGSingle		(SVX_RES(IMG_SINGLE))
50 ,	maIMGDouble		(SVX_RES(IMG_DOUBLE))
51 ,	maIMGBold		(SVX_RES(IMG_BOLD2))
52 ,	maIMGDot		(SVX_RES(IMG_DOT))
53 ,	maIMGDotBold	(SVX_RES(IMG_DOT_BOLD))
54 ,	maIMGDash		(SVX_RES(IMG_DASH))
55 ,	maIMGDashLong	(SVX_RES(IMG_DASH_LONG))
56 ,	maIMGDashDot	(SVX_RES(IMG_DASH_DOT))
57 ,	maIMGDashDotDot	(SVX_RES(IMG_DASH_DOT_DOT))
58 ,	maIMGWave		(SVX_RES(IMG_WAVE))
59 
60 // high contrast
61 ,	maIMGSingleH	(SVX_RES(IMG_SINGLE_H))
62 ,	maIMGDoubleH	(SVX_RES(IMG_DOUBLE_H))
63 ,	maIMGBoldH		(SVX_RES(IMG_BOLD2_H))
64 ,	maIMGDotH		(SVX_RES(IMG_DOT_H))
65 ,	maIMGDotBoldH	(SVX_RES(IMG_DOT_BOLD_H))
66 ,	maIMGDashH		(SVX_RES(IMG_DASH_H))
67 ,	maIMGDashLongH	(SVX_RES(IMG_DASH_LONG_H))
68 ,	maIMGDashDotH	(SVX_RES(IMG_DASH_DOT_H))
69 ,	maIMGDashDotDotH(SVX_RES(IMG_DASH_DOT_DOT_H))
70 ,	maIMGWaveH		(SVX_RES(IMG_WAVE_H))
71 
72 ,	maIMGSingleSel		(SVX_RES(IMG_SINGLE_SEL))
73 ,	maIMGDoubleSel		(SVX_RES(IMG_DOUBLE_SEL))
74 ,	maIMGBoldSel		(SVX_RES(IMG_BOLD2_SEL))
75 ,	maIMGDotSel			(SVX_RES(IMG_DOT_SEL))
76 ,	maIMGDotBoldSel		(SVX_RES(IMG_DOT_BOLD_SEL))
77 ,	maIMGDashSel		(SVX_RES(IMG_DASH_SEL))
78 ,	maIMGDashLongSel	(SVX_RES(IMG_DASH_LONG_SEL))
79 ,	maIMGDashDotSel		(SVX_RES(IMG_DASH_DOT_SEL))
80 ,	maIMGDashDotDotSel	(SVX_RES(IMG_DASH_DOT_DOT_SEL))
81 ,	maIMGWaveSel		(SVX_RES(IMG_WAVE_SEL))
82 
83 {
84 	initial();
85 	FreeResource();
86 }
87 
initial()88 void TextUnderlineControl::initial()
89 {
90 	maVSUnderline.SetColor(GetSettings().GetStyleSettings().GetHighContrastMode()?
91 		GetSettings().GetStyleSettings().GetMenuColor():
92 		sfx2::sidebar::Theme::GetColor( sfx2::sidebar::Theme::Paint_PanelBackground ));
93 	maVSUnderline.SetBackground(GetSettings().GetStyleSettings().GetHighContrastMode()?
94 		GetSettings().GetStyleSettings().GetMenuColor():
95 		sfx2::sidebar::Theme::GetColor( sfx2::sidebar::Theme::Paint_PanelBackground ));
96 
97 	Link aLink = LINK( this, TextUnderlineControl, PBClickHdl ) ;
98 	maPBOptions.SetClickHdl(aLink);
99 
100 	maVSUnderline.SetStyle( maVSUnderline.GetStyle()| WB_3DLOOK | WB_NO_DIRECTSELECT );
101 
102 	// 'none' item
103 	maVSUnderline.SetStyle( maVSUnderline.GetStyle()| WB_NONEFIELD | WB_MENUSTYLEVALUESET );
104 	maVSUnderline.SetText( String(SVX_RES(STR_WITHOUT) ) );
105 
106 	maVSUnderline.InsertItem(1, maIMGSingle ,String(SVX_RES(STR_SINGLE)));
107 	maVSUnderline.SetItemData(1, (void*)(sal_uInt64)UNDERLINE_SINGLE);
108 
109 	maVSUnderline.InsertItem(2, maIMGDouble ,String(SVX_RES(STR_DOUBLE)));
110 	maVSUnderline.SetItemData(2, (void*)(sal_uInt64)UNDERLINE_DOUBLE);
111 
112 	maVSUnderline.InsertItem(3, maIMGBold, String(SVX_RES(STR_BOLD)));
113 	maVSUnderline.SetItemData(3,(void*)(sal_uInt64)UNDERLINE_BOLD);
114 
115 	maVSUnderline.InsertItem(4, maIMGDot, String(SVX_RES(STR_DOT)));
116 	maVSUnderline.SetItemData(4,(void*)(sal_uInt64)UNDERLINE_DOTTED);
117 
118 	maVSUnderline.InsertItem(5, maIMGDotBold, String(SVX_RES(STR_DOT_BOLD)));
119 	maVSUnderline.SetItemData(5,(void*)(sal_uInt64)UNDERLINE_BOLDDOTTED);
120 
121 	maVSUnderline.InsertItem(6, maIMGDash, String(SVX_RES(STR_DASH)));
122 	maVSUnderline.SetItemData(6,(void*)(sal_uInt64)UNDERLINE_DASH);
123 
124 	maVSUnderline.InsertItem(7, maIMGDashLong,String(SVX_RES(STR_DASH_LONG)));
125 	maVSUnderline.SetItemData(7,(void*)(sal_uInt64)UNDERLINE_LONGDASH);
126 
127 	maVSUnderline.InsertItem(8, maIMGDashDot, String(SVX_RES(STR_DASH_DOT)));
128 	maVSUnderline.SetItemData(8,(void*)(sal_uInt64)UNDERLINE_DASHDOT);
129 
130 	maVSUnderline.InsertItem(9, maIMGDashDotDot, String(SVX_RES(STR_DASH_DOT_DOT)));
131 	maVSUnderline.SetItemData(9,(void*)(sal_uInt64)UNDERLINE_DASHDOTDOT);
132 
133 	maVSUnderline.InsertItem(10, maIMGWave, String(SVX_RES(STR_WAVE)));
134 	maVSUnderline.SetItemData(10,(void*)(sal_uInt64)UNDERLINE_WAVE);
135 
136 	maVSUnderline.SetColCount( 1 );
137 	aLink = LINK( this, TextUnderlineControl, VSSelectHdl ) ;
138 	maVSUnderline.SetSelectHdl(aLink);
139 
140 	maVSUnderline.StartSelection();
141 	maVSUnderline.Show();
142 }
143 
144 
Rearrange(FontUnderline eLine)145 void TextUnderlineControl::Rearrange(FontUnderline eLine)
146 {
147 	// high contrast
148 	maVSUnderline.SetItemImage(1, GetDisplayBackground().GetColor().IsDark()? maIMGSingleH :maIMGSingle);
149 	maVSUnderline.SetItemImage(2, GetDisplayBackground().GetColor().IsDark()? maIMGDoubleH : maIMGDouble );
150 	maVSUnderline.SetItemImage(3, GetDisplayBackground().GetColor().IsDark()? maIMGBoldH : maIMGBold);
151 	maVSUnderline.SetItemImage(4, GetDisplayBackground().GetColor().IsDark()? maIMGDotH : maIMGDot);
152 	maVSUnderline.SetItemImage(5, GetDisplayBackground().GetColor().IsDark()? maIMGDotBoldH :maIMGDotBold);
153 	maVSUnderline.SetItemImage(6, GetDisplayBackground().GetColor().IsDark()? maIMGDashH :maIMGDash);
154 	maVSUnderline.SetItemImage(7, GetDisplayBackground().GetColor().IsDark()? maIMGDashLongH : maIMGDashLong);
155 	maVSUnderline.SetItemImage(8, GetDisplayBackground().GetColor().IsDark()? maIMGDashDotH : maIMGDashDot);
156 	maVSUnderline.SetItemImage(9, GetDisplayBackground().GetColor().IsDark()? maIMGDashDotDotH : maIMGDashDotDot);
157 	maVSUnderline.SetItemImage(10, GetDisplayBackground().GetColor().IsDark()? maIMGWaveH : maIMGWave);
158 
159 	switch(eLine)
160 	{
161 	case UNDERLINE_SINGLE:
162 		maVSUnderline.SetItemImage(1, maIMGSingleSel);
163 		maVSUnderline.SelectItem(1);
164 		maVSUnderline.GrabFocus();
165 		break;
166 	case UNDERLINE_DOUBLE:
167 		maVSUnderline.SetItemImage(2, maIMGDoubleSel);
168 		maVSUnderline.SelectItem(2);
169 		maVSUnderline.GrabFocus();
170 		break;
171 	case UNDERLINE_BOLD:
172 		maVSUnderline.SetItemImage(3, maIMGBoldSel);
173 		maVSUnderline.SelectItem(3);
174 		maVSUnderline.GrabFocus();
175 		break;
176 	case UNDERLINE_DOTTED:
177 		maVSUnderline.SetItemImage(4, maIMGDotSel);
178 		maVSUnderline.SelectItem(4);
179 		maVSUnderline.GrabFocus();
180 		break;
181 	case UNDERLINE_BOLDDOTTED:
182 		maVSUnderline.SetItemImage(5, maIMGDotBoldSel);
183 		maVSUnderline.SelectItem(5);
184 		maVSUnderline.GrabFocus();
185 		break;
186 	case UNDERLINE_DASH:
187 		maVSUnderline.SetItemImage(6, maIMGDashSel);
188 		maVSUnderline.SelectItem(6);
189 		maVSUnderline.GrabFocus();
190 		break;
191 	case UNDERLINE_LONGDASH:
192 		maVSUnderline.SetItemImage(7, maIMGDashLongSel);
193 		maVSUnderline.SelectItem(7);
194 		maVSUnderline.GrabFocus();
195 		break;
196 	case UNDERLINE_DASHDOT:
197 		maVSUnderline.SetItemImage(8, maIMGDashDotSel);
198 		maVSUnderline.SelectItem(8);
199 		maVSUnderline.GrabFocus();
200 		break;
201 	case UNDERLINE_DASHDOTDOT:
202 		maVSUnderline.SetItemImage(9, maIMGDashDotDotSel);
203 		maVSUnderline.SelectItem(9);
204 		maVSUnderline.GrabFocus();
205 		break;
206 	case UNDERLINE_WAVE:
207 		maVSUnderline.SetItemImage(10, maIMGWaveSel);
208 		maVSUnderline.SelectItem(10);
209 		maVSUnderline.GrabFocus();
210 		break;
211 	case UNDERLINE_NONE:
212 		maVSUnderline.SelectItem(0);
213 		maVSUnderline.GrabFocus();
214 		break;
215 	default:
216 		maVSUnderline.SelectItem(1);
217 		maVSUnderline.SetNoSelection();
218 		maPBOptions.GrabFocus();
219 	}
220 	maVSUnderline.StartSelection();
221 }
222 
223 
IMPL_LINK(TextUnderlineControl,VSSelectHdl,void *,pControl)224 IMPL_LINK(TextUnderlineControl, VSSelectHdl, void *, pControl)
225 {
226 	if ( pControl == &maVSUnderline )
227 	{
228 		const sal_uInt16 iPos = maVSUnderline.GetSelectItemId();
229 		const FontUnderline eUnderline = ( iPos == 0 )
230 										 ? UNDERLINE_NONE
231 										 : (FontUnderline)(sal_uInt64)maVSUnderline.GetItemData( iPos );
232 
233 		SvxUnderlineItem aLineItem(eUnderline, SID_ATTR_CHAR_UNDERLINE);
234 
235 		aLineItem.SetColor(mrTextPropertyPanel.GetUnderlineColor());
236 		mpBindings->GetDispatcher()->Execute(SID_ATTR_CHAR_UNDERLINE, SFX_CALLMODE_RECORD, &aLineItem, 0L);
237 
238 		mrTextPropertyPanel.SetUnderline(eUnderline);
239 
240 		mrTextPropertyPanel.EndUnderlinePopupMode();
241 	}
242 	return( 0L );
243 }
244 
IMPL_LINK(TextUnderlineControl,PBClickHdl,PushButton *,pPBtn)245 IMPL_LINK(TextUnderlineControl, PBClickHdl, PushButton *, pPBtn)
246 {
247 	if(pPBtn == &maPBOptions)
248 	{
249 		if (mpBindings)
250 		{
251 			SfxDispatcher* pDisp = mpBindings->GetDispatcher();
252 			pDisp->Execute( SID_CHAR_DLG_EFFECT, SFX_CALLMODE_ASYNCHRON );
253 		}
254 		mrTextPropertyPanel.EndUnderlinePopupMode();
255 	}
256 	return 0;
257 }
258 
259 }}
260