diff --git a/ChangeLog b/ChangeLog index ec528760..96ff4d85 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2017-12-21 Markus Gans + * Refactoring FButton::draw + * Passing more strings by reference + 2017-12-21 Markus Gans * Refactoring FMenuBar::drawItems * (de)allocation functions in FTerm diff --git a/examples/termcap.cpp b/examples/termcap.cpp index eed18176..b0c4a944 100644 --- a/examples/termcap.cpp +++ b/examples/termcap.cpp @@ -33,7 +33,7 @@ static FVTerm* terminal; // function prototype void tcapBooleans (const std::string&, bool); void tcapNumeric (const std::string&, int); -void tcapString (const std::string&, const char*); +void tcapString (const std::string&, const char[]); void debug (FApplication&); void booleans(); void numeric(); @@ -59,7 +59,7 @@ void tcapNumeric (const std::string& name, int cap_num) } //---------------------------------------------------------------------- -void tcapString (const std::string& name, const char* cap_str) +void tcapString (const std::string& name, const char cap_str[]) { uInt len; std::string sequence; diff --git a/include/final/fbutton.h b/include/final/fbutton.h index f43b871b..11d757b4 100644 --- a/include/final/fbutton.h +++ b/include/final/fbutton.h @@ -136,10 +136,19 @@ class FButton : public FWidget // Methods void init(); + void getButtonState(); uChar getHotkey(); void setHotkeyAccelerator(); void detectHotkey(); + int getHotkeyPos (wchar_t[], wchar_t[], uInt); + int clickAnimationIndent (FWidget*); + void clearRightMargin (FWidget*); + void drawMarginLeft(); + void drawMarginRight(); + void drawTopBottomBackground(); + void drawButtonTextLine (wchar_t[]); void draw(); + void updateStatusBar(); void updateButtonColor(); void processClick(); @@ -148,6 +157,12 @@ class FButton : public FWidget bool button_down; bool click_animation; int click_time; + int indent; + int space; + int center_offset; + int vcenter_offset; + int txtlength; + int hotkeypos; short button_fg; short button_bg; short button_hotkey_fg; @@ -155,6 +170,17 @@ class FButton : public FWidget short button_focus_bg; short button_inactive_fg; short button_inactive_bg; + + struct state + { + uChar focus : 1; + uChar active_focus : 1; + uChar active : 1; + uChar flat : 1; + uChar non_flat_shadow : 1; + uChar no_underline : 1; + uChar : 2; // padding bits + } is; }; #pragma pack(pop) diff --git a/include/final/flistbox.h b/include/final/flistbox.h index 4b232990..9687bc93 100644 --- a/include/final/flistbox.h +++ b/include/final/flistbox.h @@ -247,6 +247,8 @@ class FListBox : public FWidget void drawLabel(); void drawList(); void drawListLine (int, listBoxItems::iterator, bool); + void printLeftBracket (fc::brackets_type); + void printRightBracket (fc::brackets_type); void drawListBracketsLine (int, listBoxItems::iterator, bool); void setLineAttributes (int, bool, bool, bool&); void unsetAttributes(); diff --git a/include/final/flistview.h b/include/final/flistview.h index 9210e77c..6d984df3 100644 --- a/include/final/flistview.h +++ b/include/final/flistview.h @@ -226,7 +226,6 @@ inline const char* FListViewIterator::getClassName() const inline int FListViewIterator::getPosition() const { return position; } - //---------------------------------------------------------------------- // class FListView //---------------------------------------------------------------------- @@ -293,6 +292,9 @@ class FListView : public FWidget void onFocusIn (FFocusEvent*); void onFocusOut (FFocusEvent*); + // Data Members + static FObjectIterator null_iter; + protected: // Methods void adjustViewport(); diff --git a/include/final/fmenu.h b/include/final/fmenu.h index 77256860..a5cd3a7f 100644 --- a/include/final/fmenu.h +++ b/include/final/fmenu.h @@ -204,7 +204,7 @@ class FMenu : public FWindow, public FMenuList void drawAcceleratorKey (int&, int); void drawTrailingSpaces (int); void setLineAttributes (FMenuItem*, int); - void setCursorToHotkeyPosition (FMenuItem*, int); + void setCursorToHotkeyPosition (FMenuItem*); void processActivate(); // Friend classes @@ -221,6 +221,7 @@ class FMenu : public FWindow, public FMenuList FMenu* opened_sub_menu; FMenu* shown_sub_menu; uInt max_item_width; + int hotkeypos; bool mouse_down; bool has_checkable_items; }; diff --git a/include/final/fobject.h b/include/final/fobject.h index 45516dfd..b4d0440d 100644 --- a/include/final/fobject.h +++ b/include/final/fobject.h @@ -86,7 +86,7 @@ class FObject bool isChild (FObject*) const; bool isDirectChild (FObject*) const; bool isWidget() const; - bool isInstanceOf (const char*) const; + bool isInstanceOf (const char[]) const; bool isTimerInUpdating() const; // Methods @@ -186,7 +186,7 @@ inline bool FObject::isWidget() const { return widget_object; } //---------------------------------------------------------------------- -inline bool FObject::isInstanceOf (const char* classname) const +inline bool FObject::isInstanceOf (const char classname[]) const { return ( classname ) ? bool(strcmp(classname, getClassName()) == 0) : false; } //---------------------------------------------------------------------- diff --git a/include/final/fstring.h b/include/final/fstring.h index f8ae4417..c8cb1957 100644 --- a/include/final/fstring.h +++ b/include/final/fstring.h @@ -84,9 +84,9 @@ class FString FString (uInt, char); FString (const FString&); // implicit conversion copy constructor FString (const std::wstring&); // implicit conversion constructor - FString (const wchar_t*); // implicit conversion constructor + FString (const wchar_t[]); // implicit conversion constructor FString (const std::string&); // implicit conversion constructor - FString (const char*); // implicit conversion constructor + FString (const char[]); // implicit conversion constructor FString (const wchar_t); // implicit conversion constructor FString (const char); // implicit conversion constructor @@ -96,25 +96,25 @@ class FString // Overloaded operators FString& operator = (const FString&); FString& operator = (const std::wstring&); - const FString& operator = (const wchar_t*); + const FString& operator = (const wchar_t[]); FString& operator = (const std::string&); - const FString& operator = (const char*); + const FString& operator = (const char[]); const FString& operator = (const wchar_t); const FString& operator = (const char); const FString& operator += (const FString&); const FString& operator += (const std::wstring&); - const FString& operator += (const wchar_t*); + const FString& operator += (const wchar_t[]); const FString& operator += (const std::string&); - const FString& operator += (const char*); + const FString& operator += (const char[]); const FString& operator += (const wchar_t); const FString& operator += (const char); const FString operator + (const FString&); const FString operator + (const std::wstring&); - const FString operator + (const wchar_t*); + const FString operator + (const wchar_t[]); const FString operator + (const std::string&); - const FString operator + (const char*); + const FString operator + (const char[]); const FString operator + (const wchar_t); const FString operator + (const char); @@ -150,44 +150,44 @@ class FString bool operator < (const FString&) const; bool operator < (const std::wstring&) const; - bool operator < (const wchar_t*) const; + bool operator < (const wchar_t[]) const; bool operator < (const std::string&) const; - bool operator < (const char*) const; + bool operator < (const char[]) const; bool operator < (const wchar_t) const; bool operator < (const char) const; bool operator <= (const FString&) const; bool operator <= (const std::wstring&) const; - bool operator <= (const wchar_t*) const; + bool operator <= (const wchar_t[]) const; bool operator <= (const std::string&) const; - bool operator <= (const char*) const; + bool operator <= (const char[]) const; bool operator <= (const wchar_t) const; bool operator <= (const char) const; bool operator == (const FString&) const; bool operator == (const std::wstring&) const; - bool operator == (const wchar_t*) const; + bool operator == (const wchar_t[]) const; bool operator == (const std::string&) const; - bool operator == (const char*) const; + bool operator == (const char[]) const; bool operator == (const wchar_t) const; bool operator == (const char) const; bool operator != (const FString&) const; bool operator != (const std::wstring&) const; - bool operator != (const wchar_t*) const; + bool operator != (const wchar_t[]) const; bool operator != (const std::string&) const; - bool operator != (const char*) const; + bool operator != (const char[]) const; bool operator != (const wchar_t) const; bool operator != (const char) const; bool operator >= (const FString&) const; bool operator >= (const std::wstring&) const; - bool operator >= (const wchar_t*) const; + bool operator >= (const wchar_t[]) const; bool operator >= (const std::string&) const; - bool operator >= (const char*) const; + bool operator >= (const char[]) const; bool operator >= (const wchar_t) const; bool operator >= (const char) const; bool operator > (const FString&) const; bool operator > (const std::wstring&) const; - bool operator > (const wchar_t*) const; + bool operator > (const wchar_t[]) const; bool operator > (const std::string&) const; - bool operator > (const char*) const; + bool operator > (const char[]) const; bool operator > (const wchar_t) const; bool operator > (const char) const; @@ -197,9 +197,9 @@ class FString friend const FString operator + (const FString&, const FString&); friend const FString operator + (const FString&, const wchar_t); friend const FString operator + (const std::wstring&, const FString&); - friend const FString operator + (const wchar_t*, const FString&); + friend const FString operator + (const wchar_t[], const FString&); friend const FString operator + (const std::string&, const FString&); - friend const FString operator + (const char*, const FString&); + friend const FString operator + (const char[], const FString&); friend const FString operator + (const wchar_t, const FString&); friend const FString operator + (const char, const FString&); friend const FString operator + (const wchar_t, const std::wstring&); @@ -223,8 +223,8 @@ class FString wchar_t front() const; wchar_t back() const; - FString& sprintf (const wchar_t*, ...); - FString& sprintf (const char*, ...) + FString& sprintf (const wchar_t[], ...); + FString& sprintf (const char[], ...) #if defined(__clang__) __attribute__((__format__ (__printf__, 2, 3))) #elif defined(__GNUC__) @@ -264,14 +264,14 @@ class FString FStringList split (const FString&); FStringList split (const std::wstring&); - FStringList split (const wchar_t*); + FStringList split (const wchar_t[]); FStringList split (const std::string&); - FStringList split (const char*); + FStringList split (const char[]); FStringList split (const wchar_t); FStringList split (const char); - FString& setString (const wchar_t*); - FString& setString (const char*); + FString& setString (const wchar_t[]); + FString& setString (const char[]); FString& setNumber (sInt16); FString& setNumber (uInt16); @@ -291,58 +291,58 @@ class FString FString& setFormatedNumber (uLong, char = nl_langinfo(THOUSEP)[0]); const FString& insert (const FString&, uInt); - const FString& insert (const wchar_t*, uInt); - const FString& insert (const char*, uInt); + const FString& insert (const wchar_t[], uInt); + const FString& insert (const char[], uInt); const FString& insert (const wchar_t, uInt); const FString& insert (const char, uInt); FString replace (const FString&, const FString&); FString replace (const FString&, const std::wstring&); - FString replace (const FString&, const wchar_t*); + FString replace (const FString&, const wchar_t[]); FString replace (const FString&, const std::string&); - FString replace (const FString&, const char*); + FString replace (const FString&, const char[]); FString replace (const FString&, const wchar_t); FString replace (const FString&, const char); FString replace (const std::wstring&, const FString&); FString replace (const std::wstring&, const std::wstring&); - FString replace (const std::wstring&, const wchar_t*); + FString replace (const std::wstring&, const wchar_t[]); FString replace (const std::wstring&, const std::string&); - FString replace (const std::wstring&, const char*); + FString replace (const std::wstring&, const char[]); FString replace (const std::wstring&, const wchar_t); FString replace (const std::wstring&, const char); FString replace (const std::string&, const FString&); FString replace (const std::string&, const std::wstring&); - FString replace (const std::string&, const wchar_t*); + FString replace (const std::string&, const wchar_t[]); FString replace (const std::string&, const std::string&); - FString replace (const std::string&, const char*); + FString replace (const std::string&, const char[]); FString replace (const std::string&, const wchar_t); FString replace (const std::string&, const char); - FString replace (const wchar_t*, const FString&); - FString replace (const wchar_t*, const std::wstring&); - FString replace (const wchar_t*, const wchar_t*); - FString replace (const wchar_t*, const std::string&); - FString replace (const wchar_t*, const char*); - FString replace (const wchar_t*, const wchar_t); - FString replace (const wchar_t*, const char); - FString replace (const char*, const FString&); - FString replace (const char*, const std::wstring&); - FString replace (const char*, const wchar_t*); - FString replace (const char*, const std::string&); - FString replace (const char*, const char*); - FString replace (const char*, const wchar_t); - FString replace (const char*, const char); + FString replace (const wchar_t[], const FString&); + FString replace (const wchar_t[], const std::wstring&); + FString replace (const wchar_t[], const wchar_t[]); + FString replace (const wchar_t[], const std::string&); + FString replace (const wchar_t[], const char[]); + FString replace (const wchar_t[], const wchar_t); + FString replace (const wchar_t[], const char); + FString replace (const char[], const FString&); + FString replace (const char[], const std::wstring&); + FString replace (const char[], const wchar_t[]); + FString replace (const char[], const std::string&); + FString replace (const char[], const char[]); + FString replace (const char[], const wchar_t); + FString replace (const char[], const char); FString replace (const wchar_t, const FString&); FString replace (const wchar_t, const std::wstring&); - FString replace (const wchar_t, const wchar_t*); + FString replace (const wchar_t, const wchar_t[]); FString replace (const wchar_t, const std::string&); - FString replace (const wchar_t, const char*); + FString replace (const wchar_t, const char[]); FString replace (const wchar_t, const wchar_t); FString replace (const wchar_t, const char); FString replace (const char, const FString&); FString replace (const char, const std::wstring&); - FString replace (const char, const wchar_t*); + FString replace (const char, const wchar_t[]); FString replace (const char, const std::string&); - FString replace (const char, const char*); + FString replace (const char, const char[]); FString replace (const char, const wchar_t); FString replace (const char, const char); @@ -352,13 +352,13 @@ class FString FString removeBackspaces() const; const FString& overwrite (const FString&, uInt); - const FString& overwrite (const wchar_t*, uInt); + const FString& overwrite (const wchar_t[], uInt); const FString& overwrite (const wchar_t, uInt); const FString& remove (uInt, uInt); bool includes (const FString&); - bool includes (const wchar_t*); - bool includes (const char*); + bool includes (const wchar_t[]); + bool includes (const char[]); bool includes (const wchar_t); bool includes (const char); @@ -371,12 +371,12 @@ class FString // Methods void initLength (uInt); - void _assign (const wchar_t*); - void _insert (uInt, uInt, const wchar_t*); + void _assign (const wchar_t[]); + void _insert (uInt, uInt, const wchar_t[]); void _remove (uInt, uInt); - char* wc_to_c_str (const wchar_t*) const; - wchar_t* c_to_wc_str (const char*) const; - wchar_t* extractToken (wchar_t**, const wchar_t*, const wchar_t*); + char* wc_to_c_str (const wchar_t[]) const; + wchar_t* c_to_wc_str (const char[]) const; + wchar_t* extractToken (wchar_t*[], const wchar_t[], const wchar_t[]); // Data Members wchar_t* string; @@ -426,7 +426,7 @@ inline FStringList FString::split (const std::wstring& s) { return split(FString(s)); } //---------------------------------------------------------------------- -inline FStringList FString::split (const wchar_t* s) +inline FStringList FString::split (const wchar_t s[]) { return split(FString(s)); } //---------------------------------------------------------------------- @@ -434,7 +434,7 @@ inline FStringList FString::split (const std::string& s) { return split(FString(s)); } //---------------------------------------------------------------------- -inline FStringList FString::split (const char* s) +inline FStringList FString::split (const char s[]) { return split(FString(s)); } //---------------------------------------------------------------------- diff --git a/include/final/fterm.h b/include/final/fterm.h index 3c7fb27b..12bb6cf3 100644 --- a/include/final/fterm.h +++ b/include/final/fterm.h @@ -303,14 +303,14 @@ class FTerm // function pointer -> static function static int (*Fputchar)(int); - static void putstringf (const char* const, ...) + static void putstringf (const char[], ...) #if defined(__clang__) __attribute__((__format__ (__printf__, 1, 2))) #elif defined(__GNUC__) __attribute__ ((format (printf, 1, 2))) #endif ; - static void putstring (const char* const, int = 1); + static void putstring (const char[], int = 1); #if defined(__sun) && defined(__SVR4) static int putchar_ASCII (register char); @@ -456,7 +456,7 @@ class FTerm #if defined(__linux__) static int getScreenFont(); - static int setScreenFont ( uChar*, uInt, uInt, uInt + static int setScreenFont ( uChar[], uInt, uInt, uInt , bool = false ); static int setUnicodeMap (struct unimapdesc*); static int getUnicodeMap (); diff --git a/include/final/ftermbuffer.h b/include/final/ftermbuffer.h index 43b96a84..4e72b741 100644 --- a/include/final/ftermbuffer.h +++ b/include/final/ftermbuffer.h @@ -77,8 +77,8 @@ class FTermBuffer // Methods void clear(); - int writef (const wchar_t*, ...); - int writef (const char*, ...) + int writef (const wchar_t[], ...); + int writef (const char[], ...) #if defined(__clang__) __attribute__((__format__ (__printf__, 2, 3))) #elif defined(__GNUC__) @@ -86,8 +86,8 @@ class FTermBuffer #endif ; int write (const std::wstring&); - int write (const wchar_t*); - int write (const char*); + int write (const wchar_t[]); + int write (const char[]); int write (const std::string&); int write (const FString&); int write (int); diff --git a/include/final/fvterm.h b/include/final/fvterm.h index 846dcac4..fcd3646d 100644 --- a/include/final/fvterm.h +++ b/include/final/fvterm.h @@ -222,8 +222,8 @@ class FVTerm : public FTerm , FPreprocessingHandler ); virtual void delPreprocessingHandler (FVTerm*); - int printf (const wchar_t*, ...); - int printf (const char*, ...) + int printf (const wchar_t[], ...); + int printf (const char[], ...) #if defined(__clang__) __attribute__((__format__ (__printf__, 2, 3))) #elif defined(__GNUC__) @@ -232,10 +232,10 @@ class FVTerm : public FTerm ; int print (const std::wstring&); int print (term_area*, const std::wstring&); - int print (const wchar_t*); - int print (term_area*, const wchar_t*); - int print (const char*); - int print (term_area*, const char*); + int print (const wchar_t[]); + int print (term_area*, const wchar_t[]); + int print (const char[]); + int print (term_area*, const char[]); int print (const std::string&); int print (term_area*, const std::string&); int print (const FString&); diff --git a/src/fbutton.cpp b/src/fbutton.cpp index 352d0224..669ca387 100644 --- a/src/fbutton.cpp +++ b/src/fbutton.cpp @@ -37,6 +37,12 @@ FButton::FButton(FWidget* parent) , button_down(false) , click_animation(true) , click_time(150) + , indent(0) + , space(int(' ')) + , center_offset(0) + , vcenter_offset(0) + , txtlength(0) + , hotkeypos(-1) , button_fg(wc.button_active_fg) , button_bg(wc.button_active_bg) , button_hotkey_fg(wc.button_hotkey_fg) @@ -44,6 +50,7 @@ FButton::FButton(FWidget* parent) , button_focus_bg(wc.button_active_focus_bg) , button_inactive_fg(wc.button_inactive_fg) , button_inactive_bg(wc.button_inactive_bg) + , is() { init(); } @@ -55,6 +62,12 @@ FButton::FButton (const FString& txt, FWidget* parent) , button_down(false) , click_animation(true) , click_time(150) + , indent(0) + , space(int(' ')) + , center_offset(0) + , vcenter_offset(0) + , txtlength(0) + , hotkeypos(-1) , button_fg(wc.button_active_fg) , button_bg(wc.button_active_bg) , button_hotkey_fg(wc.button_hotkey_fg) @@ -62,6 +75,7 @@ FButton::FButton (const FString& txt, FWidget* parent) , button_focus_bg(wc.button_active_focus_bg) , button_inactive_fg(wc.button_inactive_fg) , button_inactive_bg(wc.button_inactive_bg) + , is() { init(); detectHotkey(); @@ -453,6 +467,18 @@ void FButton::init() setShadow(); } +//---------------------------------------------------------------------- +void FButton::getButtonState() +{ + int active_focus = fc::active + fc::focus; + is.active_focus = ((flags & active_focus) == active_focus); + is.active = ((flags & fc::active) != 0); + is.focus = ((flags & fc::focus) != 0); + is.flat = isFlat(); + is.non_flat_shadow = ((flags & (fc::shadow + fc::flat)) == fc::shadow); + is.no_underline = ((flags & fc::no_underline) != 0); +} + //---------------------------------------------------------------------- uChar FButton::getHotkey() { @@ -511,112 +537,18 @@ inline void FButton::detectHotkey() } //---------------------------------------------------------------------- -void FButton::draw() +int FButton::getHotkeyPos (wchar_t src[], wchar_t dest[], uInt length) { - int active_focus - , d - , i - , j - , x - , mono_offset - , mono_1st_char - , margin - , length - , hotkeypos - , hotkey_offset - , space; - bool is_ActiveFocus - , is_Active - , is_Focus - , is_Flat - , is_NonFlatShadow - , is_NoUnderline; - register wchar_t* src; - register wchar_t* dest; - wchar_t* ButtonText; - FString txt; - FWidget* parent_widget = getParentWidget(); - - length = int(text.getLength()); - hotkeypos = -1; - hotkey_offset = 0; - space = int(' '); - - try - { - if ( isMonochron() || getMaxColor() < 16 ) - ButtonText = new wchar_t[length + 3](); - else - ButtonText = new wchar_t[length + 1](); - } - catch (const std::bad_alloc& ex) - { - std::cerr << "not enough memory to alloc " << ex.what() << std::endl; - return; - } - - txt = FString(text); - src = const_cast(txt.wc_str()); - dest = const_cast(ButtonText); - - active_focus = fc::active + fc::focus; - is_ActiveFocus = ((flags & active_focus) == active_focus); - is_Active = ((flags & fc::active) != 0); - is_Focus = ((flags & fc::focus) != 0); - is_Flat = isFlat(); - is_NonFlatShadow = ((flags & (fc::shadow + fc::flat)) == fc::shadow); - is_NoUnderline = ((flags & fc::no_underline) != 0); - - if ( isMonochron() ) - setReverse(true); - - if ( button_down && click_animation ) - { - // noshadow + indent one character to the right - if ( is_Flat ) - clearFlatBorder(); - else - clearShadow(); - - if ( parent_widget ) - setColor ( parent_widget->getForegroundColor() - , parent_widget->getBackgroundColor() ); - - for (int y = 1; y <= getHeight(); y++) - { - setPrintPos (1, y); - print (' '); // clear one left █ - } - - d = 1; - } - else - d = 0; - - if ( ! is_Active && isMonochron() ) - space = fc::MediumShade; // ▒ - - if ( isMonochron() && is_ActiveFocus ) - { - txt = "<" + txt + ">"; - length = int(txt.getLength()); - src = const_cast(txt.wc_str()); - mono_1st_char = 1; - mono_offset = 2; - } - else - { - mono_1st_char = 0; - mono_offset = 0; - } - // find hotkey position in string // + generate a new string without the '&'-sign - for (i = 0; i < length; i++) + int pos = -1; + wchar_t* txt = src; + + for (uInt i = 0; i < length; i++) { - if ( i < length && txt[uInt(i)] == '&' && hotkeypos == -1 ) + if ( i < length && txt[i] == L'&' && pos == -1 ) { - hotkeypos = i; + pos = int(i); i++; src++; } @@ -624,158 +556,271 @@ void FButton::draw() *dest++ = *src++; } - if ( hotkeypos != -1 ) - hotkey_offset = 1; + return pos; +} - if ( length - hotkey_offset + mono_offset - hotkey_offset <= getWidth() ) - margin = 1; +//---------------------------------------------------------------------- +inline int FButton::clickAnimationIndent (FWidget* parent_widget) +{ + if ( ! button_down || ! click_animation ) + return 0; + + // noshadow + indent one character to the right + if ( is.flat ) + clearFlatBorder(); else - margin = 0; + clearShadow(); - if ( isMonochron() && (is_Active || is_Focus) ) - setReverse(false); + if ( parent_widget ) + setColor ( parent_widget->getForegroundColor() + , parent_widget->getBackgroundColor() ); - if ( margin == 1 ) + for (int y = 1; y <= getHeight(); y++) { - setColor (getForegroundColor(), button_bg); + setPrintPos (1, y); + print (' '); // clear one left █ + } - for (int y = 0; y < getHeight(); y++) - { - setPrintPos (1 + d, 1 + y); + return 1; +} + +//---------------------------------------------------------------------- +inline void FButton::clearRightMargin (FWidget* parent_widget) +{ + if ( button_down + || isNewFont() + || ( ! is.flat && hasShadow() && ! isMonochron()) ) + return; + + // Restore the right background after button down + if ( parent_widget ) + setColor ( parent_widget->getForegroundColor() + , parent_widget->getBackgroundColor() ); + + for (int y = 1; y <= getHeight(); y++) + { + if ( isMonochron() ) + setReverse(true); // Light background + + setPrintPos (1 + getWidth(), y); + print (' '); // clear right + + if ( is.active && isMonochron() ) + setReverse(false); // Dark background + } +} + +//---------------------------------------------------------------------- +inline void FButton::drawMarginLeft() +{ + // Print left margin + + setColor (getForegroundColor(), button_bg); + + for (int y = 0; y < getHeight(); y++) + { + setPrintPos (1 + indent, 1 + y); + + if ( isMonochron() && is.active_focus && y == vcenter_offset ) + print (fc::BlackRightPointingPointer); // ► + else print (space); // full block █ - } } +} - if ( is_Flat && ! button_down ) - drawFlatBorder(); +//---------------------------------------------------------------------- +inline void FButton::drawMarginRight() +{ + // Print right margin - if ( ! button_down - && ! isNewFont() - && (is_Flat || ! hasShadow() || isMonochron()) ) + for (int y = 0; y < getHeight(); y++) { - // clear the right █ from button down - if ( parent_widget ) - setColor ( parent_widget->getForegroundColor() - , parent_widget->getBackgroundColor() ); + setPrintPos (getWidth() + indent, 1 + y); - for (int y = 1; y <= getHeight(); y++) - { - if ( isMonochron() ) - setReverse(true); + if ( isMonochron() && is.active_focus && y == vcenter_offset ) + print (fc::BlackLeftPointingPointer); // ◄ + else + print (space); // full block █ + } +} - setPrintPos (1 + getWidth(), y); - print (' '); // clear right +//---------------------------------------------------------------------- +inline void FButton::drawTopBottomBackground() +{ + // Print top and bottom button background - if ( isMonochron() ) - setReverse(false); - } + if ( getHeight() < 2 ) + return; + + for (int y = 0; y < vcenter_offset; y++) + { + setPrintPos (2 + indent, 1 + y); + + for (int x = 1; x < getWidth() - 1; x++) + print (space); // █ } - if ( hotkeypos != -1 ) - length--; + for (int y = vcenter_offset + 1; y < getHeight(); y++) + { + setPrintPos (2 + indent, 1 + y); - i = getWidth() - length - 1; - i = int(i / 2); + for (int x = 1; x < getWidth() - 1; x++) + print (space); // █ + } +} - if ( getHeight() >= 2 ) - j = int((getHeight() - 1) / 2); - else - j = 0; - - setPrintPos (1 + margin + d, 1 + j); +//---------------------------------------------------------------------- +inline void FButton::drawButtonTextLine (wchar_t button_text[]) +{ + int pos; + center_offset = int((getWidth() - txtlength - 1) / 2); + setPrintPos (2 + indent, 1 + vcenter_offset); setColor (button_fg, button_bg); - for (x = 0; x < i; x++) + // Print button text line -------- + for (pos = 0; pos < center_offset; pos++) print (space); // █ if ( hotkeypos == -1 ) - setCursorPos (1 + margin + i + mono_1st_char, 1 + j ); // first character + setCursorPos ( 2 + center_offset + , 1 + vcenter_offset ); // first character else - setCursorPos (1 + margin + i + hotkeypos, 1 + j ); // hotkey + setCursorPos ( 2 + center_offset + hotkeypos + , 1 + vcenter_offset ); // hotkey - if ( is_ActiveFocus && (isMonochron() || getMaxColor() < 16) ) + if ( ! is.active && isMonochron() ) + setReverse(true); // Light background + + if ( is.active_focus && (isMonochron() || getMaxColor() < 16) ) setBold(); - for (int z = 0; x < i + length && z < getWidth(); z++, x++) + for ( int z = 0 + ; pos < center_offset + txtlength && z < getWidth() - 2 + ; z++, pos++) { - if ( (z == hotkeypos) && is_Active ) + if ( (z == hotkeypos) && is.active ) { setColor (button_hotkey_fg, button_bg); - if ( ! is_ActiveFocus && getMaxColor() < 16 ) + if ( ! is.active_focus && getMaxColor() < 16 ) setBold(); - if ( ! is_NoUnderline ) + if ( ! is.no_underline ) setUnderline(); - print ( ButtonText[z] ); + print (button_text[z]); - if ( ! is_ActiveFocus && getMaxColor() < 16 ) + if ( ! is.active_focus && getMaxColor() < 16 ) unsetBold(); - if ( ! is_NoUnderline ) + if ( ! is.no_underline ) unsetUnderline(); setColor (button_fg, button_bg); } else { - print ( ButtonText[z] ); + print (button_text[z]); } } - if ( is_ActiveFocus && (isMonochron() || getMaxColor() < 16) ) + if ( txtlength > getWidth() - 2 ) + { + // Print ellipsis + setPrintPos (getWidth() + indent - 2, 1); + print (L".."); + } + + if ( is.active_focus && (isMonochron() || getMaxColor() < 16) ) unsetBold(); - for (x = i + length; x < getWidth() - 1; x++) + for (pos = center_offset + txtlength; pos < getWidth() - 2; pos++) print (space); // █ +} + +//---------------------------------------------------------------------- +void FButton::draw() +{ + wchar_t* button_text; + FWidget* parent_widget = getParentWidget(); + txtlength = int(text.getLength()); + space = int(' '); + getButtonState(); + + try + { + button_text = new wchar_t[txtlength + 1](); + } + catch (const std::bad_alloc& ex) + { + std::cerr << "not enough memory to alloc " << ex.what() << std::endl; + return; + } + + if ( isMonochron() ) + setReverse(true); // Light background + + // Click animation preprocessing + indent = clickAnimationIndent (parent_widget); + + // Clear right margin after animation + clearRightMargin (parent_widget); + + if ( ! is.active && isMonochron() ) + space = fc::MediumShade; // ▒ simulates greyed out at Monochron + + if ( isMonochron() && (is.active || is.focus) ) + setReverse(false); // Dark background + + if ( is.flat && ! button_down ) + drawFlatBorder(); + + hotkeypos = getHotkeyPos(text.wc_str(), button_text, uInt(txtlength)); + + if ( hotkeypos != -1 ) + txtlength--; if ( getHeight() >= 2 ) - { - for (i = 0; i < j; i++) - { - setPrintPos (2 + d, 1 + i); + vcenter_offset = int((getHeight() - 1) / 2); + else + vcenter_offset = 0; - for (int z = 1; z < getWidth(); z++) - print (space); // █ - } - for (i = j + 1; i < getHeight(); i++) - { - setPrintPos (2 + d, 1 + i); + // Print left margin + drawMarginLeft(); - for (int z = 1; z < getWidth(); z++) - print (space); // █ - } - } + // Print button text line + drawButtonTextLine(button_text); - if ( isMonochron() ) - setReverse(true); + // Print right margin + drawMarginRight(); - if ( is_NonFlatShadow && ! button_down ) - { - if ( parent_widget ) - setColor ( parent_widget->getForegroundColor() - , parent_widget->getBackgroundColor() ); + // Print top and bottom button background + drawTopBottomBackground(); - print(' '); // restore background after button down + // Draw button shadow + if ( is.non_flat_shadow && ! button_down ) drawShadow(); - } if ( isMonochron() ) - setReverse(false); + setReverse(false); // Dark background - delete[] ButtonText; + delete[] button_text; + updateStatusBar(); +} - if ( is_Focus && getStatusBar() ) +//---------------------------------------------------------------------- +void FButton::updateStatusBar() +{ + if ( ! is.focus || ! getStatusBar() ) + return; + + const FString& msg = getStatusbarMessage(); + const FString& curMsg = getStatusBar()->getMessage(); + + if ( curMsg != msg ) { - const FString& msg = getStatusbarMessage(); - const FString& curMsg = getStatusBar()->getMessage(); - - if ( curMsg != msg ) - { - getStatusBar()->setMessage(msg); - getStatusBar()->drawMessage(); - } + getStatusBar()->setMessage(msg); + getStatusBar()->drawMessage(); } } diff --git a/src/fbuttongroup.cpp b/src/fbuttongroup.cpp index 678f5332..650f8555 100644 --- a/src/fbuttongroup.cpp +++ b/src/fbuttongroup.cpp @@ -559,6 +559,9 @@ void FButtonGroup::drawLabel() else FWidget::setPrintPos (0, 1); + if ( isMonochron() ) + setReverse(true); + if ( isEnabled() ) setColor(wc.label_emphasis_fg, wc.label_bg); else @@ -584,6 +587,9 @@ void FButtonGroup::drawLabel() print ( LabelText[z] ); } + if ( isMonochron() ) + setReverse(true); + setViewportPrint(); delete[] LabelText; } diff --git a/src/flabel.cpp b/src/flabel.cpp index 80ace3fc..458cf5b7 100644 --- a/src/flabel.cpp +++ b/src/flabel.cpp @@ -561,7 +561,7 @@ void FLabel::printLine ( wchar_t line[] //---------------------------------------------------------------------- void FLabel::draw() { - wchar_t* LabelText; + wchar_t* label_text; uInt length; int hotkeypos, align_offset; @@ -592,7 +592,7 @@ void FLabel::draw() try { - LabelText = new wchar_t[length + 1](); + label_text = new wchar_t[length + 1](); } catch (const std::bad_alloc& ex) { @@ -601,7 +601,7 @@ void FLabel::draw() } wchar_t* src = const_cast(multiline_text[y].wc_str()); - wchar_t* dest = const_cast(LabelText); + wchar_t* dest = const_cast(label_text); if ( ! hotkey_printed ) hotkeypos = getHotkeyPos(src, dest, length); @@ -613,18 +613,18 @@ void FLabel::draw() if ( hotkeypos != -1 ) { align_offset = getAlignOffset (int(length - 1)); - printLine (LabelText, length - 1, hotkeypos, align_offset); + printLine (label_text, length - 1, hotkeypos, align_offset); hotkey_printed = true; hotkeypos = -1; } else { align_offset = getAlignOffset (int(length)); - printLine (LabelText, length, -1, align_offset); + printLine (label_text, length, -1, align_offset); } y++; - delete[] LabelText; + delete[] label_text; } } else @@ -633,7 +633,7 @@ void FLabel::draw() try { - LabelText = new wchar_t[length + 1](); + label_text = new wchar_t[length + 1](); } catch (const std::bad_alloc& ex) { @@ -641,15 +641,15 @@ void FLabel::draw() return; } - hotkeypos = getHotkeyPos (text.wc_str(), LabelText, length); + hotkeypos = getHotkeyPos (text.wc_str(), label_text, length); if ( hotkeypos != -1 ) length--; setPrintPos (1,1); align_offset = getAlignOffset (int(length)); - printLine (LabelText, length, hotkeypos, align_offset); - delete[] LabelText; + printLine (label_text, length, hotkeypos, align_offset); + delete[] label_text; } if ( isMonochron() ) diff --git a/src/flistbox.cpp b/src/flistbox.cpp index 2829db14..80f280a9 100644 --- a/src/flistbox.cpp +++ b/src/flistbox.cpp @@ -1259,14 +1259,15 @@ inline void FListBox::drawListLine ( int y uInt i, len; uInt inc_len = inc_search.getLength(); bool isCurrentLine = bool(y + yoffset + 1 == current); + bool isFocus = ((flags & fc::focus) != 0); FString element; element = getString(iter).mid ( uInt(1 + xoffset) , uInt(getWidth() - nf_offset - 4) ); const wchar_t* const& element_str = element.wc_str(); len = element.getLength(); - if ( isMonochron() && isCurrentLine ) - print ('>'); + if ( isMonochron() && isCurrentLine && isFocus ) + print (fc::BlackRightPointingPointer); // ► else print (' '); @@ -1276,16 +1277,16 @@ inline void FListBox::drawListLine ( int y for (i = 0; i < len; i++) { - if ( serach_mark && i == inc_len ) + if ( serach_mark && i == inc_len && isFocus ) setColor ( wc.current_element_focus_fg , wc.current_element_focus_bg ); print (element_str[i]); } - if ( isMonochron() && isCurrentLine ) + if ( isMonochron() && isCurrentLine && isFocus ) { - print ('<'); + print (fc::BlackLeftPointingPointer); // ◄ i++; } @@ -1293,6 +1294,58 @@ inline void FListBox::drawListLine ( int y print (' '); } +//---------------------------------------------------------------------- +inline void FListBox::printLeftBracket (fc::brackets_type bracket_type) +{ + switch ( bracket_type ) + { + case fc::NoBrackets: + break; + + case fc::SquareBrackets: + print ('['); + break; + + case fc::Parenthesis: + print ('('); + break; + + case fc::CurlyBrackets: + print ('{'); + break; + + case fc::AngleBrackets: + print ('<'); + break; + } +} + +//---------------------------------------------------------------------- +inline void FListBox::printRightBracket (fc::brackets_type bracket_type) +{ + switch ( bracket_type ) + { + case fc::NoBrackets: + break; + + case fc::SquareBrackets: + print (']'); + break; + + case fc::Parenthesis: + print (')'); + break; + + case fc::CurlyBrackets: + print ('}'); + break; + + case fc::AngleBrackets: + print ('>'); + break; + } +} + //---------------------------------------------------------------------- inline void FListBox::drawListBracketsLine ( int y , listBoxItems::iterator iter @@ -1305,37 +1358,17 @@ inline void FListBox::drawListBracketsLine ( int y , i = 0 , b = 0; bool isCurrentLine = bool(y + yoffset + 1 == current); + bool isFocus = ((flags & fc::focus) != 0); - if ( isMonochron() && isCurrentLine ) - print ('>'); + if ( isMonochron() && isCurrentLine && isFocus ) + print (fc::BlackRightPointingPointer); // ► else print (' '); if ( xoffset == 0 ) { b = 1; - - switch ( iter->brackets ) - { - case fc::NoBrackets: - break; - - case fc::SquareBrackets: - print ('['); - break; - - case fc::Parenthesis: - print ('('); - break; - - case fc::CurlyBrackets: - print ('{'); - break; - - case fc::AngleBrackets: - print ('<'); - break; - } + printLeftBracket (iter->brackets); element = getString(iter).mid ( uInt(1 + xoffset) , uInt(getWidth() - nf_offset - 5) ); @@ -1369,34 +1402,13 @@ inline void FListBox::drawListBracketsLine ( int y setColor ( wc.current_element_focus_fg , wc.current_element_focus_bg ); - switch ( iter->brackets ) - { - case fc::NoBrackets: - break; - - case fc::SquareBrackets: - print (']'); - break; - - case fc::Parenthesis: - print (')'); - break; - - case fc::CurlyBrackets: - print ('}'); - break; - - case fc::AngleBrackets: - print ('>'); - break; - } - + printRightBracket (iter->brackets); i++; } - if ( isMonochron() && isCurrentLine ) + if ( isMonochron() && isCurrentLine && isFocus ) { - print ('<'); + print (fc::BlackLeftPointingPointer); // ◄ i++; } diff --git a/src/flistview.cpp b/src/flistview.cpp index 00856d90..3d408bd3 100644 --- a/src/flistview.cpp +++ b/src/flistview.cpp @@ -28,8 +28,8 @@ #include "final/fstatusbar.h" #include "final/ftermbuffer.h" -// Global null FObject iterator -static FObject::FObjectIterator null_iter; +// Static class attribute +FObject::FObjectIterator FListView::null_iter; //---------------------------------------------------------------------- // class FListViewItem @@ -154,7 +154,7 @@ FObject::FObjectIterator FListViewItem::insert (FListViewItem* child) { // Add a FListViewItem as child element if ( ! child ) - return null_iter; + return FListView::null_iter; return appendItem(child); } @@ -163,8 +163,8 @@ FObject::FObjectIterator FListViewItem::insert (FListViewItem* child) FObject::FObjectIterator FListViewItem::insert ( FListViewItem* child , FObjectIterator parent_iter ) { - if ( parent_iter == null_iter ) - return null_iter; + if ( parent_iter == FListView::null_iter ) + return FListView::null_iter; if ( *parent_iter ) { @@ -182,7 +182,7 @@ FObject::FObjectIterator FListViewItem::insert ( FListViewItem* child } } - return null_iter; + return FListView::null_iter; } //---------------------------------------------------------------------- @@ -586,8 +586,8 @@ FObject::FObjectIterator FListView::insert ( FListViewItem* item FObjectIterator item_iter; headerItems::iterator header_iter; - if ( parent_iter == null_iter ) - return null_iter; + if ( parent_iter == FListView::null_iter ) + return FListView::null_iter; // Determine the line width header_iter = header.begin(); @@ -636,10 +636,10 @@ FObject::FObjectIterator FListView::insert ( FListViewItem* item item_iter = parent->appendItem (item); } else - item_iter = null_iter; + item_iter = FListView::null_iter; } else - item_iter = null_iter; + item_iter = FListView::null_iter; if ( itemlist.size() == 1 ) { @@ -661,20 +661,20 @@ FObject::FObjectIterator FListView::insert ( const FStringList& cols { FListViewItem* item; - if ( cols.empty() || parent_iter == null_iter ) - return null_iter; + if ( cols.empty() || parent_iter == FListView::null_iter ) + return FListView::null_iter; if ( ! *parent_iter ) parent_iter = root; try { - item = new FListViewItem (cols, d, null_iter); + item = new FListViewItem (cols, d, FListView::null_iter); } catch (const std::bad_alloc& ex) { std::cerr << "not enough memory to alloc " << ex.what() << std::endl; - return null_iter; + return FListView::null_iter; } item->replaceControlCodes(); diff --git a/src/fmenu.cpp b/src/fmenu.cpp index fcb9490c..88f2fda8 100644 --- a/src/fmenu.cpp +++ b/src/fmenu.cpp @@ -40,6 +40,7 @@ FMenu::FMenu(FWidget* parent) , opened_sub_menu(0) , shown_sub_menu(0) , max_item_width(0) + , hotkeypos(-1) , mouse_down(false) , has_checkable_items(false) { @@ -54,6 +55,7 @@ FMenu::FMenu (const FString& txt, FWidget* parent) , opened_sub_menu(0) , shown_sub_menu(0) , max_item_width(0) + , hotkeypos(-1) , mouse_down(false) , has_checkable_items(false) { @@ -1298,14 +1300,14 @@ int FMenu::getHotkeyPos (wchar_t src[], wchar_t dest[], uInt length) { // Find hotkey position in string // + generate a new string without the '&'-sign - int hotkeypos = -1; + int pos = -1; wchar_t* txt = src; for (uInt i = 0; i < length; i++) { - if ( i < length && txt[i] == L'&' && hotkeypos == -1 ) + if ( i < length && txt[i] == L'&' && pos == -1 ) { - hotkeypos = int(i); + pos = int(i); i++; src++; } @@ -1313,7 +1315,7 @@ int FMenu::getHotkeyPos (wchar_t src[], wchar_t dest[], uInt length) *dest++ = *src++; } - return hotkeypos; + return pos; } //---------------------------------------------------------------------- @@ -1383,12 +1385,11 @@ inline void FMenu::drawSeparator (int y) } //---------------------------------------------------------------------- -void FMenu::drawMenuLine (FMenuItem* menuitem, int y) +inline void FMenu::drawMenuLine (FMenuItem* menuitem, int y) { FString txt = menuitem->getText(); menuText txtdata; uInt txt_length = uInt(txt.getLength()); - int hotkeypos; int to_char = int(txt_length); int accel_key = menuitem->accel_key; bool is_enabled = menuitem->isEnabled(); @@ -1420,7 +1421,7 @@ void FMenu::drawMenuLine (FMenuItem* menuitem, int y) txtdata.length = to_char; txtdata.no_underline = ((menuitem->getFlags() & fc::no_underline) != 0); - setCursorToHotkeyPosition (menuitem, hotkeypos); + setCursorToHotkeyPosition (menuitem); if ( ! is_enabled || is_selected ) txtdata.hotkeypos = -1; @@ -1445,7 +1446,7 @@ void FMenu::drawMenuLine (FMenuItem* menuitem, int y) } //---------------------------------------------------------------------- -void FMenu::drawCheckMarkPrefix (FMenuItem* menuitem) +inline void FMenu::drawCheckMarkPrefix (FMenuItem* menuitem) { bool is_checked = menuitem->isChecked(); bool is_checkable = menuitem->checkable; @@ -1490,7 +1491,7 @@ void FMenu::drawCheckMarkPrefix (FMenuItem* menuitem) } //---------------------------------------------------------------------- -void FMenu::drawMenuText (menuText& data) +inline void FMenu::drawMenuText (menuText& data) { // Print menu text @@ -1527,7 +1528,7 @@ void FMenu::drawMenuText (menuText& data) } //---------------------------------------------------------------------- -void FMenu::drawSubMenuIndicator (int& startpos) +inline void FMenu::drawSubMenuIndicator (int& startpos) { int c = ( has_checkable_items ) ? 1 : 0; int len = int(max_item_width) - (startpos + c + 3); @@ -1543,7 +1544,7 @@ void FMenu::drawSubMenuIndicator (int& startpos) } //---------------------------------------------------------------------- -void FMenu::drawAcceleratorKey (int& startpos, int accel_key) +inline void FMenu::drawAcceleratorKey (int& startpos, int accel_key) { FString accel_name (getKeyName(accel_key)); int c = ( has_checkable_items ) ? 1 : 0; @@ -1560,7 +1561,7 @@ void FMenu::drawAcceleratorKey (int& startpos, int accel_key) } //---------------------------------------------------------------------- -void FMenu::drawTrailingSpaces (int startpos) +inline void FMenu::drawTrailingSpaces (int startpos) { int c = ( has_checkable_items ) ? 1 : 0; // Print trailing blank space @@ -1569,7 +1570,7 @@ void FMenu::drawTrailingSpaces (int startpos) } //---------------------------------------------------------------------- -void FMenu::setLineAttributes (FMenuItem* menuitem, int y) +inline void FMenu::setLineAttributes (FMenuItem* menuitem, int y) { bool is_enabled = menuitem->isEnabled(); bool is_selected = menuitem->isSelected(); @@ -1607,7 +1608,7 @@ void FMenu::setLineAttributes (FMenuItem* menuitem, int y) } //---------------------------------------------------------------------- -void FMenu::setCursorToHotkeyPosition (FMenuItem* menuitem, int hotkeypos) +inline void FMenu::setCursorToHotkeyPosition (FMenuItem* menuitem) { bool is_checkable = menuitem->checkable; bool is_selected = menuitem->isSelected(); diff --git a/src/fmenubar.cpp b/src/fmenubar.cpp index 97a9fe47..d01ccd36 100644 --- a/src/fmenubar.cpp +++ b/src/fmenubar.cpp @@ -805,7 +805,7 @@ void FMenuBar::drawItems() } //---------------------------------------------------------------------- -void FMenuBar::drawItem (FMenuItem* menuitem, int& x) +inline void FMenuBar::drawItem (FMenuItem* menuitem, int& x) { FString txt = menuitem->getText(); menuText txtdata; @@ -866,7 +866,7 @@ void FMenuBar::drawItem (FMenuItem* menuitem, int& x) } //---------------------------------------------------------------------- -void FMenuBar::setLineAttributes (FMenuItem* menuitem) +inline void FMenuBar::setLineAttributes (FMenuItem* menuitem) { bool is_enabled = menuitem->isEnabled(); bool is_selected = menuitem->isSelected(); @@ -897,7 +897,7 @@ void FMenuBar::setLineAttributes (FMenuItem* menuitem) } //---------------------------------------------------------------------- -void FMenuBar::drawMenuText (menuText& data) +inline void FMenuBar::drawMenuText (menuText& data) { // Print menu text diff --git a/src/fstring.cpp b/src/fstring.cpp index e62da4c3..a9e29cc6 100644 --- a/src/fstring.cpp +++ b/src/fstring.cpp @@ -155,7 +155,7 @@ FString::FString (const std::wstring& s) } //---------------------------------------------------------------------- -FString::FString (const wchar_t* s) +FString::FString (const wchar_t s[]) : string(0) , length(0) , bufsize(0) @@ -186,7 +186,7 @@ FString::FString (const std::string& s) } //---------------------------------------------------------------------- -FString::FString (const char* s) +FString::FString (const char s[]) : string(0) , length(0) , bufsize(0) @@ -272,7 +272,7 @@ FString& FString::operator = (const std::wstring& s) } //---------------------------------------------------------------------- -const FString& FString::operator = (const wchar_t* s) +const FString& FString::operator = (const wchar_t s[]) { if ( s ) _assign (s); @@ -299,7 +299,7 @@ FString& FString::operator = (const std::string& s) } //---------------------------------------------------------------------- -const FString& FString::operator = (const char* s) +const FString& FString::operator = (const char s[]) { const wchar_t* wc_string = c_to_wc_str(s); @@ -349,7 +349,7 @@ const FString& FString::operator += (const std::wstring& s) } //---------------------------------------------------------------------- -const FString& FString::operator += (const wchar_t* s) +const FString& FString::operator += (const wchar_t s[]) { _insert (length, uInt(std::wcslen(s)), s); return *this; @@ -370,7 +370,7 @@ const FString& FString::operator += (const std::string& s) } //---------------------------------------------------------------------- -const FString& FString::operator += (const char* s) +const FString& FString::operator += (const char s[]) { const wchar_t* wc_string = c_to_wc_str(s); @@ -420,7 +420,7 @@ const FString FString::operator + (const std::wstring& s) } //---------------------------------------------------------------------- -const FString FString::operator + (const wchar_t* s) +const FString FString::operator + (const wchar_t s[]) { FString tmp(string); tmp._insert (length, uInt(std::wcslen(s)), s); @@ -442,7 +442,7 @@ const FString FString::operator + (const std::string& s) } //---------------------------------------------------------------------- -const FString FString::operator + (const char* s) +const FString FString::operator + (const char s[]) { FString tmp(string); wchar_t* wc_string = c_to_wc_str(s); @@ -700,7 +700,7 @@ uInt FString::getUTF8length() const } //---------------------------------------------------------------------- -FString& FString::sprintf (const wchar_t* format, ...) +FString& FString::sprintf (const wchar_t format[], ...) { static const int BUFSIZE = 4096; wchar_t buffer[BUFSIZE]; @@ -715,7 +715,7 @@ FString& FString::sprintf (const wchar_t* format, ...) } //---------------------------------------------------------------------- -FString& FString::sprintf (const char* format, ...) +FString& FString::sprintf (const char format[], ...) { const wchar_t* wc_string; char buf[1024]; @@ -1220,14 +1220,14 @@ FStringList FString::split (const FString& delimiter) } //---------------------------------------------------------------------- -FString& FString::setString (const wchar_t* s) +FString& FString::setString (const wchar_t s[]) { _assign (s); return *this; } //---------------------------------------------------------------------- -FString& FString::setString (const char* s) +FString& FString::setString (const char s[]) { const wchar_t* wc_string = c_to_wc_str(s); @@ -1426,7 +1426,7 @@ bool FString::operator < (const std::wstring& s) const } //---------------------------------------------------------------------- -bool FString::operator < (const wchar_t* s) const +bool FString::operator < (const wchar_t s[]) const { const FString tmp(s); return *this < tmp; @@ -1440,7 +1440,7 @@ bool FString::operator < (const std::string& s) const } //---------------------------------------------------------------------- -bool FString::operator < (const char* s) const +bool FString::operator < (const char s[]) const { const FString tmp(s); return *this < tmp; @@ -1486,7 +1486,7 @@ bool FString::operator <= (const std::wstring& s) const } //---------------------------------------------------------------------- -bool FString::operator <= (const wchar_t* s) const +bool FString::operator <= (const wchar_t s[]) const { const FString tmp(s); return *this <= tmp; @@ -1500,7 +1500,7 @@ bool FString::operator <= (const std::string& s) const } //---------------------------------------------------------------------- -bool FString::operator <= (const char* s) const +bool FString::operator <= (const char s[]) const { const FString tmp(s); return *this <= tmp; @@ -1543,7 +1543,7 @@ bool FString::operator == (const std::wstring& s) const } //---------------------------------------------------------------------- -bool FString::operator == (const wchar_t* s) const +bool FString::operator == (const wchar_t s[]) const { const FString tmp(s); return *this == tmp; @@ -1557,7 +1557,7 @@ bool FString::operator == (const std::string& s) const } //---------------------------------------------------------------------- -bool FString::operator == (const char* s) const +bool FString::operator == (const char s[]) const { const FString tmp(s); return *this == tmp; @@ -1600,7 +1600,7 @@ bool FString::operator != (const std::wstring& s) const } //---------------------------------------------------------------------- -bool FString::operator != (const wchar_t* s) const +bool FString::operator != (const wchar_t s[]) const { const FString tmp(s); return *this != tmp; @@ -1614,7 +1614,7 @@ bool FString::operator != (const std::string& s) const } //---------------------------------------------------------------------- -bool FString::operator != (const char* s) const +bool FString::operator != (const char s[]) const { const FString tmp(s); return *this != tmp; @@ -1660,7 +1660,7 @@ bool FString::operator >= (const std::wstring& s) const } //---------------------------------------------------------------------- -bool FString::operator >= (const wchar_t* s) const +bool FString::operator >= (const wchar_t s[]) const { const FString tmp(s); return *this >= tmp; @@ -1674,7 +1674,7 @@ bool FString::operator >= (const std::string& s) const } //---------------------------------------------------------------------- -bool FString::operator >= (const char* s) const +bool FString::operator >= (const char s[]) const { const FString tmp(s); return *this >= tmp; @@ -1720,7 +1720,7 @@ bool FString::operator > (const std::wstring& s) const } //---------------------------------------------------------------------- -bool FString::operator > (const wchar_t* s) const +bool FString::operator > (const wchar_t s[]) const { const FString tmp(s); return *this > tmp; @@ -1734,7 +1734,7 @@ bool FString::operator > (const std::string& s) const } //---------------------------------------------------------------------- -bool FString::operator > (const char* s) const +bool FString::operator > (const char s[]) const { const FString tmp(s); return *this > tmp; @@ -1765,7 +1765,7 @@ const FString& FString::insert (const FString& s, uInt pos) } //---------------------------------------------------------------------- -const FString& FString::insert (const wchar_t* s, uInt pos) +const FString& FString::insert (const wchar_t s[], uInt pos) { if ( pos >= length ) throw std::out_of_range(""); @@ -1775,7 +1775,7 @@ const FString& FString::insert (const wchar_t* s, uInt pos) } //---------------------------------------------------------------------- -const FString& FString::insert (const char* s, uInt pos) +const FString& FString::insert (const char s[], uInt pos) { return insert(FString(s), pos); } @@ -1838,7 +1838,7 @@ FString FString::replace (const FString& from, const std::wstring& to) } //---------------------------------------------------------------------- -FString FString::replace (const FString& from, const wchar_t* to) +FString FString::replace (const FString& from, const wchar_t to[]) { FString to_str(to); return replace (from, to_str); @@ -1852,7 +1852,7 @@ FString FString::replace (const FString& from, const std::string& to) } //---------------------------------------------------------------------- -FString FString::replace (const FString& from, const char* to) +FString FString::replace (const FString& from, const char to[]) { FString to_str(to); return replace (from, to_str); @@ -1888,7 +1888,7 @@ FString FString::replace (const std::wstring& from, const std::wstring& to) } //---------------------------------------------------------------------- -FString FString::replace (const std::wstring& from, const wchar_t* to) +FString FString::replace (const std::wstring& from, const wchar_t to[]) { FString from_str(from); FString to_str(to); @@ -1904,7 +1904,7 @@ FString FString::replace (const std::wstring& from, const std::string& to) } //---------------------------------------------------------------------- -FString FString::replace (const std::wstring& from, const char* to) +FString FString::replace (const std::wstring& from, const char to[]) { FString from_str(from); FString to_str(to); @@ -1944,7 +1944,7 @@ FString FString::replace (const std::string& from, const std::wstring& to) } //---------------------------------------------------------------------- -FString FString::replace (const std::string& from, const wchar_t* to) +FString FString::replace (const std::string& from, const wchar_t to[]) { FString from_str(from); FString to_str(to); @@ -1960,7 +1960,7 @@ FString FString::replace (const std::string& from, const std::string& to) } //---------------------------------------------------------------------- -FString FString::replace (const std::string& from, const char* to) +FString FString::replace (const std::string& from, const char to[]) { FString from_str(from); FString to_str(to); @@ -1984,14 +1984,14 @@ FString FString::replace (const std::string& from, const char to) } //---------------------------------------------------------------------- -FString FString::replace (const wchar_t* from, const FString& to) +FString FString::replace (const wchar_t from[], const FString& to) { FString from_str(from); return replace (from_str, to); } //---------------------------------------------------------------------- -FString FString::replace (const wchar_t* from, const std::wstring& to) +FString FString::replace (const wchar_t from[], const std::wstring& to) { FString from_str(from); FString to_str(to); @@ -1999,7 +1999,7 @@ FString FString::replace (const wchar_t* from, const std::wstring& to) } //---------------------------------------------------------------------- -FString FString::replace (const wchar_t* from, const wchar_t* to) +FString FString::replace (const wchar_t from[], const wchar_t to[]) { FString from_str(from); FString to_str(to); @@ -2007,7 +2007,23 @@ FString FString::replace (const wchar_t* from, const wchar_t* to) } //---------------------------------------------------------------------- -FString FString::replace (const wchar_t* from, const wchar_t to) +FString FString::replace (const wchar_t from[], const std::string& to) +{ + FString from_str(from); + FString to_str(to); + return replace (from_str, to_str); +} + +//---------------------------------------------------------------------- +FString FString::replace (const wchar_t from[], const char to[]) +{ + FString from_str(from); + FString to_str(to); + return replace (from_str, to_str); +} + +//---------------------------------------------------------------------- +FString FString::replace (const wchar_t from[], const wchar_t to) { FString from_str(from); FString to_wchar(to); @@ -2015,7 +2031,7 @@ FString FString::replace (const wchar_t* from, const wchar_t to) } //---------------------------------------------------------------------- -FString FString::replace (const wchar_t* from, const char to) +FString FString::replace (const wchar_t from[], const char to) { FString from_str(from); FString to_char(to); @@ -2023,7 +2039,7 @@ FString FString::replace (const wchar_t* from, const char to) } //---------------------------------------------------------------------- -FString FString::replace (const char* from, const FString& to) +FString FString::replace (const char from[], const FString& to) { FString from_str(from); FString to_str(to); @@ -2031,7 +2047,7 @@ FString FString::replace (const char* from, const FString& to) } //---------------------------------------------------------------------- -FString FString::replace (const char* from, const std::wstring& to) +FString FString::replace (const char from[], const std::wstring& to) { FString from_str(from); FString to_str(to); @@ -2039,7 +2055,7 @@ FString FString::replace (const char* from, const std::wstring& to) } //---------------------------------------------------------------------- -FString FString::replace (const char* from, const wchar_t* to) +FString FString::replace (const char from[], const wchar_t to[]) { FString from_str(from); FString to_str(to); @@ -2047,7 +2063,7 @@ FString FString::replace (const char* from, const wchar_t* to) } //---------------------------------------------------------------------- -FString FString::replace (const char* from, const std::string& to) +FString FString::replace (const char from[], const std::string& to) { FString from_str(from); FString to_str(to); @@ -2055,7 +2071,7 @@ FString FString::replace (const char* from, const std::string& to) } //---------------------------------------------------------------------- -FString FString::replace (const char* from, const char* to) +FString FString::replace (const char from[], const char to[]) { FString from_str(from); FString to_str(to); @@ -2063,7 +2079,7 @@ FString FString::replace (const char* from, const char* to) } //---------------------------------------------------------------------- -FString FString::replace (const char* from, const wchar_t to) +FString FString::replace (const char from[], const wchar_t to) { FString from_str(from); FString to_wchar(to); @@ -2071,7 +2087,7 @@ FString FString::replace (const char* from, const wchar_t to) } //---------------------------------------------------------------------- -FString FString::replace (const char* from, const char to) +FString FString::replace (const char from[], const char to) { FString from_str(from); FString to_char(to); @@ -2122,7 +2138,7 @@ FString FString::replace (const wchar_t from, const std::wstring& to) } //---------------------------------------------------------------------- -FString FString::replace (const wchar_t from, const wchar_t* to) +FString FString::replace (const wchar_t from, const wchar_t to[]) { FString to_str(to); return replace (from, to_str); @@ -2136,7 +2152,7 @@ FString FString::replace (const wchar_t from, const std::string& to) } //---------------------------------------------------------------------- -FString FString::replace (const wchar_t from, const char* to) +FString FString::replace (const wchar_t from, const char to[]) { FString to_str(to); return replace (from, to_str); @@ -2165,7 +2181,7 @@ FString FString::replace (const char from, const std::wstring& to) } //---------------------------------------------------------------------- -FString FString::replace (const char from, const wchar_t* to) +FString FString::replace (const char from, const wchar_t to[]) { FString from_str(from); FString to_str(to); @@ -2181,7 +2197,7 @@ FString FString::replace (const char from, const std::string& to) } //---------------------------------------------------------------------- -FString FString::replace (const char from, const char* to) +FString FString::replace (const char from, const char to[]) { FString from_str(from); FString to_str(to); @@ -2368,7 +2384,7 @@ const FString& FString::overwrite (const FString& s, uInt pos) } //---------------------------------------------------------------------- -const FString& FString::overwrite (const wchar_t* s, uInt pos) +const FString& FString::overwrite (const wchar_t s[], uInt pos) { uInt len = uInt(std::wcslen(s)); @@ -2412,13 +2428,13 @@ bool FString::includes (const FString& s) } //---------------------------------------------------------------------- -bool FString::includes (const wchar_t* s) +bool FString::includes (const wchar_t s[]) { return ( std::wcsstr(string, s) != 0 ); } //---------------------------------------------------------------------- -bool FString::includes (const char* s) +bool FString::includes (const char s[]) { bool ret; const wchar_t* wc_string = c_to_wc_str(s); @@ -2472,7 +2488,7 @@ inline void FString::initLength (uInt len) } //---------------------------------------------------------------------- -inline void FString::_assign (const wchar_t* s) +inline void FString::_assign (const wchar_t s[]) { if ( s == string ) return; @@ -2502,7 +2518,7 @@ inline void FString::_assign (const wchar_t* s) } //---------------------------------------------------------------------- -inline void FString::_insert (uInt pos, uInt len, const wchar_t* s) +inline void FString::_insert (uInt pos, uInt len, const wchar_t s[]) { if ( len == 0 ) // String s is a null or a empty string return; @@ -2617,7 +2633,7 @@ inline void FString::_remove (uInt pos, uInt len) } //---------------------------------------------------------------------- -inline char* FString::wc_to_c_str (const wchar_t* s) const +inline char* FString::wc_to_c_str (const wchar_t s[]) const { int mblength , size @@ -2678,7 +2694,7 @@ inline char* FString::wc_to_c_str (const wchar_t* s) const } //---------------------------------------------------------------------- -inline wchar_t* FString::c_to_wc_str (const char* s) const +inline wchar_t* FString::c_to_wc_str (const char s[]) const { int wclength , size @@ -2747,9 +2763,9 @@ inline wchar_t* FString::c_to_wc_str (const char* s) const } //---------------------------------------------------------------------- -inline wchar_t* FString::extractToken ( wchar_t** rest - , const wchar_t* s - , const wchar_t* delim ) +inline wchar_t* FString::extractToken ( wchar_t* rest[] + , const wchar_t s[] + , const wchar_t delim[] ) { register wchar_t* token; token = ( s ) ? const_cast(s) : *rest; @@ -2797,7 +2813,7 @@ const FString operator + (const std::wstring& s1, const FString& s2) } //---------------------------------------------------------------------- -const FString operator + (const wchar_t* s1, const FString& s2) +const FString operator + (const wchar_t s1[], const FString& s2) { FString tmp(s1); tmp._insert ( uInt(std::wcslen(s1)) @@ -2817,7 +2833,7 @@ const FString operator + (const std::string& s1, const FString& s2) } //---------------------------------------------------------------------- -const FString operator + (const char* s1, const FString& s2) +const FString operator + (const char s1[], const FString& s2) { FString tmp(s1); tmp._insert ( tmp.getLength() diff --git a/src/fterm.cpp b/src/fterm.cpp index 8b2ec4cc..b601241a 100644 --- a/src/fterm.cpp +++ b/src/fterm.cpp @@ -1618,7 +1618,7 @@ const FString FTerm::getSecDA() } //---------------------------------------------------------------------- -void FTerm::putstringf (const char* const format, ...) +void FTerm::putstringf (const char format[], ...) { assert ( format != 0 ); char buf[512]; @@ -1634,7 +1634,7 @@ void FTerm::putstringf (const char* const format, ...) } //---------------------------------------------------------------------- -inline void FTerm::putstring (const char* const s, int affcnt) +inline void FTerm::putstring (const char s[], int affcnt) { #if defined(__sun) && defined(__SVR4) tputs (C_STR(s), affcnt, FTerm::putchar_ASCII); @@ -2137,19 +2137,29 @@ int FTerm::getFramebuffer_bpp () //---------------------------------------------------------------------- int FTerm::openConsole() -{ +{ + static const char* terminal_devices[] = + { + "/proc/self/fd/0", + "/dev/tty", + "/dev/tty0", + "/dev/vc/0", + "/dev/systty", + "/dev/console", + 0 + }; + if ( fd_tty >= 0 ) // console is already opened return 0; - if ( *term_name && (fd_tty = open (term_name, O_RDWR, 0)) < 0 ) - if ( (fd_tty = open("/proc/self/fd/0", O_RDWR, 0)) < 0 ) - if ( (fd_tty = open("/dev/tty", O_RDWR, 0)) < 0 ) - if ( (fd_tty = open("/dev/tty0", O_RDWR, 0)) < 0 ) - if ( (fd_tty = open("/dev/vc/0", O_RDWR, 0)) < 0 ) - if ( (fd_tty = open("/dev/systty", O_RDWR, 0)) < 0 ) - if ( (fd_tty = open("/dev/console", O_RDWR, 0)) < 0 ) - return -1; // No file descriptor referring to the console - return 0; + if ( ! *term_name ) + return 0; + + for (int i = 0; terminal_devices[i] != 0; i++) + if ( (fd_tty = open(terminal_devices[i], O_RDWR, 0)) >= 0 ) + return 0; + + return -1; // No file descriptor referring to the console } //---------------------------------------------------------------------- @@ -2324,7 +2334,7 @@ int FTerm::getScreenFont() } //---------------------------------------------------------------------- -int FTerm::setScreenFont ( uChar* fontdata, uInt count +int FTerm::setScreenFont ( uChar fontdata[], uInt count , uInt fontwidth, uInt fontheight , bool direct) { diff --git a/src/ftermbuffer.cpp b/src/ftermbuffer.cpp index f2cdfc01..f361ca6d 100644 --- a/src/ftermbuffer.cpp +++ b/src/ftermbuffer.cpp @@ -43,7 +43,7 @@ FTermBuffer::~FTermBuffer() // destructor // public methods of FTermBuffer //---------------------------------------------------------------------- -int FTermBuffer::writef (const wchar_t* format, ...) +int FTermBuffer::writef (const wchar_t format[], ...) { assert ( format != 0 ); static const int BufSize = 1024; @@ -59,7 +59,7 @@ int FTermBuffer::writef (const wchar_t* format, ...) } //---------------------------------------------------------------------- -int FTermBuffer::writef (const char* format, ...) +int FTermBuffer::writef (const char format[], ...) { assert ( format != 0 ); int len; @@ -106,14 +106,14 @@ int FTermBuffer::write (const std::wstring& s) } //---------------------------------------------------------------------- -int FTermBuffer::write (const wchar_t* s) +int FTermBuffer::write (const wchar_t s[]) { assert ( s != 0 ); return write (FString(s)); } //---------------------------------------------------------------------- -int FTermBuffer::write (const char* s) +int FTermBuffer::write (const char s[]) { assert ( s != 0 ); FString str(s); diff --git a/src/fvterm.cpp b/src/fvterm.cpp index 589710e3..6eed3b8f 100644 --- a/src/fvterm.cpp +++ b/src/fvterm.cpp @@ -306,7 +306,7 @@ void FVTerm::delPreprocessingHandler (FVTerm* instance) } //---------------------------------------------------------------------- -int FVTerm::printf (const wchar_t* format, ...) +int FVTerm::printf (const wchar_t format[], ...) { assert ( format != 0 ); static const int BufSize = 1024; @@ -322,7 +322,7 @@ int FVTerm::printf (const wchar_t* format, ...) } //---------------------------------------------------------------------- -int FVTerm::printf (const char* format, ...) +int FVTerm::printf (const char format[], ...) { assert ( format != 0 ); int len; @@ -377,14 +377,14 @@ int FVTerm::print (term_area* area, const std::wstring& s) } //---------------------------------------------------------------------- -int FVTerm::print (const wchar_t* s) +int FVTerm::print (const wchar_t s[]) { assert ( s != 0 ); return print (FString(s)); } //---------------------------------------------------------------------- -int FVTerm::print (term_area* area, const wchar_t* s) +int FVTerm::print (term_area* area, const wchar_t s[]) { assert ( area != 0 ); assert ( s != 0 ); @@ -392,7 +392,7 @@ int FVTerm::print (term_area* area, const wchar_t* s) } //---------------------------------------------------------------------- -int FVTerm::print (const char* s) +int FVTerm::print (const char s[]) { assert ( s != 0 ); FString str(s); @@ -400,7 +400,7 @@ int FVTerm::print (const char* s) } //---------------------------------------------------------------------- -int FVTerm::print (term_area* area, const char* s) +int FVTerm::print (term_area* area, const char s[]) { assert ( area != 0 ); assert ( s != 0 );