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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
|
/* -*- 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 "sal/config.h"
#include <officecfg/Office/Common.hxx>
#include <svtools/ctrltool.hxx>
#include <svtools/svlbitm.hxx>
#include <vcl/svapp.hxx>
#include <vcl/wrkwin.hxx>
#include <svtools/fontsubstconfig.hxx>
#include "fontsubs.hxx"
#include <dialmgr.hxx>
#include "helpid.hrc"
#include <cuires.hrc>
/*********************************************************************/
/* */
/* TabPage font replacement */
/* */
/*********************************************************************/
SvxFontSubstTabPage::SvxFontSubstTabPage( vcl::Window* pParent,
const SfxItemSet& rSet )
: SfxTabPage(pParent, "OptFontsPage", "cui/ui/optfontspage.ui", &rSet)
, pConfig(new SvtFontSubstConfig)
, pCheckButtonData(0)
{
get(m_pUseTableCB, "usetable");
get(m_pReplacements, "replacements");
get(m_pFont1CB, "font1");
get(m_pFont2CB, "font2");
m_pFont1CB->SetStyle(m_pFont1CB->GetStyle() | WB_SORT);
m_pFont2CB->SetStyle(m_pFont2CB->GetStyle() | WB_SORT);
get(m_pApply, "apply");
get(m_pDelete, "delete");
get(m_pFontNameLB, "fontname");
m_sAutomatic = m_pFontNameLB->GetEntry(0);
assert(!m_sAutomatic.isEmpty());
get(m_pNonPropFontsOnlyCB, "nonpropfontonly");
get(m_pFontHeightLB, "fontheight");
SvSimpleTableContainer *pCheckLBContainer = get<SvSimpleTableContainer>("checklb");
Size aControlSize(248, 75);
aControlSize = LogicToPixel(aControlSize, MAP_APPFONT);
pCheckLBContainer->set_width_request(aControlSize.Width());
pCheckLBContainer->set_height_request(aControlSize.Height());
m_pCheckLB = new SvxFontSubstCheckListBox(*pCheckLBContainer, 0);
m_pCheckLB->SetHelpId(HID_OFA_FONT_SUBST_CLB);
m_pCheckLB->SetStyle(m_pCheckLB->GetStyle()|WB_HSCROLL|WB_VSCROLL);
m_pCheckLB->SetSelectionMode(MULTIPLE_SELECTION);
m_pCheckLB->SortByCol(2);
long aStaticTabs[] = { 4, 0, 0, 0, 0 };
m_pCheckLB->SvSimpleTable::SetTabs(&aStaticTabs[0]);
OUString sHeader1(get<FixedText>("always")->GetText());
OUString sHeader2(get<FixedText>("screenonly")->GetText());
OUStringBuffer sHeader;
sHeader.append(sHeader1).append("\t").append(sHeader2)
.append("\t ").append(get<FixedText>("font")->GetText())
.append("\t ").append(get<FixedText>("replacewith")->GetText());
m_pCheckLB->InsertHeaderEntry(sHeader.makeStringAndClear());
HeaderBar &rBar = m_pCheckLB->GetTheHeaderBar();
HeaderBarItemBits nBits = rBar.GetItemBits(1) | HeaderBarItemBits::FIXEDPOS | HeaderBarItemBits::FIXED;
nBits &= ~HeaderBarItemBits::CLICKABLE;
rBar.SetItemBits(1, nBits);
rBar.SetItemBits(2, nBits);
m_pCheckLB->setColSizes();
aTextColor = m_pCheckLB->GetTextColor();
Link aLink(LINK(this, SvxFontSubstTabPage, SelectHdl));
m_pCheckLB->SetSelectHdl(aLink);
m_pUseTableCB->SetClickHdl(aLink);
m_pFont1CB->SetSelectHdl(aLink);
m_pFont1CB->SetModifyHdl(aLink);
m_pFont2CB->SetSelectHdl(aLink);
m_pFont2CB->SetModifyHdl(aLink);
m_pApply->SetClickHdl(aLink);
m_pDelete->SetClickHdl(aLink);
m_pNonPropFontsOnlyCB->SetClickHdl(LINK(this, SvxFontSubstTabPage, NonPropFontsHdl));
sal_uInt16 nHeight;
for(nHeight = 6; nHeight <= 16; nHeight++)
m_pFontHeightLB->InsertEntry(OUString::number(nHeight));
for(nHeight = 18; nHeight <= 28; nHeight+= 2)
m_pFontHeightLB->InsertEntry(OUString::number(nHeight));
for(nHeight = 32; nHeight <= 48; nHeight+= 4)
m_pFontHeightLB->InsertEntry(OUString::number(nHeight));
for(nHeight = 54; nHeight <= 72; nHeight+= 6)
m_pFontHeightLB->InsertEntry(OUString::number(nHeight));
for(nHeight = 80; nHeight <= 96; nHeight+= 8)
m_pFontHeightLB->InsertEntry(OUString::number(nHeight));
}
SvTreeListEntry* SvxFontSubstTabPage::CreateEntry(OUString& rFont1, OUString& rFont2)
{
SvTreeListEntry* pEntry = new SvTreeListEntry;
if( !pCheckButtonData )
pCheckButtonData = new SvLBoxButtonData( m_pCheckLB );
pEntry->AddItem( new SvLBoxContextBmp( pEntry, 0, Image(), Image(), false)); // Sonst Puff!
pEntry->AddItem( new SvLBoxButton( pEntry,
SvLBoxButtonKind_enabledCheckbox, 0,
pCheckButtonData ) );
pEntry->AddItem( new SvLBoxButton( pEntry,
SvLBoxButtonKind_enabledCheckbox, 0,
pCheckButtonData ) );
pEntry->AddItem( new SvLBoxString( pEntry, 0, rFont1 ) );
pEntry->AddItem( new SvLBoxString( pEntry, 0, rFont2 ) );
return pEntry;
}
SvxFontSubstTabPage::~SvxFontSubstTabPage()
{
delete pCheckButtonData;
delete pConfig;
delete m_pCheckLB;
}
SfxTabPage* SvxFontSubstTabPage::Create( vcl::Window* pParent,
const SfxItemSet* rAttrSet)
{
return new SvxFontSubstTabPage(pParent, *rAttrSet);
}
bool SvxFontSubstTabPage::FillItemSet( SfxItemSet* )
{
pConfig->ClearSubstitutions();// remove all entries
pConfig->Enable(m_pUseTableCB->IsChecked());
SvTreeListEntry* pEntry = m_pCheckLB->First();
while (pEntry)
{
SubstitutionStruct aAdd;
aAdd.sFont = SvTabListBox::GetEntryText(pEntry, 0);
aAdd.sReplaceBy = SvTabListBox::GetEntryText(pEntry, 1);
aAdd.bReplaceAlways = m_pCheckLB->IsChecked(pEntry, 0);
aAdd.bReplaceOnScreenOnly = m_pCheckLB->IsChecked(pEntry, 1);
pConfig->AddSubstitution(aAdd);
pEntry = m_pCheckLB->Next(pEntry);
}
if(pConfig->IsModified())
pConfig->Commit();
pConfig->Apply();
std::shared_ptr< comphelper::ConfigurationChanges > batch(
comphelper::ConfigurationChanges::create());
if(m_pFontHeightLB->IsValueChangedFromSaved())
officecfg::Office::Common::Font::SourceViewFont::FontHeight::set(
static_cast< sal_Int16 >(m_pFontHeightLB->GetSelectEntry().toInt32()),
batch);
if(m_pNonPropFontsOnlyCB->IsValueChangedFromSaved())
officecfg::Office::Common::Font::SourceViewFont::
NonProportionalFontsOnly::set(
m_pNonPropFontsOnlyCB->IsChecked(), batch);
//font name changes cannot be detected by saved values
OUString sFontName;
if(m_pFontNameLB->GetSelectEntryPos())
sFontName = m_pFontNameLB->GetSelectEntry();
officecfg::Office::Common::Font::SourceViewFont::FontName::set(
boost::optional< OUString >(sFontName), batch);
batch->commit();
return false;
}
void SvxFontSubstTabPage::Reset( const SfxItemSet* )
{
m_pCheckLB->SetUpdateMode(false);
m_pCheckLB->Clear();
FontList aFntLst( Application::GetDefaultDevice() );
m_pFont1CB->Fill( &aFntLst );
m_pFont2CB->Fill( &aFntLst );
sal_Int32 nCount = pConfig->SubstitutionCount();
if (nCount)
m_pUseTableCB->Check(pConfig->IsEnabled());
for (sal_Int32 i = 0; i < nCount; ++i)
{
const SubstitutionStruct* pSubs = pConfig->GetSubstitution(i);
OUString aTmpStr1(pSubs->sFont);
OUString aTmpStr2(pSubs->sReplaceBy);
SvTreeListEntry* pEntry = CreateEntry(aTmpStr1, aTmpStr2);
m_pCheckLB->Insert(pEntry);
m_pCheckLB->CheckEntry(pEntry, 0, pSubs->bReplaceAlways);
m_pCheckLB->CheckEntry(pEntry, 1, pSubs->bReplaceOnScreenOnly);
}
CheckEnable();
m_pCheckLB->SetUpdateMode(true);
//fill font name box first
m_pNonPropFontsOnlyCB->Check(
officecfg::Office::Common::Font::SourceViewFont::
NonProportionalFontsOnly::get());
NonPropFontsHdl(m_pNonPropFontsOnlyCB);
OUString sFontName(
officecfg::Office::Common::Font::SourceViewFont::FontName::get().
get_value_or(OUString()));
if(!sFontName.isEmpty())
m_pFontNameLB->SelectEntry(sFontName);
else
m_pFontNameLB->SelectEntryPos(0);
m_pFontHeightLB->SelectEntry(
OUString::number(
officecfg::Office::Common::Font::SourceViewFont::FontHeight::
get()));
m_pNonPropFontsOnlyCB->SaveValue();
m_pFontHeightLB->SaveValue();
}
IMPL_LINK(SvxFontSubstTabPage, SelectHdl, vcl::Window*, pWin)
{
if (pWin == m_pApply || pWin == m_pDelete)
{
SvTreeListEntry* pEntry;
// nCol is stupidly the nCol'th text column, not counted!
// Therefore "0" as column.
sal_uLong nPos = m_pCheckLB->GetEntryPos(m_pFont1CB->GetText(), 0);
if (pWin == m_pApply)
{
if (nPos != 0xffffffff)
{
// change entry
m_pCheckLB->SetEntryText(m_pFont2CB->GetText(), nPos, 1);
pEntry = m_pCheckLB->GetEntry(nPos);
}
else
{
// new entry
OUString sFont1 = m_pFont1CB->GetText();
OUString sFont2 = m_pFont2CB->GetText();
pEntry = CreateEntry(sFont1, sFont2);
m_pCheckLB->Insert(pEntry);
}
m_pCheckLB->SelectAll(false);
m_pCheckLB->Select(pEntry);
}
else if (pWin == m_pDelete)
{
if (nPos != 0xffffffff)
{
pEntry = m_pCheckLB->FirstSelected();
while (pEntry)
{
SvTreeListEntry* pDelEntry = pEntry;
pEntry = m_pCheckLB->NextSelected(pEntry);
m_pCheckLB->RemoveEntry(pDelEntry);
}
}
}
}
if (pWin == m_pCheckLB)
{
SvTreeListEntry* pEntry = m_pCheckLB->FirstSelected();
if (m_pCheckLB->NextSelected(pEntry) == 0)
{
m_pFont1CB->SetText(SvTabListBox::GetEntryText(pEntry, 0));
m_pFont2CB->SetText(SvTabListBox::GetEntryText(pEntry, 1));
}
}
if (pWin == m_pFont1CB)
{
sal_uLong nPos = m_pCheckLB->GetEntryPos(m_pFont1CB->GetText(), 0);
if (nPos != 0xffffffff)
{
SvTreeListEntry* pEntry = m_pCheckLB->GetEntry(nPos);
if (pEntry != m_pCheckLB->FirstSelected())
{
m_pCheckLB->SelectAll(false);
m_pCheckLB->Select(pEntry);
}
}
}
CheckEnable();
return 0;
}
IMPL_LINK(SvxFontSubstTabPage, NonPropFontsHdl, CheckBox*, pBox)
{
OUString sFontName = m_pFontNameLB->GetSelectEntry();
bool bNonPropOnly = pBox->IsChecked();
m_pFontNameLB->Clear();
FontList aFntLst( Application::GetDefaultDevice() );
m_pFontNameLB->InsertEntry(m_sAutomatic);
sal_uInt16 nFontCount = aFntLst.GetFontNameCount();
for(sal_uInt16 nFont = 0; nFont < nFontCount; nFont++)
{
const vcl::FontInfo& rInfo = aFntLst.GetFontName( nFont );
if(!bNonPropOnly || rInfo.GetPitch() == PITCH_FIXED)
m_pFontNameLB->InsertEntry(rInfo.GetName());
}
m_pFontNameLB->SelectEntry(sFontName);
return 0;
}
void SvxFontSubstTabPage::CheckEnable()
{
bool bEnableAll = m_pUseTableCB->IsChecked();
m_pReplacements->Enable(bEnableAll);
if (bEnableAll)
{
bool bApply, bDelete;
SvTreeListEntry* pEntry = m_pCheckLB->FirstSelected();
OUString sEntry = m_pFont1CB->GetText();
sEntry += "\t";
sEntry += m_pFont2CB->GetText();
// because of OS/2 optimization error (Bug #56267) a bit more intricate:
if (m_pFont1CB->GetText().isEmpty() || m_pFont2CB->GetText().isEmpty())
bApply = false;
else if(m_pFont1CB->GetText() == m_pFont2CB->GetText())
bApply = false;
else if(m_pCheckLB->GetEntryPos(sEntry) != 0xffffffff)
bApply = false;
else if(pEntry != 0 && m_pCheckLB->NextSelected(pEntry) != 0)
bApply = false;
else
bApply = true;
bDelete = pEntry != 0;
m_pApply->Enable(bApply);
m_pDelete->Enable(bDelete);
}
if (bEnableAll)
{
if (!m_pCheckLB->IsEnabled())
{
m_pCheckLB->EnableTable();
m_pCheckLB->SetTextColor(aTextColor);
m_pCheckLB->Invalidate();
SelectHdl(m_pFont1CB);
}
}
else
{
if (m_pCheckLB->IsEnabled())
{
m_pCheckLB->DisableTable();
m_pCheckLB->SetTextColor(Color(COL_GRAY));
m_pCheckLB->Invalidate();
m_pCheckLB->SelectAll(false);
}
}
}
void SvxFontSubstCheckListBox::setColSizes()
{
HeaderBar &rBar = GetTheHeaderBar();
if (rBar.GetItemCount() < 4)
return;
long nW1 = rBar.GetTextWidth(rBar.GetItemText(3));
long nW2 = rBar.GetTextWidth(rBar.GetItemText(4));
long nMax = std::max( nW1, nW2 ) + 6; // width of the longest header + a little offset
long nMin = rBar.LogicToPixel(Size(10, 0), MAP_APPFONT).Width();
nMax = std::max( nMax, nMin );
const long nDoubleMax = 2*nMax;
const long nRest = GetSizePixel().Width() - nDoubleMax;
long aStaticTabs[] = { 4, 0, 0, 0, 0 };
aStaticTabs[2] = nMax;
aStaticTabs[3] = nDoubleMax;
aStaticTabs[4] = nDoubleMax + nRest/2;
SvSimpleTable::SetTabs(aStaticTabs, MAP_PIXEL);
}
void SvxFontSubstCheckListBox::Resize()
{
SvSimpleTable::Resize();
setColSizes();
}
void SvxFontSubstCheckListBox::SetTabs()
{
SvSimpleTable::SetTabs();
sal_uInt16 nAdjust = SV_LBOXTAB_ADJUST_RIGHT|SV_LBOXTAB_ADJUST_LEFT|SV_LBOXTAB_ADJUST_CENTER|SV_LBOXTAB_ADJUST_NUMERIC|SV_LBOXTAB_FORCE;
SvLBoxTab* pTab = aTabs[1];
pTab->nFlags &= ~nAdjust;
pTab->nFlags |= SV_LBOXTAB_PUSHABLE|SV_LBOXTAB_ADJUST_CENTER|SV_LBOXTAB_FORCE;
pTab = aTabs[2];
pTab->nFlags &= ~nAdjust;
pTab->nFlags |= SV_LBOXTAB_PUSHABLE|SV_LBOXTAB_ADJUST_CENTER|SV_LBOXTAB_FORCE;
}
void SvxFontSubstCheckListBox::KeyInput( const KeyEvent& rKEvt )
{
if(!rKEvt.GetKeyCode().GetModifier() &&
KEY_SPACE == rKEvt.GetKeyCode().GetCode())
{
sal_uLong nSelPos = GetModel()->GetAbsPos(GetCurEntry());
sal_uInt16 nCol = GetCurrentTabPos() - 1;
if ( nCol < 2 )
{
CheckEntryPos( nSelPos, nCol, !IsChecked( nSelPos, nCol ) );
CallImplEventListeners( VCLEVENT_CHECKBOX_TOGGLE, (void*)GetEntry( nSelPos ) );
}
else
{
sal_uInt16 nCheck = IsChecked(nSelPos, 1) ? 1 : 0;
if(IsChecked(nSelPos, 0))
nCheck += 2;
nCheck--;
nCheck &= 3;
CheckEntryPos(nSelPos, 1, 0 != (nCheck & 1));
CheckEntryPos(nSelPos, 0, 0 != (nCheck & 2));
}
}
else
SvSimpleTable::KeyInput(rKEvt);
}
void SvxFontSubstCheckListBox::CheckEntryPos(sal_uLong nPos, sal_uInt16 nCol, bool bChecked)
{
if ( nPos < GetEntryCount() )
SetCheckButtonState(
GetEntry(nPos),
nCol,
bChecked ? SvButtonState( SV_BUTTON_CHECKED ) :
SvButtonState( SV_BUTTON_UNCHECKED ) );
}
void SvxFontSubstCheckListBox::CheckEntry(SvTreeListEntry* pEntry, sal_uInt16 nCol, bool bChecked)
{
if ( pEntry )
SetCheckButtonState(
pEntry,
nCol,
bChecked ? SvButtonState( SV_BUTTON_CHECKED ) :
SvButtonState( SV_BUTTON_UNCHECKED ) );
}
bool SvxFontSubstCheckListBox::IsChecked(sal_uLong nPos, sal_uInt16 nCol)
{
return GetCheckButtonState( GetEntry(nPos), nCol ) == SV_BUTTON_CHECKED;
}
bool SvxFontSubstCheckListBox::IsChecked(SvTreeListEntry* pEntry, sal_uInt16 nCol)
{
return GetCheckButtonState( pEntry, nCol ) == SV_BUTTON_CHECKED;
}
void SvxFontSubstCheckListBox::SetCheckButtonState( SvTreeListEntry* pEntry, sal_uInt16 nCol, SvButtonState eState)
{
SvLBoxButton* pItem = static_cast<SvLBoxButton*>(pEntry->GetItem(nCol + 1));
DBG_ASSERT(pItem,"SetCheckButton:Item not found");
if (pItem->GetType() == SV_ITEM_ID_LBOXBUTTON)
{
switch( eState )
{
case SV_BUTTON_CHECKED:
pItem->SetStateChecked();
break;
case SV_BUTTON_UNCHECKED:
pItem->SetStateUnchecked();
break;
case SV_BUTTON_TRISTATE:
pItem->SetStateTristate();
break;
}
InvalidateEntry( pEntry );
}
}
SvButtonState SvxFontSubstCheckListBox::GetCheckButtonState( SvTreeListEntry* pEntry, sal_uInt16 nCol ) const
{
SvButtonState eState = SV_BUTTON_UNCHECKED;
SvLBoxButton* pItem = static_cast<SvLBoxButton*>(pEntry->GetItem(nCol + 1));
DBG_ASSERT(pItem,"GetChButnState:Item not found");
if (pItem->GetType() == SV_ITEM_ID_LBOXBUTTON)
{
SvItemStateFlags nButtonFlags = pItem->GetButtonFlags();
eState = SvLBoxButtonData::ConvertToButtonState( nButtonFlags );
}
return eState;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|