xref: /aoo42x/main/sd/source/ui/dlg/dlgassim.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sd.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #ifdef SD_DLLIMPLEMENTATION
32*cdf0e10cSrcweir #undef SD_DLLIMPLEMENTATION
33*cdf0e10cSrcweir #endif
34*cdf0e10cSrcweir #include <sfx2/docfile.hxx>
35*cdf0e10cSrcweir #include <tools/urlobj.hxx>
36*cdf0e10cSrcweir #include <unotools/pathoptions.hxx>
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir #include "sdpage.hxx"
39*cdf0e10cSrcweir #include "Outliner.hxx"
40*cdf0e10cSrcweir #include "res_bmp.hrc"
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir #include <vcl/svapp.hxx>
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir #include "dlgassim.hxx"
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir SdPageListControl::SdPageListControl(
47*cdf0e10cSrcweir     ::Window* pParent,
48*cdf0e10cSrcweir     const ResId& rResId )
49*cdf0e10cSrcweir     : SvTreeListBox(pParent, rResId)
50*cdf0e10cSrcweir {
51*cdf0e10cSrcweir 	// Tree-ListBox mit Linien versehen
52*cdf0e10cSrcweir 	SetStyle( GetStyle() | WB_TABSTOP | WB_BORDER | WB_HASLINES |
53*cdf0e10cSrcweir 						    WB_HASBUTTONS |  WB_HASLINESATROOT |
54*cdf0e10cSrcweir 							WB_HSCROLL | // #31562#
55*cdf0e10cSrcweir 							WB_HASBUTTONSATROOT );
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir     SetNodeDefaultImages ();
58*cdf0e10cSrcweir     m_pCheckButton = new SvLBoxButtonData(this);
59*cdf0e10cSrcweir     EnableCheckButton (m_pCheckButton);
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir 	SetCheckButtonHdl( LINK(this,SdPageListControl,CheckButtonClickHdl) );
62*cdf0e10cSrcweir }
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir IMPL_LINK( SdPageListControl, CheckButtonClickHdl, SvLBoxButtonData *, EMPTYARG )
65*cdf0e10cSrcweir {
66*cdf0e10cSrcweir 	SvLBoxTreeList* pTreeModel = GetModel();
67*cdf0e10cSrcweir 	SvLBoxEntry* pEntry = pTreeModel->First();
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir 	while( pEntry )
70*cdf0e10cSrcweir 	{
71*cdf0e10cSrcweir 		if(pTreeModel->IsAtRootDepth(pEntry) && GetCheckButtonState( pEntry ) == SV_BUTTON_CHECKED )
72*cdf0e10cSrcweir 			return 0;
73*cdf0e10cSrcweir 		pEntry = pTreeModel->Next( pEntry );
74*cdf0e10cSrcweir 	}
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir 	pEntry = pTreeModel->First();
77*cdf0e10cSrcweir 	SetCheckButtonState( pEntry, SV_BUTTON_CHECKED );
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir 	return 0;
80*cdf0e10cSrcweir }
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir SdPageListControl::~SdPageListControl()
83*cdf0e10cSrcweir {
84*cdf0e10cSrcweir 	delete m_pCheckButton;
85*cdf0e10cSrcweir }
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir void SdPageListControl::Clear()
88*cdf0e10cSrcweir {
89*cdf0e10cSrcweir 	SvTreeListBox::Clear();
90*cdf0e10cSrcweir }
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir SvLBoxEntry* SdPageListControl::InsertPage( const String& rPageName )
93*cdf0e10cSrcweir {
94*cdf0e10cSrcweir 	SvLBoxEntry* pEntry = new SvLBoxEntry;
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir 	pEntry->AddItem( new SvLBoxButton( pEntry, SvLBoxButtonKind_enabledCheckbox,
97*cdf0e10cSrcweir                                        0, m_pCheckButton));
98*cdf0e10cSrcweir 	pEntry->AddItem( new SvLBoxContextBmp( pEntry, 0, Image(), Image(), 0));	// Sonst Puff!
99*cdf0e10cSrcweir 	pEntry->AddItem( new SvLBoxString( pEntry, 0, rPageName ) );
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir 	GetModel()->Insert( pEntry );
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir 	return pEntry;
104*cdf0e10cSrcweir }
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir void SdPageListControl::InsertTitle( SvLBoxEntry* pParent, const String& rTitle )
107*cdf0e10cSrcweir {
108*cdf0e10cSrcweir 	SvLBoxEntry* pEntry = new SvLBoxEntry;
109*cdf0e10cSrcweir 	pEntry->AddItem( new SvLBoxString( pEntry, 0, String() ) );
110*cdf0e10cSrcweir 	pEntry->AddItem( new SvLBoxContextBmp( pEntry, 0, Image(), Image(), 0));	// Sonst Puff!
111*cdf0e10cSrcweir 	pEntry->AddItem( new SvLBoxString( pEntry, 0, rTitle ) );
112*cdf0e10cSrcweir 	GetModel()->Insert( pEntry,pParent );
113*cdf0e10cSrcweir }
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir void SdPageListControl::Fill( SdDrawDocument* pDoc )
116*cdf0e10cSrcweir {
117*cdf0e10cSrcweir 	Outliner* pOutliner = pDoc->GetInternalOutliner();
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir 	sal_uInt16 nPage = 0;
120*cdf0e10cSrcweir 	const sal_uInt16 nMaxPages = pDoc->GetPageCount();
121*cdf0e10cSrcweir 	while( nPage < nMaxPages )
122*cdf0e10cSrcweir 	{
123*cdf0e10cSrcweir 		SdPage* pPage = (SdPage*) pDoc->GetPage( nPage );
124*cdf0e10cSrcweir 		if( pPage->GetPageKind() == PK_STANDARD )
125*cdf0e10cSrcweir 		{
126*cdf0e10cSrcweir 			SvLBoxEntry* pEntry = InsertPage( pPage->GetName() );
127*cdf0e10cSrcweir 			SetCheckButtonState(pEntry, SvButtonState( SV_BUTTON_CHECKED ) );
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir 			SdrTextObj* pTO = (SdrTextObj*)pPage->GetPresObj(PRESOBJ_TEXT);
130*cdf0e10cSrcweir 			if(!pTO)
131*cdf0e10cSrcweir 			{
132*cdf0e10cSrcweir 				// Ermittelt das SdrTextObject mit dem Layout Text dieser Seite
133*cdf0e10cSrcweir 				const sal_uLong nObjectCount = pPage->GetObjCount();
134*cdf0e10cSrcweir 				for (sal_uLong nObject = 0; nObject < nObjectCount; nObject++)
135*cdf0e10cSrcweir 				{
136*cdf0e10cSrcweir 					SdrObject* pObject = pPage->GetObj(nObject);
137*cdf0e10cSrcweir 					if (pObject->GetObjInventor() == SdrInventor &&	pObject->GetObjIdentifier() == OBJ_OUTLINETEXT)
138*cdf0e10cSrcweir 					{
139*cdf0e10cSrcweir 						pTO = (SdrTextObj*)pObject;
140*cdf0e10cSrcweir 						break;
141*cdf0e10cSrcweir 					}
142*cdf0e10cSrcweir 				}
143*cdf0e10cSrcweir 			}
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir 			if (pTO && !pTO->IsEmptyPresObj())
146*cdf0e10cSrcweir 			{
147*cdf0e10cSrcweir 				OutlinerParaObject* pOPO = pTO->GetOutlinerParaObject();
148*cdf0e10cSrcweir 				if (pOPO)
149*cdf0e10cSrcweir 				{
150*cdf0e10cSrcweir 					pOutliner->Clear();
151*cdf0e10cSrcweir 					pOutliner->SetText( *pOPO );
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir 					sal_uLong nCount = pOutliner->GetParagraphCount();
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir 					Paragraph* pPara = NULL;
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir 					for (sal_uLong nPara = 0; nPara < nCount; nPara++)
158*cdf0e10cSrcweir 					{
159*cdf0e10cSrcweir 						pPara = pOutliner->GetParagraph(nPara);
160*cdf0e10cSrcweir 						if(pPara && pOutliner->GetDepth( (sal_uInt16) nPara ) == 0 )
161*cdf0e10cSrcweir 						{
162*cdf0e10cSrcweir 							String aParaText = pOutliner->GetText(pPara);
163*cdf0e10cSrcweir 							if(aParaText.Len() != 0)
164*cdf0e10cSrcweir 								InsertTitle( pEntry, aParaText );
165*cdf0e10cSrcweir 						}
166*cdf0e10cSrcweir 					}
167*cdf0e10cSrcweir 				}
168*cdf0e10cSrcweir 			}
169*cdf0e10cSrcweir 		}
170*cdf0e10cSrcweir 		nPage++;
171*cdf0e10cSrcweir 	}
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir 	pOutliner->Clear();
174*cdf0e10cSrcweir }
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir sal_uInt16 SdPageListControl::GetSelectedPage()
177*cdf0e10cSrcweir {
178*cdf0e10cSrcweir 	SvLBoxEntry* pSelEntry = GetCurEntry();
179*cdf0e10cSrcweir 	sal_uInt16 nPage = 0;
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir 	if ( pSelEntry )
182*cdf0e10cSrcweir 	{
183*cdf0e10cSrcweir 		SvLBoxTreeList* pTreeModel = GetModel();
184*cdf0e10cSrcweir 		SvLBoxEntry* pEntry = pTreeModel->First();
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir 		while( pEntry && pEntry != pSelEntry )
187*cdf0e10cSrcweir 		{
188*cdf0e10cSrcweir 			if(pTreeModel->IsAtRootDepth(pEntry))
189*cdf0e10cSrcweir 				nPage++;
190*cdf0e10cSrcweir 			pEntry = pTreeModel->Next( pEntry );
191*cdf0e10cSrcweir 		}
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir 		if(!pTreeModel->IsAtRootDepth(pSelEntry))
194*cdf0e10cSrcweir 			nPage--;
195*cdf0e10cSrcweir 	}
196*cdf0e10cSrcweir 	return nPage;
197*cdf0e10cSrcweir }
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir sal_Bool SdPageListControl::IsPageChecked( sal_uInt16 nPage )
200*cdf0e10cSrcweir {
201*cdf0e10cSrcweir 	SvLBoxEntry* pEntry = GetModel()->GetEntry(nPage);
202*cdf0e10cSrcweir 	return pEntry?(sal_Bool)(GetCheckButtonState( pEntry ) == SV_BUTTON_CHECKED): sal_False;
203*cdf0e10cSrcweir }
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir void SdPageListControl::DataChanged( const DataChangedEvent& rDCEvt )
206*cdf0e10cSrcweir {
207*cdf0e10cSrcweir     SvTreeListBox::DataChanged( rDCEvt );
208*cdf0e10cSrcweir }
209*cdf0e10cSrcweir 
210