Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / sd / source / ui / dlg / assclass.cxx
blob7123fc7a7ebd0e00715efdf62371044ecd23d282
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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)
29 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);
44 pUsedControl->Hide();
45 pUsedControl->Disable();
46 return true;
49 return false;
52 void Assistent::NextPage()
54 if(mnCurrentPage<mnPages)
56 int nPage = mnCurrentPage+1;
57 while(nPage <= mnPages && !mpPageStatus[nPage-1])
58 nPage++;
60 if(nPage <= mnPages)
61 GotoPage(nPage);
65 void Assistent::PreviousPage()
67 if(mnCurrentPage>1)
69 int nPage = mnCurrentPage-1;
70 while(nPage >= 0 && !mpPageStatus[nPage-1])
71 nPage--;
73 if(nPage >= 0)
74 GotoPage(nPage);
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)
91 (*iter)->Disable();
92 (*iter)->Hide();
95 mnCurrentPage=nPageToGo;
96 nIndex=mnCurrentPage-1;
98 iter = maPages[nIndex].begin();
99 iterEnd = maPages[nIndex].end();
101 for(; iter != iterEnd; ++iter)
103 (*iter)->Enable();
104 (*iter)->Show();
107 return true;
110 return false;
113 bool Assistent::IsLastPage() const
115 if(mnCurrentPage == mnPages)
116 return true;
118 int nPage = mnCurrentPage+1;
119 while(nPage <= mnPages && !mpPageStatus[nPage-1])
120 nPage++;
122 return nPage > mnPages;
125 bool Assistent::IsFirstPage() const
127 if(mnCurrentPage == 1)
128 return true;
130 int nPage = mnCurrentPage-1;
131 while(nPage > 0 && !mpPageStatus[nPage-1])
132 nPage--;
134 return nPage == 0;
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)
162 GotoPage(1);
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */