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 "srchxtra.hxx"
21 : #include <tools/rcid.h>
22 : #include <vcl/msgbox.hxx>
23 : #include <svl/cjkoptions.hxx>
24 : #include <svl/whiter.hxx>
25 : #include <sfx2/objsh.hxx>
26 : #include <cuires.hrc>
27 : #include "srchxtra.hrc"
28 : #include <svx/svxitems.hrc> // RID_ATTR_BEGIN
29 : #include <svx/dialmgr.hxx> // item resources
30 : #include <editeng/flstitem.hxx>
31 : #include "chardlg.hxx"
32 : #include "paragrph.hxx"
33 : #include <dialmgr.hxx>
34 : #include "backgrnd.hxx"
35 : #include <svx/dialogs.hrc> // RID_SVXPAGE_...
36 : #include <tools/resary.hxx>
37 : #include <rtl/strbuf.hxx>
38 : #include "svtools/treelistentry.hxx"
39 :
40 : // class SvxSearchFormatDialog -------------------------------------------
41 :
42 0 : SvxSearchFormatDialog::SvxSearchFormatDialog( Window* pParent, const SfxItemSet& rSet ) :
43 :
44 0 : SfxTabDialog( pParent, CUI_RES( RID_SVXDLG_SEARCHFORMAT ), &rSet ),
45 :
46 0 : pFontList( NULL )
47 :
48 : {
49 0 : FreeResource();
50 :
51 0 : AddTabPage( RID_SVXPAGE_CHAR_NAME, SvxCharNamePage::Create, 0 );
52 0 : AddTabPage( RID_SVXPAGE_CHAR_EFFECTS, SvxCharEffectsPage::Create, 0 );
53 0 : AddTabPage( RID_SVXPAGE_CHAR_POSITION, SvxCharPositionPage::Create, 0 );
54 0 : AddTabPage( RID_SVXPAGE_CHAR_TWOLINES, SvxCharTwoLinesPage::Create, 0 );
55 0 : AddTabPage( RID_SVXPAGE_STD_PARAGRAPH, SvxStdParagraphTabPage::Create, 0 );
56 0 : AddTabPage( RID_SVXPAGE_ALIGN_PARAGRAPH, SvxParaAlignTabPage::Create, 0 );
57 0 : AddTabPage( RID_SVXPAGE_EXT_PARAGRAPH, SvxExtParagraphTabPage::Create, 0 );
58 0 : AddTabPage( RID_SVXPAGE_PARA_ASIAN, SvxAsianTabPage::Create, 0 );
59 0 : AddTabPage( RID_SVXPAGE_BACKGROUND, SvxBackgroundTabPage::Create, 0 );
60 :
61 : // remove asian tabpages if necessary
62 0 : SvtCJKOptions aCJKOptions;
63 0 : if ( !aCJKOptions.IsDoubleLinesEnabled() )
64 0 : RemoveTabPage( RID_SVXPAGE_CHAR_TWOLINES );
65 0 : if ( !aCJKOptions.IsAsianTypographyEnabled() )
66 0 : RemoveTabPage( RID_SVXPAGE_PARA_ASIAN );
67 0 : }
68 :
69 : // -----------------------------------------------------------------------
70 :
71 0 : SvxSearchFormatDialog::~SvxSearchFormatDialog()
72 : {
73 0 : delete pFontList;
74 0 : }
75 :
76 : // -----------------------------------------------------------------------
77 :
78 0 : void SvxSearchFormatDialog::PageCreated( sal_uInt16 nId, SfxTabPage& rPage )
79 : {
80 0 : switch ( nId )
81 : {
82 : case RID_SVXPAGE_CHAR_NAME:
83 : {
84 0 : const FontList* pAppFontList = 0;
85 0 : SfxObjectShell* pSh = SfxObjectShell::Current();
86 :
87 0 : if ( pSh )
88 : {
89 : const SvxFontListItem* pFLItem = (const SvxFontListItem*)
90 0 : pSh->GetItem( SID_ATTR_CHAR_FONTLIST );
91 0 : if ( pFLItem )
92 0 : pAppFontList = pFLItem->GetFontList();
93 : }
94 :
95 0 : const FontList* pList = pAppFontList;
96 :
97 0 : if ( !pList )
98 : {
99 0 : if ( !pFontList )
100 0 : pFontList = new FontList( this );
101 0 : pList = pFontList;
102 : }
103 :
104 0 : if ( pList )
105 : ( (SvxCharNamePage&)rPage ).
106 0 : SetFontList( SvxFontListItem( pList, SID_ATTR_CHAR_FONTLIST ) );
107 0 : ( (SvxCharNamePage&)rPage ).EnableSearchMode();
108 0 : break;
109 : }
110 :
111 : case RID_SVXPAGE_STD_PARAGRAPH:
112 0 : ( (SvxStdParagraphTabPage&)rPage ).EnableAutoFirstLine();
113 0 : break;
114 :
115 : case RID_SVXPAGE_ALIGN_PARAGRAPH:
116 0 : ( (SvxParaAlignTabPage&)rPage ).EnableJustifyExt();
117 0 : break;
118 : case RID_SVXPAGE_BACKGROUND :
119 0 : ( (SvxBackgroundTabPage&)rPage ).ShowParaControl(sal_True);
120 0 : break;
121 : }
122 0 : }
123 :
124 : // class SvxSearchFormatDialog -------------------------------------------
125 :
126 0 : SvxSearchAttributeDialog::SvxSearchAttributeDialog( Window* pParent,
127 : SearchAttrItemList& rLst,
128 : const sal_uInt16* pWhRanges ) :
129 :
130 0 : ModalDialog( pParent, CUI_RES( RID_SVXDLG_SEARCHATTR ) ),
131 :
132 0 : aAttrFL ( this, CUI_RES( FL_ATTR ) ),
133 0 : aAttrLB ( this, CUI_RES( LB_ATTR ) ),
134 0 : aOKBtn ( this, CUI_RES( BTN_ATTR_OK ) ),
135 0 : aEscBtn ( this, CUI_RES( BTN_ATTR_CANCEL ) ),
136 0 : aHelpBtn( this, CUI_RES( BTN_ATTR_HELP ) ),
137 :
138 0 : rList( rLst )
139 :
140 : {
141 0 : FreeResource();
142 :
143 0 : aAttrLB.SetStyle( GetStyle() | WB_CLIPCHILDREN | WB_HSCROLL | WB_SORT );
144 0 : aAttrLB.GetModel()->SetSortMode( SortAscending );
145 :
146 0 : aOKBtn.SetClickHdl( LINK( this, SvxSearchAttributeDialog, OKHdl ) );
147 :
148 0 : SfxObjectShell* pSh = SfxObjectShell::Current();
149 : DBG_ASSERT( pSh, "No DocShell" );
150 :
151 0 : ResStringArray aAttrNames( SVX_RES( RID_ATTR_NAMES ) );
152 0 : SfxItemPool& rPool = pSh->GetPool();
153 0 : SfxItemSet aSet( rPool, pWhRanges );
154 0 : SfxWhichIter aIter( aSet );
155 0 : sal_uInt16 nWhich = aIter.FirstWhich();
156 :
157 0 : while ( nWhich )
158 : {
159 0 : sal_uInt16 nSlot = rPool.GetSlotId( nWhich );
160 0 : if ( nSlot >= SID_SVX_START )
161 : {
162 0 : sal_Bool bChecked = sal_False, bFound = sal_False;
163 0 : for ( sal_uInt16 i = 0; !bFound && i < rList.Count(); ++i )
164 : {
165 0 : if ( nSlot == rList[i].nSlot )
166 : {
167 0 : bFound = sal_True;
168 0 : if ( IsInvalidItem( rList[i].pItem ) )
169 0 : bChecked = sal_True;
170 : }
171 : }
172 :
173 : // item resources are in svx
174 0 : sal_uInt32 nId = aAttrNames.FindIndex( nSlot );
175 0 : SvTreeListEntry* pEntry = NULL;
176 0 : if ( RESARRAY_INDEX_NOTFOUND != nId )
177 0 : pEntry = aAttrLB.SvTreeListBox::InsertEntry( aAttrNames.GetString(nId) );
178 : else
179 : SAL_WARN( "cui.dialogs", "no resource for slot id " << static_cast<sal_Int32>(nSlot) );
180 :
181 0 : if ( pEntry )
182 : {
183 0 : aAttrLB.SetCheckButtonState( pEntry, bChecked ? SV_BUTTON_CHECKED : SV_BUTTON_UNCHECKED );
184 0 : pEntry->SetUserData( (void*)(sal_uLong)nSlot );
185 : }
186 : }
187 0 : nWhich = aIter.NextWhich();
188 : }
189 :
190 0 : aAttrLB.SetHighlightRange();
191 0 : aAttrLB.SelectEntryPos( 0 );
192 0 : }
193 :
194 : // -----------------------------------------------------------------------
195 :
196 0 : IMPL_LINK_NOARG(SvxSearchAttributeDialog, OKHdl)
197 : {
198 : SearchAttrItem aInvalidItem;
199 0 : aInvalidItem.pItem = (SfxPoolItem*)-1;
200 :
201 0 : for ( sal_uInt16 i = 0; i < aAttrLB.GetEntryCount(); ++i )
202 : {
203 0 : sal_uInt16 nSlot = (sal_uInt16)(sal_uLong)aAttrLB.GetEntryData(i);
204 0 : sal_Bool bChecked = aAttrLB.IsChecked(i);
205 :
206 : sal_uInt16 j;
207 0 : for ( j = rList.Count(); j; )
208 : {
209 0 : SearchAttrItem& rItem = rList[ --j ];
210 0 : if( rItem.nSlot == nSlot )
211 : {
212 0 : if( bChecked )
213 : {
214 0 : if( !IsInvalidItem( rItem.pItem ) )
215 0 : delete rItem.pItem;
216 0 : rItem.pItem = (SfxPoolItem*)-1;
217 : }
218 0 : else if( IsInvalidItem( rItem.pItem ) )
219 0 : rItem.pItem = 0;
220 0 : j = 1;
221 0 : break;
222 : }
223 : }
224 :
225 0 : if ( !j && bChecked )
226 : {
227 0 : aInvalidItem.nSlot = nSlot;
228 0 : rList.Insert( aInvalidItem );
229 : }
230 : }
231 :
232 : // remove invalid items (pItem == NULL)
233 0 : for ( sal_uInt16 n = rList.Count(); n; )
234 0 : if ( !rList[ --n ].pItem )
235 0 : rList.Remove( n );
236 :
237 0 : EndDialog( RET_OK );
238 0 : return 0;
239 : }
240 :
241 : // class SvxSearchSimilarityDialog ---------------------------------------
242 :
243 0 : SvxSearchSimilarityDialog::SvxSearchSimilarityDialog
244 : (
245 : Window* pParent,
246 : sal_Bool bRelax,
247 : sal_uInt16 nOther,
248 : sal_uInt16 nShorter,
249 : sal_uInt16 nLonger
250 : ) :
251 0 : ModalDialog( pParent, CUI_RES( RID_SVXDLG_SEARCHSIMILARITY ) ),
252 :
253 0 : aFixedLine ( this, CUI_RES( FL_SIMILARITY ) ),
254 0 : aOtherTxt ( this, CUI_RES( FT_OTHER ) ),
255 0 : aOtherFld ( this, CUI_RES( NF_OTHER ) ),
256 0 : aLongerTxt ( this, CUI_RES( FT_LONGER ) ),
257 0 : aLongerFld ( this, CUI_RES( NF_LONGER ) ),
258 0 : aShorterTxt ( this, CUI_RES( FT_SHORTER ) ),
259 0 : aShorterFld ( this, CUI_RES( NF_SHORTER ) ),
260 0 : aRelaxBox ( this, CUI_RES( CB_RELAX ) ),
261 :
262 0 : aOKBtn ( this, CUI_RES( BTN_ATTR_OK ) ),
263 0 : aEscBtn ( this, CUI_RES( BTN_ATTR_CANCEL ) ),
264 0 : aHelpBtn ( this, CUI_RES( BTN_ATTR_HELP ) )
265 :
266 : {
267 0 : FreeResource();
268 :
269 0 : aOtherFld.SetValue( nOther );
270 0 : aShorterFld.SetValue( nShorter );
271 0 : aLongerFld.SetValue( nLonger );
272 0 : aRelaxBox.Check( bRelax );
273 3 : }
274 :
275 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|