fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / namedlg / namemgrtable.cxx
blob89749c62747c63ca83a513bbe8dc6a4cbcdc8dfa
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 //ScRangeManagerTable
11 #include "global.hxx"
12 #include "reffact.hxx"
13 #include "document.hxx"
14 #include "docfunc.hxx"
15 #include "scresid.hxx"
16 #include "globstr.hrc"
17 #include "namedlg.hxx"
18 #include "viewdata.hxx"
19 #include "globalnames.hxx"
21 #include <sfx2/app.hxx>
23 #define ITEMID_NAME 1
24 #define ITEMID_RANGE 2
25 #define ITEMID_SCOPE 3
27 #define MINSIZE 80
29 static OUString createEntryString(const ScRangeNameLine& rLine)
31 OUString aRet = rLine.aName + "\t" + rLine.aExpression + "\t" + rLine.aScope;
32 return aRet;
35 ScRangeManagerTable::InitListener::~InitListener() {}
37 ScRangeManagerTable::ScRangeManagerTable( SvSimpleTableContainer& rParent, boost::ptr_map<OUString, ScRangeName>& rRangeMap, const ScAddress& rPos ):
38 SvSimpleTable( rParent, WB_SORT | WB_HSCROLL | WB_CLIPCHILDREN | WB_TABSTOP ),
39 maGlobalString( ScGlobal::GetRscString(STR_GLOBAL_SCOPE)),
40 mrRangeMap( rRangeMap ),
41 maPos( rPos ),
42 mpInitListener(NULL)
44 static long aStaticTabs[] = {3, 0, 0, 0 };
45 SetTabs( &aStaticTabs[0], MAP_PIXEL );
47 OUString aNameStr(ScGlobal::GetRscString(STR_HEADER_NAME));
48 OUString aRangeStr(ScGlobal::GetRscString(STR_HEADER_RANGE_OR_EXPR));
49 OUString aScopeStr(ScGlobal::GetRscString(STR_HEADER_SCOPE));
51 HeaderBar& rHeaderBar = GetTheHeaderBar();
52 InsertHeaderEntry( aNameStr );
53 InsertHeaderEntry( aRangeStr );
54 InsertHeaderEntry( aScopeStr );
55 rHeaderBar.SetEndDragHdl( LINK( this, ScRangeManagerTable, HeaderEndDragHdl ) );
57 setColWidths();
58 UpdateViewSize();
59 Init();
60 ShowTable();
61 SetSelectionMode(MULTIPLE_SELECTION);
62 SetScrolledHdl( LINK( this, ScRangeManagerTable, ScrollHdl ) );
63 void* pNull = NULL;
64 HeaderEndDragHdl(pNull);
67 void ScRangeManagerTable::Resize()
69 SvSimpleTable::Resize();
70 if (isInitialLayout(this))
71 setColWidths();
74 void ScRangeManagerTable::StateChanged( StateChangedType nStateChange )
76 SvSimpleTable::StateChanged(nStateChange);
78 if (nStateChange == StateChangedType::InitShow)
80 if (GetEntryCount())
82 SetCurEntry(GetEntryOnPos(0));
83 CheckForFormulaString();
86 if (mpInitListener)
87 mpInitListener->tableInitialized();
91 void ScRangeManagerTable::setColWidths()
93 HeaderBar &rHeaderBar = GetTheHeaderBar();
94 if (rHeaderBar.GetItemCount() < 3)
95 return;
96 long nTabSize = GetSizePixel().Width() / 3;
97 rHeaderBar.SetItemSize( ITEMID_NAME, nTabSize);
98 rHeaderBar.SetItemSize( ITEMID_RANGE, nTabSize);
99 rHeaderBar.SetItemSize( ITEMID_SCOPE, nTabSize);
100 static long aStaticTabs[] = {3, 0, nTabSize, 2*nTabSize };
101 SetTabs( &aStaticTabs[0], MAP_PIXEL );
102 void* pNull = NULL;
103 HeaderEndDragHdl(pNull);
106 ScRangeManagerTable::~ScRangeManagerTable()
108 disposeOnce();
111 void ScRangeManagerTable::dispose()
113 Clear();
114 SvSimpleTable::dispose();
117 void ScRangeManagerTable::setInitListener( InitListener* pListener )
119 mpInitListener = pListener;
122 void ScRangeManagerTable::addEntry(const ScRangeNameLine& rLine, bool bSetCurEntry)
124 SvTreeListEntry* pEntry = InsertEntryToColumn( createEntryString(rLine), TREELIST_APPEND, 0xffff);
125 if (bSetCurEntry)
126 SetCurEntry(pEntry);
129 void ScRangeManagerTable::GetCurrentLine(ScRangeNameLine& rLine)
131 SvTreeListEntry* pCurrentEntry = GetCurEntry();
132 GetLine(rLine, pCurrentEntry);
135 void ScRangeManagerTable::GetLine(ScRangeNameLine& rLine, SvTreeListEntry* pEntry)
137 rLine.aName = GetEntryText( pEntry, 0);
138 rLine.aExpression = GetEntryText(pEntry, 1);
139 rLine.aScope = GetEntryText(pEntry, 2);
142 void ScRangeManagerTable::Init()
144 SetUpdateMode(false);
145 Clear();
146 for (boost::ptr_map<OUString, ScRangeName>::const_iterator itr = mrRangeMap.begin();
147 itr != mrRangeMap.end(); ++itr)
149 const ScRangeName* pLocalRangeName = itr->second;
150 ScRangeNameLine aLine;
151 if ( itr->first == STR_GLOBAL_RANGE_NAME )
152 aLine.aScope = maGlobalString;
153 else
154 aLine.aScope = itr->first;
155 for (ScRangeName::const_iterator it = pLocalRangeName->begin();
156 it != pLocalRangeName->end(); ++it)
158 if (!it->second->HasType(RT_DATABASE))
160 aLine.aName = it->second->GetName();
161 addEntry(aLine, false);
165 SetUpdateMode(true);
168 const ScRangeData* ScRangeManagerTable::findRangeData(const ScRangeNameLine& rLine)
170 const ScRangeName* pRangeName;
171 if (rLine.aScope == maGlobalString)
172 pRangeName = mrRangeMap.find(OUString(STR_GLOBAL_RANGE_NAME))->second;
173 else
174 pRangeName = mrRangeMap.find(rLine.aScope)->second;
176 return pRangeName->findByUpperName(ScGlobal::pCharClass->uppercase(rLine.aName));
179 void ScRangeManagerTable::CheckForFormulaString()
181 for (SvTreeListEntry* pEntry = GetFirstEntryInView(); pEntry ; pEntry = GetNextEntryInView(pEntry))
183 std::map<SvTreeListEntry*, bool>::const_iterator itr = maCalculatedFormulaEntries.find(pEntry);
184 if (itr == maCalculatedFormulaEntries.end() || !itr->second)
186 ScRangeNameLine aLine;
187 GetLine( aLine, pEntry);
188 const ScRangeData* pData = findRangeData( aLine );
189 OUString aFormulaString;
190 pData->GetSymbol(aFormulaString, maPos);
191 SetEntryText(aFormulaString, pEntry, 1);
192 maCalculatedFormulaEntries.insert( std::pair<SvTreeListEntry*, bool>(pEntry, true) );
197 void ScRangeManagerTable::DeleteSelectedEntries()
199 if (GetSelectionCount())
200 RemoveSelection();
203 bool ScRangeManagerTable::IsMultiSelection()
205 return GetSelectionCount() > 1;
208 std::vector<ScRangeNameLine> ScRangeManagerTable::GetSelectedEntries()
210 std::vector<ScRangeNameLine> aSelectedEntries;
211 if (GetSelectionCount())
213 for (SvTreeListEntry* pEntry = FirstSelected(); pEntry != LastSelected(); pEntry = NextSelected(pEntry))
215 ScRangeNameLine aLine;
216 GetLine( aLine, pEntry );
217 aSelectedEntries.push_back(aLine);
219 SvTreeListEntry* pEntry = LastSelected();
220 ScRangeNameLine aLine;
221 GetLine( aLine, pEntry );
222 aSelectedEntries.push_back(aLine);
224 return aSelectedEntries;
227 void ScRangeManagerTable::SetEntry(const ScRangeNameLine& rLine)
229 for (SvTreeListEntry* pEntry = First(); pEntry; pEntry = Next(pEntry))
231 if (rLine.aName == GetEntryText(pEntry, 0)
232 && rLine.aScope == GetEntryText(pEntry, 2))
234 SetCurEntry(pEntry);
239 namespace {
241 //ensure that the minimum column size is respected
242 void CalculateItemSize(const long& rTableSize, long& rItemNameSize, long& rItemRangeSize)
244 long aItemScopeSize = rTableSize - rItemNameSize - rItemRangeSize;
246 if (rItemNameSize >= MINSIZE && rItemRangeSize >= MINSIZE && aItemScopeSize >= MINSIZE)
247 return;
249 if (rItemNameSize < MINSIZE)
251 long aDiffSize = MINSIZE - rItemNameSize;
252 if (rItemRangeSize > aItemScopeSize)
253 rItemRangeSize -= aDiffSize;
254 else
255 aItemScopeSize -= aDiffSize;
256 rItemNameSize = MINSIZE;
259 if (rItemRangeSize < MINSIZE)
261 long aDiffSize = MINSIZE - rItemRangeSize;
262 if (rItemNameSize > aItemScopeSize)
263 rItemNameSize -= aDiffSize;
264 else
265 aItemScopeSize -= aDiffSize;
266 rItemRangeSize = MINSIZE;
269 if (aItemScopeSize < MINSIZE)
271 long aDiffSize = MINSIZE - aItemScopeSize;
272 if (rItemNameSize > rItemRangeSize)
273 rItemNameSize -= aDiffSize;
274 else
275 rItemRangeSize -= aDiffSize;
281 IMPL_LINK_NOARG(ScRangeManagerTable, HeaderEndDragHdl)
283 HeaderBar& rHeaderBar = GetTheHeaderBar();
285 long nTableSize = rHeaderBar.GetSizePixel().Width();
286 long nItemNameSize = rHeaderBar.GetItemSize(ITEMID_NAME);
287 long nItemRangeSize = rHeaderBar.GetItemSize(ITEMID_RANGE);
289 //calculate column size based on user input and minimum size
290 CalculateItemSize(nTableSize, nItemNameSize, nItemRangeSize);
291 long nItemScopeSize = nTableSize - nItemNameSize - nItemRangeSize;
293 Size aSz(nItemNameSize, 0);
294 rHeaderBar.SetItemSize(ITEMID_NAME, nItemNameSize);
295 rHeaderBar.SetItemSize(ITEMID_RANGE, nItemRangeSize);
296 rHeaderBar.SetItemSize(ITEMID_SCOPE, nItemScopeSize);
298 SetTab(0, 0, MAP_APPFONT );
299 SetTab(1, PixelToLogic( aSz, MapMode(MAP_APPFONT) ).Width(), MAP_APPFONT );
300 aSz.Width() += nItemRangeSize;
301 SetTab(2, PixelToLogic( aSz, MapMode(MAP_APPFONT) ).Width(), MAP_APPFONT );
303 return 0;
306 IMPL_LINK_NOARG(ScRangeManagerTable, ScrollHdl)
308 CheckForFormulaString();
309 return 0;
312 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */