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
|
|
|
|
|
|
|
#ifndef _FLISTBOX_H
|
|
|
|
#define _FLISTBOX_H
|
|
|
|
|
|
|
|
#include "fscrollbar.h"
|
|
|
|
#include "fstring.h"
|
|
|
|
#include "fwidget.h"
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class FListBoxItem
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
#pragma pack(push)
|
|
|
|
#pragma pack(1)
|
|
|
|
|
|
|
|
class FListBoxItem
|
|
|
|
{
|
|
|
|
private:
|
2016-09-27 00:46:05 +02:00
|
|
|
FString text;
|
2015-05-23 13:35:12 +02:00
|
|
|
fc::brackets_type brackets;
|
2016-09-27 00:46:05 +02:00
|
|
|
bool selected;
|
2016-09-25 23:53:48 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
public:
|
2016-09-30 04:55:28 +02:00
|
|
|
// Constructors
|
2015-05-23 13:35:12 +02:00
|
|
|
FListBoxItem ();
|
2015-05-27 02:25:13 +02:00
|
|
|
explicit FListBoxItem (FString&);
|
|
|
|
explicit FListBoxItem (const std::string&);
|
|
|
|
explicit FListBoxItem (const char*);
|
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
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
virtual FString getText() const;
|
2016-09-25 23:53:48 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
protected:
|
|
|
|
void setText (FString&);
|
|
|
|
void setText (const std::string&);
|
|
|
|
void setText (const char*);
|
2016-09-25 23:53:48 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
private:
|
|
|
|
friend class FListBox;
|
|
|
|
};
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FListBoxItem::setText (FString& txt)
|
2015-09-22 04:18:20 +02:00
|
|
|
{ text = txt; }
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FListBoxItem::setText (const std::string& txt)
|
2015-09-22 04:18:20 +02:00
|
|
|
{ text = txt; }
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FListBoxItem::setText (const char* txt)
|
2015-09-22 04:18:20 +02:00
|
|
|
{ text = txt; }
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class FListBox
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
#pragma pack(push)
|
|
|
|
#pragma pack(1)
|
|
|
|
|
|
|
|
class FListBox : public FWidget
|
|
|
|
{
|
|
|
|
private:
|
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
|
|
|
|
2015-09-22 04:18:20 +02:00
|
|
|
std::vector<FListBoxItem> 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
|
|
|
|
|
|
|
private:
|
2016-09-30 04:55:28 +02:00
|
|
|
// Disable copy constructor
|
2015-05-23 13:35:12 +02:00
|
|
|
FListBox (const FListBox&);
|
2016-09-30 04:55:28 +02:00
|
|
|
// Disable assignment operator (=)
|
2015-05-23 13:35:12 +02:00
|
|
|
FListBox& operator = (const FListBox&);
|
2016-09-30 04:55:28 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
void init();
|
|
|
|
void draw();
|
|
|
|
void drawLabel();
|
|
|
|
void drawList();
|
|
|
|
void processClick();
|
|
|
|
void processSelect();
|
|
|
|
void processChanged();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void adjustYOffset();
|
|
|
|
void adjustSize();
|
|
|
|
|
|
|
|
public:
|
2016-09-30 04:55:28 +02:00
|
|
|
// Constructor
|
|
|
|
explicit FListBox (FWidget* = 0);
|
|
|
|
// Destructor
|
|
|
|
~FListBox();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-09-30 04:55:28 +02:00
|
|
|
const char* getClassName() const;
|
2015-05-23 13:35:12 +02:00
|
|
|
void hide();
|
|
|
|
|
2016-09-30 04:55:28 +02:00
|
|
|
// Event handlers
|
2015-05-23 13:35:12 +02:00
|
|
|
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*);
|
|
|
|
|
2016-09-30 04:55:28 +02:00
|
|
|
// Callback methods
|
2015-05-23 13:35:12 +02:00
|
|
|
void cb_VBarChange (FWidget*, void*);
|
|
|
|
void cb_HBarChange (FWidget*, void*);
|
2016-09-30 04:55:28 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
uInt count() const;
|
2016-09-30 04:55:28 +02:00
|
|
|
FListBoxItem Item (int) const;
|
2015-05-23 13:35:12 +02:00
|
|
|
int currentItem() const;
|
2016-09-30 04:55:28 +02:00
|
|
|
void setCurrentItem (int);
|
|
|
|
void selectItem (int);
|
|
|
|
void unselectItem (int);
|
|
|
|
bool isSelected (int) const;
|
|
|
|
void showInsideBrackets (int, fc::brackets_type);
|
|
|
|
void showNoBrackets (int);
|
|
|
|
bool hasBrackets (int) const;
|
2015-09-22 04:18:20 +02:00
|
|
|
// make every setGeometry from FWidget available
|
|
|
|
using FWidget::setGeometry;
|
2015-09-27 16:45:28 +02:00
|
|
|
void setGeometry (int, int, int, int, bool = true);
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
void setMultiSelection (bool);
|
|
|
|
void setMultiSelection ();
|
|
|
|
void unsetMultiSelection ();
|
|
|
|
bool isMultiSelection() const;
|
2016-09-30 04:55:28 +02:00
|
|
|
bool setEnable (bool);
|
2015-05-23 13:35:12 +02:00
|
|
|
bool setEnable();
|
|
|
|
bool unsetEnable();
|
|
|
|
bool setDisable();
|
2016-09-30 04:55:28 +02:00
|
|
|
bool setFocus (bool);
|
2015-05-23 13:35:12 +02:00
|
|
|
bool setFocus();
|
|
|
|
bool unsetFocus();
|
|
|
|
|
2015-09-22 04:18:20 +02:00
|
|
|
void insert ( FString
|
2015-09-27 16:45:28 +02:00
|
|
|
, fc::brackets_type = fc::NoBrackets
|
|
|
|
, bool = false );
|
2015-09-22 04:18:20 +02:00
|
|
|
void insert ( long
|
2015-09-27 16:45:28 +02:00
|
|
|
, fc::brackets_type = fc::NoBrackets
|
|
|
|
, bool = false );
|
2015-05-23 13:35:12 +02:00
|
|
|
void remove ( int);
|
|
|
|
void clear();
|
|
|
|
|
|
|
|
void setText (const FString);
|
|
|
|
FString& getText();
|
|
|
|
};
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
|
|
|
|
|
|
|
// FListBox inline functions
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline const char* FListBox::getClassName() const
|
|
|
|
{ return "FListBox"; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline uInt FListBox::count() const
|
|
|
|
{ return uInt(data.size()); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline FListBoxItem FListBox::Item(int index) const
|
|
|
|
{ return data[uInt(index-1)]; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline int FListBox::currentItem() const
|
|
|
|
{ return current; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
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 bool FListBox::isSelected(int index) const
|
|
|
|
{ return data[uInt(index-1)].selected; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FListBox::showNoBrackets(int index)
|
|
|
|
{ data[uInt(index-1)].brackets = fc::NoBrackets; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FListBox::hasBrackets(int index) const
|
|
|
|
{ return bool(data[uInt(index-1)].brackets > 0); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
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::isMultiSelection() const
|
2016-09-27 00:46:05 +02:00
|
|
|
{ return multi_select; }
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
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); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline FString& FListBox::getText()
|
2015-09-22 04:18:20 +02:00
|
|
|
{ return text; }
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
#endif // _FLISTBOX_H
|