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 : #include "cmdid.h"
21 : #include "swmodule.hxx"
22 : #include "view.hxx"
23 : #include "wrtsh.hxx"
24 : #include "globals.hrc"
25 : #include "helpid.h"
26 :
27 : #include <sfx2/styfitem.hxx>
28 :
29 : #include "uitool.hxx"
30 : #include "ccoll.hxx"
31 : #include "fmtcol.hxx"
32 : #include "hintids.hxx"
33 : #include "docsh.hxx"
34 : #include "docstyle.hxx"
35 : #include "hints.hxx"
36 :
37 : #include "chrdlg.hrc"
38 : #include <vcl/svapp.hxx>
39 :
40 : #include "swuiccoll.hxx"
41 :
42 : const sal_uInt16 SwCondCollPage::m_aPageRg[] = {
43 : FN_COND_COLL, FN_COND_COLL,
44 : 0
45 : };
46 :
47 : // Warning! This table is indicated directly in code (0, 1, ...)
48 : static long nTabs[] =
49 : { 2, // Number of Tabs
50 : 0, 100
51 : };
52 :
53 0 : SwCondCollPage::SwCondCollPage(vcl::Window *pParent, const SfxItemSet &rSet)
54 : : SfxTabPage(pParent, "ConditionPage",
55 : "modules/swriter/ui/conditionpage.ui", &rSet)
56 : ,
57 0 : m_rSh(::GetActiveView()->GetWrtShell()),
58 0 : m_pCmds( SwCondCollItem::GetCmds() ),
59 : m_pFormat(0),
60 :
61 0 : m_bNewTemplate(false)
62 : {
63 0 : get(m_pConditionCB, "condstyle");
64 0 : get(m_pContextFT, "contextft");
65 0 : get(m_pUsedFT, "usedft");
66 0 : get(m_pStyleFT, "styleft");
67 0 : get(m_pTbLinks, "links");
68 0 : get(m_pStyleLB, "styles");
69 0 : m_pStyleLB->SetStyle(m_pStyleLB->GetStyle() | WB_SORT);
70 0 : m_pStyleLB->SetDropDownLineCount(12);
71 0 : m_pTbLinks->set_height_request(m_pStyleLB->GetOptimalSize().Height());
72 0 : get(m_pFilterLB, "filter");
73 0 : get(m_pRemovePB, "remove");
74 0 : get(m_pAssignPB, "apply");
75 :
76 0 : const sal_Int32 nStrCount = m_pFilterLB->GetEntryCount();
77 0 : for (sal_Int32 i = 0; i < nStrCount; ++i)
78 0 : m_aStrArr.push_back(m_pFilterLB->GetEntry(i));
79 0 : m_pFilterLB->Clear();
80 :
81 0 : SetExchangeSupport();
82 :
83 : // Install handlers
84 0 : m_pConditionCB->SetClickHdl( LINK(this, SwCondCollPage, OnOffHdl));
85 0 : m_pTbLinks->SetDoubleClickHdl( LINK(this, SwCondCollPage, AssignRemoveHdl ));
86 0 : m_pStyleLB->SetDoubleClickHdl( LINK(this, SwCondCollPage, AssignRemoveHdl ));
87 0 : m_pRemovePB->SetClickHdl( LINK(this, SwCondCollPage, AssignRemoveHdl ));
88 0 : m_pAssignPB->SetClickHdl( LINK(this, SwCondCollPage, AssignRemoveHdl ));
89 0 : m_pTbLinks->SetSelectHdl( LINK(this, SwCondCollPage, SelectHdl));
90 0 : m_pStyleLB->SetSelectHdl( LINK(this, SwCondCollPage, SelectHdl));
91 0 : m_pFilterLB->SetSelectHdl( LINK(this, SwCondCollPage, SelectHdl));
92 :
93 0 : m_pTbLinks->SetStyle(m_pTbLinks->GetStyle()|WB_HSCROLL|WB_CLIPCHILDREN);
94 0 : m_pTbLinks->SetSelectionMode( SINGLE_SELECTION );
95 0 : m_pTbLinks->SetTabs( &nTabs[0], MAP_APPFONT );
96 0 : m_pTbLinks->Resize(); // OS: Hack for the right selection
97 0 : m_pTbLinks->SetSpaceBetweenEntries( 0 );
98 :
99 0 : SfxStyleFamilies aFamilies(SW_RES(DLG_STYLE_DESIGNER));
100 0 : const SfxStyleFamilyItem* pFamilyItem = 0;
101 :
102 0 : size_t nCount = aFamilies.size();
103 0 : for( size_t i = 0; i < nCount; ++i )
104 : {
105 0 : if(SFX_STYLE_FAMILY_PARA == (pFamilyItem = aFamilies.at( i ))->GetFamily())
106 0 : break;
107 : }
108 :
109 0 : if (pFamilyItem)
110 : {
111 0 : const SfxStyleFilter& rFilterList = pFamilyItem->GetFilterList();
112 0 : for( size_t i = 0; i < rFilterList.size(); ++i )
113 : {
114 0 : m_pFilterLB->InsertEntry( rFilterList[ i ]->aName);
115 0 : sal_uInt16* pFilter = new sal_uInt16(rFilterList[i]->nFlags);
116 0 : m_pFilterLB->SetEntryData(i, pFilter);
117 : }
118 : }
119 0 : m_pFilterLB->SelectEntryPos(1);
120 :
121 0 : m_pTbLinks->Show();
122 :
123 0 : }
124 :
125 0 : SwCondCollPage::~SwCondCollPage()
126 : {
127 0 : disposeOnce();
128 0 : }
129 :
130 0 : void SwCondCollPage::dispose()
131 : {
132 0 : for(sal_Int32 i = 0; i < m_pFilterLB->GetEntryCount(); ++i)
133 0 : delete static_cast<sal_uInt16*>(m_pFilterLB->GetEntryData(i));
134 :
135 0 : m_pConditionCB.clear();
136 0 : m_pContextFT.clear();
137 0 : m_pUsedFT.clear();
138 0 : m_pTbLinks.clear();
139 0 : m_pStyleFT.clear();
140 0 : m_pStyleLB.clear();
141 0 : m_pFilterLB.clear();
142 0 : m_pRemovePB.clear();
143 0 : m_pAssignPB.clear();
144 :
145 0 : SfxTabPage::dispose();
146 0 : }
147 :
148 0 : SfxTabPage::sfxpg SwCondCollPage::DeactivatePage(SfxItemSet * _pSet)
149 : {
150 0 : if( _pSet )
151 0 : FillItemSet(_pSet);
152 :
153 0 : return LEAVE_PAGE;
154 : }
155 :
156 0 : VclPtr<SfxTabPage> SwCondCollPage::Create(vcl::Window *pParent, const SfxItemSet *rSet)
157 : {
158 0 : return VclPtr<SwCondCollPage>::Create(pParent, *rSet);
159 : }
160 :
161 0 : bool SwCondCollPage::FillItemSet(SfxItemSet *rSet)
162 : {
163 0 : bool bModified = true;
164 0 : SwCondCollItem aCondItem;
165 0 : for (size_t i = 0; i < m_aStrArr.size(); ++i)
166 : {
167 0 : const OUString sEntry = m_pTbLinks->GetEntryText(i, 1);
168 0 : aCondItem.SetStyle( &sEntry, i);
169 0 : }
170 0 : rSet->Put(aCondItem);
171 0 : return bModified;
172 : }
173 :
174 0 : void SwCondCollPage::Reset(const SfxItemSet *)
175 : {
176 0 : if(m_bNewTemplate)
177 0 : m_pConditionCB->Enable();
178 0 : if(RES_CONDTXTFMTCOLL == m_pFormat->Which())
179 0 : m_pConditionCB->Check();
180 0 : OnOffHdl(m_pConditionCB);
181 :
182 0 : m_pTbLinks->Clear();
183 :
184 0 : SfxStyleSheetBasePool* pPool = m_rSh.GetView().GetDocShell()->GetStyleSheetPool();
185 0 : pPool->SetSearchMask(SFX_STYLE_FAMILY_PARA, SFXSTYLEBIT_ALL);
186 0 : m_pStyleLB->Clear();
187 0 : const SfxStyleSheetBase* pBase = pPool->First();
188 0 : while( pBase )
189 : {
190 0 : if(!m_pFormat || pBase->GetName() != m_pFormat->GetName())
191 0 : m_pStyleLB->InsertEntry(pBase->GetName());
192 0 : pBase = pPool->Next();
193 : }
194 0 : m_pStyleLB->SelectEntryPos(0);
195 :
196 0 : for (size_t n = 0; n < m_aStrArr.size(); ++n)
197 : {
198 0 : OUString aEntry( m_aStrArr[n] + "\t" );
199 :
200 0 : const SwCollCondition* pCond = 0;
201 0 : if( m_pFormat && RES_CONDTXTFMTCOLL == m_pFormat->Which() &&
202 : 0 != ( pCond = static_cast<SwConditionTextFormatColl*>(m_pFormat)->
203 0 : HasCondition( SwCollCondition( 0, m_pCmds[n].nCnd, m_pCmds[n].nSubCond ) ) )
204 0 : && pCond->GetTextFormatColl() )
205 : {
206 0 : aEntry += pCond->GetTextFormatColl()->GetName();
207 : }
208 :
209 0 : SvTreeListEntry* pE = m_pTbLinks->InsertEntryToColumn( aEntry, n );
210 0 : if(0 == n)
211 0 : m_pTbLinks->Select(pE);
212 0 : }
213 :
214 0 : }
215 :
216 0 : IMPL_LINK( SwCondCollPage, OnOffHdl, CheckBox*, pBox )
217 : {
218 0 : const bool bEnable = pBox->IsChecked();
219 0 : m_pContextFT->Enable( bEnable );
220 0 : m_pUsedFT->Enable( bEnable );
221 0 : m_pTbLinks->EnableList( bEnable );
222 0 : m_pStyleFT->Enable( bEnable );
223 0 : m_pStyleLB->Enable( bEnable );
224 0 : m_pFilterLB->Enable( bEnable );
225 0 : m_pRemovePB->Enable( bEnable );
226 0 : m_pAssignPB->Enable( bEnable );
227 0 : if( bEnable )
228 0 : SelectHdl(0);
229 0 : return 0;
230 : }
231 :
232 0 : IMPL_LINK( SwCondCollPage, AssignRemoveHdl, PushButton*, pBtn)
233 : {
234 0 : SvTreeListEntry* pE = m_pTbLinks->FirstSelected();
235 : sal_uLong nPos;
236 0 : if( !pE || LISTBOX_ENTRY_NOTFOUND ==
237 0 : ( nPos = m_pTbLinks->GetModel()->GetAbsPos( pE ) ) )
238 : {
239 : OSL_ENSURE( pE, "where's the empty entry from?" );
240 0 : return 0;
241 : }
242 :
243 0 : OUString sSel = m_aStrArr[nPos] + "\t";
244 :
245 0 : const bool bAssEnabled = pBtn != m_pRemovePB && m_pAssignPB->IsEnabled();
246 0 : m_pAssignPB->Enable( !bAssEnabled );
247 0 : m_pRemovePB->Enable( bAssEnabled );
248 0 : if ( bAssEnabled )
249 0 : sSel += m_pStyleLB->GetSelectEntry();
250 :
251 0 : m_pTbLinks->SetUpdateMode(false);
252 0 : m_pTbLinks->GetModel()->Remove(pE);
253 0 : pE = m_pTbLinks->InsertEntryToColumn(sSel, nPos);
254 0 : m_pTbLinks->Select(pE);
255 0 : m_pTbLinks->MakeVisible(pE);
256 0 : m_pTbLinks->SetUpdateMode(true);
257 0 : return 0;
258 : }
259 :
260 0 : IMPL_LINK( SwCondCollPage, SelectHdl, ListBox*, pBox)
261 : {
262 0 : if (pBox == m_pFilterLB)
263 : {
264 0 : m_pStyleLB->Clear();
265 0 : const sal_Int32 nSelPos = pBox->GetSelectEntryPos();
266 0 : const sal_uInt16 nSearchFlags = *static_cast<sal_uInt16*>(m_pFilterLB->GetEntryData(nSelPos));
267 0 : SfxStyleSheetBasePool* pPool = m_rSh.GetView().GetDocShell()->GetStyleSheetPool();
268 0 : pPool->SetSearchMask(SFX_STYLE_FAMILY_PARA, nSearchFlags);
269 0 : const SfxStyleSheetBase* pBase = pPool->First();
270 :
271 0 : while( pBase )
272 : {
273 0 : if(!m_pFormat || pBase->GetName() != m_pFormat->GetName())
274 0 : m_pStyleLB->InsertEntry(pBase->GetName());
275 0 : pBase = pPool->Next();
276 : }
277 0 : m_pStyleLB->SelectEntryPos(0);
278 0 : SelectHdl(m_pStyleLB);
279 :
280 : }
281 : else
282 : {
283 0 : SvTreeListEntry* pE = m_pTbLinks->FirstSelected();
284 : const OUString sTbEntry = pE
285 0 : ? m_pTbLinks->GetEntryText(pE).getToken(1, '\t')
286 0 : : OUString();
287 0 : const OUString sStyle = m_pStyleLB->GetSelectEntry();
288 :
289 0 : m_pAssignPB->Enable( sStyle != sTbEntry && m_pConditionCB->IsChecked() );
290 :
291 0 : if(pBox != m_pStyleLB)
292 0 : m_pRemovePB->Enable( m_pConditionCB->IsChecked() && !sTbEntry.isEmpty() );
293 : }
294 0 : return 0;
295 : }
296 :
297 0 : void SwCondCollPage::SetCollection(SwFormat* pFormat, bool bNew)
298 : {
299 0 : m_pFormat = pFormat;
300 0 : m_bNewTemplate = bNew;
301 0 : }
302 :
303 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|