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 .
21 #include <tools/debug.hxx>
22 #include <vcl/ctrl.hxx>
24 #include "assclass.hxx"
26 Assistent::Assistent(int nNoOfPages
)
27 : mnPages(nNoOfPages
), mnCurrentPage(1)
29 if(mnPages
> MAX_PAGES
)
32 mpPageStatus
.reset(new bool[mnPages
]);
34 for(int i
=0; i
< mnPages
; ++i
)
35 mpPageStatus
[i
] = true;
38 bool Assistent::InsertControl(int nDestPage
,Control
* pUsedControl
)
40 DBG_ASSERT( (nDestPage
> 0) && (nDestPage
<= mnPages
), "Page not aviable!");
42 if((nDestPage
>0)&&(nDestPage
<=mnPages
))
44 maPages
[nDestPage
-1].push_back(pUsedControl
);
46 pUsedControl
->Disable();
53 bool Assistent::NextPage()
55 if(mnCurrentPage
<mnPages
)
57 int nPage
= mnCurrentPage
+1;
58 while(nPage
<= mnPages
&& !mpPageStatus
[nPage
-1])
62 return GotoPage(nPage
);
69 bool Assistent::PreviousPage()
73 int nPage
= mnCurrentPage
-1;
74 while(nPage
>= 0 && !mpPageStatus
[nPage
-1])
78 return GotoPage(nPage
);
84 bool Assistent::GotoPage(const int nPageToGo
)
86 DBG_ASSERT( (nPageToGo
> 0) && (nPageToGo
<= mnPages
), "Page not aviable!");
88 if((nPageToGo
>0)&&(nPageToGo
<=mnPages
)&&mpPageStatus
[nPageToGo
-1])
90 int nIndex
=mnCurrentPage
-1;
92 std::vector
<Control
*>::iterator iter
= maPages
[nIndex
].begin();
93 std::vector
<Control
*>::iterator iterEnd
= maPages
[nIndex
].end();
95 for(; iter
!= iterEnd
; ++iter
)
101 mnCurrentPage
=nPageToGo
;
102 nIndex
=mnCurrentPage
-1;
104 iter
= maPages
[nIndex
].begin();
105 iterEnd
= maPages
[nIndex
].end();
107 for(; iter
!= iterEnd
; ++iter
)
120 bool Assistent::IsLastPage() const
122 if(mnCurrentPage
== mnPages
)
125 int nPage
= mnCurrentPage
+1;
126 while(nPage
<= mnPages
&& !mpPageStatus
[nPage
-1])
129 return nPage
> mnPages
;
133 bool Assistent::IsFirstPage() const
135 if(mnCurrentPage
== 1)
138 int nPage
= mnCurrentPage
-1;
139 while(nPage
> 0 && !mpPageStatus
[nPage
-1])
145 int Assistent::GetCurrentPage() const
147 return mnCurrentPage
;
150 bool Assistent::IsEnabled( int nPage
) const
152 DBG_ASSERT( (nPage
>0) && (nPage
<= mnPages
), "Page not aviable!" );
154 return (nPage
>0) && (nPage
<= mnPages
&& mpPageStatus
[nPage
-1]);
157 void Assistent::EnablePage( int nPage
)
159 DBG_ASSERT( (nPage
>0) && (nPage
<= mnPages
), "Page not aviable!" );
161 if((nPage
>0) && (nPage
< mnPages
&& !mpPageStatus
[nPage
-1]))
163 mpPageStatus
[nPage
-1] = true;
167 void Assistent::DisablePage( int nPage
)
169 DBG_ASSERT( (nPage
>0) && (nPage
<= mnPages
), "Page not aviable!" );
171 if((nPage
>0) && (nPage
<= mnPages
&& mpPageStatus
[nPage
-1]))
173 mpPageStatus
[nPage
-1] = false;
174 if(mnCurrentPage
== nPage
)
179 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */