Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #undef SC_DLLIMPLEMENTATION
22 :
23 : //------------------------------------------------------------------
24 :
25 : #include "tabbgcolordlg.hxx"
26 : #include "scresid.hxx"
27 : #include "miscdlgs.hrc"
28 :
29 : #include <tools/color.hxx>
30 : #include <sfx2/objsh.hxx>
31 : #include <svx/xtable.hxx>
32 : #include <svx/drawitem.hxx>
33 : #include <unotools/pathoptions.hxx>
34 : #include <tools/resid.hxx>
35 : #include <editeng/editrids.hrc>
36 : #include <editeng/eerdll.hxx>
37 :
38 : #include <boost/scoped_ptr.hpp>
39 :
40 : //==================================================================
41 :
42 : #define HDL(hdl) LINK(this,ScTabBgColorDlg,hdl)
43 :
44 0 : ScTabBgColorDlg::ScTabBgColorDlg( Window* pParent,
45 : const String& rTitle,
46 : const String& rTabBgColorNoColorText,
47 : const Color& rDefaultColor,
48 : const OString& sHelpId ) :
49 : ModalDialog ( pParent, ScResId( RID_SCDLG_TAB_BG_COLOR ) ),
50 : aBorderWin ( this, ScResId( TAB_BG_COLOR_CT_BORDER ) ),
51 : aTabBgColorSet ( &aBorderWin, ScResId( TAB_BG_COLOR_SET_BGDCOLOR ), this ),
52 : aBtnOk ( this, ScResId( BTN_OK ) ),
53 : aBtnCancel ( this, ScResId( BTN_CANCEL ) ),
54 : aBtnHelp ( this, ScResId( BTN_HELP ) ),
55 : aTabBgColor ( rDefaultColor ),
56 : aTabBgColorNoColorText ( rTabBgColorNoColorText ),
57 0 : msHelpId ( sHelpId )
58 :
59 : {
60 0 : SetHelpId( sHelpId );
61 0 : this->SetText( rTitle );
62 0 : this->SetStyle(GetStyle() | WB_BORDER | WB_STDFLOATWIN | WB_3DLOOK | WB_DIALOGCONTROL | WB_SYSTEMWINDOW | WB_STANDALONE | WB_HIDE);
63 :
64 0 : FillColorValueSets_Impl();
65 0 : aTabBgColorSet.SetDoubleClickHdl( HDL(TabBgColorDblClickHdl_Impl) );
66 0 : aBtnOk.SetClickHdl( HDL(TabBgColorOKHdl_Impl) );
67 0 : FreeResource();
68 0 : }
69 :
70 : //------------------------------------------------------------------------
71 :
72 0 : void ScTabBgColorDlg::GetSelectedColor( Color& rColor ) const
73 : {
74 0 : rColor = this->aTabBgColor;
75 0 : }
76 :
77 0 : ScTabBgColorDlg::~ScTabBgColorDlg()
78 : {
79 0 : }
80 :
81 0 : void ScTabBgColorDlg::FillColorValueSets_Impl()
82 : {
83 0 : SfxObjectShell* pDocSh = SfxObjectShell::Current();
84 0 : const SfxPoolItem* pItem = NULL;
85 0 : XColorListRef pColorList;
86 :
87 0 : sal_uInt16 nSelectedItem = 0;
88 :
89 : OSL_ENSURE( pDocSh, "DocShell not found!" );
90 :
91 0 : if ( pDocSh && ( 0 != ( pItem = pDocSh->GetItem(SID_COLOR_TABLE) ) ) )
92 0 : pColorList = ( (SvxColorListItem*)pItem )->GetColorList();
93 0 : if ( !pColorList.is() )
94 0 : pColorList = XColorList::CreateStdColorList();
95 :
96 0 : long nColorCount(0);
97 :
98 0 : if ( pColorList.is() )
99 : {
100 0 : nColorCount = pColorList->Count();
101 0 : aTabBgColorSet.addEntriesForXColorList(*pColorList);
102 : }
103 :
104 0 : if(nColorCount)
105 : {
106 0 : const WinBits nBits(aTabBgColorSet.GetStyle() | WB_NAMEFIELD | WB_ITEMBORDER | WB_NONEFIELD | WB_3DLOOK | WB_NO_DIRECTSELECT | WB_NOPOINTERFOCUS);
107 0 : aTabBgColorSet.SetText( aTabBgColorNoColorText );
108 0 : aTabBgColorSet.SetStyle( nBits );
109 : static sal_Int32 nAdd = 4;
110 :
111 : // calculate new size of color control as base, derive size of border win
112 0 : const Size aNewSize(aTabBgColorSet.layoutAllVisible(nColorCount));
113 0 : const Size aNewSizeBorderWin(aNewSize.Width() + nAdd, aNewSize.Height() + nAdd);
114 :
115 : // from that, calculate a new dialog size
116 0 : const Size aCurrentSizeDialog(GetOutputSizePixel());
117 0 : const Size aCurrentSizeBorderWin(aBorderWin.GetOutputSizePixel());
118 0 : const long nOffsetX(aCurrentSizeDialog.Width() - aCurrentSizeBorderWin.Width());
119 0 : const long nOffsetY(aCurrentSizeDialog.Height() - aCurrentSizeBorderWin.Height());
120 0 : const Size aNewSizeDialog(aNewSizeBorderWin.Width() + nOffsetX, aNewSizeBorderWin.Height() + nOffsetY);
121 :
122 : // also need to adapt pos and size for the three buttons; as a base, take their original
123 : // distance from the dialog bottom and get new Y-Pos
124 0 : const long aButtonOffsetFromBottom(aCurrentSizeDialog.Height() - aBtnOk.GetPosPixel().Y());
125 0 : const long aNewButtonY(aNewSizeDialog.Height() - aButtonOffsetFromBottom);
126 :
127 : // for each button, scale width and x-pos by old/new dialog sizes and re-layout
128 : // for Okay-Button
129 0 : const long aNewWidthOkay((aBtnOk.GetSizePixel().Width() * aNewSizeDialog.Width()) / aCurrentSizeDialog.Width());
130 0 : const long aNewPosOkay((aBtnOk.GetPosPixel().X() * aNewSizeDialog.Width()) / aCurrentSizeDialog.Width());
131 0 : const Size aNewSizeOkay(aNewWidthOkay, aBtnOk.GetOutputSizePixel().Height());
132 0 : aBtnOk.SetOutputSizePixel(aNewSizeOkay);
133 0 : aBtnOk.SetPosSizePixel(Point(aNewPosOkay, aNewButtonY), aNewSizeOkay);
134 :
135 : // for Cancel-Button
136 0 : const long aNewWidthCancel((aBtnCancel.GetSizePixel().Width() * aNewSizeDialog.Width()) / aCurrentSizeDialog.Width());
137 0 : const long aNewPosCancel((aBtnCancel.GetPosPixel().X() * aNewSizeDialog.Width()) / aCurrentSizeDialog.Width());
138 0 : const Size aNewSizeCancel(aNewWidthCancel, aBtnCancel.GetOutputSizePixel().Height());
139 0 : aBtnCancel.SetOutputSizePixel(aNewSizeCancel);
140 0 : aBtnCancel.SetPosSizePixel(Point(aNewPosCancel, aNewButtonY), aNewSizeCancel);
141 :
142 : // for Help-Button
143 0 : const long aNewWidthHelp((aBtnHelp.GetSizePixel().Width() * aNewSizeDialog.Width()) / aCurrentSizeDialog.Width());
144 0 : const long aNewPosHelp((aBtnHelp.GetPosPixel().X() * aNewSizeDialog.Width()) / aCurrentSizeDialog.Width());
145 0 : const Size aNewSizeHelp(aNewWidthHelp, aBtnHelp.GetOutputSizePixel().Height());
146 0 : aBtnHelp.SetOutputSizePixel(aNewSizeHelp);
147 0 : aBtnHelp.SetPosSizePixel(Point(aNewPosHelp, aNewButtonY), aNewSizeHelp);
148 :
149 : // set new sizes for color control
150 0 : aTabBgColorSet.SetOutputSizePixel(aNewSize);
151 0 : aTabBgColorSet.SetPosSizePixel(Point(nAdd/2, nAdd/2), aNewSize);
152 :
153 : // set new size for border win
154 0 : aBorderWin.SetOutputSizePixel(aNewSizeBorderWin);
155 :
156 : // set new size for dialog itself
157 0 : SetOutputSizePixel(aNewSizeDialog);
158 : }
159 :
160 0 : aTabBgColorSet.SelectItem(nSelectedItem);
161 0 : aTabBgColorSet.Resize();
162 0 : }
163 :
164 0 : IMPL_LINK_NOARG(ScTabBgColorDlg, TabBgColorDblClickHdl_Impl)
165 : /*
166 : Handler, called when color selection is changed
167 : */
168 : {
169 0 : sal_uInt16 nItemId = aTabBgColorSet.GetSelectItemId();
170 0 : Color aColor = nItemId ? ( aTabBgColorSet.GetItemColor( nItemId ) ) : Color( COL_AUTO );
171 0 : aTabBgColor = aColor;
172 0 : EndDialog( sal_True );
173 0 : return 0;
174 : }
175 :
176 0 : IMPL_LINK_NOARG(ScTabBgColorDlg, TabBgColorOKHdl_Impl)
177 : {
178 :
179 : // Handler, called when the OK button is pushed
180 :
181 0 : sal_uInt16 nItemId = aTabBgColorSet.GetSelectItemId();
182 0 : Color aColor = nItemId ? ( aTabBgColorSet.GetItemColor( nItemId ) ) : Color( COL_AUTO );
183 0 : aTabBgColor = aColor;
184 0 : EndDialog( sal_True );
185 0 : return 0;
186 : }
187 :
188 0 : ScTabBgColorDlg::ScTabBgColorValueSet::ScTabBgColorValueSet( Control* pParent, const ResId& rResId, ScTabBgColorDlg* pTabBgColorDlg ) :
189 0 : SvxColorValueSet(pParent, rResId)
190 : {
191 0 : aTabBgColorDlg = pTabBgColorDlg;
192 0 : }
193 :
194 0 : void ScTabBgColorDlg::ScTabBgColorValueSet::KeyInput( const KeyEvent& rKEvt )
195 : {
196 0 : switch ( rKEvt.GetKeyCode().GetCode() )
197 : {
198 : case KEY_SPACE:
199 : case KEY_RETURN:
200 : {
201 0 : sal_uInt16 nItemId = GetSelectItemId();
202 0 : const Color& aColor = nItemId ? ( GetItemColor( nItemId ) ) : Color( COL_AUTO );
203 0 : aTabBgColorDlg->aTabBgColor = aColor;
204 0 : aTabBgColorDlg->EndDialog(sal_True);
205 : }
206 0 : break;
207 : }
208 0 : SvxColorValueSet::KeyInput(rKEvt);
209 0 : }
210 :
211 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|