xref: /aoo41x/main/sd/source/ui/dlg/dlgassim.cxx (revision cdf0e10c)
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_sd.hxx"
30 
31 #ifdef SD_DLLIMPLEMENTATION
32 #undef SD_DLLIMPLEMENTATION
33 #endif
34 #include <sfx2/docfile.hxx>
35 #include <tools/urlobj.hxx>
36 #include <unotools/pathoptions.hxx>
37 
38 #include "sdpage.hxx"
39 #include "Outliner.hxx"
40 #include "res_bmp.hrc"
41 
42 #include <vcl/svapp.hxx>
43 
44 #include "dlgassim.hxx"
45 
46 SdPageListControl::SdPageListControl(
47     ::Window* pParent,
48     const ResId& rResId )
49     : SvTreeListBox(pParent, rResId)
50 {
51 	// Tree-ListBox mit Linien versehen
52 	SetStyle( GetStyle() | WB_TABSTOP | WB_BORDER | WB_HASLINES |
53 						    WB_HASBUTTONS |  WB_HASLINESATROOT |
54 							WB_HSCROLL | // #31562#
55 							WB_HASBUTTONSATROOT );
56 
57     SetNodeDefaultImages ();
58     m_pCheckButton = new SvLBoxButtonData(this);
59     EnableCheckButton (m_pCheckButton);
60 
61 	SetCheckButtonHdl( LINK(this,SdPageListControl,CheckButtonClickHdl) );
62 }
63 
64 IMPL_LINK( SdPageListControl, CheckButtonClickHdl, SvLBoxButtonData *, EMPTYARG )
65 {
66 	SvLBoxTreeList* pTreeModel = GetModel();
67 	SvLBoxEntry* pEntry = pTreeModel->First();
68 
69 	while( pEntry )
70 	{
71 		if(pTreeModel->IsAtRootDepth(pEntry) && GetCheckButtonState( pEntry ) == SV_BUTTON_CHECKED )
72 			return 0;
73 		pEntry = pTreeModel->Next( pEntry );
74 	}
75 
76 	pEntry = pTreeModel->First();
77 	SetCheckButtonState( pEntry, SV_BUTTON_CHECKED );
78 
79 	return 0;
80 }
81 
82 SdPageListControl::~SdPageListControl()
83 {
84 	delete m_pCheckButton;
85 }
86 
87 void SdPageListControl::Clear()
88 {
89 	SvTreeListBox::Clear();
90 }
91 
92 SvLBoxEntry* SdPageListControl::InsertPage( const String& rPageName )
93 {
94 	SvLBoxEntry* pEntry = new SvLBoxEntry;
95 
96 	pEntry->AddItem( new SvLBoxButton( pEntry, SvLBoxButtonKind_enabledCheckbox,
97                                        0, m_pCheckButton));
98 	pEntry->AddItem( new SvLBoxContextBmp( pEntry, 0, Image(), Image(), 0));	// Sonst Puff!
99 	pEntry->AddItem( new SvLBoxString( pEntry, 0, rPageName ) );
100 
101 	GetModel()->Insert( pEntry );
102 
103 	return pEntry;
104 }
105 
106 void SdPageListControl::InsertTitle( SvLBoxEntry* pParent, const String& rTitle )
107 {
108 	SvLBoxEntry* pEntry = new SvLBoxEntry;
109 	pEntry->AddItem( new SvLBoxString( pEntry, 0, String() ) );
110 	pEntry->AddItem( new SvLBoxContextBmp( pEntry, 0, Image(), Image(), 0));	// Sonst Puff!
111 	pEntry->AddItem( new SvLBoxString( pEntry, 0, rTitle ) );
112 	GetModel()->Insert( pEntry,pParent );
113 }
114 
115 void SdPageListControl::Fill( SdDrawDocument* pDoc )
116 {
117 	Outliner* pOutliner = pDoc->GetInternalOutliner();
118 
119 	sal_uInt16 nPage = 0;
120 	const sal_uInt16 nMaxPages = pDoc->GetPageCount();
121 	while( nPage < nMaxPages )
122 	{
123 		SdPage* pPage = (SdPage*) pDoc->GetPage( nPage );
124 		if( pPage->GetPageKind() == PK_STANDARD )
125 		{
126 			SvLBoxEntry* pEntry = InsertPage( pPage->GetName() );
127 			SetCheckButtonState(pEntry, SvButtonState( SV_BUTTON_CHECKED ) );
128 
129 			SdrTextObj* pTO = (SdrTextObj*)pPage->GetPresObj(PRESOBJ_TEXT);
130 			if(!pTO)
131 			{
132 				// Ermittelt das SdrTextObject mit dem Layout Text dieser Seite
133 				const sal_uLong nObjectCount = pPage->GetObjCount();
134 				for (sal_uLong nObject = 0; nObject < nObjectCount; nObject++)
135 				{
136 					SdrObject* pObject = pPage->GetObj(nObject);
137 					if (pObject->GetObjInventor() == SdrInventor &&	pObject->GetObjIdentifier() == OBJ_OUTLINETEXT)
138 					{
139 						pTO = (SdrTextObj*)pObject;
140 						break;
141 					}
142 				}
143 			}
144 
145 			if (pTO && !pTO->IsEmptyPresObj())
146 			{
147 				OutlinerParaObject* pOPO = pTO->GetOutlinerParaObject();
148 				if (pOPO)
149 				{
150 					pOutliner->Clear();
151 					pOutliner->SetText( *pOPO );
152 
153 					sal_uLong nCount = pOutliner->GetParagraphCount();
154 
155 					Paragraph* pPara = NULL;
156 
157 					for (sal_uLong nPara = 0; nPara < nCount; nPara++)
158 					{
159 						pPara = pOutliner->GetParagraph(nPara);
160 						if(pPara && pOutliner->GetDepth( (sal_uInt16) nPara ) == 0 )
161 						{
162 							String aParaText = pOutliner->GetText(pPara);
163 							if(aParaText.Len() != 0)
164 								InsertTitle( pEntry, aParaText );
165 						}
166 					}
167 				}
168 			}
169 		}
170 		nPage++;
171 	}
172 
173 	pOutliner->Clear();
174 }
175 
176 sal_uInt16 SdPageListControl::GetSelectedPage()
177 {
178 	SvLBoxEntry* pSelEntry = GetCurEntry();
179 	sal_uInt16 nPage = 0;
180 
181 	if ( pSelEntry )
182 	{
183 		SvLBoxTreeList* pTreeModel = GetModel();
184 		SvLBoxEntry* pEntry = pTreeModel->First();
185 
186 		while( pEntry && pEntry != pSelEntry )
187 		{
188 			if(pTreeModel->IsAtRootDepth(pEntry))
189 				nPage++;
190 			pEntry = pTreeModel->Next( pEntry );
191 		}
192 
193 		if(!pTreeModel->IsAtRootDepth(pSelEntry))
194 			nPage--;
195 	}
196 	return nPage;
197 }
198 
199 sal_Bool SdPageListControl::IsPageChecked( sal_uInt16 nPage )
200 {
201 	SvLBoxEntry* pEntry = GetModel()->GetEntry(nPage);
202 	return pEntry?(sal_Bool)(GetCheckButtonState( pEntry ) == SV_BUTTON_CHECKED): sal_False;
203 }
204 
205 void SdPageListControl::DataChanged( const DataChangedEvent& rDCEvt )
206 {
207     SvTreeListBox::DataChanged( rDCEvt );
208 }
209 
210