Refactoring of the FDialog mouse event handler

This commit is contained in:
Markus Gans 2017-12-29 02:10:05 +01:00
parent 260bf9ac91
commit a880684432
7 changed files with 380 additions and 319 deletions

View File

@ -1,3 +1,6 @@
2017-12-29 Markus Gans <guru.mail@muenster.de>
* Refactoring of the FDialog mouse event handler
2017-12-27 Markus Gans <guru.mail@muenster.de> 2017-12-27 Markus Gans <guru.mail@muenster.de>
* Generalize scroll functions in FScrollView * Generalize scroll functions in FScrollView
* Refactoring FScrollbar::drawBar * Refactoring FScrollbar::drawBar

View File

@ -153,6 +153,16 @@ class FDialog : public FWindow
virtual void onClose (FCloseEvent*); virtual void onClose (FCloseEvent*);
private: private:
// Typedef
typedef struct
{
int mouse_x;
int mouse_y;
FPoint termPos;
int zoom_btn;
bool mouse_over_menu;
} mouseStates;
// Constant // Constant
static const int MENU_BTN = 3; static const int MENU_BTN = 3;
static const bool PRINT_WIN_NUMBER = false; // Only for debug static const bool PRINT_WIN_NUMBER = false; // Only for debug
@ -177,7 +187,19 @@ class FDialog : public FWindow
void openMenu(); void openMenu();
void selectFirstMenuItem(); void selectFirstMenuItem();
void setZoomItem(); void setZoomItem();
int getZoomButtonWidth();
void activateZoomButton (mouseStates&);
void deactivateZoomButton();
void leaveZoomButton (mouseStates&);
void pressZoomButton (mouseStates&);
bool isMouseOverMenu (const FPoint&);
void passEventToSubMenu (mouseStates&, FMouseEvent*);
void moveSizeKey (FKeyEvent*); void moveSizeKey (FKeyEvent*);
void raiseActivateDialog();
void lowerActivateDialog();
void resizeMouseDown (mouseStates&);
void resizeMouseUpMove (mouseStates&, bool = false);
void cancelMouseResize();
void acceptMoveSize(); void acceptMoveSize();
void cancelMoveSize(); void cancelMoveSize();
static void addDialog (FWidget*); static void addDialog (FWidget*);

View File

@ -472,6 +472,9 @@ bool FDialog::expandWidth (int n)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FDialog::activateDialog() void FDialog::activateDialog()
{ {
if ( isWindowActive() )
return;
FWidget* old_focus = FWidget::getFocusWidget(); FWidget* old_focus = FWidget::getFocusWidget();
FWidget* win_focus = getWindowFocusWidget(); FWidget* win_focus = getWindowFocusWidget();
setActiveWindow(this); setActiveWindow(this);
@ -507,13 +510,7 @@ void FDialog::onKeyPress (FKeyEvent* ev)
if ( ! isEnabled() ) if ( ! isEnabled() )
return; return;
// cancel resize by mouse cancelMouseResize();
if ( ! resize_click_pos.isNull() )
{
resize_click_pos.setPoint (0,0);
drawBorder();
updateTerminal();
}
if ( ev->key() == fc::Fckey_caret // Ctrl+^ (Ctrl+6) if ( ev->key() == fc::Fckey_caret // Ctrl+^ (Ctrl+6)
|| ev->key() == fc::Fkey_f22 ) // Shift+F10 || ev->key() == fc::Fkey_f22 ) // Shift+F10
@ -525,6 +522,7 @@ void FDialog::onKeyPress (FKeyEvent* ev)
selectFirstMenuItem(); selectFirstMenuItem();
} }
// Dialog move and resize functions
if ( getMoveSizeWidget() ) if ( getMoveSizeWidget() )
moveSizeKey(ev); moveSizeKey(ev);
@ -546,131 +544,77 @@ void FDialog::onKeyPress (FKeyEvent* ev)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FDialog::onMouseDown (FMouseEvent* ev) void FDialog::onMouseDown (FMouseEvent* ev)
{ {
int mouse_x = ev->getX() mouseStates ms =
, mouse_y = ev->getY()
, zoom_btn;
if ( ! isResizeable() )
zoom_btn = 0;
else if ( isNewFont() )
zoom_btn = 2;
else
zoom_btn = 3;
if ( zoom_button_pressed || zoom_button_active )
{ {
zoom_button_pressed = false; ev->getX(),
zoom_button_active = false; ev->getY(),
drawTitleBar(); ev->getTermPos(),
} getZoomButtonWidth(),
false // mouse_over_menu
};
deactivateZoomButton();
if ( ev->getButton() == fc::LeftButton ) if ( ev->getButton() == fc::LeftButton )
{ {
bool has_raised; // Click on titlebar or window: raise + activate
raiseActivateDialog();
// click on titlebar or window: raise + activate if ( ms.mouse_x >= 4
if ( mouse_x >= 4 && mouse_x <= getWidth() - zoom_btn && mouse_y == 1 ) && ms.mouse_x <= getWidth() - ms.zoom_btn
&& ms.mouse_y == 1 )
titlebar_click_pos.setPoint (ev->getTermX(), ev->getTermY()); titlebar_click_pos.setPoint (ev->getTermX(), ev->getTermY());
else else
titlebar_click_pos.setPoint (0,0); titlebar_click_pos.setPoint (0,0);
has_raised = raiseWindow(); // Click on titlebar menu button
if ( ms.mouse_x < 4 && ms.mouse_y == 1 )
if ( ! isWindowActive() )
activateDialog();
if ( has_raised )
redraw();
// click on titlebar menu button
if ( mouse_x < 4 && mouse_y == 1 )
openMenu(); openMenu();
else if ( mouse_x > getWidth() - zoom_btn && mouse_y == 1 )
{
zoom_button_pressed = true;
zoom_button_active = true;
drawTitleBar();
}
// click on the lower right resize corner
if ( isResizeable()
&& ( (mouse_x == getWidth() && mouse_y == getHeight())
|| (mouse_x == getWidth() - 1 && mouse_y == getHeight())
|| (mouse_x == getWidth() && mouse_y == getHeight() - 1) ) )
{
resize_click_pos = ev->getTermPos();
FPoint lower_right_pos = getTermGeometry().getLowerRightPos();
if ( ev->getTermPos() != lower_right_pos )
{
FPoint deltaPos = ev->getTermPos() - lower_right_pos;
int w = lower_right_pos.getX() + deltaPos.getX() - getTermX() + 1;
int h = lower_right_pos.getY() + deltaPos.getY() - getTermY() + 1;
setSize (w, h);
}
else else
drawBorder(); activateZoomButton(ms);
}
else // Click on the lower right resize corner
resize_click_pos.setPoint (0,0); resizeMouseDown(ms);
} }
else // ev->getButton() != fc::LeftButton else // ev->getButton() != fc::LeftButton
{ {
// click on titlebar menu button // Click on titlebar menu button
if ( mouse_x < 4 && mouse_y == 1 && dialog_menu->isVisible() ) if ( ms.mouse_x < 4 && ms.mouse_y == 1
&& dialog_menu->isVisible() )
leaveMenu(); // close menu leaveMenu(); // close menu
// cancel resize cancelMouseResize(); // Cancel resize
if ( ! resize_click_pos.isNull() )
{
resize_click_pos.setPoint (0,0);
drawBorder();
updateTerminal();
}
} }
if ( ev->getButton() == fc::RightButton ) // Click on titlebar: just activate
{ if ( ev->getButton() == fc::RightButton
// click on titlebar: just activate && ms.mouse_x >= 4
if ( mouse_x >= 4 && mouse_x <= getWidth() && mouse_y == 1 ) && ms.mouse_x <= getWidth()
{ && ms.mouse_y == 1 )
if ( ! isWindowActive() )
activateDialog(); activateDialog();
}
}
if ( ev->getButton() == fc::MiddleButton ) // Click on titlebar: lower + activate
{ if ( ev->getButton() == fc::MiddleButton
// click on titlebar: lower + activate && ms.mouse_x >= 4 && ms.mouse_x <= getWidth()
if ( mouse_x >= 4 && mouse_x <= getWidth() && mouse_y == 1 ) && ms.mouse_y == 1 )
{ lowerActivateDialog();
bool has_lowered = lowerWindow();
if ( ! isWindowActive() )
activateDialog();
else if ( has_lowered )
updateTerminal();
}
}
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FDialog::onMouseUp (FMouseEvent* ev) void FDialog::onMouseUp (FMouseEvent* ev)
{ {
int zoom_btn; mouseStates ms =
{
if ( ! isResizeable() ) ev->getX(),
zoom_btn = 0; ev->getY(),
else if ( isNewFont() ) ev->getTermPos(),
zoom_btn = 2; getZoomButtonWidth(),
else false // mouse_over_menu
zoom_btn = 3; };
if ( ev->getButton() == fc::LeftButton ) if ( ev->getButton() == fc::LeftButton )
{ {
int mouse_x = ev->getX() int titlebar_x = titlebar_click_pos.getX()
, mouse_y = ev->getY()
, titlebar_x = titlebar_click_pos.getX()
, titlebar_y = titlebar_click_pos.getY(); , titlebar_y = titlebar_click_pos.getY();
if ( ! titlebar_click_pos.isNull() if ( ! titlebar_click_pos.isNull()
@ -678,204 +622,87 @@ void FDialog::onMouseUp (FMouseEvent* ev)
&& titlebar_x < getTermX() + getWidth() && titlebar_x < getTermX() + getWidth()
&& titlebar_y == getTermY() ) && titlebar_y == getTermY() )
{ {
FPoint deltaPos = ev->getTermPos() - titlebar_click_pos; FPoint deltaPos = ms.termPos - titlebar_click_pos;
move (deltaPos); move (deltaPos);
titlebar_click_pos = ev->getTermPos(); titlebar_click_pos = ms.termPos;
} }
// click on titlebar menu button // Click on titlebar menu button
if ( mouse_x < 4 if ( ms.mouse_x < 4
&& mouse_y == 1 && ms.mouse_y == 1
&& dialog_menu->isVisible() && dialog_menu->isVisible()
&& ! dialog_menu->hasSelectedItem() ) && ! dialog_menu->hasSelectedItem() )
{ {
// Sets focus to the first item // Sets focus to the first item
selectFirstMenuItem(); selectFirstMenuItem();
} }
else if ( mouse_x > getWidth() - zoom_btn
&& mouse_y == 1
&& zoom_button_pressed )
{
// zoom to maximum or restore the window size
zoomWindow();
setZoomItem();
}
// resize the dialog
if ( isResizeable() && ! resize_click_pos.isNull() )
{
FWidget* r = getRootWidget();
resize_click_pos = ev->getTermPos();
int x2 = resize_click_pos.getX()
, y2 = resize_click_pos.getY()
, x2_offset = 0
, y2_offset = 0;
if ( r )
{
x2_offset = r->getLeftPadding();
y2_offset = r->getTopPadding();
}
if ( ev->getTermPos() != getTermGeometry().getLowerRightPos() )
{
int w, h;
FPoint deltaPos = ev->getTermPos() - resize_click_pos;
if ( x2 - x2_offset <= getMaxWidth() )
w = resize_click_pos.getX() + deltaPos.getX() - getTermX() + 1;
else else
w = getMaxWidth() - getTermX() + x2_offset + 1;
if ( y2 - y2_offset <= getMaxHeight() )
h = resize_click_pos.getY() + deltaPos.getY() - getTermY() + 1;
else
h = getMaxHeight() - getTermY() + y2_offset + 1;
setSize (w, h);
}
// reset the border color
resize_click_pos.setPoint (0,0);
// redraw() is required to draw the standard (black) border
// and client objects with ignorePadding() option.
redraw();
}
}
if ( zoom_button_pressed || zoom_button_active )
{ {
zoom_button_pressed = false; // Zoom to maximum or restore the window size
zoom_button_active = false; pressZoomButton(ms);
drawTitleBar();
} }
// Resize the dialog
resizeMouseUpMove (ms, true);
}
deactivateZoomButton();
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FDialog::onMouseMove (FMouseEvent* ev) void FDialog::onMouseMove (FMouseEvent* ev)
{ {
int zoom_btn; mouseStates ms =
if ( ! isResizeable() )
zoom_btn = 0;
else if ( isNewFont() )
zoom_btn = 2;
else
zoom_btn = 3;
if ( ev->getButton() == fc::LeftButton )
{ {
int mouse_x = ev->getX(); ev->getX(),
int mouse_y = ev->getY(); ev->getY(),
ev->getTermPos(),
getZoomButtonWidth(),
isMouseOverMenu(ev->getTermPos())
};
if ( ev->getButton() != fc::LeftButton )
return;
if ( ! titlebar_click_pos.isNull() ) if ( ! titlebar_click_pos.isNull() )
{ {
FPoint deltaPos = ev->getTermPos() - titlebar_click_pos; FPoint deltaPos = ms.termPos - titlebar_click_pos;
move (deltaPos); move (deltaPos);
titlebar_click_pos = ev->getTermPos(); titlebar_click_pos = ms.termPos;
} }
if ( dialog_menu->isVisible() && dialog_menu->isShown() )
{
// Mouse event handover to the menu // Mouse event handover to the menu
const FRect& menu_geometry = dialog_menu->getTermGeometry(); if ( ms.mouse_over_menu )
passEventToSubMenu (ms, ev);
if ( dialog_menu->getCount() > 0 leaveZoomButton(ms); // Check zoom button pressed
&& menu_geometry.contains(ev->getTermPos()) ) resizeMouseUpMove(ms); // Resize the dialog
{
const FPoint& g = ev->getTermPos();
const FPoint& p = dialog_menu->termToWidgetPos(g);
int b = ev->getButton();
try
{
FMouseEvent* _ev = new FMouseEvent (fc::MouseMove_Event, p, g, b);
dialog_menu->mouse_down = true;
setClickedWidget(dialog_menu);
dialog_menu->onMouseMove(_ev);
delete _ev;
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return;
}
}
}
if ( mouse_x > getWidth() - zoom_btn && mouse_y == 1 && zoom_button_active )
zoom_button_pressed = true;
else if ( zoom_button_pressed )
zoom_button_pressed = false;
drawTitleBar();
// resize the dialog
if ( isResizeable() && ! resize_click_pos.isNull()
&& ev->getTermPos() != getTermGeometry().getLowerRightPos() )
{
FWidget* r = getRootWidget();
resize_click_pos = ev->getTermPos();
int x2 = resize_click_pos.getX()
, y2 = resize_click_pos.getY()
, x2_offset = 0
, y2_offset = 0;
if ( r )
{
x2_offset = r->getLeftPadding();
y2_offset = r->getTopPadding();
}
int w, h;
FPoint deltaPos = ev->getTermPos() - resize_click_pos;
if ( x2 - x2_offset <= getMaxWidth() )
w = resize_click_pos.getX() + deltaPos.getX() - getTermX() + 1;
else
w = getMaxWidth() - getTermX() + x2_offset + 1;
if ( y2 - y2_offset <= getMaxHeight() )
h = resize_click_pos.getY() + deltaPos.getY() - getTermY() + 1;
else
h = getMaxHeight() - getTermY() + y2_offset + 1;
setSize (w, h);
}
}
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FDialog::onMouseDoubleClick (FMouseEvent* ev) void FDialog::onMouseDoubleClick (FMouseEvent* ev)
{ {
int x mouseStates ms =
, y {
, mouse_x ev->getX(),
, mouse_y ev->getY(),
, zoom_btn; ev->getTermPos(),
getZoomButtonWidth(),
false // mouse_over_menu
};
int x, y;
if ( ev->getButton() != fc::LeftButton ) if ( ev->getButton() != fc::LeftButton )
return; return;
mouse_x = ev->getX();
mouse_y = ev->getY();
if ( ! isResizeable() )
zoom_btn = 0;
else if ( isNewFont() )
zoom_btn = 2;
else
zoom_btn = 3;
x = getTermX(); x = getTermX();
y = getTermY(); y = getTermY();
FRect title_button(x, y, 3, 1); FRect title_button(x, y, 3, 1);
FPoint tPos = ev->getTermPos(); FPoint tPos = ms.termPos;
if ( title_button.contains(tPos) ) if ( title_button.contains(tPos) )
{ {
// double click on title button // Double click on title button
FWidget* window_focus_widget; FWidget* window_focus_widget;
dialog_menu->unselectItem(); dialog_menu->unselectItem();
dialog_menu->hide(); dialog_menu->hide();
@ -894,11 +721,11 @@ void FDialog::onMouseDoubleClick (FMouseEvent* ev)
close(); close();
} }
else if ( isResizeable() else if ( isResizeable()
&& mouse_x >= 4 && ms.mouse_x >= 4
&& mouse_x <= getWidth() - zoom_btn && ms.mouse_x <= getWidth() - ms.zoom_btn
&& mouse_y == 1 ) && ms.mouse_y == 1 )
{ {
// double click on titlebar // Double click on titlebar
zoomWindow(); // window zoom/unzoom zoomWindow(); // window zoom/unzoom
setZoomItem(); setZoomItem();
} }
@ -967,7 +794,7 @@ void FDialog::onWindowRaised (FEvent*)
putArea (getTermPos(), vwin); putArea (getTermPos(), vwin);
// handle always-on-top windows // Handle always-on-top windows
if ( always_on_top_list && ! always_on_top_list->empty() ) if ( always_on_top_list && ! always_on_top_list->empty() )
{ {
widgetList::const_iterator iter, last; widgetList::const_iterator iter, last;
@ -1021,7 +848,7 @@ void FDialog::draw()
tooltip = 0; tooltip = 0;
} }
// fill the background // Fill the background
setColor(); setColor();
if ( isMonochron() ) if ( isMonochron() )
@ -1075,7 +902,7 @@ void FDialog::init()
setRightPadding(1); setRightPadding(1);
ignorePadding(); ignorePadding();
setDialogWidget(); setDialogWidget();
// initialize geometry values // Initialize geometry values
setGeometry (1, 1, 10, 10, false); setGeometry (1, 1, 10, 10, false);
setMinimumSize (15, 4); setMinimumSize (15, 4);
addDialog(this); addDialog(this);
@ -1197,22 +1024,22 @@ void FDialog::drawBorder()
for (int y = y1; y < y2; y++) for (int y = y1; y < y2; y++)
{ {
setPrintPos (x1, y); setPrintPos (x1, y);
// border left ⎸ // Border left ⎸
print (fc::NF_border_line_left); print (fc::NF_border_line_left);
setPrintPos (x2, y); setPrintPos (x2, y);
// border right⎹ // Border right⎹
print (fc::NF_rev_border_line_right); print (fc::NF_rev_border_line_right);
} }
setPrintPos (x1, y2); setPrintPos (x1, y2);
// lower left corner border ⎣ // Lower left corner border ⎣
print (fc::NF_border_corner_lower_left); print (fc::NF_border_corner_lower_left);
for (int x = 1; x < getWidth() - 1; x++) // low line _ for (int x = 1; x < getWidth() - 1; x++) // low line _
print (fc::NF_border_line_bottom); print (fc::NF_border_line_bottom);
setPrintPos (x2, y2); setPrintPos (x2, y2);
// lower right corner border ⎦ // Lower right corner border ⎦
print (fc::NF_rev_border_corner_lower_right); print (fc::NF_rev_border_corner_lower_right);
} }
else else
@ -1358,7 +1185,7 @@ void FDialog::drawZoomButton()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FDialog::drawTextBar() void FDialog::drawTextBar()
{ {
// fill with spaces (left of the title) // Fill with spaces (left of the title)
int center_offset int center_offset
, zoom_btn , zoom_btn
, length , length
@ -1372,13 +1199,7 @@ void FDialog::drawTextBar()
else else
setColor (wc.titlebar_inactive_fg, wc.titlebar_inactive_bg); setColor (wc.titlebar_inactive_fg, wc.titlebar_inactive_bg);
if ( ! isResizeable() ) zoom_btn = getZoomButtonWidth();
zoom_btn = 0;
else if ( isNewFont() )
zoom_btn = 2;
else
zoom_btn = 3;
length = int(tb_text.getLength()); length = int(tb_text.getLength());
center_offset = int((getWidth() - length - MENU_BTN - zoom_btn) / 2); center_offset = int((getWidth() - length - MENU_BTN - zoom_btn) / 2);
@ -1429,7 +1250,7 @@ void FDialog::leaveMenu()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FDialog::openMenu() void FDialog::openMenu()
{ {
// open the titlebar menu // Open the titlebar menu
if ( ! dialog_menu ) if ( ! dialog_menu )
return; return;
@ -1453,7 +1274,7 @@ void FDialog::openMenu()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FDialog::selectFirstMenuItem() void FDialog::selectFirstMenuItem()
{ {
// focus to the first enabled menu item // Focus to the first enabled menu item
FMenuItem* first_item; FMenuItem* first_item;
dialog_menu->selectFirstItem(); dialog_menu->selectFirstItem();
first_item = dialog_menu->getSelectedItem(); first_item = dialog_menu->getSelectedItem();
@ -1487,6 +1308,110 @@ void FDialog::setZoomItem()
} }
} }
//----------------------------------------------------------------------
inline int FDialog::getZoomButtonWidth()
{
if ( ! isResizeable() )
return 0;
else if ( isNewFont() )
return 2;
else
return 3;
}
//----------------------------------------------------------------------
inline void FDialog::deactivateZoomButton()
{
if ( ! zoom_button_pressed && ! zoom_button_active )
return;
zoom_button_pressed = false;
zoom_button_active = false;
drawTitleBar();
}
//----------------------------------------------------------------------
inline void FDialog::activateZoomButton (mouseStates& ms)
{
if ( ms.mouse_x <= getWidth() - ms.zoom_btn
|| ms.mouse_y != 1 )
return;
zoom_button_pressed = true;
zoom_button_active = true;
drawTitleBar();
}
//----------------------------------------------------------------------
inline void FDialog::leaveZoomButton (mouseStates& ms)
{
bool zoom_button_pressed_before = zoom_button_pressed;
if ( ms.mouse_x > getWidth() - ms.zoom_btn
&& ms.mouse_x <= getWidth()
&& ms.mouse_y == 1
&& zoom_button_active )
zoom_button_pressed = true;
else if ( zoom_button_pressed )
zoom_button_pressed = false;
if ( zoom_button_pressed_before != zoom_button_pressed )
drawTitleBar();
}
//----------------------------------------------------------------------
void FDialog::pressZoomButton (mouseStates& ms)
{
if ( ms.mouse_x <= getWidth() - ms.zoom_btn
|| ms.mouse_y != 1
|| ! zoom_button_pressed )
return;
// Zoom to maximum or restore the window size
zoomWindow();
setZoomItem();
}
//----------------------------------------------------------------------
inline bool FDialog::isMouseOverMenu (const FPoint& termpos)
{
const FRect& menu_geometry = dialog_menu->getTermGeometry();
if ( dialog_menu->getCount() > 0 && menu_geometry.contains(termpos) )
return true;
return false;
}
//----------------------------------------------------------------------
inline void FDialog::passEventToSubMenu ( mouseStates& ms
, FMouseEvent* ev )
{
// Mouse event handover to the dialog menu
if ( ! ms.mouse_over_menu
|| ! dialog_menu->isVisible()
|| ! dialog_menu->isShown() )
return;
const FPoint& g = ms.termPos;
const FPoint& p = dialog_menu->termToWidgetPos(g);
int b = ev->getButton();
try
{
FMouseEvent* _ev = new FMouseEvent (fc::MouseMove_Event, p, g, b);
dialog_menu->mouse_down = true;
setClickedWidget(dialog_menu);
dialog_menu->onMouseMove(_ev);
delete _ev;
}
catch (const std::bad_alloc& ex)
{
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
return;
}
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FDialog::moveSizeKey (FKeyEvent* ev) inline void FDialog::moveSizeKey (FKeyEvent* ev)
{ {
@ -1553,6 +1478,116 @@ inline void FDialog::moveSizeKey (FKeyEvent* ev)
} }
} }
//----------------------------------------------------------------------
inline void FDialog::raiseActivateDialog()
{
bool has_raised = raiseWindow();
activateDialog();
if ( has_raised )
redraw();
}
//----------------------------------------------------------------------
inline void FDialog::lowerActivateDialog()
{
bool has_lowered = lowerWindow();
if ( ! isWindowActive() )
activateDialog();
else if ( has_lowered )
updateTerminal();
}
//----------------------------------------------------------------------
void FDialog::resizeMouseDown (mouseStates& ms)
{
// Click on the lower right resize corner
if ( isResizeable()
&& ( (ms.mouse_x == getWidth() && ms.mouse_y == getHeight())
|| (ms.mouse_x == getWidth() - 1 && ms.mouse_y == getHeight())
|| (ms.mouse_x == getWidth() && ms.mouse_y == getHeight() - 1) ) )
{
resize_click_pos = ms.termPos;
FPoint lower_right_pos = getTermGeometry().getLowerRightPos();
if ( ms.termPos != lower_right_pos )
{
FPoint deltaPos = ms.termPos - lower_right_pos;
int w = lower_right_pos.getX() + deltaPos.getX() - getTermX() + 1;
int h = lower_right_pos.getY() + deltaPos.getY() - getTermY() + 1;
setSize (w, h);
}
else
drawBorder();
}
else
resize_click_pos.setPoint (0,0);
}
//----------------------------------------------------------------------
void FDialog::resizeMouseUpMove (mouseStates& ms, bool mouse_up)
{
// Resize the dialog
if ( isResizeable() && ! resize_click_pos.isNull() )
{
FWidget* r = getRootWidget();
resize_click_pos = ms.termPos;
int x2 = resize_click_pos.getX()
, y2 = resize_click_pos.getY()
, x2_offset = 0
, y2_offset = 0;
if ( r )
{
x2_offset = r->getLeftPadding();
y2_offset = r->getTopPadding();
}
if ( ms.termPos != getTermGeometry().getLowerRightPos() )
{
int w, h;
FPoint deltaPos = ms.termPos - resize_click_pos;
if ( x2 - x2_offset <= getMaxWidth() )
w = resize_click_pos.getX() + deltaPos.getX() - getTermX() + 1;
else
w = getMaxWidth() - getTermX() + x2_offset + 1;
if ( y2 - y2_offset <= getMaxHeight() )
h = resize_click_pos.getY() + deltaPos.getY() - getTermY() + 1;
else
h = getMaxHeight() - getTermY() + y2_offset + 1;
setSize (w, h);
}
if ( mouse_up )
{
// Reset the border color
resize_click_pos.setPoint (0,0);
// redraw() is required to draw the standard (black) border
// and client objects with ignorePadding() option.
redraw();
}
}
}
//----------------------------------------------------------------------
void FDialog::cancelMouseResize()
{
// Cancel resize by mouse
if ( resize_click_pos.isNull() )
return;
resize_click_pos.setPoint (0,0);
drawBorder();
updateTerminal();
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FDialog::acceptMoveSize() inline void FDialog::acceptMoveSize()
{ {
@ -1585,7 +1620,7 @@ inline void FDialog::cancelMoveSize()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FDialog::addDialog (FWidget* obj) void FDialog::addDialog (FWidget* obj)
{ {
// add the dialog object obj to the dialog list // Add the dialog object obj to the dialog list
if ( dialog_list ) if ( dialog_list )
dialog_list->push_back(obj); dialog_list->push_back(obj);
} }
@ -1593,7 +1628,7 @@ void FDialog::addDialog (FWidget* obj)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FDialog::delDialog (FWidget* obj) void FDialog::delDialog (FWidget* obj)
{ {
// delete the dialog object obj from the dialog list // Delete the dialog object obj from the dialog list
if ( ! dialog_list || dialog_list->empty() ) if ( ! dialog_list || dialog_list->empty() )
return; return;

View File

@ -1716,7 +1716,6 @@ void FListView::processChanged()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
inline void FListView::keyLeft (int& first_line_position_before) inline void FListView::keyLeft (int& first_line_position_before)
{ {
int element_count = int(getCount());
int position_before = current_iter.getPosition(); int position_before = current_iter.getPosition();
FListViewItem* item = getCurrentItem(); FListViewItem* item = getCurrentItem();
@ -1727,7 +1726,7 @@ inline void FListView::keyLeft (int& first_line_position_before)
// Collapse element // Collapse element
item->collapse(); item->collapse();
adjustSize(); adjustSize();
element_count = int(getCount()); int element_count = int(getCount());
recalculateVerticalBar (element_count); recalculateVerticalBar (element_count);
// Force vertical scrollbar redraw // Force vertical scrollbar redraw
first_line_position_before = -1; first_line_position_before = -1;

View File

@ -281,11 +281,6 @@ void FMenu::onMouseUp (FMouseEvent* ev)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FMenu::onMouseMove (FMouseEvent* ev) void FMenu::onMouseMove (FMouseEvent* ev)
{ {
mouseStates state;
// Set all state flags to false
std::memset (&state, 0, sizeof(state));
shown_sub_menu = 0;
if ( ev->getButton() != fc::LeftButton ) if ( ev->getButton() != fc::LeftButton )
return; return;
@ -295,38 +290,45 @@ void FMenu::onMouseMove (FMouseEvent* ev)
if ( ! mouse_down || item_list.empty() ) if ( ! mouse_down || item_list.empty() )
return; return;
state.mouse_over_menu = isMouseOverMenu (ev->getTermPos()); mouseStates ms =
state.mouse_over_submenu = isMouseOverSubMenu (ev->getTermPos()); {
state.mouse_over_supermenu = isMouseOverSuperMenu (ev->getTermPos()); false, // focus_changed
state.mouse_over_menubar = isMouseOverMenuBar (ev->getTermPos()); false, // hide_sub_menu
isMouseOverMenu (ev->getTermPos()),
isMouseOverSubMenu (ev->getTermPos()),
isMouseOverSuperMenu (ev->getTermPos()),
isMouseOverMenuBar (ev->getTermPos())
};
shown_sub_menu = 0;
// Mouse pointer over an entry in the menu list // Mouse pointer over an entry in the menu list
mouseMoveOverList (ev->getPos(), state); mouseMoveOverList (ev->getPos(), ms);
if ( state.mouse_over_submenu ) if ( ms.mouse_over_submenu )
{ {
passEventToSubMenu(ev); // Event handover to sub-menu passEventToSubMenu(ev); // Event handover to sub-menu
return; return;
} }
if ( ! state.mouse_over_menu && state.mouse_over_supermenu ) if ( ! ms.mouse_over_menu && ms.mouse_over_supermenu )
{ {
passEventToSuperMenu(ev); // Event handover to super-menu passEventToSuperMenu(ev); // Event handover to super-menu
return; return;
} }
if ( state.mouse_over_menubar ) if ( ms.mouse_over_menubar )
{ {
passEventToMenuBar(ev); // Event handover to the menu bar passEventToMenuBar(ev); // Event handover to the menu bar
return; return;
} }
if ( ! hasSelectedItem() && state.mouse_over_menu ) if ( ! hasSelectedItem() && ms.mouse_over_menu )
{ {
mouseMoveOverBorder(state); // Mouse is over border or separator mouseMoveOverBorder(ms); // Mouse is over border or separator
} }
if ( state.focus_changed ) if ( ms.focus_changed )
redraw(); redraw();
if ( shown_sub_menu ) if ( shown_sub_menu )
@ -334,7 +336,7 @@ void FMenu::onMouseMove (FMouseEvent* ev)
closeOpenedSubMenu(); closeOpenedSubMenu();
openSubMenu (shown_sub_menu); openSubMenu (shown_sub_menu);
} }
else if ( state.hide_sub_menu ) else if ( ms.hide_sub_menu )
{ {
closeOpenedSubMenu(); closeOpenedSubMenu();
updateTerminal(); updateTerminal();
@ -833,7 +835,7 @@ bool FMenu::mouseUpOverList (FPoint mouse_pos)
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
bool FMenu::mouseMoveOverList (FPoint mouse_pos, mouseStates& state) bool FMenu::mouseMoveOverList (FPoint mouse_pos, mouseStates& ms)
{ {
std::vector<FMenuItem*>::const_iterator iter, last; std::vector<FMenuItem*>::const_iterator iter, last;
bool isOverList = false; bool isOverList = false;
@ -880,9 +882,9 @@ bool FMenu::mouseMoveOverList (FPoint mouse_pos, mouseStates& state)
shown_sub_menu = sub_menu; shown_sub_menu = sub_menu;
} }
else if ( opened_sub_menu ) else if ( opened_sub_menu )
state.hide_sub_menu = true; ms.hide_sub_menu = true;
state.focus_changed = true; ms.focus_changed = true;
} }
if ( ! (*iter)->isSeparator() ) if ( ! (*iter)->isSeparator() )
@ -890,10 +892,10 @@ bool FMenu::mouseMoveOverList (FPoint mouse_pos, mouseStates& state)
} }
else else
{ {
if ( state.mouse_over_menu if ( ms.mouse_over_menu
&& (*iter)->isEnabled() && (*iter)->isEnabled()
&& (*iter)->isSelected() && (*iter)->isSelected()
&& ! state.mouse_over_submenu ) && ! ms.mouse_over_submenu )
{ {
// Unselect selected item without mouse focus // Unselect selected item without mouse focus
(*iter)->unsetSelected(); (*iter)->unsetSelected();
@ -902,7 +904,7 @@ bool FMenu::mouseMoveOverList (FPoint mouse_pos, mouseStates& state)
if ( getSelectedItem() == *iter ) if ( getSelectedItem() == *iter )
setSelectedItem(0); setSelectedItem(0);
state.focus_changed = true; ms.focus_changed = true;
} }
} }
@ -923,7 +925,7 @@ void FMenu::mouseUpOverBorder()
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FMenu::mouseMoveOverBorder (mouseStates& state) void FMenu::mouseMoveOverBorder (mouseStates& ms)
{ {
// Mouse is moved over border or separator line // Mouse is moved over border or separator line
@ -940,7 +942,7 @@ void FMenu::mouseMoveOverBorder (mouseStates& state)
} }
if ( opened_sub_menu ) if ( opened_sub_menu )
state.hide_sub_menu = true; ms.hide_sub_menu = true;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------

View File

@ -654,7 +654,7 @@ inline bool FOptiAttr::setTermBold (char_data*& term)
inline bool FOptiAttr::unsetTermBold (char_data*& term) inline bool FOptiAttr::unsetTermBold (char_data*& term)
{ {
// Back to normal intensity (turns off bold + dim) // Back to normal intensity (turns off bold + dim)
if ( append_sequence(F_exit_bold_mode.cap) ) if ( term && append_sequence(F_exit_bold_mode.cap) )
{ {
if ( F_exit_bold_mode.caused_reset ) if ( F_exit_bold_mode.caused_reset )
reset(term); reset(term);

View File

@ -308,7 +308,7 @@ void FScrollbar::drawVerticalBar()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FScrollbar::drawHorizontalBar() void FScrollbar::drawHorizontalBar()
{ {
int z = 0; int z;
setColor (wc.scrollbar_fg, wc.scrollbar_bg); setColor (wc.scrollbar_fg, wc.scrollbar_bg);
if ( isNewFont() ) if ( isNewFont() )
@ -316,7 +316,7 @@ void FScrollbar::drawHorizontalBar()
else else
setPrintPos (2, 1); setPrintPos (2, 1);
for (; z < slider_pos; z++) for (z = 0; z < slider_pos; z++)
{ {
if ( isNewFont() ) if ( isNewFont() )
print (fc::NF_border_line_upper); // ¯ print (fc::NF_border_line_upper); // ¯