1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tabbgcolordlg.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 #undef SC_DLLIMPLEMENTATION
36 //------------------------------------------------------------------
38 #include <tools/debug.hxx>
39 #include <tools/color.hxx>
40 #include <sfx2/objsh.hxx>
41 #include <svx/xtable.hxx>
42 #include <svx/drawitem.hxx>
43 #include <svtools/pathoptions.hxx>
44 #include <tools/resid.hxx>
45 #include "tabbgcolordlg.hxx"
46 #include "scresid.hxx"
47 #include "miscdlgs.hrc"
48 #include <svx/svxitems.hrc>
50 //==================================================================
52 #define HDL(hdl) LINK(this,ScTabBgColorDlg,hdl)
54 __EXPORT
ScTabBgColorDlg::ScTabBgColorDlg( Window
* pParent
,
56 const String
& rTabBgColorNoColorText
,
57 const Color
& rDefaultColor
,
59 ModalDialog ( pParent
, ScResId( RID_SCDLG_TAB_BG_COLOR
) ),
60 aBorderWin ( this, ScResId( TAB_BG_COLOR_CT_BORDER
) ),
61 aTabBgColorSet ( &aBorderWin
, ScResId( TAB_BG_COLOR_SET_BGDCOLOR
), this ),
62 aTabBgColorBox ( this, ScResId( TAB_BG_COLOR_GB_BGDCOLOR
) ),
63 aBtnOk ( this, ScResId( BTN_OK
) ),
64 aBtnCancel ( this, ScResId( BTN_CANCEL
) ),
65 aBtnHelp ( this, ScResId( BTN_HELP
) ),
66 aTabBgColorNoColorText ( rTabBgColorNoColorText
),
67 aTabBgColor ( rDefaultColor
),
72 this->SetText( rTitle
);
73 this->SetStyle(GetStyle() | WB_BORDER
| WB_STDFLOATWIN
| WB_3DLOOK
| WB_DIALOGCONTROL
| WB_SYSTEMWINDOW
| WB_STANDALONE
| WB_HIDE
);
74 //TODO: Assign Help ID's to all controls...
75 aTabBgColorBox
.SetText(rTitle
);
76 FillColorValueSets_Impl();
77 aTabBgColorSet
.SetDoubleClickHdl( HDL(TabBgColorDblClickHdl_Impl
) );
78 aBtnOk
.SetClickHdl( HDL(TabBgColorOKHdl_Impl
) );
82 //------------------------------------------------------------------------
84 void ScTabBgColorDlg::GetSelectedColor( Color
& rColor
) const
86 rColor
= this->aTabBgColor
;
89 __EXPORT
ScTabBgColorDlg::~ScTabBgColorDlg()
93 void ScTabBgColorDlg::FillColorValueSets_Impl()
95 SfxObjectShell
* pDocSh
= SfxObjectShell::Current();
96 const SfxPoolItem
* pItem
= NULL
;
97 XColorTable
* pColorTable
= NULL
;
98 const Size aSize15x15
= Size( 15, 15 );
99 const Size aSize10x10
= Size( 10, 10 );
100 const Size aSize5x5
= Size( 5, 5 );
101 USHORT nSelectedItem
= 0;
102 FASTBOOL bOwn
= FALSE
;
104 DBG_ASSERT( pDocSh
, "DocShell not found!" );
106 if ( pDocSh
&& ( 0 != ( pItem
= pDocSh
->GetItem( SID_COLOR_TABLE
) ) ) )
107 pColorTable
= ( (SvxColorTableItem
*)pItem
)->GetColorTable();
111 pColorTable
= new XColorTable( SvtPathOptions().GetPalettePath() );
116 long nCount
= pColorTable
->Count();
117 XColorEntry
* pEntry
= NULL
;
118 Color
aColWhite( COL_WHITE
);
119 String
aStrWhite( ScResId( RID_SVXITEMS_COLOR_WHITE
) );
120 WinBits nBits
= ( aTabBgColorSet
.GetStyle() | WB_NAMEFIELD
| WB_ITEMBORDER
| WB_NONEFIELD
| WB_3DLOOK
| WB_NO_DIRECTSELECT
| WB_NOPOINTERFOCUS
);
121 aTabBgColorSet
.SetText( aTabBgColorNoColorText
);
122 aTabBgColorSet
.SetStyle( nBits
);
123 for ( i
= 0; i
< nCount
; i
++ )
125 pEntry
= pColorTable
->GetColor(i
);
126 aTabBgColorSet
.InsertItem( i
+ 1, pEntry
->GetColor(), pEntry
->GetName() );
127 if (pEntry
->GetColor() == aTabBgColor
)
128 nSelectedItem
= (i
+ 1);
133 aTabBgColorSet
.InsertItem( i
+ 1, aColWhite
, aStrWhite
);
139 aTabBgColorSet
.SetStyle( nBits
| WB_VSCROLL
);
142 aTabBgColorSet
.SetColCount( 10 );
143 aTabBgColorSet
.SetLineCount( 10 );
144 aTabBgColorSet
.CalcWindowSizePixel( aSize15x15
);
145 aTabBgColorSet
.Format();
146 aTabBgColorSet
.SelectItem(nSelectedItem
);
147 aTabBgColorSet
.Resize();
152 IMPL_LINK( ScTabBgColorDlg
, TabBgColorDblClickHdl_Impl
, ValueSet
*, EMPTYARG
)
154 Handler, called when color selection is changed
157 USHORT nItemId
= aTabBgColorSet
.GetSelectItemId();
158 Color aColor
= nItemId
? ( aTabBgColorSet
.GetItemColor( nItemId
) ) : Color( COL_AUTO
);
159 aTabBgColor
= aColor
;
164 IMPL_LINK( ScTabBgColorDlg
, TabBgColorOKHdl_Impl
, OKButton
*, EMPTYARG
)
167 // Handler, called when the OK button is pushed
169 USHORT nItemId
= aTabBgColorSet
.GetSelectItemId();
170 Color aColor
= nItemId
? ( aTabBgColorSet
.GetItemColor( nItemId
) ) : Color( COL_AUTO
);
171 aTabBgColor
= aColor
;
176 __EXPORT
ScTabBgColorDlg::ScTabBgColorValueSet::ScTabBgColorValueSet( Control
* pParent
, const ResId
& rResId
, ScTabBgColorDlg
* pTabBgColorDlg
) :
177 ValueSet(pParent
, rResId
)
179 aTabBgColorDlg
= pTabBgColorDlg
;
182 void ScTabBgColorDlg::ScTabBgColorValueSet::KeyInput( const KeyEvent
& rKEvt
)
184 switch ( rKEvt
.GetKeyCode().GetCode() )
189 USHORT nItemId
= GetSelectItemId();
190 const Color
& aColor
= nItemId
? ( GetItemColor( nItemId
) ) : Color( COL_AUTO
);
191 aTabBgColorDlg
->aTabBgColor
= aColor
;
192 aTabBgColorDlg
->EndDialog(TRUE
);
196 ValueSet::KeyInput(rKEvt
);