finalcut/src/fwindow.cpp

408 lines
9.2 KiB
C++
Raw Normal View History

// 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"
// static attributes
FWindow* FWindow::previous_widget = 0;
2015-05-23 13:35:12 +02:00
//----------------------------------------------------------------------
// 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
{
if ( previous_widget == this )
previous_widget = 0;
}
2015-05-23 13:35:12 +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-05-23 13:35:12 +02:00
// public methods of FWindow
//----------------------------------------------------------------------
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
//----------------------------------------------------------------------
FWindow* FWindow::getWindowWidgetAt (int x, int y)
2015-05-23 13:35:12 +02:00
{
// returns the window object to the corresponding coordinates
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)
{
// add the window object obj to the window list
2015-05-23 13:35:12 +02:00
if ( window_list )
window_list->push_back(obj);
}
//----------------------------------------------------------------------
void FWindow::delWindow (FWidget* obj)
{
// delete the window object obj from the window list
2015-05-23 13:35:12 +02:00
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)
{
// returns the window object to the given widget obj
2015-05-23 13:35:12 +02:00
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)
{
// returns the window layer from the widget obj
2015-05-23 13:35:12 +02:00
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)
{
// swaps the window layer between obj1 and obj2
2015-05-23 13:35:12 +02:00
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)
{
// raises the window widget obj to the top
2015-05-23 13:35:12 +02:00
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-05-22 19:18:16 +02:00
if ( (window_list->back()->getFlags() & fc::modal) != 0
&& ! obj->isMenu() )
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)
{
// lowers the window widget obj to the bottom
2015-05-23 13:35:12 +02:00
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)
{
// activate FWindow object window
2015-05-23 13:35:12 +02:00
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()
{
// returns the active FWindow object
2015-05-23 13:35:12 +02:00
FWindow* active_window = static_cast<FWindow*>(FApplication::active_window);
return active_window;
}
//----------------------------------------------------------------------
void FWindow::switchToPrevWindow()
{
// switch to previous window
activatePrevWindow();
FWindow* active_window = getActiveWindow();
if ( active_window )
{
FWidget* focus_widget = active_window->getFocusWidget();
if ( ! active_window->isActiveWindow() )
setActiveWindow(active_window);
raiseWindow (active_window);
if ( focus_widget )
focus_widget->setFocus();
active_window->redraw();
}
}
2015-05-23 13:35:12 +02:00
//----------------------------------------------------------------------
bool FWindow::activatePrevWindow()
{
// activate the previous window
FWindow* w = previous_widget;
if ( w && ! w->isHiddenWindow() && ! w->isActiveWindow() )
2015-05-23 13:35:12 +02:00
{
setActiveWindow(w);
return true;
2015-05-23 13:35:12 +02:00
}
else
return false;
2015-05-23 13:35:12 +02:00
}
//----------------------------------------------------------------------
bool FWindow::activateWindow (bool on)
2015-05-23 13:35:12 +02:00
{
// activate/deactivate this window
2015-05-23 13:35:12 +02:00
if ( on )
FApplication::active_window = this;
return window_active = (on) ? true : false;
}
2015-10-19 00:07:07 +02:00
//----------------------------------------------------------------------
bool FWindow::isHiddenWindow() const
{
// returns the window hidden state
2015-10-19 00:07:07 +02:00
term_area* area = getVWin();
if ( area )
return ! area->visible;
else
return false;
}