NXWidgets  1.19
ctabpanel.cxx
Go to the documentation of this file.
1 /****************************************************************************
2  * NxWidgets/libnxwidgets/src/ctabpanel.hxx
3  *
4  * Copyright (C) 2013-2014 Gregory Nutt. All rights reserved.
5  * Author: Petteri Aimonen <jpa@kapsi.fi>
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
18  * me be used to endorse or promote products derived from this software
19  * without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *
34  ****************************************************************************/
35 
36 /****************************************************************************
37  * Included Files
38  ****************************************************************************/
39 
40 #include <nuttx/config.h>
41 
42 #include <stdint.h>
43 #include <stdbool.h>
44 
45 #include <nuttx/nx/nxglib.h>
46 
47 #include "ctabpanel.hxx"
48 #include "cgraphicsport.hxx"
49 #include "cwidgetstyle.hxx"
50 
51 /****************************************************************************
52  * Pre-Processor Definitions
53  ****************************************************************************/
54 
55 /****************************************************************************
56  * CTabPanel Method Implementations
57  ****************************************************************************/
58 
59 using namespace NXWidgets;
60 
61 CTabPanel::CTabPanel(CWidgetControl *pWidgetControl, uint8_t numPages,
62  nxgl_coord_t x, nxgl_coord_t y,
63  nxgl_coord_t width, nxgl_coord_t height,
64  nxgl_coord_t buttonHeight,
65  FAR const CWidgetStyle *style
66  ):
67  CNxWidget(pWidgetControl, x, y, width, height, 0, style)
68 {
69  m_buttonbar = new CLatchButtonArray(pWidgetControl, x, y,
70  numPages, 1,
71  width / numPages,
72  buttonHeight,
73  0);
75  this->addWidget(m_buttonbar);
76 
77  for (int i = 0; i < numPages; i++)
78  {
79  CNxWidget *tabpage = new CNxWidget(pWidgetControl, x, y + buttonHeight,
80  width, height - buttonHeight, 0);
82  tabpage->setBorderless(true);
83  m_tabpages.push_back(tabpage);
84  this->addWidget(tabpage);
85  }
86 
87  // Activate the first page
88 
89  showPage(0);
90 }
91 
92 void CTabPanel::setPageName(uint8_t index, const CNxString &name)
93 {
94  m_buttonbar->setText(index, 0, name);
95 }
96 
97 void CTabPanel::showPage(uint8_t index)
98 {
99  if (!m_buttonbar->isThisButtonStuckDown(index, 0))
100  {
101  m_buttonbar->stickDown(index, 0);
102  }
103 
104  for (int i = 0; i < m_tabpages.size(); i++)
105  {
106  if (i != index)
107  {
108  m_tabpages.at(i)->hide();
109  m_tabpages.at(i)->disable();
110  }
111  }
112 
113  m_tabpages.at(index)->enable();
114  m_tabpages.at(index)->show();
115 }
116 
118 {
119  if (e.getSource() == m_buttonbar)
120  {
121  int x = 0;
122  int y = 0;
123 
125  showPage(x);
127  }
128 }
129 
131 {
132  int x = 0;
133  int y = 0;
135  return x;
136 }
uint8_t getCurrentPageIndex() const
Definition: ctabpanel.cxx:130
const T & getSource(void) const
Definition: teventargs.hxx:127
void setPageName(uint8_t index, const CNxString &name)
Definition: ctabpanel.cxx:92
virtual void handleActionEvent(const CWidgetEventArgs &e)
Definition: ctabpanel.cxx:117
TNxArray< CNxWidget * > m_tabpages
Definition: ctabpanel.hxx:83
nxgl_mxpixel_t getBackgroundColor(void) const
Definition: cnxwidget.hxx:716
CNxWidget(const CNxWidget &widget)
Definition: cnxwidget.hxx:271
virtual void setText(int column, int row, const CNxString &text)
CTabPanel(CWidgetControl *pWidgetControl, uint8_t numPages, nxgl_coord_t x, nxgl_coord_t y, nxgl_coord_t width, nxgl_coord_t height, nxgl_coord_t buttonHeight, FAR const CWidgetStyle *style=(FAR const CWidgetStyle *) NULL)
Definition: ctabpanel.cxx:61
void addWidgetEventHandler(CWidgetEventHandler *eventHandler)
Definition: cnxwidget.hxx:854
virtual bool stickDown(int column, int row)
CWidgetEventHandlerList * m_widgetEventHandlers
Definition: cnxwidget.hxx:191
void addWidget(CNxWidget *widget)
Definition: cnxwidget.cxx:1293
CLatchButtonArray * m_buttonbar
Definition: ctabpanel.hxx:84
void showPage(uint8_t index)
Definition: ctabpanel.cxx:97
virtual bool isAnyButtonStuckDown(int &column, int &row) const
virtual bool isThisButtonStuckDown(int column, int row) const
void setBorderless(bool isBorderless)
Definition: cnxwidget.cxx:461
void setBackgroundColor(nxgl_mxpixel_t color)
Definition: cnxwidget.hxx:928