xref: /aoo41x/main/sd/source/ui/dlg/dlgassim.cxx (revision 79aad27f)
1*5b190011SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*5b190011SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*5b190011SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*5b190011SAndrew Rist  * distributed with this work for additional information
6*5b190011SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*5b190011SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*5b190011SAndrew Rist  * "License"); you may not use this file except in compliance
9*5b190011SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*5b190011SAndrew Rist  *
11*5b190011SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*5b190011SAndrew Rist  *
13*5b190011SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*5b190011SAndrew Rist  * software distributed under the License is distributed on an
15*5b190011SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*5b190011SAndrew Rist  * KIND, either express or implied.  See the License for the
17*5b190011SAndrew Rist  * specific language governing permissions and limitations
18*5b190011SAndrew Rist  * under the License.
19*5b190011SAndrew Rist  *
20*5b190011SAndrew Rist  *************************************************************/
21*5b190011SAndrew Rist 
22*5b190011SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sd.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #ifdef SD_DLLIMPLEMENTATION
28cdf0e10cSrcweir #undef SD_DLLIMPLEMENTATION
29cdf0e10cSrcweir #endif
30cdf0e10cSrcweir #include <sfx2/docfile.hxx>
31cdf0e10cSrcweir #include <tools/urlobj.hxx>
32cdf0e10cSrcweir #include <unotools/pathoptions.hxx>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include "sdpage.hxx"
35cdf0e10cSrcweir #include "Outliner.hxx"
36cdf0e10cSrcweir #include "res_bmp.hrc"
37cdf0e10cSrcweir 
38cdf0e10cSrcweir #include <vcl/svapp.hxx>
39cdf0e10cSrcweir 
40cdf0e10cSrcweir #include "dlgassim.hxx"
41cdf0e10cSrcweir 
SdPageListControl(::Window * pParent,const ResId & rResId)42cdf0e10cSrcweir SdPageListControl::SdPageListControl(
43cdf0e10cSrcweir     ::Window* pParent,
44cdf0e10cSrcweir     const ResId& rResId )
45cdf0e10cSrcweir     : SvTreeListBox(pParent, rResId)
46cdf0e10cSrcweir {
47cdf0e10cSrcweir 	// Tree-ListBox mit Linien versehen
48cdf0e10cSrcweir 	SetStyle( GetStyle() | WB_TABSTOP | WB_BORDER | WB_HASLINES |
49cdf0e10cSrcweir 						    WB_HASBUTTONS |  WB_HASLINESATROOT |
50cdf0e10cSrcweir 							WB_HSCROLL | // #31562#
51cdf0e10cSrcweir 							WB_HASBUTTONSATROOT );
52cdf0e10cSrcweir 
53cdf0e10cSrcweir     SetNodeDefaultImages ();
54cdf0e10cSrcweir     m_pCheckButton = new SvLBoxButtonData(this);
55cdf0e10cSrcweir     EnableCheckButton (m_pCheckButton);
56cdf0e10cSrcweir 
57cdf0e10cSrcweir 	SetCheckButtonHdl( LINK(this,SdPageListControl,CheckButtonClickHdl) );
58cdf0e10cSrcweir }
59cdf0e10cSrcweir 
IMPL_LINK(SdPageListControl,CheckButtonClickHdl,SvLBoxButtonData *,EMPTYARG)60cdf0e10cSrcweir IMPL_LINK( SdPageListControl, CheckButtonClickHdl, SvLBoxButtonData *, EMPTYARG )
61cdf0e10cSrcweir {
62cdf0e10cSrcweir 	SvLBoxTreeList* pTreeModel = GetModel();
63cdf0e10cSrcweir 	SvLBoxEntry* pEntry = pTreeModel->First();
64cdf0e10cSrcweir 
65cdf0e10cSrcweir 	while( pEntry )
66cdf0e10cSrcweir 	{
67cdf0e10cSrcweir 		if(pTreeModel->IsAtRootDepth(pEntry) && GetCheckButtonState( pEntry ) == SV_BUTTON_CHECKED )
68cdf0e10cSrcweir 			return 0;
69cdf0e10cSrcweir 		pEntry = pTreeModel->Next( pEntry );
70cdf0e10cSrcweir 	}
71cdf0e10cSrcweir 
72cdf0e10cSrcweir 	pEntry = pTreeModel->First();
73cdf0e10cSrcweir 	SetCheckButtonState( pEntry, SV_BUTTON_CHECKED );
74cdf0e10cSrcweir 
75cdf0e10cSrcweir 	return 0;
76cdf0e10cSrcweir }
77cdf0e10cSrcweir 
~SdPageListControl()78cdf0e10cSrcweir SdPageListControl::~SdPageListControl()
79cdf0e10cSrcweir {
80cdf0e10cSrcweir 	delete m_pCheckButton;
81cdf0e10cSrcweir }
82cdf0e10cSrcweir 
Clear()83cdf0e10cSrcweir void SdPageListControl::Clear()
84cdf0e10cSrcweir {
85cdf0e10cSrcweir 	SvTreeListBox::Clear();
86cdf0e10cSrcweir }
87cdf0e10cSrcweir 
InsertPage(const String & rPageName)88cdf0e10cSrcweir SvLBoxEntry* SdPageListControl::InsertPage( const String& rPageName )
89cdf0e10cSrcweir {
90cdf0e10cSrcweir 	SvLBoxEntry* pEntry = new SvLBoxEntry;
91cdf0e10cSrcweir 
92cdf0e10cSrcweir 	pEntry->AddItem( new SvLBoxButton( pEntry, SvLBoxButtonKind_enabledCheckbox,
93cdf0e10cSrcweir                                        0, m_pCheckButton));
94cdf0e10cSrcweir 	pEntry->AddItem( new SvLBoxContextBmp( pEntry, 0, Image(), Image(), 0));	// Sonst Puff!
95cdf0e10cSrcweir 	pEntry->AddItem( new SvLBoxString( pEntry, 0, rPageName ) );
96cdf0e10cSrcweir 
97cdf0e10cSrcweir 	GetModel()->Insert( pEntry );
98cdf0e10cSrcweir 
99cdf0e10cSrcweir 	return pEntry;
100cdf0e10cSrcweir }
101cdf0e10cSrcweir 
InsertTitle(SvLBoxEntry * pParent,const String & rTitle)102cdf0e10cSrcweir void SdPageListControl::InsertTitle( SvLBoxEntry* pParent, const String& rTitle )
103cdf0e10cSrcweir {
104cdf0e10cSrcweir 	SvLBoxEntry* pEntry = new SvLBoxEntry;
105cdf0e10cSrcweir 	pEntry->AddItem( new SvLBoxString( pEntry, 0, String() ) );
106cdf0e10cSrcweir 	pEntry->AddItem( new SvLBoxContextBmp( pEntry, 0, Image(), Image(), 0));	// Sonst Puff!
107cdf0e10cSrcweir 	pEntry->AddItem( new SvLBoxString( pEntry, 0, rTitle ) );
108cdf0e10cSrcweir 	GetModel()->Insert( pEntry,pParent );
109cdf0e10cSrcweir }
110cdf0e10cSrcweir 
Fill(SdDrawDocument * pDoc)111cdf0e10cSrcweir void SdPageListControl::Fill( SdDrawDocument* pDoc )
112cdf0e10cSrcweir {
113cdf0e10cSrcweir 	Outliner* pOutliner = pDoc->GetInternalOutliner();
114cdf0e10cSrcweir 
115cdf0e10cSrcweir 	sal_uInt16 nPage = 0;
116cdf0e10cSrcweir 	const sal_uInt16 nMaxPages = pDoc->GetPageCount();
117cdf0e10cSrcweir 	while( nPage < nMaxPages )
118cdf0e10cSrcweir 	{
119cdf0e10cSrcweir 		SdPage* pPage = (SdPage*) pDoc->GetPage( nPage );
120cdf0e10cSrcweir 		if( pPage->GetPageKind() == PK_STANDARD )
121cdf0e10cSrcweir 		{
122cdf0e10cSrcweir 			SvLBoxEntry* pEntry = InsertPage( pPage->GetName() );
123cdf0e10cSrcweir 			SetCheckButtonState(pEntry, SvButtonState( SV_BUTTON_CHECKED ) );
124cdf0e10cSrcweir 
125cdf0e10cSrcweir 			SdrTextObj* pTO = (SdrTextObj*)pPage->GetPresObj(PRESOBJ_TEXT);
126cdf0e10cSrcweir 			if(!pTO)
127cdf0e10cSrcweir 			{
128cdf0e10cSrcweir 				// Ermittelt das SdrTextObject mit dem Layout Text dieser Seite
129cdf0e10cSrcweir 				const sal_uLong nObjectCount = pPage->GetObjCount();
130cdf0e10cSrcweir 				for (sal_uLong nObject = 0; nObject < nObjectCount; nObject++)
131cdf0e10cSrcweir 				{
132cdf0e10cSrcweir 					SdrObject* pObject = pPage->GetObj(nObject);
133cdf0e10cSrcweir 					if (pObject->GetObjInventor() == SdrInventor &&	pObject->GetObjIdentifier() == OBJ_OUTLINETEXT)
134cdf0e10cSrcweir 					{
135cdf0e10cSrcweir 						pTO = (SdrTextObj*)pObject;
136cdf0e10cSrcweir 						break;
137cdf0e10cSrcweir 					}
138cdf0e10cSrcweir 				}
139cdf0e10cSrcweir 			}
140cdf0e10cSrcweir 
141cdf0e10cSrcweir 			if (pTO && !pTO->IsEmptyPresObj())
142cdf0e10cSrcweir 			{
143cdf0e10cSrcweir 				OutlinerParaObject* pOPO = pTO->GetOutlinerParaObject();
144cdf0e10cSrcweir 				if (pOPO)
145cdf0e10cSrcweir 				{
146cdf0e10cSrcweir 					pOutliner->Clear();
147cdf0e10cSrcweir 					pOutliner->SetText( *pOPO );
148cdf0e10cSrcweir 
149cdf0e10cSrcweir 					sal_uLong nCount = pOutliner->GetParagraphCount();
150cdf0e10cSrcweir 
151cdf0e10cSrcweir 					Paragraph* pPara = NULL;
152cdf0e10cSrcweir 
153cdf0e10cSrcweir 					for (sal_uLong nPara = 0; nPara < nCount; nPara++)
154cdf0e10cSrcweir 					{
155cdf0e10cSrcweir 						pPara = pOutliner->GetParagraph(nPara);
156cdf0e10cSrcweir 						if(pPara && pOutliner->GetDepth( (sal_uInt16) nPara ) == 0 )
157cdf0e10cSrcweir 						{
158cdf0e10cSrcweir 							String aParaText = pOutliner->GetText(pPara);
159cdf0e10cSrcweir 							if(aParaText.Len() != 0)
160cdf0e10cSrcweir 								InsertTitle( pEntry, aParaText );
161cdf0e10cSrcweir 						}
162cdf0e10cSrcweir 					}
163cdf0e10cSrcweir 				}
164cdf0e10cSrcweir 			}
165cdf0e10cSrcweir 		}
166cdf0e10cSrcweir 		nPage++;
167cdf0e10cSrcweir 	}
168cdf0e10cSrcweir 
169cdf0e10cSrcweir 	pOutliner->Clear();
170cdf0e10cSrcweir }
171cdf0e10cSrcweir 
GetSelectedPage()172cdf0e10cSrcweir sal_uInt16 SdPageListControl::GetSelectedPage()
173cdf0e10cSrcweir {
174cdf0e10cSrcweir 	SvLBoxEntry* pSelEntry = GetCurEntry();
175cdf0e10cSrcweir 	sal_uInt16 nPage = 0;
176cdf0e10cSrcweir 
177cdf0e10cSrcweir 	if ( pSelEntry )
178cdf0e10cSrcweir 	{
179cdf0e10cSrcweir 		SvLBoxTreeList* pTreeModel = GetModel();
180cdf0e10cSrcweir 		SvLBoxEntry* pEntry = pTreeModel->First();
181cdf0e10cSrcweir 
182cdf0e10cSrcweir 		while( pEntry && pEntry != pSelEntry )
183cdf0e10cSrcweir 		{
184cdf0e10cSrcweir 			if(pTreeModel->IsAtRootDepth(pEntry))
185cdf0e10cSrcweir 				nPage++;
186cdf0e10cSrcweir 			pEntry = pTreeModel->Next( pEntry );
187cdf0e10cSrcweir 		}
188cdf0e10cSrcweir 
189cdf0e10cSrcweir 		if(!pTreeModel->IsAtRootDepth(pSelEntry))
190cdf0e10cSrcweir 			nPage--;
191cdf0e10cSrcweir 	}
192cdf0e10cSrcweir 	return nPage;
193cdf0e10cSrcweir }
194cdf0e10cSrcweir 
IsPageChecked(sal_uInt16 nPage)195cdf0e10cSrcweir sal_Bool SdPageListControl::IsPageChecked( sal_uInt16 nPage )
196cdf0e10cSrcweir {
197cdf0e10cSrcweir 	SvLBoxEntry* pEntry = GetModel()->GetEntry(nPage);
198cdf0e10cSrcweir 	return pEntry?(sal_Bool)(GetCheckButtonState( pEntry ) == SV_BUTTON_CHECKED): sal_False;
199cdf0e10cSrcweir }
200cdf0e10cSrcweir 
DataChanged(const DataChangedEvent & rDCEvt)201cdf0e10cSrcweir void SdPageListControl::DataChanged( const DataChangedEvent& rDCEvt )
202cdf0e10cSrcweir {
203cdf0e10cSrcweir     SvTreeListBox::DataChanged( rDCEvt );
204cdf0e10cSrcweir }
205cdf0e10cSrcweir 
206