2015-09-25 21:37:19 +02:00
|
|
|
// File: flistbox.h
|
|
|
|
// Provides: class FListBoxItem
|
|
|
|
// class FListBox
|
|
|
|
//
|
|
|
|
// Inheritance diagram
|
|
|
|
// ═══════════════════
|
|
|
|
//
|
|
|
|
// ▕▔▔▔▔▔▔▔▔▔▏ ▕▔▔▔▔▔▔▔▔▔▏
|
|
|
|
// ▕ FObject ▏ ▕ FTerm ▏
|
|
|
|
// ▕▁▁▁▁▁▁▁▁▁▏ ▕▁▁▁▁▁▁▁▁▁▏
|
|
|
|
// ▲ ▲
|
|
|
|
// │ │
|
|
|
|
// └─────┬─────┘
|
|
|
|
// │
|
2016-10-11 04:57:36 +02:00
|
|
|
// ▕▔▔▔▔▔▔▔▔▏
|
|
|
|
// ▕ FVTerm ▏
|
|
|
|
// ▕▁▁▁▁▁▁▁▁▏
|
|
|
|
// ▲
|
|
|
|
// │
|
2015-09-25 21:37:19 +02:00
|
|
|
// ▕▔▔▔▔▔▔▔▔▔▏
|
|
|
|
// ▕ FWidget ▏
|
|
|
|
// ▕▁▁▁▁▁▁▁▁▁▏
|
|
|
|
// ▲
|
|
|
|
// │
|
|
|
|
// ▕▔▔▔▔▔▔▔▔▔▔▏1 *▕▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏
|
|
|
|
// ▕ FListBox ▏- - - -▕ FListBoxItem ▏
|
|
|
|
// ▕▁▁▁▁▁▁▁▁▁▁▏ ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏
|
|
|
|
//
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-04-09 20:08:53 +02:00
|
|
|
#ifndef FLISTBOX_H
|
|
|
|
#define FLISTBOX_H
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
#include "fscrollbar.h"
|
|
|
|
#include "fstring.h"
|
|
|
|
#include "fwidget.h"
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class FListBoxItem
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
#pragma pack(push)
|
|
|
|
#pragma pack(1)
|
|
|
|
|
|
|
|
class FListBoxItem
|
|
|
|
{
|
|
|
|
public:
|
2016-09-30 04:55:28 +02:00
|
|
|
// Constructors
|
2015-05-23 13:35:12 +02:00
|
|
|
FListBoxItem ();
|
2017-02-25 15:18:29 +01:00
|
|
|
FListBoxItem (const FListBoxItem&); // copy constructor
|
2017-03-17 22:59:06 +01:00
|
|
|
explicit FListBoxItem (const FString&, FWidget::data_ptr = 0);
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2016-09-30 04:55:28 +02:00
|
|
|
// Destructor
|
2015-05-23 13:35:12 +02:00
|
|
|
virtual ~FListBoxItem();
|
2016-09-30 04:55:28 +02:00
|
|
|
|
2017-02-25 15:18:29 +01:00
|
|
|
// Assignment operator (=)
|
|
|
|
FListBoxItem& operator = (const FListBoxItem&);
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
// Accessors
|
2015-05-23 13:35:12 +02:00
|
|
|
virtual FString getText() const;
|
2017-02-24 23:16:05 +01:00
|
|
|
virtual FWidget::data_ptr getData() const;
|
2016-09-25 23:53:48 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
protected:
|
2017-02-24 23:16:05 +01:00
|
|
|
// Mutators
|
2017-03-17 22:59:06 +01:00
|
|
|
void setText (const FString&);
|
2017-02-24 00:30:07 +01:00
|
|
|
void setData (FWidget::data_ptr);
|
2016-09-25 23:53:48 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
private:
|
2016-11-02 00:37:58 +01:00
|
|
|
// Friend classes
|
2015-05-23 13:35:12 +02:00
|
|
|
friend class FListBox;
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
// Data Members
|
|
|
|
FString text;
|
2017-02-24 00:30:07 +01:00
|
|
|
FWidget::data_ptr data_pointer;
|
2016-11-02 00:37:58 +01:00
|
|
|
fc::brackets_type brackets;
|
|
|
|
bool selected;
|
2015-05-23 13:35:12 +02:00
|
|
|
};
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
// FListBoxItem inline functions
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline FString FListBoxItem::getText() const
|
2015-09-22 04:18:20 +02:00
|
|
|
{ return text; }
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-02-24 23:16:05 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline FWidget::data_ptr FListBoxItem::getData() const
|
|
|
|
{ return data_pointer; }
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
2017-03-17 22:59:06 +01:00
|
|
|
inline void FListBoxItem::setText (const FString& txt)
|
2015-09-22 04:18:20 +02:00
|
|
|
{ text = txt; }
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-02-24 00:30:07 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FListBoxItem::setData (FWidget::data_ptr data)
|
|
|
|
{ data_pointer = data; }
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class FListBox
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
#pragma pack(push)
|
|
|
|
#pragma pack(1)
|
|
|
|
|
|
|
|
class FListBox : public FWidget
|
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
public:
|
|
|
|
// Using-declaration
|
|
|
|
using FWidget::setGeometry;
|
|
|
|
|
|
|
|
// Constructor
|
|
|
|
explicit FListBox (FWidget* = 0);
|
|
|
|
|
|
|
|
// Destructor
|
|
|
|
~FListBox();
|
|
|
|
|
|
|
|
// Accessors
|
|
|
|
const char* getClassName() const;
|
|
|
|
uInt getCount() const;
|
|
|
|
FListBoxItem getItem (int) const;
|
|
|
|
int currentItem() const;
|
|
|
|
FString& getText();
|
|
|
|
|
|
|
|
// Mutators
|
|
|
|
void setCurrentItem (int);
|
|
|
|
void selectItem (int);
|
|
|
|
void unselectItem (int);
|
|
|
|
void showInsideBrackets (int, fc::brackets_type);
|
|
|
|
void showNoBrackets (int);
|
|
|
|
void setGeometry (int, int, int, int, bool = true);
|
|
|
|
void setMultiSelection (bool);
|
|
|
|
void setMultiSelection ();
|
|
|
|
void unsetMultiSelection ();
|
|
|
|
bool setEnable (bool);
|
|
|
|
bool setEnable();
|
|
|
|
bool unsetEnable();
|
|
|
|
bool setDisable();
|
|
|
|
bool setFocus (bool);
|
|
|
|
bool setFocus();
|
|
|
|
bool unsetFocus();
|
2017-03-26 20:40:04 +02:00
|
|
|
void setText (const FString&);
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
// Inquiries
|
|
|
|
bool isSelected (int) const;
|
|
|
|
bool isMultiSelection() const;
|
|
|
|
bool hasBrackets (int) const;
|
|
|
|
|
|
|
|
// Methods
|
|
|
|
void hide();
|
2017-03-26 20:40:04 +02:00
|
|
|
void insert ( const FString&
|
2016-11-02 00:37:58 +01:00
|
|
|
, fc::brackets_type = fc::NoBrackets
|
2017-02-24 00:30:07 +01:00
|
|
|
, bool = false
|
|
|
|
, data_ptr = 0);
|
2016-11-02 00:37:58 +01:00
|
|
|
void insert ( long
|
|
|
|
, fc::brackets_type = fc::NoBrackets
|
2017-02-24 00:30:07 +01:00
|
|
|
, bool = false
|
|
|
|
, data_ptr = 0 );
|
2016-11-02 00:37:58 +01:00
|
|
|
void remove (int);
|
|
|
|
void clear();
|
|
|
|
|
|
|
|
// Event handlers
|
|
|
|
void onKeyPress (FKeyEvent*);
|
|
|
|
void onMouseDown (FMouseEvent*);
|
|
|
|
void onMouseUp (FMouseEvent*);
|
|
|
|
void onMouseMove (FMouseEvent*);
|
|
|
|
void onMouseDoubleClick (FMouseEvent*);
|
|
|
|
void onWheel (FWheelEvent*);
|
|
|
|
void onTimer (FTimerEvent*);
|
|
|
|
void onFocusIn (FFocusEvent*);
|
|
|
|
void onFocusOut (FFocusEvent*);
|
|
|
|
|
|
|
|
// Callback methods
|
2017-02-24 00:30:07 +01:00
|
|
|
void cb_VBarChange (FWidget*, data_ptr);
|
|
|
|
void cb_HBarChange (FWidget*, data_ptr);
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
protected:
|
|
|
|
// Methods
|
|
|
|
void adjustYOffset();
|
|
|
|
void adjustSize();
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
private:
|
2016-11-02 00:37:58 +01:00
|
|
|
// Typedef
|
|
|
|
typedef std::vector<FListBoxItem> listBoxItem;
|
|
|
|
|
|
|
|
// Enumeration
|
2016-09-27 00:46:05 +02:00
|
|
|
enum dragScroll
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
|
|
|
noScroll = 0,
|
|
|
|
scrollUp = 1,
|
|
|
|
scrollDown = 2,
|
|
|
|
scrollUpSelect = 3,
|
|
|
|
scrollDownSelect = 4
|
|
|
|
};
|
2016-09-27 00:46:05 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
// Disable copy constructor
|
|
|
|
FListBox (const FListBox&);
|
|
|
|
|
|
|
|
// Disable assignment operator (=)
|
|
|
|
FListBox& operator = (const FListBox&);
|
|
|
|
|
|
|
|
// Methods
|
|
|
|
void init();
|
|
|
|
void draw();
|
|
|
|
void drawLabel();
|
|
|
|
void drawList();
|
|
|
|
void processClick();
|
|
|
|
void processSelect();
|
|
|
|
void processChanged();
|
|
|
|
|
|
|
|
// Data Members
|
|
|
|
listBoxItem data;
|
2016-09-27 00:46:05 +02:00
|
|
|
FScrollbar* vbar;
|
|
|
|
FScrollbar* hbar;
|
2015-09-22 04:18:20 +02:00
|
|
|
FString text;
|
|
|
|
FString inc_search;
|
2016-09-27 00:46:05 +02:00
|
|
|
bool multi_select;
|
|
|
|
bool mouse_select;
|
|
|
|
dragScroll drag_scroll;
|
|
|
|
bool scroll_timer;
|
|
|
|
int scroll_repeat;
|
|
|
|
int scroll_distance;
|
2015-09-22 04:18:20 +02:00
|
|
|
int current;
|
|
|
|
int last_current;
|
|
|
|
int secect_from_item;
|
|
|
|
int xoffset;
|
|
|
|
int yoffset;
|
|
|
|
int last_yoffset;
|
|
|
|
int nf_offset;
|
2016-09-27 00:46:05 +02:00
|
|
|
int max_line_width;
|
2015-05-23 13:35:12 +02:00
|
|
|
};
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
|
|
|
|
|
|
|
// FListBox inline functions
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline const char* FListBox::getClassName() const
|
|
|
|
{ return "FListBox"; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
inline uInt FListBox::getCount() const
|
2015-05-23 13:35:12 +02:00
|
|
|
{ return uInt(data.size()); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
inline FListBoxItem FListBox::getItem (int index) const
|
2015-05-23 13:35:12 +02:00
|
|
|
{ return data[uInt(index-1)]; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline int FListBox::currentItem() const
|
|
|
|
{ return current; }
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline FString& FListBox::getText()
|
|
|
|
{ return text; }
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FListBox::selectItem (int index)
|
|
|
|
{ data[uInt(index-1)].selected = true; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FListBox::unselectItem (int index)
|
|
|
|
{ data[uInt(index-1)].selected = false; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FListBox::showNoBrackets(int index)
|
|
|
|
{ data[uInt(index-1)].brackets = fc::NoBrackets; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FListBox::setMultiSelection (bool on)
|
2016-09-27 00:46:05 +02:00
|
|
|
{ multi_select = on; }
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FListBox::setMultiSelection()
|
|
|
|
{ setMultiSelection(true); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FListBox::unsetMultiSelection()
|
|
|
|
{ setMultiSelection(false); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FListBox::setEnable()
|
|
|
|
{ return setEnable(true); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FListBox::unsetEnable()
|
|
|
|
{ return setEnable(false); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FListBox::setDisable()
|
|
|
|
{ return setEnable(false); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FListBox::setFocus()
|
|
|
|
{ return setFocus(true); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FListBox::unsetFocus()
|
|
|
|
{ return setFocus(false); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-03-12 00:29:56 +01:00
|
|
|
inline bool FListBox::isSelected (int index) const
|
2016-11-02 00:37:58 +01:00
|
|
|
{ return data[uInt(index-1)].selected; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FListBox::isMultiSelection() const
|
|
|
|
{ return multi_select; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FListBox::hasBrackets(int index) const
|
|
|
|
{ return bool(data[uInt(index-1)].brackets > 0); }
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-04-09 20:08:53 +02:00
|
|
|
#endif // FLISTBOX_H
|