LibreOffice Module cui (master)  1
srchxtra.cxx
Go to the documentation of this file.
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 <srchxtra.hxx>
21 #include <sal/log.hxx>
22 #include <svl/cjkoptions.hxx>
23 #include <svl/intitem.hxx>
24 #include <svl/whiter.hxx>
25 #include <sfx2/objsh.hxx>
26 #include <svx/flagsdef.hxx>
27 #include <svx/strarray.hxx>
28 #include <editeng/flstitem.hxx>
29 #include <chardlg.hxx>
30 #include <paragrph.hxx>
31 #include <backgrnd.hxx>
32 #include <editeng/editids.hrc>
33 #include <svx/svxids.hrc>
34 #include <tools/debug.hxx>
35 #include <tools/resary.hxx>
36 #include <vcl/svapp.hxx>
37 
39  : SfxTabDialogController(pParent, "cui/ui/searchformatdialog.ui", "SearchFormatDialog", &rSet)
40 {
41  AddTabPage("font", SvxCharNamePage::Create, nullptr);
42  AddTabPage("fonteffects", SvxCharEffectsPage::Create, nullptr);
43  AddTabPage("position", SvxCharPositionPage::Create, nullptr);
44  AddTabPage("asianlayout", SvxCharTwoLinesPage::Create, nullptr);
45  AddTabPage("labelTP_PARA_STD", SvxStdParagraphTabPage::Create, nullptr);
46  AddTabPage("labelTP_PARA_ALIGN", SvxParaAlignTabPage::Create, nullptr);
47  AddTabPage("labelTP_PARA_EXT", SvxExtParagraphTabPage::Create, nullptr);
48  AddTabPage("labelTP_PARA_ASIAN", SvxAsianTabPage::Create, nullptr );
49  AddTabPage("background", SvxBkgTabPage::Create, nullptr);
50 
51  // remove asian tabpages if necessary
52  SvtCJKOptions aCJKOptions;
53  if ( !aCJKOptions.IsDoubleLinesEnabled() )
54  RemoveTabPage("asianlayout");
55  if ( !aCJKOptions.IsAsianTypographyEnabled() )
56  RemoveTabPage("labelTP_PARA_ASIAN");
57 }
58 
60 {
61 }
62 
63 void SvxSearchFormatDialog::PageCreated(const OString& rId, SfxTabPage& rPage)
64 {
65  if (rId == "font")
66  {
67  const FontList* pApm_pFontList = nullptr;
69 
70  if ( pSh )
71  {
72  const SvxFontListItem* pFLItem = static_cast<const SvxFontListItem*>(
73  pSh->GetItem( SID_ATTR_CHAR_FONTLIST ));
74  if ( pFLItem )
75  pApm_pFontList = pFLItem->GetFontList();
76  }
77 
78  const FontList* pList = pApm_pFontList;
79 
80  if ( !pList )
81  {
82  if ( !m_pFontList )
84  pList = m_pFontList.get();
85  }
86 
87  static_cast<SvxCharNamePage&>(rPage).
88  SetFontList( SvxFontListItem( pList, SID_ATTR_CHAR_FONTLIST ) );
89  static_cast<SvxCharNamePage&>(rPage).EnableSearchMode();
90  }
91  else if (rId == "labelTP_PARA_STD")
92  {
93  static_cast<SvxStdParagraphTabPage&>(rPage).EnableAutoFirstLine();
94  }
95  else if (rId == "labelTP_PARA_ALIGN")
96  {
97  static_cast<SvxParaAlignTabPage&>(rPage).EnableJustifyExt();
98  }
99  else if (rId == "background")
100  {
101  SfxAllItemSet aSet(*(GetInputSetImpl()->GetPool()));
102  aSet.Put(SfxUInt32Item(SID_FLAG_TYPE,static_cast<sal_uInt32>(SvxBackgroundTabFlags::SHOW_HIGHLIGHTING)));
103  rPage.PageCreated(aSet);
104  }
105 }
106 
108  SearchAttrItemList& rLst, const sal_uInt16* pWhRanges)
109  : GenericDialogController(pParent, "cui/ui/searchattrdialog.ui", "SearchAttrDialog")
110  , rList(rLst)
111  , m_xAttrLB(m_xBuilder->weld_tree_view("treeview"))
112  , m_xOKBtn(m_xBuilder->weld_button("ok"))
113 {
114  m_xAttrLB->set_size_request(m_xAttrLB->get_approximate_digit_width() * 50,
115  m_xAttrLB->get_height_rows(12));
116 
117  std::vector<int> aWidths;
118  aWidths.push_back(m_xAttrLB->get_checkbox_column_width());
119  m_xAttrLB->set_column_fixed_widths(aWidths);
120 
121  m_xOKBtn->connect_clicked(LINK( this, SvxSearchAttributeDialog, OKHdl));
122 
124  DBG_ASSERT( pSh, "No DocShell" );
125 
126  SfxItemPool& rPool = pSh->GetPool();
127  SfxItemSet aSet( rPool, pWhRanges );
128  SfxWhichIter aIter( aSet );
129  sal_uInt16 nWhich = aIter.FirstWhich();
130 
131  while ( nWhich )
132  {
133  sal_uInt16 nSlot = rPool.GetSlotId( nWhich );
134  if ( nSlot >= SID_SVX_START )
135  {
136  bool bChecked = false, bFound = false;
137  for ( sal_uInt16 i = 0; !bFound && i < rList.Count(); ++i )
138  {
139  if ( nSlot == rList[i].nSlot )
140  {
141  bFound = true;
142  if ( IsInvalidItem( rList[i].pItem ) )
143  bChecked = true;
144  }
145  }
146 
147  // item resources are in svx
148  sal_uInt32 nId = SvxAttrNameTable::FindIndex(nSlot);
149  if (RESARRAY_INDEX_NOTFOUND != nId)
150  {
151  m_xAttrLB->append();
152  const int nRow = m_xAttrLB->n_children() - 1;
153  m_xAttrLB->set_toggle(nRow, bChecked ? TRISTATE_TRUE : TRISTATE_FALSE, 0);
154  m_xAttrLB->set_text(nRow, SvxAttrNameTable::GetString(nId), 1);
155  m_xAttrLB->set_id(nRow, OUString::number(nSlot));
156  }
157  else
158  SAL_WARN( "cui.dialogs", "no resource for slot id " << static_cast<sal_Int32>(nSlot) );
159  }
160  nWhich = aIter.NextWhich();
161  }
162 
163  m_xAttrLB->make_sorted();
164  m_xAttrLB->select(0);
165 }
166 
168 {
169 }
170 
172 {
173  SearchAttrItem aInvalidItem;
174  aInvalidItem.pItem = INVALID_POOL_ITEM;
175 
176  for (int i = 0, nCount = m_xAttrLB->n_children(); i < nCount; ++i)
177  {
178  sal_uInt16 nSlot = m_xAttrLB->get_id(i).toUInt32();
179  bool bChecked = m_xAttrLB->get_toggle(i, 0) == TRISTATE_TRUE;
180 
181  sal_uInt16 j;
182  for ( j = rList.Count(); j; )
183  {
184  SearchAttrItem& rItem = rList[ --j ];
185  if( rItem.nSlot == nSlot )
186  {
187  if( bChecked )
188  {
189  if( !IsInvalidItem( rItem.pItem ) )
190  delete rItem.pItem;
191  rItem.pItem = INVALID_POOL_ITEM;
192  }
193  else if( IsInvalidItem( rItem.pItem ) )
194  rItem.pItem = nullptr;
195  j = 1;
196  break;
197  }
198  }
199 
200  if ( !j && bChecked )
201  {
202  aInvalidItem.nSlot = nSlot;
203  rList.Insert( aInvalidItem );
204  }
205  }
206 
207  // remove invalid items (pItem == NULL)
208  for ( sal_uInt16 n = rList.Count(); n; )
209  if ( !rList[ --n ].pItem )
210  rList.Remove( n );
211 
212  m_xDialog->response(RET_OK);
213 }
214 
215 // class SvxSearchSimilarityDialog ---------------------------------------
216 
218  sal_uInt16 nOther, sal_uInt16 nShorter, sal_uInt16 nLonger)
219  : GenericDialogController(pParent, "cui/ui/similaritysearchdialog.ui", "SimilaritySearchDialog")
220  , m_xOtherFld(m_xBuilder->weld_spin_button("otherfld"))
221  , m_xLongerFld(m_xBuilder->weld_spin_button("longerfld"))
222  , m_xShorterFld(m_xBuilder->weld_spin_button("shorterfld"))
223  , m_xRelaxBox(m_xBuilder->weld_check_button("relaxbox"))
224 {
225  m_xOtherFld->set_value(nOther);
226  m_xShorterFld->set_value(nShorter);
227  m_xLongerFld->set_value(nLonger);
228  m_xRelaxBox->set_active(bRelax);
229 }
230 
232 {
233 }
234 
235 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
IMPL_LINK_NOARG(SvxSearchAttributeDialog, OKHdl, weld::Button &, void)
Definition: srchxtra.cxx:171
static VclPtr< SfxTabPage > Create(TabPageParent pParent, const SfxItemSet *rSet)
Definition: paragrph.cxx:2228
std::unique_ptr< weld::TreeView > m_xAttrLB
Definition: srchxtra.hxx:52
virtual void PageCreated(const SfxAllItemSet &aSet)
virtual ~SvxSearchAttributeDialog() override
Definition: srchxtra.cxx:167
SfxPoolItem * pItem
void RemoveTabPage(const OString &rName)
sal_Int16 nId
static VclPtr< SfxTabPage > Create(TabPageParent pParent, const SfxItemSet *rSet)
Definition: chardlg.cxx:1699
sal_uInt16 FirstWhich()
static OUString GetString(sal_uInt32 i)
static VclPtr< SfxTabPage > Create(TabPageParent pParent, const SfxItemSet *rSet)
Definition: chardlg.cxx:2690
SfxItemSet * GetInputSetImpl()
static SfxObjectShell * Current()
SvxSearchSimilarityDialog(weld::Window *pParent, bool bRelax, sal_uInt16 nOther, sal_uInt16 nShorter, sal_uInt16 nLonger)
Definition: srchxtra.cxx:217
TRISTATE_TRUE
#define RESARRAY_INDEX_NOTFOUND
sal_uInt16 NextWhich()
static OutputDevice * GetDefaultDevice()
static VclPtr< SfxTabPage > Create(TabPageParent, const SfxItemSet *)
Definition: backgrnd.cxx:1549
static VclPtr< SfxTabPage > Create(TabPageParent pParent, const SfxItemSet *rSet)
Definition: paragrph.cxx:1066
SfxItemPool & GetPool() const
sal_uInt16 nSlot
const SfxPoolItem * GetItem(sal_uInt16 nSlotId) const
#define DBG_ASSERT(sCon, aError)
bool IsDoubleLinesEnabled() const
int i
TRISTATE_FALSE
std::unique_ptr< weld::Button > m_xOKBtn
Definition: srchxtra.hxx:53
sal_uInt16 Count() const
SvxSearchAttributeDialog(weld::Window *pParent, SearchAttrItemList &rLst, const sal_uInt16 *pWhRanges)
Definition: srchxtra.cxx:107
virtual ~SvxSearchSimilarityDialog() override
Definition: srchxtra.cxx:231
virtual ~SvxSearchFormatDialog() override
Definition: srchxtra.cxx:59
sal_uInt16 GetSlotId(sal_uInt16 nWhich) const
SearchAttrItemList & rList
Definition: srchxtra.hxx:50
static VclPtr< SfxTabPage > Create(TabPageParent pParent, const SfxItemSet *rSet)
Definition: paragrph.cxx:1363
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
bool IsAsianTypographyEnabled() const
std::unique_ptr< weld::SpinButton > m_xLongerFld
Definition: srchxtra.hxx:64
static sal_uInt32 FindIndex(int nValue)
static VclPtr< SfxTabPage > Create(TabPageParent pParent, const SfxItemSet *rSet)
Definition: chardlg.cxx:1214
std::unique_ptr< FontList > m_pFontList
Definition: srchxtra.hxx:37
SvxSearchFormatDialog(weld::Window *pParent, const SfxItemSet &rSet)
Definition: srchxtra.cxx:38
RET_OK
void AddTabPage(const OString &rName, CreateTabPage pCreateFunc, GetTabPageRanges pRangesFunc)
static VclPtr< SfxTabPage > Create(TabPageParent pParent, const SfxItemSet *rSet)
Definition: chardlg.cxx:3209
std::unique_ptr< weld::SpinButton > m_xOtherFld
Definition: srchxtra.hxx:63
std::unique_ptr< weld::SpinButton > m_xShorterFld
Definition: srchxtra.hxx:65
#define SAL_WARN(area, stream)
static VclPtr< SfxTabPage > Create(TabPageParent pParent, const SfxItemSet *rSet)
Definition: paragrph.cxx:212
#define INVALID_POOL_ITEM
const FontList * GetFontList() const
virtual void PageCreated(const OString &rId, SfxTabPage &rPage) override
Definition: srchxtra.cxx:63
bool IsInvalidItem(const SfxPoolItem *pItem)
std::unique_ptr< weld::CheckButton > m_xRelaxBox
Definition: srchxtra.hxx:66