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