2015-09-25 21:37:19 +02:00
|
|
|
// File: fwindow.cpp
|
|
|
|
// Provides: class FWindow
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
#include "fapp.h"
|
2015-08-09 23:44:11 +02:00
|
|
|
#include "fmenubar.h"
|
2015-05-23 13:35:12 +02:00
|
|
|
#include "fstatusbar.h"
|
|
|
|
#include "fwindow.h"
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class FWindow
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// constructors and destructor
|
|
|
|
//----------------------------------------------------------------------
|
2015-09-22 04:18:20 +02:00
|
|
|
FWindow::FWindow(FWidget* parent)
|
|
|
|
: FWidget(parent)
|
|
|
|
, window_active(false)
|
|
|
|
{ }
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FWindow::~FWindow() // destructor
|
2015-09-22 04:18:20 +02:00
|
|
|
{ }
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2015-09-22 22:12:31 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
// protected methods of FWindow
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool FWindow::event (FEvent* ev)
|
|
|
|
{
|
|
|
|
switch ( ev->type() )
|
|
|
|
{
|
2016-01-17 02:57:08 +01:00
|
|
|
case fc::WindowActive_Event:
|
2015-05-23 13:35:12 +02:00
|
|
|
onWindowActive (ev);
|
|
|
|
break;
|
|
|
|
|
2016-01-17 02:57:08 +01:00
|
|
|
case fc::WindowInactive_Event:
|
2015-05-23 13:35:12 +02:00
|
|
|
onWindowInactive (ev);
|
|
|
|
break;
|
|
|
|
|
2016-01-17 02:57:08 +01:00
|
|
|
case fc::WindowRaised_Event:
|
2015-05-23 13:35:12 +02:00
|
|
|
onWindowRaised (ev);
|
|
|
|
break;
|
|
|
|
|
2016-01-17 02:57:08 +01:00
|
|
|
case fc::WindowLowered_Event:
|
2015-05-23 13:35:12 +02:00
|
|
|
onWindowLowered (ev);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return FWidget::event(ev);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FWindow::onWindowActive (FEvent*)
|
2015-09-22 04:18:20 +02:00
|
|
|
{ }
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FWindow::onWindowInactive (FEvent*)
|
2015-09-22 04:18:20 +02:00
|
|
|
{ }
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FWindow::onWindowRaised (FEvent*)
|
2015-09-22 04:18:20 +02:00
|
|
|
{ }
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FWindow::onWindowLowered (FEvent*)
|
2015-09-22 04:18:20 +02:00
|
|
|
{ }
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2015-09-22 22:12:31 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
// public methods of FWindow
|
2015-09-22 22:12:31 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FWindow::show()
|
|
|
|
{
|
|
|
|
term_area* area = getVWin();
|
|
|
|
if ( area )
|
|
|
|
area->visible = true;
|
|
|
|
FWidget::show();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FWindow::hide()
|
|
|
|
{
|
|
|
|
term_area* area = getVWin();
|
|
|
|
if ( area )
|
|
|
|
area->visible = false;
|
|
|
|
FWidget::hide();
|
|
|
|
}
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
2015-10-19 00:07:07 +02:00
|
|
|
FWindow* FWindow::getWindowWidgetAt(int x, int y)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
|
|
|
if ( statusBar() && statusBar()->getGeometryGlobal().contains(x,y) )
|
|
|
|
return statusBar();
|
|
|
|
|
2015-08-09 23:44:11 +02:00
|
|
|
if ( menuBar() && menuBar()->getGeometryGlobal().contains(x,y) )
|
|
|
|
return menuBar();
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( window_list && ! window_list->empty() )
|
|
|
|
{
|
|
|
|
widgetList::const_iterator iter, begin;
|
|
|
|
iter = window_list->end();
|
|
|
|
begin = window_list->begin();
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
--iter;
|
2015-10-19 00:07:07 +02:00
|
|
|
if ( *iter )
|
|
|
|
{
|
|
|
|
FWindow* w = static_cast<FWindow*>(*iter);
|
|
|
|
if ( ! w->isHiddenWindow()
|
|
|
|
&& w->getGeometryGlobal().contains(x,y) )
|
|
|
|
return w;
|
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
while ( iter != begin );
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FWindow::addWindow (FWidget* obj)
|
|
|
|
{
|
|
|
|
if ( window_list )
|
|
|
|
window_list->push_back(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FWindow::delWindow (FWidget* obj)
|
|
|
|
{
|
|
|
|
if ( window_list && ! window_list->empty() )
|
|
|
|
{
|
|
|
|
widgetList::iterator iter;
|
|
|
|
iter = window_list->begin();
|
|
|
|
|
|
|
|
while ( iter != window_list->end() )
|
|
|
|
{
|
|
|
|
if ( (*iter) == obj )
|
|
|
|
{
|
|
|
|
window_list->erase(iter);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FWindow* FWindow::getWindowWidget (FWidget* obj)
|
|
|
|
{
|
|
|
|
FWidget* p_obj = obj->parentWidget();
|
|
|
|
while ( ! obj->isWindow() && p_obj )
|
|
|
|
{
|
|
|
|
obj = p_obj;
|
|
|
|
p_obj = p_obj->parentWidget();
|
|
|
|
}
|
|
|
|
if ( obj->isWindow() )
|
|
|
|
return static_cast<FWindow*>(obj);
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
int FWindow::getWindowLayer (FWidget* obj)
|
|
|
|
{
|
|
|
|
widgetList::iterator iter, end;
|
|
|
|
FWidget* window;
|
|
|
|
|
|
|
|
if ( ! window_list )
|
|
|
|
return -1;
|
|
|
|
if ( window_list->empty() )
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if ( ! obj->isWindow() )
|
|
|
|
{
|
|
|
|
if ( (window = getWindowWidget(obj)) == 0 )
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
window = obj;
|
|
|
|
|
|
|
|
iter = window_list->begin();
|
|
|
|
end = window_list->end();
|
|
|
|
|
|
|
|
while ( iter != end )
|
|
|
|
{
|
|
|
|
if ( *iter == window )
|
|
|
|
break;
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
|
|
|
|
return int(std::distance(window_list->begin(), iter) + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FWindow::swapWindow (FWidget* obj1, FWidget* obj2)
|
|
|
|
{
|
|
|
|
widgetList::iterator iter, iter1, iter2, end;
|
|
|
|
|
|
|
|
if ( ! window_list )
|
|
|
|
return;
|
|
|
|
if ( window_list->empty() )
|
|
|
|
return;
|
2016-01-24 14:53:09 +01:00
|
|
|
if ( (obj1->getFlags() & fc::modal) != 0 )
|
2015-05-23 13:35:12 +02:00
|
|
|
return;
|
2016-01-24 14:53:09 +01:00
|
|
|
if ( (obj2->getFlags() & fc::modal) != 0 )
|
2015-05-23 13:35:12 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
iter = window_list->begin();
|
|
|
|
end = window_list->end();
|
|
|
|
iter1 = end;
|
|
|
|
iter2 = end;
|
|
|
|
|
|
|
|
while ( iter != end )
|
|
|
|
{
|
|
|
|
if ( (*iter) == obj1 )
|
|
|
|
iter1 = iter;
|
|
|
|
else if ( (*iter) == obj2 )
|
|
|
|
iter2 = iter;
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( iter1 != end && iter2 != end )
|
|
|
|
std::swap (iter1, iter2);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool FWindow::raiseWindow (FWidget* obj)
|
|
|
|
{
|
|
|
|
widgetList::iterator iter;
|
|
|
|
|
|
|
|
if ( ! window_list )
|
|
|
|
return false;
|
|
|
|
if ( window_list->empty() )
|
|
|
|
return false;
|
|
|
|
if ( ! obj->isWindow() )
|
|
|
|
return false;
|
|
|
|
if ( window_list->back() == obj )
|
|
|
|
return false;
|
2016-01-24 14:53:09 +01:00
|
|
|
if ( (window_list->back()->getFlags() & fc::modal) != 0 )
|
2015-05-23 13:35:12 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
iter = window_list->begin();
|
|
|
|
|
|
|
|
while ( iter != window_list->end() )
|
|
|
|
{
|
|
|
|
if ( *iter == obj )
|
|
|
|
{
|
|
|
|
window_list->erase (iter);
|
|
|
|
window_list->push_back (obj);
|
2016-01-17 02:57:08 +01:00
|
|
|
FEvent ev(fc::WindowRaised_Event);
|
2015-05-23 13:35:12 +02:00
|
|
|
FApplication::sendEvent(obj, &ev);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool FWindow::lowerWindow (FWidget* obj)
|
|
|
|
{
|
|
|
|
widgetList::iterator iter;
|
|
|
|
|
|
|
|
if ( ! window_list )
|
|
|
|
return false;
|
|
|
|
if ( window_list->empty() )
|
|
|
|
return false;
|
|
|
|
if ( ! obj->isWindow() )
|
|
|
|
return false;
|
|
|
|
if ( window_list->front() == obj )
|
|
|
|
return false;
|
2016-01-24 14:53:09 +01:00
|
|
|
if ( (obj->getFlags() & fc::modal) != 0 )
|
2015-05-23 13:35:12 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
iter = window_list->begin();
|
|
|
|
|
|
|
|
while ( iter != window_list->end() )
|
|
|
|
{
|
|
|
|
if ( *iter == obj )
|
|
|
|
{
|
|
|
|
window_list->erase (iter);
|
|
|
|
window_list->insert (window_list->begin(), obj);
|
2016-01-17 02:57:08 +01:00
|
|
|
FEvent ev(fc::WindowLowered_Event);
|
2015-05-23 13:35:12 +02:00
|
|
|
FApplication::sendEvent(obj, &ev);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FWindow::setActiveWindow (FWindow* window)
|
|
|
|
{
|
|
|
|
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 )
|
|
|
|
{
|
|
|
|
if ( *iter == window )
|
|
|
|
{
|
|
|
|
if ( ! window->isActiveWindow() )
|
|
|
|
{
|
|
|
|
window->activateWindow();
|
2016-01-17 02:57:08 +01:00
|
|
|
FEvent ev(fc::WindowActive_Event);
|
2015-05-23 13:35:12 +02:00
|
|
|
FApplication::sendEvent(window, &ev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FWindow* w = static_cast<FWindow*>(*iter);
|
|
|
|
if ( w->isActiveWindow() )
|
|
|
|
{
|
|
|
|
w->deactivateWindow();
|
2016-01-17 02:57:08 +01:00
|
|
|
FEvent ev(fc::WindowInactive_Event);
|
2015-05-23 13:35:12 +02:00
|
|
|
FApplication::sendEvent(*iter, &ev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FWindow* FWindow::getActiveWindow()
|
|
|
|
{
|
|
|
|
FWindow* active_window = static_cast<FWindow*>(FApplication::active_window);
|
|
|
|
return active_window;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool FWindow::activatePrevWindow()
|
|
|
|
{
|
|
|
|
if ( window_list && window_list->size() > 1 )
|
|
|
|
{
|
|
|
|
widgetList::const_iterator iter, begin;
|
|
|
|
iter = window_list->end();
|
|
|
|
begin = window_list->begin();
|
|
|
|
--iter;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
--iter;
|
|
|
|
FWindow* w = static_cast<FWindow*>(*iter);
|
2015-11-07 23:16:09 +01:00
|
|
|
if ( w && ! w->isHiddenWindow() && ! w->isActiveWindow() )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
|
|
|
setActiveWindow(w);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while ( iter != begin );
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool FWindow::activateWindow(bool on)
|
|
|
|
{
|
|
|
|
if ( on )
|
|
|
|
FApplication::active_window = this;
|
|
|
|
|
|
|
|
return window_active = (on) ? true : false;
|
|
|
|
}
|
2015-10-19 00:07:07 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool FWindow::isHiddenWindow() const
|
|
|
|
{
|
|
|
|
term_area* area = getVWin();
|
|
|
|
if ( area )
|
|
|
|
return ! area->visible;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|