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 <tools/debug.hxx>
21 #include <vcl/ctrl.hxx>
23 #include <assclass.hxx>
25 Assistent::Assistent(int nNoOfPages
)
26 : mnPages(nNoOfPages
), mnCurrentPage(1)
28 if(mnPages
> MAX_PAGES
)
31 mpPageStatus
.reset(new bool[mnPages
]);
33 for(int i
=0; i
< mnPages
; ++i
)
34 mpPageStatus
[i
] = true;
37 bool Assistent::InsertControl(int nDestPage
, vcl::Window
* pUsedControl
)
39 DBG_ASSERT( (nDestPage
> 0) && (nDestPage
<= mnPages
), "Page not available!");
41 if((nDestPage
>0)&&(nDestPage
<=mnPages
))
43 maPages
[nDestPage
-1].emplace_back(pUsedControl
);
45 pUsedControl
->Disable();
52 void Assistent::NextPage()
54 if(mnCurrentPage
<mnPages
)
56 int nPage
= mnCurrentPage
+1;
57 while(nPage
<= mnPages
&& !mpPageStatus
[nPage
-1])
65 void Assistent::PreviousPage()
69 int nPage
= mnCurrentPage
-1;
70 while(nPage
>= 0 && !mpPageStatus
[nPage
-1])
78 bool Assistent::GotoPage(const int nPageToGo
)
80 DBG_ASSERT( (nPageToGo
> 0) && (nPageToGo
<= mnPages
), "Page not available!");
82 if((nPageToGo
>0)&&(nPageToGo
<=mnPages
)&&mpPageStatus
[nPageToGo
-1])
84 int nIndex
=mnCurrentPage
-1;
86 auto iter
= maPages
[nIndex
].begin();
87 auto iterEnd
= maPages
[nIndex
].end();
89 for(; iter
!= iterEnd
; ++iter
)
95 mnCurrentPage
=nPageToGo
;
96 nIndex
=mnCurrentPage
-1;
98 iter
= maPages
[nIndex
].begin();
99 iterEnd
= maPages
[nIndex
].end();
101 for(; iter
!= iterEnd
; ++iter
)
113 bool Assistent::IsLastPage() const
115 if(mnCurrentPage
== mnPages
)
118 int nPage
= mnCurrentPage
+1;
119 while(nPage
<= mnPages
&& !mpPageStatus
[nPage
-1])
122 return nPage
> mnPages
;
125 bool Assistent::IsFirstPage() const
127 if(mnCurrentPage
== 1)
130 int nPage
= mnCurrentPage
-1;
131 while(nPage
> 0 && !mpPageStatus
[nPage
-1])
137 bool Assistent::IsEnabled( int nPage
) const
139 DBG_ASSERT( (nPage
>0) && (nPage
<= mnPages
), "Page not available!" );
141 return (nPage
>0) && (nPage
<= mnPages
&& mpPageStatus
[nPage
-1]);
144 void Assistent::EnablePage( int nPage
)
146 DBG_ASSERT( (nPage
>0) && (nPage
<= mnPages
), "Page not available!" );
148 if((nPage
>0) && (nPage
< mnPages
&& !mpPageStatus
[nPage
-1]))
150 mpPageStatus
[nPage
-1] = true;
154 void Assistent::DisablePage( int nPage
)
156 DBG_ASSERT( (nPage
>0) && (nPage
<= mnPages
), "Page not available!" );
158 if((nPage
>0) && (nPage
<= mnPages
&& mpPageStatus
[nPage
-1]))
160 mpPageStatus
[nPage
-1] = false;
161 if(mnCurrentPage
== nPage
)
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */