fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / condformat / condformatmgr.cxx
blob05ad63aa6ec9ae9ee43561fe66fdd262a0c4cd7a
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 #include "condformatmgr.hxx"
11 #include "scresid.hxx"
12 #include "globstr.hrc"
13 #include "condformatdlg.hxx"
14 #include <vcl/msgbox.hxx>
15 #include "document.hxx"
17 ScCondFormatManagerWindow::ScCondFormatManagerWindow(SvSimpleTableContainer& rParent,
18 ScDocument* pDoc, ScConditionalFormatList* pFormatList)
19 : SvSimpleTable(rParent, WB_HSCROLL | WB_SORT | WB_TABSTOP)
20 , mpDoc(pDoc)
21 , mpFormatList(pFormatList)
23 OUString aConditionStr(ScGlobal::GetRscString(STR_HEADER_COND));
24 OUString aRangeStr(ScGlobal::GetRscString(STR_HEADER_RANGE));
26 OUStringBuffer sHeader;
27 sHeader.append(aRangeStr).append("\t").append(aConditionStr);
28 InsertHeaderEntry(sHeader.makeStringAndClear(), HEADERBAR_APPEND, HeaderBarItemBits::LEFT | HeaderBarItemBits::VCENTER);
29 setColSizes();
31 Init();
32 Show();
33 SetSelectionMode(MULTIPLE_SELECTION);
36 OUString ScCondFormatManagerWindow::createEntryString(const ScConditionalFormat& rFormat)
38 ScRangeList aRange = rFormat.GetRange();
39 OUString aStr;
40 aRange.Format(aStr, SCA_VALID, mpDoc, mpDoc->GetAddressConvention());
41 aStr += "\t";
42 aStr += ScCondFormatHelper::GetExpression(rFormat, aRange.GetTopLeftCorner());
43 return aStr;
46 void ScCondFormatManagerWindow::Init()
48 SetUpdateMode(false);
50 if (mpFormatList)
52 for(ScConditionalFormatList::iterator itr = mpFormatList->begin(); itr != mpFormatList->end(); ++itr)
54 SvTreeListEntry* pEntry = InsertEntryToColumn( createEntryString(*itr), TREELIST_APPEND, 0xffff );
55 maMapLBoxEntryToCondIndex.insert(std::pair<SvTreeListEntry*,sal_Int32>(pEntry,itr->GetKey()));
59 SetUpdateMode(true);
61 if (mpFormatList && mpFormatList->size())
62 SelectRow(0);
65 void ScCondFormatManagerWindow::Resize()
67 SvSimpleTable::Resize();
68 if (GetParentDialog()->isCalculatingInitialLayoutSize())
69 setColSizes();
72 void ScCondFormatManagerWindow::DeleteSelection()
74 if(GetSelectionCount())
76 for(SvTreeListEntry* pEntry = FirstSelected(); pEntry != NULL; pEntry = NextSelected(pEntry))
78 sal_Int32 nIndex = maMapLBoxEntryToCondIndex.find(pEntry)->second;
79 mpFormatList->erase(nIndex);
81 RemoveSelection();
85 ScConditionalFormat* ScCondFormatManagerWindow::GetSelection()
87 SvTreeListEntry* pEntry = FirstSelected();
88 if(!pEntry)
89 return NULL;
91 sal_Int32 nIndex = maMapLBoxEntryToCondIndex.find(pEntry)->second;
92 return mpFormatList->GetFormat(nIndex);
95 void ScCondFormatManagerWindow::setColSizes()
97 HeaderBar &rBar = GetTheHeaderBar();
98 if (rBar.GetItemCount() < 2)
99 return;
100 long aStaticTabs[]= { 2, 0, 0 };
101 aStaticTabs[2] = rBar.GetSizePixel().Width() / 2;
102 SvSimpleTable::SetTabs(aStaticTabs, MAP_PIXEL);
105 ScCondFormatManagerDlg::ScCondFormatManagerDlg(vcl::Window* pParent, ScDocument* pDoc, const ScConditionalFormatList* pFormatList, const ScAddress& rPos):
106 ModalDialog(pParent, "CondFormatManager", "modules/scalc/ui/condformatmanager.ui"),
107 mpFormatList( pFormatList ? new ScConditionalFormatList(*pFormatList) : NULL),
108 mpDoc(pDoc),
109 maPos(rPos),
110 mbModified(false)
112 SvSimpleTableContainer *pContainer = get<SvSimpleTableContainer>("CONTAINER");
113 Size aSize(LogicToPixel(Size(290, 220), MAP_APPFONT));
114 pContainer->set_width_request(aSize.Width());
115 pContainer->set_height_request(aSize.Height());
116 m_pCtrlManager = VclPtr<ScCondFormatManagerWindow>::Create(*pContainer, mpDoc, mpFormatList);
117 get(m_pBtnAdd, "add");
118 get(m_pBtnRemove, "remove");
119 get(m_pBtnEdit, "edit");
121 m_pBtnRemove->SetClickHdl(LINK(this, ScCondFormatManagerDlg, RemoveBtnHdl));
122 m_pBtnEdit->SetClickHdl(LINK(this, ScCondFormatManagerDlg, EditBtnHdl));
123 m_pBtnAdd->SetClickHdl(LINK(this, ScCondFormatManagerDlg, AddBtnHdl));
124 m_pCtrlManager->SetDoubleClickHdl(LINK(this, ScCondFormatManagerDlg, EditBtnHdl));
127 ScCondFormatManagerDlg::~ScCondFormatManagerDlg()
129 disposeOnce();
132 void ScCondFormatManagerDlg::dispose()
134 delete mpFormatList;
135 m_pBtnAdd.clear();
136 m_pBtnRemove.clear();
137 m_pBtnEdit.clear();
138 m_pCtrlManager.disposeAndClear();
139 ModalDialog::dispose();
143 ScConditionalFormatList* ScCondFormatManagerDlg::GetConditionalFormatList()
145 ScConditionalFormatList* pList = mpFormatList;
146 mpFormatList = NULL;
147 return pList;
150 // ---------------------------------------------------------------
151 // Get the current conditional format selected.
153 ScConditionalFormat* ScCondFormatManagerDlg::GetCondFormatSelected()
155 return m_pCtrlManager->GetSelection();
158 IMPL_LINK_NOARG(ScCondFormatManagerDlg, RemoveBtnHdl)
160 m_pCtrlManager->DeleteSelection();
161 mbModified = true;
162 return 0;
165 IMPL_LINK_NOARG(ScCondFormatManagerDlg, EditBtnHdl)
167 ScConditionalFormat* pFormat = m_pCtrlManager->GetSelection();
169 if(!pFormat)
170 return 0;
172 EndDialog( DLG_RET_EDIT );
174 return 0;
177 IMPL_LINK_NOARG(ScCondFormatManagerDlg, AddBtnHdl)
179 EndDialog( DLG_RET_ADD );
181 return 0;
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */