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/.
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
)
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
);
33 SetSelectionMode(MULTIPLE_SELECTION
);
36 OUString
ScCondFormatManagerWindow::createEntryString(const ScConditionalFormat
& rFormat
)
38 ScRangeList aRange
= rFormat
.GetRange();
40 aRange
.Format(aStr
, SCA_VALID
, mpDoc
, mpDoc
->GetAddressConvention());
42 aStr
+= ScCondFormatHelper::GetExpression(rFormat
, aRange
.GetTopLeftCorner());
46 void ScCondFormatManagerWindow::Init()
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()));
61 if (mpFormatList
&& mpFormatList
->size())
65 void ScCondFormatManagerWindow::Resize()
67 SvSimpleTable::Resize();
68 if (GetParentDialog()->isCalculatingInitialLayoutSize())
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
);
85 ScConditionalFormat
* ScCondFormatManagerWindow::GetSelection()
87 SvTreeListEntry
* pEntry
= FirstSelected();
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)
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
),
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()
132 void ScCondFormatManagerDlg::dispose()
136 m_pBtnRemove
.clear();
138 m_pCtrlManager
.disposeAndClear();
139 ModalDialog::dispose();
143 ScConditionalFormatList
* ScCondFormatManagerDlg::GetConditionalFormatList()
145 ScConditionalFormatList
* pList
= mpFormatList
;
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();
165 IMPL_LINK_NOARG(ScCondFormatManagerDlg
, EditBtnHdl
)
167 ScConditionalFormat
* pFormat
= m_pCtrlManager
->GetSelection();
172 EndDialog( DLG_RET_EDIT
);
177 IMPL_LINK_NOARG(ScCondFormatManagerDlg
, AddBtnHdl
)
179 EndDialog( DLG_RET_ADD
);
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */