finalcut/src/fdialog.cpp

1098 lines
26 KiB
C++
Raw Normal View History

// File: fdialog.cpp
// Provides: class FDialog
2015-05-23 13:35:12 +02:00
#include "fapp.h"
#include "fdialog.h"
#include "fstatusbar.h"
//----------------------------------------------------------------------
// class FDialog
//----------------------------------------------------------------------
// constructor and destructor
//----------------------------------------------------------------------
2015-09-22 04:18:20 +02:00
FDialog::FDialog(FWidget* parent)
: FWindow(parent)
, tb_text()
, result_code(FDialog::Reject)
, maximized(false)
, TitleBarClickPos()
, oldGeometry()
, focus_widget(0)
2016-06-12 23:06:58 +02:00
, dialog_menu()
, dgl_menuitem()
2015-05-23 13:35:12 +02:00
{
2015-09-22 04:18:20 +02:00
init();
2015-05-23 13:35:12 +02:00
}
//----------------------------------------------------------------------
2015-09-22 04:18:20 +02:00
FDialog::FDialog (const FString& txt, FWidget* parent)
: FWindow(parent)
, tb_text(txt)
, result_code(FDialog::Reject)
, maximized(false)
, TitleBarClickPos()
, oldGeometry()
, focus_widget(0)
2016-06-12 23:06:58 +02:00
, dialog_menu()
, dgl_menuitem()
2015-05-23 13:35:12 +02:00
{
2015-09-22 04:18:20 +02:00
init();
2015-05-23 13:35:12 +02:00
}
//----------------------------------------------------------------------
FDialog::~FDialog() // destructor
{
delete accelerator_list;
accelerator_list = 0;
activatePrevWindow();
delWindow(this);
FApplication* fapp = static_cast<FApplication*>(getRootWidget());
if ( ! fapp->quit_now )
{
const FRect& geometry = getGeometryGlobalShadow();
restoreVTerm (geometry);
parentWidget()->redraw();
}
if ( window_list && ! window_list->empty() )
{
widgetList::const_iterator iter, end;
iter = window_list->begin();
end = window_list->end();
while ( iter != end )
{
putArea ((*iter)->getGlobalPos(), (*iter)->getVWin());
2016-01-24 14:53:09 +01:00
if ( ! maximized && ((*iter)->getFlags() & fc::shadow) != 0 )
2015-05-23 13:35:12 +02:00
static_cast<FDialog*>(*iter)->drawDialogShadow();
++iter;
}
setFocusWidget(0);
updateTerminal();
flush_out();
}
if ( vwin != 0 )
{
if ( vwin->changes != 0 )
delete[] vwin->changes;
if ( vwin->text != 0 )
delete[] vwin->text;
delete vwin;
}
if ( isModal() )
unsetModal();
}
// private methods of FDialog
//----------------------------------------------------------------------
void FDialog::init()
{
2016-06-12 23:06:58 +02:00
FWidget* rootObj = getRootWidget();
xmin = 1 + rootObj->getLeftPadding();
ymin = 1 + rootObj->getTopPadding();
xmax = rootObj->getWidth();
ymax = rootObj->getHeight();
2015-05-23 13:35:12 +02:00
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;
createArea (vwin);
setGeometry (1, 1, 10, 10, false); // initialize geometry values
ignore_padding = true;
window_object = true;
2016-06-12 23:06:58 +02:00
dialog_object = true;
2015-05-23 13:35:12 +02:00
addWindow(this);
setActiveWindow(this);
foregroundColor = wc.dialog_fg;
backgroundColor = wc.dialog_bg;
if ( hasFocus() )
2016-01-24 14:53:09 +01:00
flags |= fc::focus;
2015-05-23 13:35:12 +02:00
if ( isEnabled() )
2016-01-24 14:53:09 +01:00
flags |= fc::active;
2015-05-23 13:35:12 +02:00
FWidget* old_focus = FWidget::getFocusWidget();
if ( old_focus )
{
setFocus();
2015-05-23 13:35:12 +02:00
old_focus->redraw();
}
2015-10-17 19:40:43 +02:00
accelerator_list = new Accelerators();
2016-06-12 23:06:58 +02:00
dialog_menu = new FMenu ("-", this);
dialog_menu->move (xpos, ypos+1);
2016-06-13 22:44:15 +02:00
2016-06-12 23:06:58 +02:00
dgl_menuitem = dialog_menu->getItem();
if ( dgl_menuitem )
{
dgl_menuitem->ignorePadding();
dgl_menuitem->unsetFocusable();
}
FMenuItem* close_item = new FMenuItem ("&Close", dialog_menu);
close_item->setStatusbarMessage ("Close window");
close_item->addCallback
(
"clicked",
_METHOD_CALLBACK (this, &FDialog::cb_close)
);
2015-05-23 13:35:12 +02:00
}
//----------------------------------------------------------------------
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;
if ( isNewFont() )
{
short fg;
2015-05-23 13:35:12 +02:00
if ( ! isRootWidget() )
fg = parentWidget()->getForegroundColor();
else
fg = wc.term_fg;
for (int y=y1; y <= y2; y++)
{
setColor (fg, backgroundColor);
gotoxy (x1, y);
// border left ⎸
print (fc::NF_border_line_left);
gotoxy (x2, y);
// border right⎹
print (fc::NF_rev_border_line_right);
}
2016-01-24 14:53:09 +01:00
if ( (flags & fc::shadow) == 0 )
2015-05-23 13:35:12 +02:00
{
setColor (fg, backgroundColor);
gotoxy (x1, y2);
// lower left corner border ⎣
print (fc::NF_border_corner_lower_left);
for (int x=1; x < width-1; x++) // low line _
print (fc::NF_border_line_bottom);
gotoxy (x2, y2);
// lower right corner border ⎦
print (fc::NF_rev_border_corner_lower_right);
}
}
else
{
gotoxy (x1, y1);
print (fc::BoxDrawingsDownAndRight); // ┌
for (int x=x1+1; x < x2; x++)
print (fc::BoxDrawingsHorizontal); // ─
print (fc::BoxDrawingsDownAndLeft); // ┐
gotoxy (x1, y2);
print (fc::BoxDrawingsUpAndRight); // └
for (int x=x1+1; x < x2; x++)
print (fc::BoxDrawingsHorizontal); // ─
print (fc::BoxDrawingsUpAndLeft); // ┘
for (int y=y1+1; y < y2; y++)
{
gotoxy (x1, y);
print (fc::BoxDrawingsVertical); // │
gotoxy (x2, y);
print (fc::BoxDrawingsVertical); // │
}
}
}
//----------------------------------------------------------------------
void FDialog::drawTitleBar()
{
int i,x;
2015-09-20 05:44:50 +02:00
uInt length = tb_text.getLength();
2015-05-23 13:35:12 +02:00
// draw the title button
gotoxy (xpos+xmin-1, ypos+ymin-1);
setColor (wc.titlebar_button_fg, wc.titlebar_button_bg);
if ( isMonochron() )
2015-10-11 21:56:16 +02:00
{
if ( isActiveWindow() )
setReverse(false);
else
setReverse(true);
}
2015-10-23 23:57:00 +02:00
2015-05-23 13:35:12 +02:00
if ( isNewFont() )
{
print (fc::NF_rev_menu_button1);
print (fc::NF_rev_menu_button2);
print (fc::NF_rev_menu_button3);
}
else if ( isMonochron() )
2016-06-12 23:06:58 +02:00
{
print ('[');
if ( dgl_menuitem )
print (dgl_menuitem->getText());
else
print ('-');
print (']');
}
2015-05-23 13:35:12 +02:00
else
2016-06-12 23:06:58 +02:00
{
print (' ');
if ( dgl_menuitem )
print (dgl_menuitem->getText());
else
print ('-');
print (' ');
}
2015-05-23 13:35:12 +02:00
// fill with spaces (left of the title)
2015-10-23 23:57:00 +02:00
if ( getMaxColor() < 16 )
setBold();
2016-06-12 23:06:58 +02:00
if ( isActiveWindow() || dialog_menu->isVisible() )
2015-05-23 13:35:12 +02:00
setColor (wc.titlebar_active_fg, wc.titlebar_active_bg);
else
setColor (wc.titlebar_inactive_fg, wc.titlebar_inactive_bg);
i = width - 3 - int(length);
i = int(i/2);
for (x=1; x <= i; x++)
print (' ');
// the title bar text
2015-12-08 21:05:00 +01:00
if ( tb_text )
print (tb_text);
2015-05-23 13:35:12 +02:00
// fill the rest of the bar
2015-09-24 00:41:43 +02:00
for (; x+1+int(length) < width-1; x++)
2015-05-23 13:35:12 +02:00
print (' ');
2015-10-23 23:57:00 +02:00
if ( getMaxColor() < 16 )
unsetBold();
2015-05-23 13:35:12 +02:00
if ( isMonochron() )
setReverse(false);
/* print the number of window in stack */
//gotoxy(xpos+xmin+width-4, ypos+ymin-1);
//printf ("(%d)", getWindowLayer(this));
}
2016-06-13 22:44:15 +02:00
//----------------------------------------------------------------------
void FDialog::leaveMenu()
{
dialog_menu->unselectItem();
dialog_menu->hide();
activateWindow();
raiseWindow();
getFocusWidget()->setFocus();
redraw();
if ( statusBar() )
statusBar()->drawMessage();
updateTerminal();
flush_out();
}
2016-06-12 23:06:58 +02:00
//----------------------------------------------------------------------
void FDialog::cb_close (FWidget*, void*)
{
dialog_menu->unselectItem();
dialog_menu->hide();
setClickedWidget(0);
drawTitleBar();
close();
}
2015-05-23 13:35:12 +02:00
// protected methods of FDialog
//----------------------------------------------------------------------
void FDialog::done(int result)
{
hide();
result_code = result;
}
//----------------------------------------------------------------------
void FDialog::drawDialogShadow()
{
2016-01-24 14:53:09 +01:00
if ((flags & fc::trans_shadow) != 0)
2015-05-23 13:35:12 +02:00
{
// transparent shadow
drawShadow();
2015-10-11 21:56:16 +02:00
2016-01-24 14:53:09 +01:00
if ( isNewFont() && ((flags & fc::scrollable) == 0) )
2015-05-23 13:35:12 +02:00
{
FOptiAttr::char_data ch;
2015-10-29 21:10:50 +01:00
// left of the shadow ▀▀
2015-05-23 13:35:12 +02:00
gotoxy (xpos+xmin-1, ypos+ymin-1+height);
for (int x=0; x <= 1; x++)
{
ch = getCoveredCharacter (xpos+xmin-1+x, ypos+ymin-1+height, this);
setColor (wc.shadow_fg, ch.bg_color);
// high line ⎺
print (fc::NF_border_line_upper);
}
}
}
else
{
2015-10-11 21:56:16 +02:00
if ( isMonochron() )
return;
2015-05-23 13:35:12 +02:00
drawShadow();
2015-10-11 21:56:16 +02:00
FOptiAttr::char_data ch;
2015-05-23 13:35:12 +02:00
ch = getCoveredCharacter (xpos+xmin-1, ypos+ymin-1+height, this);
2015-10-29 21:10:50 +01:00
// left of the shadow ▀▀
2015-05-23 13:35:12 +02:00
gotoxy (xpos+xmin-1, ypos+ymin-1+height);
2016-01-24 14:53:09 +01:00
if ( isNewFont() && ((flags & fc::scrollable) == 0) )
2015-05-23 13:35:12 +02:00
{
setColor (wc.shadow_fg, ch.bg_color);
// high line ⎺
print (fc::NF_border_line_upper);
}
else
{
setColor(ch.fg_color, ch.bg_color);
if ( ch.bold )
setBold();
if ( ch.dim )
setDim();
if ( ch.italic )
setItalic();
2015-05-23 13:35:12 +02:00
if ( ch.underline )
setUnderline();
if ( ch.blink )
setBlink();
if ( ch.reverse )
setReverse();
if ( ch.standout )
setStandout();
if ( ch.invisible )
setInvisible();
if ( ch.protect )
setProtected();
if ( ch.crossed_out )
setCrossedOut();
if ( ch.dbl_underline )
setDoubleUnderline();
if ( ch.alt_charset )
setAltCharset (true);
if ( ch.pc_charset )
setPCcharset (true);
2015-05-23 13:35:12 +02:00
print (ch.code);
setNormal();
2015-05-23 13:35:12 +02:00
}
}
}
//----------------------------------------------------------------------
void FDialog::draw()
{
if ( maximized && ! isRootWidget() )
{
xpos = 1;
ypos = 1;
width = xmax;
height = ymax;
}
2015-10-11 21:56:16 +02:00
setUpdateVTerm(false);
2015-05-23 13:35:12 +02:00
// fill the background
setColor (foregroundColor, backgroundColor);
2015-10-11 21:56:16 +02:00
if ( isMonochron() )
setReverse(true);
2015-05-23 13:35:12 +02:00
clrscr();
drawBorder();
drawTitleBar();
2016-01-24 14:53:09 +01:00
if ( ! maximized && (flags & fc::shadow) != 0 )
2015-05-23 13:35:12 +02:00
drawDialogShadow();
2016-01-24 14:53:09 +01:00
if ( (flags & fc::resizeable) != 0 )
2015-05-23 13:35:12 +02:00
{
2015-10-11 21:56:16 +02:00
if ( isMonochron() )
setReverse(false);
2015-05-23 13:35:12 +02:00
if ( maximized )
{
if ( isNewFont() )
{
gotoxy (xpos+xmin+width-3, ypos+ymin-1);
setColor (wc.titlebar_button_fg, wc.titlebar_button_bg);
print (fc::NF_rev_down_pointing_triangle1);
print (fc::NF_rev_down_pointing_triangle2);
}
else
{
gotoxy (xpos+xmin+width-4, ypos+ymin-1);
setColor (wc.titlebar_button_fg, wc.titlebar_button_bg);
print (' ');
print (fc::BlackDownPointingTriangle); // ▼
print (' ');
}
}
else
{
if ( isNewFont() )
{
gotoxy (xpos+xmin+width-3, ypos+ymin-1);
setColor (wc.titlebar_button_fg, wc.titlebar_button_bg);
print (fc::NF_rev_up_pointing_triangle1);
print (fc::NF_rev_up_pointing_triangle2);
}
else
{
gotoxy (xpos+xmin+width-4, ypos+ymin-1);
setColor (wc.titlebar_button_fg, wc.titlebar_button_bg);
print (' ');
print (fc::BlackUpPointingTriangle); // ▲
print (' ');
}
}
}
2015-10-11 21:56:16 +02:00
if ( isMonochron() )
setReverse(false);
2015-05-23 13:35:12 +02:00
setUpdateVTerm(true);
}
//----------------------------------------------------------------------
void FDialog::onShow (FShowEvent*)
2015-09-22 04:18:20 +02:00
{ }
2015-05-23 13:35:12 +02:00
//----------------------------------------------------------------------
void FDialog::onHide (FHideEvent*)
2015-09-22 04:18:20 +02:00
{ }
2015-05-23 13:35:12 +02:00
//----------------------------------------------------------------------
2015-09-20 05:44:50 +02:00
void FDialog::onClose (FCloseEvent* ev)
2015-05-23 13:35:12 +02:00
{
2015-09-20 05:44:50 +02:00
ev->accept();
2015-05-23 13:35:12 +02:00
result_code = FDialog::Reject;
}
// public methods of FDialog
//----------------------------------------------------------------------
2015-09-20 05:44:50 +02:00
void FDialog::onKeyPress (FKeyEvent* ev)
2015-05-23 13:35:12 +02:00
{
if ( ! isEnabled() || this == getMainWidget() )
return;
2015-09-20 05:44:50 +02:00
if ( ev->key() == fc::Fkey_escape
|| ev->key() == fc::Fkey_escape_mintty )
2015-05-23 13:35:12 +02:00
{
2015-09-20 05:44:50 +02:00
ev->accept();
2015-05-23 13:35:12 +02:00
if ( isModal() )
done (FDialog::Reject);
else
close();
}
}
//----------------------------------------------------------------------
2015-09-20 05:44:50 +02:00
void FDialog::onMouseDown (FMouseEvent* ev)
2015-05-23 13:35:12 +02:00
{
2015-09-20 05:44:50 +02:00
int mouse_x = ev->getX();
int mouse_y = ev->getY();
2015-05-23 13:35:12 +02:00
2016-01-17 02:57:08 +01:00
if ( ev->getButton() == fc::LeftButton )
2015-05-23 13:35:12 +02:00
{
// click on titlebar or window: raise + activate
if ( mouse_x >= 4 && mouse_x <= width && mouse_y == 1 )
2015-09-20 05:44:50 +02:00
TitleBarClickPos.setPoint (ev->getGlobalX(), ev->getGlobalY());
2015-05-23 13:35:12 +02:00
else
TitleBarClickPos.setPoint (0,0);
bool has_raised = raiseWindow();
if ( ! isActiveWindow() )
{
FWidget* old_focus = FWidget::getFocusWidget();
setActiveWindow(this);
if ( focus_widget )
{
focus_widget->setFocus();
focus_widget->redraw();
if ( old_focus )
old_focus->redraw();
}
else if ( old_focus && focusFirstChild() )
old_focus->redraw();
updateTerminal();
2015-05-23 13:35:12 +02:00
}
if ( has_raised )
redraw();
2016-06-12 23:06:58 +02:00
// click on titlebar menu button
if ( mouse_x < 4 && mouse_y == 1 )
{
if ( dialog_menu->isVisible() )
2016-06-13 22:44:15 +02:00
leaveMenu();
2016-06-12 23:06:58 +02:00
else
{
setOpenMenu(dialog_menu);
dialog_menu->move (xpos, ypos+1);
dialog_menu->setVisible();
dialog_menu->show();
dialog_menu->raiseWindow(dialog_menu);
dialog_menu->redraw();
}
}
}
else // ev->getButton() != fc::LeftButton
{
// click on titlebar menu button
if ( mouse_x < 4 && mouse_y == 1 && dialog_menu->isVisible() )
2016-06-13 22:44:15 +02:00
leaveMenu(); // close menu
2015-05-23 13:35:12 +02:00
}
2016-01-17 02:57:08 +01:00
if ( ev->getButton() == fc::RightButton )
2015-05-23 13:35:12 +02:00
{
// click on titlebar: just activate
if ( mouse_x >= 4 && mouse_x <= width && mouse_y == 1 )
{
if ( ! isActiveWindow() )
{
FWidget* old_focus = FWidget::getFocusWidget();
setActiveWindow(this);
if ( focus_widget )
{
focus_widget->setFocus();
focus_widget->redraw();
if ( old_focus )
old_focus->redraw();
}
else if ( focusFirstChild() )
if ( old_focus )
old_focus->redraw();
}
}
}
2016-01-17 02:57:08 +01:00
if ( ev->getButton() == fc::MiddleButton )
2015-05-23 13:35:12 +02:00
{
// click on titlebar: lower + activate
if ( mouse_x >= 4 && mouse_x <= width && mouse_y == 1 )
{
bool has_lowered = lowerWindow();
if ( ! isActiveWindow() )
{
FWidget* old_focus = FWidget::getFocusWidget();
setActiveWindow(this);
if ( focus_widget )
{
focus_widget->setFocus();
focus_widget->redraw();
if ( old_focus )
old_focus->redraw();
}
else if ( focusFirstChild() )
if ( old_focus )
old_focus->redraw();
};
if ( has_lowered )
updateTerminal();
}
}
}
//----------------------------------------------------------------------
2015-09-20 05:44:50 +02:00
void FDialog::onMouseUp (FMouseEvent* ev)
2015-05-23 13:35:12 +02:00
{
int titlebar_x = TitleBarClickPos.getX();
int titlebar_y = TitleBarClickPos.getY();
2016-01-17 02:57:08 +01:00
if ( ev->getButton() == fc::LeftButton )
2015-05-23 13:35:12 +02:00
{
2016-06-12 23:06:58 +02:00
int mouse_x = ev->getX();
int mouse_y = ev->getY();
2015-05-23 13:35:12 +02:00
if ( ! TitleBarClickPos.isNull()
2015-09-24 00:41:43 +02:00
&& titlebar_x > xpos+xmin+2
&& titlebar_x < xpos+xmin+width
2015-05-23 13:35:12 +02:00
&& titlebar_y == ypos+ymin-1 )
{
FPoint currentPos(getGeometry().getX(), getGeometry().getY());
2015-09-20 05:44:50 +02:00
FPoint deltaPos = ev->getGlobalPos() - TitleBarClickPos;
2015-05-23 13:35:12 +02:00
move (currentPos + deltaPos);
2015-09-20 05:44:50 +02:00
TitleBarClickPos = ev->getGlobalPos();
2015-05-23 13:35:12 +02:00
}
2016-06-12 23:06:58 +02:00
// click on titlebar menu button
if ( mouse_x < 4
&& mouse_y == 1
&& dialog_menu->isVisible()
&& ! dialog_menu->hasSelectedItem() )
{
2016-06-13 22:44:15 +02:00
FMenuItem* first_item;
2016-06-12 23:06:58 +02:00
dialog_menu->selectFirstItem();
first_item = dialog_menu->getSelectedItem();
if ( first_item )
first_item->setFocus();
dialog_menu->redraw();
if ( statusBar() )
statusBar()->drawMessage();
updateTerminal();
flush_out();
}
2015-05-23 13:35:12 +02:00
}
}
//----------------------------------------------------------------------
2015-09-20 05:44:50 +02:00
void FDialog::onMouseMove (FMouseEvent* ev)
2015-05-23 13:35:12 +02:00
{
2016-01-17 02:57:08 +01:00
if ( ev->getButton() == fc::LeftButton )
2015-05-23 13:35:12 +02:00
{
if ( ! TitleBarClickPos.isNull() )
2015-05-23 13:35:12 +02:00
{
FPoint currentPos(getGeometry().getX(), getGeometry().getY());
2015-09-20 05:44:50 +02:00
FPoint deltaPos = ev->getGlobalPos() - TitleBarClickPos;
2015-05-23 13:35:12 +02:00
move (currentPos + deltaPos);
2015-09-20 05:44:50 +02:00
TitleBarClickPos = ev->getGlobalPos();
2015-05-23 13:35:12 +02:00
}
2016-06-12 23:06:58 +02:00
if ( dialog_menu->isVisible() && dialog_menu->isShown() )
{
// Mouse event handover to the menu
const FRect& menu_geometry = dialog_menu->getGeometryGlobal();
2016-06-13 22:44:15 +02:00
2016-06-12 23:06:58 +02:00
if ( dialog_menu->count() > 0
&& menu_geometry.contains(ev->getGlobalPos()) )
{
const FPoint& g = ev->getGlobalPos();
const FPoint& p = dialog_menu->globalToLocalPos(g);
int b = ev->getButton();
FMouseEvent* _ev = new FMouseEvent (fc::MouseMove_Event, p, g, b);
dialog_menu->mouse_down = true;
setClickedWidget(dialog_menu);
dialog_menu->onMouseMove(_ev);
delete _ev;
}
}
2015-05-23 13:35:12 +02:00
}
}
//----------------------------------------------------------------------
2015-09-20 05:44:50 +02:00
void FDialog::onMouseDoubleClick (FMouseEvent* ev)
2015-05-23 13:35:12 +02:00
{
int x, y;
2016-01-17 02:57:08 +01:00
if ( ev->getButton() != fc::LeftButton )
2015-05-23 13:35:12 +02:00
return;
x = xpos + xmin - 1;
y = ypos + ymin - 1;
FRect title_button(x, y, 3, 1);
2015-09-20 05:44:50 +02:00
FPoint gPos = ev->getGlobalPos();
2015-05-23 13:35:12 +02:00
if ( title_button.contains(gPos) )
{
2016-06-12 23:06:58 +02:00
dialog_menu->unselectItem();
dialog_menu->hide();
2015-05-23 13:35:12 +02:00
setClickedWidget(0);
2016-06-12 23:06:58 +02:00
if ( isModal() )
done(FDialog::Reject);
else
close();
2015-05-23 13:35:12 +02:00
}
}
//----------------------------------------------------------------------
void FDialog::onWindowActive (FEvent*)
{
if ( isVisible() && isShown() )
drawTitleBar();
2016-06-12 23:06:58 +02:00
if ( focus_widget && focus_widget->isVisible() && focus_widget->isShown() )
2015-05-23 13:35:12 +02:00
{
2016-06-12 23:06:58 +02:00
focus_widget->setFocus();
focus_widget->redraw();
if ( statusBar() )
statusBar()->drawMessage();
2015-05-23 13:35:12 +02:00
}
2016-06-12 23:06:58 +02:00
else
focusFirstChild();
2015-05-23 13:35:12 +02:00
}
//----------------------------------------------------------------------
void FDialog::onWindowInactive (FEvent*)
{
if ( isVisible() && isEnabled() )
drawTitleBar();
}
//----------------------------------------------------------------------
void FDialog::onWindowRaised (FEvent*)
{
widgetList::const_iterator iter, end;
2015-09-15 23:07:24 +02:00
if ( ! isVisible() || ! isShown() )
return;
2015-05-23 13:35:12 +02:00
putArea (getGlobalPos(), vwin);
if ( ! window_list )
return;
if ( window_list->empty() )
return;
2015-10-29 21:10:50 +01:00
// redraw shadow of the other windows
2015-05-23 13:35:12 +02:00
iter = window_list->begin();
end = window_list->end();
while ( iter != end )
{
if ( *iter != this
&& ! maximized
2016-01-24 14:53:09 +01:00
&& ((*iter)->getFlags() & fc::shadow) != 0 )
2015-05-23 13:35:12 +02:00
static_cast<FDialog*>(*iter)->drawDialogShadow();
++iter;
}
}
//----------------------------------------------------------------------
void FDialog::onWindowLowered (FEvent*)
{
widgetList::const_iterator iter, end;
if ( ! window_list )
return;
if ( window_list->empty() )
return;
iter = window_list->begin();
end = window_list->end();
while ( iter != end )
{
putArea ((*iter)->getGlobalPos(), (*iter)->getVWin());
2016-01-24 14:53:09 +01:00
if ( ! maximized && ((*iter)->getFlags() & fc::shadow) != 0 )
2015-05-23 13:35:12 +02:00
static_cast<FDialog*>(*iter)->drawDialogShadow();
++iter;
}
}
//----------------------------------------------------------------------
void FDialog::show()
{
if ( ! isVisible() )
return;
FWindow::show();
2015-05-23 13:35:12 +02:00
// set the cursor to the focus widget
if ( FWidget::getFocusWidget()
&& FWidget::getFocusWidget()->isVisible()
&& FWidget::getFocusWidget()->hasVisibleCursor()
&& FWidget::getFocusWidget()->isCursorInside() )
{
FWidget::getFocusWidget()->setCursor();
showCursor();
flush_out();
}
if ( isModal() )
{
FApplication* fapp = static_cast<FApplication*>(getRootWidget());
fapp->enter_loop();
if ( this == getMainWidget() )
fapp->quit();
}
}
//----------------------------------------------------------------------
void FDialog::hide()
{
FWindow::hide();
2015-05-23 13:35:12 +02:00
if ( isModal() )
{
FApplication* fapp = static_cast<FApplication*>(getRootWidget());
fapp->exit_loop();
}
}
//----------------------------------------------------------------------
int FDialog::exec()
{
result_code = FDialog::Reject;
show();
return result_code;
}
//----------------------------------------------------------------------
void FDialog::move (const FPoint& pos)
{
move( pos.getX(), pos.getY() );
}
//----------------------------------------------------------------------
void FDialog::move (int x, int y)
{
int dx, dy, old_x, old_y;
if ( x == xpos && y == ypos )
return;
if ( x+width < 1 || x > getColumnNumber() || y < 1 || y > getLineNumber() )
return;
dx = xpos - x;
dy = ypos - y;
2015-08-09 23:44:11 +02:00
old_x = getGlobalX();
old_y = getGlobalY();
2015-05-23 13:35:12 +02:00
short& rsw = shadow.x_ref(); // right shadow width;
short& bsh = shadow.y_ref(); // bottom shadow height
oldGeometry = getGeometryShadow();
FWidget::move(x,y);
xpos = x;
ypos = y;
putArea (getGlobalPos(), vwin);
2015-05-23 13:35:12 +02:00
if ( getGeometry().overlap(oldGeometry) )
{
// dx > 0 : move left
// dx = 0 : move vertical
// dx < 0 : move right
// dy > 0 : move up
// dy = 0 : move horizontal
// dy < 0 : move down
if ( dx > 0 )
{
if ( dy > 0 )
restoreVTerm (old_x+width+rsw-dx, old_y, dx, height+bsh-dy);
else
restoreVTerm (old_x+width+rsw-dx, old_y+abs(dy), dx, height+bsh-abs(dy));
}
else
{
if ( dy > 0 )
restoreVTerm (old_x, old_y, abs(dx), height+bsh-dy);
else
restoreVTerm (old_x, old_y+abs(dy), abs(dx), height+bsh-abs(dy));
}
if ( dy > 0 )
restoreVTerm (old_x, old_y+height+bsh-dy, width+rsw, dy);
else
restoreVTerm (old_x, old_y, width+rsw, abs(dy));
}
else
{
restoreVTerm (old_x, old_y, width+rsw, height+bsh);
}
2016-01-24 14:53:09 +01:00
if ( ! maximized && (flags & fc::shadow) != 0 )
2015-05-23 13:35:12 +02:00
drawDialogShadow();
// handle overlaid windows
if ( window_list && ! window_list->empty() )
{
bool overlaid = false;
widgetList::const_iterator iter, end;
iter = window_list->begin();
end = window_list->end();
while ( iter != end )
{
if ( overlaid )
{
putArea ((*iter)->getGlobalPos(), (*iter)->getVWin());
2016-01-24 14:53:09 +01:00
if ( ! maximized && ((*iter)->getFlags() & fc::shadow) != 0 )
2015-05-23 13:35:12 +02:00
static_cast<FDialog*>(*iter)->drawDialogShadow();
}
if ( vwin == (*iter)->getVWin() )
overlaid = true;
++iter;
}
}
FWidget::adjustSize();
// set the cursor to the focus widget
if ( FWidget::getFocusWidget()
&& FWidget::getFocusWidget()->isVisible()
&& FWidget::getFocusWidget()->hasVisibleCursor() )
{
FPoint cursor_pos = FWidget::getFocusWidget()->getCursorPos();
cursor_pos -= FPoint(dx,dy);
if ( ! FWidget::getFocusWidget()->setCursorPos(cursor_pos) )
hideCursor();
}
updateTerminal();
}
//----------------------------------------------------------------------
void FDialog::setWidth (int w, bool adjust)
{
int old_width = width;
FWidget::setWidth (w, adjust);
if ( vwin && width != old_width )
resizeArea (vwin);
}
//----------------------------------------------------------------------
void FDialog::setHeight (int h, bool adjust)
{
int old_height = height;
FWidget::setHeight (h, adjust);
if ( vwin && height != old_height )
resizeArea (vwin);
}
//----------------------------------------------------------------------
void FDialog::setGeometry (int x, int y, int w, int h, bool adjust)
{
int old_width = width;
int old_height = height;
FWidget::setGeometry (x, y, w, h, adjust);
if ( vwin && (width != old_width || height != old_height) )
resizeArea (vwin);
}
//----------------------------------------------------------------------
FWidget* FDialog::getFocusWidget() const
{
return static_cast<FWidget*>(focus_widget);
}
//----------------------------------------------------------------------
void FDialog::setFocusWidget (FWidget* obj)
{
focus_widget = obj;
}
//----------------------------------------------------------------------
bool FDialog::setFocus (bool on)
{
FWidget::setFocus(on);
if ( on )
2016-01-24 14:53:09 +01:00
flags |= fc::focus;
2015-05-23 13:35:12 +02:00
else
2016-01-24 14:53:09 +01:00
flags &= ~fc::focus;
2015-05-23 13:35:12 +02:00
return on;
}
//----------------------------------------------------------------------
bool FDialog::setModal (bool on)
{
if ( isModal() == on )
return true;
if ( on )
{
2016-01-24 14:53:09 +01:00
flags |= fc::modal;
2015-05-23 13:35:12 +02:00
modal_dialogs++;
}
else
{
2016-01-24 14:53:09 +01:00
flags &= ~fc::modal;
2015-05-23 13:35:12 +02:00
modal_dialogs--;
}
return on;
}
//----------------------------------------------------------------------
bool FDialog::setTransparentShadow (bool on)
{
if ( on )
{
2016-01-24 14:53:09 +01:00
flags |= fc::shadow;
flags |= fc::trans_shadow;
2015-05-23 13:35:12 +02:00
shadow.setPoint(2,1);
adjustWidgetSizeShadow = getGeometry() + getShadow();
adjustWidgetSizeGlobalShadow = getGeometryGlobal() + getShadow();
}
else
{
2016-01-24 14:53:09 +01:00
flags &= ~fc::shadow;
flags &= ~fc::trans_shadow;
2015-05-23 13:35:12 +02:00
shadow.setPoint(0,0);
adjustWidgetSizeShadow = getGeometry() + getShadow();
adjustWidgetSizeGlobalShadow = getGeometryGlobal() + getShadow();
}
resizeArea (vwin);
return on;
}
//----------------------------------------------------------------------
bool FDialog::setShadow (bool on)
{
2015-10-11 21:56:16 +02:00
if ( isMonochron() )
return false;
2015-05-23 13:35:12 +02:00
if ( on )
{
2016-01-24 14:53:09 +01:00
flags |= fc::shadow;
flags &= ~fc::trans_shadow;
2015-05-23 13:35:12 +02:00
shadow.setPoint(1,1);
adjustWidgetSizeShadow = getGeometry() + getShadow();
adjustWidgetSizeGlobalShadow = getGeometryGlobal() + getShadow();
}
else
{
2016-01-24 14:53:09 +01:00
flags &= ~fc::shadow;
flags &= ~fc::trans_shadow;
2015-05-23 13:35:12 +02:00
shadow.setPoint(0,0);
adjustWidgetSizeShadow = getGeometry() + getShadow();
adjustWidgetSizeGlobalShadow = getGeometryGlobal() + getShadow();
}
resizeArea (vwin);
return on;
}
//----------------------------------------------------------------------
bool FDialog::setScrollable (bool on)
{
if ( on )
2016-01-24 14:53:09 +01:00
flags |= fc::scrollable;
2015-05-23 13:35:12 +02:00
else
2016-01-24 14:53:09 +01:00
flags &= ~fc::scrollable;
2015-05-23 13:35:12 +02:00
return on;
}
//----------------------------------------------------------------------
bool FDialog::setResizeable (bool on)
{
if ( on )
2016-01-24 14:53:09 +01:00
flags |= fc::resizeable;
2015-05-23 13:35:12 +02:00
else
2016-01-24 14:53:09 +01:00
flags &= ~fc::resizeable;
2015-05-23 13:35:12 +02:00
return on;
}
//----------------------------------------------------------------------
bool FDialog::setMaximized()
{
if ( maximized )
return true;
maximized = true;
// setGeometry(1, 1, xmax, ymax);
return maximized;
}