ManaPlus
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends
GuiTable Class Reference

#include <guitable.h>

Inheritance diagram for GuiTable:
Widget MouseListener KeyListener TableModelListener Widget2

Public Member Functions

 GuiTable (const Widget2 *const widget, TableModel *const initial_model, const Opaque opacity)
 
 ~GuiTable ()
 
void setModel (TableModel *const m)
 
const TableModelgetModel () const
 
void setSelected (const int row, const int column)
 
int getSelectedRow () const
 
int getSelectedColumn () const
 
void setSelectedRow (const int selected)
 
void setSelectedColumn (const int selected)
 
bool isWrappingEnabled () const
 
void setWrappingEnabled (bool wrappingEnabled)
 
Rect getChildrenArea ()
 
void setLinewiseSelection (bool linewise)
 
void draw (Graphics *const graphics)
 
void safeDraw (Graphics *const graphics)
 
WidgetgetWidgetAt (int x, int y)
 
void moveToTop (Widget *const widget)
 
void moveToBottom (Widget *const widget)
 
void setFocusHandler (FocusHandler *const focusHandler)
 
void keyPressed (KeyEvent &event)
 
void setOpaque (Opaque opaque)
 
bool isOpaque () const
 
void mousePressed (MouseEvent &event)
 
void mouseWheelMovedUp (MouseEvent &event)
 
void mouseWheelMovedDown (MouseEvent &event)
 
void mouseDragged (MouseEvent &event)
 
void modelUpdated (const bool completed)
 
void requestFocus ()
 
void setSelectableGui (bool b)
 
- 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
 
virtual void logic ()
 
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 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)
 
virtual void focusNext ()
 
virtual void focusPrevious ()
 
virtual void showWidgetPart (Widget *const widget, const Rect &area)
 
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 ()
 
virtual void postInit ()
 
- 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 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 mouseMoved (MouseEvent &event)
 
- Public Member Functions inherited from KeyListener
virtual ~KeyListener ()
 
virtual void keyReleased (KeyEvent &event)
 
- Public Member Functions inherited from TableModelListener
 TableModelListener ()
 
virtual ~TableModelListener ()
 

Protected Member Functions

void uninstallActionListeners ()
 
void installActionListeners ()
 
int getRowHeight () const
 
int getColumnWidth (const int i) const
 
- 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 MouseListener
 MouseListener ()
 
- Protected Member Functions inherited from KeyListener
 KeyListener ()
 

Private Member Functions

int getRowForY (const int y) const
 
int getColumnForX (const int x) const
 
void recomputeDimensions ()
 

Private Attributes

TableModelmModel
 
WidgetmTopWidget
 
std::vector< GuiTableActionListener * > mActionListeners2
 
Color mHighlightColor
 
int mSelectedRow
 
int mSelectedColumn
 
bool mLinewiseMode
 
bool mWrappingEnabled
 
Opaque mOpaque
 
bool mSelectableGui
 

Static Private Attributes

static float mAlpha = 1.0
 

Friends

class GuiTableActionListener
 

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 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 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 table, with rows and columns made out of sub-widgets. Largely inspired by (and can be thought of as a generalisation of) the guichan listbox implementation.

Normally you want this within a ScrollArea.

Definition at line 48 of file guitable.h.

Constructor & Destructor Documentation

◆ GuiTable()

GuiTable::GuiTable ( const Widget2 *const  widget,
TableModel *const  initial_model,
const Opaque  opacity 
)

Definition at line 42 of file guitable.cpp.

References Widget::addKeyListener(), Widget::addMouseListener(), ThemeColorId::BACKGROUND, Widget2::getThemeColor(), Widget::mAllowLogic, Widget::mBackgroundColor, Widget::setFocusable(), and setModel().

44  :
45  Widget(widget),
46  MouseListener(),
47  KeyListener(),
49  mModel(nullptr),
50  mTopWidget(nullptr),
53  mSelectedRow(-1),
54  mSelectedColumn(-1),
55  mLinewiseMode(false),
56  mWrappingEnabled(false),
57  mOpaque(opacity),
58  mSelectableGui(true)
59 {
60  mAllowLogic = false;
62 
63  setModel(initial_model);
64  setFocusable(true);
65 
66  addMouseListener(this);
67  addKeyListener(this);
68 }
std::vector< GuiTableActionListener * > mActionListeners2
Definition: guitable.h:191
bool mSelectableGui
Definition: guitable.h:204
Widget * mTopWidget
Definition: guitable.h:188
TableModel * mModel
Definition: guitable.h:185
Color mBackgroundColor
Definition: widget.h:1090
int mSelectedRow
Definition: guitable.h:198
Color mHighlightColor
Definition: guitable.h:196
Widget(const Widget2 *const widget)
Definition: widget.cpp:84
bool mAllowLogic
Definition: widget.h:1159
void addMouseListener(MouseListener *const mouseListener)
Definition: widget.cpp:291
void addKeyListener(KeyListener *const keyListener)
Definition: widget.cpp:271
bool mWrappingEnabled
Definition: guitable.h:202
int mSelectedColumn
Definition: guitable.h:199
void setModel(TableModel *const m)
Definition: guitable.cpp:84
void setFocusable(const bool focusable)
Definition: widget.cpp:191
Opaque mOpaque
Definition: guitable.h:203
const Color & getThemeColor(const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
Definition: widget2.h:44
bool mLinewiseMode
Definition: guitable.h:201

◆ ~GuiTable()

GuiTable::~GuiTable ( )

Definition at line 70 of file guitable.cpp.

References delete2, gui, mModel, Gui::removeDragged(), and uninstallActionListeners().

71 {
72  if (gui != nullptr)
73  gui->removeDragged(this);
74 
76  delete2(mModel);
77 }
Gui * gui
Definition: gui.cpp:110
#define delete2(var)
Definition: delete2.h:24
TableModel * mModel
Definition: guitable.h:185
void removeDragged(const Widget *const widget)
Definition: gui.cpp:1160
void uninstallActionListeners()
Definition: guitable.cpp:198

Member Function Documentation

◆ draw()

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

Draws the widget. It is called by the parent widget when it is time for the widget to draw itself. The graphics object is set up so that all drawing is relative to the widget, i.e coordinate (0,0) is the top left corner of the widget. It is not possible to draw outside of a widget's dimension.

Parameters
graphicsaA graphics object to draw with.

Implements Widget.

Definition at line 226 of file guitable.cpp.

References Color::a, BLOCK_END, BLOCK_START, CAST_S32, CAST_U32, Widget::draw(), Graphics::fillRectangle(), TableModel::getColumns(), getColumnWidth(), Widget::getDimension(), TableModel::getElementAt(), Widget::getHeight(), getRowHeight(), TableModel::getRows(), Widget::getWidth(), Settings::guiAlpha, Rect::height, mAlpha, Widget::mBackgroundColor, Widget::mDimension, mHighlightColor, mLinewiseMode, mModel, mOpaque, mSelectedColumn, mSelectedRow, mTopWidget, Opaque_true, Graphics::popClipArea(), Graphics::pushClipArea(), Graphics::setColor(), Widget::setDimension(), settings, Rect::width, y, and Rect::y.

Referenced by setLinewiseSelection().

227 {
228  if (getRowHeight() == 0)
229  return;
230 
231  BLOCK_START("GuiTable::draw")
232  if (settings.guiAlpha != mAlpha)
233  mAlpha = settings.guiAlpha;
234 
235  const Rect &rect = mDimension;
236  const int width = rect.width;
237  const int height = rect.height;
238  const int y = rect.y;
239  if (mOpaque == Opaque_true)
240  {
241  mBackgroundColor.a = CAST_U32(mAlpha * 255.0F);
242  graphics->setColor(mBackgroundColor);
243  graphics->fillRectangle(Rect(0, 0, width, height));
244  }
245 
246  // First, determine how many rows we need to draw,
247  // and where we should start.
248  int rHeight = getRowHeight();
249  if (rHeight == 0)
250  rHeight = 1;
251  int first_row = -(y / rHeight);
252 
253  if (first_row < 0)
254  first_row = 0;
255 
256  unsigned int rows_nr = CAST_U32(1 +
257  height / rHeight); // May overestimate by one.
258  unsigned int max_rows_nr;
259  if (mModel->getRows() < first_row)
260  {
261  max_rows_nr = 0U;
262  }
263  else
264  {
265  max_rows_nr = CAST_U32(
266  mModel->getRows() - first_row); // clip if neccessary:
267  }
268  if (max_rows_nr < rows_nr)
269  rows_nr = max_rows_nr;
270 
271  // Now determine the first and last column
272  // Take the easy way out; these are usually bounded and all visible.
273  const unsigned first_column = 0;
274  const unsigned last_column1 = CAST_U32(
275  mModel->getColumns());
276 
277  int y_offset = first_row * rHeight;
278 
279  for (unsigned int r = CAST_U32(first_row);
280  r < CAST_U32(first_row) + rows_nr;
281  ++r)
282  {
283  int x_offset = 0;
284 
285  for (unsigned c = first_column; c + 1 <= last_column1; ++c)
286  {
287  Widget *const widget = mModel->getElementAt(CAST_S32(r),
288  CAST_S32(c));
289  const int cWidth = CAST_S32(getColumnWidth(
290  CAST_S32(c)));
291  if (widget != nullptr)
292  {
293  Rect bounds(x_offset, y_offset, cWidth, rHeight);
294 
295  if (widget == mTopWidget)
296  {
297  bounds.height = widget->getHeight();
298  bounds.width = widget->getWidth();
299  }
300 
301  widget->setDimension(bounds);
302 
303  if (mSelectedRow > -1)
304  {
306  mAlpha * 255.0F);
307  graphics->setColor(mHighlightColor);
308 
309  if (mLinewiseMode && r == CAST_U32(
310  mSelectedRow) && c == 0)
311  {
312  graphics->fillRectangle(Rect(0, y_offset,
313  width, rHeight));
314  }
315  else if (!mLinewiseMode && mSelectedColumn > 0
316  && c == CAST_U32(mSelectedColumn)
317  && r == CAST_U32(mSelectedRow))
318  {
319  graphics->fillRectangle(Rect(
320  x_offset, y_offset, cWidth, rHeight));
321  }
322  }
323  graphics->pushClipArea(bounds);
324  widget->draw(graphics);
325  graphics->popClipArea();
326  }
327 
328  x_offset += cWidth;
329  }
330 
331  y_offset += rHeight;
332  }
333 
334  if (mTopWidget != nullptr)
335  {
336  const Rect &bounds = mTopWidget->getDimension();
337  graphics->pushClipArea(bounds);
338  mTopWidget->draw(graphics);
339  graphics->popClipArea();
340  }
341  BLOCK_END("GuiTable::draw")
342 }
#define CAST_U32
Definition: cast.h:30
int getWidth() const
Definition: widget.h:220
virtual void draw(Graphics *const graphics)=0
unsigned int a
Definition: color.h:250
virtual int getColumns() const =0
int getColumnWidth(const int i) const
Definition: guitable.cpp:145
Definition: rect.h:72
int getRowHeight() const
Definition: guitable.cpp:140
#define BLOCK_START(name)
Definition: perfomance.h:78
void setDimension(const Rect &dimension)
Definition: widget.cpp:168
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:79
virtual void popClipArea()
Definition: graphics.cpp:738
Widget * mTopWidget
Definition: guitable.h:188
virtual int getRows() const =0
TableModel * mModel
Definition: guitable.h:185
Settings settings
Definition: settings.cpp:31
Color mBackgroundColor
Definition: widget.h:1090
virtual void setColor(const Color &color)
Definition: graphics.h:319
#define CAST_S32
Definition: cast.h:29
int mSelectedRow
Definition: guitable.h:198
Color mHighlightColor
Definition: guitable.h:196
const Rect & getDimension() const
Definition: widget.h:316
int mSelectedColumn
Definition: guitable.h:199
virtual void fillRectangle(const Rect &rectangle)=0
Definition: widget.h:97
const bool Opaque_true
Definition: opaque.h:29
Opaque mOpaque
Definition: guitable.h:203
int getHeight() const
Definition: widget.h:239
virtual void pushClipArea(const Rect &area)
Definition: graphics.cpp:676
bool mLinewiseMode
Definition: guitable.h:201
Rect mDimension
Definition: widget.h:1100
static float mAlpha
Definition: guitable.h:183
virtual Widget * getElementAt(const int row, const int column) const =0

◆ getChildrenArea()

Rect GuiTable::getChildrenArea ( )
virtual

Gets the area of the widget occupied by the widget's children. By default this method returns an empty rectangle as not all widgets are containers. If you want to make a container this method should return the area where the children resides. This method is used when drawing children of a widget when computing clip rectangles for the children.

An example of a widget that overloads this method is ScrollArea. A ScrollArea has a view of its contant and that view is the children area. The size of a ScrollArea's children area might vary depending on if the scroll bars of the ScrollArea is shown or not.

Returns
The area of the widget occupied by the widget's children.
See also
BasicContainer
BasicContainer::getChildrenArea
BasicContainer::drawChildren

Reimplemented from Widget.

Definition at line 475 of file guitable.cpp.

References Rect::height, Widget::mDimension, and Rect::width.

Referenced by setWrappingEnabled().

476 {
477  return Rect(0, 0, mDimension.width, mDimension.height);
478 }
int width
Definition: rect.h:218
Definition: rect.h:72
int height
Definition: rect.h:223
Rect mDimension
Definition: widget.h:1100

◆ getColumnForX()

int GuiTable::getColumnForX ( const int  x) const
private

Definition at line 630 of file guitable.cpp.

References TableModel::getColumns(), getColumnWidth(), and mModel.

Referenced by getWidgetAt(), mouseDragged(), mousePressed(), and setSelectableGui().

631 {
632  int column;
633  int delta = 0;
634 
635  const int colnum = mModel->getColumns();
636  for (column = 0; column < colnum; column ++)
637  {
638  delta += getColumnWidth(column);
639  if (x <= delta)
640  break;
641  }
642 
643  if (column < 0 || column >= colnum)
644  return -1;
645  return column;
646 }
virtual int getColumns() const =0
int getColumnWidth(const int i) const
Definition: guitable.cpp:145
TableModel * mModel
Definition: guitable.h:185

◆ getColumnWidth()

int GuiTable::getColumnWidth ( const int  i) const
protected

Definition at line 145 of file guitable.cpp.

References TableModel::getColumnWidth(), and mModel.

Referenced by draw(), getColumnForX(), recomputeDimensions(), safeDraw(), and setSelectableGui().

146 {
147  return mModel->getColumnWidth(i) + 4; // border
148 }
TableModel * mModel
Definition: guitable.h:185
virtual int getColumnWidth(const int index) const =0

◆ getModel()

const TableModel * GuiTable::getModel ( ) const

Retrieves the active table model

Definition at line 79 of file guitable.cpp.

References mModel.

80 {
81  return mModel;
82 }
TableModel * mModel
Definition: guitable.h:185

◆ getRowForY()

int GuiTable::getRowForY ( const int  y) const
private

Definition at line 617 of file guitable.cpp.

References getRowHeight(), TableModel::getRows(), and mModel.

Referenced by getWidgetAt(), mouseDragged(), mousePressed(), and setSelectableGui().

618 {
619  int row = -1;
620 
621  const int rowHeight = getRowHeight();
622  if (rowHeight > 0)
623  row = y / rowHeight;
624 
625  if (row < 0 || row >= mModel->getRows())
626  return -1;
627  return row;
628 }
int getRowHeight() const
Definition: guitable.cpp:140
virtual int getRows() const =0
TableModel * mModel
Definition: guitable.h:185

◆ getRowHeight()

int GuiTable::getRowHeight ( ) const
protected

Definition at line 140 of file guitable.cpp.

References TableModel::getRowHeight(), and mModel.

Referenced by draw(), getRowForY(), recomputeDimensions(), safeDraw(), and setSelectableGui().

141 {
142  return mModel->getRowHeight() + 4; // border
143 }
virtual int getRowHeight() const =0
TableModel * mModel
Definition: guitable.h:185

◆ getSelectedColumn()

int GuiTable::getSelectedColumn ( ) const

Definition at line 135 of file guitable.cpp.

References mSelectedColumn.

136 {
137  return mSelectedColumn;
138 }
int mSelectedColumn
Definition: guitable.h:199

◆ getSelectedRow()

int GuiTable::getSelectedRow ( ) const

Definition at line 130 of file guitable.cpp.

References mSelectedRow.

Referenced by Setup_Relations::action(), mouseWheelMovedDown(), and mouseWheelMovedUp().

131 {
132  return mSelectedRow;
133 }
int mSelectedRow
Definition: guitable.h:198

◆ getWidgetAt()

Widget * GuiTable::getWidgetAt ( int  x,
int  y 
)
virtual

Gets a widget from a certain position in the widget. This function is used to decide which gets mouse input, thus it can be overloaded to change that behaviour.

NOTE: This always returns NULL if the widget is not a container.

Parameters
xThe x coordinate of the widget to get.
yThe y coordinate of the widget to get.
Returns
The widget at the specified coodinate, NULL if no widget is found.

Reimplemented from Widget.

Definition at line 594 of file guitable.cpp.

References getColumnForX(), Widget::getDimension(), TableModel::getElementAt(), getRowForY(), Widget::isFocusable(), Rect::isPointInRect(), mModel, and mTopWidget.

Referenced by setLinewiseSelection().

595 {
596  if (mModel == nullptr)
597  return nullptr;
598 
599  const int row = getRowForY(y);
600  const int column = getColumnForX(x);
601 
602  if (mTopWidget != nullptr &&
604  {
605  return mTopWidget;
606  }
607 
608  if (row > -1 && column > -1)
609  {
610  Widget *const w = mModel->getElementAt(row, column);
611  if (w != nullptr && w->isFocusable())
612  return w;
613  }
614  return nullptr;
615 }
bool isPointInRect(const int x_, const int y_) const
Definition: rect.h:196
Widget * mTopWidget
Definition: guitable.h:188
TableModel * mModel
Definition: guitable.h:185
const Rect & getDimension() const
Definition: widget.h:316
int getColumnForX(const int x) const
Definition: guitable.cpp:630
int getRowForY(const int y) const
Definition: guitable.cpp:617
Definition: widget.h:97
bool isFocusable() const
Definition: widget.cpp:198
virtual Widget * getElementAt(const int row, const int column) const =0

◆ installActionListeners()

void GuiTable::installActionListeners ( )
protected

Installs all action listeners on inner widgets.

Definition at line 204 of file guitable.cpp.

References TableModel::getColumns(), TableModel::getElementAt(), Widget::getFocusHandler(), TableModel::getRows(), GuiTableActionListener, mActionListeners2, mModel, and setFocusHandler().

Referenced by modelUpdated(), setModel(), and setSelectableGui().

205 {
206  const int rows = mModel->getRows();
207  const int columns = mModel->getColumns();
208 
209  for (int row = 0; row < rows; ++row)
210  {
211  for (int column = 0; column < columns; ++column)
212  {
213  Widget *const widget = mModel->getElementAt(row, column);
214  if (widget != nullptr)
215  {
217  this, widget, row, column));
218  }
219  }
220  }
221 
223 }
std::vector< GuiTableActionListener * > mActionListeners2
Definition: guitable.h:191
virtual int getColumns() const =0
FocusHandler * getFocusHandler()
Definition: widget.h:473
virtual int getRows() const =0
TableModel * mModel
Definition: guitable.h:185
void setFocusHandler(FocusHandler *const focusHandler)
Definition: guitable.cpp:648
friend class GuiTableActionListener
Definition: guitable.h:54
Definition: widget.h:97
virtual Widget * getElementAt(const int row, const int column) const =0

◆ isOpaque()

bool GuiTable::isOpaque ( ) const
inline

Checks if the table is opaque, that is if the table area displays its background.

Returns
True if the table is opaque, false otherwise.

Definition at line 145 of file guitable.h.

References modelUpdated(), mOpaque, mouseDragged(), mousePressed(), mouseWheelMovedDown(), mouseWheelMovedUp(), Opaque_true, and requestFocus().

146  { return mOpaque == Opaque_true; }
const bool Opaque_true
Definition: opaque.h:29
Opaque mOpaque
Definition: guitable.h:203

◆ isWrappingEnabled()

bool GuiTable::isWrappingEnabled ( ) const
inline

Definition at line 90 of file guitable.h.

References mWrappingEnabled.

91  { return mWrappingEnabled; }
bool mWrappingEnabled
Definition: guitable.h:202

◆ keyPressed()

void GuiTable::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 481 of file guitable.cpp.

References Widget::distributeActionEvent(), TableModel::getColumns(), TableModel::getRows(), InputAction::GUI_DOWN, InputAction::GUI_END, InputAction::GUI_HOME, InputAction::GUI_LEFT, InputAction::GUI_RIGHT, InputAction::GUI_SELECT, InputAction::GUI_UP, mModel, mSelectedColumn, mSelectedRow, setSelectedColumn(), and setSelectedRow().

Referenced by setLinewiseSelection().

482 {
483  const InputActionT action = event.getActionId();
484 
485  if (action == InputAction::GUI_SELECT)
486  {
488  event.consume();
489  }
490  else if (action == InputAction::GUI_UP)
491  {
493  event.consume();
494  }
495  else if (action == InputAction::GUI_DOWN)
496  {
498  event.consume();
499  }
500  else if (action == InputAction::GUI_LEFT)
501  {
503  event.consume();
504  }
505  else if (action == InputAction::GUI_RIGHT)
506  {
508  event.consume();
509  }
510  else if (action == InputAction::GUI_HOME)
511  {
512  setSelectedRow(0);
514  event.consume();
515  }
516  else if (action == InputAction::GUI_END && (mModel != nullptr))
517  {
518  setSelectedRow(mModel->getRows() - 1);
520  event.consume();
521  }
522 }
virtual int getColumns() const =0
virtual int getRows() const =0
TableModel * mModel
Definition: guitable.h:185
void distributeActionEvent()
Definition: widget.cpp:492
void setSelectedColumn(const int selected)
Definition: guitable.cpp:179
int mSelectedRow
Definition: guitable.h:198
InputAction ::T InputActionT
Definition: inputaction.h:714
int mSelectedColumn
Definition: guitable.h:199
void setSelectedRow(const int selected)
Definition: guitable.cpp:150

◆ modelUpdated()

void GuiTable::modelUpdated ( const bool  completed)
virtual

Must be invoked by the TableModel whenever a global change is about to occur or has occurred (e.g., when a row or column is being removed or added).

This method is triggered twice, once before and once after the update.

Parameters
completedwhether we are signalling the end of the update

Implements TableModelListener.

Definition at line 580 of file guitable.cpp.

References installActionListeners(), mTopWidget, recomputeDimensions(), and uninstallActionListeners().

Referenced by isOpaque().

581 {
582  if (completed)
583  {
586  }
587  else
588  { // before the update?
589  mTopWidget = nullptr; // No longer valid in general
591  }
592 }
void installActionListeners()
Definition: guitable.cpp:204
Widget * mTopWidget
Definition: guitable.h:188
void recomputeDimensions()
Definition: guitable.cpp:99
void uninstallActionListeners()
Definition: guitable.cpp:198

◆ mouseDragged()

void GuiTable::mouseDragged ( MouseEvent event)
virtual

Called when the mouse has moved and the mouse has previously been pressed on the widget.

Parameters
eventDescribes the event.

Reimplemented from MouseListener.

Definition at line 567 of file guitable.cpp.

References MouseEvent::getButton(), getColumnForX(), getRowForY(), MouseEvent::getX(), MouseEvent::getY(), MouseButton::LEFT, setSelectedColumn(), setSelectedRow(), x, and y.

Referenced by isOpaque().

568 {
569  if (event.getButton() != MouseButton::LEFT)
570  return;
571 
572  // Make table selection update on drag
573  const int x = std::max(0, event.getX());
574  const int y = std::max(0, event.getY());
575 
578 }
MouseButtonT getButton() const
Definition: mouseevent.h:115
void setSelectedColumn(const int selected)
Definition: guitable.cpp:179
int getColumnForX(const int x) const
Definition: guitable.cpp:630
int getRowForY(const int y) const
Definition: guitable.cpp:617
int getY() const
Definition: mouseevent.h:137
int getX() const
Definition: mouseevent.h:126
void setSelectedRow(const int selected)
Definition: guitable.cpp:150

◆ mousePressed()

void GuiTable::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 525 of file guitable.cpp.

References Widget::distributeActionEvent(), MouseEvent::getButton(), getColumnForX(), TableModel::getColumns(), getRowForY(), MouseEvent::getX(), MouseEvent::getY(), MouseButton::LEFT, mModel, mSelectableGui, mSelectedColumn, and mSelectedRow.

Referenced by isOpaque().

526 {
527  if (!mSelectableGui)
528  return;
529 
530  if (event.getButton() == MouseButton::LEFT)
531  {
532  const int row = getRowForY(event.getY());
533  const int column = getColumnForX(event.getX());
534 
535  if (row > -1 && column > -1 &&
536  row < mModel->getRows() && column < mModel->getColumns())
537  {
538  mSelectedColumn = column;
539  mSelectedRow = row;
540  event.consume();
541  }
542 
544  }
545 }
bool mSelectableGui
Definition: guitable.h:204
virtual int getColumns() const =0
MouseButtonT getButton() const
Definition: mouseevent.h:115
TableModel * mModel
Definition: guitable.h:185
void distributeActionEvent()
Definition: widget.cpp:492
int mSelectedRow
Definition: guitable.h:198
int mSelectedColumn
Definition: guitable.h:199
int getColumnForX(const int x) const
Definition: guitable.cpp:630
int getRowForY(const int y) const
Definition: guitable.cpp:617
int getY() const
Definition: mouseevent.h:137
int getX() const
Definition: mouseevent.h:126

◆ mouseWheelMovedDown()

void GuiTable::mouseWheelMovedDown ( MouseEvent event)
virtual

Called when the mouse wheel has moved down on the widget area.

Parameters
eventDescribes the event.

Reimplemented from MouseListener.

Definition at line 558 of file guitable.cpp.

References getSelectedRow(), Widget::isFocused(), and setSelectedRow().

Referenced by isOpaque().

559 {
560  if (isFocused())
561  {
563  event.consume();
564  }
565 }
virtual bool isFocused() const
Definition: widget.cpp:183
int getSelectedRow() const
Definition: guitable.cpp:130
void setSelectedRow(const int selected)
Definition: guitable.cpp:150

◆ mouseWheelMovedUp()

void GuiTable::mouseWheelMovedUp ( MouseEvent event)
virtual

Called when the mouse wheel has moved up on the widget area.

Parameters
eventDescribes the event.

Reimplemented from MouseListener.

Definition at line 547 of file guitable.cpp.

References getSelectedRow(), Widget::isFocused(), mWrappingEnabled, and setSelectedRow().

Referenced by isOpaque().

548 {
549  if (isFocused())
550  {
551  const int selRow = getSelectedRow();
552  if (selRow > 0 || (selRow == 0 && mWrappingEnabled))
553  setSelectedRow(selRow - 1);
554  event.consume();
555  }
556 }
virtual bool isFocused() const
Definition: widget.cpp:183
int getSelectedRow() const
Definition: guitable.cpp:130
bool mWrappingEnabled
Definition: guitable.h:202
void setSelectedRow(const int selected)
Definition: guitable.cpp:150

◆ moveToBottom()

void GuiTable::moveToBottom ( Widget *const  widget)
virtual

Moves a widget in this widget to the bottom of this widget. The moved widget will be drawn below all other widgets in this widget.

Parameters
widgetThe widget to move to the bottom.
See also
moveToTop

Reimplemented from Widget.

Definition at line 468 of file guitable.cpp.

References Widget::moveToBottom(), and mTopWidget.

Referenced by setLinewiseSelection().

469 {
470  Widget::moveToBottom(widget);
471  if (widget == mTopWidget)
472  mTopWidget = nullptr;
473 }
Widget * mTopWidget
Definition: guitable.h:188
virtual void moveToBottom(Widget *widget)
Definition: widget.h:876

◆ moveToTop()

void GuiTable::moveToTop ( Widget *const  widget)
virtual

Moves a widget to the top of this widget. The moved widget will be drawn above all other widgets in this widget.

Parameters
widgetThe widget to move to the top.
See also
moveToBottom

Reimplemented from Widget.

Definition at line 462 of file guitable.cpp.

References Widget::moveToTop(), and mTopWidget.

Referenced by setLinewiseSelection().

463 {
464  Widget::moveToTop(widget);
465  mTopWidget = widget;
466 }
Widget * mTopWidget
Definition: guitable.h:188
virtual void moveToTop(Widget *widget)
Definition: widget.h:866

◆ recomputeDimensions()

void GuiTable::recomputeDimensions ( )
private

Definition at line 99 of file guitable.cpp.

References TableModel::getColumns(), getColumnWidth(), getRowHeight(), TableModel::getRows(), mModel, mSelectableGui, mSelectedColumn, mSelectedRow, Widget::setHeight(), and Widget::setWidth().

Referenced by modelUpdated(), setModel(), and setSelectableGui().

100 {
101  if (mModel == nullptr)
102  return;
103 
104  const int rows_nr = mModel->getRows();
105  const int columns_nr = mModel->getColumns();
106  int width = 0;
107 
108  if (mSelectableGui)
109  {
110  if (mSelectedRow >= rows_nr)
111  mSelectedRow = rows_nr - 1;
112 
113  if (mSelectedColumn >= columns_nr)
114  mSelectedColumn = columns_nr - 1;
115  }
116 
117  for (int i = 0; i < columns_nr; i++)
118  width += getColumnWidth(i);
119 
120  setWidth(width);
121  setHeight(getRowHeight() * rows_nr);
122 }
void setWidth(const int width)
Definition: widget.cpp:132
bool mSelectableGui
Definition: guitable.h:204
virtual int getColumns() const =0
int getColumnWidth(const int i) const
Definition: guitable.cpp:145
int getRowHeight() const
Definition: guitable.cpp:140
virtual int getRows() const =0
TableModel * mModel
Definition: guitable.h:185
int mSelectedRow
Definition: guitable.h:198
int mSelectedColumn
Definition: guitable.h:199
void setHeight(const int height)
Definition: widget.cpp:139

◆ requestFocus()

void GuiTable::requestFocus ( )
virtual

Requests focus for the widget. A widget will only recieve focus if it is focusable.

Reimplemented from Widget.

Definition at line 670 of file guitable.cpp.

References Widget::mFocusHandler, and Widget::requestFocus().

Referenced by isOpaque().

671 {
672  if (mFocusHandler == nullptr)
673  return;
675 }
FocusHandler * mFocusHandler
Definition: widget.h:1115
virtual void requestFocus()
Definition: widget.cpp:203

◆ safeDraw()

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

Implements Widget.

Definition at line 344 of file guitable.cpp.

References Color::a, BLOCK_END, BLOCK_START, CAST_S32, CAST_U32, Graphics::fillRectangle(), TableModel::getColumns(), getColumnWidth(), Widget::getDimension(), TableModel::getElementAt(), Widget::getHeight(), getRowHeight(), TableModel::getRows(), Widget::getWidth(), Settings::guiAlpha, Rect::height, mAlpha, Widget::mBackgroundColor, Widget::mDimension, mHighlightColor, mLinewiseMode, mModel, mOpaque, mSelectedColumn, mSelectedRow, mTopWidget, Opaque_true, Graphics::popClipArea(), Graphics::pushClipArea(), Widget::safeDraw(), Graphics::setColor(), Widget::setDimension(), settings, Rect::width, y, and Rect::y.

Referenced by setLinewiseSelection().

345 {
346  if (getRowHeight() == 0)
347  return;
348 
349  BLOCK_START("GuiTable::draw")
350  if (settings.guiAlpha != mAlpha)
351  mAlpha = settings.guiAlpha;
352 
353  const Rect &rect = mDimension;
354  const int width = rect.width;
355  const int height = rect.height;
356  const int y = rect.y;
357  if (mOpaque == Opaque_true)
358  {
359  mBackgroundColor.a = CAST_U32(mAlpha * 255.0F);
360  graphics->setColor(mBackgroundColor);
361  graphics->fillRectangle(Rect(0, 0, width, height));
362  }
363 
364  // First, determine how many rows we need to draw,
365  // and where we should start.
366  int rHeight = getRowHeight();
367  if (rHeight == 0)
368  rHeight = 1;
369  int first_row = -(y / rHeight);
370 
371  if (first_row < 0)
372  first_row = 0;
373 
374  unsigned int rows_nr = CAST_U32(
375  1 + height / rHeight); // May overestimate by one.
376  unsigned int max_rows_nr;
377  if (mModel->getRows() < first_row)
378  {
379  max_rows_nr = 0;
380  }
381  else
382  {
383  max_rows_nr = CAST_U32(
384  mModel->getRows() - first_row); // clip if neccessary:
385  }
386  if (max_rows_nr < rows_nr)
387  rows_nr = max_rows_nr;
388 
389  // Now determine the first and last column
390  // Take the easy way out; these are usually bounded and all visible.
391  const unsigned int first_column = 0;
392  const unsigned int last_column1 = CAST_U32(
393  mModel->getColumns());
394 
395  int y_offset = first_row * rHeight;
396 
397  for (unsigned int r = CAST_U32(first_row);
398  r < CAST_U32(first_row + CAST_S32(rows_nr));
399  ++r)
400  {
401  int x_offset = 0;
402 
403  for (unsigned c = first_column; c + 1 <= last_column1; ++c)
404  {
405  Widget *const widget = mModel->getElementAt(CAST_S32(r),
406  CAST_S32(c));
407  const int cWidth = CAST_S32(getColumnWidth(
408  CAST_S32(c)));
409  if (widget != nullptr)
410  {
411  Rect bounds(x_offset, y_offset, cWidth, rHeight);
412 
413  if (widget == mTopWidget)
414  {
415  bounds.height = widget->getHeight();
416  bounds.width = widget->getWidth();
417  }
418 
419  widget->setDimension(bounds);
420 
421  if (mSelectedRow > -1)
422  {
424  mAlpha * 255.0F);
425  graphics->setColor(mHighlightColor);
426 
427  if (mLinewiseMode && r == CAST_U32(
428  mSelectedRow) && c == 0)
429  {
430  graphics->fillRectangle(Rect(0, y_offset,
431  width, rHeight));
432  }
433  else if (!mLinewiseMode && mSelectedColumn > 0
434  && c == CAST_U32(mSelectedColumn)
435  && r == CAST_U32(mSelectedRow))
436  {
437  graphics->fillRectangle(Rect(
438  x_offset, y_offset, cWidth, rHeight));
439  }
440  }
441  graphics->pushClipArea(bounds);
442  widget->safeDraw(graphics);
443  graphics->popClipArea();
444  }
445 
446  x_offset += cWidth;
447  }
448 
449  y_offset += rHeight;
450  }
451 
452  if (mTopWidget != nullptr)
453  {
454  const Rect &bounds = mTopWidget->getDimension();
455  graphics->pushClipArea(bounds);
456  mTopWidget->safeDraw(graphics);
457  graphics->popClipArea();
458  }
459  BLOCK_END("GuiTable::draw")
460 }
#define CAST_U32
Definition: cast.h:30
int getWidth() const
Definition: widget.h:220
unsigned int a
Definition: color.h:250
virtual int getColumns() const =0
int getColumnWidth(const int i) const
Definition: guitable.cpp:145
Definition: rect.h:72
int getRowHeight() const
Definition: guitable.cpp:140
virtual void safeDraw(Graphics *const graphics)=0
#define BLOCK_START(name)
Definition: perfomance.h:78
void setDimension(const Rect &dimension)
Definition: widget.cpp:168
if(!vert) return
#define BLOCK_END(name)
Definition: perfomance.h:79
virtual void popClipArea()
Definition: graphics.cpp:738
Widget * mTopWidget
Definition: guitable.h:188
virtual int getRows() const =0
TableModel * mModel
Definition: guitable.h:185
Settings settings
Definition: settings.cpp:31
Color mBackgroundColor
Definition: widget.h:1090
virtual void setColor(const Color &color)
Definition: graphics.h:319
#define CAST_S32
Definition: cast.h:29
int mSelectedRow
Definition: guitable.h:198
Color mHighlightColor
Definition: guitable.h:196
const Rect & getDimension() const
Definition: widget.h:316
int mSelectedColumn
Definition: guitable.h:199
virtual void fillRectangle(const Rect &rectangle)=0
Definition: widget.h:97
const bool Opaque_true
Definition: opaque.h:29
Opaque mOpaque
Definition: guitable.h:203
int getHeight() const
Definition: widget.h:239
virtual void pushClipArea(const Rect &area)
Definition: graphics.cpp:676
bool mLinewiseMode
Definition: guitable.h:201
Rect mDimension
Definition: widget.h:1100
static float mAlpha
Definition: guitable.h:183
virtual Widget * getElementAt(const int row, const int column) const =0

◆ setFocusHandler()

void GuiTable::setFocusHandler ( FocusHandler *const  focusHandler)
virtual

Sets the focus handler to be used.

WARNING: This function is used internally and should not be called or overloaded unless you know what you are doing.

Parameters
focusHandlerThe focus handler to use.
See also
getFocusHandler

Reimplemented from Widget.

Definition at line 648 of file guitable.cpp.

References TableModel::getColumns(), TableModel::getElementAt(), TableModel::getRows(), mModel, and Widget::setFocusHandler().

Referenced by installActionListeners(), and setLinewiseSelection().

649 {
650  // add check for focusHandler. may be need remove it?
651 
652  if (focusHandler == nullptr)
653  return;
654 
655  Widget::setFocusHandler(focusHandler);
656 
657  const int rows = mModel->getRows();
658  const int cols = mModel->getColumns();
659  for (int r = 0; r < rows; ++r)
660  {
661  for (int c = 0; c < cols ; ++c)
662  {
663  Widget *const w = mModel->getElementAt(r, c);
664  if (w != nullptr)
665  w->setFocusHandler(focusHandler);
666  }
667  }
668 }
virtual int getColumns() const =0
virtual int getRows() const =0
TableModel * mModel
Definition: guitable.h:185
Definition: widget.h:97
virtual void setFocusHandler(FocusHandler *const focusHandler)
Definition: widget.cpp:237
virtual Widget * getElementAt(const int row, const int column) const =0

◆ setLinewiseSelection()

void GuiTable::setLinewiseSelection ( bool  linewise)
inline

Toggle whether to use linewise selection mode, in which the table selects an entire line at a time, rather than a single cell.

Note that column information is tracked even in linewise selection mode;

this mode therefore only affects visualisation.

Disabled by default.

Parameters
linewiseWhether to enable linewise selection mode

Definition at line 111 of file guitable.h.

References A_NONNULL, A_WARN_UNUSED, draw(), getWidgetAt(), keyPressed(), mLinewiseMode, moveToBottom(), moveToTop(), safeDraw(), setFocusHandler(), x, and y.

Referenced by Setup_Relations::Setup_Relations().

112  { mLinewiseMode = linewise; }
bool mLinewiseMode
Definition: guitable.h:201

◆ setModel()

void GuiTable::setModel ( TableModel *const  m)

Sets the table model

Note that actions issued by widgets returned from the model will update the table selection, but only AFTER any event handlers installed within the widget have been triggered. To be notified after such an update, add an action listener to the table instead.

Definition at line 84 of file guitable.cpp.

References installActionListeners(), TableModel::installListener(), mModel, recomputeDimensions(), TableModel::removeListener(), and uninstallActionListeners().

Referenced by GuiTable(), and Setup_Relations::updateAll().

85 {
86  if (mModel != nullptr)
87  {
89  mModel->removeListener(this);
90  }
91 
92  mModel = new_model;
94 
95  new_model->installListener(this);
97 }
void installActionListeners()
Definition: guitable.cpp:204
void recomputeDimensions()
Definition: guitable.cpp:99
TableModel * mModel
Definition: guitable.h:185
virtual void removeListener(TableModelListener *const listener)
Definition: tablemodel.cpp:39
void uninstallActionListeners()
Definition: guitable.cpp:198

◆ setOpaque()

void GuiTable::setOpaque ( Opaque  opaque)
inline

Sets the table to be opaque, that is sets the table to display its background.

Parameters
opaqueTrue if the table should be opaque, false otherwise.

Definition at line 136 of file guitable.h.

References mOpaque.

Referenced by Setup_Relations::Setup_Relations().

137  { mOpaque = opaque; }
Opaque mOpaque
Definition: guitable.h:203

◆ setSelectableGui()

void GuiTable::setSelectableGui ( bool  b)
inline

◆ setSelected()

void GuiTable::setSelected ( const int  row,
const int  column 
)

Definition at line 124 of file guitable.cpp.

References mSelectedColumn, and mSelectedRow.

Referenced by GuiTableActionListener::action().

125 {
126  mSelectedColumn = column;
127  mSelectedRow = row;
128 }
int mSelectedRow
Definition: guitable.h:198
int mSelectedColumn
Definition: guitable.h:199

◆ setSelectedColumn()

void GuiTable::setSelectedColumn ( const int  selected)

Definition at line 179 of file guitable.cpp.

References TableModel::getColumns(), mModel, mSelectedColumn, and mWrappingEnabled.

Referenced by keyPressed(), and mouseDragged().

180 {
181  const int columns = mModel->getColumns();
182  if ((selected >= columns && mWrappingEnabled) ||
183  (selected < 0 && !mWrappingEnabled))
184  {
185  mSelectedColumn = 0;
186  }
187  else if ((selected >= columns && !mWrappingEnabled) ||
188  (selected < 0 && mWrappingEnabled))
189  {
190  mSelectedColumn = columns - 1;
191  }
192  else
193  {
194  mSelectedColumn = selected;
195  }
196 }
virtual int getColumns() const =0
TableModel * mModel
Definition: guitable.h:185
bool mWrappingEnabled
Definition: guitable.h:202
int mSelectedColumn
Definition: guitable.h:199

◆ setSelectedRow()

void GuiTable::setSelectedRow ( const int  selected)

Definition at line 150 of file guitable.cpp.

References TableModel::getRows(), mModel, mSelectableGui, mSelectedRow, and mWrappingEnabled.

Referenced by keyPressed(), mouseDragged(), mouseWheelMovedDown(), and mouseWheelMovedUp().

151 {
152  if (!mSelectableGui)
153  {
154  mSelectedRow = -1;
155  }
156  else
157  {
158  const int rows = mModel->getRows();
159  if (selected < 0 && !mWrappingEnabled)
160  {
161  mSelectedRow = -1;
162  }
163  else if (selected >= rows && mWrappingEnabled)
164  {
165  mSelectedRow = 0;
166  }
167  else if ((selected >= rows && !mWrappingEnabled) ||
168  (selected < 0 && mWrappingEnabled))
169  {
170  mSelectedRow = rows - 1;
171  }
172  else
173  {
174  mSelectedRow = selected;
175  }
176  }
177 }
bool mSelectableGui
Definition: guitable.h:204
virtual int getRows() const =0
TableModel * mModel
Definition: guitable.h:185
int mSelectedRow
Definition: guitable.h:198
bool mWrappingEnabled
Definition: guitable.h:202

◆ setWrappingEnabled()

void GuiTable::setWrappingEnabled ( bool  wrappingEnabled)
inline

Definition at line 93 of file guitable.h.

References A_WARN_UNUSED, getChildrenArea(), and mWrappingEnabled.

94  { mWrappingEnabled = wrappingEnabled; }
bool mWrappingEnabled
Definition: guitable.h:202

◆ uninstallActionListeners()

void GuiTable::uninstallActionListeners ( )
protected

Frees all action listeners on inner widgets.

Definition at line 198 of file guitable.cpp.

References delete_all(), and mActionListeners2.

Referenced by modelUpdated(), setModel(), setSelectableGui(), and ~GuiTable().

199 {
201  mActionListeners2.clear();
202 }
std::vector< GuiTableActionListener * > mActionListeners2
Definition: guitable.h:191
void delete_all(Container &c)
Definition: dtor.h:55

Friends And Related Function Documentation

◆ GuiTableActionListener

friend class GuiTableActionListener
friend

Definition at line 54 of file guitable.h.

Referenced by installActionListeners().

Field Documentation

◆ mActionListeners2

std::vector<GuiTableActionListener *> GuiTable::mActionListeners2
private

Vector for compactness; used as a list in practice.

Definition at line 191 of file guitable.h.

Referenced by installActionListeners(), and uninstallActionListeners().

◆ mAlpha

float GuiTable::mAlpha = 1.0
staticprivate

Definition at line 183 of file guitable.h.

Referenced by draw(), and safeDraw().

◆ mHighlightColor

Color GuiTable::mHighlightColor
private

Holds the background color of the table.

Definition at line 196 of file guitable.h.

Referenced by draw(), and safeDraw().

◆ mLinewiseMode

bool GuiTable::mLinewiseMode
private

Definition at line 201 of file guitable.h.

Referenced by draw(), safeDraw(), and setLinewiseSelection().

◆ mModel

TableModel* GuiTable::mModel
private

◆ mOpaque

Opaque GuiTable::mOpaque
private

Definition at line 203 of file guitable.h.

Referenced by draw(), isOpaque(), safeDraw(), and setOpaque().

◆ mSelectableGui

bool GuiTable::mSelectableGui
private

Definition at line 204 of file guitable.h.

Referenced by mousePressed(), recomputeDimensions(), setSelectableGui(), and setSelectedRow().

◆ mSelectedColumn

int GuiTable::mSelectedColumn
private

◆ mSelectedRow

int GuiTable::mSelectedRow
private

◆ mTopWidget

Widget* GuiTable::mTopWidget
private

If someone moves a fresh widget to the top, we must display it.

Definition at line 188 of file guitable.h.

Referenced by draw(), getWidgetAt(), modelUpdated(), moveToBottom(), moveToTop(), and safeDraw().

◆ mWrappingEnabled

bool GuiTable::mWrappingEnabled
private

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