1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sfx2/docfile.hxx>
21 #include <unotools/pathoptions.hxx>
24 #include "Outliner.hxx"
25 #include "res_bmp.hrc"
27 #include <vcl/svapp.hxx>
28 #include "svtools/svlbitm.hxx"
29 #include "svtools/treelistentry.hxx"
31 #include "dlgassim.hxx"
33 SdPageListControl::SdPageListControl(
36 : SvTreeListBox(pParent
, rResId
)
38 // add lines to tree listbox
39 SetStyle( GetStyle() | WB_TABSTOP
| WB_BORDER
| WB_HASLINES
|
40 WB_HASBUTTONS
| WB_HASLINESATROOT
|
42 WB_HASBUTTONSATROOT
);
44 SetNodeDefaultImages ();
45 m_pCheckButton
= new SvLBoxButtonData(this);
46 EnableCheckButton (m_pCheckButton
);
48 SetCheckButtonHdl( LINK(this,SdPageListControl
,CheckButtonClickHdl
) );
51 IMPL_LINK_NOARG(SdPageListControl
, CheckButtonClickHdl
)
53 SvTreeList
* pTreeModel
= GetModel();
54 SvTreeListEntry
* pEntry
= pTreeModel
->First();
58 if(pTreeModel
->IsAtRootDepth(pEntry
) && GetCheckButtonState( pEntry
) == SV_BUTTON_CHECKED
)
60 pEntry
= pTreeModel
->Next( pEntry
);
63 pEntry
= pTreeModel
->First();
64 SetCheckButtonState( pEntry
, SV_BUTTON_CHECKED
);
69 SdPageListControl::~SdPageListControl()
71 delete m_pCheckButton
;
74 void SdPageListControl::Clear()
76 SvTreeListBox::Clear();
79 SvTreeListEntry
* SdPageListControl::InsertPage( const String
& rPageName
)
81 SvTreeListEntry
* pEntry
= new SvTreeListEntry
;
83 pEntry
->AddItem( new SvLBoxButton( pEntry
, SvLBoxButtonKind_enabledCheckbox
,
85 pEntry
->AddItem( new SvLBoxContextBmp( pEntry
, 0, Image(), Image(), 0)); // otherwise boom!
86 pEntry
->AddItem( new SvLBoxString( pEntry
, 0, rPageName
) );
88 GetModel()->Insert( pEntry
);
93 void SdPageListControl::InsertTitle( SvTreeListEntry
* pParent
, const String
& rTitle
)
95 SvTreeListEntry
* pEntry
= new SvTreeListEntry
;
96 pEntry
->AddItem( new SvLBoxString( pEntry
, 0, String() ) );
97 pEntry
->AddItem( new SvLBoxContextBmp( pEntry
, 0, Image(), Image(), 0)); // otherwise boom!
98 pEntry
->AddItem( new SvLBoxString( pEntry
, 0, rTitle
) );
99 GetModel()->Insert( pEntry
,pParent
);
102 void SdPageListControl::Fill( SdDrawDocument
* pDoc
)
104 Outliner
* pOutliner
= pDoc
->GetInternalOutliner();
106 sal_uInt16 nPage
= 0;
107 const sal_uInt16 nMaxPages
= pDoc
->GetPageCount();
108 while( nPage
< nMaxPages
)
110 SdPage
* pPage
= (SdPage
*) pDoc
->GetPage( nPage
);
111 if( pPage
->GetPageKind() == PK_STANDARD
)
113 SvTreeListEntry
* pEntry
= InsertPage( pPage
->GetName() );
114 SetCheckButtonState(pEntry
, SvButtonState( SV_BUTTON_CHECKED
) );
116 SdrTextObj
* pTO
= (SdrTextObj
*)pPage
->GetPresObj(PRESOBJ_TEXT
);
119 // determines the SdrTextObject with the layout text of this page
120 const sal_uLong nObjectCount
= pPage
->GetObjCount();
121 for (sal_uLong nObject
= 0; nObject
< nObjectCount
; nObject
++)
123 SdrObject
* pObject
= pPage
->GetObj(nObject
);
124 if (pObject
->GetObjInventor() == SdrInventor
&& pObject
->GetObjIdentifier() == OBJ_OUTLINETEXT
)
126 pTO
= (SdrTextObj
*)pObject
;
132 if (pTO
&& !pTO
->IsEmptyPresObj())
134 OutlinerParaObject
* pOPO
= pTO
->GetOutlinerParaObject();
138 pOutliner
->SetText( *pOPO
);
140 sal_Int32 nCount
= pOutliner
->GetParagraphCount();
142 Paragraph
* pPara
= NULL
;
144 for (sal_Int32 nPara
= 0; nPara
< nCount
; nPara
++)
146 pPara
= pOutliner
->GetParagraph(nPara
);
147 if(pPara
&& pOutliner
->GetDepth( nPara
) == 0 )
149 String aParaText
= pOutliner
->GetText(pPara
);
150 if(aParaText
.Len() != 0)
151 InsertTitle( pEntry
, aParaText
);
163 sal_uInt16
SdPageListControl::GetSelectedPage()
165 SvTreeListEntry
* pSelEntry
= GetCurEntry();
166 sal_uInt16 nPage
= 0;
170 SvTreeList
* pTreeModel
= GetModel();
171 SvTreeListEntry
* pEntry
= pTreeModel
->First();
173 while( pEntry
&& pEntry
!= pSelEntry
)
175 if(pTreeModel
->IsAtRootDepth(pEntry
))
177 pEntry
= pTreeModel
->Next( pEntry
);
180 if(!pTreeModel
->IsAtRootDepth(pSelEntry
))
186 sal_Bool
SdPageListControl::IsPageChecked( sal_uInt16 nPage
)
188 SvTreeListEntry
* pEntry
= GetModel()->GetEntry(nPage
);
189 return pEntry
?(sal_Bool
)(GetCheckButtonState( pEntry
) == SV_BUTTON_CHECKED
): sal_False
;
192 void SdPageListControl::DataChanged( const DataChangedEvent
& rDCEvt
)
194 SvTreeListBox::DataChanged( rDCEvt
);
197 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */