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