From 9df9eb5961775aa5a9aaa0123ed948fcdb7fda4b Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Mon, 16 May 2016 21:11:32 +0200 Subject: [PATCH] Improve adjustSize() --- src/fmenu.cpp | 12 +++-- src/fmenubar.cpp | 7 +-- src/fstatusbar.cpp | 29 ++++++----- src/fstatusbar.h | 2 +- src/fterm.cpp | 11 +++- src/fwidget.cpp | 123 ++++++++++++++++++++++++++++++++++++--------- src/fwidget.h | 1 + test/ui.cpp | 3 +- 8 files changed, 139 insertions(+), 49 deletions(-) diff --git a/src/fmenu.cpp b/src/fmenu.cpp index 38887412..e03b1047 100644 --- a/src/fmenu.cpp +++ b/src/fmenu.cpp @@ -89,12 +89,13 @@ FMenu::~FMenu() //---------------------------------------------------------------------- void FMenu::init(FWidget* parent) { + FWidget* rootObj = getRootWidget(); + xmin = 1 + rootObj->getLeftPadding(); + ymin = 1 + rootObj->getTopPadding(); + xmax = rootObj->getWidth(); + ymax = rootObj->getHeight(); width = 10; height = 2; - xmin = 1; - ymin = 1; - xmax = width; - ymax = height; client_xmin = 1; client_ymin = 1; client_xmax = width; @@ -113,7 +114,8 @@ void FMenu::init(FWidget* parent) foregroundColor = wc.menu_active_fg; backgroundColor = wc.menu_active_bg; - item->setMenu(this); + if ( item ) + item->setMenu(this); if ( parent ) { diff --git a/src/fmenubar.cpp b/src/fmenubar.cpp index b3c69c9f..5eca0a53 100644 --- a/src/fmenubar.cpp +++ b/src/fmenubar.cpp @@ -43,16 +43,17 @@ void FMenuBar::init() ypos = 1; createArea (vmenubar); vmenubar->visible = true; + window_object = true; + ignore_padding = true; + // initialize geometry values setGeometry (1, 1, getColumnNumber(), 1, false); - getRootWidget()->setTopPadding(1, true); setMenuBar(this); + getRootWidget()->setTopPadding(1, true); addAccelerator (fc::Fkey_f10); addAccelerator (fc::Fckey_space); foregroundColor = wc.menu_active_fg; backgroundColor = wc.menu_active_bg; - window_object = true; - ignore_padding = true; unsetFocusable(); } diff --git a/src/fstatusbar.cpp b/src/fstatusbar.cpp index 63688b44..c4286bbd 100644 --- a/src/fstatusbar.cpp +++ b/src/fstatusbar.cpp @@ -185,16 +185,16 @@ void FStatusBar::init() ypos = getLineNumber(); createArea (vstatusbar); vstatusbar->visible = true; + window_object = true; + ignore_padding = true; + mouse_down = false; // initialize geometry values setGeometry (1, ypos, getColumnNumber(), 1, false); - getRootWidget()->setBottomPadding(1, true); setStatusBar(this); + getRootWidget()->setBottomPadding(1, true); foregroundColor = wc.statusbar_fg; backgroundColor = wc.statusbar_bg; - window_object = true; - mouse_down = false; - ignore_padding = true; unsetFocusable(); } @@ -338,17 +338,6 @@ void FStatusBar::drawKeys() x_msg = x; } -//---------------------------------------------------------------------- -void FStatusBar::adjustSize() -{ - xmin = ymin = 1; - height = 1; - xpos = 1; - width = getColumnNumber(); - ypos = getLineNumber(); - FWidget::adjustSize(); -} - // public methods of FStatusBar //---------------------------------------------------------------------- @@ -709,6 +698,16 @@ void FStatusBar::clear() keylist.clear(); } +//---------------------------------------------------------------------- +void FStatusBar::adjustSize() +{ + xmin = ymin = 1; + height = 1; + xpos = 1; + width = getColumnNumber(); + ypos = getLineNumber(); +} + //---------------------------------------------------------------------- void FStatusBar::cb_statuskey_activated (FWidget* widget, void*) { diff --git a/src/fstatusbar.h b/src/fstatusbar.h index 6387f444..6fdf6c9f 100644 --- a/src/fstatusbar.h +++ b/src/fstatusbar.h @@ -158,7 +158,6 @@ class FStatusBar : public FWindow void init(); void draw(); void drawKeys(); - void adjustSize(); public: explicit FStatusBar (FWidget* = 0); // constructor @@ -192,6 +191,7 @@ class FStatusBar : public FWindow void remove (int); void clear(); + void adjustSize(); void cb_statuskey_activated (FWidget*, void*); }; #pragma pack(pop) diff --git a/src/fterm.cpp b/src/fterm.cpp index fd46bf83..24533bec 100644 --- a/src/fterm.cpp +++ b/src/fterm.cpp @@ -275,8 +275,17 @@ void FTerm::identifyTermType() } else if ( term_name ) { - FILE *fp; // fallback: look into /etc/ttytype or /etc/ttys + // + // file format: + // + // + // Example: + // linux tty1 + // vt100 ttys0 + + FILE *fp; + if ( (fp = fopen("/etc/ttytype", "r")) != 0 || (fp = fopen("/etc/ttys", "r")) != 0 ) { diff --git a/src/fwidget.cpp b/src/fwidget.cpp index 07f36b93..7dc4b890 100644 --- a/src/fwidget.cpp +++ b/src/fwidget.cpp @@ -484,6 +484,35 @@ void FWidget::adjustSize() } } +//---------------------------------------------------------------------- +void FWidget::adjustSizeGlobal() +{ + if ( ! isRootWidget() ) + { + getRootWidget()->adjustSizeGlobal(); + return; + } + + if ( menubar ) + menubar->adjustSize(); + + if ( statusbar ) + statusbar->adjustSize(); + + if ( window_list && ! window_list->empty() ) + { + widgetList::const_iterator iter, end; + iter = window_list->begin(); + end = window_list->end(); + + while ( iter != end ) + { + (*iter)->adjustSize(); + ++iter; + } + } +} + //---------------------------------------------------------------------- void FWidget::setStatusBar (FStatusBar* sbar) { @@ -1246,6 +1275,7 @@ void FWidget::resize() statusbar->setGeometry(1, height, width, 1, false); if ( vstatusbar ) resizeArea(vstatusbar); + statusbar->adjustSize(); } if ( window_list && ! window_list->empty() ) { @@ -1597,9 +1627,20 @@ void FWidget::setTopPadding (int t, bool adjust) { if ( top_padding == t ) return; - (t > 0) ? top_padding = t : top_padding = 1; + + (t > 0) ? top_padding = t : top_padding = 0; + if ( adjust ) - adjustSize(); + { + if ( isRootWidget() ) + { + FWidget* r_obj = rootObject; + r_obj->client_ymin = 1 + r_obj->top_padding; + adjustSizeGlobal(); + } + else + adjustSize(); + } } //---------------------------------------------------------------------- @@ -1607,9 +1648,20 @@ void FWidget::setLeftPadding (int l, bool adjust) { if ( left_padding == l ) return; - (l > 0) ? left_padding = l : left_padding = 1; + + (l > 0) ? left_padding = l : left_padding = 0; + if ( adjust ) - adjustSize(); + { + if ( isRootWidget() ) + { + FWidget* r_obj = rootObject; + r_obj->client_xmin = 1 + r_obj->left_padding; + adjustSizeGlobal(); + } + else + adjustSize(); + } } //---------------------------------------------------------------------- @@ -1617,9 +1669,20 @@ void FWidget::setBottomPadding (int b, bool adjust) { if ( bottom_padding == b ) return; - (b > 0) ? bottom_padding = b : bottom_padding = 1; + + (b > 0) ? bottom_padding = b : bottom_padding = 0; + if ( adjust ) - adjustSize(); + { + if ( isRootWidget() ) + { + FWidget* r_obj = rootObject; + r_obj->client_ymax = r_obj->height - r_obj->bottom_padding; + adjustSizeGlobal(); + } + else + adjustSize(); + } } //---------------------------------------------------------------------- @@ -1627,30 +1690,43 @@ void FWidget::setRightPadding (int r, bool adjust) { if ( right_padding == r ) return; - (r > 0) ? right_padding = r : right_padding = 1; + + (r > 0) ? right_padding = r : right_padding = 0; + if ( adjust ) - adjustSize(); + { + if ( isRootWidget() ) + { + FWidget* r_obj = rootObject; + r_obj->client_xmax = r_obj->width - r_obj->right_padding; + adjustSizeGlobal(); + } + else + adjustSize(); + } } //---------------------------------------------------------------------- void FWidget::getTermGeometry() { + FWidget* r_obj = rootObject; + if ( openConsole() == 0 ) { getTermSize(); closeConsole(); } - - rootObject->width = term->getWidth(); - rootObject->height = term->getHeight(); - rootObject->xmin = 1; - rootObject->ymin = 1; - rootObject->xmax = rootObject->width; - rootObject->ymax = rootObject->height; - rootObject->client_xmin = 1 + rootObject->left_padding; - rootObject->client_ymin = 1 + rootObject->top_padding; - rootObject->client_xmax = rootObject->width; - rootObject->client_ymax = rootObject->height; + + r_obj->width = term->getWidth(); + r_obj->height = term->getHeight(); + r_obj->xmin = 1; + r_obj->ymin = 1; + r_obj->xmax = r_obj->width; + r_obj->ymax = r_obj->height; + r_obj->client_xmin = 1 + r_obj->left_padding; + r_obj->client_ymin = 1 + r_obj->top_padding; + r_obj->client_xmax = r_obj->width - r_obj->right_padding; + r_obj->client_ymax = r_obj->height - r_obj->bottom_padding; } //---------------------------------------------------------------------- @@ -1659,10 +1735,11 @@ void FWidget::setTermGeometry (int w, int h) // Set xterm size to w x h if ( xterm ) { - rootObject->xpos = 1; - rootObject->ypos = 1; - rootObject->width = w; // columns - rootObject->height = h; // lines + FWidget* r_obj = rootObject; + r_obj->xpos = 1; + r_obj->ypos = 1; + r_obj->width = w; // columns + r_obj->height = h; // lines setTermSize (w, h); getTermGeometry(); diff --git a/src/fwidget.h b/src/fwidget.h index 0c9c5f94..76854a29 100644 --- a/src/fwidget.h +++ b/src/fwidget.h @@ -286,6 +286,7 @@ class FWidget : public FObject, public FTerm protected: virtual void adjustSize(); + void adjustSizeGlobal(); virtual void setStatusBar (FStatusBar*); virtual void setMenuBar (FMenuBar*); // Event handlers diff --git a/test/ui.cpp b/test/ui.cpp index 6d059f9a..47c77a38 100644 --- a/test/ui.cpp +++ b/test/ui.cpp @@ -790,7 +790,8 @@ void MyDialog::adjustSize() if ( X < 1 ) X = 1; setX (X, false); - myList->setHeight (getHeight() - 3, false); + if ( myList ) + myList->setHeight (getHeight() - 3, false); FDialog::adjustSize(); }