finalcut/src/fdialog.cpp

1193 lines
25 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)
, zoom_button_pressed(false)
, zoom_button_active(false)
2015-09-22 04:18:20 +02:00
, TitleBarClickPos()
, oldGeometry()
2016-06-12 23:06:58 +02:00
, dialog_menu()
, dgl_menuitem()
, zoom_item()
, close_item()
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)
, zoom_button_pressed(false)
, zoom_button_active(false)
2015-09-22 04:18:20 +02:00
, TitleBarClickPos()
, oldGeometry()
2016-06-12 23:06:58 +02:00
, dialog_menu()
, dgl_menuitem()
, zoom_item()
, close_item()
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
{
2016-07-28 01:04:27 +02:00
FApplication* fapp = static_cast<FApplication*>(getRootWidget());
bool is_quit = fapp->isQuit();
delete dialog_menu;
dgl_menuitem = 0;
2015-05-23 13:35:12 +02:00
delete accelerator_list;
accelerator_list = 0;
2016-07-28 01:04:27 +02:00
if ( ! is_quit )
switchToPrevWindow();
2015-05-23 13:35:12 +02:00
delWindow(this);
delDialog(this);
2015-05-23 13:35:12 +02:00
2016-07-28 01:04:27 +02:00
if ( ! is_quit )
2015-05-23 13:35:12 +02:00
{
const FRect& geometry = getGeometryGlobalShadow();
restoreVTerm (geometry);
}
if ( vwin != 0 )
{
if ( vwin->changes != 0 )
delete[] vwin->changes;
2015-05-23 13:35:12 +02:00
if ( vwin->text != 0 )
delete[] vwin->text;
2015-05-23 13:35:12 +02:00
delete vwin;
}
2015-05-23 13:35:12 +02:00
if ( isModal() )
unsetModal();
}
// private methods of FDialog
//----------------------------------------------------------------------
void FDialog::init()
{
FWidget* old_focus;
FWidget* rootObj = getRootWidget();
2016-06-12 23:06:58 +02:00
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;
2016-06-12 23:06:58 +02:00
dialog_object = true;
addDialog(this);
2015-05-23 13:35:12 +02:00
addWindow(this);
setActiveWindow(this);
setTransparentShadow();
2015-05-23 13:35:12 +02:00
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
old_focus = FWidget::getFocusWidget();
2015-05-23 13:35:12 +02:00
if ( old_focus )
{
setFocus();
2015-05-23 13:35:12 +02:00
old_focus->redraw();
}
2016-06-12 23:06:58 +02:00
accelerator_list = new Accelerators();
// Add the dialog menu
2016-06-12 23:06:58 +02:00
dialog_menu = new FMenu ("-", this);
dialog_menu->move (xpos, ypos+1);
dgl_menuitem = dialog_menu->getItem();
2016-06-12 23:06:58 +02:00
if ( dgl_menuitem )
{
dgl_menuitem->ignorePadding();
dgl_menuitem->unsetFocusable();
}
zoom_item = new FMenuItem ("&Zoom", dialog_menu);
zoom_item->setStatusbarMessage ("Enlarge or restore the window size");
zoom_item->setDisable();
zoom_item->addCallback
(
"clicked",
_METHOD_CALLBACK (this, &FDialog::cb_zoom)
);
close_item = new FMenuItem ("&Close", dialog_menu);
close_item->setStatusbarMessage ("Close this window");
2016-06-12 23:06:58 +02:00
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 ( resize )
// setColor (wc.dialog_resize_fg, backgroundColor);
2015-05-23 13:35:12 +02:00
if ( isNewFont() )
{
for (int y=y1; y <= y2; y++)
{
gotoxy (x1, y);
// border left ⎸
print (fc::NF_border_line_left);
gotoxy (x2, y);
// border right⎹
print (fc::NF_rev_border_line_right);
}
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);
2015-05-23 13:35:12 +02:00
}
else
{
gotoxy (x1, y1);
print (fc::BoxDrawingsDownAndRight); // ┌
2015-05-23 13:35:12 +02:00
for (int x=x1+1; x < x2; x++)
print (fc::BoxDrawingsHorizontal); // ─
print (fc::BoxDrawingsDownAndLeft); // ┐
2015-05-23 13:35:12 +02:00
gotoxy (x1, y2);
print (fc::BoxDrawingsUpAndRight); // └
2015-05-23 13:35:12 +02:00
for (int x=x1+1; x < x2; x++)
print (fc::BoxDrawingsHorizontal); // ─
2015-05-23 13:35:12 +02:00
print (fc::BoxDrawingsUpAndLeft); // ┘
for (int y=y1+1; y < y2; y++)
{
gotoxy (x1, y);
print (fc::BoxDrawingsVertical); // │
gotoxy (x2, y);
print (fc::BoxDrawingsVertical); // │
}
2015-05-23 13:35:12 +02:00
}
}
//----------------------------------------------------------------------
void FDialog::drawTitleBar()
{
int i,x,length, zoom_btn;
const int menu_btn = 3;
2015-05-23 13:35:12 +02:00
// draw the title button
gotoxy (xpos+xmin-1, ypos+ymin-1);
if ( dialog_menu && dialog_menu->isVisible() )
setColor (wc.titlebar_button_focus_fg, wc.titlebar_button_focus_bg);
else
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 ('[');
2016-06-12 23:06:58 +02:00
if ( dgl_menuitem )
print (dgl_menuitem->getText());
else
print ('-');
2016-06-12 23:06:58 +02:00
print (']');
}
2015-05-23 13:35:12 +02:00
else
2016-06-12 23:06:58 +02:00
{
print (' ');
2016-06-12 23:06:58 +02:00
if ( dgl_menuitem )
print (dgl_menuitem->getText());
else
print ('-');
2016-06-12 23:06:58 +02:00
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();
if ( isActiveWindow() || (dialog_menu && 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);
if ( (flags & fc::resizeable) == 0 )
zoom_btn = 0;
else if ( isNewFont() )
zoom_btn = 2;
else
zoom_btn = 3;
length = int(tb_text.getLength());
i = width - length - menu_btn - zoom_btn;
2015-05-23 13:35:12 +02:00
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
for (; x+1+length < width-zoom_btn-1; x++)
2015-05-23 13:35:12 +02:00
print (' ');
2015-10-23 23:57:00 +02:00
if ( getMaxColor() < 16 )
unsetBold();
// draw the zoom/unzoom button
if ( (flags & fc::resizeable) != 0 )
{
if ( zoom_button_pressed )
setColor (wc.titlebar_button_focus_fg, wc.titlebar_button_focus_bg);
else
setColor (wc.titlebar_button_fg, wc.titlebar_button_bg);
if ( isZoomed() )
{
if ( isNewFont() )
{
print (fc::NF_rev_down_pointing_triangle1);
print (fc::NF_rev_down_pointing_triangle2);
}
else
{
if ( isMonochron() )
{
print ('[');
print (fc::BlackDownPointingTriangle); // ▼
print (']');
}
else
{
print (' ');
if ( isCygwinTerminal() )
print ('v');
else
print (fc::BlackDownPointingTriangle); // ▼
print (' ');
}
}
}
else // is not zoomed
{
if ( isNewFont() )
{
print (fc::NF_rev_up_pointing_triangle1);
print (fc::NF_rev_up_pointing_triangle2);
}
else
{
if ( isMonochron() )
{
print ('[');
print (fc::BlackUpPointingTriangle); // ▲
print (']');
}
else
{
print (' ');
if ( isCygwinTerminal() )
print ('^');
else
print (fc::BlackUpPointingTriangle); // ▲
print (' ');
}
}
}
}
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();
if ( getWindowFocusWidget() )
getWindowFocusWidget()->setFocus();
2016-06-13 22:44:15 +02:00
redraw();
2016-06-13 22:44:15 +02:00
if ( statusBar() )
statusBar()->drawMessage();
2016-06-13 22:44:15 +02:00
updateTerminal();
flush_out();
}
//----------------------------------------------------------------------
void FDialog::cb_zoom (FWidget*, void*)
{
dialog_menu->unselectItem();
dialog_menu->hide();
setClickedWidget(0);
drawTitleBar();
zoomWindow();
}
2016-06-12 23:06:58 +02:00
//----------------------------------------------------------------------
void FDialog::cb_close (FWidget*, void*)
{
dialog_menu->unselectItem();
dialog_menu->hide();
setClickedWidget(0);
drawTitleBar();
close();
}
//----------------------------------------------------------------------
void FDialog::addDialog (FWidget* obj)
{
// add the dialog object obj to the dialog list
if ( dialog_list )
dialog_list->push_back(obj);
}
//----------------------------------------------------------------------
void FDialog::delDialog (FWidget* obj)
{
// delete the dialog object obj from the dialog list
if ( ! dialog_list || dialog_list->empty() )
return;
widgetList::iterator iter;
iter = dialog_list->begin();
while ( iter != dialog_list->end() )
{
if ( (*iter) == obj )
{
dialog_list->erase(iter);
return;
}
++iter;
}
}
2016-06-12 23:06:58 +02:00
2015-05-23 13:35:12 +02:00
// protected methods of FDialog
//----------------------------------------------------------------------
void FDialog::done(int result)
{
hide();
result_code = result;
}
//----------------------------------------------------------------------
void FDialog::drawDialogShadow()
{
if ( isMonochron() && (flags & fc::trans_shadow) == 0 )
return;
2015-05-23 13:35:12 +02:00
drawShadow();
gotoxy (xpos+xmin-1, ypos+ymin-1+height);
setTransparent();
print(' ');
unsetTransparent();
2015-05-23 13:35:12 +02:00
}
//----------------------------------------------------------------------
void FDialog::draw()
{
/*if ( isZoomed() && ! isRootWidget() )
2015-05-23 13:35:12 +02:00
{
xpos = 1;
ypos = 1;
width = xmax;
height = ymax;
}*/
2015-10-11 21:56:16 +02:00
updateVTerm(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);
clearArea();
2015-05-23 13:35:12 +02:00
drawBorder();
drawTitleBar();
if ( (flags & fc::shadow) != 0 )
2015-05-23 13:35:12 +02:00
drawDialogShadow();
2015-10-11 21:56:16 +02:00
if ( isMonochron() )
setReverse(false);
updateVTerm(true);
2015-05-23 13:35:12 +02:00
}
//----------------------------------------------------------------------
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();
int zoom_btn;
if ( (flags & fc::resizeable) == 0 )
zoom_btn = 0;
else if ( isNewFont() )
zoom_btn = 2;
else
zoom_btn = 3;
if ( zoom_button_pressed || zoom_button_active )
{
zoom_button_pressed = false;
zoom_button_active = false;
drawTitleBar();
}
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
{
bool has_raised;
2015-05-23 13:35:12 +02:00
// click on titlebar or window: raise + activate
if ( mouse_x >= 4 && mouse_x <= width-zoom_btn && 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);
has_raised = raiseWindow();
2015-05-23 13:35:12 +02:00
if ( ! isActiveWindow() )
2016-07-25 23:50:57 +02:00
activateDialog();
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();
drawTitleBar();
}
2016-06-12 23:06:58 +02:00
else
{
setOpenMenu(dialog_menu);
dialog_menu->move (xpos, ypos+1);
dialog_menu->setVisible();
drawTitleBar();
2016-06-12 23:06:58 +02:00
dialog_menu->show();
dialog_menu->raiseWindow(dialog_menu);
dialog_menu->redraw();
}
}
else if ( mouse_x > width-zoom_btn && mouse_y == 1 )
{
zoom_button_pressed = true;
zoom_button_active = true;
drawTitleBar();
}
2016-06-12 23:06:58 +02:00
}
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() )
2016-07-25 23:50:57 +02:00
activateDialog();
2015-05-23 13:35:12 +02:00
}
}
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() )
2016-07-25 23:50:57 +02:00
activateDialog();
else if ( has_lowered )
2015-05-23 13:35:12 +02:00
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();
int zoom_btn;
if ( (flags & fc::resizeable) == 0 )
zoom_btn = 0;
else if ( isNewFont() )
zoom_btn = 2;
else
zoom_btn = 3;
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
{
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();
2016-06-12 23:06:58 +02:00
if ( first_item )
first_item->setFocus();
2016-06-12 23:06:58 +02:00
dialog_menu->redraw();
2016-06-12 23:06:58 +02:00
if ( statusBar() )
statusBar()->drawMessage();
2016-06-12 23:06:58 +02:00
updateTerminal();
flush_out();
}
else if ( mouse_x > width - zoom_btn
&& mouse_y == 1
&& zoom_button_pressed )
{
// zoom to maximum or restore the window size
zoomWindow();
}
}
if ( zoom_button_pressed || zoom_button_active )
{
zoom_button_pressed = false;
zoom_button_active = false;
drawTitleBar();
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
{
int zoom_btn;
if ( (flags & fc::resizeable) == 0 )
zoom_btn = 0;
else if ( isNewFont() )
zoom_btn = 2;
else
zoom_btn = 3;
2016-01-17 02:57:08 +01:00
if ( ev->getButton() == fc::LeftButton )
2015-05-23 13:35:12 +02:00
{
int mouse_x = ev->getX();
int mouse_y = ev->getY();
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;
}
}
if ( mouse_x > width - zoom_btn && mouse_y == 1 && zoom_button_active )
{
zoom_button_pressed = true;
drawTitleBar();
}
else if ( zoom_button_pressed )
{
zoom_button_pressed = false;
drawTitleBar();
}
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) )
{
FWidget* window_focus_widget;
2016-06-12 23:06:58 +02:00
dialog_menu->unselectItem();
dialog_menu->hide();
activateWindow();
raiseWindow();
window_focus_widget = getWindowFocusWidget();
if ( window_focus_widget )
window_focus_widget->setFocus();
2015-05-23 13:35:12 +02:00
setClickedWidget(0);
2016-06-12 23:06:58 +02:00
if ( isModal() )
done (FDialog::Reject);
2016-06-12 23:06:58 +02:00
else
close();
2015-05-23 13:35:12 +02:00
}
}
//----------------------------------------------------------------------
void FDialog::onAccel (FAccelEvent*)
{
if ( ! (isHiddenWindow() || isActiveWindow()) )
{
2016-07-25 23:50:57 +02:00
bool has_raised = raiseWindow();
activateDialog();
2016-07-25 23:50:57 +02:00
if ( has_raised )
redraw();
2016-07-25 23:50:57 +02:00
updateTerminal();
}
}
2015-05-23 13:35:12 +02:00
//----------------------------------------------------------------------
void FDialog::onWindowActive (FEvent*)
{
if ( isVisible() && isShown() )
drawTitleBar();
if ( ! FWidget::getFocusWidget() )
2015-05-23 13:35:12 +02:00
{
FWidget* win_focus = getWindowFocusWidget();
if ( win_focus
&& win_focus->isVisible()
&& win_focus->isShown() )
{
win_focus->setFocus();
win_focus->redraw();
}
else
focusFirstChild();
2015-05-23 13:35:12 +02:00
}
if ( statusBar() )
statusBar()->drawMessage();
updateTerminal();
2015-05-23 13:35:12 +02:00
}
//----------------------------------------------------------------------
void FDialog::onWindowInactive (FEvent*)
{
if ( dialog_menu && ! dialog_menu->isVisible() )
FWindow::previous_widget = this;
2015-05-23 13:35:12 +02:00
if ( isVisible() && isEnabled() )
drawTitleBar();
if ( hasFocus() )
unsetFocus();
2015-05-23 13:35:12 +02:00
}
//----------------------------------------------------------------------
void FDialog::onWindowRaised (FEvent*)
{
widgetList::const_iterator iter, end;
2015-09-15 23:07:24 +02:00
if ( ! (isVisible() && isShown()) )
2015-09-15 23:07:24 +02:00
return;
2015-05-23 13:35:12 +02:00
putArea (getGlobalPos(), vwin);
if ( ! window_list )
return;
2015-05-23 13:35:12 +02:00
if ( window_list->empty() )
return;
}
//----------------------------------------------------------------------
void FDialog::onWindowLowered (FEvent*)
{
widgetList::const_iterator iter, end;
if ( ! window_list )
return;
2015-05-23 13:35:12 +02:00
if ( window_list->empty() )
return;
iter = window_list->begin();
end = window_list->end();
while ( iter != end )
{
putArea ((*iter)->getGlobalPos(), (*iter)->getVWin());
++iter;
}
}
//----------------------------------------------------------------------
void FDialog::show()
{
if ( ! isVisible() )
return;
FWindow::show();
2015-05-23 13:35:12 +02:00
// set the cursor to the focus widget
FWidget* focus_widget = FWidget::getFocusWidget();
if ( focus_widget
&& focus_widget->isVisible()
&& focus_widget->hasVisibleCursor()
&& focus_widget->isCursorInside() )
2015-05-23 13:35:12 +02:00
{
focus_widget->setCursor();
2015-05-23 13:35:12 +02:00
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;
2015-05-23 13:35:12 +02:00
if ( x+width < 1 || x > getColumnNumber() || y < 1 || y > getLineNumber() )
return;
if ( isZoomed() )
return;
2015-05-23 13:35:12 +02:00
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);updateTerminal();
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);
}
// 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());
2015-05-23 13:35:12 +02:00
if ( vwin == (*iter)->getVWin() )
overlaid = true;
2015-05-23 13:35:12 +02:00
++iter;
}
}
FWidget::adjustSize();
// set the cursor to the focus widget
FWidget* focus_widget = FWidget::getFocusWidget();
if ( focus_widget
&& focus_widget->isVisible()
&& focus_widget->hasVisibleCursor() )
2015-05-23 13:35:12 +02:00
{
FPoint cursor_pos = focus_widget->getCursorPos();
2015-05-23 13:35:12 +02:00
cursor_pos -= FPoint(dx,dy);
if ( ! focus_widget->setCursorPos(cursor_pos) )
2015-05-23 13:35:12 +02:00
hideCursor();
}
2015-05-23 13:35:12 +02:00
updateTerminal();
}
2016-07-25 23:50:57 +02:00
//----------------------------------------------------------------------
void FDialog::activateDialog()
{
FWidget* old_focus = FWidget::getFocusWidget();
FWidget* win_focus = getWindowFocusWidget();
2016-07-25 23:50:57 +02:00
setActiveWindow(this);
2016-07-28 23:38:17 +02:00
setFocus();
setFocusWidget(this);
2016-07-25 23:50:57 +02:00
if ( win_focus && numOfFocusableChildren() > 1 )
2016-07-25 23:50:57 +02:00
{
win_focus->setFocus();
win_focus->redraw();
2016-07-25 23:50:57 +02:00
if ( old_focus )
old_focus->redraw();
}
else if ( old_focus )
{
if ( ! focusFirstChild() )
old_focus->unsetFocus();
2016-07-31 22:49:09 +02:00
if ( ! old_focus->isWindow() )
old_focus->redraw();
2016-07-25 23:50:57 +02:00
}
if ( statusBar() )
statusBar()->drawMessage();
updateTerminal();
}
2015-05-23 13:35:12 +02:00
//----------------------------------------------------------------------
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--;
}
2015-05-23 13:35:12 +02:00
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();
}
2015-05-23 13:35:12 +02:00
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();
}
2015-05-23 13:35:12 +02:00
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;
zoom_item->setEnable();
}
2015-05-23 13:35:12 +02:00
else
{
2016-01-24 14:53:09 +01:00
flags &= ~fc::resizeable;
zoom_item->setDisable();
}
2015-05-23 13:35:12 +02:00
return on;
}