ManaPlus
Public Member Functions | Private Types | Private Member Functions | Private Attributes
TabbedArea Class Reference

#include <tabbedarea.h>

Inheritance diagram for TabbedArea:
ActionListener BasicContainer KeyListener MouseListener WidgetListener Widget WidgetDeathListener Widget2

Public Member Functions

 TabbedArea (const Widget2 *const widget)
 
 ~TabbedArea ()
 
void postInit ()
 
void draw (Graphics *const graphics)
 
void safeDraw (Graphics *const graphics)
 
int getNumberOfTabs () const
 
TabgetTab (const std::string &name) const
 
TabgetTabByIndex (const int index) const
 
WidgetgetWidgetByIndex (const int index) const
 
WidgetgetWidget (const std::string &name) const
 
WidgetgetCurrentWidget () const
 
void addTab (Tab *const tab, Widget *const widget)
 
void addTab (const std::string &caption, Widget *const widget)
 
void addTab (Image *const image, Widget *const widget)
 
bool isTabSelected (const size_t index) const
 
bool isTabSelected (const Tab *const tab) const
 
bool isTabPresent (const Tab *const tab) const
 
void removeTab (Tab *const tab)
 
void removeAll (const bool del)
 
void logic ()
 
int getContainerHeight () const
 
void setSelectedTab (Tab *const tab)
 
void setSelectedTabDefault ()
 
void setSelectedTabByIndex (const size_t index)
 
int getSelectedTabIndex () const
 
TabgetSelectedTab () const
 
void setOpaque (const Opaque opaque)
 
bool isOpaque () const
 
void adjustSize ()
 
void setSelectedTabByName (const std::string &name)
 
void widgetResized (const Event &event)
 
void adjustTabPositions ()
 
void action (const ActionEvent &actionEvent)
 
void mousePressed (MouseEvent &event)
 
void enableScrollButtons (const bool enable)
 
void setRightMargin (const int n)
 
int getRightMargin () const
 
void setFollowDownScroll (const bool n)
 
bool getFollowDownScroll () const
 
void keyPressed (KeyEvent &event)
 
void setBlockSwitching (const bool b)
 
void setWidth (int width)
 
void setHeight (int height)
 
void setSize (int width, int height)
 
void setDimension (const Rect &dimension)
 
void death (const Event &event)
 
void setResizeHeight (bool b)
 
void adjustWidget (Widget *const widget) const
 
void selectNextTab ()
 
void selectPrevTab ()
 
WidgetgetTabContainer () const
 
WidgetgetWidgetContainer () const
 
- Public Member Functions inherited from ActionListener
virtual ~ActionListener ()
 
- Public Member Functions inherited from BasicContainer
 BasicContainer (const Widget2 *const widget)
 
 ~BasicContainer ()
 
void showWidgetPart (Widget *const widget, const Rect &area)
 
void moveToTop (Widget *const widget)
 
void moveToBottom (Widget *const widget)
 
Rect getChildrenArea ()
 
void focusNext ()
 
void focusPrevious ()
 
void setFocusHandler (FocusHandler *const focusHandler)
 
void setInternalFocusHandler (FocusHandler *const focusHandler)
 
WidgetgetWidgetAt (int x, int y)
 
WidgetfindFirstWidget (const std::set< Widget * > &list)
 
void add (Widget *const widget)
 
virtual void remove (Widget *const widget)
 
virtual void clear ()
 
- Public Member Functions inherited from Widget
 Widget (const Widget2 *const widget)
 
 ~Widget ()
 
virtual void drawFrame (Graphics *graphics)
 
virtual void safeDrawFrame (Graphics *graphics)
 
void setFrameSize (const unsigned int frameSize)
 
unsigned int getFrameSize () const
 
WidgetgetParent () const
 
void setWidth (const int width)
 
int getWidth () const
 
void setHeight (const int height)
 
int getHeight () const
 
void setSize (const int width, const int height)
 
void setX (const int x)
 
int getX () const
 
void setY (const int y)
 
int getY () const
 
void setPosition (const int x, const int y)
 
void setDimension (const Rect &dimension)
 
const RectgetDimension () const
 
void setFocusable (const bool focusable)
 
bool isFocusable () const
 
virtual bool isFocused () const
 
void setEnabled (const bool enabled)
 
bool isEnabled () const
 
void setVisible (Visible visible)
 
bool isVisible () const
 
void setBaseColor (const Color &color)
 
const ColorgetBaseColor () const
 
void setForegroundColor (const Color &color)
 
const ColorgetForegroundColor () const
 
void setBackgroundColor (const Color &color)
 
const ColorgetBackgroundColor () const
 
virtual void requestFocus ()
 
virtual void requestMoveToTop ()
 
virtual void requestMoveToBottom ()
 
FocusHandlergetFocusHandler ()
 
void addActionListener (ActionListener *const actionListener)
 
void removeActionListener (ActionListener *const actionListener)
 
void addDeathListener (WidgetDeathListener *const deathListener)
 
void removeDeathListener (WidgetDeathListener *const deathListener)
 
void addMouseListener (MouseListener *const mouseListener)
 
void removeMouseListener (MouseListener *const mouseListener)
 
void addKeyListener (KeyListener *const keyListener)
 
void removeKeyListener (KeyListener *const keyListener)
 
void addFocusListener (FocusListener *const focusListener)
 
void removeFocusListener (FocusListener *const focusListener)
 
void addWidgetListener (WidgetListener *const widgetListener)
 
void removeWidgetListener (WidgetListener *const widgetListener)
 
void setActionEventId (const std::string &actionEventId)
 
const std::string & getActionEventId () const
 
virtual void getAbsolutePosition (int &x, int &y) const
 
virtual void setParent (Widget *parent)
 
FontgetFont () const
 
void setFont (Font *const font)
 
virtual void fontChanged ()
 
bool isTabInEnabled () const
 
void setTabInEnabled (const bool enabled)
 
bool isTabOutEnabled () const
 
void setTabOutEnabled (const bool enabled)
 
void requestModalFocus ()
 
virtual void requestModalMouseInputFocus ()
 
virtual void releaseModalFocus ()
 
virtual void releaseModalMouseInputFocus ()
 
virtual bool isModalFocused () const
 
virtual bool isModalMouseInputFocused () const
 
const std::list< MouseListener * > & getMouseListeners () const A_CONST
 
const std::list< KeyListener * > & getKeyListeners () const A_CONST
 
const std::list< FocusListener * > & getFocusListeners () const A_CONST
 
virtual FocusHandlergetInternalFocusHandler ()
 
void setInternalFocusHandler (FocusHandler *const internalFocusHandler)
 
void setId (const std::string &id)
 
const std::string & getId () const
 
virtual void showPart (const Rect &rectangle)
 
bool isAllowLogic () const
 
void setMouseConsume (const bool b)
 
bool isMouseConsume () const
 
void setRedraw (const bool b)
 
virtual bool isSelectable () const
 
void setSelectable (const bool selectable)
 
void windowResized ()
 
- Public Member Functions inherited from Widget2
virtual ~Widget2 ()
 
const ColorgetThemeColor (const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
 
const ColorgetThemeCharColor (const signed char c, bool &valid) const A_INLINE
 
virtual void setWidget2 (const Widget2 *const widget)
 
void setPalette (int palette)
 
void checkPalette ()
 
void setForegroundColor2 (const Color &color)
 
WidgetgetWindow () const
 
virtual void setWindow (Widget *const window)
 
- Public Member Functions inherited from WidgetDeathListener
virtual ~WidgetDeathListener ()
 
- Public Member Functions inherited from KeyListener
virtual ~KeyListener ()
 
virtual void keyReleased (KeyEvent &event)
 
- Public Member Functions inherited from MouseListener
virtual ~MouseListener ()
 
virtual void mouseEntered (MouseEvent &event)
 
virtual void mouseExited (MouseEvent &event)
 
virtual void mouseReleased (MouseEvent &event)
 
virtual void mouseClicked (MouseEvent &event)
 
virtual void mouseWheelMovedUp (MouseEvent &event)
 
virtual void mouseWheelMovedDown (MouseEvent &event)
 
virtual void mouseMoved (MouseEvent &event)
 
virtual void mouseDragged (MouseEvent &event)
 
- Public Member Functions inherited from WidgetListener
virtual ~WidgetListener ()
 
virtual void widgetMoved (const Event &event)
 
virtual void widgetHidden (const Event &event)
 
virtual void widgetShown (const Event &event)
 

Private Types

typedef std::vector< std::pair< Tab *, Widget * > > TabContainer
 

Private Member Functions

void updateArrowEnableState ()
 
void updateTabsWidth ()
 
void updateVisibleTabsWidth ()
 

Private Attributes

ButtonmArrowButton [2]
 
TabmSelectedTab
 
BasicContainer2mTabContainer
 
BasicContainer2mWidgetContainer
 
std::vector< Tab * > mTabsToDelete
 
TabContainer mTabs
 
int mTabsWidth
 
int mVisibleTabsWidth
 
unsigned int mTabScrollIndex
 
int mRightMargin
 
Opaque mOpaque
 
bool mEnableScrollButtons
 
bool mFollowDownScroll
 
bool mBlockSwitching
 
bool mResizeHeight
 

Additional Inherited Members

- Static Public Member Functions inherited from Widget
static void setGlobalFont (Font *const font)
 
static FontgetGloablFont ()
 
static void cleanGlobalFont ()
 
static bool widgetExists (const Widget *const widget)
 
static void distributeWindowResizeEvent ()
 
static WidgetcallPostInit (Widget *const widget)
 
- Data Fields inherited from Widget
Visible mVisible
 
- Protected Types inherited from BasicContainer
typedef std::vector< Widget * > WidgetList
 
typedef WidgetList::iterator WidgetListIterator
 
typedef WidgetList::const_iterator WidgetListConstIterator
 
typedef WidgetList::reverse_iterator WidgetListReverseIterator
 
typedef WidgetList::const_reverse_iterator WidgetListCReverseIterator
 
- Protected Types inherited from Widget
typedef std::list< MouseListener * > MouseListenerList
 
typedef MouseListenerList::iterator MouseListenerIterator
 
typedef std::list< KeyListener * > KeyListenerList
 
typedef KeyListenerList::iterator KeyListenerIterator
 
typedef std::list< ActionListener * > ActionListenerList
 
typedef ActionListenerList::iterator ActionListenerIterator
 
typedef std::list< WidgetDeathListener * > WidgetDeathListenerList
 
typedef WidgetDeathListenerList::iterator WidgetDeathListenerIterator
 
typedef std::list< FocusListener * > FocusListenerList
 
typedef FocusListenerList::iterator FocusListenerIterator
 
typedef std::list< WidgetListener * > WidgetListenerList
 
typedef WidgetListenerList::iterator WidgetListenerIterator
 
- Protected Member Functions inherited from ActionListener
 ActionListener ()
 
- Protected Member Functions inherited from BasicContainer
virtual void drawChildren (Graphics *const graphics)
 
virtual void safeDrawChildren (Graphics *const graphics)
 
virtual void logicChildren ()
 
- Protected Member Functions inherited from Widget
void distributeActionEvent ()
 
void distributeResizedEvent ()
 
void distributeMovedEvent ()
 
void distributeHiddenEvent ()
 
void distributeShownEvent ()
 
- Protected Member Functions inherited from Widget2
 Widget2 (const Widget2 *const widget)
 
- Protected Member Functions inherited from WidgetDeathListener
 WidgetDeathListener ()
 
- Protected Member Functions inherited from KeyListener
 KeyListener ()
 
- Protected Member Functions inherited from MouseListener
 MouseListener ()
 
- Protected Member Functions inherited from WidgetListener
 WidgetListener ()
 
- Protected Attributes inherited from BasicContainer
WidgetList mWidgets
 
WidgetList mLogicWidgets
 
- Protected Attributes inherited from Widget
MouseListenerList mMouseListeners
 
KeyListenerList mKeyListeners
 
ActionListenerList mActionListeners
 
WidgetDeathListenerList mDeathListeners
 
FocusListenerList mFocusListeners
 
WidgetListenerList mWidgetListeners
 
Color mForegroundColor
 
Color mBackgroundColor
 
Color mBaseColor
 
Rect mDimension
 
std::string mActionEventId
 
std::string mId
 
FocusHandlermFocusHandler
 
FocusHandlermInternalFocusHandler
 
WidgetmParent
 
FontmCurrentFont
 
unsigned int mFrameSize
 
bool mFocusable
 
bool mTabIn
 
bool mTabOut
 
bool mEnabled
 
bool mAllowLogic
 
bool mMouseConsume
 
bool mRedraw
 
bool mSelectable
 
- Protected Attributes inherited from Widget2
int mPaletteOffset
 
WidgetmWindow
 
Color mForegroundColor2
 
- Static Protected Attributes inherited from Widget
static FontmGlobalFont = 0
 

Detailed Description

A tabbed area, the same as the guichan tabbed area in 0.8, but extended

Definition at line 85 of file tabbedarea.h.

Member Typedef Documentation

◆ TabContainer

typedef std::vector<std::pair<Tab*, Widget*> > TabbedArea::TabContainer
private

Definition at line 248 of file tabbedarea.h.

Constructor & Destructor Documentation

◆ TabbedArea()

TabbedArea::TabbedArea ( const Widget2 *const  widget)
explicit

Constructor.

Definition at line 80 of file tabbedarea.cpp.

80  :
82  BasicContainer(widget),
83  KeyListener(),
84  MouseListener(),
86  mArrowButton(),
87  mSelectedTab(nullptr),
88  mTabContainer(new BasicContainer2(widget)),
89  mWidgetContainer(new BasicContainer2(widget)),
90  mTabsToDelete(),
91  mTabs(),
92  mTabsWidth(0),
94  mTabScrollIndex(0),
95  mRightMargin(0),
97  mEnableScrollButtons(false),
98  mFollowDownScroll(false),
99  mBlockSwitching(true),
100  mResizeHeight(true)
101 {
102  setFocusable(true);
103  addKeyListener(this);
104  addMouseListener(this);
105 }
bool mFollowDownScroll
Definition: tabbedarea.h:295
int mVisibleTabsWidth
Definition: tabbedarea.h:282
TabContainer mTabs
Definition: tabbedarea.h:266
std::vector< Tab * > mTabsToDelete
Definition: tabbedarea.h:265
BasicContainer2 * mWidgetContainer
Definition: tabbedarea.h:264
Opaque mOpaque
Definition: tabbedarea.h:293
unsigned int mTabScrollIndex
Definition: tabbedarea.h:290
int mTabsWidth
Definition: tabbedarea.h:271
int mRightMargin
Definition: tabbedarea.h:291
bool mEnableScrollButtons
Definition: tabbedarea.h:294
BasicContainer2 * mTabContainer
Definition: tabbedarea.h:263
bool mBlockSwitching
Definition: tabbedarea.h:296
Button * mArrowButton[2]
Definition: tabbedarea.h:251
bool mResizeHeight
Definition: tabbedarea.h:297
Tab * mSelectedTab
Definition: tabbedarea.h:262
void setFocusable(const bool focusable)
Definition: widget.cpp:192
void addMouseListener(MouseListener *const mouseListener)
Definition: widget.cpp:292
void addKeyListener(KeyListener *const keyListener)
Definition: widget.cpp:272
friend class BasicContainer
Definition: widget.h:101
const bool Opaque_false
Definition: opaque.h:30

References Widget::addKeyListener(), Widget::addMouseListener(), and Widget::setFocusable().

◆ ~TabbedArea()

TabbedArea::~TabbedArea ( )

Definition at line 131 of file tabbedarea.cpp.

132 {
133  if (gui != nullptr)
134  gui->removeDragged(this);
135 
136  // +++ virtual method calls
139 
142 
143  for (size_t i = 0, sz = mTabsToDelete.size(); i < sz; i++)
145 
148 }
virtual void remove(Widget *const widget)
void removeDragged(const Widget *const widget)
Definition: gui.cpp:1162
#define delete2(var)
Definition: delete2.h:25
Gui * gui
Definition: gui.cpp:111

References delete2, gui, mArrowButton, mTabContainer, mTabsToDelete, mWidgetContainer, BasicContainer::remove(), and Gui::removeDragged().

Member Function Documentation

◆ action()

void TabbedArea::action ( const ActionEvent actionEvent)
virtual

Called when an action is recieved from a widget. It is used to be able to recieve a notification that an action has occured.

Parameters
actionEventThe event of the action.

Implements ActionListener.

Definition at line 649 of file tabbedarea.cpp.

650 {
651  Widget *const source = actionEvent.getSource();
652  Tab *const tab = dynamic_cast<Tab *>(source);
653 
654  if (tab != nullptr)
655  {
656  setSelectedTab(tab);
657  }
658  else
659  {
660  const std::string &eventId = actionEvent.getId();
661  if (eventId == "shift_left")
662  {
663  if (mTabScrollIndex != 0U)
664  --mTabScrollIndex;
665  }
666  else if (eventId == "shift_right")
667  {
668  if (CAST_SIZE(mTabScrollIndex) < mTabs.size() - 1)
669  ++mTabScrollIndex;
670  }
673  }
674 }
#define CAST_SIZE
Definition: cast.h:34
const std::string & getId() const
Definition: actionevent.h:122
Widget * getSource() const
Definition: event.h:104
Definition: tab.h:88
void setSelectedTab(Tab *const tab)
Definition: tabbedarea.cpp:407
void adjustTabPositions()
Definition: tabbedarea.cpp:606
void updateArrowEnableState()
Definition: tabbedarea.cpp:676
Definition: widget.h:99

References adjustTabPositions(), CAST_SIZE, ActionEvent::getId(), Event::getSource(), mTabs, mTabScrollIndex, setSelectedTab(), and updateArrowEnableState().

◆ addTab() [1/3]

void TabbedArea::addTab ( const std::string &  caption,
Widget *const  widget 
)

Definition at line 274 of file tabbedarea.cpp.

275 {
276  Tab *const tab = new Tab(this);
277  tab->setCaption(caption);
278  mTabsToDelete.push_back(tab);
279 
280  addTab(tab, widget);
281 }
void setCaption(const std::string &caption)
Definition: tab.cpp:458
void addTab(Tab *const tab, Widget *const widget)
Definition: tabbedarea.cpp:238

References addTab(), mTabsToDelete, and Tab::setCaption().

◆ addTab() [2/3]

void TabbedArea::addTab ( Image *const  image,
Widget *const  widget 
)

Definition at line 283 of file tabbedarea.cpp.

284 {
285  Tab *const tab = new Tab(this);
286  tab->setImage(image);
287  mTabsToDelete.push_back(tab);
288 
289  addTab(tab, widget);
290 }
void setImage(Image *const image)
Definition: tab.cpp:465

References addTab(), mTabsToDelete, and Tab::setImage().

◆ addTab() [3/3]

void TabbedArea::addTab ( Tab *const  tab,
Widget *const  widget 
)

Add a tab. Overridden since it needs to size the widget.

Parameters
tabThe tab widget for the tab.
widgetThe widget to view when the tab is selected.

Definition at line 238 of file tabbedarea.cpp.

240 {
241  if ((tab == nullptr) || (widget == nullptr))
242  return;
243 
244  tab->setTabbedArea(this);
245  tab->addActionListener(this);
246 
247  mTabContainer->add(tab);
248  mTabs.push_back(std::pair<Tab*, Widget*>(tab, widget));
249 
250  if ((mSelectedTab == nullptr) && tab->mVisible == Visible_true)
251  setSelectedTab(tab);
252 
254  adjustSize();
255 
256  const int frameSize = 2 * mFrameSize;
257  widget->setSize(getWidth() - frameSize,
258  getHeight() - frameSize - mTabContainer->getHeight());
259 
260  widgetResized(Event(nullptr));
261  updateTabsWidth();
263 }
virtual void add(Widget *const widget)
Definition: event.h:79
void setTabbedArea(TabbedArea *tabbedArea)
Definition: tab.cpp:448
void adjustSize()
Definition: tabbedarea.cpp:569
void updateTabsWidth()
Definition: tabbedarea.cpp:545
void widgetResized(const Event &event)
Definition: tabbedarea.cpp:474
void setSize(const int width, const int height)
Definition: widget.cpp:367
unsigned int mFrameSize
Definition: widget.h:1138
Visible mVisible
Definition: widget.h:963
void addActionListener(ActionListener *const actionListener)
Definition: widget.cpp:252
int getHeight() const
Definition: widget.h:240
int getWidth() const
Definition: widget.h:221
const bool Visible_true
Definition: visible.h:30

References BasicContainer2::add(), Widget::addActionListener(), adjustSize(), adjustTabPositions(), Widget::getHeight(), Widget::getWidth(), Widget::mFrameSize, mSelectedTab, mTabContainer, mTabs, Widget::mVisible, setSelectedTab(), Widget::setSize(), Tab::setTabbedArea(), updateArrowEnableState(), updateTabsWidth(), Visible_true, and widgetResized().

Referenced by SkillDialog::addDefaultTab(), ChatWindow::addTab(), addTab(), StatusWindow::addTab(), ShortcutWindow::addTab(), SocialWindow::addTab(), StatusWindow::addTabBasic(), ClanWindow::ClanWindow(), DebugWindow::DebugWindow(), SetupWindow::externalUpdate(), SkillDialog::loadXmlFile(), EmoteWindow::postInit(), SetupWindow::postInit(), and SocialWindow::postInit().

◆ adjustSize()

void TabbedArea::adjustSize ( )

Definition at line 569 of file tabbedarea.cpp.

570 {
571  int maxTabHeight = 0;
572 
573  const int width = mDimension.width;
574  const int height = mDimension.height;
575 
576  for (size_t i = 0, sz = mTabs.size(); i < sz; i++)
577  {
578  if (mTabs[i].first->getHeight() > maxTabHeight)
579  maxTabHeight = mTabs[i].first->getHeight();
580  }
581 
582  mTabContainer->setSize(width - mRightMargin, maxTabHeight);
583 
584  mWidgetContainer->setPosition(0, maxTabHeight);
585  mWidgetContainer->setSize(width, height - maxTabHeight);
586  Widget *const w = getCurrentWidget();
587  if (w != nullptr)
588  {
589  const int wFrameSize = w->getFrameSize();
590  const int frame2 = 2 * wFrameSize;
591 
592  w->setPosition(wFrameSize, wFrameSize);
593  if (mResizeHeight)
594  {
595  w->setSize(mWidgetContainer->getWidth() - frame2,
596  mWidgetContainer->getHeight() - frame2);
597  }
598  else
599  {
600  w->setSize(mWidgetContainer->getWidth() - frame2,
601  w->getHeight());
602  }
603  }
604 }
int width
Definition: rect.h:219
int height
Definition: rect.h:224
Widget * getCurrentWidget() const
Definition: tabbedarea.cpp:229
unsigned int getFrameSize() const
Definition: widget.h:184
Rect mDimension
Definition: widget.h:1101
void setPosition(const int x, const int y)
Definition: widget.cpp:161

References getCurrentWidget(), Widget::getFrameSize(), Widget::getHeight(), Widget::getWidth(), Rect::height, Widget::mDimension, mResizeHeight, mRightMargin, mTabContainer, mTabs, mWidgetContainer, Widget::setPosition(), Widget::setSize(), and Rect::width.

Referenced by addTab(), StatusWindow::addTabs(), ChatWindow::adjustTabSize(), removeTab(), setDimension(), setHeight(), setSize(), setWidth(), widgetResized(), SkillDialog::widgetResized(), and SocialWindow::widgetResized().

◆ adjustTabPositions()

void TabbedArea::adjustTabPositions ( )

Definition at line 606 of file tabbedarea.cpp.

607 {
608  int maxTabHeight = 0;
609  const size_t sz = mTabs.size();
610  for (size_t i = 0; i < sz; ++i)
611  {
612  const Tab *const tab = mTabs[i].first;
613  if ((tab != nullptr) &&
614  tab->mVisible == Visible_true &&
615  tab->getHeight() > maxTabHeight)
616  {
617  maxTabHeight = tab->getHeight();
618  }
619  }
620 
621  unsigned int x = (mEnableScrollButtons &&
623  mArrowButton[0]->getWidth() : 0U;
624  for (size_t i = mTabScrollIndex; i < sz; ++i)
625  {
626  Tab *const tab = mTabs[i].first;
627  if ((tab == nullptr) || tab->mVisible == Visible_false)
628  continue;
629  tab->setPosition(x, maxTabHeight - tab->getHeight());
630  x += tab->getWidth();
631  }
632 
633  // If the tabs are scrolled, we hide them away.
634  if (mTabScrollIndex > 0)
635  {
636  x = 0;
637  for (unsigned i = 0; i < mTabScrollIndex; ++i)
638  {
639  Tab *const tab = mTabs[i].first;
640  if ((tab != nullptr) && tab->mVisible == Visible_true)
641  {
642  x -= tab->getWidth();
643  tab->setPosition(x, maxTabHeight - tab->getHeight());
644  }
645  }
646  }
647 }
const bool Visible_false
Definition: visible.h:30

References Widget::getHeight(), Widget::getWidth(), mArrowButton, mEnableScrollButtons, mTabs, mTabScrollIndex, Widget::mVisible, Widget::setPosition(), Visible_false, Visible_true, and x.

Referenced by action(), SkillDialog::addDefaultTab(), SkillDialog::addSkill(), addTab(), Tab::adjustSize(), SkillDialog::updateSkill(), and widgetResized().

◆ adjustWidget()

void TabbedArea::adjustWidget ( Widget *const  widget) const

Definition at line 265 of file tabbedarea.cpp.

266 {
267  if (widget == nullptr)
268  return;
269  const int frameSize = 2 * mFrameSize;
270  widget->setSize(getWidth() - frameSize,
271  getHeight() - frameSize - mTabContainer->getHeight());
272 }

References Widget::getHeight(), Widget::getWidth(), Widget::mFrameSize, mTabContainer, and Widget::setSize().

Referenced by EmoteWindow::widgetResized().

◆ death()

void TabbedArea::death ( const Event event)
virtual

Called when a widget dies. It is used to be able to recieve a notification when a death of a widget occurs.

Parameters
eventThe event of the death.

Reimplemented from BasicContainer.

Definition at line 809 of file tabbedarea.cpp.

810 {
811  Tab *const tab = dynamic_cast<Tab*>(event.getSource());
812 
813  if (tab != nullptr)
814  removeTab(tab);
815  else
816  BasicContainer::death(event);
817 }
void death(const Event &event)
void removeTab(Tab *const tab)
Definition: tabbedarea.cpp:323

References BasicContainer::death(), and removeTab().

◆ draw()

void TabbedArea::draw ( Graphics *const  graphics)
virtual

Draw the tabbed area.

Implements Widget.

Definition at line 188 of file tabbedarea.cpp.

189 {
190  BLOCK_START("TabbedArea::draw")
191  if (mTabs.empty())
192  {
193  BLOCK_END("TabbedArea::draw")
194  return;
195  }
196 
197  drawChildren(graphics);
199 }
virtual void drawChildren(Graphics *const graphics)
void draw(Graphics *const graphics)
Definition: tabbedarea.cpp:188
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:80
#define BLOCK_START(name)
Definition: perfomance.h:79
std::string empty
Definition: podict.cpp:26

References BLOCK_END, BLOCK_START, BasicContainer::drawChildren(), and mTabs.

◆ enableScrollButtons()

void TabbedArea::enableScrollButtons ( const bool  enable)

Definition at line 150 of file tabbedarea.cpp.

151 {
152  if (mEnableScrollButtons && !enable)
153  {
154  if (mArrowButton[0] != nullptr)
155  remove(mArrowButton[0]);
156  if (mArrowButton[1] != nullptr)
157  remove(mArrowButton[1]);
158  }
159  else if (!mEnableScrollButtons && enable)
160  {
161  if (mArrowButton[0] != nullptr)
162  add(mArrowButton[0]);
163  if (mArrowButton[1] != nullptr)
164  add(mArrowButton[1]);
165  }
166  mEnableScrollButtons = enable;
167 }
void add(Widget *const widget)

References BasicContainer::add(), mArrowButton, mEnableScrollButtons, and BasicContainer::remove().

Referenced by ChatWindow::ChatWindow(), and SetupWindow::postInit().

◆ getContainerHeight()

int TabbedArea::getContainerHeight ( ) const
inline

Definition at line 164 of file tabbedarea.h.

165  { return mWidgetContainer->getHeight(); }

References Widget::getHeight(), and mWidgetContainer.

Referenced by ChatWindow::adjustTabSize().

◆ getCurrentWidget()

Widget * TabbedArea::getCurrentWidget ( ) const

Returns the widget for the current tab

Definition at line 229 of file tabbedarea.cpp.

230 {
231  const Tab *const tab = getSelectedTab();
232 
233  if (tab != nullptr)
234  return getWidget(tab->getCaption());
235  return nullptr;
236 }
const std::string & getCaption() const
Definition: tab.cpp:473
Tab * getSelectedTab() const
Definition: tabbedarea.h:175
Widget * getWidget(const std::string &name) const
Definition: tabbedarea.cpp:214

References Tab::getCaption(), getSelectedTab(), and getWidget().

Referenced by adjustSize(), ShortcutWindow::widgetHidden(), and widgetResized().

◆ getFollowDownScroll()

bool TabbedArea::getFollowDownScroll ( ) const
inline

Definition at line 214 of file tabbedarea.h.

215  { return mFollowDownScroll; }

References mFollowDownScroll.

◆ getNumberOfTabs()

int TabbedArea::getNumberOfTabs ( ) const

Return how many tabs have been created.

Definition at line 169 of file tabbedarea.cpp.

170 {
171  return CAST_S32(mTabs.size());
172 }
#define CAST_S32
Definition: cast.h:30

References CAST_S32, and mTabs.

Referenced by ChatWindow::nextTab(), ChatWindow::prevTab(), removeAll(), and ChatWindow::selectTabByType().

◆ getRightMargin()

int TabbedArea::getRightMargin ( ) const
inline

Definition at line 208 of file tabbedarea.h.

209  { return mRightMargin; }

References mRightMargin.

◆ getSelectedTab()

Tab* TabbedArea::getSelectedTab ( ) const
inline

◆ getSelectedTabIndex()

int TabbedArea::getSelectedTabIndex ( ) const

Definition at line 449 of file tabbedarea.cpp.

450 {
451  for (unsigned int i = 0, fsz = CAST_U32(mTabs.size());
452  i < fsz;
453  i++)
454  {
455  if (mTabs[i].first == mSelectedTab)
456  return i;
457  }
458 
459  return -1;
460 }
#define CAST_U32
Definition: cast.h:31

References CAST_U32, mSelectedTab, and mTabs.

Referenced by ChatWindow::closeTab(), ShortcutWindow::getTabIndex(), keyPressed(), ChatWindow::nextTab(), ChatWindow::prevTab(), removeAll(), removeTab(), selectNextTab(), selectPrevTab(), ClanWindow::slowLogic(), and DebugWindow::slowLogic().

◆ getTab()

Tab * TabbedArea::getTab ( const std::string &  name) const

Return tab with specified name as caption.

Definition at line 174 of file tabbedarea.cpp.

175 {
176  TabContainer::const_iterator itr = mTabs.begin();
177  const TabContainer::const_iterator itr_end = mTabs.end();
178  while (itr != itr_end)
179  {
180  if ((*itr).first->getCaption() == name)
181  return static_cast<Tab*>((*itr).first);
182 
183  ++itr;
184  }
185  return nullptr;
186 }

References mTabs.

Referenced by SetupWindow::unloadTab().

◆ getTabByIndex()

Tab * TabbedArea::getTabByIndex ( const int  index) const

Definition at line 716 of file tabbedarea.cpp.

717 {
718  if (index < 0 || index >= CAST_S32(mTabs.size()))
719  return nullptr;
720  return static_cast<Tab*>(mTabs[index].first);
721 }

References CAST_S32, and mTabs.

Referenced by ChatWindow::closeTab(), ChatWindow::joinRoom(), ChatWindow::selectTabByType(), and EmoteWindow::~EmoteWindow().

◆ getTabContainer()

Widget* TabbedArea::getTabContainer ( ) const
inline

◆ getWidget()

Widget * TabbedArea::getWidget ( const std::string &  name) const

Returns the widget with the tab that has specified caption

Definition at line 214 of file tabbedarea.cpp.

215 {
216  TabContainer::const_iterator itr = mTabs.begin();
217  const TabContainer::const_iterator itr_end = mTabs.end();
218  while (itr != itr_end)
219  {
220  if ((*itr).first->getCaption() == name)
221  return (*itr).second;
222 
223  ++itr;
224  }
225 
226  return nullptr;
227 }

References mTabs.

Referenced by getCurrentWidget().

◆ getWidgetByIndex()

Widget * TabbedArea::getWidgetByIndex ( const int  index) const

Definition at line 723 of file tabbedarea.cpp.

724 {
725  if (index < 0 || index >= CAST_S32(mTabs.size()))
726  return nullptr;
727  return mTabs[index].second;
728 }

References CAST_S32, and mTabs.

◆ getWidgetContainer()

Widget* TabbedArea::getWidgetContainer ( ) const
inline

◆ isOpaque()

bool TabbedArea::isOpaque ( ) const
inline

Definition at line 181 of file tabbedarea.h.

182  { return mOpaque == Opaque_true; }
const bool Opaque_true
Definition: opaque.h:30

References mOpaque, and Opaque_true.

◆ isTabPresent()

bool TabbedArea::isTabPresent ( const Tab *const  tab) const

Definition at line 300 of file tabbedarea.cpp.

301 {
302  FOR_EACH (TabContainer::const_iterator, it, mTabs)
303  {
304  if ((*it).first == tab || (*it).second == tab)
305  return true;
306  }
307  return false;
308 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:25

References FOR_EACH, and mTabs.

Referenced by ChatWindow::isTabPresent().

◆ isTabSelected() [1/2]

bool TabbedArea::isTabSelected ( const size_t  index) const

Definition at line 292 of file tabbedarea.cpp.

293 {
294  if (index >= mTabs.size())
295  return false;
296 
297  return mSelectedTab == mTabs[index].first;
298 }

References mSelectedTab, and mTabs.

Referenced by Tab::draw(), and Tab::safeDraw().

◆ isTabSelected() [2/2]

bool TabbedArea::isTabSelected ( const Tab *const  tab) const

Definition at line 310 of file tabbedarea.cpp.

311 {
312  return mSelectedTab == tab;
313 }

References mSelectedTab.

◆ keyPressed()

void TabbedArea::keyPressed ( KeyEvent event)
virtual

Called if a key is pressed when the widget has keyboard focus. If a key is held down the widget will generate multiple key presses.

Parameters
eventDiscribes the event.

Reimplemented from KeyListener.

Definition at line 778 of file tabbedarea.cpp.

779 {
780  if (mBlockSwitching || event.isConsumed() || !isFocused())
781  return;
782 
783  const InputActionT actionId = event.getActionId();
784 
785  if (actionId == InputAction::GUI_LEFT)
786  {
787  int index = getSelectedTabIndex();
788  index--;
789 
790  if (index < 0)
791  return;
792 
793  setSelectedTab(mTabs[index].first);
794  event.consume();
795  }
796  else if (actionId == InputAction::GUI_RIGHT)
797  {
798  int index = getSelectedTabIndex();
799  index++;
800 
801  if (index >= CAST_S32(mTabs.size()))
802  return;
803 
804  setSelectedTab(mTabs[index].first);
805  event.consume();
806  }
807 }
bool isConsumed() const
int getSelectedTabIndex() const
Definition: tabbedarea.cpp:449
virtual bool isFocused() const
Definition: widget.cpp:184
InputAction ::T InputActionT
Definition: inputaction.h:717

References CAST_S32, getSelectedTabIndex(), InputAction::GUI_LEFT, InputAction::GUI_RIGHT, InputGuiEvent::isConsumed(), Widget::isFocused(), mBlockSwitching, mTabs, and setSelectedTab().

◆ logic()

void TabbedArea::logic ( )
virtual

Overload the logic function since it's broken in guichan 0.8.

Reimplemented from BasicContainer.

Definition at line 380 of file tabbedarea.cpp.

381 {
382  BLOCK_START("TabbedArea::logic")
383  logicChildren();
385 }
virtual void logicChildren()
void logic()
Definition: tabbedarea.cpp:380

References BLOCK_END, BLOCK_START, and BasicContainer::logicChildren().

◆ mousePressed()

void TabbedArea::mousePressed ( MouseEvent event)
virtual

Called when a mouse button has been pressed on the widget area.

NOTE: A mouse press is NOT equal to a mouse click. Use mouseClickMessage to check for mouse clicks.

Parameters
eventDescribes the event.

Reimplemented from MouseListener.

Definition at line 387 of file tabbedarea.cpp.

388 {
389  if (event.isConsumed())
390  return;
391 
392  if (event.getButton() == MouseButton::LEFT)
393  {
394  Widget *const widget = mTabContainer->getWidgetAt(
395  event.getX(), event.getY());
396  Tab *const tab = dynamic_cast<Tab *>(widget);
397 
398  if (tab != nullptr)
399  {
400  event.consume();
401  setSelectedTab(tab);
402  requestFocus();
403  }
404  }
405 }
Widget * getWidgetAt(int x, int y)
MouseButtonT getButton() const
Definition: mouseevent.h:116
int getX() const
Definition: mouseevent.h:127
int getY() const
Definition: mouseevent.h:138
virtual void requestFocus()
Definition: widget.cpp:204

References MouseEvent::getButton(), BasicContainer::getWidgetAt(), MouseEvent::getX(), MouseEvent::getY(), InputGuiEvent::isConsumed(), MouseButton::LEFT, mTabContainer, Widget::requestFocus(), and setSelectedTab().

◆ postInit()

void TabbedArea::postInit ( )
virtual

Reimplemented from Widget.

Definition at line 107 of file tabbedarea.cpp.

108 {
110 
113 
115  addWidgetListener(this);
116 
117  mArrowButton[0] = new Button(this,
118  "<",
119  "shift_left",
120  BUTTON_SKIN,
121  this);
122  mArrowButton[1] = new Button(this,
123  ">",
124  "shift_right",
125  BUTTON_SKIN,
126  this);
127 
128  widgetResized(Event(nullptr));
129 }
const std::string BUTTON_SKIN
Definition: button.h:89
void setOpaque(Opaque opaque)
Definition: button.h:102
void addWidgetListener(WidgetListener *const widgetListener)
Definition: widget.cpp:302

References BasicContainer::add(), Widget::addWidgetListener(), BUTTON_SKIN, mArrowButton, mTabContainer, mWidgetContainer, Opaque_false, BasicContainer2::setOpaque(), and widgetResized().

◆ removeAll()

void TabbedArea::removeAll ( const bool  del)

Definition at line 730 of file tabbedarea.cpp.

731 {
732  if (getSelectedTabIndex() != -1)
733  {
735  }
736  while (getNumberOfTabs() > 0)
737  {
738  const int idx = getNumberOfTabs() - 1;
739  Tab *tab = mTabs[idx].first;
740  Widget *widget = mTabs[idx].second;
741  removeTab(tab);
742  if (del)
743  {
744  delete tab;
745  delete widget;
746  }
747  }
748 }
int getNumberOfTabs() const
Definition: tabbedarea.cpp:169
void setSelectedTabByIndex(const size_t index)
Definition: tabbedarea.cpp:315

References CAST_U32, getNumberOfTabs(), getSelectedTabIndex(), mTabs, removeTab(), and setSelectedTabByIndex().

Referenced by SkillDialog::clearSkills(), EmoteWindow::~EmoteWindow(), and ShortcutWindow::~ShortcutWindow().

◆ removeTab()

void TabbedArea::removeTab ( Tab *const  tab)

Overload the remove tab function as it's broken in guichan 0.8.

Definition at line 323 of file tabbedarea.cpp.

324 {
325  int tabIndexToBeSelected = -1;
326 
327  if (tab == mSelectedTab)
328  {
329  const int index = getSelectedTabIndex();
330  const size_t sz = mTabs.size();
331  if (index == CAST_S32(sz) - 1 && sz == 1)
332  tabIndexToBeSelected = -1;
333  else
334  tabIndexToBeSelected = index - 1;
335  }
336 
337  for (TabContainer::iterator iter = mTabs.begin();
338  iter != mTabs.end(); ++iter)
339  {
340  if (iter->first == tab)
341  {
342  mTabContainer->remove(tab);
343  mTabs.erase(iter);
344  break;
345  }
346  }
347 
348  for (STD_VECTOR<Tab*>::iterator iter2 = mTabsToDelete.begin();
349  iter2 != mTabsToDelete.end(); ++iter2)
350  {
351  if (*iter2 == tab)
352  {
353  mTabsToDelete.erase(iter2);
354  delete tab;
355  break;
356  }
357  }
358 
359  const int tabsSize = CAST_S32(mTabs.size());
360  if (tabIndexToBeSelected >= tabsSize)
361  tabIndexToBeSelected = tabsSize - 1;
362  if (tabIndexToBeSelected < -1)
363  tabIndexToBeSelected = -1;
364 
365  if (tabIndexToBeSelected == -1)
366  {
367  mSelectedTab = nullptr;
369  }
370  else
371  {
372  setSelectedTabByIndex(tabIndexToBeSelected);
373  }
374 
375  adjustSize();
376  updateTabsWidth();
377  widgetResized(Event(nullptr));
378 }
virtual void clear()

References adjustSize(), CAST_S32, BasicContainer::clear(), getSelectedTabIndex(), mSelectedTab, mTabContainer, mTabs, mTabsToDelete, mWidgetContainer, BasicContainer::remove(), setSelectedTabByIndex(), updateTabsWidth(), and widgetResized().

Referenced by death(), removeAll(), ChatWindow::removeTab(), SocialWindow::removeTab(), SetupWindow::unloadTab(), and EmoteWindow::~EmoteWindow().

◆ safeDraw()

void TabbedArea::safeDraw ( Graphics *const  graphics)
virtual

Implements Widget.

Definition at line 201 of file tabbedarea.cpp.

202 {
203  BLOCK_START("TabbedArea::draw")
204  if (mTabs.empty())
205  {
206  BLOCK_END("TabbedArea::draw")
207  return;
208  }
209 
210  safeDrawChildren(graphics);
212 }
virtual void safeDrawChildren(Graphics *const graphics)

References BLOCK_END, BLOCK_START, mTabs, and BasicContainer::safeDrawChildren().

◆ selectNextTab()

void TabbedArea::selectNextTab ( )

Definition at line 819 of file tabbedarea.cpp.

820 {
821  int tab = getSelectedTabIndex();
822  tab++;
823  if (tab == CAST_S32(mTabs.size()))
824  tab = 0;
825  setSelectedTab(mTabs[tab].first);
826 }

References CAST_S32, getSelectedTabIndex(), mTabs, and setSelectedTab().

Referenced by ShortcutWindow::nextTab(), and SocialWindow::nextTab().

◆ selectPrevTab()

void TabbedArea::selectPrevTab ( )

Definition at line 828 of file tabbedarea.cpp.

829 {
830  int tab = getSelectedTabIndex();
831 
832  if (tab == 0)
833  tab = CAST_S32(mTabs.size());
834  if (tab < 0)
835  return;
836  tab--;
837  setSelectedTab(mTabs[tab].first);
838 }

References CAST_S32, getSelectedTabIndex(), mTabs, and setSelectedTab().

Referenced by ShortcutWindow::prevTab(), and SocialWindow::prevTab().

◆ setBlockSwitching()

void TabbedArea::setBlockSwitching ( const bool  b)
inline

Definition at line 219 of file tabbedarea.h.

220  { mBlockSwitching = b; }

References mBlockSwitching.

◆ setDimension()

void TabbedArea::setDimension ( const Rect dimension)

Definition at line 771 of file tabbedarea.cpp.

772 {
773  // +++ need use virtual
774  Widget::setDimension(dimension);
775  adjustSize();
776 }
void setDimension(const Rect &dimension)
Definition: widget.cpp:169

References adjustSize(), and Widget::setDimension().

Referenced by ClanWindow::ClanWindow(), DebugWindow::DebugWindow(), SetupWindow::postInit(), ClanWindow::widgetResized(), DebugWindow::widgetResized(), and SetupWindow::widgetResized().

◆ setFollowDownScroll()

void TabbedArea::setFollowDownScroll ( const bool  n)
inline

Definition at line 211 of file tabbedarea.h.

212  { mFollowDownScroll = n; }

References mFollowDownScroll.

Referenced by ChatWindow::ChatWindow().

◆ setHeight()

void TabbedArea::setHeight ( int  height)

Definition at line 757 of file tabbedarea.cpp.

758 {
759  // +++ need use virtual
760  Widget::setHeight(height);
761  adjustSize();
762 }
void setHeight(const int height)
Definition: widget.cpp:140

References adjustSize(), and Widget::setHeight().

Referenced by ChatWindow::adjustTabSize(), and EmoteWindow::postInit().

◆ setOpaque()

void TabbedArea::setOpaque ( const Opaque  opaque)
inline

Definition at line 178 of file tabbedarea.h.

179  { mOpaque = opaque; }

References mOpaque.

◆ setResizeHeight()

void TabbedArea::setResizeHeight ( bool  b)
inline

Definition at line 232 of file tabbedarea.h.

233  { mResizeHeight = b; }

References mResizeHeight.

Referenced by ChatWindow::ChatWindow().

◆ setRightMargin()

void TabbedArea::setRightMargin ( const int  n)
inline

Definition at line 205 of file tabbedarea.h.

206  { mRightMargin = n; }

References mRightMargin.

Referenced by ChatWindow::updateTabsMargin().

◆ setSelectedTab()

void TabbedArea::setSelectedTab ( Tab *const  tab)

Definition at line 407 of file tabbedarea.cpp.

408 {
409  for (size_t i = 0; i < mTabs.size(); i++)
410  {
411  if (mTabs[i].first == mSelectedTab)
412  mWidgetContainer->remove(mTabs[i].second);
413  }
414 
415  for (size_t i = 0; i < mTabs.size(); i++)
416  {
417  if (mTabs[i].first == tab)
418  {
419  mSelectedTab = tab;
420  mWidgetContainer->add(mTabs[i].second);
421  }
422  }
423 
424  Tab *const newTab = tab;
425 
426  if (newTab != nullptr)
427  newTab->setCurrent();
428 
429  widgetResized(Event(nullptr));
430 }
virtual void setCurrent()
Definition: tab.h:211

References BasicContainer2::add(), mSelectedTab, mTabs, mWidgetContainer, BasicContainer::remove(), Tab::setCurrent(), and widgetResized().

Referenced by action(), ChatWindow::addChannelTab(), ChatWindow::addSpecialChannelTab(), addTab(), ChatWindow::addWhisperTab(), keyPressed(), mousePressed(), selectNextTab(), selectPrevTab(), ChatWindow::selectTabByType(), setSelectedTabByIndex(), setSelectedTabByName(), and setSelectedTabDefault().

◆ setSelectedTabByIndex()

void TabbedArea::setSelectedTabByIndex ( const size_t  index)

Definition at line 315 of file tabbedarea.cpp.

316 {
317  if (index >= mTabs.size())
318  return;
319 
320  setSelectedTab(mTabs[index].first);
321 }

References mTabs, and setSelectedTab().

Referenced by ChatWindow::defaultTab(), ChatWindow::nextTab(), ChatWindow::prevTab(), removeAll(), and removeTab().

◆ setSelectedTabByName()

void TabbedArea::setSelectedTabByName ( const std::string &  name)

Definition at line 462 of file tabbedarea.cpp.

463 {
464  FOR_EACH (TabContainer::const_iterator, itr, mTabs)
465  {
466  if (((*itr).first != nullptr) && (*itr).first->getCaption() == name)
467  {
468  setSelectedTab((*itr).first);
469  return;
470  }
471  }
472 }

References FOR_EACH, mTabs, and setSelectedTab().

Referenced by SetupWindow::activateTab().

◆ setSelectedTabDefault()

void TabbedArea::setSelectedTabDefault ( )

Definition at line 432 of file tabbedarea.cpp.

433 {
434  if (mSelectedTab == nullptr ||
436  {
437  for (size_t i = 0; i < mTabs.size(); i++)
438  {
439  Tab *const tab = mTabs[i].first;
440  if ((tab != nullptr) && tab->mVisible == Visible_true)
441  {
442  setSelectedTab(tab);
443  return;
444  }
445  }
446  }
447 }

References mSelectedTab, mTabs, Widget::mVisible, setSelectedTab(), Visible_false, and Visible_true.

Referenced by SkillDialog::addDefaultTab(), SkillDialog::addSkill(), and SkillDialog::updateSkill().

◆ setSize()

void TabbedArea::setSize ( int  width,
int  height 
)

Definition at line 764 of file tabbedarea.cpp.

765 {
766  // +++ need use virtual
767  Widget::setSize(width, height);
768  adjustSize();
769 }

References adjustSize(), and Widget::setSize().

Referenced by EmoteWindow::widgetResized().

◆ setWidth()

void TabbedArea::setWidth ( int  width)

Definition at line 750 of file tabbedarea.cpp.

751 {
752  // +++ need use virtual
753  Widget::setWidth(width);
754  adjustSize();
755 }
void setWidth(const int width)
Definition: widget.cpp:133

References adjustSize(), and Widget::setWidth().

Referenced by ChatWindow::adjustTabSize(), and EmoteWindow::postInit().

◆ updateArrowEnableState()

void TabbedArea::updateArrowEnableState ( )
private

Check whether the arrow should be clickable

Definition at line 676 of file tabbedarea.cpp.

677 {
678  updateTabsWidth();
679  if ((mArrowButton[0] == nullptr) || (mArrowButton[1] == nullptr))
680  return;
681 
682  const int width = mDimension.width;
683  if (mTabsWidth > width - 4
684  - mArrowButton[0]->getWidth()
686  {
689  }
690  else
691  {
694  mTabScrollIndex = 0;
695  }
696 
697  // Left arrow consistency check
698  if (mTabScrollIndex == 0U)
699  mArrowButton[0]->setEnabled(false);
700  else
701  mArrowButton[0]->setEnabled(true);
702 
703  // Right arrow consistency check
704  if (mVisibleTabsWidth < width - 4
705  - mArrowButton[0]->getWidth()
707  {
708  mArrowButton[1]->setEnabled(false);
709  }
710  else
711  {
712  mArrowButton[1]->setEnabled(true);
713  }
714 }
void setVisible(Visible visible)
Definition: widget.cpp:225
void setEnabled(const bool enabled)
Definition: widget.h:352

References Widget::getWidth(), mArrowButton, Widget::mDimension, mRightMargin, mTabScrollIndex, mTabsWidth, mVisibleTabsWidth, Widget::setEnabled(), Widget::setVisible(), updateTabsWidth(), Visible_false, Visible_true, and Rect::width.

Referenced by action(), addTab(), and widgetResized().

◆ updateTabsWidth()

void TabbedArea::updateTabsWidth ( )
private

Update the overall width of all tab. Used to know whether the arrows have to be drawn or not.

Definition at line 545 of file tabbedarea.cpp.

546 {
547  mTabsWidth = 0;
548  FOR_EACH (TabContainer::const_iterator, itr, mTabs)
549  {
550  Tab *const tab = (*itr).first;
551  if ((tab != nullptr) && tab->mVisible == Visible_true)
552  mTabsWidth += tab->getWidth();
553  }
555 }
void updateVisibleTabsWidth()
Definition: tabbedarea.cpp:557

References FOR_EACH, Widget::getWidth(), mTabs, mTabsWidth, Widget::mVisible, updateVisibleTabsWidth(), and Visible_true.

Referenced by addTab(), removeTab(), and updateArrowEnableState().

◆ updateVisibleTabsWidth()

void TabbedArea::updateVisibleTabsWidth ( )
private

Update the overall width of visible tab. Used to know whether the arrows have to be enable or not.

Definition at line 557 of file tabbedarea.cpp.

558 {
559  unsigned int visibleTabsWidth = 0;
560  for (size_t i = mTabScrollIndex, sz = mTabs.size(); i < sz; ++i)
561  {
562  Tab *const tab = mTabs[i].first;
563  if (tab != nullptr && tab->mVisible == Visible_true)
564  visibleTabsWidth += CAST_S32(tab->getWidth());
565  }
566  mVisibleTabsWidth = visibleTabsWidth;
567 }

References CAST_S32, Widget::getWidth(), mTabs, mTabScrollIndex, Widget::mVisible, mVisibleTabsWidth, and Visible_true.

Referenced by updateTabsWidth().

◆ widgetResized()

void TabbedArea::widgetResized ( const Event event)
virtual

Invoked when a widget changes its size.

Parameters
eventDescribes the event.

Reimplemented from WidgetListener.

Definition at line 474 of file tabbedarea.cpp.

475 {
476  adjustSize();
477 
478  const int frameSize = 2 * mFrameSize;
479  const int widgetFrameSize = 2 * mWidgetContainer->getFrameSize();
480  const int w1 = mDimension.width;
481  const int h1 = mDimension.height;
482  const int height = h1 - frameSize
483  - mWidgetContainer->getY() - widgetFrameSize;
484 
485  Widget *const w = getCurrentWidget();
486  ScrollArea *const scr = dynamic_cast<ScrollArea *>(w);
487  if (scr != nullptr)
488  {
489  if (mFollowDownScroll && height != 0)
490  {
491  const Rect &rect = w->getDimension();
492  if (rect.height != 0 && rect.height > height + 2)
493  {
494  if (scr->getVerticalScrollAmount()
495  >= scr->getVerticalMaxScroll() - 2
496  && scr->getVerticalScrollAmount()
497  <= scr->getVerticalMaxScroll() + 2)
498  {
499  const int newScroll = scr->getVerticalScrollAmount()
500  + rect.height - height;
501  w->setSize(mWidgetContainer->getWidth() - frameSize,
502  mWidgetContainer->getHeight() - frameSize);
503  if (newScroll != 0)
504  scr->setVerticalScrollAmount(newScroll);
505  }
506  }
507  }
508  }
509 
510  if (mArrowButton[1] != nullptr)
511  {
512  // Check whether there is room to show more tabs now.
513  int innerWidth = w1 - 4 - mArrowButton[0]->getWidth()
515  if (innerWidth < 0)
516  innerWidth = 0;
517 
518  int newWidth = mVisibleTabsWidth;
519  while ((mTabScrollIndex != 0U) && newWidth < innerWidth)
520  {
521  Tab *const tab = mTabs[mTabScrollIndex - 1].first;
522  if ((tab != nullptr) && tab->mVisible == Visible_true)
523  {
524  newWidth += tab->getWidth();
525  if (newWidth < innerWidth)
526  --mTabScrollIndex;
527  }
528  }
529 
530  if (mArrowButton[1] != nullptr)
531  {
532  const int width = w1 - frameSize - widgetFrameSize;
533  // Move the right arrow to fit the windows content.
534  newWidth = width - mArrowButton[1]->getWidth() - mRightMargin;
535  if (newWidth < 0)
536  newWidth = 0;
537  mArrowButton[1]->setPosition(newWidth, 0);
538  }
539  }
540 
543 }
Definition: rect.h:74
void setVerticalScrollAmount(const int vScroll)
int getVerticalMaxScroll()
int getVerticalScrollAmount() const
Definition: scrollarea.h:274
const Rect & getDimension() const
Definition: widget.h:317
int getY() const
Definition: widget.h:288

References adjustSize(), adjustTabPositions(), getCurrentWidget(), Widget::getDimension(), Widget::getFrameSize(), Widget::getHeight(), ScrollArea::getVerticalMaxScroll(), ScrollArea::getVerticalScrollAmount(), Widget::getWidth(), Widget::getY(), Rect::height, mArrowButton, Widget::mDimension, mFollowDownScroll, Widget::mFrameSize, mRightMargin, mTabs, mTabScrollIndex, Widget::mVisible, mVisibleTabsWidth, mWidgetContainer, Widget::setPosition(), Widget::setSize(), ScrollArea::setVerticalScrollAmount(), updateArrowEnableState(), Visible_true, and Rect::width.

Referenced by addTab(), postInit(), removeTab(), and setSelectedTab().

Field Documentation

◆ mArrowButton

Button* TabbedArea::mArrowButton[2]
private

◆ mBlockSwitching

bool TabbedArea::mBlockSwitching
private

Definition at line 296 of file tabbedarea.h.

Referenced by keyPressed(), and setBlockSwitching().

◆ mEnableScrollButtons

bool TabbedArea::mEnableScrollButtons
private

Definition at line 294 of file tabbedarea.h.

Referenced by adjustTabPositions(), and enableScrollButtons().

◆ mFollowDownScroll

bool TabbedArea::mFollowDownScroll
private

Definition at line 295 of file tabbedarea.h.

Referenced by getFollowDownScroll(), setFollowDownScroll(), and widgetResized().

◆ mOpaque

Opaque TabbedArea::mOpaque
private

Definition at line 293 of file tabbedarea.h.

Referenced by isOpaque(), and setOpaque().

◆ mResizeHeight

bool TabbedArea::mResizeHeight
private

Definition at line 297 of file tabbedarea.h.

Referenced by adjustSize(), and setResizeHeight().

◆ mRightMargin

int TabbedArea::mRightMargin
private

◆ mSelectedTab

Tab* TabbedArea::mSelectedTab
private

◆ mTabContainer

BasicContainer2* TabbedArea::mTabContainer
private

◆ mTabs

TabContainer TabbedArea::mTabs
private

◆ mTabScrollIndex

unsigned int TabbedArea::mTabScrollIndex
private

The tab scroll index. When scrolling with the arrows, the tabs must be displayed according to the current index. So the first tab displayed may not be the first in the list.

Note
the index must start at 0.

Definition at line 290 of file tabbedarea.h.

Referenced by action(), adjustTabPositions(), updateArrowEnableState(), updateVisibleTabsWidth(), and widgetResized().

◆ mTabsToDelete

std::vector<Tab*> TabbedArea::mTabsToDelete
private

Definition at line 265 of file tabbedarea.h.

Referenced by addTab(), removeTab(), and ~TabbedArea().

◆ mTabsWidth

int TabbedArea::mTabsWidth
private

The overall width of all tab.

Definition at line 271 of file tabbedarea.h.

Referenced by updateArrowEnableState(), and updateTabsWidth().

◆ mVisibleTabsWidth

int TabbedArea::mVisibleTabsWidth
private

The overall width of visible tab.

Definition at line 282 of file tabbedarea.h.

Referenced by updateArrowEnableState(), updateVisibleTabsWidth(), and widgetResized().

◆ mWidgetContainer

BasicContainer2* TabbedArea::mWidgetContainer
private

The documentation for this class was generated from the following files: