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