xref: /trunk/main/sd/source/ui/dlg/assclass.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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 
32 #include <tools/list.hxx>
33 #include <tools/debug.hxx>
34 #include <vcl/ctrl.hxx>
35 
36 #include "assclass.hxx"
37 
38 
39 Assistent::Assistent(int nNoOfPages)
40 {
41     mnPages=nNoOfPages;
42     if(mnPages>MAX_PAGES)
43     {
44         mnPages=MAX_PAGES;
45     }
46 
47     mpPageStatus = new bool[mnPages];
48 
49     for(sal_uInt8 i=0;i<mnPages;i++)
50     {
51         mpPages[i]=new List();
52         mpPageStatus[i] = sal_True;
53     }
54     mnCurrentPage=1;
55 }
56 
57 
58 
59 bool Assistent::InsertControl(int nDestPage,Control* pUsedControl)
60 {
61     DBG_ASSERT( (nDestPage > 0) && (nDestPage <= mnPages), "Seite nicht vorhanden!");
62     if((nDestPage>0)&&(nDestPage<=mnPages))
63     {
64         mpPages[nDestPage-1]->Insert(pUsedControl,LIST_APPEND);
65         pUsedControl->Hide();
66         pUsedControl->Disable();
67         return true;
68     }
69     else
70     {
71         return false;
72     }
73 }
74 
75 
76 bool Assistent::NextPage()
77 {
78     if(mnCurrentPage<mnPages)
79     {
80         int nPage = mnCurrentPage+1;
81         while(nPage <= mnPages && !mpPageStatus[nPage-1])
82           nPage++;
83 
84         if(nPage <= mnPages)
85             return GotoPage(nPage);
86     }
87     return false;
88 }
89 
90 
91 bool Assistent::PreviousPage()
92 {
93     if(mnCurrentPage>1)
94     {
95         int nPage = mnCurrentPage-1;
96         while(nPage >= 0 && !mpPageStatus[nPage-1])
97             nPage--;
98 
99         if(nPage >= 0)
100             return GotoPage(nPage);
101     }
102     return false;
103 }
104 
105 
106 bool Assistent::GotoPage(const int nPageToGo)
107 {
108     DBG_ASSERT( (nPageToGo > 0) && (nPageToGo <= mnPages), "Seite nicht vorhanden!");
109 
110     if((nPageToGo>0)&&(nPageToGo<=mnPages)&&mpPageStatus[nPageToGo-1])
111     {
112         int i;
113         Control* pCurControl;
114         int nIndex=mnCurrentPage-1;
115 
116         for(i=0;i<(int)mpPages[nIndex]->Count();i++)
117         {
118             pCurControl=(Control*)mpPages[nIndex]->GetObject(i);
119             pCurControl->Disable();
120             pCurControl->Hide();
121                 //schaltet die Controls der vorherigen Seite
122                 //zurueck
123         }
124         mnCurrentPage=nPageToGo;
125         nIndex=mnCurrentPage-1;
126         for(i=0;i<(int)mpPages[nIndex]->Count();i++)
127         {
128 
129             pCurControl=(Control*)mpPages[nIndex]->GetObject(i);
130             pCurControl->Enable();
131             pCurControl->Show();
132                 //zeigt die neue Seite im Fenster an
133         }
134         return true;
135     }
136     else
137     {
138         return false;
139     }
140 }
141 
142 
143 bool Assistent::IsLastPage()
144 {
145     if(mnCurrentPage==mnPages)
146     {
147         return true;
148     }
149     else
150     {
151         int nPage = mnCurrentPage+1;
152         while(nPage <= mnPages && !mpPageStatus[nPage-1])
153             nPage++;
154 
155         return nPage > mnPages;
156     }
157 }
158 
159 
160 bool Assistent::IsFirstPage()
161 {
162     if(mnCurrentPage==1)
163     {
164         return true;
165     }
166     else
167     {
168         int nPage = mnCurrentPage-1;
169         while(nPage > 0 && !mpPageStatus[nPage-1])
170             nPage--;
171 
172         return nPage == 0;
173     }
174 }
175 
176 
177 
178 int Assistent::GetCurrentPage()
179 {
180     return mnCurrentPage;
181 }
182 
183 Assistent::~Assistent()
184 {
185     for( int i=0;i<mnPages;i++)
186     {
187         delete mpPages[i];
188     }
189 
190     delete [] mpPageStatus;
191 }
192 
193 bool Assistent::IsEnabled( int nPage )
194 {
195     DBG_ASSERT( (nPage>0) && (nPage <= mnPages), "Seite nicht vorhanden!" );
196 
197     return (nPage>0) && (nPage <= mnPages && mpPageStatus[nPage-1]);
198 }
199 
200 void Assistent::EnablePage( int nPage )
201 {
202     DBG_ASSERT( (nPage>0) && (nPage <= mnPages), "Seite nicht vorhanden!" );
203 
204     if((nPage>0) && (nPage < mnPages && !mpPageStatus[nPage-1]))
205     {
206         mpPageStatus[nPage-1] = true;
207     }
208 }
209 
210 void Assistent::DisablePage( int nPage )
211 {
212     DBG_ASSERT( (nPage>0) && (nPage <= mnPages), "Seite nicht vorhanden!" );
213 
214     if((nPage>0) && (nPage <= mnPages && mpPageStatus[nPage-1]))
215     {
216         mpPageStatus[nPage-1] = false;
217         if(mnCurrentPage == nPage)
218             GotoPage(1);
219     }
220 }
221