Stream and assignment operator support for FLabel

This commit is contained in:
Markus Gans 2017-09-20 05:44:41 +02:00
parent b41411e764
commit a6c30bb2b5
11 changed files with 168 additions and 36 deletions

View File

@ -1,6 +1,7 @@
2017-09-19 Markus Gans <guru.mail@muenster.de> 2017-09-19 Markus Gans <guru.mail@muenster.de>
* FString has now got its own streaming functionality for * FString has now got its own streaming functionality for
inbound and outbound type conversion inbound and outbound type conversion
* Added stream and assignment operator support for FLabel
2017-09-19 Markus Gans <guru.mail@muenster.de> 2017-09-19 Markus Gans <guru.mail@muenster.de>
* The command line help text is now available in all applications * The command line help text is now available in all applications

View File

@ -31,17 +31,17 @@ int main (int argc, char* argv[])
dgl.setGeometry (4, 3, 41, 11); dgl.setGeometry (4, 3, 41, 11);
// Create text labels // Create text labels
FLabel label_1(&dgl), FLabel label_1(&dgl);
label_2(&dgl); FLabel label_2(&dgl);
label_1.setText ( wchar_t(fc::BlackUpPointingTriangle) label_1 << wchar_t(fc::BlackUpPointingTriangle)
+ std::wstring(L"\n") << std::wstring(L"\n")
+ wchar_t(fc::BoxDrawingsUpAndRight) << wchar_t(fc::BoxDrawingsUpAndRight)
+ FString(2, wchar_t(fc::BoxDrawingsHorizontal)) << FString(2, wchar_t(fc::BoxDrawingsHorizontal))
+ " Double click the title bar button," ); << " Double click the title bar button,";
label_2.setText ( "press Q on the keyboard,\n" label_2 << "press Q on the keyboard,\n"
"or push the button below to exit\n" << "or push the button below to exit\n"
"the program." ); << "the program.";
label_1.setGeometry (1, 1, 38, 2); label_1.setGeometry (1, 1, 38, 2);
label_2.setGeometry (5, 3, 34, 3); label_2.setGeometry (5, 3, 34, 3);

View File

@ -87,7 +87,7 @@ Listbox::Listbox (FWidget* parent)
list1->setText ("FListBoxItem"); list1->setText ("FListBoxItem");
for (int i=1; i < 30; i++) for (int i=1; i < 30; i++)
list1->insert (L"----- " + FString().setNumber(i) + L" -----"); list1->insert (L"----- " + (FString() << i) + L" -----");
// listbox 2 // listbox 2
double_list = new std::list<double>; double_list = new std::list<double>;

View File

@ -63,9 +63,9 @@ ColorChooser::ColorChooser (FWidget* parent)
// Text label // Text label
FLabel* headline = new FLabel (this); FLabel* headline = new FLabel (this);
headline->setGeometry(1, 1, 8, 1); headline->setGeometry(1, 1, 8, 1);
headline->setText ("Color");
headline->setEmphasis(); headline->setEmphasis();
headline->setAlignment (fc::alignCenter); headline->setAlignment (fc::alignCenter);
*headline << "Color";
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -203,9 +203,9 @@ Brushes::Brushes (FWidget* parent)
// Text label // Text label
FLabel* headline = new FLabel (this); FLabel* headline = new FLabel (this);
headline->setGeometry(1, 1, 8, 1); headline->setGeometry(1, 1, 8, 1);
headline->setText ("Brush");
headline->setEmphasis(); headline->setEmphasis();
headline->setAlignment (fc::alignCenter); headline->setAlignment (fc::alignCenter);
*headline << "Brush";
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -220,8 +220,8 @@ scrollviewdemo::scrollviewdemo (FWidget* parent)
// Text label // Text label
FLabel* label = new FLabel (this); FLabel* label = new FLabel (this);
label->setGeometry(2, 1, 46, 1); label->setGeometry(2, 1, 46, 1);
label->setText (L"Use scrollbars to change the viewport position");
label->setEmphasis(); label->setEmphasis();
*label << L"Use scrollbars to change the viewport position";
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -516,16 +516,16 @@ MyDialog::MyDialog (FWidget* parent)
// Text labels // Text labels
FLabel* headline = new FLabel (this); FLabel* headline = new FLabel (this);
headline->setGeometry(21, 3, 10, 1); headline->setGeometry(21, 3, 10, 1);
headline->setText (L"List items");
headline->setEmphasis(); headline->setEmphasis();
headline->setAlignment (fc::alignCenter); headline->setAlignment (fc::alignCenter);
*headline = L"List items";
FLabel* tagged = new FLabel (L"Tagged:", this); FLabel* tagged = new FLabel (L"Tagged:", this);
tagged->setGeometry(21, 4, 7, 1); tagged->setGeometry(21, 4, 7, 1);
FLabel* tagged_count = new FLabel(this); FLabel* tagged_count = new FLabel(this);
tagged_count->setGeometry(29, 4, 5, 1); tagged_count->setGeometry(29, 4, 5, 1);
tagged_count->setNumber(0); *tagged_count << 0;
FLabel* sum = new FLabel (L"Sum:", this); FLabel* sum = new FLabel (L"Sum:", this);
sum->setGeometry(21, 5, 7, 3); sum->setGeometry(21, 5, 7, 3);
@ -533,7 +533,7 @@ MyDialog::MyDialog (FWidget* parent)
FLabel* sum_count = new FLabel (this); FLabel* sum_count = new FLabel (this);
sum_count->setGeometry(29, 5, 5, 3); sum_count->setGeometry(29, 5, 5, 3);
sum_count->setNumber (long(myList->getCount())); *sum_count << myList->getCount();
// Statusbar at the bottom // Statusbar at the bottom
FStatusBar* statusbar = new FStatusBar (this); FStatusBar* statusbar = new FStatusBar (this);
@ -830,7 +830,8 @@ void MyDialog::cb_updateNumber (FWidget* widget, data_ptr data)
if ( list->isSelected(int(n)) ) if ( list->isSelected(int(n)) )
select_num++; select_num++;
num->setNumber(select_num); num->clear();
*num << select_num;
num->redraw(); num->redraw();
} }

View File

@ -130,7 +130,7 @@ void watch::printTime()
else else
str.sprintf("%02d:%02d ", now.tm_hour, now.tm_min); str.sprintf("%02d:%02d ", now.tm_hour, now.tm_min);
time_str->setText(str); *time_str = str;
time_str->redraw(); time_str->redraw();
} }
@ -165,7 +165,7 @@ void watch::cb_clock (FWidget*, data_ptr)
else else
{ {
delAllTimer(); delAllTimer();
time_str->setText("--:--:--"); *time_str = "--:--:--";
time_str->redraw(); time_str->redraw();
} }
} }
@ -183,9 +183,10 @@ void watch::cb_seconds (FWidget*, data_ptr)
else else
{ {
if ( sec ) if ( sec )
time_str->setText("--:--:--"); *time_str = "--:--:--";
else else
time_str->setText("--:-- "); *time_str = "--:-- ";
time_str->redraw(); time_str->redraw();
} }
} }

View File

@ -111,12 +111,12 @@ void smallWindow::adjustSize()
{ {
if ( isZoomed() ) if ( isZoomed() )
{ {
top_right_label->setText("unzoom"); *top_right_label = "unzoom";
bottom_label->hide(); bottom_label->hide();
} }
else else
{ {
top_right_label->setText("zoom"); *top_right_label = "zoom";
bottom_label->setVisible(); bottom_label->setVisible();
} }

View File

@ -53,6 +53,19 @@ class FLabel : public FWidget
// Destructor // Destructor
virtual ~FLabel(); virtual ~FLabel();
// Overloaded operators
FLabel& operator = (const FString&);
FLabel& operator << (const FString&);
FLabel& operator << (const wchar_t);
FLabel& operator << (const uInt);
FLabel& operator << (const int);
FLabel& operator << (const uLong);
FLabel& operator << (const long);
FLabel& operator << (const float);
FLabel& operator << (const double);
FLabel& operator << (const lDouble);
const FLabel& operator >> (FString&);
// Accessors // Accessors
const char* getClassName() const; const char* getClassName() const;
FTerm* getAccelWidget(); FTerm* getAccelWidget();
@ -69,7 +82,11 @@ class FLabel : public FWidget
bool setReverseMode(); bool setReverseMode();
bool unsetReverseMode(); bool unsetReverseMode();
bool setEnable (bool); bool setEnable (bool);
void setNumber(long); void setNumber (uLong);
void setNumber (long);
void setNumber (float, int = FLT_DIG);
void setNumber (double, int = DBL_DIG);
void setNumber (lDouble, int = LDBL_DIG);
void setText (const FString&); void setText (const FString&);
// Inquiries // Inquiries
@ -78,6 +95,7 @@ class FLabel : public FWidget
// Methods // Methods
void hide(); void hide();
void clear();
// Event handlers // Event handlers
void onMouseDown (FMouseEvent*); void onMouseDown (FMouseEvent*);
@ -152,6 +170,26 @@ inline bool FLabel::setReverseMode()
inline bool FLabel::unsetReverseMode() inline bool FLabel::unsetReverseMode()
{ return setReverseMode(false); } { return setReverseMode(false); }
//----------------------------------------------------------------------
inline void FLabel::setNumber (uLong num)
{ setText(FString().setNumber(num)); }
//----------------------------------------------------------------------
inline void FLabel::setNumber (long num)
{ setText(FString().setNumber(num)); }
//----------------------------------------------------------------------
inline void FLabel::setNumber (float num, int precision)
{ setText(FString().setNumber(num, precision)); }
//----------------------------------------------------------------------
inline void FLabel::setNumber (double num, int precision)
{ setText(FString().setNumber(num, precision)); }
//----------------------------------------------------------------------
inline void FLabel::setNumber (lDouble num, int precision)
{ setText(FString().setNumber(num, precision)); }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline bool FLabel::hasEmphasis() inline bool FLabel::hasEmphasis()
{ return emphasis; } { return emphasis; }
@ -160,4 +198,8 @@ inline bool FLabel::hasEmphasis()
inline bool FLabel::hasReverseMode() inline bool FLabel::hasReverseMode()
{ return reverse_mode; } { return reverse_mode; }
//----------------------------------------------------------------------
inline void FLabel::clear()
{ text.clear(); }
#endif // FLABEL_H #endif // FLABEL_H

View File

@ -50,6 +50,98 @@ FLabel::~FLabel() // destructor
delAccelerator(); delAccelerator();
} }
// FLabel operators
//----------------------------------------------------------------------
FLabel& FLabel::operator = (const FString& s)
{
setText(s);
return *this;
}
//----------------------------------------------------------------------
FLabel& FLabel::operator << (const FString& s)
{
setText(text + s);
return *this;
}
//----------------------------------------------------------------------
FLabel& FLabel::operator << (const wchar_t c)
{
setText(text + c);
return *this;
}
//----------------------------------------------------------------------
FLabel& FLabel::operator << (const uInt num)
{
FString num_str;
num_str << num;
setText(text + num_str);
return *this;
}
//----------------------------------------------------------------------
FLabel& FLabel::operator << (const int num)
{
FString num_str;
num_str << num;
setText(text + num_str);
return *this;
}
//----------------------------------------------------------------------
FLabel& FLabel::operator << (const uLong num)
{
FString num_str;
num_str << num;
setText(text + num_str);
return *this;
}
//----------------------------------------------------------------------
FLabel& FLabel::operator << (const long num)
{
FString num_str;
num_str << num;
setText(text + num_str);
return *this;
}
//----------------------------------------------------------------------
FLabel& FLabel::operator << (const float num)
{
FString num_str;
num_str << num;
setText(text + num_str);
return *this;
}
//----------------------------------------------------------------------
FLabel& FLabel::operator << (const double num)
{
FString num_str;
num_str << num;
setText(text + num_str);
return *this;
}
//----------------------------------------------------------------------
FLabel& FLabel::operator << (const lDouble num)
{
FString num_str;
num_str << num;
setText(text + num_str);
return *this;
}
//----------------------------------------------------------------------
const FLabel& FLabel::operator >> (FString& s)
{
s += text;
return *this;
}
// public methods of FLabel // public methods of FLabel
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -107,12 +199,6 @@ bool FLabel::setEnable (bool on)
return on; return on;
} }
//----------------------------------------------------------------------
void FLabel::setNumber (long num)
{
setText(FString().setNumber(num));
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FLabel::setText (const FString& txt) void FLabel::setText (const FString& txt)
{ {
@ -459,9 +545,6 @@ void FLabel::draw()
uInt length; uInt length;
int hotkeypos, align_offset; int hotkeypos, align_offset;
if ( text.isNull() || text.isEmpty() )
return;
if ( isMonochron() ) if ( isMonochron() )
{ {
setReverse(true); setReverse(true);

View File

@ -468,7 +468,7 @@ FString& FString::operator << (const FString& s)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FString& FString::operator << (const wchar_t c) FString& FString::operator << (const wchar_t c)
{ {
FString s = FString(c); FString s(c);
_insert (length, s.length, s.string); _insert (length, s.length, s.string);
return *this; return *this;
} }
@ -476,7 +476,7 @@ FString& FString::operator << (const wchar_t c)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FString& FString::operator << (const char c) FString& FString::operator << (const char c)
{ {
FString s = FString(c); FString s(c);
_insert (length, s.length, s.string); _insert (length, s.length, s.string);
return *this; return *this;
} }
@ -2467,6 +2467,10 @@ inline void FString::_insert (uInt pos, uInt len, const wchar_t* s)
if ( ! string ) if ( ! string )
{ {
// string is null // string is null
if ( len == 0 ) // String s is also a null string
return;
length = len; length = len;
bufsize = FWDBUFFER + length + 1; bufsize = FWDBUFFER + length + 1;