1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #undef SC_DLLIMPLEMENTATION
23 //------------------------------------------------------------------
25 #include "tabbgcolordlg.hxx"
26 #include "scresid.hxx"
27 #include "miscdlgs.hrc"
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>
38 #include <boost/scoped_ptr.hpp>
40 //==================================================================
42 #define HDL(hdl) LINK(this,ScTabBgColorDlg,hdl)
44 ScTabBgColorDlg::ScTabBgColorDlg( Window
* pParent
,
45 const OUString
& rTitle
,
46 const OUString
& 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
),
61 this->SetText( rTitle
);
62 this->SetStyle(GetStyle() | WB_BORDER
| WB_STDFLOATWIN
| WB_3DLOOK
| WB_DIALOGCONTROL
| WB_SYSTEMWINDOW
| WB_STANDALONE
| WB_HIDE
);
64 FillColorValueSets_Impl();
65 aTabBgColorSet
.SetDoubleClickHdl( HDL(TabBgColorDblClickHdl_Impl
) );
66 aBtnOk
.SetClickHdl( HDL(TabBgColorOKHdl_Impl
) );
70 //------------------------------------------------------------------------
72 void ScTabBgColorDlg::GetSelectedColor( Color
& rColor
) const
74 rColor
= this->aTabBgColor
;
77 ScTabBgColorDlg::~ScTabBgColorDlg()
81 void ScTabBgColorDlg::FillColorValueSets_Impl()
83 SfxObjectShell
* pDocSh
= SfxObjectShell::Current();
84 const SfxPoolItem
* pItem
= NULL
;
85 XColorListRef pColorList
;
87 sal_uInt16 nSelectedItem
= 0;
89 OSL_ENSURE( pDocSh
, "DocShell not found!" );
91 if ( pDocSh
&& ( 0 != ( pItem
= pDocSh
->GetItem(SID_COLOR_TABLE
) ) ) )
92 pColorList
= ( (SvxColorListItem
*)pItem
)->GetColorList();
93 if ( !pColorList
.is() )
94 pColorList
= XColorList::CreateStdColorList();
98 if ( pColorList
.is() )
100 nColorCount
= pColorList
->Count();
101 aTabBgColorSet
.addEntriesForXColorList(*pColorList
);
106 const WinBits
nBits(aTabBgColorSet
.GetStyle() | WB_NAMEFIELD
| WB_ITEMBORDER
| WB_NONEFIELD
| WB_3DLOOK
| WB_NO_DIRECTSELECT
| WB_NOPOINTERFOCUS
);
107 aTabBgColorSet
.SetText( aTabBgColorNoColorText
);
108 aTabBgColorSet
.SetStyle( nBits
);
109 static sal_Int32 nAdd
= 4;
111 // calculate new size of color control as base, derive size of border win
112 const Size
aNewSize(aTabBgColorSet
.layoutAllVisible(nColorCount
));
113 const Size
aNewSizeBorderWin(aNewSize
.Width() + nAdd
, aNewSize
.Height() + nAdd
);
115 // from that, calculate a new dialog size
116 const Size
aCurrentSizeDialog(GetOutputSizePixel());
117 const Size
aCurrentSizeBorderWin(aBorderWin
.GetOutputSizePixel());
118 const long nOffsetX(aCurrentSizeDialog
.Width() - aCurrentSizeBorderWin
.Width());
119 const long nOffsetY(aCurrentSizeDialog
.Height() - aCurrentSizeBorderWin
.Height());
120 const Size
aNewSizeDialog(aNewSizeBorderWin
.Width() + nOffsetX
, aNewSizeBorderWin
.Height() + nOffsetY
);
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 const long aButtonOffsetFromBottom(aCurrentSizeDialog
.Height() - aBtnOk
.GetPosPixel().Y());
125 const long aNewButtonY(aNewSizeDialog
.Height() - aButtonOffsetFromBottom
);
127 // for each button, scale width and x-pos by old/new dialog sizes and re-layout
129 const long aNewWidthOkay((aBtnOk
.GetSizePixel().Width() * aNewSizeDialog
.Width()) / aCurrentSizeDialog
.Width());
130 const long aNewPosOkay((aBtnOk
.GetPosPixel().X() * aNewSizeDialog
.Width()) / aCurrentSizeDialog
.Width());
131 const Size
aNewSizeOkay(aNewWidthOkay
, aBtnOk
.GetOutputSizePixel().Height());
132 aBtnOk
.SetOutputSizePixel(aNewSizeOkay
);
133 aBtnOk
.SetPosSizePixel(Point(aNewPosOkay
, aNewButtonY
), aNewSizeOkay
);
136 const long aNewWidthCancel((aBtnCancel
.GetSizePixel().Width() * aNewSizeDialog
.Width()) / aCurrentSizeDialog
.Width());
137 const long aNewPosCancel((aBtnCancel
.GetPosPixel().X() * aNewSizeDialog
.Width()) / aCurrentSizeDialog
.Width());
138 const Size
aNewSizeCancel(aNewWidthCancel
, aBtnCancel
.GetOutputSizePixel().Height());
139 aBtnCancel
.SetOutputSizePixel(aNewSizeCancel
);
140 aBtnCancel
.SetPosSizePixel(Point(aNewPosCancel
, aNewButtonY
), aNewSizeCancel
);
143 const long aNewWidthHelp((aBtnHelp
.GetSizePixel().Width() * aNewSizeDialog
.Width()) / aCurrentSizeDialog
.Width());
144 const long aNewPosHelp((aBtnHelp
.GetPosPixel().X() * aNewSizeDialog
.Width()) / aCurrentSizeDialog
.Width());
145 const Size
aNewSizeHelp(aNewWidthHelp
, aBtnHelp
.GetOutputSizePixel().Height());
146 aBtnHelp
.SetOutputSizePixel(aNewSizeHelp
);
147 aBtnHelp
.SetPosSizePixel(Point(aNewPosHelp
, aNewButtonY
), aNewSizeHelp
);
149 // set new sizes for color control
150 aTabBgColorSet
.SetOutputSizePixel(aNewSize
);
151 aTabBgColorSet
.SetPosSizePixel(Point(nAdd
/2, nAdd
/2), aNewSize
);
153 // set new size for border win
154 aBorderWin
.SetOutputSizePixel(aNewSizeBorderWin
);
156 // set new size for dialog itself
157 SetOutputSizePixel(aNewSizeDialog
);
160 aTabBgColorSet
.SelectItem(nSelectedItem
);
161 aTabBgColorSet
.Resize();
164 IMPL_LINK_NOARG(ScTabBgColorDlg
, TabBgColorDblClickHdl_Impl
)
166 Handler, called when color selection is changed
169 sal_uInt16 nItemId
= aTabBgColorSet
.GetSelectItemId();
170 Color aColor
= nItemId
? ( aTabBgColorSet
.GetItemColor( nItemId
) ) : Color( COL_AUTO
);
171 aTabBgColor
= aColor
;
172 EndDialog( sal_True
);
176 IMPL_LINK_NOARG(ScTabBgColorDlg
, TabBgColorOKHdl_Impl
)
179 // Handler, called when the OK button is pushed
181 sal_uInt16 nItemId
= aTabBgColorSet
.GetSelectItemId();
182 Color aColor
= nItemId
? ( aTabBgColorSet
.GetItemColor( nItemId
) ) : Color( COL_AUTO
);
183 aTabBgColor
= aColor
;
184 EndDialog( sal_True
);
188 ScTabBgColorDlg::ScTabBgColorValueSet::ScTabBgColorValueSet( Control
* pParent
, const ResId
& rResId
, ScTabBgColorDlg
* pTabBgColorDlg
) :
189 SvxColorValueSet(pParent
, rResId
)
191 aTabBgColorDlg
= pTabBgColorDlg
;
194 void ScTabBgColorDlg::ScTabBgColorValueSet::KeyInput( const KeyEvent
& rKEvt
)
196 switch ( rKEvt
.GetKeyCode().GetCode() )
201 sal_uInt16 nItemId
= GetSelectItemId();
202 const Color
& aColor
= nItemId
? ( GetItemColor( nItemId
) ) : Color( COL_AUTO
);
203 aTabBgColorDlg
->aTabBgColor
= aColor
;
204 aTabBgColorDlg
->EndDialog(sal_True
);
208 SvxColorValueSet::KeyInput(rKEvt
);
211 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */