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 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_scui.hxx"
26
27
28 //------------------------------------------------------------------
29
30 #include "tabbgcolordlg.hxx"
31 #include "scresid.hxx"
32 #include "miscdlgs.hrc"
33
34 #include <tools/debug.hxx>
35 #include <tools/color.hxx>
36 #include <sfx2/objsh.hxx>
37 #include <svx/xtable.hxx>
38 #include <svx/drawitem.hxx>
39 #include <unotools/pathoptions.hxx>
40 #include <tools/resid.hxx>
41 #include <editeng/editrids.hrc>
42 #include <editeng/eerdll.hxx>
43
44 #include <boost/scoped_ptr.hpp>
45
46 //==================================================================
47
48 #define HDL(hdl) LINK(this,ScTabBgColorDlg,hdl)
49
ScTabBgColorDlg(Window * pParent,const String & rTitle,const String & rTabBgColorNoColorText,const Color & rDefaultColor,const rtl::OString & sHelpId)50 ScTabBgColorDlg::ScTabBgColorDlg( Window* pParent,
51 const String& rTitle,
52 const String& rTabBgColorNoColorText,
53 const Color& rDefaultColor,
54 const rtl::OString& sHelpId ) :
55 ModalDialog ( pParent, ScResId( RID_SCDLG_TAB_BG_COLOR ) ),
56 aBorderWin ( this, ScResId( TAB_BG_COLOR_CT_BORDER ) ),
57 aTabBgColorSet ( &aBorderWin, ScResId( TAB_BG_COLOR_SET_BGDCOLOR ), this ),
58 aBtnOk ( this, ScResId( BTN_OK ) ),
59 aBtnCancel ( this, ScResId( BTN_CANCEL ) ),
60 aBtnHelp ( this, ScResId( BTN_HELP ) ),
61 aTabBgColor ( rDefaultColor ),
62 aTabBgColorNoColorText ( rTabBgColorNoColorText ),
63 msHelpId ( sHelpId )
64
65 {
66 SetHelpId( sHelpId );
67 this->SetText( rTitle );
68 this->SetStyle(GetStyle() | WB_BORDER | WB_STDFLOATWIN | WB_3DLOOK | WB_DIALOGCONTROL | WB_SYSTEMWINDOW | WB_STANDALONE | WB_HIDE);
69
70 FillColorValueSets_Impl();
71 aTabBgColorSet.SetDoubleClickHdl( HDL(TabBgColorDblClickHdl_Impl) );
72 aBtnOk.SetClickHdl( HDL(TabBgColorOKHdl_Impl) );
73 FreeResource();
74 }
75
76 //------------------------------------------------------------------------
77
GetSelectedColor(Color & rColor) const78 void ScTabBgColorDlg::GetSelectedColor( Color& rColor ) const
79 {
80 rColor = this->aTabBgColor;
81 }
82
~ScTabBgColorDlg()83 ScTabBgColorDlg::~ScTabBgColorDlg()
84 {
85 }
86
FillColorValueSets_Impl()87 void ScTabBgColorDlg::FillColorValueSets_Impl()
88 {
89 SfxObjectShell* pDocSh = SfxObjectShell::Current();
90 const SfxPoolItem* pItem = NULL;
91 XColorListSharedPtr aColorTable;
92 const Size aSize15x15 = Size( 15, 15 );
93 const Size aSize10x10 = Size( 10, 10 );
94 const Size aSize5x5 = Size( 5, 5 );
95 sal_uInt16 nSelectedItem = 0;
96
97 DBG_ASSERT( pDocSh, "DocShell not found!" );
98
99 if ( pDocSh && ( 0 != ( pItem = pDocSh->GetItem(SID_COLOR_TABLE) ) ) )
100 {
101 aColorTable = static_cast< const SvxColorTableItem* >(pItem)->GetColorTable();
102 }
103
104 if ( !aColorTable.get() )
105 {
106 aColorTable = XPropertyListFactory::CreateSharedXColorList(SvtPathOptions().GetPalettePath());
107 }
108
109 long nColorCount(0);
110
111 if ( aColorTable.get() )
112 {
113 nColorCount = aColorTable->Count();
114 Color aColWhite( COL_WHITE );
115 String aStrWhite( EditResId( RID_SVXITEMS_COLOR_WHITE ) );
116
117 aTabBgColorSet.addEntriesForXColorList(aColorTable);
118 }
119
120 if(nColorCount)
121 {
122 const WinBits nBits(aTabBgColorSet.GetStyle() | WB_NAMEFIELD | WB_ITEMBORDER | WB_NONEFIELD | WB_3DLOOK | WB_NO_DIRECTSELECT | WB_NOPOINTERFOCUS);
123 aTabBgColorSet.SetText( aTabBgColorNoColorText );
124 aTabBgColorSet.SetStyle( nBits );
125 static sal_Int32 nAdd = 4;
126
127 // calculate new size of color control as base, derive size of border win
128 const Size aNewSize(aTabBgColorSet.layoutAllVisible(nColorCount));
129 const Size aNewSizeBorderWin(aNewSize.Width() + nAdd, aNewSize.Height() + nAdd);
130
131 // from that, calculate a new dialog size
132 const Size aCurrentSizeDialog(GetOutputSizePixel());
133 const Size aCurrentSizeBorderWin(aBorderWin.GetOutputSizePixel());
134 const long nOffsetX(aCurrentSizeDialog.Width() - aCurrentSizeBorderWin.Width());
135 const long nOffsetY(aCurrentSizeDialog.Height() - aCurrentSizeBorderWin.Height());
136 const Size aNewSizeDialog(aNewSizeBorderWin.Width() + nOffsetX, aNewSizeBorderWin.Height() + nOffsetY);
137
138 // also need to adapt pos and size for the three buttons; as a base, take their original
139 // distance from the dialog bottom and get new Y-Pos
140 const long aButtonOffsetFromBottom(aCurrentSizeDialog.Height() - aBtnOk.GetPosPixel().Y());
141 const long aNewButtonY(aNewSizeDialog.Height() - aButtonOffsetFromBottom);
142
143 // for each button, scale width and x-pos by old/new dialog sizes and re-layout
144 // for Okay-Button
145 const long aNewWidthOkay((aBtnOk.GetSizePixel().Width() * aNewSizeDialog.Width()) / aCurrentSizeDialog.Width());
146 const long aNewPosOkay((aBtnOk.GetPosPixel().X() * aNewSizeDialog.Width()) / aCurrentSizeDialog.Width());
147 const Size aNewSizeOkay(aNewWidthOkay, aBtnOk.GetOutputSizePixel().Height());
148 aBtnOk.SetOutputSizePixel(aNewSizeOkay);
149 aBtnOk.SetPosSizePixel(Point(aNewPosOkay, aNewButtonY), aNewSizeOkay);
150
151 // for Cancel-Button
152 const long aNewWidthCancel((aBtnCancel.GetSizePixel().Width() * aNewSizeDialog.Width()) / aCurrentSizeDialog.Width());
153 const long aNewPosCancel((aBtnCancel.GetPosPixel().X() * aNewSizeDialog.Width()) / aCurrentSizeDialog.Width());
154 const Size aNewSizeCancel(aNewWidthCancel, aBtnCancel.GetOutputSizePixel().Height());
155 aBtnCancel.SetOutputSizePixel(aNewSizeCancel);
156 aBtnCancel.SetPosSizePixel(Point(aNewPosCancel, aNewButtonY), aNewSizeCancel);
157
158 // for Help-Button
159 const long aNewWidthHelp((aBtnHelp.GetSizePixel().Width() * aNewSizeDialog.Width()) / aCurrentSizeDialog.Width());
160 const long aNewPosHelp((aBtnHelp.GetPosPixel().X() * aNewSizeDialog.Width()) / aCurrentSizeDialog.Width());
161 const Size aNewSizeHelp(aNewWidthHelp, aBtnHelp.GetOutputSizePixel().Height());
162 aBtnHelp.SetOutputSizePixel(aNewSizeHelp);
163 aBtnHelp.SetPosSizePixel(Point(aNewPosHelp, aNewButtonY), aNewSizeHelp);
164
165 // set new sizes for color control
166 aTabBgColorSet.SetOutputSizePixel(aNewSize);
167 aTabBgColorSet.SetPosSizePixel(Point(nAdd/2, nAdd/2), aNewSize);
168
169 // set new size for border win
170 aBorderWin.SetOutputSizePixel(aNewSizeBorderWin);
171
172 // set new size for dialog itself
173 SetOutputSizePixel(aNewSizeDialog);
174 }
175
176 aTabBgColorSet.SelectItem(nSelectedItem);
177 aTabBgColorSet.Resize();
178 }
179
IMPL_LINK(ScTabBgColorDlg,TabBgColorDblClickHdl_Impl,ValueSet *,EMPTYARG)180 IMPL_LINK( ScTabBgColorDlg, TabBgColorDblClickHdl_Impl, ValueSet*, EMPTYARG )
181 /*
182 Handler, called when color selection is changed
183 */
184 {
185 sal_uInt16 nItemId = aTabBgColorSet.GetSelectItemId();
186 Color aColor = nItemId ? ( aTabBgColorSet.GetItemColor( nItemId ) ) : Color( COL_AUTO );
187 aTabBgColor = aColor;
188 EndDialog( sal_True );
189 return 0;
190 }
191
IMPL_LINK(ScTabBgColorDlg,TabBgColorOKHdl_Impl,OKButton *,EMPTYARG)192 IMPL_LINK( ScTabBgColorDlg, TabBgColorOKHdl_Impl, OKButton*, EMPTYARG )
193 {
194
195 // Handler, called when the OK button is pushed
196
197 sal_uInt16 nItemId = aTabBgColorSet.GetSelectItemId();
198 Color aColor = nItemId ? ( aTabBgColorSet.GetItemColor( nItemId ) ) : Color( COL_AUTO );
199 aTabBgColor = aColor;
200 EndDialog( sal_True );
201 return 0;
202 }
203
ScTabBgColorValueSet(Control * pParent,const ResId & rResId,ScTabBgColorDlg * pTabBgColorDlg)204 ScTabBgColorDlg::ScTabBgColorValueSet::ScTabBgColorValueSet( Control* pParent, const ResId& rResId, ScTabBgColorDlg* pTabBgColorDlg ) :
205 SvxColorValueSet(pParent, rResId)
206 {
207 aTabBgColorDlg = pTabBgColorDlg;
208 }
209
KeyInput(const KeyEvent & rKEvt)210 void ScTabBgColorDlg::ScTabBgColorValueSet::KeyInput( const KeyEvent& rKEvt )
211 {
212 switch ( rKEvt.GetKeyCode().GetCode() )
213 {
214 case KEY_SPACE:
215 case KEY_RETURN:
216 {
217 sal_uInt16 nItemId = GetSelectItemId();
218 const Color& aColor = nItemId ? ( GetItemColor( nItemId ) ) : Color( COL_AUTO );
219 aTabBgColorDlg->aTabBgColor = aColor;
220 aTabBgColorDlg->EndDialog(sal_True);
221 }
222 break;
223 }
224 SvxColorValueSet::KeyInput(rKEvt);
225 }
226