1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_cui.hxx" 30 31 // include --------------------------------------------------------------- 32 33 #include "srchxtra.hxx" 34 #include <tools/rcid.h> 35 #include <vcl/msgbox.hxx> 36 #include <svl/cjkoptions.hxx> 37 #include <svl/whiter.hxx> 38 #include <sfx2/objsh.hxx> 39 #include <cuires.hrc> 40 #include "srchxtra.hrc" 41 #include <svx/svxitems.hrc> // RID_ATTR_BEGIN 42 #include <svx/dialmgr.hxx> // item resources 43 #include <editeng/flstitem.hxx> 44 #include "chardlg.hxx" 45 #include "paragrph.hxx" 46 #include <dialmgr.hxx> 47 #include "backgrnd.hxx" 48 #include <svx/dialogs.hrc> // RID_SVXPAGE_... 49 #include <tools/resary.hxx> 50 51 // class SvxSearchFormatDialog ------------------------------------------- 52 53 SvxSearchFormatDialog::SvxSearchFormatDialog( Window* pParent, const SfxItemSet& rSet ) : 54 55 SfxTabDialog( pParent, CUI_RES( RID_SVXDLG_SEARCHFORMAT ), &rSet ), 56 57 pFontList( NULL ) 58 59 { 60 FreeResource(); 61 62 AddTabPage( RID_SVXPAGE_CHAR_NAME, SvxCharNamePage::Create, 0 ); 63 AddTabPage( RID_SVXPAGE_CHAR_EFFECTS, SvxCharEffectsPage::Create, 0 ); 64 AddTabPage( RID_SVXPAGE_CHAR_POSITION, SvxCharPositionPage::Create, 0 ); 65 AddTabPage( RID_SVXPAGE_CHAR_TWOLINES, SvxCharTwoLinesPage::Create, 0 ); 66 AddTabPage( RID_SVXPAGE_STD_PARAGRAPH, SvxStdParagraphTabPage::Create, 0 ); 67 AddTabPage( RID_SVXPAGE_ALIGN_PARAGRAPH, SvxParaAlignTabPage::Create, 0 ); 68 AddTabPage( RID_SVXPAGE_EXT_PARAGRAPH, SvxExtParagraphTabPage::Create, 0 ); 69 AddTabPage( RID_SVXPAGE_PARA_ASIAN, SvxAsianTabPage::Create, 0 ); 70 AddTabPage( RID_SVXPAGE_BACKGROUND, SvxBackgroundTabPage::Create, 0 ); 71 72 // remove asian tabpages if necessary 73 SvtCJKOptions aCJKOptions; 74 if ( !aCJKOptions.IsDoubleLinesEnabled() ) 75 RemoveTabPage( RID_SVXPAGE_CHAR_TWOLINES ); 76 if ( !aCJKOptions.IsAsianTypographyEnabled() ) 77 RemoveTabPage( RID_SVXPAGE_PARA_ASIAN ); 78 } 79 80 // ----------------------------------------------------------------------- 81 82 SvxSearchFormatDialog::~SvxSearchFormatDialog() 83 { 84 delete pFontList; 85 } 86 87 // ----------------------------------------------------------------------- 88 89 void SvxSearchFormatDialog::PageCreated( sal_uInt16 nId, SfxTabPage& rPage ) 90 { 91 switch ( nId ) 92 { 93 case RID_SVXPAGE_CHAR_NAME: 94 { 95 const FontList* pAppFontList = 0; 96 SfxObjectShell* pSh = SfxObjectShell::Current(); 97 98 if ( pSh ) 99 { 100 const SvxFontListItem* pFLItem = (const SvxFontListItem*) 101 pSh->GetItem( SID_ATTR_CHAR_FONTLIST ); 102 if ( pFLItem ) 103 pAppFontList = pFLItem->GetFontList(); 104 } 105 106 const FontList* pList = pAppFontList; 107 108 if ( !pList ) 109 { 110 if ( !pFontList ) 111 pFontList = new FontList( this ); 112 pList = pFontList; 113 } 114 115 if ( pList ) 116 ( (SvxCharNamePage&)rPage ). 117 SetFontList( SvxFontListItem( pList, SID_ATTR_CHAR_FONTLIST ) ); 118 ( (SvxCharNamePage&)rPage ).EnableSearchMode(); 119 break; 120 } 121 122 case RID_SVXPAGE_STD_PARAGRAPH: 123 ( (SvxStdParagraphTabPage&)rPage ).EnableAutoFirstLine(); 124 break; 125 126 case RID_SVXPAGE_ALIGN_PARAGRAPH: 127 ( (SvxParaAlignTabPage&)rPage ).EnableJustifyExt(); 128 break; 129 case RID_SVXPAGE_BACKGROUND : 130 ( (SvxBackgroundTabPage&)rPage ).ShowParaControl(sal_True); 131 break; 132 } 133 } 134 135 // class SvxSearchFormatDialog ------------------------------------------- 136 137 SvxSearchAttributeDialog::SvxSearchAttributeDialog( Window* pParent, 138 SearchAttrItemList& rLst, 139 const sal_uInt16* pWhRanges ) : 140 141 ModalDialog( pParent, CUI_RES( RID_SVXDLG_SEARCHATTR ) ), 142 143 aAttrFL ( this, CUI_RES( FL_ATTR ) ), 144 aAttrLB ( this, CUI_RES( LB_ATTR ) ), 145 aOKBtn ( this, CUI_RES( BTN_ATTR_OK ) ), 146 aEscBtn ( this, CUI_RES( BTN_ATTR_CANCEL ) ), 147 aHelpBtn( this, CUI_RES( BTN_ATTR_HELP ) ), 148 149 rList( rLst ) 150 151 { 152 FreeResource(); 153 154 aAttrLB.SetStyle( GetStyle() | WB_CLIPCHILDREN | WB_HSCROLL | WB_SORT ); 155 aAttrLB.GetModel()->SetSortMode( SortAscending ); 156 157 aOKBtn.SetClickHdl( LINK( this, SvxSearchAttributeDialog, OKHdl ) ); 158 159 SfxObjectShell* pSh = SfxObjectShell::Current(); 160 DBG_ASSERT( pSh, "No DocShell" ); 161 162 ResStringArray aAttrNames( SVX_RES( RID_ATTR_NAMES ) ); 163 SfxItemPool& rPool = pSh->GetPool(); 164 SfxItemSet aSet( rPool, pWhRanges ); 165 SfxWhichIter aIter( aSet ); 166 sal_uInt16 nWhich = aIter.FirstWhich(); 167 168 while ( nWhich ) 169 { 170 sal_uInt16 nSlot = rPool.GetSlotId( nWhich ); 171 if ( nSlot >= SID_SVX_START ) 172 { 173 sal_Bool bChecked = sal_False, bFound = sal_False; 174 for ( sal_uInt16 i = 0; !bFound && i < rList.Count(); ++i ) 175 { 176 if ( nSlot == rList[i].nSlot ) 177 { 178 bFound = sal_True; 179 if ( IsInvalidItem( rList[i].pItem ) ) 180 bChecked = sal_True; 181 } 182 } 183 184 // item resources are in svx 185 sal_uInt32 nId = aAttrNames.FindIndex( nSlot ); 186 SvLBoxEntry* pEntry = NULL; 187 if ( RESARRAY_INDEX_NOTFOUND != nId ) 188 pEntry = aAttrLB.SvTreeListBox::InsertEntry( aAttrNames.GetString(nId) ); 189 else 190 { 191 ByteString sError( "no resource for slot id\nslot = " ); 192 sError += ByteString::CreateFromInt32( nSlot ); 193 DBG_ERRORFILE( sError.GetBuffer() ); 194 } 195 196 if ( pEntry ) 197 { 198 aAttrLB.SetCheckButtonState( pEntry, bChecked ? SV_BUTTON_CHECKED : SV_BUTTON_UNCHECKED ); 199 pEntry->SetUserData( (void*)(sal_uLong)nSlot ); 200 } 201 } 202 nWhich = aIter.NextWhich(); 203 } 204 205 aAttrLB.SetHighlightRange(); 206 aAttrLB.SelectEntryPos( 0 ); 207 } 208 209 // ----------------------------------------------------------------------- 210 211 IMPL_LINK( SvxSearchAttributeDialog, OKHdl, Button *, EMPTYARG ) 212 { 213 SearchAttrItem aInvalidItem; 214 aInvalidItem.pItem = (SfxPoolItem*)-1; 215 216 for ( sal_uInt16 i = 0; i < aAttrLB.GetEntryCount(); ++i ) 217 { 218 sal_uInt16 nSlot = (sal_uInt16)(sal_uLong)aAttrLB.GetEntryData(i); 219 sal_Bool bChecked = aAttrLB.IsChecked(i); 220 221 sal_uInt16 j; 222 for ( j = rList.Count(); j; ) 223 { 224 SearchAttrItem& rItem = rList[ --j ]; 225 if( rItem.nSlot == nSlot ) 226 { 227 if( bChecked ) 228 { 229 if( !IsInvalidItem( rItem.pItem ) ) 230 delete rItem.pItem; 231 rItem.pItem = (SfxPoolItem*)-1; 232 } 233 else if( IsInvalidItem( rItem.pItem ) ) 234 rItem.pItem = 0; 235 j = 1; 236 break; 237 } 238 } 239 240 if ( !j && bChecked ) 241 { 242 aInvalidItem.nSlot = nSlot; 243 rList.Insert( aInvalidItem ); 244 } 245 } 246 247 // remove invalid items (pItem == NULL) 248 for ( sal_uInt16 n = rList.Count(); n; ) 249 if ( !rList[ --n ].pItem ) 250 rList.Remove( n ); 251 252 EndDialog( RET_OK ); 253 return 0; 254 } 255 256 // class SvxSearchSimilarityDialog --------------------------------------- 257 258 SvxSearchSimilarityDialog::SvxSearchSimilarityDialog 259 ( 260 Window* pParent, 261 sal_Bool bRelax, 262 sal_uInt16 nOther, 263 sal_uInt16 nShorter, 264 sal_uInt16 nLonger 265 ) : 266 ModalDialog( pParent, CUI_RES( RID_SVXDLG_SEARCHSIMILARITY ) ), 267 268 aFixedLine ( this, CUI_RES( FL_SIMILARITY ) ), 269 aOtherTxt ( this, CUI_RES( FT_OTHER ) ), 270 aOtherFld ( this, CUI_RES( NF_OTHER ) ), 271 aLongerTxt ( this, CUI_RES( FT_LONGER ) ), 272 aLongerFld ( this, CUI_RES( NF_LONGER ) ), 273 aShorterTxt ( this, CUI_RES( FT_SHORTER ) ), 274 aShorterFld ( this, CUI_RES( NF_SHORTER ) ), 275 aRelaxBox ( this, CUI_RES( CB_RELAX ) ), 276 277 aOKBtn ( this, CUI_RES( BTN_ATTR_OK ) ), 278 aEscBtn ( this, CUI_RES( BTN_ATTR_CANCEL ) ), 279 aHelpBtn ( this, CUI_RES( BTN_ATTR_HELP ) ) 280 281 { 282 FreeResource(); 283 284 aOtherFld.SetValue( nOther ); 285 aShorterFld.SetValue( nShorter ); 286 aLongerFld.SetValue( nLonger ); 287 aRelaxBox.Check( bRelax ); 288 } 289 290