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 rtl::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 : const Size aSize15x15 = Size( 15, 15 );
88 0 : sal_uInt16 nSelectedItem = 0;
89 :
90 : OSL_ENSURE( pDocSh, "DocShell not found!" );
91 :
92 0 : if ( pDocSh && ( 0 != ( pItem = pDocSh->GetItem(SID_COLOR_TABLE) ) ) )
93 0 : pColorList = ( (SvxColorListItem*)pItem )->GetColorList();
94 0 : if ( !pColorList.is() )
95 0 : pColorList = XColorList::CreateStdColorList();
96 :
97 0 : if ( pColorList.is() )
98 : {
99 0 : sal_uInt16 i = 0;
100 0 : long nCount = pColorList->Count();
101 0 : XColorEntry* pEntry = NULL;
102 0 : Color aColWhite( COL_WHITE );
103 0 : String aStrWhite( EditResId( RID_SVXITEMS_COLOR_WHITE ) );
104 0 : WinBits nBits = ( aTabBgColorSet.GetStyle() | WB_NAMEFIELD | WB_ITEMBORDER | WB_NONEFIELD | WB_3DLOOK | WB_NO_DIRECTSELECT | WB_NOPOINTERFOCUS);
105 0 : aTabBgColorSet.SetText( aTabBgColorNoColorText );
106 0 : aTabBgColorSet.SetStyle( nBits );
107 0 : for ( i = 0; i < nCount; i++ )
108 : {
109 0 : pEntry = pColorList->GetColor(i);
110 0 : aTabBgColorSet.InsertItem( i + 1, pEntry->GetColor(), pEntry->GetName() );
111 0 : if (pEntry->GetColor() == aTabBgColor)
112 0 : nSelectedItem = (i + 1);
113 : }
114 :
115 0 : while ( i < 80 )
116 : {
117 0 : aTabBgColorSet.InsertItem( i + 1, aColWhite, aStrWhite );
118 0 : i++;
119 : }
120 :
121 0 : if ( nCount > 80 )
122 : {
123 0 : aTabBgColorSet.SetStyle( nBits | WB_VSCROLL );
124 0 : }
125 : }
126 0 : aTabBgColorSet.SetColCount( 10 );
127 0 : aTabBgColorSet.SetLineCount( 10 );
128 0 : aTabBgColorSet.CalcWindowSizePixel( aSize15x15 );
129 0 : aTabBgColorSet.Format();
130 0 : aTabBgColorSet.SelectItem(nSelectedItem);
131 0 : aTabBgColorSet.Resize();
132 0 : }
133 :
134 0 : IMPL_LINK_NOARG(ScTabBgColorDlg, TabBgColorDblClickHdl_Impl)
135 : /*
136 : Handler, called when color selection is changed
137 : */
138 : {
139 0 : sal_uInt16 nItemId = aTabBgColorSet.GetSelectItemId();
140 0 : Color aColor = nItemId ? ( aTabBgColorSet.GetItemColor( nItemId ) ) : Color( COL_AUTO );
141 0 : aTabBgColor = aColor;
142 0 : EndDialog( sal_True );
143 0 : return 0;
144 : }
145 :
146 0 : IMPL_LINK_NOARG(ScTabBgColorDlg, TabBgColorOKHdl_Impl)
147 : {
148 :
149 : // Handler, called when the OK button is pushed
150 :
151 0 : sal_uInt16 nItemId = aTabBgColorSet.GetSelectItemId();
152 0 : Color aColor = nItemId ? ( aTabBgColorSet.GetItemColor( nItemId ) ) : Color( COL_AUTO );
153 0 : aTabBgColor = aColor;
154 0 : EndDialog( sal_True );
155 0 : return 0;
156 : }
157 :
158 0 : ScTabBgColorDlg::ScTabBgColorValueSet::ScTabBgColorValueSet( Control* pParent, const ResId& rResId, ScTabBgColorDlg* pTabBgColorDlg ) :
159 0 : ValueSet(pParent, rResId)
160 : {
161 0 : aTabBgColorDlg = pTabBgColorDlg;
162 0 : }
163 :
164 0 : void ScTabBgColorDlg::ScTabBgColorValueSet::KeyInput( const KeyEvent& rKEvt )
165 : {
166 0 : switch ( rKEvt.GetKeyCode().GetCode() )
167 : {
168 : case KEY_SPACE:
169 : case KEY_RETURN:
170 : {
171 0 : sal_uInt16 nItemId = GetSelectItemId();
172 0 : const Color& aColor = nItemId ? ( GetItemColor( nItemId ) ) : Color( COL_AUTO );
173 0 : aTabBgColorDlg->aTabBgColor = aColor;
174 0 : aTabBgColorDlg->EndDialog(sal_True);
175 : }
176 0 : break;
177 : }
178 0 : ValueSet::KeyInput(rKEvt);
179 0 : }
180 :
181 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|