1efeef26fSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3efeef26fSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4efeef26fSAndrew Rist * or more contributor license agreements. See the NOTICE file 5efeef26fSAndrew Rist * distributed with this work for additional information 6efeef26fSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7efeef26fSAndrew Rist * to you under the Apache License, Version 2.0 (the 8efeef26fSAndrew Rist * "License"); you may not use this file except in compliance 9efeef26fSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11efeef26fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13efeef26fSAndrew Rist * Unless required by applicable law or agreed to in writing, 14efeef26fSAndrew Rist * software distributed under the License is distributed on an 15efeef26fSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16efeef26fSAndrew Rist * KIND, either express or implied. See the License for the 17efeef26fSAndrew Rist * specific language governing permissions and limitations 18efeef26fSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20efeef26fSAndrew Rist *************************************************************/ 21efeef26fSAndrew Rist 22efeef26fSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_sw.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #ifdef SW_DLLIMPLEMENTATION 28cdf0e10cSrcweir #undef SW_DLLIMPLEMENTATION 29cdf0e10cSrcweir #endif 30cdf0e10cSrcweir 31cdf0e10cSrcweir 32cdf0e10cSrcweir 33cdf0e10cSrcweir #include "cmdid.h" 34cdf0e10cSrcweir #include <tools/list.hxx> 35cdf0e10cSrcweir #include "swmodule.hxx" 36cdf0e10cSrcweir #include "view.hxx" 37cdf0e10cSrcweir #include "wrtsh.hxx" 38cdf0e10cSrcweir #include "globals.hrc" 39cdf0e10cSrcweir #include "helpid.h" 40cdf0e10cSrcweir 41cdf0e10cSrcweir 42cdf0e10cSrcweir #include <sfx2/styfitem.hxx> 43cdf0e10cSrcweir 44cdf0e10cSrcweir #include "uitool.hxx" 45cdf0e10cSrcweir #include "ccoll.hxx" 46cdf0e10cSrcweir #include "fmtcol.hxx" 47cdf0e10cSrcweir #include "hintids.hxx" 48cdf0e10cSrcweir #include "docsh.hxx" 49cdf0e10cSrcweir #include "docstyle.hxx" 50cdf0e10cSrcweir #include "hints.hxx" 51cdf0e10cSrcweir 52cdf0e10cSrcweir #include "chrdlg.hrc" 53cdf0e10cSrcweir #include "ccoll.hrc" 54cdf0e10cSrcweir #include <vcl/svapp.hxx> 55cdf0e10cSrcweir 56cdf0e10cSrcweir #include "swuiccoll.hxx" 57cdf0e10cSrcweir 58cdf0e10cSrcweir static sal_uInt16 __FAR_DATA aPageRg[] = { 59cdf0e10cSrcweir FN_COND_COLL, FN_COND_COLL, 60cdf0e10cSrcweir 0 61cdf0e10cSrcweir }; 62cdf0e10cSrcweir 63cdf0e10cSrcweir // Achtung im Code wird dieses Array direkt (0, 1, ...) indiziert 64cdf0e10cSrcweir static long nTabs[] = 65cdf0e10cSrcweir { 2, // Number of Tabs 66cdf0e10cSrcweir 0, 100 67cdf0e10cSrcweir }; 68cdf0e10cSrcweir 69cdf0e10cSrcweir /**************************************************************************** 70cdf0e10cSrcweir Page: Ctor 71cdf0e10cSrcweir ****************************************************************************/ 72cdf0e10cSrcweir 73cdf0e10cSrcweir 74cdf0e10cSrcweir SwCondCollPage::SwCondCollPage(Window *pParent, const SfxItemSet &rSet) 75cdf0e10cSrcweir 76cdf0e10cSrcweir : SfxTabPage(pParent, SW_RES(TP_CONDCOLL), rSet), 77cdf0e10cSrcweir aConditionFL( this, SW_RES( FL_CONDITION )), 78cdf0e10cSrcweir aConditionCB( this, SW_RES( CB_CONDITION ) ), 79cdf0e10cSrcweir aContextFT ( this, SW_RES( FT_CONTEXT ) ), 80cdf0e10cSrcweir aUsedFT ( this, SW_RES( FT_USED ) ), 81cdf0e10cSrcweir aTbLinks( this, SW_RES( TB_CONDCOLLS ) ), 82cdf0e10cSrcweir aStyleFT ( this, SW_RES( FT_STYLE ) ), 83cdf0e10cSrcweir aStyleLB ( this, SW_RES( LB_STYLE ) ), 84cdf0e10cSrcweir aFilterLB ( this, SW_RES( LB_FILTER ) ), 85cdf0e10cSrcweir aRemovePB ( this, SW_RES( PB_REMOVE ) ), 86cdf0e10cSrcweir aAssignPB ( this, SW_RES( PB_ASSIGN ) ), 87cdf0e10cSrcweir sNoTmpl ( SW_RES( STR_NOTEMPL ) ), 88cdf0e10cSrcweir aStrArr ( SW_RES( STR_REGIONS ) ), 89cdf0e10cSrcweir rSh(::GetActiveView()->GetWrtShell()), 90cdf0e10cSrcweir pCmds( SwCondCollItem::GetCmds() ), 91cdf0e10cSrcweir pFmt(0), 92cdf0e10cSrcweir 93cdf0e10cSrcweir bNewTemplate(sal_False) 94cdf0e10cSrcweir { 95cdf0e10cSrcweir FreeResource(); 96cdf0e10cSrcweir SetExchangeSupport(); 97cdf0e10cSrcweir 98cdf0e10cSrcweir aRemovePB.SetAccessibleRelationMemberOf(&aConditionFL); 99cdf0e10cSrcweir aAssignPB.SetAccessibleRelationMemberOf(&aConditionFL); 100cdf0e10cSrcweir aTbLinks.SetAccessibleRelationLabeledBy(&aConditionCB); 101cdf0e10cSrcweir 102cdf0e10cSrcweir // Handler installieren 103cdf0e10cSrcweir aConditionCB.SetClickHdl( LINK(this, SwCondCollPage, OnOffHdl)); 104cdf0e10cSrcweir aTbLinks.SetDoubleClickHdl( LINK(this, SwCondCollPage, AssignRemoveHdl )); 105cdf0e10cSrcweir aStyleLB.SetDoubleClickHdl( LINK(this, SwCondCollPage, AssignRemoveHdl )); 106cdf0e10cSrcweir aRemovePB.SetClickHdl( LINK(this, SwCondCollPage, AssignRemoveHdl )); 107cdf0e10cSrcweir aAssignPB.SetClickHdl( LINK(this, SwCondCollPage, AssignRemoveHdl )); 108cdf0e10cSrcweir aTbLinks.SetSelectHdl( LINK(this, SwCondCollPage, SelectHdl)); 109cdf0e10cSrcweir aStyleLB.SetSelectHdl( LINK(this, SwCondCollPage, SelectHdl)); 110cdf0e10cSrcweir aFilterLB.SetSelectHdl( LINK(this, SwCondCollPage, SelectHdl)); 111cdf0e10cSrcweir 112cdf0e10cSrcweir aTbLinks.SetStyle(aTbLinks.GetStyle()|WB_HSCROLL|WB_CLIPCHILDREN); 113cdf0e10cSrcweir aTbLinks.SetSelectionMode( SINGLE_SELECTION ); 114cdf0e10cSrcweir aTbLinks.SetTabs( &nTabs[0], MAP_APPFONT ); 115cdf0e10cSrcweir aTbLinks.Resize(); // OS: Hack fuer richtige Selektion 116cdf0e10cSrcweir aTbLinks.SetSpaceBetweenEntries( 0 ); 117cdf0e10cSrcweir aTbLinks.SetHelpId(HID_COND_COLL_TABLIST); 118cdf0e10cSrcweir 119cdf0e10cSrcweir SfxStyleFamilies aFamilies(SW_RES(DLG_STYLE_DESIGNER)); 120cdf0e10cSrcweir const SfxStyleFamilyItem* pFamilyItem = 0; 121cdf0e10cSrcweir sal_uInt16 nCount = aFamilies.Count(); 122cdf0e10cSrcweir sal_uInt16 i; 123cdf0e10cSrcweir 124cdf0e10cSrcweir for( i = 0; i < nCount; ++i) 125cdf0e10cSrcweir { 126cdf0e10cSrcweir if(SFX_STYLE_FAMILY_PARA == (sal_uInt16)(pFamilyItem = aFamilies.GetObject(i))->GetFamily()) 127cdf0e10cSrcweir break; 128cdf0e10cSrcweir } 129cdf0e10cSrcweir 130*ca62e2c2SSteve Yin //IAccessibility2 Impplementaton 2009----- 131*ca62e2c2SSteve Yin if( pFamilyItem ) 132*ca62e2c2SSteve Yin { 133cdf0e10cSrcweir const SfxStyleFilter& rFilterList = pFamilyItem->GetFilterList(); 134cdf0e10cSrcweir for( i = 0; i < rFilterList.Count(); ++i) 135cdf0e10cSrcweir { 136cdf0e10cSrcweir aFilterLB.InsertEntry(rFilterList.GetObject(i)->aName); 137cdf0e10cSrcweir sal_uInt16* pFilter = new sal_uInt16(rFilterList.GetObject(i)->nFlags); 138cdf0e10cSrcweir aFilterLB.SetEntryData(i, pFilter); 139cdf0e10cSrcweir } 140*ca62e2c2SSteve Yin //-----IAccessibility2 Impplementaton 2009 141*ca62e2c2SSteve Yin } 142cdf0e10cSrcweir aFilterLB.SelectEntryPos(1); 143cdf0e10cSrcweir 144cdf0e10cSrcweir aTbLinks.Show(); 145cdf0e10cSrcweir 146cdf0e10cSrcweir } 147cdf0e10cSrcweir 148cdf0e10cSrcweir /**************************************************************************** 149cdf0e10cSrcweir Page: Dtor 150cdf0e10cSrcweir ****************************************************************************/ 151cdf0e10cSrcweir 152cdf0e10cSrcweir 153cdf0e10cSrcweir __EXPORT SwCondCollPage::~SwCondCollPage() 154cdf0e10cSrcweir { 155cdf0e10cSrcweir for(sal_uInt16 i = 0; i < aFilterLB.GetEntryCount(); ++i) 156cdf0e10cSrcweir delete (sal_uInt16*)aFilterLB.GetEntryData(i); 157cdf0e10cSrcweir 158cdf0e10cSrcweir } 159cdf0e10cSrcweir 160cdf0e10cSrcweir 161cdf0e10cSrcweir int __EXPORT SwCondCollPage::DeactivatePage(SfxItemSet * _pSet) 162cdf0e10cSrcweir { 163cdf0e10cSrcweir if( _pSet ) 164cdf0e10cSrcweir FillItemSet(*_pSet); 165cdf0e10cSrcweir 166cdf0e10cSrcweir return LEAVE_PAGE; 167cdf0e10cSrcweir } 168cdf0e10cSrcweir 169cdf0e10cSrcweir /**************************************************************************** 170cdf0e10cSrcweir Page: Factory 171cdf0e10cSrcweir ****************************************************************************/ 172cdf0e10cSrcweir 173cdf0e10cSrcweir 174cdf0e10cSrcweir SfxTabPage* __EXPORT SwCondCollPage::Create(Window *pParent, const SfxItemSet &rSet) 175cdf0e10cSrcweir { 176cdf0e10cSrcweir return new SwCondCollPage(pParent, rSet); 177cdf0e10cSrcweir } 178cdf0e10cSrcweir 179cdf0e10cSrcweir /**************************************************************************** 180cdf0e10cSrcweir Page: FillItemSet-Overload 181cdf0e10cSrcweir ****************************************************************************/ 182cdf0e10cSrcweir 183cdf0e10cSrcweir 184cdf0e10cSrcweir sal_Bool __EXPORT SwCondCollPage::FillItemSet(SfxItemSet &rSet) 185cdf0e10cSrcweir { 186cdf0e10cSrcweir sal_Bool bModified = sal_True; 187cdf0e10cSrcweir SwCondCollItem aCondItem; 188cdf0e10cSrcweir for(sal_uInt16 i = 0; i < aStrArr.Count(); i++) 189cdf0e10cSrcweir { 190cdf0e10cSrcweir String sEntry = aTbLinks.GetEntryText(i, 1); 191cdf0e10cSrcweir aCondItem.SetStyle( &sEntry, i); 192cdf0e10cSrcweir } 193cdf0e10cSrcweir rSet.Put(aCondItem); 194cdf0e10cSrcweir return bModified; 195cdf0e10cSrcweir } 196cdf0e10cSrcweir 197cdf0e10cSrcweir /**************************************************************************** 198cdf0e10cSrcweir Page: Reset-Overload 199cdf0e10cSrcweir ****************************************************************************/ 200cdf0e10cSrcweir 201cdf0e10cSrcweir 202cdf0e10cSrcweir void __EXPORT SwCondCollPage::Reset(const SfxItemSet &/*rSet*/) 203cdf0e10cSrcweir { 204cdf0e10cSrcweir if(bNewTemplate) 205cdf0e10cSrcweir aConditionCB.Enable(); 206cdf0e10cSrcweir if(RES_CONDTXTFMTCOLL == pFmt->Which()) 207cdf0e10cSrcweir aConditionCB.Check(); 208cdf0e10cSrcweir OnOffHdl(&aConditionCB); 209cdf0e10cSrcweir 210cdf0e10cSrcweir aTbLinks.Clear(); 211cdf0e10cSrcweir 212cdf0e10cSrcweir SfxStyleSheetBasePool* pPool = rSh.GetView().GetDocShell()->GetStyleSheetPool(); 213cdf0e10cSrcweir pPool->SetSearchMask(SFX_STYLE_FAMILY_PARA, SFXSTYLEBIT_ALL); 214cdf0e10cSrcweir aStyleLB.Clear(); 215cdf0e10cSrcweir const SfxStyleSheetBase* pBase = pPool->First(); 216cdf0e10cSrcweir while( pBase ) 217cdf0e10cSrcweir { 218cdf0e10cSrcweir if(!pFmt || pBase->GetName() != pFmt->GetName()) 219cdf0e10cSrcweir aStyleLB.InsertEntry(pBase->GetName()); 220cdf0e10cSrcweir pBase = pPool->Next(); 221cdf0e10cSrcweir } 222cdf0e10cSrcweir aStyleLB.SelectEntryPos(0); 223cdf0e10cSrcweir 224cdf0e10cSrcweir for( sal_uInt16 n = 0; n < aStrArr.Count(); n++) 225cdf0e10cSrcweir { 226cdf0e10cSrcweir String aEntry( aStrArr.GetString(n) ); 227cdf0e10cSrcweir aEntry += '\t'; 228cdf0e10cSrcweir 229cdf0e10cSrcweir const SwCollCondition* pCond = 0; 230cdf0e10cSrcweir if( pFmt && RES_CONDTXTFMTCOLL == pFmt->Which() && 231cdf0e10cSrcweir 0 != ( pCond = ((SwConditionTxtFmtColl*)pFmt)-> 232cdf0e10cSrcweir HasCondition( SwCollCondition( 0, pCmds[n].nCnd, pCmds[n].nSubCond ) ) ) 233cdf0e10cSrcweir && pCond->GetTxtFmtColl() ) 234cdf0e10cSrcweir { 235cdf0e10cSrcweir aEntry += pCond->GetTxtFmtColl()->GetName(); 236cdf0e10cSrcweir } 237cdf0e10cSrcweir 238cdf0e10cSrcweir SvLBoxEntry* pE = aTbLinks.InsertEntryToColumn( aEntry, n ); 239cdf0e10cSrcweir if(0 == n) 240cdf0e10cSrcweir aTbLinks.Select(pE); 241cdf0e10cSrcweir } 242cdf0e10cSrcweir 243cdf0e10cSrcweir } 244cdf0e10cSrcweir 245cdf0e10cSrcweir /**************************************************************************** 246cdf0e10cSrcweir 247cdf0e10cSrcweir ****************************************************************************/ 248cdf0e10cSrcweir 249cdf0e10cSrcweir 250cdf0e10cSrcweir sal_uInt16* __EXPORT SwCondCollPage::GetRanges() 251cdf0e10cSrcweir { 252cdf0e10cSrcweir return aPageRg; 253cdf0e10cSrcweir } 254cdf0e10cSrcweir 255cdf0e10cSrcweir 256cdf0e10cSrcweir /**************************************************************************** 257cdf0e10cSrcweir 258cdf0e10cSrcweir ****************************************************************************/ 259cdf0e10cSrcweir 260cdf0e10cSrcweir 261cdf0e10cSrcweir IMPL_LINK( SwCondCollPage, OnOffHdl, CheckBox*, pBox ) 262cdf0e10cSrcweir { 263cdf0e10cSrcweir const sal_Bool bEnable = pBox->IsChecked(); 264cdf0e10cSrcweir aContextFT.Enable( bEnable ); 265cdf0e10cSrcweir aUsedFT .Enable( bEnable ); 266cdf0e10cSrcweir aTbLinks .EnableList( bEnable != sal_False ); 267cdf0e10cSrcweir aStyleFT .Enable( bEnable ); 268cdf0e10cSrcweir aStyleLB .Enable( bEnable ); 269cdf0e10cSrcweir aFilterLB .Enable( bEnable ); 270cdf0e10cSrcweir aRemovePB .Enable( bEnable ); 271cdf0e10cSrcweir aAssignPB .Enable( bEnable ); 272cdf0e10cSrcweir if( bEnable ) 273cdf0e10cSrcweir SelectHdl(0); 274cdf0e10cSrcweir return 0; 275cdf0e10cSrcweir } 276cdf0e10cSrcweir 277cdf0e10cSrcweir /**************************************************************************** 278cdf0e10cSrcweir 279cdf0e10cSrcweir ****************************************************************************/ 280cdf0e10cSrcweir 281cdf0e10cSrcweir 282cdf0e10cSrcweir IMPL_LINK( SwCondCollPage, AssignRemoveHdl, PushButton*, pBtn) 283cdf0e10cSrcweir { 284cdf0e10cSrcweir SvLBoxEntry* pE = aTbLinks.FirstSelected(); 285cdf0e10cSrcweir sal_uLong nPos; 286cdf0e10cSrcweir if( !pE || LISTBOX_ENTRY_NOTFOUND == 287cdf0e10cSrcweir ( nPos = aTbLinks.GetModel()->GetAbsPos( pE ) ) ) 288cdf0e10cSrcweir { 289cdf0e10cSrcweir ASSERT( pE, "wo kommt der leere Eintrag her?" ); 290cdf0e10cSrcweir return 0; 291cdf0e10cSrcweir } 292cdf0e10cSrcweir 293cdf0e10cSrcweir String sSel = aStrArr.GetString( sal_uInt16(nPos) ); 294cdf0e10cSrcweir sSel += '\t'; 295cdf0e10cSrcweir 296cdf0e10cSrcweir const sal_Bool bAssEnabled = pBtn != &aRemovePB && aAssignPB.IsEnabled(); 297cdf0e10cSrcweir aAssignPB.Enable( !bAssEnabled ); 298cdf0e10cSrcweir aRemovePB.Enable( bAssEnabled ); 299cdf0e10cSrcweir if ( bAssEnabled ) 300cdf0e10cSrcweir sSel += aStyleLB.GetSelectEntry(); 301cdf0e10cSrcweir 302cdf0e10cSrcweir aTbLinks.SetUpdateMode(sal_False); 303cdf0e10cSrcweir aTbLinks.GetModel()->Remove(pE); 304cdf0e10cSrcweir pE = aTbLinks.InsertEntryToColumn(sSel, nPos); 305cdf0e10cSrcweir aTbLinks.Select(pE); 306cdf0e10cSrcweir aTbLinks.MakeVisible(pE); 307cdf0e10cSrcweir aTbLinks.SetUpdateMode(sal_True); 308cdf0e10cSrcweir return 0; 309cdf0e10cSrcweir } 310cdf0e10cSrcweir 311cdf0e10cSrcweir /**************************************************************************** 312cdf0e10cSrcweir 313cdf0e10cSrcweir ****************************************************************************/ 314cdf0e10cSrcweir 315cdf0e10cSrcweir 316cdf0e10cSrcweir IMPL_LINK( SwCondCollPage, SelectHdl, ListBox*, pBox) 317cdf0e10cSrcweir { 318cdf0e10cSrcweir if(pBox == &aFilterLB) 319cdf0e10cSrcweir { 320cdf0e10cSrcweir aStyleLB.Clear(); 321cdf0e10cSrcweir sal_uInt16 nSearchFlags = pBox->GetSelectEntryPos(); 322cdf0e10cSrcweir nSearchFlags = *(sal_uInt16*)aFilterLB.GetEntryData(nSearchFlags); 323cdf0e10cSrcweir SfxStyleSheetBasePool* pPool = rSh.GetView().GetDocShell()->GetStyleSheetPool(); 324cdf0e10cSrcweir pPool->SetSearchMask(SFX_STYLE_FAMILY_PARA, nSearchFlags); 325cdf0e10cSrcweir const SfxStyleSheetBase* pBase = pPool->First(); 326cdf0e10cSrcweir while( pBase ) 327cdf0e10cSrcweir { 328cdf0e10cSrcweir if(!pFmt || pBase->GetName() != pFmt->GetName()) 329cdf0e10cSrcweir aStyleLB.InsertEntry(pBase->GetName()); 330cdf0e10cSrcweir pBase = pPool->Next(); 331cdf0e10cSrcweir } 332cdf0e10cSrcweir aStyleLB.SelectEntryPos(0); 333cdf0e10cSrcweir SelectHdl(&aStyleLB); 334cdf0e10cSrcweir 335cdf0e10cSrcweir } 336cdf0e10cSrcweir else 337cdf0e10cSrcweir { 338cdf0e10cSrcweir String sTbEntry; 339cdf0e10cSrcweir SvLBoxEntry* pE = aTbLinks.FirstSelected(); 340cdf0e10cSrcweir if(pE) 341cdf0e10cSrcweir sTbEntry = aTbLinks.GetEntryText(pE); 342cdf0e10cSrcweir sTbEntry = sTbEntry.GetToken(1, '\t'); 343cdf0e10cSrcweir String sStyle = aStyleLB.GetSelectEntry(); 344cdf0e10cSrcweir 345cdf0e10cSrcweir aAssignPB.Enable( sStyle != sTbEntry && aConditionCB.IsChecked() ); 346cdf0e10cSrcweir 347cdf0e10cSrcweir if(pBox != &aStyleLB) 348cdf0e10cSrcweir aRemovePB.Enable( aConditionCB.IsChecked() && sTbEntry.Len() ); 349cdf0e10cSrcweir } 350cdf0e10cSrcweir return 0; 351cdf0e10cSrcweir } 352cdf0e10cSrcweir 353cdf0e10cSrcweir /**************************************************************************** 354cdf0e10cSrcweir 355cdf0e10cSrcweir ****************************************************************************/ 356cdf0e10cSrcweir 357cdf0e10cSrcweir 358cdf0e10cSrcweir void SwCondCollPage::SetCollection( SwFmt* pFormat, sal_Bool bNew ) 359cdf0e10cSrcweir { 360cdf0e10cSrcweir pFmt = pFormat; 361cdf0e10cSrcweir bNewTemplate = bNew; 362cdf0e10cSrcweir } 363