LibreOffice Module sd (master) 1
assclass.cxx
Go to the documentation of this file.
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 <tools/debug.hxx>
21#include <vcl/weld.hxx>
22
23#include <assclass.hxx>
24
25Assistent::Assistent(int nNoOfPages)
26 : mnPages(nNoOfPages), mnCurrentPage(1)
27{
28 if(mnPages > MAX_PAGES)
30
31 mpPageStatus.reset(new bool[mnPages]);
32
33 for(int i=0; i < mnPages; ++i)
34 mpPageStatus[i] = true;
35}
36
37bool Assistent::InsertControl(int nDestPage, weld::Widget* pUsedControl)
38{
39 DBG_ASSERT( (nDestPage > 0) && (nDestPage <= mnPages), "Page not available!");
40
41 if((nDestPage>0)&&(nDestPage<=mnPages))
42 {
43 maPages[nDestPage-1].emplace_back(pUsedControl);
44 pUsedControl->hide();
45 pUsedControl->set_sensitive(false);
46 return true;
47 }
48
49 return false;
50}
51
53{
55 {
56 int nPage = mnCurrentPage+1;
57 while(nPage <= mnPages && !mpPageStatus[nPage-1])
58 nPage++;
59
60 if(nPage <= mnPages)
61 GotoPage(nPage);
62 }
63}
64
66{
67 if(mnCurrentPage>1)
68 {
69 int nPage = mnCurrentPage-1;
70 while(nPage >= 0 && !mpPageStatus[nPage-1])
71 nPage--;
72
73 if(nPage >= 0)
74 GotoPage(nPage);
75 }
76}
77
78bool Assistent::GotoPage(const int nPageToGo)
79{
80 DBG_ASSERT( (nPageToGo > 0) && (nPageToGo <= mnPages), "Page not available!");
81
82 if((nPageToGo>0)&&(nPageToGo<=mnPages)&&mpPageStatus[nPageToGo-1])
83 {
85
86 for(auto& rxPage : maPages[nIndex])
87 {
88 rxPage->set_sensitive(false);
89 rxPage->hide();
90 }
91
92 mnCurrentPage=nPageToGo;
94
95 for(auto& rxPage : maPages[nIndex])
96 {
97 rxPage->set_sensitive(true);
98 rxPage->show();
99 }
100
101 return true;
102 }
103
104 return false;
105}
106
108{
110 return true;
111
112 int nPage = mnCurrentPage+1;
113 while(nPage <= mnPages && !mpPageStatus[nPage-1])
114 nPage++;
115
116 return nPage > mnPages;
117}
118
120{
121 if(mnCurrentPage == 1)
122 return true;
123
124 int nPage = mnCurrentPage-1;
125 while(nPage > 0 && !mpPageStatus[nPage-1])
126 nPage--;
127
128 return nPage == 0;
129}
130
131bool Assistent::IsEnabled( int nPage ) const
132{
133 DBG_ASSERT( (nPage>0) && (nPage <= mnPages), "Page not available!" );
134
135 return (nPage>0) && (nPage <= mnPages && mpPageStatus[nPage-1]);
136}
137
138void Assistent::EnablePage( int nPage )
139{
140 DBG_ASSERT( (nPage>0) && (nPage <= mnPages), "Page not available!" );
141
142 if((nPage>0) && (nPage < mnPages && !mpPageStatus[nPage-1]))
143 {
144 mpPageStatus[nPage-1] = true;
145 }
146}
147
148void Assistent::DisablePage( int nPage )
149{
150 DBG_ASSERT( (nPage>0) && (nPage <= mnPages), "Page not available!" );
151
152 if((nPage>0) && (nPage <= mnPages && mpPageStatus[nPage-1]))
153 {
154 mpPageStatus[nPage-1] = false;
155 if(mnCurrentPage == nPage)
156 GotoPage(1);
157 }
158}
159
160/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define MAX_PAGES
Definition: assclass.hxx:27
void NextPage()
Definition: assclass.cxx:52
bool IsLastPage() const
Definition: assclass.cxx:107
bool IsFirstPage() const
Definition: assclass.cxx:119
std::vector< weld::Widget * > maPages[MAX_PAGES]
contains for every page the controls, which have to be connected? correctly
Definition: assclass.hxx:35
void EnablePage(int nPage)
Definition: assclass.cxx:138
int mnPages
number of pages
Definition: assclass.hxx:38
void PreviousPage()
Definition: assclass.cxx:65
Assistent(int nNoOfPage)
Definition: assclass.cxx:25
bool IsEnabled(int nPage) const
Definition: assclass.cxx:131
std::unique_ptr< bool[]> mpPageStatus
Definition: assclass.hxx:42
bool InsertControl(int nDestPage, weld::Widget *pUsedControl)
adds a control to the specified page
Definition: assclass.cxx:37
bool GotoPage(const int nPageToGo)
Definition: assclass.cxx:78
int mnCurrentPage
Definition: assclass.hxx:40
void DisablePage(int nPage)
Definition: assclass.cxx:148
virtual void hide()=0
virtual void set_sensitive(bool sensitive)=0
#define DBG_ASSERT(sCon, aError)
sal_Int32 nIndex
int i