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