Data import from a standard container in FListBox
This commit is contained in:
parent
90fa4b0391
commit
ca7ba6ae7e
|
@ -37,6 +37,7 @@ test/term-attributes
|
|||
test/transparent
|
||||
test/input-dialog
|
||||
test/choice
|
||||
test/listbox
|
||||
test/mandelbrot
|
||||
test/keyboard
|
||||
test/mouse
|
||||
|
|
|
@ -1,7 +1,13 @@
|
|||
2017-04-23 Markus Gans <guru.mail@muenster.de>
|
||||
* Import of data from a standard container in FListBox
|
||||
is now possible
|
||||
* The new "listbox" example shows the handling with
|
||||
standard containers
|
||||
|
||||
2017-04-17 Markus Gans <guru.mail@muenster.de>
|
||||
* Speed up FString::setNumber() by using a decimal
|
||||
string lookup table
|
||||
* FString allocates no new memory if the size sufficient
|
||||
* FString allocates no new memory if the size in sufficient
|
||||
|
||||
2017-04-15 Markus Gans <guru.mail@muenster.de>
|
||||
* Fix unsigned integer underflow in FString::_insert()
|
||||
|
|
114
src/flistbox.cpp
114
src/flistbox.cpp
|
@ -7,6 +7,9 @@
|
|||
#include "fscrollbar.h"
|
||||
#include "fstatusbar.h"
|
||||
|
||||
// function pointer
|
||||
FString& (*FListBox::getString)(FListBox::listBoxItems::iterator);
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// class FListBoxItem
|
||||
|
@ -127,16 +130,24 @@ void FListBox::setCurrentItem (int index)
|
|||
redraw();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
void FListBox::setCurrentItem (listBoxItems::iterator iter)
|
||||
{
|
||||
int index = int(std::distance(data.begin(), iter) + 1);
|
||||
setCurrentItem(index);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
void FListBox::showInsideBrackets ( int index
|
||||
, fc::brackets_type b )
|
||||
{
|
||||
data[uInt(index-1)].brackets = b;
|
||||
listBoxItems::iterator iter = index2iterator(index - 1);
|
||||
iter->brackets = b;
|
||||
|
||||
if ( b == fc::NoBrackets )
|
||||
return;
|
||||
|
||||
int len = int(data[uInt(index-1)].getText().getLength() + 2);
|
||||
int len = int(iter->getText().getLength() + 2);
|
||||
|
||||
if ( len > max_line_width )
|
||||
{
|
||||
|
@ -261,16 +272,13 @@ void FListBox::hide()
|
|||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
void FListBox::insert ( const FString& item
|
||||
, fc::brackets_type b
|
||||
, bool s
|
||||
, data_ptr d )
|
||||
void FListBox::insert (FListBoxItem listItem)
|
||||
{
|
||||
int len, element_count;
|
||||
|
||||
len = int(item.getLength());
|
||||
len = int(listItem.text.getLength());
|
||||
|
||||
if ( b )
|
||||
if ( listItem.brackets )
|
||||
len += 2;
|
||||
|
||||
if ( len > max_line_width )
|
||||
|
@ -287,10 +295,7 @@ void FListBox::insert ( const FString& item
|
|||
hbar->setVisible();
|
||||
}
|
||||
}
|
||||
FListBoxItem listItem (item);
|
||||
listItem.data_pointer = d;
|
||||
listItem.brackets = b;
|
||||
listItem.selected = s;
|
||||
|
||||
data.push_back (listItem);
|
||||
|
||||
element_count = int(getCount());
|
||||
|
@ -302,6 +307,18 @@ void FListBox::insert ( const FString& item
|
|||
vbar->setVisible();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
void FListBox::insert ( const FString& item
|
||||
, fc::brackets_type b
|
||||
, bool s
|
||||
, data_ptr d )
|
||||
{
|
||||
FListBoxItem listItem (item, d);
|
||||
listItem.brackets = b;
|
||||
listItem.selected = s;
|
||||
insert (listItem);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
void FListBox::insert ( long item
|
||||
, fc::brackets_type b
|
||||
|
@ -323,12 +340,16 @@ void FListBox::remove (int item)
|
|||
element_count = int(getCount());
|
||||
max_line_width = 0;
|
||||
|
||||
for (int i=0; i < element_count; i++)
|
||||
listBoxItems::iterator iter = data.begin();
|
||||
|
||||
while ( iter != data.end() )
|
||||
{
|
||||
int len = int(data[uInt(i)].getText().getLength());
|
||||
int len = int(iter->getText().getLength());
|
||||
|
||||
if ( len > max_line_width )
|
||||
max_line_width = len;
|
||||
|
||||
++iter;
|
||||
}
|
||||
|
||||
hbar->setMaximum(max_line_width - getWidth() + nf_offset + 4);
|
||||
|
@ -553,18 +574,20 @@ void FListBox::onKeyPress (FKeyEvent* ev)
|
|||
{
|
||||
inc_search += L' ';
|
||||
bool inc_found = false;
|
||||
uInt end = getCount();
|
||||
listBoxItems::iterator iter = data.begin();
|
||||
|
||||
for (uInt i=0; i < end; i++)
|
||||
while ( iter != data.end() )
|
||||
{
|
||||
if ( ! inc_found
|
||||
&& inc_search.toLower()
|
||||
== data[i].getText().left(inc_len+1).toLower() )
|
||||
== iter->getText().left(inc_len+1).toLower() )
|
||||
{
|
||||
setCurrentItem(int(i+1));
|
||||
setCurrentItem(iter);
|
||||
inc_found = true;
|
||||
break;
|
||||
}
|
||||
|
||||
++iter;
|
||||
}
|
||||
|
||||
if ( ! inc_found )
|
||||
|
@ -600,16 +623,18 @@ void FListBox::onKeyPress (FKeyEvent* ev)
|
|||
|
||||
if ( inc_len > 1 )
|
||||
{
|
||||
uInt end = getCount();
|
||||
listBoxItems::iterator iter = data.begin();
|
||||
|
||||
for (uInt i=0; i < end; i++)
|
||||
while ( iter != data.end() )
|
||||
{
|
||||
if ( inc_search.toLower()
|
||||
== data[i].getText().left(inc_len-1).toLower() )
|
||||
== iter->getText().left(inc_len-1).toLower() )
|
||||
{
|
||||
setCurrentItem(int(i+1));
|
||||
setCurrentItem(iter);
|
||||
break;
|
||||
}
|
||||
|
||||
++iter;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -640,18 +665,20 @@ void FListBox::onKeyPress (FKeyEvent* ev)
|
|||
|
||||
uInt inc_len = inc_search.getLength();
|
||||
bool inc_found = false;
|
||||
uInt end = getCount();
|
||||
listBoxItems::iterator iter = data.begin();
|
||||
|
||||
for (uInt i=0; i < end; i++)
|
||||
while ( iter != data.end() )
|
||||
{
|
||||
if ( ! inc_found
|
||||
&& inc_search.toLower()
|
||||
== data[i].getText().left(inc_len).toLower() )
|
||||
== iter->getText().left(inc_len).toLower() )
|
||||
{
|
||||
setCurrentItem(int(i+1));
|
||||
setCurrentItem(iter);
|
||||
inc_found = true;
|
||||
break;
|
||||
}
|
||||
|
||||
++iter;
|
||||
}
|
||||
|
||||
if ( ! inc_found )
|
||||
|
@ -1431,6 +1458,12 @@ void FListBox::adjustSize()
|
|||
|
||||
|
||||
// private methods of FListBox
|
||||
//----------------------------------------------------------------------
|
||||
FString& FListBox::getString_FListBoxItem (listBoxItems::iterator iter)
|
||||
{
|
||||
return iter->getText();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
void FListBox::init()
|
||||
{
|
||||
|
@ -1472,6 +1505,9 @@ void FListBox::init()
|
|||
setLeftPadding(1);
|
||||
setBottomPadding(1);
|
||||
setRightPadding(1 + nf_offset);
|
||||
|
||||
// set the new getString function pointer
|
||||
getString = &FListBox::getString_FListBoxItem;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
@ -1564,6 +1600,7 @@ void FListBox::drawList()
|
|||
FString element;
|
||||
uInt start, end, inc_len;
|
||||
bool isFocus;
|
||||
listBoxItems::iterator iter;
|
||||
|
||||
if ( data.empty() || getHeight() <= 2 || getWidth() <= 4 )
|
||||
return;
|
||||
|
@ -1587,13 +1624,15 @@ void FListBox::drawList()
|
|||
end = std::max(last_pos, current_pos)+1;
|
||||
}
|
||||
|
||||
iter = index2iterator(int(start) + yoffset);
|
||||
|
||||
for (uInt y=start; y < end; y++)
|
||||
{
|
||||
setPrintPos (2, 2 + int(y));
|
||||
bool serach_mark = false;
|
||||
bool lineHasBrackets = hasBrackets(int(y) + yoffset + 1);
|
||||
bool isLineSelected = isSelected(int(y) + yoffset + 1);
|
||||
bool isCurrentLine = bool(uInt(y) + uInt(yoffset) + 1 == uInt(current));
|
||||
bool lineHasBrackets = hasBrackets(iter);
|
||||
bool isLineSelected = isSelected(iter);
|
||||
bool isCurrentLine = bool(y + uInt(yoffset) + 1 == uInt(current));
|
||||
|
||||
if ( isLineSelected )
|
||||
{
|
||||
|
@ -1680,7 +1719,7 @@ void FListBox::drawList()
|
|||
{
|
||||
b=1;
|
||||
|
||||
switch ( data[y+uInt(yoffset)].brackets )
|
||||
switch ( iter->brackets )
|
||||
{
|
||||
case fc::NoBrackets:
|
||||
break;
|
||||
|
@ -1702,13 +1741,11 @@ void FListBox::drawList()
|
|||
break;
|
||||
}
|
||||
|
||||
element = data[y+uInt(yoffset)].getText()
|
||||
.mid ( uInt(1+xoffset)
|
||||
element = getString(iter).mid ( uInt(1+xoffset)
|
||||
, uInt(getWidth()-nf_offset-5) );
|
||||
}
|
||||
else
|
||||
element = data[y+uInt(yoffset)].getText()
|
||||
.mid ( uInt(xoffset)
|
||||
element = getString(iter).mid ( uInt(xoffset)
|
||||
, uInt(getWidth()-nf_offset-4) );
|
||||
|
||||
const wchar_t* const& element_str = element.wc_str();
|
||||
|
@ -1727,7 +1764,7 @@ void FListBox::drawList()
|
|||
print (element_str[i]);
|
||||
}
|
||||
|
||||
full_length = int(data[y+uInt(yoffset)].getText().getLength());
|
||||
full_length = int(getString(iter).getLength());
|
||||
|
||||
if ( b+i < uInt(getWidth()-nf_offset-4) && xoffset <= full_length+1 )
|
||||
{
|
||||
|
@ -1735,7 +1772,7 @@ void FListBox::drawList()
|
|||
setColor ( wc.current_element_focus_fg
|
||||
, wc.current_element_focus_bg );
|
||||
|
||||
switch ( data[y+uInt(yoffset)].brackets )
|
||||
switch ( iter->brackets )
|
||||
{
|
||||
case fc::NoBrackets:
|
||||
break;
|
||||
|
@ -1772,8 +1809,7 @@ void FListBox::drawList()
|
|||
else // line has no brackets
|
||||
{
|
||||
uInt i, len;
|
||||
element = data[y+uInt(yoffset)].getText()
|
||||
.mid ( uInt(1+xoffset)
|
||||
element = getString(iter).mid ( uInt(1+xoffset)
|
||||
, uInt(getWidth()-nf_offset-4) );
|
||||
const wchar_t* const& element_str = element.wc_str();
|
||||
len = element.getLength();
|
||||
|
@ -1800,6 +1836,8 @@ void FListBox::drawList()
|
|||
for (; i < uInt(getWidth()-nf_offset-3); i++)
|
||||
print (' ');
|
||||
}
|
||||
|
||||
++iter;
|
||||
}
|
||||
|
||||
if ( isMonochron() ) // unset for the last element
|
||||
|
|
137
src/flistbox.h
137
src/flistbox.h
|
@ -57,7 +57,7 @@ class FListBoxItem
|
|||
FListBoxItem& operator = (const FListBoxItem&);
|
||||
|
||||
// Accessors
|
||||
virtual FString getText() const;
|
||||
virtual FString& getText();
|
||||
virtual FWidget::data_ptr getData() const;
|
||||
|
||||
protected:
|
||||
|
@ -80,7 +80,7 @@ class FListBoxItem
|
|||
|
||||
// FListBoxItem inline functions
|
||||
//----------------------------------------------------------------------
|
||||
inline FString FListBoxItem::getText() const
|
||||
inline FString& FListBoxItem::getText()
|
||||
{ return text; }
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
@ -106,11 +106,16 @@ inline void FListBoxItem::setData (FWidget::data_ptr data)
|
|||
class FListBox : public FWidget
|
||||
{
|
||||
public:
|
||||
// Typedef
|
||||
typedef std::vector<FListBoxItem> listBoxItems;
|
||||
|
||||
// Using-declaration
|
||||
using FWidget::setGeometry;
|
||||
|
||||
// Constructor
|
||||
explicit FListBox (FWidget* = 0);
|
||||
template <class Iterator, class InsertConverter>
|
||||
FListBox (Iterator, Iterator, InsertConverter, FWidget* = 0);
|
||||
|
||||
// Destructor
|
||||
~FListBox();
|
||||
|
@ -118,16 +123,21 @@ class FListBox : public FWidget
|
|||
// Accessors
|
||||
const char* getClassName() const;
|
||||
uInt getCount() const;
|
||||
FListBoxItem getItem (int) const;
|
||||
FListBoxItem getItem (int);
|
||||
FListBoxItem getItem (listBoxItems::iterator) const;
|
||||
int currentItem() const;
|
||||
FString& getText();
|
||||
|
||||
// Mutators
|
||||
void setCurrentItem (int);
|
||||
void setCurrentItem (listBoxItems::iterator);
|
||||
void selectItem (int);
|
||||
void selectItem (listBoxItems::iterator);
|
||||
void unselectItem (int);
|
||||
void unselectItem (listBoxItems::iterator);
|
||||
void showInsideBrackets (int, fc::brackets_type);
|
||||
void showNoBrackets (int);
|
||||
void showNoBrackets (listBoxItems::iterator);
|
||||
void setGeometry (int, int, int, int, bool = true);
|
||||
void setMultiSelection (bool);
|
||||
void setMultiSelection ();
|
||||
|
@ -142,12 +152,17 @@ class FListBox : public FWidget
|
|||
void setText (const FString&);
|
||||
|
||||
// Inquiries
|
||||
bool isSelected (int) const;
|
||||
bool isSelected (int);
|
||||
bool isSelected (listBoxItems::iterator) const;
|
||||
bool isMultiSelection() const;
|
||||
bool hasBrackets (int) const;
|
||||
bool hasBrackets (int);
|
||||
bool hasBrackets (listBoxItems::iterator) const;
|
||||
|
||||
// Methods
|
||||
void hide();
|
||||
template <class Iterator, class InsertConverter>
|
||||
void insert (Iterator, Iterator, InsertConverter);
|
||||
void insert (FListBoxItem);
|
||||
void insert ( const FString&
|
||||
, fc::brackets_type = fc::NoBrackets
|
||||
, bool = false
|
||||
|
@ -180,9 +195,6 @@ class FListBox : public FWidget
|
|||
void adjustSize();
|
||||
|
||||
private:
|
||||
// Typedef
|
||||
typedef std::vector<FListBoxItem> listBoxItem;
|
||||
|
||||
// Enumeration
|
||||
enum dragScroll
|
||||
{
|
||||
|
@ -199,6 +211,10 @@ class FListBox : public FWidget
|
|||
// Disable assignment operator (=)
|
||||
FListBox& operator = (const FListBox&);
|
||||
|
||||
// Accessors
|
||||
static FString& getString_FListBoxItem (listBoxItems::iterator);
|
||||
static FString& (*getString)(listBoxItems::iterator);
|
||||
|
||||
// Methods
|
||||
void init();
|
||||
void draw();
|
||||
|
@ -207,9 +223,10 @@ class FListBox : public FWidget
|
|||
void processClick();
|
||||
void processSelect();
|
||||
void processChanged();
|
||||
listBoxItems::iterator index2iterator (int);
|
||||
|
||||
// Data Members
|
||||
listBoxItem data;
|
||||
listBoxItems data;
|
||||
FScrollbar* vbar;
|
||||
FScrollbar* hbar;
|
||||
FString text;
|
||||
|
@ -233,6 +250,42 @@ class FListBox : public FWidget
|
|||
|
||||
|
||||
// FListBox inline functions
|
||||
//----------------------------------------------------------------------
|
||||
template <class Iterator, class InsertConverter>
|
||||
inline FListBox::FListBox ( Iterator first
|
||||
, Iterator last
|
||||
, InsertConverter convert
|
||||
, FWidget* parent )
|
||||
: FWidget(parent)
|
||||
, data()
|
||||
, vbar(0)
|
||||
, hbar(0)
|
||||
, text()
|
||||
, inc_search()
|
||||
, multi_select(false)
|
||||
, mouse_select(false)
|
||||
, drag_scroll(FListBox::noScroll)
|
||||
, scroll_timer(false)
|
||||
, scroll_repeat(100)
|
||||
, scroll_distance(1)
|
||||
, current(0)
|
||||
, last_current(-1)
|
||||
, secect_from_item(-1)
|
||||
, xoffset(0)
|
||||
, yoffset(0)
|
||||
, last_yoffset(-1)
|
||||
, nf_offset(0)
|
||||
, max_line_width(0)
|
||||
{
|
||||
init();
|
||||
|
||||
while ( first != last )
|
||||
{
|
||||
insert(convert(first), fc::NoBrackets, false, &(*first));
|
||||
++first;
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
inline const char* FListBox::getClassName() const
|
||||
{ return "FListBox"; }
|
||||
|
@ -242,8 +295,15 @@ inline uInt FListBox::getCount() const
|
|||
{ return uInt(data.size()); }
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
inline FListBoxItem FListBox::getItem (int index) const
|
||||
{ return data[uInt(index-1)]; }
|
||||
inline FListBoxItem FListBox::getItem (int index) //const
|
||||
{
|
||||
listBoxItems::iterator iter = index2iterator(index - 1);
|
||||
return *iter;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
inline FListBoxItem FListBox::getItem (listBoxItems::iterator iter) const
|
||||
{ return *iter; }
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
inline int FListBox::currentItem() const
|
||||
|
@ -255,15 +315,27 @@ inline FString& FListBox::getText()
|
|||
|
||||
//----------------------------------------------------------------------
|
||||
inline void FListBox::selectItem (int index)
|
||||
{ data[uInt(index-1)].selected = true; }
|
||||
{ index2iterator(index - 1)->selected = true; }
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
inline void FListBox::selectItem (listBoxItems::iterator iter)
|
||||
{ iter->selected = true; }
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
inline void FListBox::unselectItem (int index)
|
||||
{ data[uInt(index-1)].selected = false; }
|
||||
{ index2iterator(index - 1)->selected = false; }
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
inline void FListBox::unselectItem (listBoxItems::iterator iter)
|
||||
{ iter->selected = false; }
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
inline void FListBox::showNoBrackets (int index)
|
||||
{ data[uInt(index-1)].brackets = fc::NoBrackets; }
|
||||
{ index2iterator(index - 1)->brackets = fc::NoBrackets; }
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
inline void FListBox::showNoBrackets (listBoxItems::iterator iter)
|
||||
{ iter->brackets = fc::NoBrackets; }
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
inline void FListBox::setMultiSelection (bool on)
|
||||
|
@ -298,15 +370,44 @@ inline bool FListBox::unsetFocus()
|
|||
{ return setFocus(false); }
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
inline bool FListBox::isSelected (int index) const
|
||||
{ return data[uInt(index-1)].selected; }
|
||||
inline bool FListBox::isSelected (int index)
|
||||
{ return index2iterator(index - 1)->selected; }
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
inline bool FListBox::isSelected (listBoxItems::iterator iter) const
|
||||
{ return iter->selected; }
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
inline bool FListBox::isMultiSelection() const
|
||||
{ return multi_select; }
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
inline bool FListBox::hasBrackets(int index) const
|
||||
{ return bool(data[uInt(index-1)].brackets > 0); }
|
||||
inline bool FListBox::hasBrackets(int index)
|
||||
{ return bool(index2iterator(index - 1)->brackets > 0); }
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
inline bool FListBox::hasBrackets(listBoxItems::iterator iter) const
|
||||
{ return bool(iter->brackets > 0); }
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
template <class Iterator, class InsertConverter>
|
||||
inline void FListBox::insert ( Iterator first
|
||||
, Iterator last
|
||||
, InsertConverter convert )
|
||||
{
|
||||
while ( first != last )
|
||||
{
|
||||
insert (convert(first), fc::NoBrackets, false, &(*first));
|
||||
++first;
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
inline FListBox::listBoxItems::iterator FListBox::index2iterator (int index)
|
||||
{
|
||||
listBoxItems::iterator iter = data.begin();
|
||||
std::advance (iter, index);
|
||||
return iter;
|
||||
}
|
||||
|
||||
#endif // FLISTBOX_H
|
||||
|
|
|
@ -10,6 +10,7 @@ noinst_PROGRAMS = \
|
|||
dialog \
|
||||
input-dialog \
|
||||
choice \
|
||||
listbox \
|
||||
opti-move \
|
||||
termcap \
|
||||
string-operations \
|
||||
|
@ -30,6 +31,7 @@ hello_SOURCES = hello.cpp
|
|||
dialog_SOURCES = dialog.cpp
|
||||
input_dialog_SOURCES = input-dialog.cpp
|
||||
choice_SOURCES = choice.cpp
|
||||
listbox_SOURCES = listbox.cpp
|
||||
opti_move_SOURCES = opti-move.cpp
|
||||
string_operations_SOURCES = string-operations.cpp
|
||||
mandelbrot_SOURCES = mandelbrot.cpp
|
||||
|
|
|
@ -83,12 +83,12 @@ POST_UNINSTALL = :
|
|||
build_triplet = @build@
|
||||
host_triplet = @host@
|
||||
noinst_PROGRAMS = hello$(EXEEXT) dialog$(EXEEXT) input-dialog$(EXEEXT) \
|
||||
choice$(EXEEXT) opti-move$(EXEEXT) termcap$(EXEEXT) \
|
||||
string-operations$(EXEEXT) mandelbrot$(EXEEXT) \
|
||||
calculator$(EXEEXT) watch$(EXEEXT) term-attributes$(EXEEXT) \
|
||||
transparent$(EXEEXT) keyboard$(EXEEXT) mouse$(EXEEXT) \
|
||||
timer$(EXEEXT) scrollview$(EXEEXT) windows$(EXEEXT) \
|
||||
menu$(EXEEXT) ui$(EXEEXT)
|
||||
choice$(EXEEXT) listbox$(EXEEXT) opti-move$(EXEEXT) \
|
||||
termcap$(EXEEXT) string-operations$(EXEEXT) \
|
||||
mandelbrot$(EXEEXT) calculator$(EXEEXT) watch$(EXEEXT) \
|
||||
term-attributes$(EXEEXT) transparent$(EXEEXT) \
|
||||
keyboard$(EXEEXT) mouse$(EXEEXT) timer$(EXEEXT) \
|
||||
scrollview$(EXEEXT) windows$(EXEEXT) menu$(EXEEXT) ui$(EXEEXT)
|
||||
subdir = test
|
||||
DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
|
||||
$(top_srcdir)/depcomp
|
||||
|
@ -126,6 +126,9 @@ input_dialog_LDADD = $(LDADD)
|
|||
am_keyboard_OBJECTS = keyboard.$(OBJEXT)
|
||||
keyboard_OBJECTS = $(am_keyboard_OBJECTS)
|
||||
keyboard_LDADD = $(LDADD)
|
||||
am_listbox_OBJECTS = listbox.$(OBJEXT)
|
||||
listbox_OBJECTS = $(am_listbox_OBJECTS)
|
||||
listbox_LDADD = $(LDADD)
|
||||
am_mandelbrot_OBJECTS = mandelbrot.$(OBJEXT)
|
||||
mandelbrot_OBJECTS = $(am_mandelbrot_OBJECTS)
|
||||
mandelbrot_LDADD = $(LDADD)
|
||||
|
@ -201,18 +204,19 @@ am__v_CXXLD_0 = @echo " CXXLD " $@;
|
|||
am__v_CXXLD_1 =
|
||||
SOURCES = $(calculator_SOURCES) $(choice_SOURCES) $(dialog_SOURCES) \
|
||||
$(hello_SOURCES) $(input_dialog_SOURCES) $(keyboard_SOURCES) \
|
||||
$(mandelbrot_SOURCES) $(menu_SOURCES) $(mouse_SOURCES) \
|
||||
$(opti_move_SOURCES) $(scrollview_SOURCES) \
|
||||
$(listbox_SOURCES) $(mandelbrot_SOURCES) $(menu_SOURCES) \
|
||||
$(mouse_SOURCES) $(opti_move_SOURCES) $(scrollview_SOURCES) \
|
||||
$(string_operations_SOURCES) $(term_attributes_SOURCES) \
|
||||
$(termcap_SOURCES) $(timer_SOURCES) $(transparent_SOURCES) \
|
||||
$(ui_SOURCES) $(watch_SOURCES) $(windows_SOURCES)
|
||||
DIST_SOURCES = $(calculator_SOURCES) $(choice_SOURCES) \
|
||||
$(dialog_SOURCES) $(hello_SOURCES) $(input_dialog_SOURCES) \
|
||||
$(keyboard_SOURCES) $(mandelbrot_SOURCES) $(menu_SOURCES) \
|
||||
$(mouse_SOURCES) $(opti_move_SOURCES) $(scrollview_SOURCES) \
|
||||
$(string_operations_SOURCES) $(term_attributes_SOURCES) \
|
||||
$(termcap_SOURCES) $(timer_SOURCES) $(transparent_SOURCES) \
|
||||
$(ui_SOURCES) $(watch_SOURCES) $(windows_SOURCES)
|
||||
$(keyboard_SOURCES) $(listbox_SOURCES) $(mandelbrot_SOURCES) \
|
||||
$(menu_SOURCES) $(mouse_SOURCES) $(opti_move_SOURCES) \
|
||||
$(scrollview_SOURCES) $(string_operations_SOURCES) \
|
||||
$(term_attributes_SOURCES) $(termcap_SOURCES) $(timer_SOURCES) \
|
||||
$(transparent_SOURCES) $(ui_SOURCES) $(watch_SOURCES) \
|
||||
$(windows_SOURCES)
|
||||
am__can_run_installinfo = \
|
||||
case $$AM_UPDATE_INFO_DIR in \
|
||||
n|no|NO) false;; \
|
||||
|
@ -366,6 +370,7 @@ hello_SOURCES = hello.cpp
|
|||
dialog_SOURCES = dialog.cpp
|
||||
input_dialog_SOURCES = input-dialog.cpp
|
||||
choice_SOURCES = choice.cpp
|
||||
listbox_SOURCES = listbox.cpp
|
||||
opti_move_SOURCES = opti-move.cpp
|
||||
string_operations_SOURCES = string-operations.cpp
|
||||
mandelbrot_SOURCES = mandelbrot.cpp
|
||||
|
@ -449,6 +454,10 @@ keyboard$(EXEEXT): $(keyboard_OBJECTS) $(keyboard_DEPENDENCIES) $(EXTRA_keyboard
|
|||
@rm -f keyboard$(EXEEXT)
|
||||
$(AM_V_CXXLD)$(CXXLINK) $(keyboard_OBJECTS) $(keyboard_LDADD) $(LIBS)
|
||||
|
||||
listbox$(EXEEXT): $(listbox_OBJECTS) $(listbox_DEPENDENCIES) $(EXTRA_listbox_DEPENDENCIES)
|
||||
@rm -f listbox$(EXEEXT)
|
||||
$(AM_V_CXXLD)$(CXXLINK) $(listbox_OBJECTS) $(listbox_LDADD) $(LIBS)
|
||||
|
||||
mandelbrot$(EXEEXT): $(mandelbrot_OBJECTS) $(mandelbrot_DEPENDENCIES) $(EXTRA_mandelbrot_DEPENDENCIES)
|
||||
@rm -f mandelbrot$(EXEEXT)
|
||||
$(AM_V_CXXLD)$(CXXLINK) $(mandelbrot_OBJECTS) $(mandelbrot_LDADD) $(LIBS)
|
||||
|
@ -513,6 +522,7 @@ distclean-compile:
|
|||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hello.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/input-dialog.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/keyboard.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/listbox.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mandelbrot.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/menu.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mouse.Po@am__quote@
|
||||
|
|
|
@ -0,0 +1,161 @@
|
|||
// File: ui.cpp
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
#include "final.h"
|
||||
|
||||
// Global application object
|
||||
static FString* temp_str = 0;
|
||||
|
||||
// Function prototypes
|
||||
FString& doubleToString (std::list<double>::const_iterator iter);
|
||||
FString& mapToString (std::map<FString, FString>::const_iterator iter);
|
||||
|
||||
// Import converter functions
|
||||
FString& doubleToString (std::list<double>::const_iterator iter)
|
||||
{
|
||||
return temp_str->setNumber(*iter);
|
||||
}
|
||||
|
||||
FString& mapToString (std::map<FString, FString>::const_iterator iter)
|
||||
{
|
||||
return *temp_str = iter->first + ": " + iter->second;
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// class Listbox
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
#pragma pack(push)
|
||||
#pragma pack(1)
|
||||
|
||||
class Listbox : public FDialog
|
||||
{
|
||||
public:
|
||||
// Constructor
|
||||
explicit Listbox (FWidget* = 0);
|
||||
// Destructor
|
||||
~Listbox();
|
||||
|
||||
private:
|
||||
// Disable copy constructor
|
||||
Listbox (const Listbox&);
|
||||
// Disable assignment operator (=)
|
||||
Listbox& operator = (const Listbox&);
|
||||
|
||||
// Event handlers
|
||||
void onClose (FCloseEvent*);
|
||||
|
||||
// Callback methods
|
||||
void cb_exitApp (FWidget*, data_ptr);
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
Listbox::Listbox (FWidget* parent)
|
||||
: FDialog(parent)
|
||||
{
|
||||
temp_str = new FString;
|
||||
|
||||
// listbox 1
|
||||
FListBox* list1 = new FListBox (this);
|
||||
list1->setGeometry(2, 1, 18, 10);
|
||||
list1->setText ("FListBoxItem");
|
||||
|
||||
for (int i=1; i < 30; i++)
|
||||
list1->insert (L"----- " + FString().setNumber(i) + L" -----");
|
||||
|
||||
// listbox 2
|
||||
FListBox* list2 = new FListBox (this);
|
||||
list2->setGeometry(21, 1, 10, 10);
|
||||
list2->setText ("double");
|
||||
|
||||
std::list<double> double_list;
|
||||
|
||||
for (double i=1; i<=15; i++)
|
||||
double_list.push_back(2*i + (i/100));
|
||||
|
||||
list2->insert (double_list.begin(), double_list.end(), doubleToString);
|
||||
|
||||
// listbox 3
|
||||
std::map<FString, FString> TLD;
|
||||
TLD["com"] = "Commercial";
|
||||
TLD["org"] = "Organization";
|
||||
TLD["net"] = "Network";
|
||||
TLD["edu"] = "Education";
|
||||
TLD["gov"] = "Government";
|
||||
|
||||
FListBox* list3;
|
||||
list3 = new FListBox (TLD.begin(), TLD.end(), mapToString, this);
|
||||
list3->setGeometry(32, 1, 21, 10);
|
||||
list3->setText ("key: value");
|
||||
|
||||
// Quit button
|
||||
FButton* Quit = new FButton (this);
|
||||
Quit->setGeometry(42, 12, 10, 1);
|
||||
Quit->setText (L"&Quit");
|
||||
|
||||
// Add some function callbacks
|
||||
Quit->addCallback
|
||||
(
|
||||
"clicked",
|
||||
F_METHOD_CALLBACK (this, &Listbox::cb_exitApp)
|
||||
);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
Listbox::~Listbox()
|
||||
{
|
||||
delete temp_str;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
void Listbox::onClose (FCloseEvent* ev)
|
||||
{
|
||||
int ret = FMessageBox::info ( this, "Quit"
|
||||
, "Do you really want\n"
|
||||
"to quit the program ?"
|
||||
, FMessageBox::Yes
|
||||
, FMessageBox::No );
|
||||
if ( ret == FMessageBox::Yes )
|
||||
ev->accept();
|
||||
else
|
||||
ev->ignore();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
void Listbox::cb_exitApp (FWidget*, data_ptr)
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// main part
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
int main (int argc, char* argv[])
|
||||
{
|
||||
if ( argv[1] && ( std::strcmp(argv[1], "--help") == 0
|
||||
|| std::strcmp(argv[1], "-h") == 0 ) )
|
||||
{
|
||||
std::cout << "Generic options:" << std::endl
|
||||
<< " -h, --help "
|
||||
<< "Display this help and exit" << std::endl;
|
||||
FApplication::print_cmd_Options();
|
||||
std::exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
FApplication app(argc, argv);
|
||||
|
||||
Listbox d(&app);
|
||||
d.setText (L"Listbox");
|
||||
d.setGeometry (int(1+(app.getWidth()-56)/2), 5, 56, 16);
|
||||
d.setShadow();
|
||||
|
||||
app.setMainWidget(&d);
|
||||
d.show();
|
||||
return app.exec();
|
||||
}
|
|
@ -507,6 +507,7 @@ MyDialog::MyDialog (FWidget* parent)
|
|||
myList->setText ("Items");
|
||||
myList->setStatusbarMessage ("99 items in a list");
|
||||
myList->setMultiSelection();
|
||||
|
||||
for (int z=1; z < 100; z++)
|
||||
myList->insert (FString().setNumber(z) + L" placeholder");
|
||||
|
||||
|
|
Loading…
Reference in New Issue