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  m_xAttrLB->enable_toggle_buttons(weld::ColumnToggleType::Check);
118 
119  m_xOKBtn->connect_clicked(LINK( this, SvxSearchAttributeDialog, OKHdl));
120 
122  DBG_ASSERT( pSh, "No DocShell" );
123 
124  SfxItemPool& rPool = pSh->GetPool();
125  SfxItemSet aSet( rPool, pWhRanges );
126  SfxWhichIter aIter( aSet );
127  sal_uInt16 nWhich = aIter.FirstWhich();
128 
129  while ( nWhich )
130  {
131  sal_uInt16 nSlot = rPool.GetSlotId( nWhich );
132  if ( nSlot >= SID_SVX_START )
133  {
134  bool bChecked = false, bFound = false;
135  for ( sal_uInt16 i = 0; !bFound && i < rList.Count(); ++i )
136  {
137  if ( nSlot == rList[i].nSlot )
138  {
139  bFound = true;
140  if ( IsInvalidItem( rList[i].pItem ) )
141  bChecked = true;
142  }
143  }
144 
145  // item resources are in svx
146  sal_uInt32 nId = SvxAttrNameTable::FindIndex(nSlot);
147  if (RESARRAY_INDEX_NOTFOUND != nId)
148  {
149  m_xAttrLB->append();
150  const int nRow = m_xAttrLB->n_children() - 1;
151  m_xAttrLB->set_toggle(nRow, bChecked ? TRISTATE_TRUE : TRISTATE_FALSE);
152  m_xAttrLB->set_text(nRow, SvxAttrNameTable::GetString(nId), 0);
153  m_xAttrLB->set_id(nRow, OUString::number(nSlot));
154  }
155  else
156  SAL_WARN( "cui.dialogs", "no resource for slot id " << static_cast<sal_Int32>(nSlot) );
157  }
158  nWhich = aIter.NextWhich();
159  }
160 
161  m_xAttrLB->make_sorted();
162  m_xAttrLB->select(0);
163 }
164 
166 {
167 }
168 
170 {
171  SearchAttrItem aInvalidItem;
172  aInvalidItem.pItem = INVALID_POOL_ITEM;
173 
174  for (int i = 0, nCount = m_xAttrLB->n_children(); i < nCount; ++i)
175  {
176  sal_uInt16 nSlot = m_xAttrLB->get_id(i).toUInt32();
177  bool bChecked = m_xAttrLB->get_toggle(i) == TRISTATE_TRUE;
178 
179  sal_uInt16 j;
180  for ( j = rList.Count(); j; )
181  {
182  SearchAttrItem& rItem = rList[ --j ];
183  if( rItem.nSlot == nSlot )
184  {
185  if( bChecked )
186  {
187  if( !IsInvalidItem( rItem.pItem ) )
188  delete rItem.pItem;
189  rItem.pItem = INVALID_POOL_ITEM;
190  }
191  else if( IsInvalidItem( rItem.pItem ) )
192  rItem.pItem = nullptr;
193  j = 1;
194  break;
195  }
196  }
197 
198  if ( !j && bChecked )
199  {
200  aInvalidItem.nSlot = nSlot;
201  rList.Insert( aInvalidItem );
202  }
203  }
204 
205  // remove invalid items (pItem == NULL)
206  for ( sal_uInt16 n = rList.Count(); n; )
207  if ( !rList[ --n ].pItem )
208  rList.Remove( n );
209 
210  m_xDialog->response(RET_OK);
211 }
212 
213 // class SvxSearchSimilarityDialog ---------------------------------------
214 
216  sal_uInt16 nOther, sal_uInt16 nShorter, sal_uInt16 nLonger)
217  : GenericDialogController(pParent, "cui/ui/similaritysearchdialog.ui", "SimilaritySearchDialog")
218  , m_xOtherFld(m_xBuilder->weld_spin_button("otherfld"))
219  , m_xLongerFld(m_xBuilder->weld_spin_button("longerfld"))
220  , m_xShorterFld(m_xBuilder->weld_spin_button("shorterfld"))
221  , m_xRelaxBox(m_xBuilder->weld_check_button("relaxbox"))
222 {
223  m_xOtherFld->set_value(nOther);
224  m_xShorterFld->set_value(nShorter);
225  m_xLongerFld->set_value(nLonger);
226  m_xRelaxBox->set_active(bRelax);
227 }
228 
230 {
231 }
232 
233 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
IMPL_LINK_NOARG(SvxSearchAttributeDialog, OKHdl, weld::Button &, void)
Definition: srchxtra.cxx:169
std::unique_ptr< weld::TreeView > m_xAttrLB
Definition: srchxtra.hxx:51
virtual void PageCreated(const SfxAllItemSet &aSet)
virtual ~SvxSearchAttributeDialog() override
Definition: srchxtra.cxx:165
SfxPoolItem * pItem
sal_Int64 n
void RemoveTabPage(const OString &rName)
sal_Int16 nId
sal_uInt16 FirstWhich()
static OUString GetString(sal_uInt32 i)
SfxItemSet * GetInputSetImpl()
static SfxObjectShell * Current()
SvxSearchSimilarityDialog(weld::Window *pParent, bool bRelax, sal_uInt16 nOther, sal_uInt16 nShorter, sal_uInt16 nLonger)
Definition: srchxtra.cxx:215
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
Definition: paragrph.cxx:212
TRISTATE_TRUE
#define RESARRAY_INDEX_NOTFOUND
sal_uInt16 NextWhich()
static OutputDevice * GetDefaultDevice()
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
Definition: paragrph.cxx:1063
int nCount
SfxItemPool & GetPool() const
sal_uInt16 nSlot
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
Definition: chardlg.cxx:1190
const SfxPoolItem * GetItem(sal_uInt16 nSlotId) const
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
Definition: paragrph.cxx:2233
#define DBG_ASSERT(sCon, aError)
int i
bool IsDoubleLinesEnabled() const
TRISTATE_FALSE
std::unique_ptr< weld::Button > m_xOKBtn
Definition: srchxtra.hxx:52
sal_uInt16 Count() const
SvxSearchAttributeDialog(weld::Window *pParent, SearchAttrItemList &rLst, const sal_uInt16 *pWhRanges)
Definition: srchxtra.cxx:107
virtual ~SvxSearchSimilarityDialog() override
Definition: srchxtra.cxx:229
virtual ~SvxSearchFormatDialog() override
Definition: srchxtra.cxx:59
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *)
Definition: backgrnd.cxx:232
sal_uInt16 GetSlotId(sal_uInt16 nWhich) const
SearchAttrItemList & rList
Definition: srchxtra.hxx:49
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
bool IsAsianTypographyEnabled() const
std::unique_ptr< weld::SpinButton > m_xLongerFld
Definition: srchxtra.hxx:63
static sal_uInt32 FindIndex(int nValue)
std::unique_ptr< FontList > m_pFontList
Definition: srchxtra.hxx:36
SvxSearchFormatDialog(weld::Window *pParent, const SfxItemSet &rSet)
Definition: srchxtra.cxx:38
RET_OK
void AddTabPage(const OString &rName, CreateTabPage pCreateFunc, GetTabPageRanges pRangesFunc)
Reference< XExecutableDialog > m_xDialog
std::unique_ptr< weld::SpinButton > m_xOtherFld
Definition: srchxtra.hxx:62
std::unique_ptr< weld::SpinButton > m_xShorterFld
Definition: srchxtra.hxx:64
#define SAL_WARN(area, stream)
#define INVALID_POOL_ITEM
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
Definition: chardlg.cxx:1664
const FontList * GetFontList() const
virtual void PageCreated(const OString &rId, SfxTabPage &rPage) override
Definition: srchxtra.cxx:63
bool IsInvalidItem(const SfxPoolItem *pItem)
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
Definition: paragrph.cxx:1360
std::unique_ptr< weld::CheckButton > m_xRelaxBox
Definition: srchxtra.hxx:65
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
Definition: chardlg.cxx:2628
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
Definition: chardlg.cxx:3146