Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <sfx2/docfile.hxx>
21 : #include <unotools/pathoptions.hxx>
22 :
23 : #include "sdpage.hxx"
24 : #include "Outliner.hxx"
25 : #include "res_bmp.hrc"
26 :
27 : #include <vcl/svapp.hxx>
28 : #include <vcl/builder.hxx>
29 : #include "svtools/svlbitm.hxx"
30 : #include "svtools/treelistentry.hxx"
31 :
32 : #include "dlgassim.hxx"
33 :
34 0 : SdPageListControl::SdPageListControl(
35 : vcl::Window* pParent,
36 : const WinBits nStyle )
37 0 : : SvTreeListBox(pParent, nStyle)
38 : {
39 : // add lines to tree listbox
40 0 : SetStyle( GetStyle() | WB_TABSTOP | WB_BORDER | WB_HASLINES |
41 : WB_HASBUTTONS | WB_HASLINESATROOT |
42 : WB_HSCROLL |
43 0 : WB_HASBUTTONSATROOT );
44 :
45 0 : SetNodeDefaultImages ();
46 0 : m_pCheckButton = new SvLBoxButtonData(this);
47 0 : EnableCheckButton (m_pCheckButton);
48 :
49 0 : SetCheckButtonHdl( LINK(this,SdPageListControl,CheckButtonClickHdl) );
50 0 : }
51 :
52 0 : extern "C" SAL_DLLPUBLIC_EXPORT vcl::Window* SAL_CALL makeSdPageListControl(vcl::Window *pParent, VclBuilder::stringmap &rMap)
53 : {
54 0 : WinBits nWinStyle = WB_TABSTOP;
55 0 : OString sBorder = VclBuilder::extractCustomProperty(rMap);
56 0 : if (!sBorder.isEmpty())
57 0 : nWinStyle |= WB_BORDER;
58 0 : return new SdPageListControl(pParent, nWinStyle);
59 : }
60 :
61 0 : IMPL_LINK_NOARG(SdPageListControl, CheckButtonClickHdl)
62 : {
63 0 : SvTreeList* pTreeModel = GetModel();
64 0 : SvTreeListEntry* pEntry = pTreeModel->First();
65 :
66 0 : while( pEntry )
67 : {
68 0 : if(pTreeModel->IsAtRootDepth(pEntry) && GetCheckButtonState( pEntry ) == SV_BUTTON_CHECKED )
69 0 : return 0;
70 0 : pEntry = pTreeModel->Next( pEntry );
71 : }
72 :
73 0 : pEntry = pTreeModel->First();
74 0 : SetCheckButtonState( pEntry, SV_BUTTON_CHECKED );
75 :
76 0 : return 0;
77 : }
78 :
79 0 : SdPageListControl::~SdPageListControl()
80 : {
81 0 : delete m_pCheckButton;
82 0 : }
83 :
84 0 : void SdPageListControl::Clear()
85 : {
86 0 : SvTreeListBox::Clear();
87 0 : }
88 :
89 0 : SvTreeListEntry* SdPageListControl::InsertPage( const OUString& rPageName )
90 : {
91 0 : SvTreeListEntry* pEntry = new SvTreeListEntry;
92 :
93 : pEntry->AddItem( new SvLBoxButton( pEntry, SvLBoxButtonKind_enabledCheckbox,
94 0 : 0, m_pCheckButton));
95 0 : pEntry->AddItem( new SvLBoxContextBmp( pEntry, 0, Image(), Image(), false)); // otherwise boom!
96 0 : pEntry->AddItem( new SvLBoxString( pEntry, 0, rPageName ) );
97 :
98 0 : GetModel()->Insert( pEntry );
99 :
100 0 : return pEntry;
101 : }
102 :
103 0 : void SdPageListControl::InsertTitle( SvTreeListEntry* pParent, const OUString& rTitle )
104 : {
105 0 : SvTreeListEntry* pEntry = new SvTreeListEntry;
106 0 : pEntry->AddItem( new SvLBoxString( pEntry, 0, OUString() ) );
107 0 : pEntry->AddItem( new SvLBoxContextBmp( pEntry, 0, Image(), Image(), false)); // otherwise boom!
108 0 : pEntry->AddItem( new SvLBoxString( pEntry, 0, rTitle ) );
109 0 : GetModel()->Insert( pEntry,pParent );
110 0 : }
111 :
112 0 : void SdPageListControl::Fill( SdDrawDocument* pDoc )
113 : {
114 0 : Outliner* pOutliner = pDoc->GetInternalOutliner();
115 :
116 0 : sal_uInt16 nPage = 0;
117 0 : const sal_uInt16 nMaxPages = pDoc->GetPageCount();
118 0 : while( nPage < nMaxPages )
119 : {
120 0 : SdPage* pPage = (SdPage*) pDoc->GetPage( nPage );
121 0 : if( pPage->GetPageKind() == PK_STANDARD )
122 : {
123 0 : SvTreeListEntry* pEntry = InsertPage( pPage->GetName() );
124 0 : SetCheckButtonState(pEntry, SvButtonState( SV_BUTTON_CHECKED ) );
125 :
126 0 : SdrTextObj* pTO = (SdrTextObj*)pPage->GetPresObj(PRESOBJ_TEXT);
127 0 : if(!pTO)
128 : {
129 : // determines the SdrTextObject with the layout text of this page
130 0 : const size_t nObjectCount = pPage->GetObjCount();
131 0 : for (size_t nObject = 0; nObject < nObjectCount; ++nObject)
132 : {
133 0 : SdrObject* pObject = pPage->GetObj(nObject);
134 0 : if (pObject->GetObjInventor() == SdrInventor && pObject->GetObjIdentifier() == OBJ_OUTLINETEXT)
135 : {
136 0 : pTO = (SdrTextObj*)pObject;
137 0 : break;
138 : }
139 : }
140 : }
141 :
142 0 : if (pTO && !pTO->IsEmptyPresObj())
143 : {
144 0 : OutlinerParaObject* pOPO = pTO->GetOutlinerParaObject();
145 0 : if (pOPO)
146 : {
147 0 : pOutliner->Clear();
148 0 : pOutliner->SetText( *pOPO );
149 :
150 0 : sal_Int32 nCount = pOutliner->GetParagraphCount();
151 :
152 0 : Paragraph* pPara = NULL;
153 :
154 0 : for (sal_Int32 nPara = 0; nPara < nCount; nPara++)
155 : {
156 0 : pPara = pOutliner->GetParagraph(nPara);
157 0 : if(pPara && pOutliner->GetDepth( nPara ) == 0 )
158 : {
159 0 : OUString aParaText = pOutliner->GetText(pPara);
160 0 : if (!aParaText.isEmpty())
161 0 : InsertTitle( pEntry, aParaText );
162 : }
163 : }
164 : }
165 : }
166 : }
167 0 : nPage++;
168 : }
169 :
170 0 : pOutliner->Clear();
171 0 : }
172 :
173 0 : sal_uInt16 SdPageListControl::GetSelectedPage()
174 : {
175 0 : SvTreeListEntry* pSelEntry = GetCurEntry();
176 0 : sal_uInt16 nPage = 0;
177 :
178 0 : if ( pSelEntry )
179 : {
180 0 : SvTreeList* pTreeModel = GetModel();
181 0 : SvTreeListEntry* pEntry = pTreeModel->First();
182 :
183 0 : while( pEntry && pEntry != pSelEntry )
184 : {
185 0 : if(pTreeModel->IsAtRootDepth(pEntry))
186 0 : nPage++;
187 0 : pEntry = pTreeModel->Next( pEntry );
188 : }
189 :
190 0 : if(!pTreeModel->IsAtRootDepth(pSelEntry))
191 0 : nPage--;
192 : }
193 0 : return nPage;
194 : }
195 :
196 0 : bool SdPageListControl::IsPageChecked( sal_uInt16 nPage )
197 : {
198 0 : SvTreeListEntry* pEntry = GetModel()->GetEntry(nPage);
199 0 : return pEntry && (GetCheckButtonState( pEntry ) == SV_BUTTON_CHECKED);
200 : }
201 :
202 0 : void SdPageListControl::DataChanged( const DataChangedEvent& rDCEvt )
203 : {
204 0 : SvTreeListBox::DataChanged( rDCEvt );
205 0 : }
206 :
207 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|