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 84 of file tabbedarea.h.

Member Typedef Documentation

◆ TabContainer

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

Definition at line 247 of file tabbedarea.h.

Constructor & Destructor Documentation

◆ TabbedArea()

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

Constructor.

Definition at line 79 of file tabbedarea.cpp.

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

79  :
81  BasicContainer(widget),
82  KeyListener(),
83  MouseListener(),
85  mArrowButton(),
86  mSelectedTab(nullptr),
87  mTabContainer(new BasicContainer2(widget)),
88  mWidgetContainer(new BasicContainer2(widget)),
89  mTabsToDelete(),
90  mTabs(),
91  mTabsWidth(0),
93  mTabScrollIndex(0),
94  mRightMargin(0),
96  mEnableScrollButtons(false),
97  mFollowDownScroll(false),
98  mBlockSwitching(true),
99  mResizeHeight(true)
100 {
101  setFocusable(true);
102  addKeyListener(this);
103  addMouseListener(this);
104 }
int mVisibleTabsWidth
Definition: tabbedarea.h:281
BasicContainer2 * mWidgetContainer
Definition: tabbedarea.h:263
bool mBlockSwitching
Definition: tabbedarea.h:295
BasicContainer2 * mTabContainer
Definition: tabbedarea.h:262
bool mResizeHeight
Definition: tabbedarea.h:296
Tab * mSelectedTab
Definition: tabbedarea.h:261
unsigned int mTabScrollIndex
Definition: tabbedarea.h:289
TabContainer mTabs
Definition: tabbedarea.h:265
void addMouseListener(MouseListener *const mouseListener)
Definition: widget.cpp:291
const bool Opaque_false
Definition: opaque.h:29
void addKeyListener(KeyListener *const keyListener)
Definition: widget.cpp:271
Opaque mOpaque
Definition: tabbedarea.h:292
Button * mArrowButton[2]
Definition: tabbedarea.h:250
bool mFollowDownScroll
Definition: tabbedarea.h:294
void setFocusable(const bool focusable)
Definition: widget.cpp:191
int mRightMargin
Definition: tabbedarea.h:290
std::vector< Tab * > mTabsToDelete
Definition: tabbedarea.h:264
bool mEnableScrollButtons
Definition: tabbedarea.h:293
int mTabsWidth
Definition: tabbedarea.h:270
BasicContainer(const Widget2 *const widget)

◆ ~TabbedArea()

TabbedArea::~TabbedArea ( )

Definition at line 122 of file tabbedarea.cpp.

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

123 {
124  if (gui != nullptr)
125  gui->removeDragged(this);
126 
127  // +++ virtual method calls
128  remove(mTabContainer);
129  remove(mWidgetContainer);
130 
133 
134  for (size_t i = 0, sz = mTabsToDelete.size(); i < sz; i++)
136 
137  delete2(mArrowButton[0]);
138  delete2(mArrowButton[1]);
139 }
BasicContainer2 * mWidgetContainer
Definition: tabbedarea.h:263
Gui * gui
Definition: gui.cpp:110
BasicContainer2 * mTabContainer
Definition: tabbedarea.h:262
#define delete2(var)
Definition: delete2.h:24
Button * mArrowButton[2]
Definition: tabbedarea.h:250
void removeDragged(const Widget *const widget)
Definition: gui.cpp:1160
std::vector< Tab * > mTabsToDelete
Definition: tabbedarea.h:264

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 638 of file tabbedarea.cpp.

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

Referenced by isOpaque().

639 {
640  Widget *const source = actionEvent.getSource();
641  Tab *const tab = dynamic_cast<Tab *>(source);
642 
643  if (tab != nullptr)
644  {
645  setSelectedTab(tab);
646  }
647  else
648  {
649  const std::string &eventId = actionEvent.getId();
650  if (eventId == "shift_left")
651  {
652  if (mTabScrollIndex != 0u)
653  --mTabScrollIndex;
654  }
655  else if (eventId == "shift_right")
656  {
657  if (CAST_SIZE(mTabScrollIndex) < mTabs.size() - 1)
658  ++mTabScrollIndex;
659  }
662  }
663 }
void adjustTabPositions()
Definition: tabbedarea.cpp:596
Definition: tab.h:84
void setSelectedTab(Tab *const tab)
Definition: tabbedarea.cpp:398
void updateArrowEnableState()
Definition: tabbedarea.cpp:665
Widget * getSource() const
Definition: event.h:103
const std::string & getId() const
Definition: actionevent.h:121
unsigned int mTabScrollIndex
Definition: tabbedarea.h:289
TabContainer mTabs
Definition: tabbedarea.h:265
Definition: widget.h:97
#define CAST_SIZE
Definition: cast.h:33

◆ addTab() [1/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 229 of file tabbedarea.cpp.

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(), SocialWindow::addTab(), ShortcutWindow::addTab(), StatusWindow::addTab(), addTab(), ChatWindow::addTab(), StatusWindow::addTabBasic(), DebugWindow::DebugWindow(), SetupWindow::externalUpdate(), SkillDialog::loadXmlFile(), EmoteWindow::postInit(), SetupWindow::postInit(), and SocialWindow::postInit().

231 {
232  if ((tab == nullptr) || (widget == nullptr))
233  return;
234 
235  tab->setTabbedArea(this);
236  tab->addActionListener(this);
237 
238  mTabContainer->add(tab);
239  mTabs.push_back(std::pair<Tab*, Widget*>(tab, widget));
240 
241  if ((mSelectedTab == nullptr) && tab->mVisible == Visible_true)
242  setSelectedTab(tab);
243 
245  adjustSize();
246 
247  const int frameSize = 2 * mFrameSize;
248  widget->setSize(getWidth() - frameSize,
249  getHeight() - frameSize - mTabContainer->getHeight());
250 
251  widgetResized(Event(nullptr));
252  updateTabsWidth();
254 }
void setSize(const int width, const int height)
Definition: widget.cpp:366
void adjustTabPositions()
Definition: tabbedarea.cpp:596
int getWidth() const
Definition: widget.h:220
const bool Visible_true
Definition: visible.h:29
void addActionListener(ActionListener *const actionListener)
Definition: widget.cpp:251
BasicContainer2 * mTabContainer
Definition: tabbedarea.h:262
void setSelectedTab(Tab *const tab)
Definition: tabbedarea.cpp:398
Visible mVisible
Definition: widget.h:962
void updateArrowEnableState()
Definition: tabbedarea.cpp:665
Tab * mSelectedTab
Definition: tabbedarea.h:261
unsigned int mFrameSize
Definition: widget.h:1137
virtual void add(Widget *const widget)
void widgetResized(const Event &event)
Definition: tabbedarea.cpp:465
TabContainer mTabs
Definition: tabbedarea.h:265
void updateTabsWidth()
Definition: tabbedarea.cpp:536
void adjustSize()
Definition: tabbedarea.cpp:559
Definition: event.h:77
void setTabbedArea(TabbedArea *tabbedArea)
Definition: tab.cpp:447
int getHeight() const
Definition: widget.h:239

◆ addTab() [2/3]

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

Definition at line 265 of file tabbedarea.cpp.

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

266 {
267  Tab *const tab = new Tab(this);
268  tab->setCaption(caption);
269  mTabsToDelete.push_back(tab);
270 
271  addTab(tab, widget);
272 }
void setCaption(const std::string &caption)
Definition: tab.cpp:457
Definition: tab.h:84
std::vector< Tab * > mTabsToDelete
Definition: tabbedarea.h:264
void addTab(Tab *const tab, Widget *const widget)
Definition: tabbedarea.cpp:229

◆ addTab() [3/3]

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

Definition at line 274 of file tabbedarea.cpp.

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

275 {
276  Tab *const tab = new Tab(this);
277  tab->setImage(image);
278  mTabsToDelete.push_back(tab);
279 
280  addTab(tab, widget);
281 }
Definition: tab.h:84
void setImage(Image *const image)
Definition: tab.cpp:464
std::vector< Tab * > mTabsToDelete
Definition: tabbedarea.h:264
void addTab(Tab *const tab, Widget *const widget)
Definition: tabbedarea.cpp:229

◆ adjustSize()

void TabbedArea::adjustSize ( )

Definition at line 559 of file tabbedarea.cpp.

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(), isOpaque(), removeTab(), setDimension(), setHeight(), setSize(), setWidth(), SocialWindow::widgetResized(), SkillDialog::widgetResized(), and widgetResized().

560 {
561  int maxTabHeight = 0;
562 
563  const int width = mDimension.width;
564  const int height = mDimension.height;
565 
566  for (size_t i = 0, sz = mTabs.size(); i < sz; i++)
567  {
568  if (mTabs[i].first->getHeight() > maxTabHeight)
569  maxTabHeight = mTabs[i].first->getHeight();
570  }
571 
572  mTabContainer->setSize(width - mRightMargin, maxTabHeight);
573 
574  mWidgetContainer->setPosition(0, maxTabHeight);
575  mWidgetContainer->setSize(width, height - maxTabHeight);
576  Widget *const w = getCurrentWidget();
577  if (w != nullptr)
578  {
579  const int wFrameSize = w->getFrameSize();
580  const int frame2 = 2 * wFrameSize;
581 
582  w->setPosition(wFrameSize, wFrameSize);
583  if (mResizeHeight)
584  {
585  w->setSize(mWidgetContainer->getWidth() - frame2,
586  mWidgetContainer->getHeight() - frame2);
587  }
588  else
589  {
590  w->setSize(mWidgetContainer->getWidth() - frame2,
591  w->getHeight());
592  }
593  }
594 }
void setSize(const int width, const int height)
Definition: widget.cpp:366
int width
Definition: rect.h:218
int getWidth() const
Definition: widget.h:220
BasicContainer2 * mWidgetContainer
Definition: tabbedarea.h:263
Widget * getCurrentWidget() const
Definition: tabbedarea.cpp:220
BasicContainer2 * mTabContainer
Definition: tabbedarea.h:262
unsigned int getFrameSize() const
Definition: widget.h:183
bool mResizeHeight
Definition: tabbedarea.h:296
TabContainer mTabs
Definition: tabbedarea.h:265
void setPosition(const int x, const int y)
Definition: widget.cpp:160
int height
Definition: rect.h:223
int mRightMargin
Definition: tabbedarea.h:290
Definition: widget.h:97
int getHeight() const
Definition: widget.h:239
Rect mDimension
Definition: widget.h:1100

◆ adjustTabPositions()

void TabbedArea::adjustTabPositions ( )

Definition at line 596 of file tabbedarea.cpp.

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(), isOpaque(), SkillDialog::updateSkill(), and widgetResized().

597 {
598  int maxTabHeight = 0;
599  const size_t sz = mTabs.size();
600  for (size_t i = 0; i < sz; ++i)
601  {
602  const Tab *const tab = mTabs[i].first;
603  if ((tab != nullptr) &&
604  tab->mVisible == Visible_true &&
605  tab->getHeight() > maxTabHeight)
606  {
607  maxTabHeight = tab->getHeight();
608  }
609  }
610 
612  ? mArrowButton[0]->getWidth() : 0;
613  for (size_t i = mTabScrollIndex; i < sz; ++i)
614  {
615  Tab *const tab = mTabs[i].first;
616  if ((tab == nullptr) || tab->mVisible == Visible_false)
617  continue;
618  tab->setPosition(x, maxTabHeight - tab->getHeight());
619  x += tab->getWidth();
620  }
621 
622  // If the tabs are scrolled, we hide them away.
623  if (mTabScrollIndex > 0)
624  {
625  x = 0;
626  for (unsigned i = 0; i < mTabScrollIndex; ++i)
627  {
628  Tab *const tab = mTabs[i].first;
629  if ((tab != nullptr) && tab->mVisible == Visible_true)
630  {
631  x -= tab->getWidth();
632  tab->setPosition(x, maxTabHeight - tab->getHeight());
633  }
634  }
635  }
636 }
int getWidth() const
Definition: widget.h:220
const bool Visible_true
Definition: visible.h:29
Definition: tab.h:84
Visible mVisible
Definition: widget.h:962
const bool Visible_false
Definition: visible.h:29
unsigned int mTabScrollIndex
Definition: tabbedarea.h:289
TabContainer mTabs
Definition: tabbedarea.h:265
void setPosition(const int x, const int y)
Definition: widget.cpp:160
Button * mArrowButton[2]
Definition: tabbedarea.h:250
int getHeight() const
Definition: widget.h:239
bool mEnableScrollButtons
Definition: tabbedarea.h:293

◆ adjustWidget()

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

Definition at line 256 of file tabbedarea.cpp.

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

Referenced by setResizeHeight(), and EmoteWindow::widgetResized().

257 {
258  if (widget == nullptr)
259  return;
260  const int frameSize = 2 * mFrameSize;
261  widget->setSize(getWidth() - frameSize,
262  getHeight() - frameSize - mTabContainer->getHeight());
263 }
void setSize(const int width, const int height)
Definition: widget.cpp:366
int getWidth() const
Definition: widget.h:220
BasicContainer2 * mTabContainer
Definition: tabbedarea.h:262
unsigned int mFrameSize
Definition: widget.h:1137
int getHeight() const
Definition: widget.h:239

◆ 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 798 of file tabbedarea.cpp.

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

Referenced by setBlockSwitching().

799 {
800  Tab *const tab = dynamic_cast<Tab*>(event.getSource());
801 
802  if (tab != nullptr)
803  removeTab(tab);
804  else
805  BasicContainer::death(event);
806 }
Definition: tab.h:84
void removeTab(Tab *const tab)
Definition: tabbedarea.cpp:314
void death(const Event &event)

◆ draw()

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

Draw the tabbed area.

Implements Widget.

Definition at line 179 of file tabbedarea.cpp.

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

180 {
181  BLOCK_START("TabbedArea::draw")
182  if (mTabs.empty())
183  {
184  BLOCK_END("TabbedArea::draw")
185  return;
186  }
187 
188  drawChildren(graphics);
190 }
#define BLOCK_START(name)
Definition: perfomance.h:78
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:79
void draw(Graphics *const graphics)
Definition: tabbedarea.cpp:179
TabContainer mTabs
Definition: tabbedarea.h:265
std::string empty
Definition: podict.cpp:25
virtual void drawChildren(Graphics *const graphics)

◆ enableScrollButtons()

void TabbedArea::enableScrollButtons ( const bool  enable)

Definition at line 141 of file tabbedarea.cpp.

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

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

142 {
143  if (mEnableScrollButtons && !enable)
144  {
145  if (mArrowButton[0] != nullptr)
146  remove(mArrowButton[0]);
147  if (mArrowButton[1] != nullptr)
148  remove(mArrowButton[1]);
149  }
150  else if (!mEnableScrollButtons && enable)
151  {
152  if (mArrowButton[0] != nullptr)
153  add(mArrowButton[0]);
154  if (mArrowButton[1] != nullptr)
155  add(mArrowButton[1]);
156  }
157  mEnableScrollButtons = enable;
158 }
void add(Widget *const widget)
Button * mArrowButton[2]
Definition: tabbedarea.h:250
bool mEnableScrollButtons
Definition: tabbedarea.h:293

◆ getContainerHeight()

int TabbedArea::getContainerHeight ( ) const
inline

◆ getCurrentWidget()

Widget * TabbedArea::getCurrentWidget ( ) const

Returns the widget for the current tab

Definition at line 220 of file tabbedarea.cpp.

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

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

221 {
222  const Tab *const tab = getSelectedTab();
223 
224  if (tab != nullptr)
225  return getWidget(tab->getCaption());
226  return nullptr;
227 }
Widget * getWidget(const std::string &name) const
Definition: tabbedarea.cpp:205
Definition: tab.h:84
Tab * getSelectedTab() const
Definition: tabbedarea.h:174
const std::string & getCaption() const
Definition: tab.cpp:472

◆ getFollowDownScroll()

bool TabbedArea::getFollowDownScroll ( ) const
inline

Definition at line 213 of file tabbedarea.h.

References keyPressed(), and mFollowDownScroll.

214  { return mFollowDownScroll; }
bool mFollowDownScroll
Definition: tabbedarea.h:294

◆ getNumberOfTabs()

int TabbedArea::getNumberOfTabs ( ) const

Return how many tabs have been created.

Definition at line 160 of file tabbedarea.cpp.

References CAST_S32, and mTabs.

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

161 {
162  return CAST_S32(mTabs.size());
163 }
#define CAST_S32
Definition: cast.h:29
TabContainer mTabs
Definition: tabbedarea.h:265

◆ getRightMargin()

int TabbedArea::getRightMargin ( ) const
inline

Definition at line 207 of file tabbedarea.h.

References mRightMargin.

208  { return mRightMargin; }
int mRightMargin
Definition: tabbedarea.h:290

◆ getSelectedTab()

Tab* TabbedArea::getSelectedTab ( ) const
inline

◆ getSelectedTabIndex()

int TabbedArea::getSelectedTabIndex ( ) const

Definition at line 440 of file tabbedarea.cpp.

References CAST_U32, mSelectedTab, and mTabs.

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

441 {
442  for (unsigned int i = 0, fsz = CAST_U32(mTabs.size());
443  i < fsz;
444  i++)
445  {
446  if (mTabs[i].first == mSelectedTab)
447  return i;
448  }
449 
450  return -1;
451 }
#define CAST_U32
Definition: cast.h:30
Tab * mSelectedTab
Definition: tabbedarea.h:261
TabContainer mTabs
Definition: tabbedarea.h:265

◆ getTab()

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

Return tab with specified name as caption.

Definition at line 165 of file tabbedarea.cpp.

References mTabs.

Referenced by SetupWindow::unloadTab().

166 {
167  TabContainer::const_iterator itr = mTabs.begin();
168  const TabContainer::const_iterator itr_end = mTabs.end();
169  while (itr != itr_end)
170  {
171  if ((*itr).first->getCaption() == name)
172  return static_cast<Tab*>((*itr).first);
173 
174  ++itr;
175  }
176  return nullptr;
177 }
TabContainer mTabs
Definition: tabbedarea.h:265

◆ getTabByIndex()

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

Definition at line 705 of file tabbedarea.cpp.

References CAST_S32, and mTabs.

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

706 {
707  if (index < 0 || index >= CAST_S32(mTabs.size()))
708  return nullptr;
709  return static_cast<Tab*>(mTabs[index].first);
710 }
Definition: tab.h:84
#define CAST_S32
Definition: cast.h:29
TabContainer mTabs
Definition: tabbedarea.h:265

◆ 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 205 of file tabbedarea.cpp.

References mTabs.

Referenced by getCurrentWidget().

206 {
207  TabContainer::const_iterator itr = mTabs.begin();
208  const TabContainer::const_iterator itr_end = mTabs.end();
209  while (itr != itr_end)
210  {
211  if ((*itr).first->getCaption() == name)
212  return (*itr).second;
213 
214  ++itr;
215  }
216 
217  return nullptr;
218 }
TabContainer mTabs
Definition: tabbedarea.h:265

◆ getWidgetByIndex()

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

Definition at line 712 of file tabbedarea.cpp.

References CAST_S32, and mTabs.

713 {
714  if (index < 0 || index >= CAST_S32(mTabs.size()))
715  return nullptr;
716  return mTabs[index].second;
717 }
#define CAST_S32
Definition: cast.h:29
TabContainer mTabs
Definition: tabbedarea.h:265

◆ getWidgetContainer()

Widget* TabbedArea::getWidgetContainer ( ) const
inline

◆ isOpaque()

bool TabbedArea::isOpaque ( ) const
inline

Definition at line 180 of file tabbedarea.h.

References action(), adjustSize(), adjustTabPositions(), enableScrollButtons(), mOpaque, mousePressed(), Opaque_true, setSelectedTabByName(), and widgetResized().

181  { return mOpaque == Opaque_true; }
Opaque mOpaque
Definition: tabbedarea.h:292
const bool Opaque_true
Definition: opaque.h:29

◆ isTabPresent()

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

Definition at line 291 of file tabbedarea.cpp.

References FOR_EACH, and mTabs.

Referenced by ChatWindow::isTabPresent().

292 {
293  FOR_EACH (TabContainer::const_iterator, it, mTabs)
294  {
295  if ((*it).first == tab || (*it).second == tab)
296  return true;
297  }
298  return false;
299 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
TabContainer mTabs
Definition: tabbedarea.h:265

◆ isTabSelected() [1/2]

bool TabbedArea::isTabSelected ( const size_t  index) const

Definition at line 283 of file tabbedarea.cpp.

References mSelectedTab, and mTabs.

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

284 {
285  if (index >= mTabs.size())
286  return false;
287 
288  return mSelectedTab == mTabs[index].first;
289 }
Tab * mSelectedTab
Definition: tabbedarea.h:261
TabContainer mTabs
Definition: tabbedarea.h:265

◆ isTabSelected() [2/2]

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

Definition at line 301 of file tabbedarea.cpp.

References mSelectedTab.

302 {
303  return mSelectedTab == tab;
304 }
Tab * mSelectedTab
Definition: tabbedarea.h:261

◆ 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 767 of file tabbedarea.cpp.

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

Referenced by getFollowDownScroll().

768 {
769  if (mBlockSwitching || event.isConsumed() || !isFocused())
770  return;
771 
772  const InputActionT actionId = event.getActionId();
773 
774  if (actionId == InputAction::GUI_LEFT)
775  {
776  int index = getSelectedTabIndex();
777  index--;
778 
779  if (index < 0)
780  return;
781 
782  setSelectedTab(mTabs[index].first);
783  event.consume();
784  }
785  else if (actionId == InputAction::GUI_RIGHT)
786  {
787  int index = getSelectedTabIndex();
788  index++;
789 
790  if (index >= CAST_S32(mTabs.size()))
791  return;
792 
793  setSelectedTab(mTabs[index].first);
794  event.consume();
795  }
796 }
bool mBlockSwitching
Definition: tabbedarea.h:295
virtual bool isFocused() const
Definition: widget.cpp:183
void setSelectedTab(Tab *const tab)
Definition: tabbedarea.cpp:398
#define CAST_S32
Definition: cast.h:29
int getSelectedTabIndex() const
Definition: tabbedarea.cpp:440
InputAction ::T InputActionT
Definition: inputaction.h:714
TabContainer mTabs
Definition: tabbedarea.h:265
bool isConsumed() const

◆ logic()

void TabbedArea::logic ( )
virtual

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

Reimplemented from BasicContainer.

Definition at line 371 of file tabbedarea.cpp.

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

372 {
373  BLOCK_START("TabbedArea::logic")
374  logicChildren();
376 }
void logic()
Definition: tabbedarea.cpp:371
#define BLOCK_START(name)
Definition: perfomance.h:78
#define BLOCK_END(name)
Definition: perfomance.h:79
virtual void 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 378 of file tabbedarea.cpp.

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

Referenced by isOpaque().

379 {
380  if (event.isConsumed())
381  return;
382 
383  if (event.getButton() == MouseButton::LEFT)
384  {
385  Widget *const widget = mTabContainer->getWidgetAt(
386  event.getX(), event.getY());
387  Tab *const tab = dynamic_cast<Tab *>(widget);
388 
389  if (tab != nullptr)
390  {
391  event.consume();
392  setSelectedTab(tab);
393  requestFocus();
394  }
395  }
396 }
Definition: tab.h:84
MouseButtonT getButton() const
Definition: mouseevent.h:115
BasicContainer2 * mTabContainer
Definition: tabbedarea.h:262
void setSelectedTab(Tab *const tab)
Definition: tabbedarea.cpp:398
Widget * getWidgetAt(int x, int y)
virtual void requestFocus()
Definition: widget.cpp:203
bool isConsumed() const
Definition: widget.h:97
int getX() const
Definition: mouseevent.h:126

◆ postInit()

void TabbedArea::postInit ( )
virtual

Reimplemented from Widget.

Definition at line 106 of file tabbedarea.cpp.

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

107 {
109 
112 
114  addWidgetListener(this);
115 
116  mArrowButton[0] = new Button(this, "<", "shift_left", this);
117  mArrowButton[1] = new Button(this, ">", "shift_right", this);
118 
119  widgetResized(Event(nullptr));
120 }
BasicContainer2 * mWidgetContainer
Definition: tabbedarea.h:263
Definition: button.h:94
BasicContainer2 * mTabContainer
Definition: tabbedarea.h:262
void add(Widget *const widget)
void widgetResized(const Event &event)
Definition: tabbedarea.cpp:465
const bool Opaque_false
Definition: opaque.h:29
Button * mArrowButton[2]
Definition: tabbedarea.h:250
void setOpaque(Opaque opaque)
void addWidgetListener(WidgetListener *const widgetListener)
Definition: widget.cpp:301
Definition: event.h:77

◆ removeAll()

void TabbedArea::removeAll ( const bool  del)

Definition at line 719 of file tabbedarea.cpp.

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

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

720 {
721  if (getSelectedTabIndex() != -1)
722  {
724  }
725  while (getNumberOfTabs() > 0)
726  {
727  const int idx = getNumberOfTabs() - 1;
728  Tab *tab = mTabs[idx].first;
729  Widget *widget = mTabs[idx].second;
730  removeTab(tab);
731  if (del)
732  {
733  delete tab;
734  delete widget;
735  }
736  }
737 }
#define CAST_U32
Definition: cast.h:30
Definition: tab.h:84
void removeTab(Tab *const tab)
Definition: tabbedarea.cpp:314
int getNumberOfTabs() const
Definition: tabbedarea.cpp:160
int getSelectedTabIndex() const
Definition: tabbedarea.cpp:440
TabContainer mTabs
Definition: tabbedarea.h:265
void setSelectedTabByIndex(const size_t index)
Definition: tabbedarea.cpp:306
Definition: widget.h:97

◆ removeTab()

void TabbedArea::removeTab ( Tab *const  tab)

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

Definition at line 314 of file tabbedarea.cpp.

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

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

315 {
316  int tabIndexToBeSelected = -1;
317 
318  if (tab == mSelectedTab)
319  {
320  const int index = getSelectedTabIndex();
321  const size_t sz = mTabs.size();
322  if (index == CAST_S32(sz) - 1 && sz == 1)
323  tabIndexToBeSelected = -1;
324  else
325  tabIndexToBeSelected = index - 1;
326  }
327 
328  for (TabContainer::iterator iter = mTabs.begin();
329  iter != mTabs.end(); ++iter)
330  {
331  if (iter->first == tab)
332  {
333  mTabContainer->remove(tab);
334  mTabs.erase(iter);
335  break;
336  }
337  }
338 
339  for (STD_VECTOR<Tab*>::iterator iter2 = mTabsToDelete.begin();
340  iter2 != mTabsToDelete.end(); ++iter2)
341  {
342  if (*iter2 == tab)
343  {
344  mTabsToDelete.erase(iter2);
345  delete tab;
346  break;
347  }
348  }
349 
350  const int tabsSize = CAST_S32(mTabs.size());
351  if (tabIndexToBeSelected >= tabsSize)
352  tabIndexToBeSelected = tabsSize - 1;
353  if (tabIndexToBeSelected < -1)
354  tabIndexToBeSelected = -1;
355 
356  if (tabIndexToBeSelected == -1)
357  {
358  mSelectedTab = nullptr;
360  }
361  else
362  {
363  setSelectedTabByIndex(tabIndexToBeSelected);
364  }
365 
366  adjustSize();
367  updateTabsWidth();
368  widgetResized(Event(nullptr));
369 }
BasicContainer2 * mWidgetContainer
Definition: tabbedarea.h:263
BasicContainer2 * mTabContainer
Definition: tabbedarea.h:262
virtual void clear()
#define CAST_S32
Definition: cast.h:29
Tab * mSelectedTab
Definition: tabbedarea.h:261
int getSelectedTabIndex() const
Definition: tabbedarea.cpp:440
virtual void remove(Widget *const widget)
void widgetResized(const Event &event)
Definition: tabbedarea.cpp:465
TabContainer mTabs
Definition: tabbedarea.h:265
void updateTabsWidth()
Definition: tabbedarea.cpp:536
void setSelectedTabByIndex(const size_t index)
Definition: tabbedarea.cpp:306
void adjustSize()
Definition: tabbedarea.cpp:559
Definition: event.h:77
std::vector< Tab * > mTabsToDelete
Definition: tabbedarea.h:264

◆ safeDraw()

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

Implements Widget.

Definition at line 192 of file tabbedarea.cpp.

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

193 {
194  BLOCK_START("TabbedArea::draw")
195  if (mTabs.empty())
196  {
197  BLOCK_END("TabbedArea::draw")
198  return;
199  }
200 
201  safeDrawChildren(graphics);
203 }
#define BLOCK_START(name)
Definition: perfomance.h:78
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:79
void draw(Graphics *const graphics)
Definition: tabbedarea.cpp:179
TabContainer mTabs
Definition: tabbedarea.h:265
std::string empty
Definition: podict.cpp:25
virtual void safeDrawChildren(Graphics *const graphics)

◆ selectNextTab()

void TabbedArea::selectNextTab ( )

Definition at line 808 of file tabbedarea.cpp.

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

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

809 {
810  int tab = getSelectedTabIndex();
811  tab++;
812  if (tab == CAST_S32(mTabs.size()))
813  tab = 0;
814  setSelectedTab(mTabs[tab].first);
815 }
void setSelectedTab(Tab *const tab)
Definition: tabbedarea.cpp:398
#define CAST_S32
Definition: cast.h:29
int getSelectedTabIndex() const
Definition: tabbedarea.cpp:440
TabContainer mTabs
Definition: tabbedarea.h:265

◆ selectPrevTab()

void TabbedArea::selectPrevTab ( )

Definition at line 817 of file tabbedarea.cpp.

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

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

818 {
819  int tab = getSelectedTabIndex();
820 
821  if (tab == 0)
822  tab = CAST_S32(mTabs.size());
823  if (tab < 0)
824  return;
825  tab--;
826  setSelectedTab(mTabs[tab].first);
827 }
void setSelectedTab(Tab *const tab)
Definition: tabbedarea.cpp:398
#define CAST_S32
Definition: cast.h:29
int getSelectedTabIndex() const
Definition: tabbedarea.cpp:440
TabContainer mTabs
Definition: tabbedarea.h:265

◆ setBlockSwitching()

void TabbedArea::setBlockSwitching ( const bool  b)
inline

Definition at line 218 of file tabbedarea.h.

References death(), mBlockSwitching, setDimension(), setHeight(), setSize(), and setWidth().

219  { mBlockSwitching = b; }
bool mBlockSwitching
Definition: tabbedarea.h:295

◆ setDimension()

void TabbedArea::setDimension ( const Rect dimension)

Definition at line 760 of file tabbedarea.cpp.

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

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

761 {
762  // +++ need use virtual
763  Widget::setDimension(dimension);
764  adjustSize();
765 }
void setDimension(const Rect &dimension)
Definition: widget.cpp:168
void adjustSize()
Definition: tabbedarea.cpp:559

◆ setFollowDownScroll()

void TabbedArea::setFollowDownScroll ( const bool  n)
inline

Definition at line 210 of file tabbedarea.h.

References mFollowDownScroll.

Referenced by ChatWindow::ChatWindow().

211  { mFollowDownScroll = n; }
bool mFollowDownScroll
Definition: tabbedarea.h:294

◆ setHeight()

void TabbedArea::setHeight ( int  height)

Definition at line 746 of file tabbedarea.cpp.

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

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

747 {
748  // +++ need use virtual
749  Widget::setHeight(height);
750  adjustSize();
751 }
void setHeight(const int height)
Definition: widget.cpp:139
void adjustSize()
Definition: tabbedarea.cpp:559

◆ setOpaque()

void TabbedArea::setOpaque ( const Opaque  opaque)
inline

Definition at line 177 of file tabbedarea.h.

References mOpaque.

178  { mOpaque = opaque; }
Opaque mOpaque
Definition: tabbedarea.h:292

◆ setResizeHeight()

void TabbedArea::setResizeHeight ( bool  b)
inline

Definition at line 231 of file tabbedarea.h.

References adjustWidget(), mResizeHeight, selectNextTab(), and selectPrevTab().

Referenced by ChatWindow::ChatWindow().

232  { mResizeHeight = b; }
bool mResizeHeight
Definition: tabbedarea.h:296

◆ setRightMargin()

void TabbedArea::setRightMargin ( const int  n)
inline

Definition at line 204 of file tabbedarea.h.

References mRightMargin.

Referenced by ChatWindow::updateTabsMargin().

205  { mRightMargin = n; }
int mRightMargin
Definition: tabbedarea.h:290

◆ setSelectedTab()

void TabbedArea::setSelectedTab ( Tab *const  tab)

Definition at line 398 of file tabbedarea.cpp.

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

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

399 {
400  for (size_t i = 0; i < mTabs.size(); i++)
401  {
402  if (mTabs[i].first == mSelectedTab)
403  mWidgetContainer->remove(mTabs[i].second);
404  }
405 
406  for (size_t i = 0; i < mTabs.size(); i++)
407  {
408  if (mTabs[i].first == tab)
409  {
410  mSelectedTab = tab;
411  mWidgetContainer->add(mTabs[i].second);
412  }
413  }
414 
415  Tab *const newTab = tab;
416 
417  if (newTab != nullptr)
418  newTab->setCurrent();
419 
420  widgetResized(Event(nullptr));
421 }
virtual void setCurrent()
Definition: tab.h:210
BasicContainer2 * mWidgetContainer
Definition: tabbedarea.h:263
Definition: tab.h:84
Tab * mSelectedTab
Definition: tabbedarea.h:261
virtual void add(Widget *const widget)
virtual void remove(Widget *const widget)
void widgetResized(const Event &event)
Definition: tabbedarea.cpp:465
TabContainer mTabs
Definition: tabbedarea.h:265
Definition: event.h:77

◆ setSelectedTabByIndex()

void TabbedArea::setSelectedTabByIndex ( const size_t  index)

Definition at line 306 of file tabbedarea.cpp.

References mTabs, and setSelectedTab().

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

307 {
308  if (index >= mTabs.size())
309  return;
310 
311  setSelectedTab(mTabs[index].first);
312 }
void setSelectedTab(Tab *const tab)
Definition: tabbedarea.cpp:398
TabContainer mTabs
Definition: tabbedarea.h:265

◆ setSelectedTabByName()

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

Definition at line 453 of file tabbedarea.cpp.

References FOR_EACH, mTabs, and setSelectedTab().

Referenced by SetupWindow::activateTab(), and isOpaque().

454 {
455  FOR_EACH (TabContainer::const_iterator, itr, mTabs)
456  {
457  if (((*itr).first != nullptr) && (*itr).first->getCaption() == name)
458  {
459  setSelectedTab((*itr).first);
460  return;
461  }
462  }
463 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
void setSelectedTab(Tab *const tab)
Definition: tabbedarea.cpp:398
TabContainer mTabs
Definition: tabbedarea.h:265

◆ setSelectedTabDefault()

void TabbedArea::setSelectedTabDefault ( )

Definition at line 423 of file tabbedarea.cpp.

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

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

424 {
425  if (mSelectedTab == nullptr ||
427  {
428  for (size_t i = 0; i < mTabs.size(); i++)
429  {
430  Tab *const tab = mTabs[i].first;
431  if ((tab != nullptr) && tab->mVisible == Visible_true)
432  {
433  setSelectedTab(tab);
434  return;
435  }
436  }
437  }
438 }
const bool Visible_true
Definition: visible.h:29
Definition: tab.h:84
void setSelectedTab(Tab *const tab)
Definition: tabbedarea.cpp:398
Visible mVisible
Definition: widget.h:962
Tab * mSelectedTab
Definition: tabbedarea.h:261
const bool Visible_false
Definition: visible.h:29
TabContainer mTabs
Definition: tabbedarea.h:265

◆ setSize()

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

Definition at line 753 of file tabbedarea.cpp.

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

Referenced by setBlockSwitching(), and EmoteWindow::widgetResized().

754 {
755  // +++ need use virtual
756  Widget::setSize(width, height);
757  adjustSize();
758 }
void setSize(const int width, const int height)
Definition: widget.cpp:366
void adjustSize()
Definition: tabbedarea.cpp:559

◆ setWidth()

void TabbedArea::setWidth ( int  width)

Definition at line 739 of file tabbedarea.cpp.

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

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

740 {
741  // +++ need use virtual
742  Widget::setWidth(width);
743  adjustSize();
744 }
void setWidth(const int width)
Definition: widget.cpp:132
void adjustSize()
Definition: tabbedarea.cpp:559

◆ updateArrowEnableState()

void TabbedArea::updateArrowEnableState ( )
private

Check whether the arrow should be clickable

Definition at line 665 of file tabbedarea.cpp.

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().

666 {
667  updateTabsWidth();
668  if ((mArrowButton[0] == nullptr) || (mArrowButton[1] == nullptr))
669  return;
670 
671  const int width = mDimension.width;
672  if (mTabsWidth > width - 4
673  - mArrowButton[0]->getWidth()
675  {
678  }
679  else
680  {
683  mTabScrollIndex = 0;
684  }
685 
686  // Left arrow consistency check
687  if (mTabScrollIndex == 0u)
688  mArrowButton[0]->setEnabled(false);
689  else
690  mArrowButton[0]->setEnabled(true);
691 
692  // Right arrow consistency check
693  if (mVisibleTabsWidth < width - 4
694  - mArrowButton[0]->getWidth()
696  {
697  mArrowButton[1]->setEnabled(false);
698  }
699  else
700  {
701  mArrowButton[1]->setEnabled(true);
702  }
703 }
int width
Definition: rect.h:218
int mVisibleTabsWidth
Definition: tabbedarea.h:281
int getWidth() const
Definition: widget.h:220
const bool Visible_true
Definition: visible.h:29
void setVisible(Visible visible)
Definition: widget.cpp:224
const bool Visible_false
Definition: visible.h:29
unsigned int mTabScrollIndex
Definition: tabbedarea.h:289
void updateTabsWidth()
Definition: tabbedarea.cpp:536
Button * mArrowButton[2]
Definition: tabbedarea.h:250
void setEnabled(const bool enabled)
Definition: widget.h:351
int mRightMargin
Definition: tabbedarea.h:290
int mTabsWidth
Definition: tabbedarea.h:270
Rect mDimension
Definition: widget.h:1100

◆ 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 536 of file tabbedarea.cpp.

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

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

537 {
538  mTabsWidth = 0;
539  FOR_EACH (TabContainer::const_iterator, itr, mTabs)
540  {
541  Tab *const tab = (*itr).first;
542  if ((tab != nullptr) && tab->mVisible == Visible_true)
543  mTabsWidth += tab->getWidth();
544  }
546 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
int getWidth() const
Definition: widget.h:220
const bool Visible_true
Definition: visible.h:29
Definition: tab.h:84
Visible mVisible
Definition: widget.h:962
TabContainer mTabs
Definition: tabbedarea.h:265
int mTabsWidth
Definition: tabbedarea.h:270
void updateVisibleTabsWidth()
Definition: tabbedarea.cpp:548

◆ 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 548 of file tabbedarea.cpp.

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

Referenced by updateTabsWidth().

549 {
550  mVisibleTabsWidth = 0;
551  for (size_t i = mTabScrollIndex, sz = mTabs.size(); i < sz; ++i)
552  {
553  Tab *const tab = mTabs[i].first;
554  if ((tab != nullptr) && tab->mVisible == Visible_true)
556  }
557 }
int mVisibleTabsWidth
Definition: tabbedarea.h:281
int getWidth() const
Definition: widget.h:220
const bool Visible_true
Definition: visible.h:29
Definition: tab.h:84
Visible mVisible
Definition: widget.h:962
#define CAST_S32
Definition: cast.h:29
unsigned int mTabScrollIndex
Definition: tabbedarea.h:289
TabContainer mTabs
Definition: tabbedarea.h:265

◆ 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 465 of file tabbedarea.cpp.

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(), isOpaque(), postInit(), removeTab(), and setSelectedTab().

466 {
467  adjustSize();
468 
469  const int frameSize = 2 * mFrameSize;
470  const int widgetFrameSize = 2 * mWidgetContainer->getFrameSize();
471  const int w1 = mDimension.width;
472  const int h1 = mDimension.height;
473  const int width = w1 - frameSize - widgetFrameSize;
474  const int height = h1 - frameSize
475  - mWidgetContainer->getY() - widgetFrameSize;
476 
477  Widget *const w = getCurrentWidget();
478  ScrollArea *const scr = dynamic_cast<ScrollArea *>(w);
479  if (scr != nullptr)
480  {
481  if (mFollowDownScroll && height != 0)
482  {
483  const Rect &rect = w->getDimension();
484  if (rect.height != 0 && rect.height > height + 2)
485  {
486  if (scr->getVerticalScrollAmount()
487  >= scr->getVerticalMaxScroll() - 2
488  && scr->getVerticalScrollAmount()
489  <= scr->getVerticalMaxScroll() + 2)
490  {
491  const int newScroll = scr->getVerticalScrollAmount()
492  + rect.height - height;
493  w->setSize(mWidgetContainer->getWidth() - frameSize,
494  mWidgetContainer->getHeight() - frameSize);
495  if (newScroll != 0)
496  scr->setVerticalScrollAmount(newScroll);
497  }
498  }
499  }
500  }
501 
502  if (mArrowButton[1] != nullptr)
503  {
504  // Check whether there is room to show more tabs now.
505  int innerWidth = w1 - 4 - mArrowButton[0]->getWidth()
507  if (innerWidth < 0)
508  innerWidth = 0;
509 
510  int newWidth = mVisibleTabsWidth;
511  while ((mTabScrollIndex != 0u) && newWidth < innerWidth)
512  {
513  Tab *const tab = mTabs[mTabScrollIndex - 1].first;
514  if ((tab != nullptr) && tab->mVisible == Visible_true)
515  {
516  newWidth += tab->getWidth();
517  if (newWidth < innerWidth)
518  --mTabScrollIndex;
519  }
520  }
521 
522  if (mArrowButton[1] != nullptr)
523  {
524  // Move the right arrow to fit the windows content.
525  newWidth = width - mArrowButton[1]->getWidth() - mRightMargin;
526  if (newWidth < 0)
527  newWidth = 0;
528  mArrowButton[1]->setPosition(newWidth, 0);
529  }
530  }
531 
534 }
void setSize(const int width, const int height)
Definition: widget.cpp:366
void adjustTabPositions()
Definition: tabbedarea.cpp:596
int width
Definition: rect.h:218
int mVisibleTabsWidth
Definition: tabbedarea.h:281
int getWidth() const
Definition: widget.h:220
BasicContainer2 * mWidgetContainer
Definition: tabbedarea.h:263
const bool Visible_true
Definition: visible.h:29
Definition: tab.h:84
int getY() const
Definition: widget.h:287
Definition: rect.h:72
Widget * getCurrentWidget() const
Definition: tabbedarea.cpp:220
void setVerticalScrollAmount(const int vScroll)
unsigned int getFrameSize() const
Definition: widget.h:183
int getVerticalMaxScroll()
Visible mVisible
Definition: widget.h:962
void updateArrowEnableState()
Definition: tabbedarea.cpp:665
int getVerticalScrollAmount() const
Definition: scrollarea.h:273
unsigned int mFrameSize
Definition: widget.h:1137
unsigned int mTabScrollIndex
Definition: tabbedarea.h:289
TabContainer mTabs
Definition: tabbedarea.h:265
void setPosition(const int x, const int y)
Definition: widget.cpp:160
int height
Definition: rect.h:223
Button * mArrowButton[2]
Definition: tabbedarea.h:250
const Rect & getDimension() const
Definition: widget.h:316
bool mFollowDownScroll
Definition: tabbedarea.h:294
void adjustSize()
Definition: tabbedarea.cpp:559
int mRightMargin
Definition: tabbedarea.h:290
Definition: widget.h:97
int getHeight() const
Definition: widget.h:239
Rect mDimension
Definition: widget.h:1100

Field Documentation

◆ mArrowButton

Button* TabbedArea::mArrowButton[2]
private

◆ mBlockSwitching

bool TabbedArea::mBlockSwitching
private

Definition at line 295 of file tabbedarea.h.

Referenced by keyPressed(), and setBlockSwitching().

◆ mEnableScrollButtons

bool TabbedArea::mEnableScrollButtons
private

Definition at line 293 of file tabbedarea.h.

Referenced by adjustTabPositions(), and enableScrollButtons().

◆ mFollowDownScroll

bool TabbedArea::mFollowDownScroll
private

Definition at line 294 of file tabbedarea.h.

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

◆ mOpaque

Opaque TabbedArea::mOpaque
private

Definition at line 292 of file tabbedarea.h.

Referenced by isOpaque(), and setOpaque().

◆ mResizeHeight

bool TabbedArea::mResizeHeight
private

Definition at line 296 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 289 of file tabbedarea.h.

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

◆ mTabsToDelete

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

Definition at line 264 of file tabbedarea.h.

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

◆ mTabsWidth

int TabbedArea::mTabsWidth
private

The overall width of all tab.

Definition at line 270 of file tabbedarea.h.

Referenced by updateArrowEnableState(), and updateTabsWidth().

◆ mVisibleTabsWidth

int TabbedArea::mVisibleTabsWidth
private

The overall width of visible tab.

Definition at line 281 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: