diff --git a/ChangeLog b/ChangeLog index 1bfce560..d9f15256 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2016-09-25 Markus Gans + * Splitting gotoxy in printPos (local position) + and printPosTerm (global terminal position) + * Replacing the widget position variables by FRect objects + * Rename getGeometryShadow() to getGeometryWithShadow() + * Rename getGeometryGlobal() to getTermGeometry() + * Rename getGeometryGlobalShadow() to getTermGeometryWithShadow() + * Rename globalToLocalPos() to termToWidgetPos() + * Rename getGlobalX() to getTermX() + * Rename getGlobalY() to getTermY() + * Rename getGlobalPos() to getTermPos() + * setColor() without parameters sets the default widget colors + * New methods setMinimumSize(), setMaximumSize(), setFixedSize() + and setSize() + +2016-09-12 Markus Gans + * Activate the title bar menu with ctrl+^ + 2016-09-11 Markus Gans * New zoom interaction-elements to maximize a FDialog @@ -346,7 +364,7 @@ 2015-08-08 Markus Gans * Bug fix in FDialog (use GlobalPos to move) - * Don't check mouse click position on titlebar again + * Don't check mouse click position on title bar again while FDialog is in move 2015-07-26 Markus Gans diff --git a/src/fapp.cpp b/src/fapp.cpp index 33db1f1d..447d8123 100644 --- a/src/fapp.cpp +++ b/src/fapp.cpp @@ -1444,7 +1444,7 @@ void FApplication::processMouseEvent() && menuBar()->hasSelectedItem() && ! b_state.mouse_moved ) { - if ( ! menuBar()->getGeometryGlobal().contains(*mouse) ) + if ( ! menuBar()->getTermGeometry().contains(*mouse) ) { if ( statusBar() ) statusBar()->clearMessage(); @@ -1466,7 +1466,7 @@ void FApplication::processMouseEvent() if ( clicked_widget ) { - FPoint localMousePos; + FPoint widgetMousePos; int key_state = 0; if ( b_state.shift_button == Pressed ) @@ -1478,14 +1478,14 @@ void FApplication::processMouseEvent() if ( b_state.control_button == Pressed ) key_state |= fc::ControlButton; - localMousePos = clicked_widget->globalToLocalPos(*mouse); + widgetMousePos = clicked_widget->termToWidgetPos(*mouse); if ( b_state.mouse_moved ) { if ( b_state.left_button == Pressed ) { FMouseEvent m_down_ev ( fc::MouseMove_Event - , localMousePos + , widgetMousePos , *mouse , fc::LeftButton | key_state ); sendEvent (clicked_widget, &m_down_ev); @@ -1494,7 +1494,7 @@ void FApplication::processMouseEvent() if ( b_state.right_button == Pressed ) { FMouseEvent m_down_ev ( fc::MouseMove_Event - , localMousePos + , widgetMousePos , *mouse , fc::RightButton | key_state ); sendEvent (clicked_widget, &m_down_ev); @@ -1503,7 +1503,7 @@ void FApplication::processMouseEvent() if ( b_state.middle_button == Pressed ) { FMouseEvent m_down_ev ( fc::MouseMove_Event - , localMousePos + , widgetMousePos , *mouse , fc::MiddleButton | key_state ); sendEvent (clicked_widget, &m_down_ev); @@ -1514,7 +1514,7 @@ void FApplication::processMouseEvent() if ( b_state.left_button == DoubleClick ) { FMouseEvent m_dblclick_ev ( fc::MouseDoubleClick_Event - , localMousePos + , widgetMousePos , *mouse , fc::LeftButton | key_state ); sendEvent (clicked_widget, &m_dblclick_ev); @@ -1522,7 +1522,7 @@ void FApplication::processMouseEvent() else if ( b_state.left_button == Pressed ) { FMouseEvent m_down_ev ( fc::MouseDown_Event - , localMousePos + , widgetMousePos , *mouse , fc::LeftButton | key_state ); sendEvent (clicked_widget, &m_down_ev); @@ -1530,7 +1530,7 @@ void FApplication::processMouseEvent() else if ( b_state.left_button == Released ) { FMouseEvent m_up_ev ( fc::MouseUp_Event - , localMousePos + , widgetMousePos , *mouse , fc::LeftButton | key_state ); FWidget* released_widget = clicked_widget; @@ -1545,7 +1545,7 @@ void FApplication::processMouseEvent() if ( b_state.right_button == Pressed ) { FMouseEvent m_down_ev ( fc::MouseDown_Event - , localMousePos + , widgetMousePos , *mouse , fc::RightButton | key_state ); sendEvent (clicked_widget, &m_down_ev); @@ -1553,7 +1553,7 @@ void FApplication::processMouseEvent() else if ( b_state.right_button == Released ) { FMouseEvent m_up_ev ( fc::MouseUp_Event - , localMousePos + , widgetMousePos , *mouse , fc::RightButton | key_state ); FWidget* released_widget = clicked_widget; @@ -1568,7 +1568,7 @@ void FApplication::processMouseEvent() if ( b_state.middle_button == Pressed ) { FMouseEvent m_down_ev ( fc::MouseDown_Event - , localMousePos + , widgetMousePos , *mouse , fc::MiddleButton | key_state ); sendEvent (clicked_widget, &m_down_ev); @@ -1580,7 +1580,7 @@ void FApplication::processMouseEvent() else if ( b_state.middle_button == Released ) { FMouseEvent m_up_ev ( fc::MouseUp_Event - , localMousePos + , widgetMousePos , *mouse , fc::MiddleButton | key_state ); FWidget* released_widget = clicked_widget; @@ -1598,7 +1598,7 @@ void FApplication::processMouseEvent() if ( b_state.wheel_up == Pressed ) { FWheelEvent wheel_ev ( fc::MouseWheel_Event - , localMousePos + , widgetMousePos , *mouse , fc::WheelUp ); FWidget* scroll_over_widget = clicked_widget; @@ -1609,7 +1609,7 @@ void FApplication::processMouseEvent() if ( b_state.wheel_down == Pressed ) { FWheelEvent wheel_ev ( fc::MouseWheel_Event - , localMousePos + , widgetMousePos , *mouse , fc::WheelDown ); FWidget* scroll_over_widget = clicked_widget; @@ -1865,7 +1865,7 @@ bool FApplication::sendEvent(FObject* receiver, FEvent* event) if ( modal_dialogs > 0 ) { FWidget* window; - if ( widget->isWindow() ) + if ( widget->isWindowWidget() ) window = widget; else window = FWindow::getWindowWidget(widget); @@ -1873,7 +1873,7 @@ bool FApplication::sendEvent(FObject* receiver, FEvent* event) // block events for widgets in non modal windows if ( window && (window->getFlags() & fc::modal) == 0 - && ! window->isMenu() ) + && ! window->isMenuWidget() ) { switch ( event->type() ) { diff --git a/src/fbutton.cpp b/src/fbutton.cpp index c748305d..047fecee 100644 --- a/src/fbutton.cpp +++ b/src/fbutton.cpp @@ -180,9 +180,9 @@ void FButton::draw() setColor ( parent_widget->getForegroundColor() , parent_widget->getBackgroundColor() ); - for (int y=1; y <= height; y++) + for (int y=1; y <= getHeight(); y++) { - gotoxy (xpos+xmin-1, ypos+ymin-2+y); + printPos (1, y); print (' '); // clear one left █ } @@ -221,7 +221,7 @@ void FButton::draw() if ( hotkeypos != -1 ) hotkey_offset = 1; - if ( (length - hotkey_offset + mono_offset - hotkey_offset) <= width ) + if ( (length - hotkey_offset + mono_offset - hotkey_offset) <= getWidth() ) margin = 1; else margin = 0; @@ -233,11 +233,11 @@ void FButton::draw() { if ( margin == 1 ) { - setColor (foregroundColor, button_bg); + setColor (getForegroundColor(), button_bg); - for (int y=0; y < height; y++) + for (int y=0; y < getHeight(); y++) { - gotoxy (xpos+xmin-1+d, ypos+ymin-1+y); + printPos (1+d, 1+y); print (space); // full block █ } } @@ -250,19 +250,17 @@ void FButton::draw() if ( parent_widget ) setColor (button_bg, parent_widget->getBackgroundColor()); - gotoxy (xpos+xmin-1+d, ypos+ymin-1); - - for (int y=1; y <= height; y++) + for (int y=0; y < getHeight(); y++) { - // Cygwin terminal use IBM Codepage 850 + printPos (1+d, 1+y); + + // Cygwin terminal use IBM Codepage 850 if ( isCygwinTerminal() ) print (fc::FullBlock); // █ else if ( isTeraTerm() ) print (0xdb); else print (fc::RightHalfBlock); // ▐ - - gotoxy (xpos+xmin-1+d, ypos+ymin-1+y); } } @@ -275,12 +273,12 @@ void FButton::draw() setColor ( parent_widget->getForegroundColor() , parent_widget->getBackgroundColor() ); - for (int y=1; y <= height; y++) + for (int y=1; y <= getHeight(); y++) { if ( isMonochron() ) setReverse(true); - gotoxy (xpos+xmin-1+width, ypos+ymin-2+y); + printPos (1+getWidth(), y); print (' '); // clear right if ( isMonochron() ) @@ -291,31 +289,29 @@ void FButton::draw() if ( hotkeypos != -1 ) length--; - i = width - length - 1; + i = getWidth() - length - 1; i = int(i / 2); - if ( height > 1 ) - j = int((height-1) / 2); + if ( getHeight() > 1 ) + j = int((getHeight()-1) / 2); else j=0; - gotoxy (xpos+xmin-1+margin+d, ypos+ymin-1+j); + printPos (1+margin+d, 1+j); setColor (button_fg, button_bg); for (x=0; x < i; x++) - print (space); // █ + print (space); // █ if ( hotkeypos == -1 ) - setCursorPos ( xpos+xmin-1+margin+i - , ypos+ymin-1+j ); // first character + setCursorPos (1+margin+i, 1+j ); // first character else - setCursorPos ( xpos+xmin-1+margin+i+hotkeypos - , ypos+ymin-1+j ); // hotkey + setCursorPos (1+margin+i+hotkeypos, 1+j ); // hotkey if ( is_ActiveFocus && (isMonochron() || getMaxColor() < 16) ) setBold(); - for (int z=0; x < i+length && z < width; z++,x++) + for (int z=0; x < i+length && z < getWidth(); z++,x++) { if ( (z == hotkeypos) && is_Active ) { @@ -346,23 +342,23 @@ void FButton::draw() if ( is_ActiveFocus && (isMonochron() || getMaxColor() < 16) ) unsetBold(); - for (x=i+length; x < width-1; x++) + for (x=i+length; x < getWidth()-1; x++) print (space); // █ - if ( height > 1 ) + if ( getHeight() > 1 ) { for (i=0; i < j; i++) { - gotoxy (xpos+xmin+d, ypos+ymin-1+i); + printPos (2+d, 1+i); - for (int z=1; z < width; z++) + for (int z=1; z < getWidth(); z++) print (space); // █ } - for (i=j+1; i < height; i++) + for (i=j+1; i < getHeight(); i++) { - gotoxy (xpos+xmin+d, ypos+ymin-1+i); + printPos (2+d, 1+i); - for (int z=1; z < width; z++) + for (int z=1; z < getWidth(); z++) print (space); // █ } } @@ -411,8 +407,8 @@ void FButton::updateButtonColor() } else { - button_fg = foregroundColor; - button_bg = backgroundColor; + button_fg = getForegroundColor(); + button_bg = getBackgroundColor() ; } } else // inactive @@ -514,14 +510,18 @@ void FButton::hide() setColor (fg, bg); s = hasShadow() ? 1 : 0; f = isFlat() ? 1 : 0; - size = width + s + (f << 1); + size = getWidth() + s + (f << 1); + + if ( size < 0 ) + return; + blank = new char[size+1]; memset(blank, ' ', uLong(size)); blank[size] = '\0'; - for (int y=0; y < height+s+(f << 1); y++) + for (int y=0; y < getHeight()+s+(f << 1); y++) { - gotoxy (xpos+xmin-1-f, ypos+ymin-1+y-f); + printPos (1-f, 1+y-f); print (blank); } @@ -679,9 +679,9 @@ void FButton::onMouseDown (FMouseEvent* ev) statusBar()->drawMessage(); } - FPoint gPos = ev->getGlobalPos(); + FPoint tPos = ev->getTermPos(); - if ( getGeometryGlobal().contains(gPos) ) + if ( getTermGeometry().contains(tPos) ) setDown(); } @@ -695,7 +695,7 @@ void FButton::onMouseUp (FMouseEvent* ev) { setUp(); - if ( getGeometryGlobal().contains(ev->getGlobalPos()) ) + if ( getTermGeometry().contains(ev->getTermPos()) ) processClick(); } } @@ -706,11 +706,11 @@ void FButton::onMouseMove (FMouseEvent* ev) if ( ev->getButton() != fc::LeftButton ) return; - FPoint gPos = ev->getGlobalPos(); + FPoint tPos = ev->getTermPos(); if ( click_animation ) { - if ( getGeometryGlobal().contains(gPos) ) + if ( getTermGeometry().contains(tPos) ) setDown(); else setUp(); diff --git a/src/fbuttongroup.cpp b/src/fbuttongroup.cpp index 997cdaa6..c492f5ca 100644 --- a/src/fbuttongroup.cpp +++ b/src/fbuttongroup.cpp @@ -54,16 +54,16 @@ FButtonGroup::~FButtonGroup() // destructor //---------------------------------------------------------------------- void FButtonGroup::init() { - top_padding = 1; - left_padding = 1; - bottom_padding = 1; - right_padding = 1; + setTopPadding(1); + setLeftPadding(1); + setBottomPadding(1); + setRightPadding(1); if ( isEnabled() ) flags |= fc::active; - foregroundColor = wc.label_fg; - backgroundColor = wc.label_bg; + setForegroundColor (wc.label_fg); + setBackgroundColor (wc.label_bg); buttonlist.clear(); // no buttons yet } @@ -152,7 +152,7 @@ void FButtonGroup::draw() if ( isMonochron() ) setReverse(true); - setColor (foregroundColor, backgroundColor); + setColor(); if ( border ) drawBorder(); @@ -252,9 +252,9 @@ void FButtonGroup::drawLabel() length--; if ( border ) - gotoxy (xpos+xmin, ypos+ymin-1); + printPos (2, 1); else - gotoxy (xpos+xmin-2, ypos+ymin-1); + printPos (0, 1); if ( isEnabled() ) setColor(wc.label_emphasis_fg, wc.label_bg); @@ -319,14 +319,18 @@ void FButtonGroup::hide() } setColor (fg, bg); - size = width; + size = getWidth(); + + if ( size < 0 ) + return; + blank = new char[size+1]; memset(blank, ' ', uLong(size)); blank[size] = '\0'; - for (int y=0; y < height; y++) + for (int y=0; y < getHeight(); y++) { - gotoxy (xpos+xmin-1, ypos+ymin-1+y); + printPos (1, 1+y); print (blank); } diff --git a/src/fcheckbox.cpp b/src/fcheckbox.cpp index 50b91db2..b0ed2d4a 100644 --- a/src/fcheckbox.cpp +++ b/src/fcheckbox.cpp @@ -53,8 +53,8 @@ void FCheckBox::drawCheckButton() if ( ! isVisible() ) return; - gotoxy (xpos+xmin-1, ypos+ymin-1); - setColor (foregroundColor, backgroundColor); + printPos (1,1); + setColor(); if ( isMonochron() ) { diff --git a/src/fdialog.cpp b/src/fdialog.cpp index 1e1f28b4..36a9b5c7 100644 --- a/src/fdialog.cpp +++ b/src/fdialog.cpp @@ -63,8 +63,8 @@ FDialog::~FDialog() // destructor if ( ! is_quit ) { - const FRect& geometry = getGeometryGlobalShadow(); - restoreVTerm (geometry); + const FRect& t_geometry = getTermGeometryWithShadow(); + restoreVTerm (t_geometry); } if ( vwin != 0 ) @@ -86,34 +86,23 @@ FDialog::~FDialog() // destructor //---------------------------------------------------------------------- void FDialog::init() { - FWidget* old_focus; - FWidget* rootObj = getRootWidget(); - - xmin = 1 + rootObj->getLeftPadding(); - ymin = 1 + rootObj->getTopPadding(); - xmax = rootObj->getWidth(); - ymax = rootObj->getHeight(); - width = 10; - height = 10; - client_xmin = 1; - client_ymin = 1; - client_xmax = width; - client_ymax = height; - top_padding = 2; - left_padding = 1; - bottom_padding = 1; - right_padding = 1; + FWidget* old_focus; + setTopPadding(2); + setLeftPadding(1); + setBottomPadding(1); + setRightPadding(1); + ignorePadding(); + setDialogWidget(); + // initialize geometry values + setGeometry (1, 1, 10, 10, false); createArea (vwin); - setGeometry (1, 1, 10, 10, false); // initialize geometry values - ignore_padding = true; - dialog_object = true; addDialog(this); addWindow(this); setActiveWindow(this); setTransparentShadow(); - foregroundColor = wc.dialog_fg; - backgroundColor = wc.dialog_bg; + setForegroundColor (wc.dialog_fg); + setBackgroundColor (wc.dialog_bg); if ( hasFocus() ) flags |= fc::focus; @@ -132,7 +121,7 @@ void FDialog::init() accelerator_list = new Accelerators(); // Add the dialog menu dialog_menu = new FMenu ("-", this); - dialog_menu->move (xpos, ypos+1); + dialog_menu->move (getX(), getY()+1); dgl_menuitem = dialog_menu->getItem(); if ( dgl_menuitem ) @@ -141,8 +130,8 @@ void FDialog::init() dgl_menuitem->unsetFocusable(); } - zoom_item = new FMenuItem ("&Zoom", dialog_menu); - zoom_item->setStatusbarMessage ("Enlarge or restore the window size"); + zoom_item = new FMenuItem (dialog_menu); + setZoomItem(); zoom_item->setDisable(); zoom_item->addCallback @@ -164,48 +153,47 @@ void FDialog::init() //---------------------------------------------------------------------- void FDialog::drawBorder() { - int x1, x2, y1, y2; - x1 = xpos+xmin-1; - x2 = xpos+xmin-2+width; - y1 = ypos+ymin; - y2 = ypos+ymin-2+height; + int x1 = 1; + int x2 = 1 + getWidth() - 1; + int y1 = 2; + int y2 = 1 + getHeight() - 1; //if ( resize ) - // setColor (wc.dialog_resize_fg, backgroundColor); + // setColor (wc.dialog_resize_fg, getBackgroundColor()); if ( isNewFont() ) { for (int y=y1; y <= y2; y++) { - gotoxy (x1, y); + printPos (x1, y); // border left ⎸ print (fc::NF_border_line_left); - gotoxy (x2, y); + printPos (x2, y); // border right⎹ print (fc::NF_rev_border_line_right); } - gotoxy (x1, y2); + printPos (x1, y2); // lower left corner border ⎣ print (fc::NF_border_corner_lower_left); - for (int x=1; x < width-1; x++) // low line _ + for (int x=1; x < getWidth()-1; x++) // low line _ print (fc::NF_border_line_bottom); - gotoxy (x2, y2); + printPos (x2, y2); // lower right corner border ⎦ print (fc::NF_rev_border_corner_lower_right); } else { - gotoxy (x1, y1); + printPos (x1, y1); print (fc::BoxDrawingsDownAndRight); // ┌ for (int x=x1+1; x < x2; x++) print (fc::BoxDrawingsHorizontal); // ─ print (fc::BoxDrawingsDownAndLeft); // ┐ - gotoxy (x1, y2); + printPos (x1, y2); print (fc::BoxDrawingsUpAndRight); // └ for (int x=x1+1; x < x2; x++) @@ -215,9 +203,9 @@ void FDialog::drawBorder() for (int y=y1+1; y < y2; y++) { - gotoxy (x1, y); + printPos (x1, y); print (fc::BoxDrawingsVertical); // │ - gotoxy (x2, y); + printPos (x2, y); print (fc::BoxDrawingsVertical); // │ } @@ -231,7 +219,7 @@ void FDialog::drawTitleBar() const int menu_btn = 3; // draw the title button - gotoxy (xpos+xmin-1, ypos+ymin-1); + printPos (1, 1); if ( dialog_menu && dialog_menu->isVisible() ) setColor (wc.titlebar_button_focus_fg, wc.titlebar_button_focus_bg); @@ -293,7 +281,7 @@ void FDialog::drawTitleBar() zoom_btn = 3; length = int(tb_text.getLength()); - i = width - length - menu_btn - zoom_btn; + i = getWidth() - length - menu_btn - zoom_btn; i = int(i/2); for (x=1; x <= i; x++) @@ -304,7 +292,7 @@ void FDialog::drawTitleBar() print (tb_text); // fill the rest of the bar - for (; x+1+length < width-zoom_btn-1; x++) + for (; x+1+length < getWidth()-zoom_btn-1; x++) print (' '); if ( getMaxColor() < 16 ) @@ -380,7 +368,7 @@ void FDialog::drawTitleBar() setReverse(false); /* print the number of window in stack */ -//gotoxy(xpos+xmin+width-4, ypos+ymin-1); +//printPos (getWidth()-2, 1); //printf ("(%d)", getWindowLayer(this)); } @@ -405,6 +393,66 @@ void FDialog::leaveMenu() flush_out(); } +//---------------------------------------------------------------------- +void FDialog::openMenu() +{ + // open the titlebar menu + if ( ! dialog_menu ) + return; + + if ( dialog_menu->isVisible() ) + { + leaveMenu(); + drawTitleBar(); + } + else + { + setOpenMenu(dialog_menu); + dialog_menu->move (getX(), getY()+1); + dialog_menu->setVisible(); + drawTitleBar(); + dialog_menu->show(); + dialog_menu->raiseWindow(dialog_menu); + dialog_menu->redraw(); + } +} + +//---------------------------------------------------------------------- +void FDialog::selectFirstMenuItem() +{ + // focus to the first enabled menu item + FMenuItem* first_item; + dialog_menu->selectFirstItem(); + first_item = dialog_menu->getSelectedItem(); + + if ( first_item ) + first_item->setFocus(); + + dialog_menu->redraw(); + + if ( statusBar() ) + statusBar()->drawMessage(); + + updateTerminal(); + flush_out(); +} + +//---------------------------------------------------------------------- +void FDialog::setZoomItem() +{ + if ( isZoomed() ) + { + zoom_item->setText ("&Unzoom"); + zoom_item->setStatusbarMessage ("Restore the window size"); + } + else + { + zoom_item->setText ("&Zoom"); + zoom_item->setStatusbarMessage ("Enlarge the window to the entire desktop"); + } +} + + //---------------------------------------------------------------------- void FDialog::cb_zoom (FWidget*, void*) { @@ -413,6 +461,7 @@ void FDialog::cb_zoom (FWidget*, void*) setClickedWidget(0); drawTitleBar(); zoomWindow(); + setZoomItem(); } //---------------------------------------------------------------------- @@ -471,7 +520,7 @@ void FDialog::drawDialogShadow() return; drawShadow(); - gotoxy (xpos+xmin-1, ypos+ymin-1+height); + printPos (1, 1+getHeight()); setTransparent(); print(' '); unsetTransparent(); @@ -480,17 +529,9 @@ void FDialog::drawDialogShadow() //---------------------------------------------------------------------- void FDialog::draw() { - /*if ( isZoomed() && ! isRootWidget() ) - { - xpos = 1; - ypos = 1; - width = xmax; - height = ymax; - }*/ - updateVTerm(false); // fill the background - setColor (foregroundColor, backgroundColor); + setColor(); if ( isMonochron() ) setReverse(true); @@ -527,7 +568,19 @@ void FDialog::onClose (FCloseEvent* ev) //---------------------------------------------------------------------- void FDialog::onKeyPress (FKeyEvent* ev) { - if ( ! isEnabled() || this == getMainWidget() ) + if ( ! isEnabled() ) + return; + + if ( ev->key() == fc::Fckey_caret ) // Ctrl+^ + { + ev->accept(); + // open the titlebar menu + openMenu(); + // focus to the first enabled item + selectFirstMenuItem(); + } + + if ( this == getMainWidget() ) return; if ( ev->key() == fc::Fkey_escape @@ -568,8 +621,8 @@ void FDialog::onMouseDown (FMouseEvent* ev) bool has_raised; // click on titlebar or window: raise + activate - if ( mouse_x >= 4 && mouse_x <= width-zoom_btn && mouse_y == 1 ) - TitleBarClickPos.setPoint (ev->getGlobalX(), ev->getGlobalY()); + if ( mouse_x >= 4 && mouse_x <= getWidth()-zoom_btn && mouse_y == 1 ) + TitleBarClickPos.setPoint (ev->getTermX(), ev->getTermY()); else TitleBarClickPos.setPoint (0,0); @@ -583,24 +636,8 @@ void FDialog::onMouseDown (FMouseEvent* ev) // click on titlebar menu button if ( mouse_x < 4 && mouse_y == 1 ) - { - if ( dialog_menu->isVisible() ) - { - leaveMenu(); - drawTitleBar(); - } - else - { - setOpenMenu(dialog_menu); - dialog_menu->move (xpos, ypos+1); - dialog_menu->setVisible(); - drawTitleBar(); - dialog_menu->show(); - dialog_menu->raiseWindow(dialog_menu); - dialog_menu->redraw(); - } - } - else if ( mouse_x > width-zoom_btn && mouse_y == 1 ) + openMenu(); + else if ( mouse_x > getWidth()-zoom_btn && mouse_y == 1 ) { zoom_button_pressed = true; zoom_button_active = true; @@ -617,7 +654,7 @@ void FDialog::onMouseDown (FMouseEvent* ev) if ( ev->getButton() == fc::RightButton ) { // click on titlebar: just activate - if ( mouse_x >= 4 && mouse_x <= width && mouse_y == 1 ) + if ( mouse_x >= 4 && mouse_x <= getWidth() && mouse_y == 1 ) { if ( ! isActiveWindow() ) activateDialog(); @@ -627,7 +664,7 @@ void FDialog::onMouseDown (FMouseEvent* ev) if ( ev->getButton() == fc::MiddleButton ) { // click on titlebar: lower + activate - if ( mouse_x >= 4 && mouse_x <= width && mouse_y == 1 ) + if ( mouse_x >= 4 && mouse_x <= getWidth() && mouse_y == 1 ) { bool has_lowered = lowerWindow(); @@ -659,14 +696,14 @@ void FDialog::onMouseUp (FMouseEvent* ev) int mouse_y = ev->getY(); if ( ! TitleBarClickPos.isNull() - && titlebar_x > xpos+xmin+2 - && titlebar_x < xpos+xmin+width - && titlebar_y == ypos+ymin-1 ) + && titlebar_x > getTermX() + 3 + && titlebar_x < getTermX() + getWidth() + && titlebar_y == getTermY() ) { FPoint currentPos(getGeometry().getX(), getGeometry().getY()); - FPoint deltaPos = ev->getGlobalPos() - TitleBarClickPos; + FPoint deltaPos = ev->getTermPos() - TitleBarClickPos; move (currentPos + deltaPos); - TitleBarClickPos = ev->getGlobalPos(); + TitleBarClickPos = ev->getTermPos(); } // click on titlebar menu button @@ -675,27 +712,16 @@ void FDialog::onMouseUp (FMouseEvent* ev) && dialog_menu->isVisible() && ! dialog_menu->hasSelectedItem() ) { - FMenuItem* first_item; - dialog_menu->selectFirstItem(); - first_item = dialog_menu->getSelectedItem(); - - if ( first_item ) - first_item->setFocus(); - - dialog_menu->redraw(); - - if ( statusBar() ) - statusBar()->drawMessage(); - - updateTerminal(); - flush_out(); + // Sets focus to the first item + selectFirstMenuItem(); } - else if ( mouse_x > width - zoom_btn + else if ( mouse_x > getWidth() - zoom_btn && mouse_y == 1 && zoom_button_pressed ) { // zoom to maximum or restore the window size zoomWindow(); + setZoomItem(); } } @@ -727,21 +753,21 @@ void FDialog::onMouseMove (FMouseEvent* ev) if ( ! TitleBarClickPos.isNull() ) { FPoint currentPos(getGeometry().getX(), getGeometry().getY()); - FPoint deltaPos = ev->getGlobalPos() - TitleBarClickPos; + FPoint deltaPos = ev->getTermPos() - TitleBarClickPos; move (currentPos + deltaPos); - TitleBarClickPos = ev->getGlobalPos(); + TitleBarClickPos = ev->getTermPos(); } if ( dialog_menu->isVisible() && dialog_menu->isShown() ) { // Mouse event handover to the menu - const FRect& menu_geometry = dialog_menu->getGeometryGlobal(); + const FRect& menu_geometry = dialog_menu->getTermGeometry(); if ( dialog_menu->count() > 0 - && menu_geometry.contains(ev->getGlobalPos()) ) + && menu_geometry.contains(ev->getTermPos()) ) { - const FPoint& g = ev->getGlobalPos(); - const FPoint& p = dialog_menu->globalToLocalPos(g); + const FPoint& g = ev->getTermPos(); + const FPoint& p = dialog_menu->termToWidgetPos(g); int b = ev->getButton(); FMouseEvent* _ev = new FMouseEvent (fc::MouseMove_Event, p, g, b); dialog_menu->mouse_down = true; @@ -751,7 +777,7 @@ void FDialog::onMouseMove (FMouseEvent* ev) } } - if ( mouse_x > width - zoom_btn && mouse_y == 1 && zoom_button_active ) + if ( mouse_x > getWidth() - zoom_btn && mouse_y == 1 && zoom_button_active ) { zoom_button_pressed = true; drawTitleBar(); @@ -768,18 +794,31 @@ void FDialog::onMouseMove (FMouseEvent* ev) //---------------------------------------------------------------------- void FDialog::onMouseDoubleClick (FMouseEvent* ev) { - int x, y; + int x, y, mouse_x, mouse_y, zoom_btn; + bool is_resizeable; if ( ev->getButton() != fc::LeftButton ) return; - x = xpos + xmin - 1; - y = ypos + ymin - 1; - FRect title_button(x, y, 3, 1); - FPoint gPos = ev->getGlobalPos(); + mouse_x = ev->getX(); + mouse_y = ev->getY(); + is_resizeable = bool(flags & fc::resizeable); - if ( title_button.contains(gPos) ) + if ( ! is_resizeable ) + zoom_btn = 0; + else if ( isNewFont() ) + zoom_btn = 2; + else + zoom_btn = 3; + + x = getTermX(); + y = getTermY(); + FRect title_button(x, y, 3, 1); + FPoint tPos = ev->getTermPos(); + + if ( title_button.contains(tPos) ) { + // double click on title button FWidget* window_focus_widget; dialog_menu->unselectItem(); dialog_menu->hide(); @@ -797,6 +836,15 @@ void FDialog::onMouseDoubleClick (FMouseEvent* ev) else close(); } + else if ( is_resizeable + && mouse_x >= 4 + && mouse_x <= getWidth() - zoom_btn + && mouse_y == 1 ) + { + // double click on titlebar + zoomWindow(); // window zoom/unzoom + setZoomItem(); + } } //---------------------------------------------------------------------- @@ -862,7 +910,7 @@ void FDialog::onWindowRaised (FEvent*) if ( ! (isVisible() && isShown()) ) return; - putArea (getGlobalPos(), vwin); + putArea (getTermPos(), vwin); if ( ! window_list ) return; @@ -887,7 +935,7 @@ void FDialog::onWindowLowered (FEvent*) while ( iter != end ) { - putArea ((*iter)->getGlobalPos(), (*iter)->getVWin()); + putArea ((*iter)->getTermPos(), (*iter)->getVWin()); ++iter; } } @@ -952,29 +1000,29 @@ void FDialog::move (const FPoint& pos) //---------------------------------------------------------------------- void FDialog::move (int x, int y) { - int dx, dy, old_x, old_y; + int dx, dy, old_x, old_y, rsw, bsh; - if ( x == xpos && y == ypos ) + if ( getX() == x && getY() == y ) return; - if ( x+width < 1 || x > getColumnNumber() || y < 1 || y > getLineNumber() ) + if ( x+getWidth() < 1 || x > getColumnNumber() || y < 1 || y > getLineNumber() ) return; if ( isZoomed() ) return; - dx = xpos - x; - dy = ypos - y; - old_x = getGlobalX(); - old_y = getGlobalY(); - short& rsw = shadow.x_ref(); // right shadow width; - short& bsh = shadow.y_ref(); // bottom shadow height - oldGeometry = getGeometryShadow(); + dx = getX() - x; + dy = getY() - y; + old_x = getTermX(); + old_y = getTermY(); + const FPoint& shadow = getShadow(); + rsw = shadow.getX(); // right shadow width; + bsh = shadow.getY(); // bottom shadow height + oldGeometry = getGeometryWithShadow(); FWidget::move(x,y); - xpos = x; - ypos = y; - putArea (getGlobalPos(), vwin);updateTerminal(); + setPos(x, y, false); + putArea (getTermPos(), vwin);updateTerminal(); if ( getGeometry().overlap(oldGeometry) ) { @@ -988,25 +1036,25 @@ void FDialog::move (int x, int y) if ( dx > 0 ) { if ( dy > 0 ) - restoreVTerm (old_x+width+rsw-dx, old_y, dx, height+bsh-dy); + restoreVTerm (old_x+getWidth()+rsw-dx, old_y, dx, getHeight()+bsh-dy); else - restoreVTerm (old_x+width+rsw-dx, old_y+abs(dy), dx, height+bsh-abs(dy)); + restoreVTerm (old_x+getWidth()+rsw-dx, old_y+abs(dy), dx, getHeight()+bsh-abs(dy)); } else { if ( dy > 0 ) - restoreVTerm (old_x, old_y, abs(dx), height+bsh-dy); + restoreVTerm (old_x, old_y, abs(dx), getHeight()+bsh-dy); else - restoreVTerm (old_x, old_y+abs(dy), abs(dx), height+bsh-abs(dy)); + restoreVTerm (old_x, old_y+abs(dy), abs(dx), getHeight()+bsh-abs(dy)); } if ( dy > 0 ) - restoreVTerm (old_x, old_y+height+bsh-dy, width+rsw, dy); + restoreVTerm (old_x, old_y+getHeight()+bsh-dy, getWidth()+rsw, dy); else - restoreVTerm (old_x, old_y, width+rsw, abs(dy)); + restoreVTerm (old_x, old_y, getWidth()+rsw, abs(dy)); } else { - restoreVTerm (old_x, old_y, width+rsw, height+bsh); + restoreVTerm (old_x, old_y, getWidth()+rsw, getHeight()+bsh); } // handle overlaid windows @@ -1020,7 +1068,7 @@ void FDialog::move (int x, int y) while ( iter != end ) { if ( overlaid ) - putArea ((*iter)->getGlobalPos(), (*iter)->getVWin()); + putArea ((*iter)->getTermPos(), (*iter)->getVWin()); if ( vwin == (*iter)->getVWin() ) overlaid = true; @@ -1038,7 +1086,6 @@ void FDialog::move (int x, int y) && focus_widget->hasVisibleCursor() ) { FPoint cursor_pos = focus_widget->getCursorPos(); - cursor_pos -= FPoint(dx,dy); if ( ! focus_widget->setCursorPos(cursor_pos) ) hideCursor(); @@ -1069,7 +1116,7 @@ void FDialog::activateDialog() if ( ! focusFirstChild() ) old_focus->unsetFocus(); - if ( ! old_focus->isWindow() ) + if ( ! old_focus->isWindowWidget() ) old_focus->redraw(); } @@ -1092,6 +1139,26 @@ bool FDialog::setFocus (bool on) return on; } +//---------------------------------------------------------------------- +bool FDialog::setDialogWidget (bool on) +{ + if ( isDialogWidget() == on ) + return true; + + if ( on ) + { + flags |= fc::dialog_widget; + setTermOffsetWithPadding(); + } + else + { + flags &= ~fc::dialog_widget; + setParentOffset(); + } + + return on; +} + //---------------------------------------------------------------------- bool FDialog::setModal (bool on) { @@ -1119,17 +1186,13 @@ bool FDialog::setTransparentShadow (bool on) { flags |= fc::shadow; flags |= fc::trans_shadow; - shadow.setPoint(2,1); - adjustWidgetSizeShadow = getGeometry() + getShadow(); - adjustWidgetSizeGlobalShadow = getGeometryGlobal() + getShadow(); + setShadowSize (2,1); } else { flags &= ~fc::shadow; flags &= ~fc::trans_shadow; - shadow.setPoint(0,0); - adjustWidgetSizeShadow = getGeometry() + getShadow(); - adjustWidgetSizeGlobalShadow = getGeometryGlobal() + getShadow(); + setShadowSize (0,0); } resizeArea (vwin); @@ -1146,17 +1209,13 @@ bool FDialog::setShadow (bool on) { flags |= fc::shadow; flags &= ~fc::trans_shadow; - shadow.setPoint(1,1); - adjustWidgetSizeShadow = getGeometry() + getShadow(); - adjustWidgetSizeGlobalShadow = getGeometryGlobal() + getShadow(); + setShadowSize (1,1); } else { flags &= ~fc::shadow; flags &= ~fc::trans_shadow; - shadow.setPoint(0,0); - adjustWidgetSizeShadow = getGeometry() + getShadow(); - adjustWidgetSizeGlobalShadow = getGeometryGlobal() + getShadow(); + setShadowSize (0,0); } resizeArea (vwin); diff --git a/src/fdialog.h b/src/fdialog.h index aa4bc389..0580a1d3 100644 --- a/src/fdialog.h +++ b/src/fdialog.h @@ -65,9 +65,14 @@ class FDialog : public FWindow FDialog (const FDialog&); FDialog& operator = (const FDialog&); void init(); - void drawBorder(); + // make every drawBorder from FWidget available + using FWidget::drawBorder; + virtual void drawBorder(); void drawTitleBar(); void leaveMenu(); + void openMenu(); + void selectFirstMenuItem(); + void setZoomItem(); void cb_zoom (FWidget*, void*); void cb_close (FWidget*, void*); static void addDialog (FWidget*); @@ -104,26 +109,29 @@ class FDialog : public FWindow void move (const FPoint&); void move (int, int); - bool setFocus(bool); + bool setFocus (bool); bool setFocus(); bool unsetFocus(); - bool setModal(bool); + bool setDialogWidget (bool); + bool setDialogWidget(); + bool unsetDialogWidget(); + bool setModal (bool); bool setModal(); bool unsetModal(); bool isModal(); - bool setScrollable(bool); + bool setScrollable (bool); bool setScrollable(); bool unsetScrollable(); bool isScrollable(); - bool setResizeable(bool); + bool setResizeable (bool); bool setResizeable(); bool unsetResizeable(); bool isResizeable(); - bool setTransparentShadow(bool); + bool setTransparentShadow (bool); bool setTransparentShadow(); bool unsetTransparentShadow(); bool hasTransparentShadow(); - bool setShadow(bool); + bool setShadow (bool); bool setShadow(); bool unsetShadow(); bool hasShadow(); @@ -148,6 +156,14 @@ inline bool FDialog::setFocus() inline bool FDialog::unsetFocus() { return setFocus(false); } +//---------------------------------------------------------------------- +inline bool FDialog::setDialogWidget() +{ return setDialogWidget(true); } + +//---------------------------------------------------------------------- +inline bool FDialog::unsetDialogWidget() +{ return setDialogWidget(false); } + //---------------------------------------------------------------------- inline bool FDialog::setModal() { return setModal(true); } diff --git a/src/fenum.h b/src/fenum.h index 94f4a948..b68b1ff4 100644 --- a/src/fenum.h +++ b/src/fenum.h @@ -51,15 +51,18 @@ class fc // properties of a widget enum widget_flags { - shadow = 0x00000001, - trans_shadow = 0x00000002, - active = 0x00000004, - focus = 0x00000008, - scrollable = 0x00000010, - resizeable = 0x00000020, - modal = 0x00000040, - flat = 0x00000080, - no_underline = 0x00000100 + shadow = 0x00000001, + trans_shadow = 0x00000002, + active = 0x00000004, + focus = 0x00000008, + scrollable = 0x00000010, + resizeable = 0x00000020, + modal = 0x00000040, + window_widget = 0x00000080, + dialog_widget = 0x00000100, + menu_widget = 0x00000200, + flat = 0x00000400, + no_underline = 0x00000800 }; // internal character encoding diff --git a/src/fevent.cpp b/src/fevent.cpp index f56afb8c..8d93b17e 100644 --- a/src/fevent.cpp +++ b/src/fevent.cpp @@ -63,18 +63,18 @@ FMouseEvent::FMouseEvent ( int ev_type // constructor , int button ) : FEvent(ev_type) , p(pos) - , g() + , tp() , b(button) { } //---------------------------------------------------------------------- FMouseEvent::FMouseEvent ( int ev_type // constructor , const FPoint& pos - , const FPoint& globalPos + , const FPoint& termPos , int button ) : FEvent(ev_type) , p(pos) - , g(globalPos) + , tp(termPos) , b(button) { } @@ -87,8 +87,8 @@ const FPoint& FMouseEvent::getPos() const { return p; } //---------------------------------------------------------------------- -const FPoint& FMouseEvent::getGlobalPos() const -{ return g; } +const FPoint& FMouseEvent::getTermPos() const +{ return tp; } //---------------------------------------------------------------------- int FMouseEvent::getX() const @@ -99,12 +99,12 @@ int FMouseEvent::getY() const { return p.getY(); } //---------------------------------------------------------------------- -int FMouseEvent::getGlobalX() const -{ return g.getX(); } +int FMouseEvent::getTermX() const +{ return tp.getX(); } //---------------------------------------------------------------------- -int FMouseEvent::getGlobalY() const -{ return g.getY(); } +int FMouseEvent::getTermY() const +{ return tp.getY(); } //---------------------------------------------------------------------- int FMouseEvent::getButton() const @@ -120,18 +120,18 @@ FWheelEvent::FWheelEvent ( int ev_type // constructor , int wheel ) : FEvent(ev_type) , p(pos) - , g() + , tp() , w(wheel) { } //---------------------------------------------------------------------- FWheelEvent::FWheelEvent ( int ev_type // constructor , const FPoint& pos - , const FPoint& globalPos + , const FPoint& termPos , int wheel ) : FEvent(ev_type) , p(pos) - , g(globalPos) + , tp(termPos) , w(wheel) { } @@ -144,8 +144,8 @@ const FPoint& FWheelEvent::getPos() const { return p; } //---------------------------------------------------------------------- -const FPoint& FWheelEvent::getGlobalPos() const -{ return g; } +const FPoint& FWheelEvent::getTermPos() const +{ return tp; } //---------------------------------------------------------------------- int FWheelEvent::getX() const @@ -156,12 +156,12 @@ int FWheelEvent::getY() const { return p.getY(); } //---------------------------------------------------------------------- -int FWheelEvent::getGlobalX() const -{ return g.getX(); } +int FWheelEvent::getTermX() const +{ return tp.getX(); } //---------------------------------------------------------------------- -int FWheelEvent::getGlobalY() const -{ return g.getY(); } +int FWheelEvent::getTermY() const +{ return tp.getY(); } //---------------------------------------------------------------------- int FWheelEvent::getWheel() const diff --git a/src/fevent.h b/src/fevent.h index 8c6b6bfd..dc7c7a8f 100644 --- a/src/fevent.h +++ b/src/fevent.h @@ -119,16 +119,16 @@ class FMouseEvent : public FEvent // mouse event ~FMouseEvent(); const FPoint& getPos() const; - const FPoint& getGlobalPos() const; + const FPoint& getTermPos() const; int getX() const; int getY() const; - int getGlobalX() const; - int getGlobalY() const; + int getTermX() const; + int getTermY() const; int getButton() const; protected: FPoint p; - FPoint g; + FPoint tp; int b; }; @@ -150,16 +150,16 @@ class FWheelEvent : public FEvent // wheel event ~FWheelEvent(); const FPoint& getPos() const; - const FPoint& getGlobalPos() const; + const FPoint& getTermPos() const; int getX() const; int getY() const; - int getGlobalX() const; - int getGlobalY() const; + int getTermX() const; + int getTermY() const; int getWheel() const; protected: FPoint p; - FPoint g; + FPoint tp; int w; }; diff --git a/src/ffiledialog.cpp b/src/ffiledialog.cpp index 81c7954a..f7443129 100644 --- a/src/ffiledialog.cpp +++ b/src/ffiledialog.cpp @@ -106,22 +106,16 @@ FFileDialog::~FFileDialog() // destructor void FFileDialog::init() { FWidget* parent_widget; - int x, y; - height = 15; - width = 42; - - if ( width < 15 ) - width = 15; - - if ( width < 20 ) - width = 20; - + int x, y, w, h; + w = 42; + h = 15; + setGeometry(1, 1, w, h, false); parent_widget = getParentWidget(); if ( parent_widget ) { - x = 1 + int((parent_widget->getWidth()-width)/2); - y = 1 + int((parent_widget->getHeight()-height)/3); + x = 1 + int((parent_widget->getWidth()-w)/2); + y = 1 + int((parent_widget->getHeight()-h)/3); } else x = y = 1; @@ -153,7 +147,7 @@ void FFileDialog::init() open = new FButton("&Open",this); open->setGeometry(30, 10, 9, 1); - setGeometry (x, y, width, height); + setGeometry (x, y, getWidth(), getHeight()); filename->addCallback ( @@ -488,10 +482,10 @@ void FFileDialog::adjustSize() h = 30; setHeight (h, false); - X = 1 + int((max_width-width)/2); - Y = 1 + int((max_height-height)/3); + X = 1 + int((max_width - getWidth()) / 2); + Y = 1 + int((max_height - getHeight()) / 3); setPos(X, Y, false); - filebrowser->setHeight(h-8, false); + filebrowser->setHeight (h-8, false); hidden->setY(h-4, false); cancel->setY(h-4, false); open->setY(h-4, false); diff --git a/src/flabel.cpp b/src/flabel.cpp index c4b09055..32436785 100644 --- a/src/flabel.cpp +++ b/src/flabel.cpp @@ -64,13 +64,13 @@ void FLabel::init() if ( parent_widget ) { - foregroundColor = parent_widget->getForegroundColor(); - backgroundColor = parent_widget->getBackgroundColor(); + setForegroundColor (parent_widget->getForegroundColor()); + setBackgroundColor (parent_widget->getBackgroundColor()); } else { - foregroundColor = wc.dialog_fg; - backgroundColor = wc.dialog_bg; + setForegroundColor (wc.dialog_fg); + setBackgroundColor (wc.dialog_bg); } } @@ -153,14 +153,14 @@ int FLabel::getXOffset(int length) return 0; case fc::alignCenter: - if ( length < width ) - return int((width - length) / 2); + if ( length < getWidth() ) + return int((getWidth() - length) / 2); else return 0; case fc::alignRight: - if ( length < width ) - return width - length; + if ( length < getWidth() ) + return getWidth() - length; else return 0; @@ -183,10 +183,10 @@ void FLabel::printLine ( wchar_t*& line for (int x=0; x < xoffset; x++) print (' '); - if ( length <= uInt(width) ) + if ( length <= uInt(getWidth()) ) to_char = int(length); else - to_char = width - 2; + to_char = getWidth() - 2; if ( hasReverseMode() ) setReverse(true); @@ -214,23 +214,23 @@ void FLabel::printLine ( wchar_t*& line unsetUnderline(); if ( hasEmphasis() ) - setColor (emphasis_color, backgroundColor); + setColor (emphasis_color, getBackgroundColor()); else - setColor (foregroundColor, backgroundColor); + setColor(); } else print ( line[z] ); } - if ( length > uInt(width) ) + if ( length > uInt(getWidth()) ) { - setColor (ellipsis_color, backgroundColor); + setColor (ellipsis_color, getBackgroundColor()); print (".."); - setColor (foregroundColor, backgroundColor); + setColor(); } else { - for (int x=xoffset+to_char; x < width; x++) + for (int x=xoffset+to_char; x < getWidth(); x++) print (' '); } @@ -260,19 +260,19 @@ void FLabel::draw() } if ( hasEmphasis() ) - setColor (emphasis_color, backgroundColor); + setColor (emphasis_color, getBackgroundColor()); else - setColor (foregroundColor, backgroundColor); + setColor(); hotkeypos = -1; - if ( multiline && height > 1 ) + if ( multiline && getHeight() > 1 ) { uInt y = 0; uInt text_lines = uInt(multiline_text.size()); bool hotkey_printed = false; - while ( y < text_lines && y < uInt(height) ) + while ( y < text_lines && y < uInt(getHeight()) ) { length = multiline_text[y].getLength(); LabelText = new wchar_t[length+1](); @@ -284,7 +284,7 @@ void FLabel::draw() else wcsncpy(dest, src, length); - gotoxy (xpos+xmin-1, ypos+ymin-1+int(y)); + printPos (1, 1+int(y)); if ( hotkeypos != -1 ) { @@ -314,7 +314,7 @@ void FLabel::draw() if ( hotkeypos != -1 ) length--; - gotoxy (xpos+xmin-1, ypos+ymin-1); + printPos (1,1); xoffset = getXOffset (int(length)); printLine (LabelText, length, hotkeypos, xoffset); delete[] LabelText; @@ -337,6 +337,7 @@ void FLabel::draw() void FLabel::hide() { short fg, bg; + int size; char* blank; FWidget* parent_widget = getParentWidget(); @@ -354,9 +355,15 @@ void FLabel::hide() } setColor (fg, bg); - blank = new char[width+1]; - memset(blank, ' ', uLong(width)); - blank[width] = '\0'; + size = getWidth(); + + if ( size < 0 ) + return; + + blank = new char[size+1]; + memset(blank, ' ', uLong(size)); + blank[getWidth()] = '\0'; + printPos (1,1); print (blank); delete[] blank; } diff --git a/src/flineedit.cpp b/src/flineedit.cpp index 6d26cd8c..2e3af944 100644 --- a/src/flineedit.cpp +++ b/src/flineedit.cpp @@ -22,7 +22,7 @@ FLineEdit::FLineEdit(FWidget* parent) , scrollRepeat(100) , insert_mode(true) , cursor_pos(0) - , offset(0) + , text_offset(0) , label_orientation(FLineEdit::label_left) { init(); @@ -39,7 +39,7 @@ FLineEdit::FLineEdit (const FString& txt, FWidget* parent) , scrollRepeat(100) , insert_mode(true) , cursor_pos(0) - , offset(0) + , text_offset(0) , label_orientation(FLineEdit::label_left) { init(); @@ -80,19 +80,19 @@ void FLineEdit::init() if ( hasFocus() ) { - foregroundColor = wc.inputfield_active_focus_fg; - backgroundColor = wc.inputfield_active_focus_bg; + setForegroundColor (wc.inputfield_active_focus_fg); + setBackgroundColor (wc.inputfield_active_focus_bg); } else { - foregroundColor = wc.inputfield_active_fg; - backgroundColor = wc.inputfield_active_bg; + setForegroundColor (wc.inputfield_active_fg); + setBackgroundColor (wc.inputfield_active_bg); } } else // inactive { - foregroundColor = wc.inputfield_inactive_fg; - backgroundColor = wc.inputfield_inactive_bg; + setForegroundColor (wc.inputfield_inactive_fg); + setBackgroundColor (wc.inputfield_inactive_bg); } } @@ -137,7 +137,7 @@ void FLineEdit::drawInputField() isShadow = ((flags & fc::shadow) != 0 ); updateVTerm(false); - gotoxy (xpos+xmin-1, ypos+ymin-1); + printPos (1, 1); if ( isMonochron() ) { @@ -186,8 +186,8 @@ void FLineEdit::drawInputField() if ( isActiveFocus && getMaxColor() < 16 ) setBold(); - setColor (foregroundColor, backgroundColor); - show_text = text.mid(uInt(1+offset), uInt(width-2)); + setColor(); + show_text = text.mid(uInt(1+text_offset), uInt(getWidth()-2)); if ( isUTF8_linux_terminal() ) { @@ -203,7 +203,7 @@ void FLineEdit::drawInputField() x = int(show_text.getLength()); - while ( x < width-1 ) + while ( x < getWidth()-1 ) { print (' '); x++; @@ -224,7 +224,7 @@ void FLineEdit::drawInputField() updateVTerm(true); // set the cursor to the first pos. - setCursorPos (xpos+xmin+cursor_pos-offset, ypos+ymin-1); + setCursorPos (2+cursor_pos-text_offset, 1); if ( isCursorInside() && hasFocus() && isHiddenCursor() ) showCursor(); @@ -266,11 +266,11 @@ void FLineEdit::adjustLabel() switch ( label_orientation ) { case label_above: - label->setGeometry(xpos, ypos-1, label_length, 1); + label->setGeometry(getX(), getY()-1, label_length, 1); break; case label_left: - label->setGeometry(xpos-label_length, ypos, label_length, 1); + label->setGeometry(getX()-label_length, getY(), label_length, 1); break; } } @@ -287,7 +287,7 @@ void FLineEdit::adjustSize() //---------------------------------------------------------------------- void FLineEdit::hide() { - int s, size, lable_Length; + int s, size; short fg, bg; char* blank; FWidget* parent_widget = getParentWidget(); @@ -307,42 +307,25 @@ void FLineEdit::hide() setColor (fg, bg); s = hasShadow() ? 1 : 0; - size = width + s; + size = getWidth() + s; + + if ( size < 0 ) + return; + blank = new char[size+1]; memset(blank, ' ', uLong(size)); blank[size] = '\0'; - for (int y=0; y < height+s; y++) + for (int y=0; y < getHeight()+s; y++) { - gotoxy (xpos+xmin-1, ypos+ymin-1+y); + printPos (1, 1+y); print (blank); } delete[] blank; - lable_Length = int(label_text.getLength()); - if ( lable_Length > 0 ) - { - assert ( label_orientation == label_above - || label_orientation == label_left ); - - switch ( label_orientation ) - { - case label_above: - gotoxy (xpos+xmin-1, ypos+ymin-2); - break; - - case label_left: - gotoxy (xpos+xmin-int(lable_Length)-1, ypos+ymin-1); - break; - } - - blank = new char[lable_Length+1]; - memset(blank, ' ', uLong(size)); - blank[lable_Length] = '\0'; - print (blank); - delete[] blank; - } + if ( label ) + label->hide(); } //---------------------------------------------------------------------- @@ -356,20 +339,20 @@ bool FLineEdit::setEnable (bool on) if ( hasFocus() ) { - foregroundColor = wc.inputfield_active_focus_fg; - backgroundColor = wc.inputfield_active_focus_bg; + setForegroundColor (wc.inputfield_active_focus_fg); + setBackgroundColor (wc.inputfield_active_focus_bg); } else { - foregroundColor = wc.inputfield_active_fg; - backgroundColor = wc.inputfield_active_bg; + setForegroundColor (wc.inputfield_active_fg); + setBackgroundColor (wc.inputfield_active_bg); } } else { flags &= ~fc::active; - foregroundColor = wc.inputfield_inactive_fg; - backgroundColor = wc.inputfield_inactive_bg; + setForegroundColor (wc.inputfield_inactive_fg); + setBackgroundColor (wc.inputfield_inactive_bg); } return on; @@ -386,8 +369,8 @@ bool FLineEdit::setFocus (bool on) if ( isEnabled() ) { - foregroundColor = wc.inputfield_active_focus_fg; - backgroundColor = wc.inputfield_active_focus_bg; + setForegroundColor (wc.inputfield_active_focus_fg); + setBackgroundColor (wc.inputfield_active_focus_bg); if ( statusBar() ) { @@ -405,8 +388,8 @@ bool FLineEdit::setFocus (bool on) if ( isEnabled() ) { - foregroundColor = wc.inputfield_active_fg; - backgroundColor = wc.inputfield_active_bg; + setForegroundColor (wc.inputfield_active_fg); + setBackgroundColor (wc.inputfield_active_bg); if ( statusBar() ) statusBar()->clearMessage(); @@ -443,8 +426,8 @@ void FLineEdit::onKeyPress (FKeyEvent* ev) if ( cursor_pos < 0 ) cursor_pos=0; - if ( cursor_pos < offset ) - offset--; + if ( cursor_pos < text_offset ) + text_offset--; ev->accept(); break; @@ -455,22 +438,22 @@ void FLineEdit::onKeyPress (FKeyEvent* ev) if ( cursor_pos >= len ) cursor_pos=len; - if ( cursor_pos-offset >= width-2 && offset <= len-width+1 ) - offset++; + if ( cursor_pos-text_offset >= getWidth()-2 && text_offset <= len-getWidth()+1 ) + text_offset++; ev->accept(); break; case fc::Fkey_home: cursor_pos=0; - offset=0; + text_offset=0; ev->accept(); break; case fc::Fkey_end: cursor_pos=len; - if ( cursor_pos >= width-1 ) - offset=len-width+2; + if ( cursor_pos >= getWidth()-1 ) + text_offset=len-getWidth()+2; ev->accept(); break; @@ -487,8 +470,8 @@ void FLineEdit::onKeyPress (FKeyEvent* ev) if ( cursor_pos < 0 ) cursor_pos=0; - if ( offset > 0 && len-offset < width-1 ) - offset--; + if ( text_offset > 0 && len-text_offset < getWidth()-1 ) + text_offset--; ev->accept(); break; @@ -501,8 +484,8 @@ void FLineEdit::onKeyPress (FKeyEvent* ev) processChanged(); cursor_pos--; - if ( offset > 0 ) - offset--; + if ( text_offset > 0 ) + text_offset--; } ev->accept(); @@ -567,8 +550,8 @@ void FLineEdit::onKeyPress (FKeyEvent* ev) } cursor_pos++; - if ( cursor_pos >= width-1 ) - offset++; + if ( cursor_pos >= getWidth()-1 ) + text_offset++; ev->accept(); } @@ -613,10 +596,10 @@ void FLineEdit::onMouseDown (FMouseEvent* ev) mouse_x = ev->getX(); mouse_y = ev->getY(); - if ( mouse_x >= 2 && mouse_x <= width && mouse_y == 1 ) + if ( mouse_x >= 2 && mouse_x <= getWidth() && mouse_y == 1 ) { int len = int(text.getLength()); - cursor_pos = offset + mouse_x - 2; + cursor_pos = text_offset + mouse_x - 2; if ( cursor_pos >= len ) cursor_pos = len; @@ -649,9 +632,9 @@ void FLineEdit::onMouseMove (FMouseEvent* ev) mouse_x = ev->getX(); mouse_y = ev->getY(); - if ( mouse_x >= 2 && mouse_x <= width && mouse_y == 1 ) + if ( mouse_x >= 2 && mouse_x <= getWidth() && mouse_y == 1 ) { - cursor_pos = offset + mouse_x - 2; + cursor_pos = text_offset + mouse_x - 2; if ( cursor_pos >= len ) cursor_pos=len; @@ -664,30 +647,30 @@ void FLineEdit::onMouseMove (FMouseEvent* ev) if ( mouse_x < 2 ) { // drag left - if ( ! scrollTimer && offset > 0 ) + if ( ! scrollTimer && text_offset > 0 ) { scrollTimer = true; addTimer(scrollRepeat); dragScroll = FLineEdit::scrollLeft; } - if ( offset == 0 ) + if ( text_offset == 0 ) { delOwnTimer(); dragScroll = FLineEdit::noScroll; } } - else if ( mouse_x >= width ) + else if ( mouse_x >= getWidth() ) { // drag right - if ( ! scrollTimer && offset <= len-width+1 ) + if ( ! scrollTimer && text_offset <= len-getWidth()+1 ) { scrollTimer = true; addTimer(scrollRepeat); dragScroll = FLineEdit::scrollRight; } - if ( offset == len-width+2 ) + if ( text_offset == len-getWidth()+2 ) { delOwnTimer(); dragScroll = FLineEdit::noScroll; @@ -713,16 +696,16 @@ void FLineEdit::onTimer (FTimerEvent*) return; case FLineEdit::scrollLeft: - if ( offset == 0) + if ( text_offset == 0) { dragScroll = FLineEdit::noScroll; return; } - offset--; + text_offset--; - if ( offset < 0 ) - offset = 0; + if ( text_offset < 0 ) + text_offset = 0; cursor_pos--; @@ -732,16 +715,16 @@ void FLineEdit::onTimer (FTimerEvent*) break; case FLineEdit::scrollRight: - if ( offset == len-width+2 ) + if ( text_offset == len-getWidth()+2 ) { dragScroll = FLineEdit::noScroll; return; } - offset++; + text_offset++; - if ( offset > len-width+2 ) - offset = len-width+2; + if ( text_offset > len-getWidth()+2 ) + text_offset = len-getWidth()+2; cursor_pos++; @@ -857,7 +840,7 @@ void FLineEdit::onFocusOut (FFocusEvent*) //---------------------------------------------------------------------- void FLineEdit::clearText() { - offset = 0; + text_offset = 0; cursor_pos = 0; text.clear(); } @@ -865,7 +848,7 @@ void FLineEdit::clearText() //---------------------------------------------------------------------- void FLineEdit::setText (FString txt) { - offset = 0; + text_offset = 0; cursor_pos = 0; if ( txt ) diff --git a/src/flineedit.h b/src/flineedit.h index 8ad3e65c..6ce31ec1 100644 --- a/src/flineedit.h +++ b/src/flineedit.h @@ -51,7 +51,7 @@ class FLineEdit : public FWidget int scrollRepeat; bool insert_mode; int cursor_pos; - int offset; + int text_offset; public: enum label_o diff --git a/src/flistbox.cpp b/src/flistbox.cpp index da365d63..6938bad8 100644 --- a/src/flistbox.cpp +++ b/src/flistbox.cpp @@ -98,8 +98,8 @@ void FListBox::init() nf_offset = isNewFont() ? 1 : 0; - foregroundColor = wc.dialog_fg; - backgroundColor = wc.dialog_bg; + setForegroundColor (wc.dialog_fg); + setBackgroundColor (wc.dialog_bg); VBar = new FScrollbar(fc::vertical, this); VBar->setMinimum(0); @@ -135,29 +135,24 @@ void FListBox::draw() current = 1; updateVTerm(false); - setColor (foregroundColor, backgroundColor); + setColor(); if ( isMonochron() ) setReverse(true); if ( isNewFont() ) - width--; + drawBorder (1, getWidth() - 1, 1, getHeight()); + else + drawBorder(); - drawBorder(); - - if ( isNewFont() ) + if ( isNewFont() && ! VBar->isVisible() ) { - width++; + setColor(); - if ( ! VBar->isVisible() ) + for (int y=2; y < getHeight(); y++) { - setColor (foregroundColor, backgroundColor); - - for (int y=ypos+ymin; y < ypos+ymin+height-2; y++) - { - gotoxy(xpos+xmin+width-2, y); - print (' '); // clear right side of the scrollbar - } + printPos (getWidth(),y); + print (' '); // clear right side of the scrollbar } } @@ -201,18 +196,18 @@ void FListBox::drawLabel() txt = " " + text + " "; length = txt.getLength(); - gotoxy (xpos+xmin, ypos+ymin-1); + printPos (2, 1); if ( isEnabled() ) setColor(wc.label_emphasis_fg, wc.label_bg); else setColor(wc.label_inactive_fg, wc.label_inactive_bg); - if ( length <= uInt(width-2) ) + if ( length <= uInt(getWidth()-2) ) print (txt); else { - print (text.left(uInt(width-4))); + print (text.left(uInt(getWidth()-4))); setColor (wc.label_ellipsis_fg, wc.label_bg); print(".."); } @@ -225,12 +220,12 @@ void FListBox::drawList() uInt start, end, inc_len; bool isFocus; - if ( data.empty() || height < 4 || width < 5 ) + if ( data.empty() || getHeight() < 4 || getWidth() < 5 ) return; isFocus = ((flags & fc::focus) != 0); start = 0; - end = uInt(height-2); + end = uInt(getHeight()-2); inc_len = inc_search.getLength(); if ( end > count() ) @@ -251,7 +246,7 @@ void FListBox::drawList() for (uInt y=start; y < end; y++) { - gotoxy (xpos+xmin, ypos+ymin+int(y)); + printPos (2, 2 + int(y)); bool serach_mark = false; bool lineHasBrackets = hasBrackets(int(y) + yoffset + 1); bool isLineSelected = isSelected(int(y) + yoffset + 1); @@ -288,8 +283,7 @@ void FListBox::drawList() setColor ( wc.selected_current_element_fg , wc.selected_current_element_bg ); - setCursorPos ( xpos+xmin+1 - , ypos+ymin+int(y) ); // first character + setCursorPos (3, 2 + int(y)); // first character } else { @@ -300,17 +294,15 @@ void FListBox::drawList() { setColor ( wc.current_element_focus_fg , wc.current_element_focus_bg ); + int b = ( lineHasBrackets ) ? 1: 0; - if ( inc_len > 0 ) + if ( inc_len > 0 ) // incremental search { serach_mark = true; - int b = ( lineHasBrackets ) ? 1: 0; - setCursorPos ( xpos+xmin+int(inc_len)+b - , ypos+ymin+int(y) ); // last found character + setCursorPos (2 + b + int(inc_len), 2 + int(y)); // last found character } - else - setCursorPos ( xpos+xmin+1 - , ypos+ymin+int(y) ); // first character + else // only highlighted + setCursorPos (3 + b, 2 + int(y)); // first character } else setColor ( wc.current_element_fg @@ -370,12 +362,12 @@ void FListBox::drawList() element = data[y+uInt(yoffset)].getText() .mid ( uInt(1+xoffset) - , uInt(width-nf_offset-5) ); + , uInt(getWidth()-nf_offset-5) ); } else element = data[y+uInt(yoffset)].getText() .mid ( uInt(xoffset) - , uInt(width-nf_offset-4) ); + , uInt(getWidth()-nf_offset-4) ); element_str = element.wc_str(); len = element.getLength(); @@ -395,7 +387,7 @@ void FListBox::drawList() full_length = int(data[y+uInt(yoffset)].getText().getLength()); - if ( b+i < uInt(width-nf_offset-4) && xoffset <= full_length+1 ) + if ( b+i < uInt(getWidth()-nf_offset-4) && xoffset <= full_length+1 ) { if ( serach_mark && i == inc_len ) setColor ( wc.current_element_focus_fg @@ -432,7 +424,7 @@ void FListBox::drawList() i++; } - for (; b+i < uInt(width-nf_offset-3); i++) + for (; b+i < uInt(getWidth()-nf_offset-3); i++) print (' '); } else // line has no brackets @@ -441,7 +433,7 @@ void FListBox::drawList() uInt i, len; element = data[y+uInt(yoffset)].getText() .mid ( uInt(1+xoffset) - , uInt(width-nf_offset-4) ); + , uInt(getWidth()-nf_offset-4) ); element_str = element.wc_str(); len = element.getLength(); @@ -464,7 +456,7 @@ void FListBox::drawList() i++; } - for (; i < uInt(width-nf_offset-3); i++) + for (; i < uInt(getWidth()-nf_offset-3); i++) print (' '); } } @@ -508,8 +500,8 @@ void FListBox::adjustYOffset() { int element_count = int(count()); - if ( yoffset > element_count - height + 2 ) - yoffset = element_count - height + 2; + if ( yoffset > element_count - getHeight() + 2 ) + yoffset = element_count - getHeight() + 2; if ( yoffset < 0 ) yoffset = 0; @@ -517,8 +509,8 @@ void FListBox::adjustYOffset() if ( current < yoffset ) current = yoffset; - if ( current >= yoffset + height - 1 ) - yoffset = current - height + 2; + if ( current >= yoffset + getHeight() - 1 ) + yoffset = current - getHeight() + 2; } //---------------------------------------------------------------------- @@ -529,24 +521,24 @@ void FListBox::adjustSize() FWidget::adjustSize(); element_count = int(count()); - VBar->setMaximum(element_count - height + 2); - VBar->setPageSize(element_count, height - 2); - VBar->setX(width); - VBar->setHeight (height-2, false); + VBar->setMaximum(element_count - getHeight() + 2); + VBar->setPageSize(element_count, getHeight() - 2); + VBar->setX(getWidth()); + VBar->setHeight (getHeight()-2, false); VBar->resize(); - HBar->setMaximum(maxLineWidth - width + nf_offset + 4); - HBar->setPageSize(maxLineWidth, width - nf_offset - 4); - HBar->setY(height); - HBar->setWidth (width-2, false); + HBar->setMaximum(maxLineWidth - getWidth() + nf_offset + 4); + HBar->setPageSize(maxLineWidth, getWidth() - nf_offset - 4); + HBar->setY(getHeight()); + HBar->setWidth (getWidth()-2, false); HBar->resize(); - if ( element_count < height - 1 ) + if ( element_count < getHeight() - 1 ) VBar->hide(); else VBar->setVisible(); - if ( maxLineWidth < width - nf_offset - 3 ) + if ( maxLineWidth < getWidth() - nf_offset - 3 ) HBar->hide(); else HBar->setVisible(); @@ -602,14 +594,18 @@ void FListBox::hide() setColor (fg, bg); n = isNewFont() ? 1 : 0; - size = width + n; + size = getWidth() + n; + + if ( size < 0 ) + return; + blank = new char[size+1]; memset(blank, ' ', uLong(size)); blank[size] = '\0'; - for (int y=0; y < height; y++) + for (int y=0; y < getHeight(); y++) { - gotoxy (xpos+xmin-1, ypos+ymin-1+y); + printPos (1, 1 + y); print (blank); } @@ -630,10 +626,10 @@ void FListBox::showInsideBrackets ( int index { maxLineWidth = len; - if ( len >= width - nf_offset - 3 ) + if ( len >= getWidth() - nf_offset - 3 ) { - HBar->setMaximum(maxLineWidth - width + nf_offset + 4); - HBar->setPageSize(maxLineWidth, width - nf_offset - 4); + HBar->setMaximum(maxLineWidth - getWidth() + nf_offset + 4); + HBar->setPageSize(maxLineWidth, getWidth() - nf_offset - 4); HBar->setValue (xoffset); if ( ! HBar->isVisible() ) @@ -650,13 +646,13 @@ void FListBox::setGeometry (int x, int y, int w, int h, bool adjust) if ( isNewFont() ) { - VBar->setGeometry(width, 2, 2, height-2); - HBar->setGeometry(1, height, width-2, 1); + VBar->setGeometry (getWidth(), 2, 2, getHeight()-2); + HBar->setGeometry (1, getHeight(), getWidth()-2, 1); } else { - VBar->setGeometry(width, 2, 1, height-2); - HBar->setGeometry(2, height, width-2, 1); + VBar->setGeometry (getWidth(), 2, 1, getHeight()-2); + HBar->setGeometry (2, getHeight(), getWidth()-2, 1); } } @@ -739,7 +735,7 @@ void FListBox::onKeyPress (FKeyEvent* ev) if ( current > element_count ) current = element_count; - if ( current - yoffset >= height - 1 ) + if ( current - yoffset >= getHeight() - 1 ) yoffset++; inc_search.clear(); @@ -759,8 +755,8 @@ void FListBox::onKeyPress (FKeyEvent* ev) case fc::Fkey_right: xoffset++; - if ( xoffset > maxLineWidth - width + nf_offset + 4 ) - xoffset = maxLineWidth - width + nf_offset + 4; + if ( xoffset > maxLineWidth - getWidth() + nf_offset + 4 ) + xoffset = maxLineWidth - getWidth() + nf_offset + 4; if ( xoffset < 0 ) xoffset = 0; @@ -770,14 +766,14 @@ void FListBox::onKeyPress (FKeyEvent* ev) break; case fc::Fkey_ppage: - current -= height-3; + current -= getHeight()-3; if ( current < 1 ) current=1; if ( current <= yoffset ) { - yoffset -= height-3; + yoffset -= getHeight()-3; if ( yoffset < 0 ) yoffset=0; @@ -788,17 +784,17 @@ void FListBox::onKeyPress (FKeyEvent* ev) break; case fc::Fkey_npage: - current += height-3; + current += getHeight()-3; if ( current > element_count ) current = element_count; - if ( current - yoffset >= height - 1 ) + if ( current - yoffset >= getHeight() - 1 ) { - yoffset += height-3; + yoffset += getHeight()-3; - if ( yoffset > element_count - height + 2 ) - yoffset = element_count - height + 2; + if ( yoffset > element_count - getHeight() + 2 ) + yoffset = element_count - getHeight() + 2; } inc_search.clear(); @@ -815,8 +811,8 @@ void FListBox::onKeyPress (FKeyEvent* ev) case fc::Fkey_end: current = element_count; - if ( current >= height - 1 ) - yoffset = element_count - height + 2; + if ( current >= getHeight() - 1 ) + yoffset = element_count - getHeight() + 2; inc_search.clear(); ev->accept(); @@ -836,7 +832,7 @@ void FListBox::onKeyPress (FKeyEvent* ev) if ( current > element_count ) current = element_count; - if ( current-yoffset >= height - 1 ) + if ( current-yoffset >= getHeight() - 1 ) yoffset++; ev->accept(); @@ -1030,8 +1026,8 @@ void FListBox::onMouseDown (FMouseEvent* ev) mouse_x = ev->getX(); mouse_y = ev->getY(); - if ( mouse_x > 1 && mouse_x < width - && mouse_y > 1 && mouse_y < height ) + if ( mouse_x > 1 && mouse_x < getWidth() + && mouse_y > 1 && mouse_y < getHeight() ) { current = yoffset + mouse_y - 1; @@ -1088,8 +1084,8 @@ void FListBox::onMouseUp (FMouseEvent* ev) int mouse_x = ev->getX(); int mouse_y = ev->getY(); - if ( mouse_x > 1 && mouse_x < width - && mouse_y > 1 && mouse_y < height ) + if ( mouse_x > 1 && mouse_x < getWidth() + && mouse_y > 1 && mouse_y < getHeight() ) { processChanged(); @@ -1118,8 +1114,8 @@ void FListBox::onMouseMove (FMouseEvent* ev) mouse_x = ev->getX(); mouse_y = ev->getY(); - if ( mouse_x > 1 && mouse_x < width - && mouse_y > 1 && mouse_y < height ) + if ( mouse_x > 1 && mouse_x < getWidth() + && mouse_y > 1 && mouse_y < getHeight() ) { current = yoffset + mouse_y - 1; @@ -1178,7 +1174,7 @@ void FListBox::onMouseMove (FMouseEvent* ev) if ( mouse_y < 2 ) { // drag up - if ( dragScroll != FListBox::noScroll && scrollDistance < height-2 ) + if ( dragScroll != FListBox::noScroll && scrollDistance < getHeight()-2 ) scrollDistance++; if ( ! scrollTimer && current > 1 ) @@ -1198,10 +1194,10 @@ void FListBox::onMouseMove (FMouseEvent* ev) dragScroll = FListBox::noScroll; } } - else if ( mouse_y >= height ) + else if ( mouse_y >= getHeight() ) { // drag down - if ( dragScroll != FListBox::noScroll && scrollDistance < height-2 ) + if ( dragScroll != FListBox::noScroll && scrollDistance < getHeight()-2 ) scrollDistance++; if ( ! scrollTimer && current < int(count()) ) @@ -1242,8 +1238,8 @@ void FListBox::onMouseDoubleClick (FMouseEvent* ev) mouse_x = ev->getX(); mouse_y = ev->getY(); - if ( mouse_x > 1 && mouse_x < width - && mouse_y > 1 && mouse_y < height ) + if ( mouse_x > 1 && mouse_x < getWidth() + && mouse_y > 1 && mouse_y < getHeight() ) { if ( yoffset + mouse_y - 1 > int(count()) ) return; @@ -1297,11 +1293,11 @@ void FListBox::onTimer (FTimerEvent*) if ( current > element_count ) current = element_count; - if ( current - yoffset >= height - 1 ) + if ( current - yoffset >= getHeight() - 1 ) yoffset += scrollDistance; - if ( yoffset > element_count - height + 2 ) - yoffset = element_count - height + 2; + if ( yoffset > element_count - getHeight() + 2 ) + yoffset = element_count - getHeight() + 2; default: break; @@ -1363,7 +1359,7 @@ void FListBox::onWheel (FWheelEvent* ev) element_count = int(count()); current_before = current; yoffset_before = yoffset; - yoffset_end = element_count - height + 2; + yoffset_end = element_count - getHeight() + 2; if ( yoffset_end < 0 ) yoffset_end = 0; @@ -1477,7 +1473,7 @@ void FListBox::cb_VBarChange (FWidget*, void*) switch ( scrollType ) { case FScrollbar::scrollPageBackward: - distance = height-2; + distance = getHeight()-2; // fall through case FScrollbar::scrollStepBackward: current -= distance; @@ -1494,7 +1490,7 @@ void FListBox::cb_VBarChange (FWidget*, void*) break; case FScrollbar::scrollPageForward: - distance = height-2; + distance = getHeight()-2; // fall through case FScrollbar::scrollStepForward: current += distance; @@ -1502,11 +1498,11 @@ void FListBox::cb_VBarChange (FWidget*, void*) if ( current > element_count ) current = element_count; - if ( current - yoffset >= height - 1 ) + if ( current - yoffset >= getHeight() - 1 ) yoffset += distance; - if ( yoffset > element_count - height + 2 ) - yoffset = element_count - height + 2; + if ( yoffset > element_count - getHeight() + 2 ) + yoffset = element_count - getHeight() + 2; break; @@ -1520,8 +1516,8 @@ void FListBox::cb_VBarChange (FWidget*, void*) int c = current - yoffset; yoffset = val; - if ( yoffset > element_count - height + 2 ) - yoffset = element_count - height + 2; + if ( yoffset > element_count - getHeight() + 2 ) + yoffset = element_count - getHeight() + 2; if ( yoffset < 0 ) yoffset = 0; @@ -1576,13 +1572,13 @@ void FListBox::cb_HBarChange (FWidget*, void*) { int distance = 1; int xoffset_before = xoffset; - int xoffset_end = maxLineWidth - width + nf_offset + 4; + int xoffset_end = maxLineWidth - getWidth() + nf_offset + 4; int scrollType = HBar->getScrollType(); switch ( scrollType ) { case FScrollbar::scrollPageBackward: - distance = width - nf_offset - 4; + distance = getWidth() - nf_offset - 4; // fall through case FScrollbar::scrollStepBackward: xoffset -= distance; @@ -1592,13 +1588,13 @@ void FListBox::cb_HBarChange (FWidget*, void*) break; case FScrollbar::scrollPageForward: - distance = width - nf_offset - 4; + distance = getWidth() - nf_offset - 4; // fall through case FScrollbar::scrollStepForward: xoffset += distance; - if ( xoffset > maxLineWidth - width + nf_offset + 4 ) - xoffset = maxLineWidth - width + nf_offset + 4; + if ( xoffset > maxLineWidth - getWidth() + nf_offset + 4 ) + xoffset = maxLineWidth - getWidth() + nf_offset + 4; if ( xoffset < 0 ) xoffset = 0; @@ -1614,8 +1610,8 @@ void FListBox::cb_HBarChange (FWidget*, void*) xoffset = val; - if ( xoffset > maxLineWidth - width + nf_offset + 4 ) - xoffset = maxLineWidth - width + nf_offset + 4; + if ( xoffset > maxLineWidth - getWidth() + nf_offset + 4 ) + xoffset = maxLineWidth - getWidth() + nf_offset + 4; if ( xoffset < 0 ) xoffset = 0; @@ -1685,10 +1681,10 @@ void FListBox::insert ( FString item { maxLineWidth = len; - if ( len >= width - nf_offset - 3 ) + if ( len >= getWidth() - nf_offset - 3 ) { - HBar->setMaximum(maxLineWidth - width + nf_offset + 4); - HBar->setPageSize(maxLineWidth, width - nf_offset - 4); + HBar->setMaximum(maxLineWidth - getWidth() + nf_offset + 4); + HBar->setPageSize(maxLineWidth, getWidth() - nf_offset - 4); HBar->calculateSliderValues(); if ( ! HBar->isVisible() ) @@ -1701,11 +1697,11 @@ void FListBox::insert ( FString item data.push_back (listItem); element_count = int(count()); - VBar->setMaximum(element_count - height + 2); - VBar->setPageSize(element_count, height - 2); + VBar->setMaximum(element_count - getHeight() + 2); + VBar->setPageSize(element_count, getHeight() - 2); VBar->calculateSliderValues(); - if ( ! VBar->isVisible() && element_count >= height - 1 ) + if ( ! VBar->isVisible() && element_count >= getHeight() - 1 ) VBar->setVisible(); } @@ -1737,16 +1733,16 @@ void FListBox::remove (int item) maxLineWidth = len; } - HBar->setMaximum(maxLineWidth - width + nf_offset + 4); - HBar->setPageSize(maxLineWidth, width - nf_offset - 4); + HBar->setMaximum(maxLineWidth - getWidth() + nf_offset + 4); + HBar->setPageSize(maxLineWidth, getWidth() - nf_offset - 4); - if ( HBar->isVisible() && maxLineWidth < width - nf_offset - 3 ) + if ( HBar->isVisible() && maxLineWidth < getWidth() - nf_offset - 3 ) HBar->hide(); - VBar->setMaximum(element_count - height + 2); - VBar->setPageSize(element_count, height - 2); + VBar->setMaximum(element_count - getHeight() + 2); + VBar->setPageSize(element_count, getHeight() - 2); - if ( VBar->isVisible() && element_count < height - 1 ) + if ( VBar->isVisible() && element_count < getHeight() - 1 ) VBar->hide(); if ( current >= item && current > 1 ) @@ -1755,8 +1751,8 @@ void FListBox::remove (int item) if ( current > element_count ) current = element_count; - if ( yoffset > element_count - height + 2 ) - yoffset = element_count - height + 2; + if ( yoffset > element_count - getHeight() + 2 ) + yoffset = element_count - getHeight() + 2; if ( yoffset < 0 ) yoffset = 0; @@ -1787,14 +1783,18 @@ void FListBox::clear() // clear list from screen setColor (wc.list_fg, wc.list_bg); - size = width - 2; + size = getWidth() - 2; + + if ( size < 0 ) + return; + blank = new char[size+1]; memset(blank, ' ', uLong(size)); blank[size] = '\0'; - for (int y=0; y < height-2; y++) + for (int y=0; y < getHeight()-2; y++) { - gotoxy (xpos+xmin, ypos+ymin+y); + printPos (2, 2 + y); print (blank); } diff --git a/src/flistbox.h b/src/flistbox.h index 0e7abf2b..8cbff003 100644 --- a/src/flistbox.h +++ b/src/flistbox.h @@ -43,6 +43,7 @@ class FListBoxItem FString text; fc::brackets_type brackets; bool selected; + public: FListBoxItem (); explicit FListBoxItem (FString&); @@ -50,10 +51,12 @@ class FListBoxItem explicit FListBoxItem (const char*); virtual ~FListBoxItem(); virtual FString getText() const; + protected: void setText (FString&); void setText (const std::string&); void setText (const char*); + private: friend class FListBox; }; diff --git a/src/fmenu.cpp b/src/fmenu.cpp index af25b8b7..24bbbfd2 100644 --- a/src/fmenu.cpp +++ b/src/fmenu.cpp @@ -78,8 +78,8 @@ FMenu::~FMenu() if ( ! fapp->isQuit() ) { - const FRect& geometry = getGeometryGlobalShadow(); - restoreVTerm (geometry); + const FRect& t_geometry = getTermGeometryWithShadow(); + restoreVTerm (t_geometry); } if ( vwin != 0 ) @@ -99,30 +99,20 @@ 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; - client_xmin = 1; - client_ymin = 1; - client_xmax = width; - client_ymax = height; - top_padding = 1; - left_padding = 1; - bottom_padding = 1; - right_padding = 1; + setTopPadding(1); + setLeftPadding(1); + setBottomPadding(1); + setRightPadding(1); createArea (vwin); + setMenuWidget(); setGeometry (1, 1, 10, 2, false); // initialize geometry values setTransparentShadow(); - menu_object = true; + setMenuWidget(); addWindow(this); hide(); - foregroundColor = wc.menu_active_fg; - backgroundColor = wc.menu_active_bg; + setForegroundColor (wc.menu_active_fg); + setBackgroundColor (wc.menu_active_bg); if ( item ) item->setMenu(this); @@ -185,10 +175,10 @@ void FMenu::menu_dimension() ++iter; } - adjust_X = adjustX(xpos); + adjust_X = adjustX(getX()); // set widget geometry - setGeometry (adjust_X, ypos, int(maxItemWidth + 2), int(count() + 2)); + setGeometry (adjust_X, getY(), int(maxItemWidth + 2), int(count() + 2)); // set geometry of all items iter = itemlist.begin(); @@ -201,8 +191,8 @@ void FMenu::menu_dimension() if ( (*iter)->hasMenu() ) { - int menu_X = getGlobalX() + int(maxItemWidth) + 1; - int menu_Y = (*iter)->getGlobalY() - 2; + int menu_X = getTermX() + int(maxItemWidth) + 1; + int menu_Y = (*iter)->getTermY() - 2; // set sub-menu position (*iter)->getMenu()->setPos (menu_X, menu_Y, false); } @@ -226,9 +216,9 @@ void FMenu::adjustItems() int menu_X, menu_Y; FMenu* menu = (*iter)->getMenu(); - menu_X = getGlobalX() + int(maxItemWidth) + 1; + menu_X = getTermX() + int(maxItemWidth) + 1; menu_X = menu->adjustX(menu_X); - menu_Y = (*iter)->getGlobalY() - 2; + menu_Y = (*iter)->getTermY() - 2; // set sub-menu position menu->move (menu_X, menu_Y); @@ -260,7 +250,7 @@ int FMenu::adjustX (int x_pos) //---------------------------------------------------------------------- bool FMenu::isWindowsMenu (FWidget* w) const { - return w->isDialog(); + return w->isDialogWidget(); } //---------------------------------------------------------------------- @@ -364,33 +354,33 @@ void FMenu::hideSuperMenus() } //---------------------------------------------------------------------- -bool FMenu::containsMenuStructure (int x, int y) const +bool FMenu::containsMenuStructure (int x, int y) { // Check mouse click position for item, menu and all sub menus FMenuItem* si = getSelectedItem(); - if ( getGeometryGlobal().contains(x,y) ) + if ( getTermGeometry().contains(x,y) ) return true; else if ( si && si->hasMenu() && open_sub_menu ) return si->getMenu()->containsMenuStructure(x,y); - else if ( item && item->getGeometryGlobal().contains(x,y) ) + else if ( item && item->getTermGeometry().contains(x,y) ) return true; else return false; } //---------------------------------------------------------------------- -FMenu* FMenu::superMenuAt (int x, int y) const +FMenu* FMenu::superMenuAt (int x, int y) { // Check mouse click position for super menu - if ( getGeometryGlobal().contains(x,y) ) + if ( getTermGeometry().contains(x,y) ) return 0; FWidget* super = getSuperMenu(); if ( super && isMenu(super) ) { - if ( super->getGeometryGlobal().contains(x,y) ) + if ( super->getTermGeometry().contains(x,y) ) return dynamic_cast(super); else { @@ -620,7 +610,7 @@ void FMenu::draw() area = area_widget->getVWin(); if ( area ) - putArea (xpos+xmin-1, ypos+ymin-1, area); + putArea (getTermX(), getTermY(), area); } } else @@ -630,15 +620,14 @@ void FMenu::draw() //---------------------------------------------------------------------- void FMenu::drawBorder() { - int x1, x2, y1, y2; - x1 = xpos+xmin-1; - x2 = xpos+xmin-2+width; - y1 = ypos+ymin-1; - y2 = ypos+ymin-2+height; + int x1 = 1; + int x2 = 1 + getWidth() - 1; + int y1 = 1; + int y2 = 1 + getHeight() - 1; if ( isNewFont() ) { - gotoxy (x1, y1); + printPos (x1, y1); print (fc::NF_border_corner_upper_left); // ⎡ for (int x=x1+1; x < x2; x++) @@ -648,35 +637,35 @@ void FMenu::drawBorder() for (int y=y1+1; y <= y2; y++) { - gotoxy (x1, y); + printPos (x1, y); // border left ⎸ print (fc::NF_border_line_left); - gotoxy (x2, y); + printPos (x2, y); // border right⎹ print (fc::NF_rev_border_line_right); } - gotoxy (x1, y2); + printPos (x1, y2); // lower left corner border ⎣ print (fc::NF_border_corner_lower_left); - for (int x=1; x < width-1; x++) // low line _ + for (int x=1; x < getWidth()-1; x++) // low line _ print (fc::NF_border_line_bottom); - gotoxy (x2, y2); + printPos (x2, y2); // lower right corner border ⎦ print (fc::NF_rev_border_corner_lower_right); } else { - gotoxy (x1, y1); + printPos (x1, y1); print (fc::BoxDrawingsDownAndRight); // ┌ for (int x=x1+1; x < x2; x++) print (fc::BoxDrawingsHorizontal); // ─ print (fc::BoxDrawingsDownAndLeft); // ┐ - gotoxy (x1, y2); + printPos (x1, y2); print (fc::BoxDrawingsUpAndRight); // └ for (int x=x1+1; x < x2; x++) @@ -686,9 +675,9 @@ void FMenu::drawBorder() for (int y=y1+1; y < y2; y++) { - gotoxy (x1, y); + printPos (x1, y); print (fc::BoxDrawingsVertical); // │ - gotoxy (x2, y); + printPos (x2, y); print (fc::BoxDrawingsVertical); // │ } } @@ -740,16 +729,16 @@ void FMenu::drawItems() { if ( is_selected ) { - foregroundColor = wc.menu_active_focus_fg; - backgroundColor = wc.menu_active_focus_bg; + setForegroundColor (wc.menu_active_focus_fg); + setBackgroundColor (wc.menu_active_focus_bg); if ( isMonochron() ) setReverse(false); } else { - foregroundColor = wc.menu_active_fg; - backgroundColor = wc.menu_active_bg; + setForegroundColor (wc.menu_active_fg); + setBackgroundColor (wc.menu_active_bg); if ( isMonochron() ) setReverse(true); @@ -757,15 +746,15 @@ void FMenu::drawItems() } else { - foregroundColor = wc.menu_inactive_fg; - backgroundColor = wc.menu_inactive_bg; + setForegroundColor (wc.menu_inactive_fg); + setBackgroundColor (wc.menu_inactive_bg); if ( isMonochron() ) setReverse(true); } - gotoxy (xpos+xmin, ypos+ymin+y); - setColor (foregroundColor, backgroundColor); + printPos (2, 2 + y); + setColor(); if ( has_checkable_items ) { @@ -792,14 +781,14 @@ void FMenu::drawItems() } else { - setColor (wc.menu_inactive_fg, backgroundColor); + setColor (wc.menu_inactive_fg, getBackgroundColor()); if ( getEncoding() == "ASCII" ) print ('-'); else print (fc::SmallBullet); - setColor (foregroundColor, backgroundColor); + setColor(); } } else @@ -818,14 +807,12 @@ void FMenu::drawItems() if ( hotkeypos == -1 ) { if ( is_selected ) - setCursorPos ( xpos+xmin+1 - , ypos+ymin+y ); // first character + setCursorPos (1, 2 + y); // first character } else { if ( is_selected ) - setCursorPos ( xpos+xmin+1+hotkeypos - , ypos+ymin+y ); // hotkey + setCursorPos (1 + hotkeypos, 2 + y); // hotkey txt_length--; to_char--; @@ -856,7 +843,7 @@ void FMenu::drawItems() if ( ! is_noUnderline ) unsetUnderline(); - setColor (foregroundColor, backgroundColor); + setColor(); } else print (item_text[z]); @@ -911,7 +898,7 @@ void FMenu::drawItems() //---------------------------------------------------------------------- inline void FMenu::drawSeparator(int y) { - gotoxy (xpos+xmin-1, ypos+ymin+y); + printPos (1, 2 + y); setColor (wc.menu_active_fg, wc.menu_active_bg); if ( isMonochron() ) @@ -920,14 +907,14 @@ inline void FMenu::drawSeparator(int y) if ( isNewFont() ) { print (fc::NF_border_line_vertical_right); - FString line(width-2, wchar_t(fc::BoxDrawingsHorizontal)); + FString line(getWidth()-2, wchar_t(fc::BoxDrawingsHorizontal)); print (line); print (fc::NF_rev_border_line_vertical_left); } else { print (fc::BoxDrawingsVerticalAndRight); - FString line(width-2, wchar_t(fc::BoxDrawingsHorizontal)); + FString line(getWidth()-2, wchar_t(fc::BoxDrawingsHorizontal)); print (line); print (fc::BoxDrawingsVerticalAndLeft); } @@ -1323,19 +1310,19 @@ void FMenu::onMouseMove (FMouseEvent* ev) mouse_pos = ev->getPos(); mouse_pos -= FPoint(getRightPadding(),getTopPadding()); - if ( getGeometryGlobal().contains(ev->getGlobalPos()) ) + if ( getTermGeometry().contains(ev->getTermPos()) ) mouse_over_menu = true; if ( open_sub_menu ) { - const FRect& submenu_geometry = open_sub_menu->getGeometryGlobal(); - if ( submenu_geometry.contains(ev->getGlobalPos()) ) + const FRect& submenu_geometry = open_sub_menu->getTermGeometry(); + if ( submenu_geometry.contains(ev->getTermPos()) ) mouse_over_submenu = true; } if ( isSubMenu() ) { - smenu = superMenuAt (ev->getGlobalPos()); + smenu = superMenuAt (ev->getTermPos()); if ( smenu ) mouse_over_supermenu = true; @@ -1343,7 +1330,7 @@ void FMenu::onMouseMove (FMouseEvent* ev) if ( menuBar() && isMenuBar(menuBar()) - && menuBar()->getGeometryGlobal().contains(ev->getGlobalPos()) ) + && menuBar()->getTermGeometry().contains(ev->getTermPos()) ) { mouse_over_menubar = true; } @@ -1416,10 +1403,10 @@ void FMenu::onMouseMove (FMouseEvent* ev) if ( mouse_over_submenu ) { // Mouse event handover to sub-menu - const FPoint& g = ev->getGlobalPos(); - const FPoint& p = open_sub_menu->globalToLocalPos(g); + const FPoint& t = ev->getTermPos(); + const FPoint& p = open_sub_menu->termToWidgetPos(t); int b = ev->getButton(); - FMouseEvent* _ev = new FMouseEvent (fc::MouseMove_Event, p, g, b); + FMouseEvent* _ev = new FMouseEvent (fc::MouseMove_Event, p, t, b); open_sub_menu->mouse_down = true; setClickedWidget(open_sub_menu); open_sub_menu->onMouseMove(_ev); @@ -1429,10 +1416,10 @@ void FMenu::onMouseMove (FMouseEvent* ev) else if ( ! mouse_over_menu && mouse_over_supermenu ) { // Mouse event handover to super-menu - const FPoint& g = ev->getGlobalPos(); - const FPoint& p = smenu->globalToLocalPos(g); + const FPoint& t = ev->getTermPos(); + const FPoint& p = smenu->termToWidgetPos(t); int b = ev->getButton(); - FMouseEvent* _ev = new FMouseEvent (fc::MouseMove_Event, p, g, b); + FMouseEvent* _ev = new FMouseEvent (fc::MouseMove_Event, p, t, b); smenu->mouse_down = true; setClickedWidget(smenu); smenu->onMouseMove(_ev); @@ -1443,10 +1430,10 @@ void FMenu::onMouseMove (FMouseEvent* ev) { // Mouse event handover to the menu bar FWidget* menubar = menuBar(); - const FPoint& g = ev->getGlobalPos(); - const FPoint& p = menubar->globalToLocalPos(g); + const FPoint& t = ev->getTermPos(); + const FPoint& p = menubar->termToWidgetPos(t); int b = ev->getButton(); - FMouseEvent* _ev = new FMouseEvent (fc::MouseMove_Event, p, g, b); + FMouseEvent* _ev = new FMouseEvent (fc::MouseMove_Event, p, t, b); setClickedWidget(menubar); FMenuBar* mbar = reinterpret_cast(menubar); mbar->mouse_down = true; @@ -1534,7 +1521,8 @@ void FMenu::hide() if ( isVisible() ) { FWindow::hide(); - restoreVTerm (getGeometryGlobalShadow()); + const FRect& t_geometry = getTermGeometryWithShadow(); + restoreVTerm (t_geometry); updateTerminal(); flush_out(); @@ -1555,11 +1543,11 @@ void FMenu::hide() //---------------------------------------------------------------------- void FMenu::setGeometry (int xx, int yy, int ww, int hh, bool adjust) { - int old_width = width; - int old_height = height; + int old_width = getWidth(); + int old_height = getHeight(); FWidget::setGeometry (xx, yy, ww, hh, adjust); - if ( vwin && (width != old_width || height != old_height) ) + if ( vwin && (getWidth() != old_width || getHeight() != old_height) ) resizeArea (vwin); } @@ -1603,6 +1591,20 @@ void FMenu::cb_menuitem_toggled (FWidget* widget, void*) } } +//---------------------------------------------------------------------- +bool FMenu::setMenuWidget (bool on) +{ + if ( isMenuWidget() == on ) + return true; + + if ( on ) + flags |= fc::menu_widget; + else + flags &= ~fc::menu_widget; + + return on; +} + //---------------------------------------------------------------------- bool FMenu::setTransparentShadow (bool on) { @@ -1610,17 +1612,13 @@ bool FMenu::setTransparentShadow (bool on) { flags |= fc::shadow; flags |= fc::trans_shadow; - shadow.setPoint(2,1); - adjustWidgetSizeShadow = getGeometry() + getShadow(); - adjustWidgetSizeGlobalShadow = getGeometryGlobal() + getShadow(); + setShadowSize (2,1); } else { flags &= ~fc::shadow; flags &= ~fc::trans_shadow; - shadow.setPoint(0,0); - adjustWidgetSizeShadow = getGeometry() + getShadow(); - adjustWidgetSizeGlobalShadow = getGeometryGlobal() + getShadow(); + setShadowSize (0,0); } resizeArea (vwin); diff --git a/src/fmenu.h b/src/fmenu.h index cf1057b0..b30586bb 100644 --- a/src/fmenu.h +++ b/src/fmenu.h @@ -46,45 +46,47 @@ class FMenu : public FWindow, public FMenuList { private: - FMenuItem* item; - FWidget* super_menu; - FMenu* open_sub_menu; - uInt maxItemWidth; - bool mouse_down; - bool has_checkable_items; + FMenuItem* item; + FWidget* super_menu; + FMenu* open_sub_menu; + uInt maxItemWidth; + bool mouse_down; + bool has_checkable_items; private: FMenu (const FMenu&); FMenu& operator = (const FMenu&); - void init(FWidget*); - void menu_dimension(); - void adjustItems(); - int adjustX(int); - bool isWindowsMenu (FWidget*) const; - bool isMenuBar (FWidget*) const; - bool isMenu (FWidget*) const; - bool isRadioMenuItem (FWidget*) const; - FWidget* getSuperMenu() const; - void setSuperMenu (FWidget*); - bool isSubMenu() const; - void openSubMenu (FMenu*); - void hideSubMenus(); - void hideSuperMenus(); - bool containsMenuStructure (const FPoint&) const; - bool containsMenuStructure (int, int) const; - FMenu* superMenuAt (const FPoint&) const; - FMenu* superMenuAt (int, int) const; - bool selectNextItem(); - bool selectPrevItem(); - void keypressMenuBar (FKeyEvent*&); - bool hotkeyMenu (FKeyEvent*&); - int getHotkeyPos (wchar_t*&, wchar_t*&, uInt); - void draw(); - void drawBorder(); - void drawMenuShadow(); - void drawItems(); - void drawSeparator(int); - void processActivate(); + void init(FWidget*); + void menu_dimension(); + void adjustItems(); + int adjustX(int); + bool isWindowsMenu (FWidget*) const; + bool isMenuBar (FWidget*) const; + bool isMenu (FWidget*) const; + bool isRadioMenuItem (FWidget*) const; + FWidget* getSuperMenu() const; + void setSuperMenu (FWidget*); + bool isSubMenu() const; + void openSubMenu (FMenu*); + void hideSubMenus(); + void hideSuperMenus(); + bool containsMenuStructure (const FPoint&); + bool containsMenuStructure (int, int); + FMenu* superMenuAt (const FPoint&); + FMenu* superMenuAt (int, int); + bool selectNextItem(); + bool selectPrevItem(); + void keypressMenuBar (FKeyEvent*&); + bool hotkeyMenu (FKeyEvent*&); + int getHotkeyPos (wchar_t*&, wchar_t*&, uInt); + void draw(); + // make every drawBorder from FWidget available + using FWidget::drawBorder; + virtual void drawBorder(); + void drawMenuShadow(); + void drawItems(); + void drawSeparator(int); + void processActivate(); public: explicit FMenu (FWidget* = 0); // constructor @@ -115,6 +117,9 @@ class FMenu : public FWindow, public FMenuList void setSelected(); void unsetSelected(); bool isSelected() const; + bool setMenuWidget (bool); + bool setMenuWidget(); + bool unsetMenuWidget(); bool hasHotkey() const; void setMenu (FMenu*); bool hasMenu() const; @@ -148,11 +153,11 @@ inline void FMenu::setSuperMenu (FWidget* smenu) { super_menu = smenu; } //---------------------------------------------------------------------- -inline bool FMenu::containsMenuStructure (const FPoint& p) const +inline bool FMenu::containsMenuStructure (const FPoint& p) { return containsMenuStructure (p.getX(), p.getY()); } //---------------------------------------------------------------------- -inline FMenu* FMenu::superMenuAt (const FPoint& p) const +inline FMenu* FMenu::superMenuAt (const FPoint& p) { return superMenuAt (p.getX(), p.getY()); } //---------------------------------------------------------------------- @@ -202,6 +207,13 @@ inline void FMenu::unsetSelected() //---------------------------------------------------------------------- inline bool FMenu::isSelected() const { return item->isSelected(); } +//---------------------------------------------------------------------- +inline bool FMenu::setMenuWidget() +{ return setMenuWidget(true); } + +//---------------------------------------------------------------------- +inline bool FMenu::unsetMenuWidget() +{ return setMenuWidget(false); } //---------------------------------------------------------------------- inline bool FMenu::hasHotkey() const diff --git a/src/fmenubar.cpp b/src/fmenubar.cpp index 2ec2d05c..9e67e614 100644 --- a/src/fmenubar.cpp +++ b/src/fmenubar.cpp @@ -41,14 +41,13 @@ FMenuBar::~FMenuBar() //---------------------------------------------------------------------- void FMenuBar::init() { - xmin = ymin = 1; - xpos = 1; - ypos = 1; + FWidget* r = getRootWidget(); + int w = r->getWidth(); + // initialize geometry values + setGeometry (1, 1, w, 1, false); createArea (vmenubar); vmenubar->visible = true; - ignore_padding = true; - // initialize geometry values - setGeometry (1, 1, getColumnNumber(), 1, false); + ignorePadding(); setMenuBar(this); if ( getRootWidget() ) @@ -56,8 +55,8 @@ void FMenuBar::init() addAccelerator (fc::Fkey_f10); addAccelerator (fc::Fckey_space); - foregroundColor = wc.menu_active_fg; - backgroundColor = wc.menu_active_bg; + setForegroundColor (wc.menu_active_fg); + setBackgroundColor (wc.menu_active_bg); unsetFocusable(); } @@ -312,9 +311,6 @@ int FMenuBar::getHotkeyPos (wchar_t*& src, wchar_t*& dest, uInt length) //---------------------------------------------------------------------- void FMenuBar::draw() { - xmin = ymin = 1; - height = 1; - xpos = 1; drawItems(); } @@ -325,14 +321,12 @@ void FMenuBar::drawItems() int screenWidth; int x = 1; screenWidth = getColumnNumber(); - width = screenWidth; - ypos = 1; if ( itemlist.empty() ) return; updateVTerm(false); - gotoxy (1,1); + printPos (1,1); if ( isMonochron() ) setReverse(true); @@ -361,22 +355,23 @@ void FMenuBar::drawItems() { if ( isMonochron() ) setReverse(false); - foregroundColor = wc.menu_active_focus_fg; - backgroundColor = wc.menu_active_focus_bg; + + setForegroundColor (wc.menu_active_focus_fg); + setBackgroundColor (wc.menu_active_focus_bg); } else { - foregroundColor = wc.menu_active_fg; - backgroundColor = wc.menu_active_bg; + setForegroundColor (wc.menu_active_fg); + setBackgroundColor (wc.menu_active_bg); } } else { - foregroundColor = wc.menu_inactive_fg; - backgroundColor = wc.menu_inactive_bg; + setForegroundColor (wc.menu_inactive_fg); + setBackgroundColor (wc.menu_inactive_bg); } - setColor (foregroundColor, backgroundColor); + setColor(); if ( x < screenWidth ) { @@ -431,7 +426,7 @@ void FMenuBar::drawItems() if ( ! is_noUnderline ) unsetUnderline(); - setColor (foregroundColor, backgroundColor); + setColor(); } else print (vmenubar, item_text[z]); @@ -441,12 +436,12 @@ void FMenuBar::drawItems() { if ( startpos < screenWidth ) { - gotoxy(screenWidth-1,1); + printPos (screenWidth - 1, 1); print (vmenubar, ".."); } else if ( startpos-1 <= screenWidth ) { - gotoxy(screenWidth,1); + printPos (screenWidth, 1); print (vmenubar, ' '); } } @@ -646,7 +641,7 @@ void FMenuBar::onMouseDown (FMouseEvent* ev) (*iter)->setSelected(); (*iter)->setFocus(); - if ( focused_widget && ! focused_widget->isWindow() ) + if ( focused_widget && ! focused_widget->isWindowWidget() ) focused_widget->redraw(); (*iter)->openMenu(); @@ -800,7 +795,7 @@ void FMenuBar::onMouseMove (FMouseEvent* ev) mouse_x = ev->getX(); mouse_y = ev->getY(); - if ( getGeometryGlobal().contains(ev->getGlobalPos()) ) + if ( getTermGeometry().contains(ev->getTermPos()) ) mouse_over_menubar = true; while ( iter != end ) @@ -822,7 +817,7 @@ void FMenuBar::onMouseMove (FMouseEvent* ev) (*iter)->setSelected(); (*iter)->setFocus(); - if ( focused_widget && ! focused_widget->isWindow() ) + if ( focused_widget && ! focused_widget->isWindowWidget() ) focused_widget->redraw(); (*iter)->openMenu(); @@ -863,16 +858,16 @@ void FMenuBar::onMouseMove (FMouseEvent* ev) { // Mouse event handover to the menu FMenu* menu = getSelectedItem()->getMenu(); - const FRect& menu_geometry = menu->getGeometryGlobal(); + const FRect& menu_geometry = menu->getTermGeometry(); if ( menu->count() > 0 - && menu_geometry.contains(ev->getGlobalPos()) ) + && menu_geometry.contains(ev->getTermPos()) ) { FMouseEvent* _ev; - const FPoint& g = ev->getGlobalPos(); - const FPoint& p = menu->globalToLocalPos(g); + const FPoint& t = ev->getTermPos(); + const FPoint& p = menu->termToWidgetPos(t); int b = ev->getButton(); - _ev = new FMouseEvent (fc::MouseMove_Event, p, g, b); + _ev = new FMouseEvent (fc::MouseMove_Event, p, t, b); menu->mouse_down = true; setClickedWidget(menu); menu->onMouseMove(_ev); @@ -921,10 +916,14 @@ void FMenuBar::hide() bg = wc.term_bg; setColor (fg, bg); screenWidth = getColumnNumber(); + + if ( screenWidth < 0 ) + return; + blank = new char[screenWidth+1]; memset(blank, ' ', uLong(screenWidth)); blank[screenWidth] = '\0'; - gotoxy (1,1); + printPos (1,1); print (vmenubar, blank); delete[] blank; } @@ -939,25 +938,10 @@ void FMenuBar::resetMenu() //---------------------------------------------------------------------- void FMenuBar::adjustSize() { - xmin = ymin = 1; - height = 1; - xpos = 1; - width = getColumnNumber(); - ypos = 1; + setGeometry (1, 1, getColumnNumber(), 1, false); adjustItems(); } -//---------------------------------------------------------------------- -void FMenuBar::setGeometry (int xx, int yy, int ww, int hh, bool adjust) -{ - int old_width = width; - int old_height = height; - FWidget::setGeometry (xx, yy, ww, hh, adjust); - - if ( vmenubar && (width != old_width || height != old_height) ) - resizeArea (vmenubar); -} - //---------------------------------------------------------------------- void FMenuBar::cb_item_deactivated (FWidget* widget, void*) { diff --git a/src/fmenubar.h b/src/fmenubar.h index 04fc78be..e239da5a 100644 --- a/src/fmenubar.h +++ b/src/fmenubar.h @@ -76,9 +76,6 @@ class FMenuBar : public FWindow, public FMenuList void hide(); void resetMenu(); void adjustSize(); - // make every setGeometry from FWidget available - using FWidget::setGeometry; - void setGeometry (int, int, int, int, bool = true); void cb_item_deactivated (FWidget*, void*); private: diff --git a/src/fmenuitem.cpp b/src/fmenuitem.cpp index d23c3642..d3f39ad9 100644 --- a/src/fmenuitem.cpp +++ b/src/fmenuitem.cpp @@ -348,7 +348,7 @@ void FMenuItem::processClicked() //---------------------------------------------------------------------- bool FMenuItem::isWindowsMenu (FWidget* w) const { - return ( ! w ) ? false : w->isDialog(); + return ( ! w ) ? false : w->isDialogWidget(); } //---------------------------------------------------------------------- @@ -463,7 +463,7 @@ void FMenuItem::onMouseDoubleClick (FMouseEvent* ev) { if ( super_menu ) { - const FPoint& g = ev->getGlobalPos(); + const FPoint& t = ev->getTermPos(); int b = ev->getButton(); if ( isMenu(super_menu) ) @@ -472,8 +472,8 @@ void FMenuItem::onMouseDoubleClick (FMouseEvent* ev) if ( smenu ) { - const FPoint& p2 = smenu->globalToLocalPos(g); - FMouseEvent* _ev = new FMouseEvent (fc::MouseDoubleClick_Event, p2, g, b); + const FPoint& p2 = smenu->termToWidgetPos(t); + FMouseEvent* _ev = new FMouseEvent (fc::MouseDoubleClick_Event, p2, t, b); smenu->onMouseDoubleClick(_ev); delete _ev; } @@ -485,8 +485,8 @@ void FMenuItem::onMouseDoubleClick (FMouseEvent* ev) if ( mbar ) { - const FPoint& p2 = mbar->globalToLocalPos(g); - FMouseEvent* _ev = new FMouseEvent (fc::MouseDoubleClick_Event, p2, g, b); + const FPoint& p2 = mbar->termToWidgetPos(t); + FMouseEvent* _ev = new FMouseEvent (fc::MouseDoubleClick_Event, p2, t, b); mbar->onMouseDoubleClick(_ev); delete _ev; } @@ -498,8 +498,8 @@ void FMenuItem::onMouseDoubleClick (FMouseEvent* ev) if ( dgl ) { - const FPoint& p2 = dgl->globalToLocalPos(g); - FMouseEvent* _ev = new FMouseEvent (fc::MouseDoubleClick_Event, p2, g, b); + const FPoint& p2 = dgl->termToWidgetPos(t); + FMouseEvent* _ev = new FMouseEvent (fc::MouseDoubleClick_Event, p2, t, b); dgl->onMouseDoubleClick(_ev); delete _ev; } @@ -512,7 +512,7 @@ void FMenuItem::onMouseDown (FMouseEvent* ev) { if ( super_menu ) { - const FPoint& g = ev->getGlobalPos(); + const FPoint& t = ev->getTermPos(); int b = ev->getButton(); if ( isMenu(super_menu) ) @@ -521,8 +521,8 @@ void FMenuItem::onMouseDown (FMouseEvent* ev) if ( smenu ) { - const FPoint& p2 = smenu->globalToLocalPos(g); - FMouseEvent* _ev = new FMouseEvent (fc::MouseDown_Event, p2, g, b); + const FPoint& p2 = smenu->termToWidgetPos(t); + FMouseEvent* _ev = new FMouseEvent (fc::MouseDown_Event, p2, t, b); smenu->onMouseDown(_ev); delete _ev; } @@ -534,8 +534,8 @@ void FMenuItem::onMouseDown (FMouseEvent* ev) if ( mbar ) { - const FPoint& p2 = mbar->globalToLocalPos(g); - FMouseEvent* _ev = new FMouseEvent (fc::MouseDown_Event, p2, g, b); + const FPoint& p2 = mbar->termToWidgetPos(t); + FMouseEvent* _ev = new FMouseEvent (fc::MouseDown_Event, p2, t, b); mbar->onMouseDown(_ev); delete _ev; } @@ -547,8 +547,8 @@ void FMenuItem::onMouseDown (FMouseEvent* ev) if ( dgl ) { - const FPoint& p2 = dgl->globalToLocalPos(g); - FMouseEvent* _ev = new FMouseEvent (fc::MouseDown_Event, p2, g, b); + const FPoint& p2 = dgl->termToWidgetPos(t); + FMouseEvent* _ev = new FMouseEvent (fc::MouseDown_Event, p2, t, b); dgl->onMouseDown(_ev); delete _ev; } @@ -561,7 +561,7 @@ void FMenuItem::onMouseUp (FMouseEvent* ev) { if ( super_menu ) { - const FPoint& g = ev->getGlobalPos(); + const FPoint& t = ev->getTermPos(); int b = ev->getButton(); if ( isMenu(super_menu) ) @@ -570,8 +570,8 @@ void FMenuItem::onMouseUp (FMouseEvent* ev) if ( smenu ) { - const FPoint& p2 = smenu->globalToLocalPos(g); - FMouseEvent* _ev = new FMouseEvent (fc::MouseUp_Event, p2, g, b); + const FPoint& p2 = smenu->termToWidgetPos(t); + FMouseEvent* _ev = new FMouseEvent (fc::MouseUp_Event, p2, t, b); smenu->onMouseUp(_ev); delete _ev; } @@ -583,8 +583,8 @@ void FMenuItem::onMouseUp (FMouseEvent* ev) if ( mbar ) { - const FPoint& p2 = mbar->globalToLocalPos(g); - FMouseEvent* _ev = new FMouseEvent (fc::MouseUp_Event, p2, g, b); + const FPoint& p2 = mbar->termToWidgetPos(t); + FMouseEvent* _ev = new FMouseEvent (fc::MouseUp_Event, p2, t, b); mbar->onMouseUp(_ev); delete _ev; } @@ -596,8 +596,8 @@ void FMenuItem::onMouseUp (FMouseEvent* ev) if ( dgl ) { - const FPoint& p2 = dgl->globalToLocalPos(g); - FMouseEvent* _ev = new FMouseEvent (fc::MouseUp_Event, p2, g, b); + const FPoint& p2 = dgl->termToWidgetPos(t); + FMouseEvent* _ev = new FMouseEvent (fc::MouseUp_Event, p2, t, b); dgl->onMouseUp(_ev); delete _ev; } @@ -610,7 +610,7 @@ void FMenuItem::onMouseMove (FMouseEvent* ev) { if ( super_menu ) { - const FPoint& g = ev->getGlobalPos(); + const FPoint& t = ev->getTermPos(); int b = ev->getButton(); if ( isMenu(super_menu) ) @@ -619,8 +619,8 @@ void FMenuItem::onMouseMove (FMouseEvent* ev) if ( smenu ) { - const FPoint& p2 = smenu->globalToLocalPos(g); - FMouseEvent* _ev = new FMouseEvent (fc::MouseMove_Event, p2, g, b); + const FPoint& p2 = smenu->termToWidgetPos(t); + FMouseEvent* _ev = new FMouseEvent (fc::MouseMove_Event, p2, t, b); smenu->onMouseMove(_ev); delete _ev; } @@ -632,8 +632,8 @@ void FMenuItem::onMouseMove (FMouseEvent* ev) if ( mbar ) { - const FPoint& p2 = mbar->globalToLocalPos(g); - FMouseEvent* _ev = new FMouseEvent (fc::MouseMove_Event, p2, g, b); + const FPoint& p2 = mbar->termToWidgetPos(t); + FMouseEvent* _ev = new FMouseEvent (fc::MouseMove_Event, p2, t, b); mbar->onMouseMove(_ev); delete _ev; } @@ -645,8 +645,8 @@ void FMenuItem::onMouseMove (FMouseEvent* ev) if ( dgl ) { - const FPoint& p2 = dgl->globalToLocalPos(g); - FMouseEvent* _ev = new FMouseEvent (fc::MouseMove_Event, p2, g, b); + const FPoint& p2 = dgl->termToWidgetPos(t); + FMouseEvent* _ev = new FMouseEvent (fc::MouseMove_Event, p2, t, b); dgl->onMouseMove(_ev); delete _ev; } diff --git a/src/fmessagebox.cpp b/src/fmessagebox.cpp index f262dddd..8ad54bd5 100644 --- a/src/fmessagebox.cpp +++ b/src/fmessagebox.cpp @@ -126,7 +126,7 @@ void FMessageBox::init(int button0, int button1, int button2) button[0] = new FButton (this); button[0]->setText(button_text[button0]); - button[0]->setPos(3, height-4, false); + button[0]->setPos(3, getHeight()-4, false); button[0]->setWidth(1, false); button[0]->setHeight(1, false); button[0]->setFocus(); @@ -135,7 +135,7 @@ void FMessageBox::init(int button0, int button1, int button2) { button[1] = new FButton(this); button[1]->setText(button_text[button1]); - button[1]->setPos(17, height-4, false); + button[1]->setPos(17, getHeight()-4, false); button[1]->setWidth(0, false); button[1]->setHeight(1, false); } @@ -144,7 +144,7 @@ void FMessageBox::init(int button0, int button1, int button2) { button[2] = new FButton(this); button[2]->setText(button_text[button2]); - button[2]->setPos(32, height-4, false); + button[2]->setPos(32, getHeight()-4, false); button[2]->setWidth(0, false); button[2]->setHeight(1, false); } @@ -231,7 +231,7 @@ void FMessageBox::draw() int head_offset = 0; int center_x = 0; - int msg_x = int((width - int(maxLineWidth)) / 2); // center the whole block + int msg_x = int((getWidth() - int(maxLineWidth)) / 2); // center the whole block updateVTerm(false); if ( isMonochron() ) @@ -239,18 +239,18 @@ void FMessageBox::draw() if ( ! headline_text.isNull() ) { - setColor(emphasis_color, backgroundColor); + setColor(emphasis_color, getBackgroundColor()); uInt headline_length = headline_text.getLength(); if ( center_text ) // center one line center_x = int((maxLineWidth - headline_length) / 2); - gotoxy (xpos+xmin-1+msg_x+center_x, ypos+ymin+2); + printPos (1 + msg_x + center_x, 4); print (headline_text); head_offset = 2; } - setColor(foregroundColor, backgroundColor); + setColor(); for (int i=0; i < int(text_num_lines); i++) { @@ -259,7 +259,7 @@ void FMessageBox::draw() if ( center_text ) // center one line center_x = int((maxLineWidth - line_length) / 2); - gotoxy (xpos+xmin-1+msg_x+center_x, ypos+ymin+2+head_offset+i); + printPos (1 + msg_x + center_x, 4 + head_offset + i); print(text_components[i]); } @@ -314,16 +314,16 @@ void FMessageBox::adjustButtons() btn_width += button[n]->getWidth() + gap; } - if ( btn_width >= width-4 ) + if ( btn_width >= getWidth()-4 ) { int max_width; FWidget* root_widget = getRootWidget(); setWidth(btn_width + 5); max_width = ( root_widget ) ? root_widget->getClientWidth() : 80; - setX (int((max_width-width) / 2)); + setX (int((max_width-getWidth()) / 2)); } - int btn_x = int((width-btn_width) / 2); + int btn_x = int((getWidth()-btn_width) / 2); for (uInt n=0; n < numButtons; n++) { @@ -363,8 +363,8 @@ void FMessageBox::adjustSize() max_height = 24; } - X = 1 + int((max_width-width)/2); - Y = 1 + int((max_height-height)/3); + X = 1 + int((max_width-getWidth())/2); + Y = 1 + int((max_height-getHeight())/3); setPos(X, Y, false); FDialog::adjustSize(); } @@ -410,19 +410,19 @@ FMessageBox& FMessageBox::operator = (const FMessageBox& mbox) //---------------------------------------------------------------------- void FMessageBox::setHeadline (const FString& headline) { - int old_height = height; + int old_height = getHeight(); headline_text = headline; - setHeight(height + 2, true); + setHeight(getHeight() + 2, true); for (uInt n=0; n < numButtons; n++) - button[n]->setY(height-4, false); + button[n]->setY(getHeight()-4, false); uInt len = headline_text.getLength(); if ( len > maxLineWidth ) maxLineWidth = len; - if ( vwin && height != old_height ) + if ( vwin && getHeight() != old_height ) resizeArea (vwin); } @@ -445,13 +445,13 @@ void FMessageBox::setText (const FString& txt) { text = txt; msg_dimension(); - button[0]->setY(height-4, false); + button[0]->setY(getHeight()-4, false); if ( *button_digit[1] != 0 ) - button[1]->setY(height-4, false); + button[1]->setY(getHeight()-4, false); if ( *button_digit[2] != 0 ) - button[2]->setY(height-4, false); + button[2]->setY(getHeight()-4, false); adjustButtons(); } @@ -520,8 +520,8 @@ int FMessageBox::error ( FWidget* parent mbox->beep(); mbox->setHeadline("Warning:"); mbox->setCenterText(); - mbox->foregroundColor = mbox->wc.error_box_fg; - mbox->backgroundColor = mbox->wc.error_box_bg; + mbox->setForegroundColor(mbox->wc.error_box_fg); + mbox->setBackgroundColor(mbox->wc.error_box_bg); mbox->emphasis_color = mbox->wc.error_box_emphasis_fg; reply = mbox->exec(); delete mbox; diff --git a/src/fprogressbar.cpp b/src/fprogressbar.cpp index 449f552b..447d5922 100644 --- a/src/fprogressbar.cpp +++ b/src/fprogressbar.cpp @@ -12,7 +12,7 @@ FProgressbar::FProgressbar(FWidget* parent) : FWidget(parent) , percentage(-1) - , BarLength(width) + , BarLength(getWidth()) { unsetFocusable(); setShadow(); @@ -37,7 +37,7 @@ void FProgressbar::drawPercentage() if ( isMonochron() ) setReverse(true); - gotoxy (xpos+xmin+width-5, ypos+ymin-2); + printPos (getWidth() - 3, 0); if ( percentage < 0 || percentage > 100 ) print ("--- %"); @@ -53,7 +53,7 @@ void FProgressbar::drawBar() { int i = 1; float length = float(BarLength*percentage)/100; - gotoxy (xpos+xmin-1, ypos+ymin-1); + printPos (1,1); if ( isMonochron() ) { @@ -195,19 +195,23 @@ void FProgressbar::hide() setColor (fg, bg); s = hasShadow() ? 1 : 0; - size = width + s; + size = getWidth() + s; + + if ( size < 0 ) + return; + blank = new char[size+1]; memset(blank, ' ', uLong(size)); blank[size] = '\0'; - for (int y=0; y < height+s; y++) + for (int y=0; y < getHeight()+s; y++) { - gotoxy (xpos+xmin-1, ypos+ymin-1+y); + printPos (1, 1 + y); print (blank); } delete[] blank; - gotoxy (xpos+xmin+width-5, ypos+ymin-2); + printPos (getWidth() - 4, 0); print (" "); // hide percentage } diff --git a/src/fradiobutton.cpp b/src/fradiobutton.cpp index 4424ef12..c2b76180 100644 --- a/src/fradiobutton.cpp +++ b/src/fradiobutton.cpp @@ -54,8 +54,8 @@ void FRadioButton::drawRadioButton() if ( ! isVisible() ) return; - gotoxy (xpos+xmin-1, ypos+ymin-1); - setColor (foregroundColor, backgroundColor); + printPos (1,1); + setColor(); if ( isMonochron() ) { diff --git a/src/frect.cpp b/src/frect.cpp index ec6fc132..39b7b552 100644 --- a/src/frect.cpp +++ b/src/frect.cpp @@ -116,6 +116,21 @@ void FRect::setRect (int x, int y, int width, int height) Y2 = short(y+height-1); } +//---------------------------------------------------------------------- +void FRect::setCoordinates (const FPoint& p1, const FPoint& p2) +{ + setCoordinates (p1.getX(), p1.getY(), p2.getX(), p2.getY()); +} + +//---------------------------------------------------------------------- +void FRect::setCoordinates (int x1, int y1, int x2, int y2) +{ + X1 = short(x1); + Y1 = short(y1); + X2 = short(x2); + Y2 = short(y2); +} + //---------------------------------------------------------------------- void FRect::move (int dx, int dy) { @@ -174,6 +189,16 @@ FRect FRect::intersect (const FRect& r) const return new_rect; } +//---------------------------------------------------------------------- +FRect& FRect::operator = (const FRect& r) +{ + X1 = short(r.getX1()); + Y1 = short(r.getY1()); + X2 = short(r.getX2()); + Y2 = short(r.getY2()); + return *this; +} + //---------------------------------------------------------------------- FRect operator + (const FRect& r, const FPoint& p) { diff --git a/src/frect.h b/src/frect.h index f64b5418..3589c8f1 100644 --- a/src/frect.h +++ b/src/frect.h @@ -37,37 +37,45 @@ class FRect virtual ~FRect(); // destructor virtual const char* getClassName(); - bool isNull() const; - int getX1() const; - int getY1() const; - int getX2() const; - int getY2() const; - int getX() const; - int getY() const; - FPoint getPos() const; - int getWidth() const; - int getHeight() const; + bool isNull() const; + int getX1() const; + int getY1() const; + int getX2() const; + int getY2() const; + int getX() const; + int getY() const; + FPoint getPos() const; + int getWidth() const; + int getHeight() const; - void setX1 (int); - void setY1 (int); - void setX2 (int); - void setY2 (int); - void setX (int); - void setY (int); - void setPos (int, int); - void setPos (const FPoint&); - void setWidth (int); - void setHeight (int); - void setRect (const FRect&); - void setRect (int, int, int, int); + short& x1_ref(); + short& y1_ref(); + short& x2_ref(); + short& y2_ref(); + void setX1 (int); + void setY1 (int); + void setX2 (int); + void setY2 (int); + void setX (int); + void setY (int); + void setPos (int, int); + void setPos (const FPoint&); + void setWidth (int); + void setHeight (int); + void setRect (const FRect&); + void setRect (int, int, int, int); + void setCoordinates (const FPoint&, const FPoint&); + void setCoordinates (int, int, int, int); - void move (int, int); - void move (const FPoint&); - bool contains (int, int) const; - bool contains (const FPoint&) const; - bool contains (const FRect&) const; - bool overlap (const FRect&) const; - FRect intersect (const FRect&) const; + void move (int, int); + void move (const FPoint&); + bool contains (int, int) const; + bool contains (const FPoint&) const; + bool contains (const FRect&) const; + bool overlap (const FRect&) const; + FRect intersect (const FRect&) const; + + FRect& operator = (const FRect&); friend FRect operator + (const FRect&, const FPoint&); friend FRect operator - (const FRect&, const FPoint&); @@ -90,8 +98,8 @@ inline FRect::FRect() inline FRect::FRect (int x, int y, int width, int height) : X1(short(x)) , Y1(short(y)) - , X2(short(x+width-1)) - , Y2(short(y+height-1)) + , X2(short(x + width - 1)) + , Y2(short(y + height - 1)) { } //---------------------------------------------------------------------- @@ -134,4 +142,20 @@ inline int FRect::getWidth() const inline int FRect::getHeight() const { return Y2 - Y1 + 1; } +//---------------------------------------------------------------------- +inline short& FRect::x1_ref() +{ return X1; } + +//---------------------------------------------------------------------- +inline short& FRect::y1_ref() +{ return Y1; } + +//---------------------------------------------------------------------- +inline short& FRect::x2_ref() +{ return X2; } + +//---------------------------------------------------------------------- +inline short& FRect::y2_ref() +{ return Y2; } + #endif // _FRECT_H diff --git a/src/fscrollbar.cpp b/src/fscrollbar.cpp index 90d354ed..ac117217 100644 --- a/src/fscrollbar.cpp +++ b/src/fscrollbar.cpp @@ -31,8 +31,7 @@ FScrollbar::FScrollbar(FWidget* parent) , max_color(getMaxColor()) { // The default scrollbar orientation is vertical - width = 1; - height = length; + setGeometry(1, 1, 1, length, false); init(); } @@ -72,9 +71,9 @@ FScrollbar::~FScrollbar() //---------------------------------------------------------------------- void FScrollbar::init() { - setGeometry(1, 1, width, height); - ignore_padding = true; unsetFocusable(); + ignorePadding(); + setGeometry(1, 1, getWidth(), getHeight()); } //---------------------------------------------------------------------- @@ -102,11 +101,11 @@ int FScrollbar::getClickedScrollType (int x, int y) { stype = FScrollbar::scrollPageBackward; // before slider } - else if ( y > SliderPos+SliderLength+1 && y < height ) + else if ( y > SliderPos+SliderLength+1 && y < getHeight() ) { stype = FScrollbar::scrollPageForward; // after slider } - else if ( y == height ) + else if ( y == getHeight() ) { stype = FScrollbar::scrollStepForward; // increment button } @@ -125,11 +124,11 @@ int FScrollbar::getClickedScrollType (int x, int y) { stype = FScrollbar::scrollPageBackward; // before slider } - else if ( x > SliderPos+SliderLength+2 && x < width-1 ) + else if ( x > SliderPos+SliderLength+2 && x < getWidth()-1 ) { stype = FScrollbar::scrollPageForward; // after slider } - else if ( x == width-1 || x == width ) + else if ( x == getWidth()-1 || x == getWidth() ) { stype = FScrollbar::scrollStepForward; // increment button } @@ -146,11 +145,11 @@ int FScrollbar::getClickedScrollType (int x, int y) { stype = FScrollbar::scrollPageBackward; // before slider } - else if ( x > SliderPos+SliderLength+1 && x < width ) + else if ( x > SliderPos+SliderLength+1 && x < getWidth() ) { stype = FScrollbar::scrollPageForward; // after slider } - else if ( x == width ) + else if ( x == getWidth() ) { stype = FScrollbar::scrollStepForward; // increment button } @@ -169,7 +168,7 @@ void FScrollbar::processMiddleButton (int x, int y) if ( bar_orientation == fc::vertical ) { - if ( y >1 && y < height ) + if ( y >1 && y < getHeight() ) { new_val = int( round ( float(max-min) * (y-2.0-(SliderLength/2)) / float(BarLength-SliderLength) ) ); @@ -181,7 +180,7 @@ void FScrollbar::processMiddleButton (int x, int y) { int nf = isNewFont() ? 1 : 0; - if ( x > 1+nf && x < width-nf ) + if ( x > 1+nf && x < getWidth()-nf ) { new_val = int( round ( float(max-min) * (x-2.0-nf-(SliderLength/2)) / float(BarLength-SliderLength) ) ); @@ -343,8 +342,8 @@ void FScrollbar::onMouseMove (FMouseEvent* ev) } } - if ( mouse_x < 1 || mouse_x > width - || mouse_y < 1 || mouse_y > height ) + if ( mouse_x < 1 || mouse_x > getWidth() + || mouse_y < 1 || mouse_y > getHeight() ) { delOwnTimer(); } @@ -514,17 +513,17 @@ void FScrollbar::calculateSliderValues() void FScrollbar::setOrientation (int o) { int nf = 0; - length = (height > width) ? height : width; + length = (getHeight() > getWidth()) ? getHeight() : getWidth(); if ( o == fc::vertical && bar_orientation == fc::horizontal ) { - width = 1; - height = length; + setWidth(1); + setHeight(length); } else if ( o == fc::horizontal && bar_orientation == fc::vertical ) { - height = 1; - width = length; + setWidth(length); + setHeight(1); if ( isNewFont() ) nf = 2; @@ -543,17 +542,18 @@ void FScrollbar::setGeometry (int x, int y, int w, int h, bool adjust) if ( bar_orientation == fc::vertical ) { - width = isNewFont() ? 2 : 1; - height = length; + setWidth(isNewFont() ? 2 : 1); + setHeight(length); } else // horizontal { - height = 1; - width = length; + setWidth(length); + setHeight(1); if ( isNewFont() ) nf = 2; } + SliderLength = BarLength = length-nf-2; } @@ -571,7 +571,7 @@ void FScrollbar::drawBar() for (z=1; z <= SliderPos; z++) { - gotoxy (xpos+xmin-1, ypos+ymin-1+z); + printPos (1, 1 + z); if ( isNewFont() ) print (fc::NF_border_line_left); // ⎸ @@ -589,9 +589,11 @@ void FScrollbar::drawBar() for (z=1; z <= SliderLength; z++) { - gotoxy (xpos+xmin-1, ypos+ymin-1+SliderPos+z); + printPos (1, 1 + SliderPos + z); + if ( isNewFont() ) print (' '); + print (' '); } @@ -602,7 +604,7 @@ void FScrollbar::drawBar() for (z=SliderPos+SliderLength+1; z <= BarLength; z++) { - gotoxy (xpos+xmin-1, ypos+ymin-1+z); + printPos (1, 1 + z); if ( isNewFont() ) print (fc::NF_border_line_left); // ⎸ @@ -619,9 +621,9 @@ void FScrollbar::drawBar() z = 0; if ( isNewFont() ) - gotoxy (xpos+xmin+1+z, ypos+ymin-1); + printPos (3 + z, 1); else - gotoxy (xpos+xmin+z, ypos+ymin-1); + printPos (2 + z, 1); for (; z < SliderPos; z++) { @@ -676,13 +678,13 @@ void FScrollbar::drawButtons() if ( isNewFont() ) { - gotoxy (xpos+xmin-1, ypos+ymin-1); + printPos (1,1); if ( bar_orientation == fc::vertical ) { print (fc::NF_rev_up_arrow1); print (fc::NF_rev_up_arrow2); - gotoxy (xpos+xmin-1, ypos+ymin+length-2); + printPos (1, length); print (fc::NF_rev_down_arrow1); print (fc::NF_rev_down_arrow2); } @@ -690,14 +692,14 @@ void FScrollbar::drawButtons() { print (fc::NF_rev_left_arrow1); print (fc::NF_rev_left_arrow2); - gotoxy (xpos+xmin+length-3, ypos+ymin-1); + printPos (length-1, 1); print (fc::NF_rev_right_arrow1); print (fc::NF_rev_right_arrow2); } } else { - gotoxy (xpos+xmin-1, ypos+ymin-1); + printPos (1,1); if ( isMonochron() ) setReverse(true); @@ -709,7 +711,7 @@ void FScrollbar::drawButtons() else print (fc::BlackUpPointingTriangle); // ▲ - gotoxy (xpos+xmin-1, ypos+ymin+length-2); + printPos (1, length); if ( isCygwinTerminal() ) print ('v'); @@ -719,9 +721,8 @@ void FScrollbar::drawButtons() else // horizontal { print (fc::BlackLeftPointingPointer); // ◄ - gotoxy (xpos+xmin+length-2, ypos+ymin-1); + printPos (length, 1); print (fc::BlackRightPointingPointer); // ► - } if ( isMonochron() ) diff --git a/src/fstatusbar.cpp b/src/fstatusbar.cpp index da508171..c66a230e 100644 --- a/src/fstatusbar.cpp +++ b/src/fstatusbar.cpp @@ -192,32 +192,30 @@ FStatusBar::~FStatusBar() //---------------------------------------------------------------------- void FStatusBar::init() { - xmin = ymin = 1; - xpos = 1; - ypos = getLineNumber(); + FWidget* r = getRootWidget(); + int w = r->getWidth(); + int h = r->getHeight(); + // initialize geometry values + setGeometry (1, h, w, 1, false); createArea (vstatusbar); vstatusbar->visible = true; - ignore_padding = true; + ignorePadding(); mouse_down = false; - // initialize geometry values - setGeometry (1, ypos, getColumnNumber(), 1, false); + setStatusBar(this); if ( getRootWidget() ) getRootWidget()->setBottomPadding(1, true); - foregroundColor = wc.statusbar_fg; - backgroundColor = wc.statusbar_bg; + setForegroundColor (wc.statusbar_fg); + setBackgroundColor (wc.statusbar_bg); unsetFocusable(); } //---------------------------------------------------------------------- void FStatusBar::draw() { - xmin = ymin = 1; - height = 1; - xpos = 1; drawKeys(); drawMessage(); } @@ -226,15 +224,12 @@ void FStatusBar::draw() void FStatusBar::drawKeys() { std::vector::const_iterator iter, end; - int screenWidth, lastLine; + int screenWidth; if ( ! vstatusbar ) return; screenWidth = getColumnNumber(); - lastLine = getLineNumber(); - width = screenWidth; - ypos = lastLine; x = 1; if ( keylist.empty() ) @@ -244,7 +239,7 @@ void FStatusBar::drawKeys() } updateVTerm(false); - gotoxy (1, lastLine); + printPos (1, 1); if ( isMonochron() ) setReverse(true); @@ -535,7 +530,7 @@ void FStatusBar::onMouseMove (FMouseEvent* ev) //---------------------------------------------------------------------- void FStatusBar::hide() { - int lastLine, screenWidth; + int screenWidth; short fg, bg; char* blank; @@ -543,27 +538,19 @@ void FStatusBar::hide() fg = wc.term_fg; bg = wc.term_bg; setColor (fg, bg); - lastLine = getLineNumber(); screenWidth = getColumnNumber(); + + if ( screenWidth < 0 ) + return; + blank = new char[screenWidth+1]; memset(blank, ' ', uLong(screenWidth)); blank[screenWidth] = '\0'; - gotoxy (1, lastLine); + printPos (1, 1); print (vstatusbar, blank); delete[] blank; } -//---------------------------------------------------------------------- -void FStatusBar::setGeometry (int xx, int yy, int ww, int hh, bool adjust) -{ - int old_width = width; - int old_height = height; - FWidget::setGeometry (xx, yy, ww, hh, adjust); - - if ( vstatusbar && (width != old_width || height != old_height) ) - resizeArea (vstatusbar); -} - //---------------------------------------------------------------------- bool FStatusBar::hasActivatedKey() { @@ -588,7 +575,7 @@ bool FStatusBar::hasActivatedKey() //---------------------------------------------------------------------- void FStatusBar::drawMessage() { - int termWidth, lastLine, space_offset; + int termWidth, space_offset; bool isLastActiveFocus, hasKeys; if ( ! (isVisible() && vstatusbar) ) @@ -599,7 +586,6 @@ void FStatusBar::drawMessage() x = x_msg; termWidth = getColumnNumber(); - lastLine = getLineNumber(); space_offset = 1; hasKeys = bool(! keylist.empty()); @@ -617,7 +603,7 @@ void FStatusBar::drawMessage() updateVTerm(false); setColor (wc.statusbar_fg, wc.statusbar_bg); - gotoxy (x, lastLine); + printPos (x, 1); if ( isMonochron() ) setReverse(true); @@ -739,11 +725,7 @@ void FStatusBar::clear() //---------------------------------------------------------------------- void FStatusBar::adjustSize() { - xmin = ymin = 1; - height = 1; - xpos = 1; - width = getColumnNumber(); - ypos = getLineNumber(); + setGeometry (1, getLineNumber(), getColumnNumber(), 1, false); } //---------------------------------------------------------------------- diff --git a/src/fstatusbar.h b/src/fstatusbar.h index 6fdf6c9f..3d63ca34 100644 --- a/src/fstatusbar.h +++ b/src/fstatusbar.h @@ -168,9 +168,6 @@ class FStatusBar : public FWindow void onMouseUp (FMouseEvent*); void onMouseMove (FMouseEvent*); void hide(); - // make every setGeometry from FWidget available - using FWidget::setGeometry; - void setGeometry (int, int, int, int, bool = true); uInt count() const; FStatusKey* key (int) const; diff --git a/src/fswitch.cpp b/src/fswitch.cpp index 9b463b96..de09f401 100644 --- a/src/fswitch.cpp +++ b/src/fswitch.cpp @@ -54,7 +54,7 @@ void FSwitch::drawCheckButton() wchar_t on[6] = L" On "; wchar_t off[6] = L" Off "; - gotoxy (xpos+xmin-1+switch_offset_pos, ypos+ymin-1); + printPos (1 + switch_offset_pos, 1); if ( checked ) { @@ -98,8 +98,7 @@ void FSwitch::drawCheckButton() if ( isMonochron() ) setReverse(false); - setCursorPos ( xpos + xmin + 1 + switch_offset_pos - , ypos + ymin - 1 ); + setCursorPos (3 + switch_offset_pos, 1); } else { @@ -141,8 +140,7 @@ void FSwitch::drawCheckButton() if ( isMonochron() || getMaxColor() < 16 ) setBold(false); - setCursorPos ( xpos + xmin + 5 + switch_offset_pos - , ypos + ymin - 1 ); + setCursorPos (7 + switch_offset_pos, 1); } } diff --git a/src/fterm.cpp b/src/fterm.cpp index e30da496..6f55994d 100644 --- a/src/fterm.cpp +++ b/src/fterm.cpp @@ -2374,14 +2374,14 @@ void FTerm::restoreVTerm (int x, int y, int w, int h) while ( iter != end ) { term_area* win = (*iter)->getVWin(); - const FRect& geometry = (*iter)->getGeometryGlobalShadow(); + const FRect& geometry = (*iter)->getTermGeometryWithShadow(); // window visible and contains current character if ( win && win->visible && geometry.contains(tx+x+1, ty+y+1) ) { FOptiAttr::char_data* tmp; - int win_x = (*iter)->getGlobalX() - 1; - int win_y = (*iter)->getGlobalY() - 1; + int win_x = (*iter)->getTermX() - 1; + int win_y = (*iter)->getTermY() - 1; int line_len = win->width + win->right_shadow; tmp = &win->text[(ty+y-win_y) * line_len + (tx+x-win_x)]; @@ -2426,10 +2426,10 @@ void FTerm::restoreVTerm (int x, int y, int w, int h) menubar = reinterpret_cast(FWidget::menuBar()); if ( vmenubar && menubar - && menubar->getGeometryGlobal().contains(x+tx+1, y+ty+1) ) + && menubar->getTermGeometry().contains(x+tx+1, y+ty+1) ) { - int bar_x = menubar->getGlobalX() - 1; - int bar_y = menubar->getGlobalY() - 1; + int bar_x = menubar->getTermX() - 1; + int bar_y = menubar->getTermY() - 1; if ( vmenubar->visible ) sc = &vmenubar->text[(y+ty-bar_y) * vmenubar->width + (x+tx-bar_x)]; @@ -2440,10 +2440,10 @@ void FTerm::restoreVTerm (int x, int y, int w, int h) statusbar = reinterpret_cast(FWidget::statusBar()); if ( vstatusbar && statusbar - && statusbar->getGeometryGlobal().contains(x+tx+1, y+ty+1) ) + && statusbar->getTermGeometry().contains(x+tx+1, y+ty+1) ) { - int bar_x = statusbar->getGlobalX() - 1; - int bar_y = statusbar->getGlobalY() - 1; + int bar_x = statusbar->getTermX() - 1; + int bar_y = statusbar->getTermY() - 1; if ( vstatusbar->visible ) sc = &vstatusbar->text[(y+ty-bar_y) * vstatusbar->width + (x+tx-bar_x)]; @@ -2486,7 +2486,7 @@ FTerm::covered_state FTerm::isCovered (int x, int y, FTerm::term_area* area) con while ( iter != end ) { term_area* win = (*iter)->getVWin(); - const FRect& geometry = (*iter)->getGeometryGlobalShadow(); + const FRect& geometry = (*iter)->getTermGeometryWithShadow(); if ( win && found && (*iter)->isVisible() @@ -2494,8 +2494,8 @@ FTerm::covered_state FTerm::isCovered (int x, int y, FTerm::term_area* area) con && geometry.contains(x,y) ) { FOptiAttr::char_data* tmp; - int win_x = (*iter)->getGlobalX() - 1; - int win_y = (*iter)->getGlobalY() - 1; + int win_x = (*iter)->getTermX() - 1; + int win_y = (*iter)->getTermY() - 1; int line_len = win->width + win->right_shadow; tmp = &win->text[(y-win_y-1) * line_len + (x-win_x-1)]; @@ -2526,7 +2526,7 @@ FTerm::covered_state FTerm::isCovered (int x, int y, FTerm::term_area* area) con menubar = 0; if ( area != vmenubar && menubar - && menubar->getGeometryGlobal().contains(x,y) ) + && menubar->getTermGeometry().contains(x,y) ) { is_covered = fully_covered; } @@ -2540,7 +2540,7 @@ FTerm::covered_state FTerm::isCovered (int x, int y, FTerm::term_area* area) con statusbar = 0; if ( area != vstatusbar && statusbar - && statusbar->getGeometryGlobal().contains(x,y) ) + && statusbar->getTermGeometry().contains(x,y) ) { is_covered = fully_covered; } @@ -2568,8 +2568,8 @@ void FTerm::updateVTerm (FTerm::term_area* area) if ( ! area->visible ) return; - ax = area->widget->getGlobalX() - 1; - ay = area->widget->getGlobalY() - 1; + ax = area->widget->getTermX() - 1; + ay = area->widget->getTermY() - 1; aw = area->width; ah = area->height; rsh = area->right_shadow; @@ -2609,7 +2609,8 @@ void FTerm::updateVTerm (FTerm::term_area* area) { int gx, gy, line_len; FTerm::covered_state is_covered; - gx = ax + x; // global position + // global terminal positions + gx = ax + x; gy = ay + y; if ( gx < 0 || gy < 0 ) @@ -2761,8 +2762,8 @@ void FTerm::getArea (int x, int y, int w, int h, FTerm::term_area* area) if ( ! area ) return; - dx = x - area->widget->getGlobalX(); - dy = y - area->widget->getGlobalY(); + dx = x - area->widget->getTermX(); + dy = y - area->widget->getTermY(); if ( x < 0 || y < 0 ) return; @@ -3071,14 +3072,14 @@ FOptiAttr::char_data FTerm::getCharacter ( int char_type if ( obj && *iter != obj && significant_char ) { term_area* win = (*iter)->getVWin(); - const FRect& geometry = (*iter)->getGeometryGlobalShadow(); + const FRect& geometry = (*iter)->getTermGeometryWithShadow(); // window visible and contains current character if ( win && win->visible && geometry.contains(x+1,y+1) ) { FOptiAttr::char_data* tmp; - int win_x = (*iter)->getGlobalX() - 1; - int win_y = (*iter)->getGlobalY() - 1; + int win_x = (*iter)->getTermX() - 1; + int win_y = (*iter)->getTermY() - 1; int line_len = win->width + win->right_shadow; tmp = &win->text[(y-win_y) * line_len + (x-win_x)]; @@ -4107,6 +4108,7 @@ bool FTerm::hideCursor (bool on) { if ( vi ) appendOutputBuffer (vi); + hiddenCursor = true; // global } else @@ -4118,6 +4120,7 @@ bool FTerm::hideCursor (bool on) hiddenCursor = false; } + flush_out(); if ( ! hiddenCursor && linux_terminal ) @@ -4135,6 +4138,8 @@ bool FTerm::isCursorInside() int x = w->getCursorPos().getX(); int y = w->getCursorPos().getY(); + x += w->getTermX() - 1; + y += w->getTermY() - 1; if ( term->contains(x,y) ) return true; @@ -4573,8 +4578,8 @@ int FTerm::print (FTerm::term_area* area, FString& s) nc.trans_shadow = next_attribute.trans_shadow; nc.inherit_bg = next_attribute.inherit_bg; - int ax = x - area_widget->getGlobalX(); - int ay = y - area_widget->getGlobalY(); + int ax = x - area_widget->getTermX(); + int ay = y - area_widget->getTermY(); if ( area && ax >= 0 && ay >= 0 @@ -4619,11 +4624,11 @@ int FTerm::print (FTerm::term_area* area, FString& s) rsh = area->right_shadow; bsh = area->bottom_shadow; - const FRect& area_geometry = area_widget->getGeometryGlobal(); + const FRect& area_geometry = area_widget->getTermGeometry(); if ( cursor->x_ref() > area_geometry.getX2()+rsh ) { - cursor->x_ref() = short(area_widget->getGlobalX()); + cursor->x_ref() = short(area_widget->getTermX()); cursor->y_ref()++; } @@ -4701,8 +4706,8 @@ int FTerm::print (FTerm::term_area* area, register int c) if ( ! area_widget ) return -1; - ax = x - area_widget->getGlobalX(); - ay = y - area_widget->getGlobalY(); + ax = x - area_widget->getTermX(); + ay = y - area_widget->getTermY(); if ( ax >= 0 && ay >= 0 && ax < area->width + area->right_shadow @@ -4744,11 +4749,11 @@ int FTerm::print (FTerm::term_area* area, register int c) cursor->x_ref()++; rsh = area->right_shadow; bsh = area->bottom_shadow; - const FRect& area_geometry = area_widget->getGeometryGlobal(); + const FRect& area_geometry = area_widget->getTermGeometry(); if ( cursor->x_ref() > area_geometry.getX2()+rsh ) { - cursor->x_ref() = short(area_widget->getGlobalX()); + cursor->x_ref() = short(area_widget->getTermX()); cursor->y_ref()++; } diff --git a/src/fterm.h b/src/fterm.h index 5c774934..308a0fee 100644 --- a/src/fterm.h +++ b/src/fterm.h @@ -410,6 +410,8 @@ class FTerm static FString getAnswerbackMsg(); static FString getSecDA(); + static void printPosTerm (const FPoint&); + static void printPosTerm (register int, register int); int printf (const wchar_t*, ...); int printf (const char*, ...) #if defined(__clang__) @@ -656,5 +658,13 @@ inline bool FTerm::unsetRawMode() inline bool FTerm::setCookedMode() { return setRawMode(false); } +//---------------------------------------------------------------------- +inline void FTerm::printPosTerm (const FPoint& pos) +{ printPosTerm (pos.getX(), pos.getY()); } + +//---------------------------------------------------------------------- +inline void FTerm::printPosTerm (register int x, register int y) +{ cursor->setPoint(x,y); } + #endif // _FTERM_H diff --git a/src/ftextview.cpp b/src/ftextview.cpp index 2ebdc9b1..1e33ed07 100644 --- a/src/ftextview.cpp +++ b/src/ftextview.cpp @@ -37,8 +37,8 @@ void FTextView::init() { nf_offset = isNewFont() ? 1 : 0; - foregroundColor = wc.dialog_fg; - backgroundColor = wc.dialog_bg; + setForegroundColor (wc.dialog_fg); + setBackgroundColor (wc.dialog_bg); VBar = new FScrollbar(fc::vertical, this); VBar->setMinimum(0); @@ -66,7 +66,7 @@ void FTextView::init() void FTextView::draw() { updateVTerm(false); - setColor (foregroundColor, backgroundColor); + setColor(); if ( isMonochron() ) setReverse(true); @@ -100,7 +100,7 @@ void FTextView::draw() } } - setCursorPos(1,1); + setCursorPos (getWidth(), getHeight()); updateTerminal(); flush_out(); } @@ -110,17 +110,17 @@ void FTextView::drawText() { uInt start, end; - if ( data.empty() || height < 4 || width < 5 ) + if ( data.empty() || getHeight() < 4 || getWidth() < 5 ) return; start = 0; - end = uInt(height+nf_offset-2); + end = uInt(getHeight() + nf_offset - 2); if ( end > getRows() ) end = getRows(); updateVTerm(false); - setColor (foregroundColor, backgroundColor); + setColor(); if ( isMonochron() ) setReverse(true); @@ -130,9 +130,9 @@ void FTextView::drawText() uInt i, len; FString line; const wchar_t* line_str; - gotoxy (xpos+xmin, ypos+ymin-nf_offset+int(y)); + printPos (2, 2 - nf_offset + int(y)); line = data[y+uInt(yoffset)].mid ( uInt(1 + xoffset) - , uInt(width - nf_offset - 2) ); + , uInt(getWidth() - nf_offset - 2) ); line_str = line.wc_str(); len = line.getLength(); @@ -152,7 +152,7 @@ void FTextView::drawText() print ('.'); } - for (; i < uInt(width - nf_offset - 2); i++) + for (; i < uInt(getWidth() - nf_offset - 2); i++) print (' '); } @@ -173,25 +173,43 @@ void FTextView::processChanged() void FTextView::adjustSize() { FWidget::adjustSize(); + int width = getWidth(); + int height = getHeight(); + int last_line = int(getRows()); + int max_width = int(maxLineWidth); - VBar->setMaximum (int(getRows()) - height + 2 - nf_offset); - VBar->setPageSize (int(getRows()), height - 2 + nf_offset); + if ( xoffset > max_width - width - nf_offset - 1 ) + xoffset = max_width - width - nf_offset - 1; + + if ( xoffset < 0 ) + xoffset = 0; + + if ( yoffset > last_line - height - nf_offset + 2 ) + yoffset = last_line - height - nf_offset + 2; + + if ( yoffset < 0 ) + yoffset = 0; + + VBar->setMaximum (last_line - height + 2 - nf_offset); + VBar->setPageSize (last_line, height - 2 + nf_offset); VBar->setX (width); VBar->setHeight (height - 2 + nf_offset, false); + VBar->setValue (yoffset); VBar->resize(); - HBar->setMaximum (int(maxLineWidth) - width + nf_offset + 2); - HBar->setPageSize (int(maxLineWidth), width - nf_offset - 2); + HBar->setMaximum (max_width - width + nf_offset + 2); + HBar->setPageSize (max_width, width - nf_offset - 2); HBar->setY (height); HBar->setWidth (width - 2, false); + HBar->setValue (xoffset); HBar->resize(); - if ( int(getRows()) < height + nf_offset - 1 ) + if ( last_line < height + nf_offset - 1 ) VBar->hide(); else VBar->setVisible(); - if ( int(maxLineWidth) < width-nf_offset - 1 ) + if ( max_width < width - nf_offset - 1 ) HBar->hide(); else HBar->setVisible(); @@ -222,14 +240,18 @@ void FTextView::hide() setColor (fg, bg); n = isNewFont() ? 1 : 0; - size = width + n; + size = getWidth() + n; + + if ( size < 0 ) + return; + blank = new char[size+1]; memset(blank, ' ', uLong(size)); blank[size] = '\0'; - for (int y=0; y < height; y++) + for (int y=0; y < getHeight(); y++) { - gotoxy (xpos+xmin-1, ypos+ymin-1+y); + printPos (1, 1 + y); print (blank); } @@ -253,14 +275,14 @@ void FTextView::onKeyPress (FKeyEvent* ev) break; case fc::Fkey_down: - if ( yoffset + height + nf_offset <= last_line + 1 ) + if ( yoffset + getHeight() + nf_offset <= last_line + 1 ) yoffset++; ev->accept(); break; case fc::Fkey_right: - if ( xoffset + width - nf_offset <= int(maxLineWidth) + 1 ) + if ( xoffset + getWidth() - nf_offset <= int(maxLineWidth) + 1 ) xoffset++; ev->accept(); @@ -274,7 +296,7 @@ void FTextView::onKeyPress (FKeyEvent* ev) break; case fc::Fkey_ppage: - yoffset -= height-2; + yoffset -= getHeight()-2; if ( yoffset < 0 ) yoffset = 0; @@ -283,11 +305,11 @@ void FTextView::onKeyPress (FKeyEvent* ev) break; case fc::Fkey_npage: - if ( last_line >= height ) - yoffset += height-2; + if ( last_line >= getHeight() ) + yoffset += getHeight()-2; - if ( yoffset > last_line - height - nf_offset + 2 ) - yoffset = last_line - height - nf_offset + 2; + if ( yoffset > last_line - getHeight() - nf_offset + 2 ) + yoffset = last_line - getHeight() - nf_offset + 2; if ( yoffset < 0 ) yoffset = 0; @@ -301,8 +323,8 @@ void FTextView::onKeyPress (FKeyEvent* ev) break; case fc::Fkey_end: - if ( last_line >= height ) - yoffset = last_line - height - nf_offset + 2; + if ( last_line >= getHeight() ) + yoffset = last_line - getHeight() - nf_offset + 2; ev->accept(); break; @@ -373,7 +395,7 @@ void FTextView::onWheel (FWheelEvent* ev) case fc::WheelDown: { - int yoffset_end = last_line - height - nf_offset + 2; + int yoffset_end = last_line - getHeight() - nf_offset + 2; if ( yoffset_end < 0 ) yoffset_end = 0; @@ -436,7 +458,7 @@ void FTextView::cb_VBarChange (FWidget*, void*) switch ( scrollType ) { case FScrollbar::scrollPageBackward: - distance = height+nf_offset-2; + distance = getHeight() + nf_offset - 2; // fall through case FScrollbar::scrollStepBackward: yoffset -= distance; @@ -447,13 +469,13 @@ void FTextView::cb_VBarChange (FWidget*, void*) break; case FScrollbar::scrollPageForward: - distance = height+nf_offset-2; + distance = getHeight() + nf_offset - 2; // fall through case FScrollbar::scrollStepForward: yoffset += distance; - if ( yoffset > last_line - height - nf_offset + 2 ) - yoffset = last_line - height - nf_offset + 2; + if ( yoffset > last_line - getHeight() - nf_offset + 2 ) + yoffset = last_line - getHeight() - nf_offset + 2; break; @@ -466,8 +488,8 @@ void FTextView::cb_VBarChange (FWidget*, void*) yoffset = val; - if ( yoffset > last_line - height - nf_offset + 2 ) - yoffset = last_line - height - nf_offset + 2; + if ( yoffset > last_line - getHeight() - nf_offset + 2 ) + yoffset = last_line - getHeight() - nf_offset + 2; if ( yoffset < 0 ) yoffset = 0; @@ -516,13 +538,13 @@ void FTextView::cb_HBarChange (FWidget*, void*) { int distance = 1; int xoffset_before = xoffset; - int xoffset_end = int(maxLineWidth) - width + nf_offset + 4; + int xoffset_end = int(maxLineWidth) - getWidth() + nf_offset + 4; int scrollType = HBar->getScrollType(); switch ( scrollType ) { case FScrollbar::scrollPageBackward: - distance = width - nf_offset - 4; + distance = getWidth() - nf_offset - 4; // fall through case FScrollbar::scrollStepBackward: xoffset -= distance; @@ -533,13 +555,13 @@ void FTextView::cb_HBarChange (FWidget*, void*) break; case FScrollbar::scrollPageForward: - distance = width - nf_offset - 4; + distance = getWidth() - nf_offset - 4; // fall through case FScrollbar::scrollStepForward: xoffset += distance; - if ( xoffset > int(maxLineWidth) - width + nf_offset + 4 ) - xoffset = int(maxLineWidth) - width + nf_offset + 4; + if ( xoffset > int(maxLineWidth) - getWidth() + nf_offset + 4 ) + xoffset = int(maxLineWidth) - getWidth() + nf_offset + 4; if ( xoffset < 0 ) xoffset = 0; @@ -555,8 +577,8 @@ void FTextView::cb_HBarChange (FWidget*, void*) xoffset = val; - if ( xoffset > int(maxLineWidth) - width + nf_offset + 4 ) - xoffset = int(maxLineWidth) - width + nf_offset + 4; + if ( xoffset > int(maxLineWidth) - getWidth() + nf_offset + 4 ) + xoffset = int(maxLineWidth) - getWidth() + nf_offset + 4; if ( xoffset < 0 ) xoffset = 0; @@ -612,6 +634,8 @@ void FTextView::cb_HBarChange (FWidget*, void*) void FTextView::setGeometry (int x, int y, int w, int h, bool adjust) { FWidget::setGeometry(x, y, w, h, adjust); + int width = getWidth(); + int height = getHeight(); if ( isNewFont() ) { @@ -623,6 +647,9 @@ void FTextView::setGeometry (int x, int y, int w, int h, bool adjust) VBar->setGeometry (width, 2, 1, height-2); HBar->setGeometry (2, height, width-2, 1); } + + VBar->resize(); + HBar->resize(); } //---------------------------------------------------------------------- @@ -630,7 +657,7 @@ void FTextView::setPosition (int pos) { int last_line = int(getRows()); - if ( pos < 0 || pos > last_line - height + 2 ) + if ( pos < 0 || pos > last_line - getHeight() + 2 ) return; yoffset = pos; @@ -728,10 +755,10 @@ void FTextView::insert (const FString& str, int pos) { maxLineWidth = len; - if ( len > uInt(width-nf_offset-2) ) + if ( len > uInt(getWidth() - nf_offset - 2) ) { - HBar->setMaximum (int(maxLineWidth) - width + nf_offset + 2); - HBar->setPageSize (int(maxLineWidth), width - nf_offset - 2); + HBar->setMaximum (int(maxLineWidth) - getWidth() + nf_offset + 2); + HBar->setPageSize (int(maxLineWidth), getWidth() - nf_offset - 2); HBar->calculateSliderValues(); if ( ! HBar->isVisible() ) @@ -741,14 +768,14 @@ void FTextView::insert (const FString& str, int pos) } data.insert (iter + pos, text_split.begin(), text_split.end()); - VBar->setMaximum (int(getRows()) - height + 2 - nf_offset); - VBar->setPageSize (int(getRows()), height - 2 + nf_offset); + VBar->setMaximum (int(getRows()) - getHeight() + 2 - nf_offset); + VBar->setPageSize (int(getRows()), getHeight() - 2 + nf_offset); VBar->calculateSliderValues(); - if ( ! VBar->isVisible() && int(getRows()) >= height + nf_offset - 1 ) + if ( ! VBar->isVisible() && int(getRows()) >= getHeight() + nf_offset - 1 ) VBar->setVisible(); - if ( VBar->isVisible() && int(getRows()) < height + nf_offset - 1 ) + if ( VBar->isVisible() && int(getRows()) < getHeight() + nf_offset - 1 ) VBar->hide(); processChanged(); @@ -795,15 +822,19 @@ void FTextView::clear() HBar->hide(); // clear list from screen - setColor (foregroundColor, backgroundColor); - size = width - 2; + setColor(); + size = getWidth() - 2; + + if ( size < 0 ) + return; + blank = new char[size+1]; memset(blank, ' ', uLong(size)); blank[size] = '\0'; - for (int y=0; y < height+nf_offset-2; y++) + for (int y=0; y < getHeight() + nf_offset - 2; y++) { - gotoxy (xpos+xmin, ypos+ymin-nf_offset+y); + printPos (2, 2 - nf_offset + y); print (blank); } diff --git a/src/ftogglebutton.cpp b/src/ftogglebutton.cpp index 9c3a226e..c0177cda 100644 --- a/src/ftogglebutton.cpp +++ b/src/ftogglebutton.cpp @@ -85,19 +85,19 @@ void FToggleButton::init() if ( hasFocus() ) { - foregroundColor = wc.toggle_button_active_focus_fg; - backgroundColor = wc.toggle_button_active_focus_bg; + setForegroundColor (wc.toggle_button_active_focus_fg); + setBackgroundColor (wc.toggle_button_active_focus_bg); } else { - foregroundColor = wc.toggle_button_active_fg; - backgroundColor = wc.toggle_button_active_bg; + setForegroundColor (wc.toggle_button_active_fg); + setBackgroundColor (wc.toggle_button_active_bg); } } else // inactive { - foregroundColor = wc.label_inactive_fg; - backgroundColor = wc.label_inactive_bg; + setForegroundColor (wc.label_inactive_fg); + setBackgroundColor (wc.label_inactive_bg); } } @@ -176,7 +176,7 @@ void FToggleButton::draw() // set the cursor to the button if ( isRadioButton() || isCheckboxButton() ) { - setCursorPos (xpos+xmin, ypos+ymin-1); + setCursorPos (2, 1); if ( isCursorInside() && hasFocus() ) { @@ -232,7 +232,7 @@ void FToggleButton::drawLabel() if ( hotkeypos != -1 ) length--; - gotoxy (xpos+xmin-1+label_offset_pos, ypos+ymin-1); + printPos (1 + label_offset_pos, 1); if ( isMonochron() ) setReverse(true); @@ -381,11 +381,15 @@ void FToggleButton::hide() } setColor (fg, bg); - size = width; + size = getWidth(); + + if ( size < 0 ) + return; + blank = new char[size+1]; memset(blank, ' ', uLong(size)); blank[size] = '\0'; - gotoxy (xpos+xmin-1, ypos+ymin-1); + printPos (1, 1); print (blank); delete[] blank; } @@ -424,21 +428,21 @@ bool FToggleButton::setEnable (bool on) if ( hasFocus() ) { - foregroundColor = wc.toggle_button_active_focus_fg; - backgroundColor = wc.toggle_button_active_focus_bg; + setForegroundColor (wc.toggle_button_active_focus_fg); + setBackgroundColor (wc.toggle_button_active_focus_bg); } else { - foregroundColor = wc.toggle_button_active_fg; - backgroundColor = wc.toggle_button_active_bg; + setForegroundColor (wc.toggle_button_active_fg); + setBackgroundColor (wc.toggle_button_active_bg); } } else { flags &= ~fc::active; delAccelerator(); - foregroundColor = wc.toggle_button_inactive_fg; - backgroundColor = wc.toggle_button_inactive_bg; + setForegroundColor (wc.toggle_button_inactive_fg); + setBackgroundColor (wc.toggle_button_inactive_bg); } return on; @@ -458,8 +462,8 @@ bool FToggleButton::setFocus (bool on) if ( isRadioButton() ) focus_inside_group = false; - foregroundColor = wc.toggle_button_active_focus_fg; - backgroundColor = wc.toggle_button_active_focus_bg; + setForegroundColor (wc.toggle_button_active_focus_fg); + setBackgroundColor (wc.toggle_button_active_focus_bg); if ( isCursorInside() && (isRadioButton() || isCheckboxButton()) ) showCursor(); @@ -480,8 +484,8 @@ bool FToggleButton::setFocus (bool on) if ( isEnabled() ) { - foregroundColor = wc.toggle_button_active_fg; - backgroundColor = wc.toggle_button_active_bg; + setForegroundColor (wc.toggle_button_active_fg); + setBackgroundColor (wc.toggle_button_active_bg); hideCursor(); if ( statusBar() ) @@ -525,7 +529,7 @@ void FToggleButton::onMouseUp (FMouseEvent* ev) if ( ev->getButton() != fc::LeftButton ) return; - if ( getGeometryGlobal().contains(ev->getGlobalPos()) ) + if ( getTermGeometry().contains(ev->getTermPos()) ) { if ( isRadioButton() ) { diff --git a/src/fwidget.cpp b/src/fwidget.cpp index 86b08d00..98de0532 100644 --- a/src/fwidget.cpp +++ b/src/fwidget.cpp @@ -30,36 +30,10 @@ FWidget::widget_colors FWidget::wc; //---------------------------------------------------------------------- FWidget::FWidget (FWidget* parent) : FObject(parent) - , callbackObjects() - , memberCallbackObjects() + , callback_objects() + , member_callback_objects() , accelerator_list() - , double_flatline_mask() - , xpos(1) - , ypos(1) - , width(1) - , height(1) - , xmin(1) - , ymin(1) - , xmax(1) - , ymax(1) - , top_padding(0) - , left_padding(0) - , bottom_padding(0) - , right_padding(0) - , client_xmin(0) - , client_ymin(0) - , client_xmax(0) - , client_ymax(0) - , shadow() - , adjustWidgetSizeShadow() - , adjustWidgetSizeGlobalShadow() - , ignore_padding(false) - , window_object(false) - , dialog_object(false) - , menu_object(false) , flags(0) - , foregroundColor() - , backgroundColor() , enable(true) , visible(true) , shown(false) @@ -67,11 +41,22 @@ FWidget::FWidget (FWidget* parent) , focusable(true) , visibleCursor(false) , widgetCursorPosition(-1,-1) - , widgetSize(1,1,1,1) - , adjustWidgetSize(1,1,1,1) - , adjustWidgetSizeGlobal(1,1,1,1) - , statusbar_message() + , size_hints() + , double_flatline_mask() + , padding() + , ignore_padding(false) + , wsize(1,1,1,1) + , adjust_wsize(1,1,1,1) + , adjust_wsize_term() + , adjust_wsize_shadow() + , adjust_wsize_term_shadow() + , offset() + , client_offset() + , wshadow() + , foreground_color() + , background_color() , print_area(0) + , statusbar_message() { resize_term = false; @@ -89,14 +74,11 @@ FWidget::FWidget (FWidget* parent) } else { - xmin = parent->client_xmin; - ymin = parent->client_ymin; - xmax = parent->client_xmax; - ymax = parent->client_ymax; - double_flatline_mask.top.resize (uLong(width), false); - double_flatline_mask.right.resize (uLong(height), false); - double_flatline_mask.bottom.resize (uLong(width), false); - double_flatline_mask.left.resize (uLong(height), false); + offset = parent->client_offset; + double_flatline_mask.top.resize (uLong(getWidth()), false); + double_flatline_mask.right.resize (uLong(getHeight()), false); + double_flatline_mask.bottom.resize (uLong(getWidth()), false); + double_flatline_mask.left.resize (uLong(getHeight()), false); } } @@ -138,42 +120,28 @@ FWidget::~FWidget() // destructor //---------------------------------------------------------------------- void FWidget::init() { - window_list = new widgetList(); - dialog_list = new widgetList(); - close_widget = new widgetList(); + window_list = new widgetList(); + dialog_list = new widgetList(); + close_widget = new widgetList(); - getTermGeometry(); // <-----. - // | - xpos = xmin; // xmin, ymin, xmax and ymax - ypos = ymin; // were determined with - width = xmax; // getTermGeometry() - height = ymax; - client_xmin = xmin; - client_ymin = ymin; - client_xmax = xmax; - client_ymax = ymax; + // determine width and height of the terminal + getTermSize(); + wsize.setRect(1, 1, term->getWidth(), term->getHeight()); + adjust_wsize = wsize; + offset.setRect(0, 0, term->getWidth(), term->getHeight()); + client_offset = offset; - // xpos and ypos are initialized with the value 1 - // width and height were determined with getTermGeometry() - widgetSize.setRect(xpos, ypos, width, height); - adjustWidgetSize.setRect(xpos, ypos, width, height); - adjustWidgetSizeShadow = adjustWidgetSize; - adjustWidgetSizeGlobal.setRect ( xpos + xmin - 1 - , ypos + ymin - 1 - , width, height ); - adjustWidgetSizeGlobalShadow = adjustWidgetSizeGlobal; - - double_flatline_mask.top.resize (uLong(width), false); - double_flatline_mask.right.resize (uLong(height), false); - double_flatline_mask.bottom.resize (uLong(width), false); - double_flatline_mask.left.resize (uLong(height), false); + double_flatline_mask.top.resize (uLong(getWidth()), false); + double_flatline_mask.right.resize (uLong(getHeight()), false); + double_flatline_mask.bottom.resize (uLong(getWidth()), false); + double_flatline_mask.left.resize (uLong(getHeight()), false); // default widget colors setColorTheme(); - foregroundColor = wc.term_fg; - backgroundColor = wc.term_bg; - setColor (foregroundColor, backgroundColor); + foreground_color = wc.term_fg; + background_color = wc.term_bg; + setColor (foreground_color, background_color); clearArea(); accelerator_list = new Accelerators(); @@ -419,86 +387,73 @@ void FWidget::adjustSize() { if ( ! isRootWidget() ) { - FWidget* parent_widget = getParentWidget(); + FWidget* p = getParentWidget(); - if ( isWindow() ) + if ( isWindowWidget() ) + offset = rootObject->client_offset; + else if ( ignore_padding && p ) { - xmin = rootObject->client_xmin; - ymin = rootObject->client_ymin; - xmax = rootObject->client_xmax; - ymax = rootObject->client_ymax; - } - else if ( ignore_padding && parent_widget ) - { - xmin = parent_widget->xpos + parent_widget->xmin - 1; - ymin = parent_widget->ypos + parent_widget->ymin - 1; - xmax = parent_widget->xpos + parent_widget->xmin - 2 - + parent_widget->width; - ymax = parent_widget->ypos + parent_widget->ymin - 2 - + parent_widget->height; - } - else if ( parent_widget ) - { - xmin = parent_widget->client_xmin; - ymin = parent_widget->client_ymin; - xmax = parent_widget->client_xmax; - ymax = parent_widget->client_ymax; + offset.setCoordinates ( p->getTermX() - 1 + , p->getTermY() - 1 + , p->getTermX() + p->getWidth() - 2 + , p->getTermY() + p->getHeight() - 2 ); } + else if ( p ) + offset = p->client_offset; - xpos = widgetSize.getX(); - ypos = widgetSize.getY(); - width = widgetSize.getWidth(); - height = widgetSize.getHeight(); + adjust_wsize = wsize; } - if ( ! isWindow() ) + if ( ! isWindowWidget() ) { - while ( xpos+xmin-1+width > xmax+1 ) + // move left if not enough space + while ( getTermX()+getWidth()-padding.right > offset.getX2()+2 ) { - xpos--; + adjust_wsize.x1_ref()--; + adjust_wsize.x2_ref()--; - if ( xpos < 1 ) - { - xpos = 1; - width--; - } + if ( adjust_wsize.x1_ref() < 1 ) + adjust_wsize.x1_ref() = 1; } - while ( ypos+ymin-1+height > ymax+1 ) + // move up if not enough space + while ( getTermY()+getHeight()-padding.bottom > offset.getY2()+2 ) { - ypos--; + adjust_wsize.y1_ref()--; + adjust_wsize.y2_ref()--; - if ( ypos < 1 ) - { - ypos = 1; - height--; - } + if ( adjust_wsize.y1_ref() < 1 ) + adjust_wsize.y1_ref() = 1; } - while ( xmin+width-1 > xmax ) - width--; + // reduce the width if not enough space + while ( offset.getX1()+getWidth()-1 > offset.getX2() ) + adjust_wsize.x2_ref()--; - while ( ymin+height-1 > ymax ) - height--; + if ( getWidth() < size_hints.min_width ) + adjust_wsize.setWidth(size_hints.min_width); - if ( width < 1 ) - width = 1; + if ( getWidth() < 1 ) + adjust_wsize.setWidth(1); - if ( height < 1 ) - height = 1; + // reduce the height if not enough space + while ( offset.getY1()+getHeight()-1 > offset.getY2() ) + adjust_wsize.y2_ref()--; + + if ( getHeight() < size_hints.min_height ) + adjust_wsize.setWidth(size_hints.min_height); + + if ( getHeight() < 1 ) + adjust_wsize.setHeight(1); } - adjustWidgetSize.setRect(xpos, ypos, width, height); - adjustWidgetSizeShadow = adjustWidgetSize + shadow; - adjustWidgetSizeGlobal.setRect ( xpos + xmin - 1 - , ypos + ymin - 1 - , width, height ); - adjustWidgetSizeGlobalShadow = adjustWidgetSizeGlobal + shadow; - - client_xmin = xpos + xmin - 1 + left_padding; - client_ymin = ypos + ymin - 1 + top_padding; - client_xmax = xpos + xmin - 2 + width - right_padding; - client_ymax = ypos + ymin - 2 + height - bottom_padding; + client_offset.setCoordinates + ( + getTermX() - 1 + padding.left, + getTermY() - 1 + padding.top, + getTermX() - 2 + getWidth() - padding.right, + getTermY() - 2 + getHeight() - padding.bottom + ); if ( this->hasChildren() ) { @@ -513,7 +468,7 @@ void FWidget::adjustSize() { FWidget* widget = static_cast(*iter); - if ( ! widget->isWindow() ) + if ( ! widget->isWindowWidget() ) widget->adjustSize(); ++iter; @@ -767,7 +722,7 @@ void FWidget::onClose (FCloseEvent* ev) //---------------------------------------------------------------------- bool FWidget::focusNextChild() { - if ( isDialog() ) + if ( isDialogWidget() ) return false; if ( hasParent() ) @@ -804,7 +759,7 @@ bool FWidget::focusNextChild() } while ( ! next->isEnabled() || ! next->acceptFocus() || ! next->isVisible() - || next->isWindow() ); + || next->isWindowWidget() ); FFocusEvent out (fc::FocusOut_Event); out.setFocusType(fc::FocusNextWidget); @@ -840,7 +795,7 @@ bool FWidget::focusNextChild() //---------------------------------------------------------------------- bool FWidget::focusPrevChild() { - if ( isDialog() ) + if ( isDialogWidget() ) return false; if ( hasParent() ) @@ -877,7 +832,7 @@ bool FWidget::focusPrevChild() } while ( ! prev->isEnabled() || ! prev->acceptFocus() || ! prev->isVisible() - || prev->isWindow() ); + || prev->isWindowWidget() ); FFocusEvent out (fc::FocusOut_Event); out.setFocusType(fc::FocusPreviousWidget); @@ -958,8 +913,8 @@ FWidget* FWidget::childWidgetAt (FWidget* p, int x, int y) if ( widget->isEnabled() && widget->isVisible() - && ! widget->isWindow() - && widget->getGeometryGlobal().contains(x,y) ) + && ! widget->isWindowWidget() + && widget->getTermGeometry().contains(x,y) ) { FWidget* child = childWidgetAt(widget, x, y); return (child != 0) ? child : widget; @@ -1092,7 +1047,7 @@ void FWidget::addCallback ( FString cb_signal { // add a (normal) function pointer as callback callback_data obj = { cb_signal, cb_handler, data }; - callbackObjects.push_back(obj); + callback_objects.push_back(obj); } //---------------------------------------------------------------------- @@ -1103,7 +1058,7 @@ void FWidget::addCallback ( FString cb_signal { // add a member function pointer as callback member_callback_data obj = { cb_signal, cb_instance, cb_handler, data }; - memberCallbackObjects.push_back(obj); + member_callback_objects.push_back(obj); } //---------------------------------------------------------------------- @@ -1112,15 +1067,15 @@ void FWidget::delCallback (FWidget::FCallback cb_handler) FWidget::CallbackObjects::iterator iter; // delete a cb_handler function pointer - if ( callbackObjects.empty() ) + if ( callback_objects.empty() ) return; - iter = callbackObjects.begin(); + iter = callback_objects.begin(); - while ( iter != callbackObjects.end() ) + while ( iter != callback_objects.end() ) { if ( iter->cb_handler == cb_handler ) - iter = callbackObjects.erase(iter); + iter = callback_objects.erase(iter); else ++iter; } @@ -1132,15 +1087,15 @@ void FWidget::delCallback (FWidget* cb_instance) FWidget::MemberCallbackObjects::iterator iter; // delete all member function pointer from cb_instance - if ( memberCallbackObjects.empty() ) + if ( member_callback_objects.empty() ) return; - iter = memberCallbackObjects.begin(); + iter = member_callback_objects.begin(); - while ( iter != memberCallbackObjects.end() ) + while ( iter != member_callback_objects.end() ) { if ( iter->cb_instance == cb_instance ) - iter = memberCallbackObjects.erase(iter); + iter = member_callback_objects.erase(iter); else ++iter; } @@ -1150,19 +1105,19 @@ void FWidget::delCallback (FWidget* cb_instance) inline void FWidget::delCallbacks() { // delete all callbacks from this widget - memberCallbackObjects.clear(); // member function pointer - callbackObjects.clear(); // function pointer + member_callback_objects.clear(); // member function pointer + callback_objects.clear(); // function pointer } //---------------------------------------------------------------------- void FWidget::emitCallback (FString emit_signal) { // member function pointer - if ( ! memberCallbackObjects.empty() ) + if ( ! member_callback_objects.empty() ) { FWidget::MemberCallbackObjects::const_iterator m_iter, m_end; - m_iter = memberCallbackObjects.begin(); - m_end = memberCallbackObjects.end(); + m_iter = member_callback_objects.begin(); + m_end = member_callback_objects.end(); while ( m_iter != m_end ) { @@ -1178,11 +1133,11 @@ void FWidget::emitCallback (FString emit_signal) } // function pointer - if ( ! callbackObjects.empty() ) + if ( ! callback_objects.empty() ) { FWidget::CallbackObjects::const_iterator iter, end; - iter = callbackObjects.begin(); - end = callbackObjects.end(); + iter = callback_objects.begin(); + end = callback_objects.end(); while ( iter != end ) { @@ -1331,7 +1286,7 @@ void FWidget::redraw() { FWidget* widget = static_cast(*iter); - if ( widget->isVisible() && ! widget->isWindow() ) + if ( widget->isVisible() && ! widget->isWindowWidget() ) widget->redraw(); ++iter; @@ -1355,14 +1310,14 @@ void FWidget::resize() { if ( isRootWidget() && openConsole() == 0 ) { - getTermGeometry(); + getTermSize(); closeConsole(); resizeVTerm(); resizeArea (vdesktop); if ( menubar ) { - menubar->setGeometry(1, 1, width, 1, false); + menubar->setGeometry(1, 1, getWidth(), 1, false); if ( vmenubar ) resizeArea(vmenubar); @@ -1370,7 +1325,7 @@ void FWidget::resize() if ( statusbar ) { - statusbar->setGeometry(1, height, width, 1, false); + statusbar->setGeometry(1, getHeight(), getWidth(), 1, false); if ( vstatusbar ) resizeArea(vstatusbar); @@ -1382,10 +1337,10 @@ void FWidget::resize() adjustSize(); // resize the four double-flatline-masks - double_flatline_mask.top.resize (uLong(width), false); - double_flatline_mask.right.resize (uLong(height), false); - double_flatline_mask.bottom.resize (uLong(width), false); - double_flatline_mask.left.resize (uLong(height), false); + double_flatline_mask.top.resize (uLong(getWidth()), false); + double_flatline_mask.right.resize (uLong(getHeight()), false); + double_flatline_mask.bottom.resize (uLong(getWidth()), false); + double_flatline_mask.left.resize (uLong(getHeight()), false); } //---------------------------------------------------------------------- @@ -1443,7 +1398,7 @@ void FWidget::hide() visible = false; shown = false; - if ( ! isDialog() + if ( ! isDialogWidget() && FWidget::getFocusWidget() == this && ! focusPrevChild() ) { @@ -1501,13 +1456,13 @@ bool FWidget::focusFirstChild() if ( widget->isEnabled() && widget->acceptFocus() - && ! widget->isMenu() ) + && ! widget->isMenuWidget() ) { widget->setFocus(); if ( widget->numOfChildren() >= 1 ) { - if ( ! widget->focusFirstChild() && widget->isWindow() ) + if ( ! widget->focusFirstChild() && widget->isWindowWidget() ) { ++iter; continue; @@ -1544,13 +1499,13 @@ bool FWidget::focusLastChild() if ( widget->isEnabled() && widget->acceptFocus() - && ! widget->isMenu() ) + && ! widget->isMenuWidget() ) { widget->setFocus(); if ( widget->numOfChildren() >= 1 ) { - if ( ! widget->focusLastChild() && widget->isWindow() ) + if ( ! widget->focusLastChild() && widget->isWindowWidget() ) continue; } @@ -1581,8 +1536,8 @@ bool FWidget::setFocus (bool on) if ( FWidget::getFocusWidget() ) FWidget::getFocusWidget()->unsetFocus(); - if ( (!isDialog() && focusable_children == 0) - || (isDialog() && focusable_children == 1) ) + if ( (!isDialogWidget() && focusable_children == 0) + || (isDialogWidget() && focusable_children == 1) ) { FWidget::setFocusWidget(this); } @@ -1607,6 +1562,14 @@ bool FWidget::setFocus (bool on) return focus = (on) ? true : false; } +//---------------------------------------------------------------------- +void FWidget::setColor () +{ + // Changes colors to the widget default colors + next_attribute.fg_color = foreground_color; + next_attribute.bg_color = background_color; +} + //---------------------------------------------------------------------- void FWidget::setColor (register short fg, register short bg) { @@ -1618,21 +1581,14 @@ void FWidget::setColor (register short fg, register short bg) //---------------------------------------------------------------------- void FWidget::setX (int x, bool adjust) { - if ( xpos == x && widgetSize.getX() == x ) + if ( getX() == x && wsize.getX() == x ) return; - if ( ! isWindow() ) - { - (x > 0) ? xpos = x : xpos = 1; - } - else - xpos = x; + if ( ! isWindowWidget() && x < 1 ) + x = 1; - widgetSize.setX(xpos); - adjustWidgetSize.setX(xpos); - adjustWidgetSizeShadow = adjustWidgetSize + shadow; - adjustWidgetSizeGlobal.setX(xpos + xmin - 1); - adjustWidgetSizeGlobalShadow = adjustWidgetSizeGlobal + shadow; + wsize.setX(x); + adjust_wsize.setX(x); if ( adjust ) adjustSize(); @@ -1641,21 +1597,14 @@ void FWidget::setX (int x, bool adjust) //---------------------------------------------------------------------- void FWidget::setY (int y, bool adjust) { - if ( ypos == y && widgetSize.getY() == y ) + if ( getY() == y && wsize.getY() == y ) return; - if ( ! isWindow() ) - { - (y > 0) ? ypos = y : ypos = 1; - } - else - ypos = y; + if ( ! isWindowWidget() && y < 1 ) + y = 1; - widgetSize.setY(ypos); - adjustWidgetSize.setY(ypos); - adjustWidgetSizeShadow = adjustWidgetSize + shadow; - adjustWidgetSizeGlobal.setY(ypos + ymin - 1); - adjustWidgetSizeGlobalShadow = adjustWidgetSizeGlobal + shadow; + wsize.setY(y); + adjust_wsize.setY(y); if ( adjust ) adjustSize(); @@ -1664,89 +1613,127 @@ void FWidget::setY (int y, bool adjust) //---------------------------------------------------------------------- void FWidget::setPos (int x, int y, bool adjust) { - if ( xpos == x && widgetSize.getX() == x - && ypos == y && widgetSize.getY() == y ) + if ( getX() == x && wsize.getX() == x + && getY() == y && wsize.getY() == y ) { return; } - if ( ! isWindow() ) + if ( ! isWindowWidget() ) { - (x > 0) ? xpos = x : xpos = 1; - (y > 0) ? ypos = y : ypos = 1; + if ( x < 1 ) + x = 1; + + if ( y < 1 ) + y = 1; + + wsize.setX(x); + wsize.setY(y); + adjust_wsize.setX(x); + adjust_wsize.setY(y); } else { - xpos = x; - ypos = y; + wsize.setPos(x,y); + adjust_wsize.setPos(x,y); } - widgetSize.setPos(xpos,ypos); - adjustWidgetSize.setPos(xpos,ypos); - adjustWidgetSizeShadow = adjustWidgetSize + shadow; - adjustWidgetSizeGlobal.setPos(xpos + xmin - 1, ypos + ymin - 1); - adjustWidgetSizeGlobalShadow = adjustWidgetSizeGlobal + shadow; - if ( adjust ) adjustSize(); } //---------------------------------------------------------------------- -void FWidget::setWidth (int w, bool adjust) +void FWidget::setWidth (int width, bool adjust) { - if ( width == w && widgetSize.getWidth() == w ) + width = std::min (width, size_hints.max_width); + width = std::max (width, size_hints.min_width); + + if ( getWidth() == width && wsize.getWidth() == width ) return; - (w > 0) ? width = w : width = 1; + if ( width < 1 ) + width = 1; - widgetSize.setWidth(width); - adjustWidgetSize.setWidth(width); - adjustWidgetSizeShadow = adjustWidgetSize + shadow; - adjustWidgetSizeGlobal.setWidth(width); - adjustWidgetSizeGlobalShadow = adjustWidgetSizeGlobal + shadow; + wsize.setWidth(width); + adjust_wsize.setWidth(width); if ( adjust ) adjustSize(); - double_flatline_mask.top.resize (uLong(width), false); - double_flatline_mask.bottom.resize (uLong(width), false); + double_flatline_mask.top.resize (uLong(getWidth()), false); + double_flatline_mask.bottom.resize (uLong(getWidth()), false); } //---------------------------------------------------------------------- -void FWidget::setHeight (int h, bool adjust) +void FWidget::setHeight (int height, bool adjust) { - if ( height == h && widgetSize.getHeight() == h ) + height = std::min (height, size_hints.max_height); + height = std::max (height, size_hints.min_height); + + if ( getHeight() == height && wsize.getHeight() == height ) return; - (h > 0) ? height = h : height = 1; + if ( height < 1 ) + height = 1; - widgetSize.setHeight(height); - adjustWidgetSize.setHeight(height); - adjustWidgetSizeShadow = adjustWidgetSize + shadow; - adjustWidgetSizeGlobal.setHeight(height); - adjustWidgetSizeGlobalShadow = adjustWidgetSizeGlobal + shadow; + wsize.setHeight(height); + adjust_wsize.setHeight(height); if ( adjust ) adjustSize(); - double_flatline_mask.right.resize (uLong(height), false); - double_flatline_mask.left.resize (uLong(height), false); + double_flatline_mask.right.resize (uLong(getHeight()), false); + double_flatline_mask.left.resize (uLong(getHeight()), false); } //---------------------------------------------------------------------- -void FWidget::setTopPadding (int t, bool adjust) +void FWidget::setSize (int width, int height, bool adjust) { - if ( top_padding == t ) + width = std::min (width, size_hints.max_width); + width = std::max (width, size_hints.min_width); + height = std::min (height, size_hints.max_height); + height = std::max (height, size_hints.min_height); + + if ( getWidth() == width && wsize.getWidth() == width ) return; - (t > 0) ? top_padding = t : top_padding = 0; + if ( getHeight() == height && wsize.getHeight() == height ) + return; + + if ( width < 1 ) + width = 1; + + if ( height < 1 ) + height = 1; + + wsize.setWidth(width); + wsize.setHeight(height); + adjust_wsize.setWidth(width); + adjust_wsize.setHeight(height); + + if ( adjust ) + adjustSize(); + + double_flatline_mask.top.resize (uLong(getWidth()), false); + double_flatline_mask.right.resize (uLong(getHeight()), false); + double_flatline_mask.bottom.resize (uLong(getWidth()), false); + double_flatline_mask.left.resize (uLong(getHeight()), false); +} + +//---------------------------------------------------------------------- +void FWidget::setTopPadding (int top, bool adjust) +{ + if ( padding.top == top ) + return; + + (top < 0) ? padding.top = 0 : padding.top = top; if ( adjust ) { if ( isRootWidget() ) { - FWidget* r_obj = rootObject; - r_obj->client_ymin = 1 + r_obj->top_padding; + FWidget* r = rootObject; + r->client_offset.setY1 (r->padding.top); adjustSizeGlobal(); } else @@ -1755,19 +1742,19 @@ void FWidget::setTopPadding (int t, bool adjust) } //---------------------------------------------------------------------- -void FWidget::setLeftPadding (int l, bool adjust) +void FWidget::setLeftPadding (int left, bool adjust) { - if ( left_padding == l ) + if ( padding.left == left ) return; - (l > 0) ? left_padding = l : left_padding = 0; + (left < 0) ? padding.left = 0 : padding.left = left; if ( adjust ) { if ( isRootWidget() ) { - FWidget* r_obj = rootObject; - r_obj->client_xmin = 1 + r_obj->left_padding; + FWidget* r = rootObject; + r->client_offset.setX1 (r->padding.left); adjustSizeGlobal(); } else @@ -1776,19 +1763,19 @@ void FWidget::setLeftPadding (int l, bool adjust) } //---------------------------------------------------------------------- -void FWidget::setBottomPadding (int b, bool adjust) +void FWidget::setBottomPadding (int bottom, bool adjust) { - if ( bottom_padding == b ) + if ( padding.bottom == bottom ) return; - (b > 0) ? bottom_padding = b : bottom_padding = 0; + (bottom < 0) ? padding.bottom = 0 : padding.bottom = bottom; if ( adjust ) { if ( isRootWidget() ) { - FWidget* r_obj = rootObject; - r_obj->client_ymax = r_obj->height - r_obj->bottom_padding; + FWidget* r = rootObject; + r->client_offset.setY2 (r->getHeight() - 1 - r->padding.bottom); adjustSizeGlobal(); } else @@ -1797,19 +1784,19 @@ void FWidget::setBottomPadding (int b, bool adjust) } //---------------------------------------------------------------------- -void FWidget::setRightPadding (int r, bool adjust) +void FWidget::setRightPadding (int right, bool adjust) { - if ( right_padding == r ) + if ( padding.right == right ) return; - (r > 0) ? right_padding = r : right_padding = 0; + (right < 0) ? padding.right = 0 : padding.right = right; if ( adjust ) { if ( isRootWidget() ) { - FWidget* r_obj = rootObject; - r_obj->client_xmax = r_obj->width - r_obj->right_padding; + FWidget* r = rootObject; + r->client_offset.setX2 (r->getWidth() - 1 - r->padding.right); adjustSizeGlobal(); } else @@ -1818,84 +1805,108 @@ void FWidget::setRightPadding (int r, bool adjust) } //---------------------------------------------------------------------- -void FWidget::getTermGeometry() +void FWidget::setParentOffset() { - FWidget* r_obj = rootObject; + FWidget* p = getParentWidget(); + + if ( p ) + offset = p->client_offset; +} + +//---------------------------------------------------------------------- +void FWidget::setTermOffset() +{ + FWidget* r = getRootWidget(); + int w = r->getWidth(); + int h = r->getHeight(); + offset.setCoordinates (0, 0, w - 1, h - 1); +} + +//---------------------------------------------------------------------- +void FWidget::setTermOffsetWithPadding() +{ + FWidget* r = getRootWidget(); + offset.setCoordinates ( r->getLeftPadding() + , r->getTopPadding() + , r->getWidth() - 1 - r->getRightPadding() + , r->getHeight() - 1 - r->getBottomPadding() ); +} + +//---------------------------------------------------------------------- +void FWidget::getTermSize() +{ + FWidget* r = rootObject; if ( openConsole() == 0 ) { - getTermSize(); + FTerm::getTermSize(); closeConsole(); } - 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; + r->adjust_wsize.setRect (1, 1, term->getWidth(), term->getHeight()); + r->offset.setRect (0, 0, term->getWidth(), term->getHeight()); + r->client_offset.setCoordinates + ( + r->padding.left, + r->padding.top, + term->getWidth() - 1 - r->padding.right, + term->getHeight() - 1 - r->padding.bottom + ); } //---------------------------------------------------------------------- -void FWidget::setTermGeometry (int w, int h) +void FWidget::setTermSize (int w, int h) { // Set xterm size to w x h if ( xterm ) { - 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(); + rootObject->wsize.setRect(1, 1, w, h); + rootObject->adjust_wsize = rootObject->wsize; + FTerm::setTermSize (w, h); // w = columns / h = lines + getTermSize(); } } //---------------------------------------------------------------------- void FWidget::setGeometry (int x, int y, int w, int h, bool adjust) { - int global_x, global_y; + int term_x, term_y; - if ( xpos == x && ypos == y && width == w && height == h ) + w = std::min (w, size_hints.max_width); + w = std::max (w, size_hints.min_width); + h = std::min (h, size_hints.max_height); + h = std::max (h, size_hints.min_height); + + if ( getX() == x && getY() == y && getWidth() == w && getHeight() == h ) return; - if ( ! isWindow() ) + if ( ! isWindowWidget() ) { - (x > 0) ? xpos = x : xpos = 1; - (y > 0) ? ypos = y : ypos = 1; + (x < 1) ? wsize.setX(1) : wsize.setX(x); + (y < 1) ? wsize.setY(1) : wsize.setY(y); } else { - xpos = x; - ypos = y; + wsize.setX(x); + wsize.setY(y); } - (w > 0) ? width = w : width = 1; - (h > 0) ? height = h : height = 1; + (w < 1) ? wsize.setWidth(1) : wsize.setWidth(w); + (h < 1) ? wsize.setHeight(1) : wsize.setHeight(h); - client_xmin = xpos + xmin - 1 + left_padding; - client_ymin = ypos + ymin - 1 + top_padding; - client_xmax = xpos + xmin - 2 + width - right_padding; - client_ymax = ypos + ymin - 2 + height - bottom_padding; + adjust_wsize = wsize; + term_x = getTermX(); + term_y = getTermY(); - widgetSize.setRect (xpos, ypos, width, height); - adjustWidgetSize.setRect (xpos, ypos, width, height); - adjustWidgetSizeShadow = adjustWidgetSize + shadow; - global_x = xpos + xmin - 1; - global_y = ypos + ymin - 1; - adjustWidgetSizeGlobal.setRect (global_x, global_y, width, height); - adjustWidgetSizeGlobalShadow = adjustWidgetSizeGlobal + shadow; + client_offset.setCoordinates ( term_x - 1 + padding.left + , term_y - 1 + padding.top + , term_x - 2 + getWidth() - padding.right + , term_y - 2 + getHeight() - padding.bottom ); - double_flatline_mask.top.resize (uLong(width), false); - double_flatline_mask.right.resize (uLong(height), false); - double_flatline_mask.bottom.resize (uLong(width), false); - double_flatline_mask.left.resize (uLong(height), false); + double_flatline_mask.top.resize (uLong(getWidth()), false); + double_flatline_mask.right.resize (uLong(getHeight()), false); + double_flatline_mask.bottom.resize (uLong(getWidth()), false); + double_flatline_mask.left.resize (uLong(getHeight()), false); if ( adjust ) adjustSize(); @@ -1904,20 +1915,15 @@ void FWidget::setGeometry (int x, int y, int w, int h, bool adjust) //---------------------------------------------------------------------- void FWidget::move (int x, int y) { - if ( x == xpos && y == ypos ) + if ( adjust_wsize.getX() == x && adjust_wsize.getY() == y ) return; // Avoid to move widget completely outside the terminal - if ( x+width < 1 || x > term->getWidth() || y < 1 || y > term->getHeight() ) + if ( x+getWidth() < 1 || x > term->getWidth() || y < 1 || y > term->getHeight() ) return; - xpos = x; - ypos = y; - widgetSize.setPos(x,y); - adjustWidgetSize.setPos(x,y); - adjustWidgetSizeShadow = adjustWidgetSize + shadow; - adjustWidgetSizeGlobal.setPos(x + xmin - 1, y + ymin - 1); - adjustWidgetSizeGlobalShadow = adjustWidgetSizeGlobal + shadow; + wsize.setPos(x,y); + adjust_wsize.setPos(x,y); } //---------------------------------------------------------------------- @@ -1927,7 +1933,8 @@ bool FWidget::setCursor() if ( isCursorInside() ) { - setTermXY (wcursor->getX()-1, wcursor->getY()-1); + setTermXY ( getTermX() + wcursor->getX() - 2 + , getTermY() + wcursor->getY() - 2 ); return true; } else @@ -1961,15 +1968,15 @@ void FWidget::drawShadow() return; } - x1 = xpos+xmin-1; - x2 = xpos+xmin-2+width; - y1 = ypos+ymin-1; - y2 = ypos+ymin-2+height; + x1 = 1; + x2 = getWidth(); + y1 = 1; + y2 = getHeight(); if ( trans_shadow ) { // transparent shadow - gotoxy (x2+1, y1); + printPos (x2+1, y1); setTransparent(); print (" "); unsetTransparent(); @@ -1977,14 +1984,14 @@ void FWidget::drawShadow() setColor (wc.shadow_bg, wc.shadow_fg); setTransShadow(); - for (int i=1; i < height; i++) + for (int i=1; i < getHeight(); i++) { - gotoxy (x2+1, y1+i); + printPos (x2+1, y1+i); print (" "); } unsetTransShadow(); - gotoxy (x1, y2+1); + printPos (x1, y2+1); setTransparent(); print (" "); unsetTransparent(); @@ -1992,7 +1999,7 @@ void FWidget::drawShadow() setColor (wc.shadow_bg, wc.shadow_fg); setTransShadow(); - for (int i=2; i <= width+1; i++) + for (int i=2; i <= getWidth()+1; i++) print (' '); unsetTransShadow(); @@ -2004,9 +2011,9 @@ void FWidget::drawShadow() { // non-transparent shadow int block; - gotoxy (x2+1, y1); + printPos (x2+1, y1); - if ( isWindow() ) + if ( isWindowWidget() ) { setColor (wc.shadow_fg, wc.shadow_bg); setInheritBackground(); // current background color will be ignored @@ -2026,21 +2033,21 @@ void FWidget::drawShadow() print (fc::LowerHalfBlock); // ▄ } - if ( isWindow() ) + if ( isWindowWidget() ) unsetInheritBackground(); - for (int i=1; i < height; i++) + for (int i=1; i < getHeight(); i++) { - gotoxy (x2+1, y1+i); + printPos (x2+1, y1+i); print (block); // █ } - gotoxy (x1+1, y2+1); + printPos (x1+1, y2+1); - if ( isWindow() ) + if ( isWindowWidget() ) setInheritBackground(); - for (int i=1; i <= width; i++) + for (int i=1; i <= getWidth(); i++) { if ( isTeraTerm() ) print (0xdf); // ▀ @@ -2048,7 +2055,7 @@ void FWidget::drawShadow() print (fc::UpperHalfBlock); // ▀ } - if ( isWindow() ) + if ( isWindowWidget() ) unsetInheritBackground(); } } @@ -2061,12 +2068,12 @@ void FWidget::clearShadow() if ( isMonochron() ) return; - x1 = xpos+xmin-1; - x2 = xpos+xmin-2+width; - y1 = ypos+ymin-1; - y2 = ypos+ymin-2+height; + x1 = 1; + x2 = getWidth(); + y1 = 1; + y2 = getHeight(); - if ( isWindow() ) + if ( isWindowWidget() ) { setColor (wc.shadow_fg, wc.shadow_bg); setInheritBackground(); // current background color will be ignored @@ -2074,24 +2081,24 @@ void FWidget::clearShadow() else if ( FWidget* p = getParentWidget() ) setColor (wc.shadow_fg, p->getBackgroundColor()); - if ( x2 < xmax ) + if ( x2 < offset.getX2() + 1 ) { - for (int i=0; i < height; i++) + for (int i=0; i < getHeight(); i++) { - gotoxy (x2+1, y1+i); + printPos (x2+1, y1+i); print (' '); // clear █ } } - if ( y2 < ymax ) + if ( y2 < offset.getY2() + 1 ) { - gotoxy (x1+1, y2+1); + printPos (x1+1, y2+1); - for (int i=1; i <= width; i++) + for (int i=1; i <= getWidth(); i++) print (' '); // clear ▀ } - if ( isWindow() ) + if ( isWindowWidget() ) unsetInheritBackground(); } @@ -2103,19 +2110,19 @@ void FWidget::drawFlatBorder() if ( ! isNewFont() ) return; - x1 = xpos+xmin-1; - x2 = xpos+xmin-1+width; - y1 = ypos+ymin-2; - y2 = ypos+ymin-1+height; + x1 = 1; + x2 = getWidth() + 1; + y1 = 0; + y2 = getHeight() + 1; if ( FWidget* p = getParentWidget() ) setColor (wc.dialog_fg, p->getBackgroundColor()); else setColor (wc.dialog_fg, wc.dialog_bg); - for (int y=0; y < height; y++) + for (int y=0; y < getHeight(); y++) { - gotoxy (x1-1, y1+y+1); + printPos (x1-1, y1+y+1); if ( double_flatline_mask.left[uLong(y)] ) print (fc::NF_rev_border_line_right_and_left); // left+right line (on left side) @@ -2123,21 +2130,21 @@ void FWidget::drawFlatBorder() print (fc::NF_rev_border_line_right); // right line (on left side) } - gotoxy (x2, y1+1); + printPos (x2, y1+1); - for (int y=0; y < height; y++) + for (int y=0; y < getHeight(); y++) { if ( double_flatline_mask.right[uLong(y)] ) print (fc::NF_rev_border_line_right_and_left); // left+right line (on right side) else print (fc::NF_border_line_left); // left line (on right side) - gotoxy (x2, y1+y+2); + printPos (x2, y1+y+2); } - gotoxy (x1, y1); + printPos (x1, y1); - for (int x=0; x < width; x++) + for (int x=0; x < getWidth(); x++) { if ( double_flatline_mask.top[uLong(x)] ) print (fc::NF_border_line_up_and_down); // top+bottom line (at top) @@ -2145,9 +2152,9 @@ void FWidget::drawFlatBorder() print (fc::NF_border_line_bottom); // bottom line (at top) } - gotoxy (x1, y2); + printPos (x1, y2); - for (int x=0; x < width; x++) + for (int x=0; x < getWidth(); x++) { if ( double_flatline_mask.bottom[uLong(x)] ) print (fc::NF_border_line_up_and_down); // top+bottom line (at bottom) @@ -2164,10 +2171,10 @@ void FWidget::clearFlatBorder() if ( ! isNewFont() ) return; - x1 = xpos+xmin-1; - x2 = xpos+xmin-1+width; - y1 = ypos+ymin-2; - y2 = ypos+ymin-1+height; + x1 = 1; + x2 = getWidth() + 1; + y1 = 0; + y2 = getHeight() + 1; if ( FWidget* p = getParentWidget() ) setColor (wc.dialog_fg, p->getBackgroundColor()); @@ -2175,9 +2182,9 @@ void FWidget::clearFlatBorder() setColor (wc.dialog_fg, wc.dialog_bg); // clear on left side - for (register int y=0; y < height; y++) + for (register int y=0; y < getHeight(); y++) { - gotoxy (x1-1, y1+y+1); + printPos (x1-1, y1+y+1); if ( double_flatline_mask.left[uLong(y)] ) print (fc::NF_border_line_left); @@ -2186,9 +2193,9 @@ void FWidget::clearFlatBorder() } // clear on right side - for (register int y=0; y < height; y++) + for (register int y=0; y < getHeight(); y++) { - gotoxy (x2, y1+y+1); + printPos (x2, y1+y+1); if ( double_flatline_mask.right[uLong(y)] ) print (fc::NF_rev_border_line_right); @@ -2197,9 +2204,9 @@ void FWidget::clearFlatBorder() } // clear at top - gotoxy (x1, y1); + printPos (x1, y1); - for (register int x=0; x < width; x++) + for (register int x=0; x < getWidth(); x++) { if ( double_flatline_mask.top[uLong(x)] ) print (fc::NF_border_line_upper); @@ -2208,9 +2215,9 @@ void FWidget::clearFlatBorder() } // clear at bottom - gotoxy (x1, y2); + printPos (x1, y2); - for (register int x=0; x < width; x++) + for (register int x=0; x < getWidth(); x++) { if ( double_flatline_mask.bottom[uLong(x)] ) print (fc::NF_border_line_bottom); @@ -2222,7 +2229,7 @@ void FWidget::clearFlatBorder() //---------------------------------------------------------------------- void FWidget::setDoubleFlatLine (int side, bool bit) { - uLong size; + uLong length; assert ( side == fc::top || side == fc::right @@ -2232,23 +2239,23 @@ void FWidget::setDoubleFlatLine (int side, bool bit) switch ( side ) { case fc::top: - size = double_flatline_mask.top.size(); - double_flatline_mask.top.assign(size, bit); + length = double_flatline_mask.top.size(); + double_flatline_mask.top.assign(length, bit); break; case fc::right: - size = double_flatline_mask.right.size(); - double_flatline_mask.right.assign(size, bit); + length = double_flatline_mask.right.size(); + double_flatline_mask.right.assign(length, bit); break; case fc::bottom: - size = double_flatline_mask.bottom.size(); - double_flatline_mask.bottom.assign(size, bit); + length = double_flatline_mask.bottom.size(); + double_flatline_mask.bottom.assign(length, bit); break; case fc::left: - size = double_flatline_mask.left.size(); - double_flatline_mask.left.assign(size, bit); + length = double_flatline_mask.left.size(); + double_flatline_mask.left.assign(length, bit); break; default: @@ -2259,7 +2266,7 @@ void FWidget::setDoubleFlatLine (int side, bool bit) //---------------------------------------------------------------------- void FWidget::setDoubleFlatLine (int side, int pos, bool bit) { - uLong size, index; + uLong length, index; assert ( side == fc::top || side == fc::right @@ -2273,33 +2280,33 @@ void FWidget::setDoubleFlatLine (int side, int pos, bool bit) switch ( side ) { case fc::top: - size = double_flatline_mask.top.size(); + length = double_flatline_mask.top.size(); - if ( index < size ) + if ( index < length ) double_flatline_mask.top[index] = bit; break; case fc::right: - size = double_flatline_mask.right.size(); + length = double_flatline_mask.right.size(); - if ( index < size ) + if ( index < length ) double_flatline_mask.right[index] = bit; break; case fc::bottom: - size = double_flatline_mask.bottom.size(); + length = double_flatline_mask.bottom.size(); - if ( index < size ) + if ( index < length ) double_flatline_mask.bottom[index] = bit; break; case fc::left: - size = double_flatline_mask.left.size(); + length = double_flatline_mask.left.size(); - if ( index < size ) + if ( index < length ) double_flatline_mask.left[index] = bit; break; @@ -2335,26 +2342,25 @@ std::vector& FWidget::doubleFlatLine_ref (int side) } //---------------------------------------------------------------------- -void FWidget::drawBorder() +void FWidget::drawBorder (int x1, int x2, int y1, int y2) { - int x1, x2, y1, y2; + if ( x1 > x2 ) + std::swap (x1, x2); - x1 = xpos+xmin-1; - x2 = xpos+xmin-2+width; - y1 = ypos+ymin-1; - y2 = ypos+ymin-2+height; + if ( y1 > y2 ) + std::swap (y1, y2); - if ( x1 < xmin ) - x1 = xmin; + if ( x1 < 1 ) + x1 = 1; - if ( y1 < ymin ) - y1 = ymin; + if ( y1 < 1 ) + y1 = 1; - if ( x2 > xmax ) - x2 = xmax; + if ( x2 > getWidth() ) + x2 = getWidth(); - if ( y2 > ymax ) - y2 = ymax; + if ( y2 > getHeight() ) + y2 = getHeight(); if ( FWidget* p = getParentWidget() ) setColor (wc.dialog_fg, p->getBackgroundColor()); @@ -2363,7 +2369,7 @@ void FWidget::drawBorder() if ( isNewFont() ) { - gotoxy (x1, y1); + printPos (x1, y1); print (fc::NF_border_corner_middle_upper_left); // ┌ for (int x=x1+1; x < x2; x++) @@ -2373,13 +2379,13 @@ void FWidget::drawBorder() for (int y=y1+1; y <= y2; y++) { - gotoxy (x1, y); + printPos (x1, y); print (fc::NF_border_line_left); // border left ⎸ - gotoxy (x2, y); + printPos (x2, y); print (fc::NF_rev_border_line_right); // border right⎹ } - gotoxy (x1, y2); + printPos (x1, y2); print (fc::NF_border_corner_middle_lower_left); // └ for (int x=x1+1; x < x2; x++) @@ -2389,7 +2395,7 @@ void FWidget::drawBorder() } else { - gotoxy (x1, y1); + printPos (x1, y1); print (fc::BoxDrawingsDownAndRight); // ┌ for (int x=x1+1; x < x2; x++) @@ -2399,13 +2405,13 @@ void FWidget::drawBorder() for (int y=y1+1; y < y2; y++) { - gotoxy (x1, y); + printPos (x1, y); print (fc::BoxDrawingsVertical); // │ - gotoxy (x2, y); + printPos (x2, y); print (fc::BoxDrawingsVertical); // │ } - gotoxy (x1, y2); + printPos (x1, y2); print (fc::BoxDrawingsUpAndRight); // └ for (int x=x1+1; x < x2; x++) @@ -2415,9 +2421,9 @@ void FWidget::drawBorder() for (int x=x1+1; x < x2; x++) { - gotoxy (x, y1); + printPos (x, y1); print (fc::BoxDrawingsHorizontal); // ─ - gotoxy (x, y2); + printPos (x, y2); print (fc::BoxDrawingsHorizontal); // ─ } } diff --git a/src/fwidget.h b/src/fwidget.h index 55b9bf8e..cb66aaab 100644 --- a/src/fwidget.h +++ b/src/fwidget.h @@ -107,7 +107,7 @@ class FWidget : public FObject, public FTerm }; typedef std::vector CallbackObjects; - CallbackObjects callbackObjects; + CallbackObjects callback_objects; struct member_callback_data { @@ -118,7 +118,7 @@ class FWidget : public FObject, public FTerm }; typedef std::vector MemberCallbackObjects; - MemberCallbackObjects memberCallbackObjects; + MemberCallbackObjects member_callback_objects; struct accelerator { @@ -217,6 +217,44 @@ class FWidget : public FObject, public FTerm } wc; // widget_colors wc; + int flags; + static uInt modal_dialogs; + + private: + bool enable; + bool visible; + bool shown; + bool focus; + bool focusable; + bool visibleCursor; + FPoint widgetCursorPosition; + + struct widget_size_hints + { + widget_size_hints() + : min_width (INT_MIN) + , min_height (INT_MIN) + , max_width (INT_MAX) + , max_height (INT_MAX) + { } + ~widget_size_hints() + { } + void setMinimum (int w, int h) + { + min_width = w; + min_height = h; + } + void setMaximum (int w, int h) + { + max_width = w; + max_height = h; + } + int min_width; + int min_height; + int max_width; + int max_height; + } size_hints; + struct dbl_line_mask { dbl_line_mask() : top(), right(), bottom(), left() @@ -229,52 +267,45 @@ class FWidget : public FObject, public FTerm std::vector left; } double_flatline_mask; - int xpos; - int ypos; - int width; - int height; - int xmin; - int ymin; - int xmax; - int ymax; - int top_padding; - int left_padding; - int bottom_padding; - int right_padding; - int client_xmin; - int client_ymin; - int client_xmax; - int client_ymax; - FPoint shadow; - FRect adjustWidgetSizeShadow; - FRect adjustWidgetSizeGlobalShadow; - bool ignore_padding; - bool window_object; - bool dialog_object; - bool menu_object; - int flags; - short foregroundColor; - short backgroundColor; - static uInt modal_dialogs; + struct widget_padding + { + widget_padding() : top(0), left(0), bottom(0), right(0) + { } + ~widget_padding() + { } + int top; + int left; + int bottom; + int right; + } padding; - private: - bool enable; - bool visible; - bool shown; - bool focus; - bool focusable; - bool visibleCursor; - FPoint widgetCursorPosition; - FRect widgetSize; - FRect adjustWidgetSize; - FRect adjustWidgetSizeGlobal; - FString statusbar_message; + bool ignore_padding; + + // widget size + FRect wsize; + FRect adjust_wsize; + FRect adjust_wsize_term; + FRect adjust_wsize_shadow; + FRect adjust_wsize_term_shadow; + // widget offset + FRect offset; + // offset of the widget client area + FRect client_offset; + // widget shadow size (on the right and bottom side) + FPoint wshadow; + + // default widget foreground and background color + short foreground_color; + short background_color; + + term_area* print_area; + FString statusbar_message; static FStatusBar* statusbar; - static FMenuBar* menubar; - static FWidget* show_root_widget; - static FWidget* redraw_root_widget; - term_area* print_area; + static FMenuBar* menubar; + static FWidget* show_root_widget; + static FWidget* redraw_root_widget; + friend class FTerm; friend class FApplication; friend class FToggleButton; @@ -335,9 +366,9 @@ class FWidget : public FObject, public FTerm int numOfFocusableChildren(); FWidget* getParentWidget() const; bool isRootWidget() const; - bool isWindow() const; - bool isDialog() const; - bool isMenu() const; + bool isWindowWidget() const; + bool isDialogWidget() const; + bool isMenuWidget() const; virtual bool close(); static FStatusBar* statusBar(); @@ -401,9 +432,9 @@ class FWidget : public FObject, public FTerm int getX() const; int getY() const; const FPoint getPos() const; - int getGlobalX() const; - int getGlobalY() const; - const FPoint getGlobalPos() const; + int getTermX() const; + int getTermY() const; + const FPoint getTermPos() const; int getWidth() const; int getHeight() const; int getTopPadding() const; @@ -413,15 +444,16 @@ class FWidget : public FObject, public FTerm int getClientWidth() const; int getClientHeight() const; int getMaxWidth() const; - int getMinHeight() const; + int getMaxHeight() const; const FPoint& getShadow() const; const FRect& getGeometry() const; - const FRect& getGeometryShadow() const; - const FRect& getGeometryGlobal() const; - const FRect& getGeometryGlobalShadow() const; - FPoint globalToLocalPos (const FPoint&); + const FRect& getGeometryWithShadow(); + const FRect& getTermGeometry(); + const FRect& getTermGeometryWithShadow(); + FPoint termToWidgetPos (const FPoint&); void setForegroundColor (short); void setBackgroundColor (short); + void setColor(); void setColor (short, short); void setX (int, bool = true); void setY (int, bool = true); @@ -429,14 +461,22 @@ class FWidget : public FObject, public FTerm virtual void setPos (int, int, bool = true); void setWidth (int, bool = true); void setHeight (int, bool = true); + void setSize (int, int, bool = true); void setTopPadding (int, bool = true); void setLeftPadding (int, bool = true); void setBottomPadding (int, bool = true); void setRightPadding (int, bool = true); - void getTermGeometry(); - void setTermGeometry (int, int); + void setParentOffset(); + void setTermOffset(); + void setTermOffsetWithPadding(); + void getTermSize(); + void setTermSize (int, int); virtual void setGeometry (const FRect&, bool = true); virtual void setGeometry (int, int, int, int, bool = true); + void setShadowSize (int, int); + void setMinimumSize (int, int); + void setMaximumSize (int, int); + void setFixedSize (int, int); virtual void move (const FPoint&); virtual void move (int, int); int getFlags() const; @@ -447,8 +487,8 @@ class FWidget : public FObject, public FTerm bool setCursorPos (register int, register int); void unsetCursorPos(); - static void gotoxy (const FPoint&); - static void gotoxy (register int, register int); + void printPos (const FPoint&); + void printPos (register int, register int); static void setNormal(); @@ -541,6 +581,7 @@ class FWidget : public FObject, public FTerm void setDoubleFlatLine (int, int, bool = true); void unsetDoubleFlatLine (int, int); std::vector& doubleFlatLine_ref (int); + virtual void drawBorder (int, int, int, int); virtual void drawBorder(); static void quit(); @@ -602,16 +643,16 @@ inline bool FWidget::isShown() const { return shown; } //---------------------------------------------------------------------- -inline bool FWidget::isWindow() const -{ return window_object; } +inline bool FWidget::isWindowWidget() const +{ return ((flags & fc::window_widget) != 0); } //---------------------------------------------------------------------- -inline bool FWidget::isDialog() const -{ return dialog_object; } +inline bool FWidget::isDialogWidget() const +{ return ((flags & fc::dialog_widget) != 0); } //---------------------------------------------------------------------- -inline bool FWidget::isMenu() const -{ return menu_object; } +inline bool FWidget::isMenuWidget() const +{ return ((flags & fc::menu_widget) != 0); } //---------------------------------------------------------------------- inline bool FWidget::isEnabled() const @@ -671,41 +712,41 @@ inline void FWidget::unsetFocusable() //---------------------------------------------------------------------- inline short FWidget::getForegroundColor() const -{ return foregroundColor; } +{ return foreground_color; } //---------------------------------------------------------------------- inline short FWidget::getBackgroundColor() const -{ return backgroundColor; } +{ return background_color; } //---------------------------------------------------------------------- -inline int FWidget::getX() const -{ return xpos; } +inline int FWidget::getX() const // x-position relative to the widget +{ return adjust_wsize.getX(); } //---------------------------------------------------------------------- -inline int FWidget::getY() const -{ return ypos; } +inline int FWidget::getY() const // y-position relative to the widget +{ return adjust_wsize.getY(); } //---------------------------------------------------------------------- -inline const FPoint FWidget::getPos() const -{ return adjustWidgetSize.getPos(); } +inline const FPoint FWidget::getPos() const // position relative to the widget +{ return adjust_wsize.getPos(); } //---------------------------------------------------------------------- -inline int FWidget::getGlobalX() const -{ return xpos+xmin-1; } +inline int FWidget::getTermX() const // x-position on terminal +{ return offset.getX1() + adjust_wsize.getX(); } //---------------------------------------------------------------------- -inline int FWidget::getGlobalY() const -{ return ypos+ymin-1; } +inline int FWidget::getTermY() const // y-position on terminal +{ return offset.getY1() + adjust_wsize.getY(); } //---------------------------------------------------------------------- -inline const FPoint FWidget::getGlobalPos() const -{ return FPoint(xpos+xmin-1, ypos+ymin-1); } +inline const FPoint FWidget::getTermPos() const // position on terminal +{ return FPoint(getTermX(), getTermY()); } //---------------------------------------------------------------------- -inline FPoint FWidget::globalToLocalPos (const FPoint& gPos) +inline FPoint FWidget::termToWidgetPos (const FPoint& tPos) { - return FPoint ( gPos.getX() - xpos - xmin + 2 - , gPos.getY() - ypos - ymin + 2 ); + return FPoint ( tPos.getX() + 1 - offset.getX1() - adjust_wsize.getX() + , tPos.getY() + 1 - offset.getY1() - adjust_wsize.getY() ); } //---------------------------------------------------------------------- @@ -713,7 +754,7 @@ inline void FWidget::setForegroundColor (short color) { // valid colors -1..254 if ( color == fc::Default || color >> 8 == 0 ) - foregroundColor = color; + foreground_color = color; } //---------------------------------------------------------------------- @@ -721,7 +762,7 @@ inline void FWidget::setBackgroundColor (short color) { // valid colors -1..254 if ( color == fc::Default || color >> 8 == 0 ) - backgroundColor = color; + background_color = color; } //---------------------------------------------------------------------- @@ -730,63 +771,90 @@ inline void FWidget::setPos (const FPoint& p, bool adjust) //---------------------------------------------------------------------- inline int FWidget::getWidth() const -{ return width; } +{ return adjust_wsize.getWidth(); } //---------------------------------------------------------------------- inline int FWidget::getHeight() const -{ return height; } +{ return adjust_wsize.getHeight(); } //---------------------------------------------------------------------- inline int FWidget::getTopPadding() const -{ return top_padding; } +{ return padding.top; } //---------------------------------------------------------------------- inline int FWidget::getLeftPadding() const -{ return left_padding; } +{ return padding.left; } //---------------------------------------------------------------------- inline int FWidget::getBottomPadding() const -{ return bottom_padding; } +{ return padding.bottom; } //---------------------------------------------------------------------- inline int FWidget::getRightPadding() const -{ return right_padding; } +{ return padding.right; } //---------------------------------------------------------------------- inline int FWidget::getClientWidth() const -{ return client_xmax-client_xmin+1; } +{ return client_offset.getWidth(); } //---------------------------------------------------------------------- inline int FWidget::getClientHeight() const -{ return client_ymax-client_ymin+1; } +{ return client_offset.getHeight(); } //---------------------------------------------------------------------- inline int FWidget::getMaxWidth() const -{ return xmax-xmin+1; } +{ return offset.getWidth(); } //---------------------------------------------------------------------- -inline int FWidget::getMinHeight() const -{ return ymax-ymin+1; } +inline int FWidget::getMaxHeight() const +{ return offset.getHeight(); } //---------------------------------------------------------------------- inline const FPoint& FWidget::getShadow() const -{ return shadow; } +{ return wshadow; } //---------------------------------------------------------------------- inline const FRect& FWidget::getGeometry() const -{ return adjustWidgetSize; } +{ return adjust_wsize; } //---------------------------------------------------------------------- -inline const FRect& FWidget::getGeometryShadow() const -{ return adjustWidgetSizeShadow; } +inline const FRect& FWidget::getGeometryWithShadow() +{ + adjust_wsize_shadow.setCoordinates + ( + adjust_wsize.x1_ref(), + adjust_wsize.y1_ref(), + adjust_wsize.x2_ref() + wshadow.x_ref(), + adjust_wsize.y2_ref() + wshadow.y_ref() + ); + return adjust_wsize_shadow; +} //---------------------------------------------------------------------- -inline const FRect& FWidget::getGeometryGlobal() const -{ return adjustWidgetSizeGlobal; } +inline const FRect& FWidget::getTermGeometry() +{ + adjust_wsize_term.setCoordinates + ( + adjust_wsize.x1_ref() + offset.x1_ref(), + adjust_wsize.y1_ref() + offset.y1_ref(), + adjust_wsize.x2_ref() + offset.x1_ref(), + adjust_wsize.y2_ref() + offset.y1_ref() + ); + return adjust_wsize_term; +} //---------------------------------------------------------------------- -inline const FRect& FWidget::getGeometryGlobalShadow() const -{ return adjustWidgetSizeGlobalShadow; } +inline const FRect& FWidget::getTermGeometryWithShadow() +{ + adjust_wsize_term_shadow.setCoordinates + ( + adjust_wsize.x1_ref() + offset.x1_ref(), + adjust_wsize.y1_ref() + offset.y1_ref(), + adjust_wsize.x2_ref() + offset.x1_ref() + wshadow.x_ref(), + adjust_wsize.y2_ref() + offset.y1_ref() + wshadow.y_ref() + ); + return adjust_wsize_term_shadow; +} //---------------------------------------------------------------------- inline void FWidget::setGeometry (const FRect& box, bool adjust) @@ -798,6 +866,25 @@ inline void FWidget::setGeometry (const FRect& box, bool adjust) , adjust ); } +//---------------------------------------------------------------------- +inline void FWidget::setShadowSize (int right, int bottom) +{ wshadow.setPoint (right, bottom); } + +//---------------------------------------------------------------------- +inline void FWidget::setMinimumSize (int min_width, int min_height) +{ size_hints.setMinimum (min_width, min_height); } + +//---------------------------------------------------------------------- +inline void FWidget::setMaximumSize (int max_width, int max_height) +{ size_hints.setMaximum (max_width, max_height); } + +//---------------------------------------------------------------------- +inline void FWidget::setFixedSize (int width, int height) +{ + size_hints.setMinimum (width, height); + size_hints.setMaximum (width, height); +} + //---------------------------------------------------------------------- inline void FWidget::move (const FPoint& pos) { move( pos.getX(), pos.getY() ); } @@ -819,12 +906,15 @@ inline void FWidget::unsetCursorPos() { widgetCursorPosition.setPoint(-1,-1); } //---------------------------------------------------------------------- -inline void FWidget::gotoxy (const FPoint& pos) -{ gotoxy (pos.getX(), pos.getY()); } +inline void FWidget::printPos (const FPoint& pos) +{ printPos (pos.getX(), pos.getY()); } //---------------------------------------------------------------------- -inline void FWidget::gotoxy (register int x, register int y) -{ cursor->setPoint(x,y); } +inline void FWidget::printPos (register int x, register int y) +{ + cursor->setPoint ( offset.getX1() + adjust_wsize.getX() - 1 + x, + offset.getY1() + adjust_wsize.getY() - 1 + y ); +} //---------------------------------------------------------------------- inline void FWidget::setNormal() @@ -1107,13 +1197,17 @@ inline bool FWidget::isInheritBackground() { return next_attribute.inherit_bg; } //---------------------------------------------------------------------- -inline void FWidget::unsetDoubleFlatLine(int side) +inline void FWidget::unsetDoubleFlatLine (int side) { setDoubleFlatLine(side, false); } //---------------------------------------------------------------------- -inline void FWidget::unsetDoubleFlatLine(int side, int pos) +inline void FWidget::unsetDoubleFlatLine (int side, int pos) { setDoubleFlatLine(side, pos, false); } +//---------------------------------------------------------------------- +inline void FWidget::drawBorder() +{ drawBorder (1, getWidth(), 1, getHeight()); } + // NewFont elements //---------------------------------------------------------------------- diff --git a/src/fwindow.cpp b/src/fwindow.cpp index cbc801b6..9598060d 100644 --- a/src/fwindow.cpp +++ b/src/fwindow.cpp @@ -21,10 +21,8 @@ FWindow::FWindow(FWidget* parent) , zoomed(false) , win_focus_widget(0) , normalGeometry() - , maxGeometry() - , minGeometry() { - window_object = true; + setWindowWidget(); } //---------------------------------------------------------------------- @@ -79,6 +77,15 @@ void FWindow::onWindowRaised (FEvent*) void FWindow::onWindowLowered (FEvent*) { } +//---------------------------------------------------------------------- +void FWindow::adjustSize() +{ + FWidget::adjustSize(); + + if ( zoomed ) + setGeometry (1, 1, getMaxWidth(), getMaxHeight(), false); +} + // public methods of FWindow //---------------------------------------------------------------------- @@ -106,31 +113,31 @@ void FWindow::hide() //---------------------------------------------------------------------- void FWindow::setWidth (int w, bool adjust) { - int old_width = width; + int old_width = getWidth(); FWidget::setWidth (w, adjust); - if ( vwin && width != old_width ) + if ( vwin && getWidth() != old_width ) resizeArea (vwin); } //---------------------------------------------------------------------- void FWindow::setHeight (int h, bool adjust) { - int old_height = height; + int old_height = getHeight(); FWidget::setHeight (h, adjust); - if ( vwin && height != old_height ) + if ( vwin && getHeight() != old_height ) resizeArea (vwin); } //---------------------------------------------------------------------- void FWindow::setGeometry (int x, int y, int w, int h, bool adjust) { - int old_width = width; - int old_height = height; + int old_width = getWidth(); + int old_height = getHeight(); FWidget::setGeometry (x, y, w, h, adjust); - if ( vwin && (width != old_width || height != old_height) ) + if ( vwin && (getWidth() != old_width || getHeight() != old_height) ) resizeArea (vwin); } @@ -138,10 +145,10 @@ void FWindow::setGeometry (int x, int y, int w, int h, bool adjust) FWindow* FWindow::getWindowWidgetAt (int x, int y) { // returns the window object to the corresponding coordinates - if ( statusBar() && statusBar()->getGeometryGlobal().contains(x,y) ) + if ( statusBar() && statusBar()->getTermGeometry().contains(x,y) ) return statusBar(); - if ( menuBar() && menuBar()->getGeometryGlobal().contains(x,y) ) + if ( menuBar() && menuBar()->getTermGeometry().contains(x,y) ) return menuBar(); if ( window_list && ! window_list->empty() ) @@ -158,7 +165,7 @@ FWindow* FWindow::getWindowWidgetAt (int x, int y) FWindow* w = static_cast(*iter); if ( ! w->isHiddenWindow() - && w->getGeometryGlobal().contains(x,y) ) + && w->getTermGeometry().contains(x,y) ) return w; } } @@ -205,13 +212,13 @@ FWindow* FWindow::getWindowWidget (FWidget* obj) // returns the window object to the given widget obj FWidget* p_obj = obj->getParentWidget(); - while ( ! obj->isWindow() && p_obj ) + while ( ! obj->isWindowWidget() && p_obj ) { obj = p_obj; p_obj = p_obj->getParentWidget(); } - if ( obj->isWindow() ) + if ( obj->isWindowWidget() ) return static_cast(obj); else return 0; @@ -230,7 +237,7 @@ int FWindow::getWindowLayer (FWidget* obj) if ( window_list->empty() ) return -1; - if ( ! obj->isWindow() ) + if ( ! obj->isWindowWidget() ) { if ( (window = getWindowWidget(obj)) == 0 ) return -1; @@ -301,14 +308,14 @@ bool FWindow::raiseWindow (FWidget* obj) if ( window_list->empty() ) return false; - if ( ! obj->isWindow() ) + if ( ! obj->isWindowWidget() ) return false; if ( window_list->back() == obj ) return false; if ( (window_list->back()->getFlags() & fc::modal) != 0 - && ! obj->isMenu() ) + && ! obj->isMenuWidget() ) return false; iter = window_list->begin(); @@ -342,7 +349,7 @@ bool FWindow::lowerWindow (FWidget* obj) if ( window_list->empty() ) return false; - if ( ! obj->isWindow() ) + if ( ! obj->isWindowWidget() ) return false; if ( window_list->front() == obj ) @@ -376,9 +383,9 @@ bool FWindow::zoomWindow() if ( zoomed ) { zoomed = false; - FRect currentGeometry = getGeometryShadow(); + FRect oldGeometry = getTermGeometryWithShadow(); setGeometry (normalGeometry); - restoreVTerm (currentGeometry); + restoreVTerm (oldGeometry); redraw(); } else @@ -386,13 +393,35 @@ bool FWindow::zoomWindow() zoomed = true; // save the current geometry normalGeometry = getGeometry(); - setGeometry (1, 1, getMaxWidth(), getMinHeight()); + FRect oldGeometry = getTermGeometryWithShadow(); + setGeometry (1, 1, getMaxWidth(), getMaxHeight()); + restoreVTerm (oldGeometry); redraw(); } return zoomed; } +//---------------------------------------------------------------------- +bool FWindow::setWindowWidget (bool on) +{ + if ( isWindowWidget() == on ) + return true; + + if ( on ) + { + flags |= fc::window_widget; + setTermOffset(); + } + else + { + flags &= ~fc::window_widget; + setParentOffset(); + } + + return on; +} + //---------------------------------------------------------------------- FWindow* FWindow::getActiveWindow() { @@ -500,7 +529,7 @@ void FWindow::switchToPrevWindow() { focus_widget->setFocus(); - if ( ! focus_widget->isWindow() ) + if ( ! focus_widget->isWindowWidget() ) focus_widget->redraw(); } } diff --git a/src/fwindow.h b/src/fwindow.h index e0b05b26..125efdd7 100644 --- a/src/fwindow.h +++ b/src/fwindow.h @@ -48,8 +48,6 @@ class FWindow : public FWidget bool zoomed; FWidget* win_focus_widget; FRect normalGeometry; - FRect maxGeometry; - FRect minGeometry; protected: static FWindow* previous_widget; @@ -65,6 +63,7 @@ class FWindow : public FWidget virtual void onWindowInactive (FEvent*); virtual void onWindowRaised (FEvent*); virtual void onWindowLowered (FEvent*); + virtual void adjustSize(); public: explicit FWindow (FWidget* = 0); // constructor @@ -91,6 +90,9 @@ class FWindow : public FWidget bool lowerWindow (); bool zoomWindow (); bool isZoomed() const; + bool setWindowWidget (bool); + bool setWindowWidget(); + bool unsetWindowWidget(); static FWindow* getActiveWindow(); static void setActiveWindow (FWindow*); FWidget* getWindowFocusWidget() const; @@ -127,6 +129,14 @@ inline bool FWindow::lowerWindow() inline bool FWindow::isZoomed() const { return zoomed; } +//---------------------------------------------------------------------- +inline bool FWindow::setWindowWidget() +{ return setWindowWidget(true); } + +//---------------------------------------------------------------------- +inline bool FWindow::unsetWindowWidget() +{ return setWindowWidget(false); } + //---------------------------------------------------------------------- inline bool FWindow::activateWindow() { return activateWindow(true); } diff --git a/test/calculator.cpp b/test/calculator.cpp index c9495815..4fdfb88c 100644 --- a/test/calculator.cpp +++ b/test/calculator.cpp @@ -250,13 +250,11 @@ Calc::Calc (FWidget* parent) btn->setNoUnderline(); btn->setText(button_text[key]); btn->setDoubleFlatLine(fc::top); + btn->setDoubleFlatLine(fc::bottom); if ( isNewFont() ) btn->unsetClickAnimation(); - if ( key <= Three ) - btn->setDoubleFlatLine(fc::bottom); - btn->addCallback ( "clicked", @@ -318,7 +316,7 @@ void Calc::drawDispay() if ( isMonochron() ) setReverse(false); - gotoxy (xpos+xmin+1, ypos+ymin+1); + printPos (3,3); print(display); print(L' '); setColor(wc.dialog_fg, wc.dialog_bg); @@ -329,15 +327,15 @@ void Calc::drawDispay() if ( isNewFont() ) { FString bottom_line(33, wchar_t(fc::NF_border_line_bottom)); - gotoxy (xpos+xmin+1, ypos+ymin); - print(bottom_line); - gotoxy (xpos+xmin+0, ypos+ymin+1); + printPos (3,2); + print (bottom_line); + printPos (2,3); print (wchar_t(fc::NF_rev_border_line_right)); - gotoxy (xpos+xmin+34, ypos+ymin+1); + printPos (36,3); print (wchar_t(fc::NF_border_line_left)); FString top_bottom_line_5(5, wchar_t(fc::NF_border_line_up_and_down)); FString top_line_2(2, wchar_t(fc::NF_border_line_upper)); - gotoxy (xpos+xmin+1, ypos+ymin+2); + printPos (3,4); print ( top_bottom_line_5 + top_line_2 + top_bottom_line_5 + top_line_2 + top_bottom_line_5 + top_line_2 @@ -349,7 +347,7 @@ void Calc::drawDispay() FString separator = FString(wchar_t(fc::BoxDrawingsVerticalAndRight)) + FString(35, wchar_t(fc::BoxDrawingsHorizontal)) + FString(wchar_t(fc::BoxDrawingsVerticalAndLeft)); - gotoxy (xpos+xmin-1, ypos+ymin+2); + printPos (1,4); print(separator); } @@ -415,8 +413,8 @@ bool Calc::isOperatorKey(int key) //---------------------------------------------------------------------- void Calc::setDisplay (lDouble d) { - char buffer[32]; - snprintf (buffer, sizeof(buffer), "%31.11Lg", d); + char buffer[33]; + snprintf (buffer, sizeof(buffer), "%32.11Lg", d); input = buffer; } diff --git a/test/keyboard.cpp b/test/keyboard.cpp index 6b2ece36..ce0c5643 100644 --- a/test/keyboard.cpp +++ b/test/keyboard.cpp @@ -46,7 +46,7 @@ void keyboard::draw() setNormal(); setColor(fc::Default, fc::Default); clearArea(); - gotoxy (1,1); + printPosTerm (1,1); print ("---------------\n"); print ("Press Q to quit\n"); print ("---------------\n"); diff --git a/test/mandelbrot.cpp b/test/mandelbrot.cpp index 192048f9..d3aafb27 100644 --- a/test/mandelbrot.cpp +++ b/test/mandelbrot.cpp @@ -52,8 +52,8 @@ void Mandelbrot::draw() y_max = 1.05; max_iter = 99; - xoffset = xpos+xmin; - yoffset = ypos+ymin; + xoffset = 2; + yoffset = 2; Cols = getClientWidth(); Lines = getClientHeight(); current_line = 1; @@ -63,7 +63,7 @@ void Mandelbrot::draw() for (y0=y_min; y0 < y_max && current_line <= Lines; y0+=dY) { - gotoxy (xoffset, yoffset+current_line); + printPos (xoffset, yoffset+current_line); for (x0=x_min; x0 < x_max; x0+=dX) { diff --git a/test/term-attributes.cpp b/test/term-attributes.cpp index 4aaa33e1..c11d0202 100644 --- a/test/term-attributes.cpp +++ b/test/term-attributes.cpp @@ -218,7 +218,7 @@ void AttribDemo::printAltCharset() if ( ! isMonochron() ) setColor (wc.label_fg, wc.label_bg); - gotoxy (xpos + xmin - 1, ypos + ymin - 1); + printPos (1,1); print("alternate charset: "); if ( parent->bgcolor == fc::Default ) @@ -249,8 +249,7 @@ void AttribDemo::draw() for (int y=0; y < getParentWidget()->getHeight()-7; y++) { - gotoxy ( xpos + xmin - 1, - ypos + ymin + y ); + printPos (1, 2+y); if ( ! isMonochron() ) setColor (wc.label_fg, wc.label_bg); @@ -354,7 +353,7 @@ void AttribDemo::draw() if ( ! isMonochron() ) setColor(wc.label_fg, wc.label_bg); - gotoxy (xpos + xmin - 1, ypos + ymin + 13); + printPos (1, 15); short bg = static_cast(getParent())->bgcolor; print (" Background color:"); @@ -363,7 +362,7 @@ void AttribDemo::draw() else printf ( " %d", bg); - gotoxy (xpos + xmin + 14, ypos + ymin + 15); + printPos (16, 17); print ("Change background color ->"); updateVTerm(true); } diff --git a/test/timer.cpp b/test/timer.cpp index 98a9d57c..80bad1e5 100644 --- a/test/timer.cpp +++ b/test/timer.cpp @@ -51,7 +51,7 @@ void timer::draw() setNormal(); setColor (fc::Default, fc::Default); clearArea(); - gotoxy (1,1); + printPosTerm (1,1); print ("---------------\n"); print ("Press Q to quit\n"); print ("---------------\n"); diff --git a/test/transparent.cpp b/test/transparent.cpp index 11052292..d58d5f58 100644 --- a/test/transparent.cpp +++ b/test/transparent.cpp @@ -78,7 +78,7 @@ void Transparent::draw() for (int n=1; n <= getClientHeight(); n++) { - gotoxy(xpos+xmin, ypos+ymin+n); + printPos (2, 2+n); print(line); } @@ -192,10 +192,10 @@ void MainWindow::draw() if ( isMonochron() ) setReverse(true); - setColor(foregroundColor, backgroundColor); - gotoxy(xpos+xmin, ypos+ymin+2); + setColor(); + printPos (2,4); print(line1); - gotoxy(xpos+xmin, ypos+ymin+3); + printPos (2,5); print(line2); if ( isMonochron() ) diff --git a/test/ui.cpp b/test/ui.cpp index f4ee3c11..74e956f9 100644 --- a/test/ui.cpp +++ b/test/ui.cpp @@ -68,7 +68,7 @@ ProgressDialog::ProgressDialog (FWidget* parent) progressBar = new FProgressbar(this); progressBar->setGeometry(2, 3, 34, 1, false); - //progressBar->setPercentage(78);< + //progressBar->setPercentage(78); reset->addCallback ( @@ -211,8 +211,8 @@ void TextWindow::append (const FString& str) //---------------------------------------------------------------------- void TextWindow::adjustSize() { - scrollText->setGeometry (1, 2, getWidth(), getHeight()-1); FDialog::adjustSize(); + scrollText->setGeometry (1, 2, getWidth(), getHeight()-1); } @@ -888,7 +888,7 @@ int main (int argc, char* argv[]) app.setXTermTitle (title); //app.setEncoding("VT100"); - //app.setTermGeometry(94,30); + //app.setTermSize(94,30); //app.setNewFont(); MyDialog d(&app); diff --git a/test/windows.cpp b/test/windows.cpp index cd713039..e73ec959 100644 --- a/test/windows.cpp +++ b/test/windows.cpp @@ -239,6 +239,7 @@ void Window::cb_createWindows (FWidget*, void*) x = dx + 5 + (n%3)*25 + int(n/3)*3; y = dy + 11 + int(n/3)*3; win->setGeometry (x, y, 20, 8); + win->setMinimumSize (20, 8); win->setResizeable(); win->show(); @@ -305,7 +306,7 @@ void Window::cb_next (FWidget*, void*) } while ( ! next->isEnabled() || ! next->acceptFocus() || ! next->isVisible() - || ! next->isWindow() ); + || ! next->isWindowWidget() ); activateWindow(next); break; @@ -328,7 +329,7 @@ void Window::cb_previous (FWidget*, void*) { --iter; - if ( (*iter)->isDialog() + if ( (*iter)->isDialogWidget() && static_cast(*iter)->isActiveWindow() ) { FDialog* prev; @@ -345,7 +346,7 @@ void Window::cb_previous (FWidget*, void*) } while ( ! prev->isEnabled() || ! prev->acceptFocus() || ! prev->isVisible() - || ! prev->isWindow() ); + || ! prev->isWindowWidget() ); activateWindow(prev); break;