2017-11-04 07:03:53 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* windows.cpp - Shows window handling *
|
|
|
|
* *
|
|
|
|
* This file is part of the Final Cut widget toolkit *
|
|
|
|
* *
|
2018-01-28 19:54:52 +01:00
|
|
|
* Copyright 2016-2018 Markus Gans *
|
2017-11-04 07:03:53 +01:00
|
|
|
* *
|
|
|
|
* The Final Cut is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU Lesser General Public License *
|
|
|
|
* as published by the Free Software Foundation; either version 3 of *
|
|
|
|
* the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* The Final Cut is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU Lesser General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU Lesser General Public *
|
|
|
|
* License along with this program. If not, see *
|
|
|
|
* <http://www.gnu.org/licenses/>. *
|
|
|
|
***********************************************************************/
|
2016-07-31 20:28:45 +02:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
#include <vector>
|
2017-10-31 00:41:59 +01:00
|
|
|
#include <final/final.h>
|
2016-07-31 20:28:45 +02:00
|
|
|
|
2017-10-02 07:32:33 +02:00
|
|
|
|
2016-09-27 00:46:05 +02:00
|
|
|
//----------------------------------------------------------------------
|
2017-10-02 07:32:33 +02:00
|
|
|
// class SmallWindow
|
2016-09-27 00:46:05 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
#pragma pack(push)
|
|
|
|
#pragma pack(1)
|
|
|
|
|
2017-10-02 07:32:33 +02:00
|
|
|
class SmallWindow : public FDialog
|
2016-09-27 00:46:05 +02:00
|
|
|
{
|
2017-09-11 03:06:02 +02:00
|
|
|
public:
|
|
|
|
// Constructor
|
2017-10-02 07:32:33 +02:00
|
|
|
explicit SmallWindow (FWidget* = 0);
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Destructor
|
2017-10-02 07:32:33 +02:00
|
|
|
~SmallWindow();
|
2016-09-27 00:46:05 +02:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
private:
|
|
|
|
// Disable copy constructor
|
2017-10-02 07:32:33 +02:00
|
|
|
SmallWindow (const SmallWindow&);
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Disable assignment operator (=)
|
2017-10-02 07:32:33 +02:00
|
|
|
SmallWindow& operator = (const SmallWindow&);
|
2016-09-30 04:55:28 +02:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Method
|
|
|
|
void adjustSize();
|
2016-09-30 04:55:28 +02:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Event handlers
|
|
|
|
void onShow (FShowEvent*);
|
|
|
|
void onTimer (FTimerEvent*);
|
2016-09-27 00:46:05 +02:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Data Members
|
|
|
|
FLabel* left_arrow;
|
|
|
|
FLabel* right_arrow;
|
|
|
|
FLabel* top_left_label;
|
|
|
|
FLabel* top_right_label;
|
|
|
|
FLabel* bottom_label;
|
2016-09-27 00:46:05 +02:00
|
|
|
};
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-10-02 07:32:33 +02:00
|
|
|
SmallWindow::SmallWindow (FWidget* parent)
|
2016-09-27 00:46:05 +02:00
|
|
|
: FDialog(parent)
|
2016-09-29 04:29:12 +02:00
|
|
|
, left_arrow()
|
|
|
|
, right_arrow()
|
|
|
|
, top_left_label()
|
|
|
|
, top_right_label()
|
|
|
|
, bottom_label()
|
2016-09-27 00:46:05 +02:00
|
|
|
{
|
2016-09-30 04:55:28 +02:00
|
|
|
wchar_t arrow_up, arrow_down;
|
|
|
|
|
2017-04-05 00:30:52 +02:00
|
|
|
arrow_up = fc::BlackUpPointingTriangle;
|
|
|
|
arrow_down = fc::BlackDownPointingTriangle;
|
2016-09-30 04:55:28 +02:00
|
|
|
|
|
|
|
left_arrow = new FLabel (arrow_up, this);
|
2016-09-29 04:29:12 +02:00
|
|
|
left_arrow->setForegroundColor (wc.label_inactive_fg);
|
|
|
|
left_arrow->setEmphasis();
|
|
|
|
left_arrow->ignorePadding();
|
|
|
|
left_arrow->setGeometry (2, 2, 1, 1);
|
|
|
|
|
2016-09-30 04:55:28 +02:00
|
|
|
right_arrow = new FLabel (arrow_up, this);
|
2016-09-29 04:29:12 +02:00
|
|
|
right_arrow->setForegroundColor (wc.label_inactive_fg);
|
|
|
|
right_arrow->setEmphasis();
|
|
|
|
right_arrow->ignorePadding();
|
|
|
|
right_arrow->setGeometry (getWidth() - 1, 2, 1, 1);
|
|
|
|
|
2017-09-09 22:03:17 +02:00
|
|
|
const FString& top_left_label_text = "menu";
|
2016-09-29 04:29:12 +02:00
|
|
|
top_left_label = new FLabel (top_left_label_text, this);
|
|
|
|
top_left_label->setForegroundColor (wc.label_inactive_fg);
|
|
|
|
top_left_label->setEmphasis();
|
|
|
|
top_left_label->setGeometry (1, 1, 6, 1);
|
|
|
|
|
2017-09-09 22:03:17 +02:00
|
|
|
const FString& top_right_label_text = "zoom";
|
2016-09-29 04:29:12 +02:00
|
|
|
top_right_label = new FLabel (top_right_label_text, this);
|
|
|
|
top_right_label->setAlignment (fc::alignRight);
|
|
|
|
top_right_label->setForegroundColor (wc.label_inactive_fg);
|
|
|
|
top_right_label->setEmphasis();
|
|
|
|
top_right_label->setGeometry (getClientWidth() - 5, 1, 6, 1);
|
|
|
|
|
|
|
|
FString bottom_label_text = "resize\n"
|
2016-09-30 04:55:28 +02:00
|
|
|
"corner\n";
|
|
|
|
bottom_label_text += arrow_down;
|
2016-09-29 04:29:12 +02:00
|
|
|
bottom_label = new FLabel (bottom_label_text, this);
|
|
|
|
bottom_label->setAlignment (fc::alignRight);
|
|
|
|
bottom_label->setForegroundColor (wc.label_inactive_fg);
|
|
|
|
bottom_label->setEmphasis();
|
|
|
|
bottom_label->setGeometry (13, 3, 6, 3);
|
2016-09-27 00:46:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-10-02 07:32:33 +02:00
|
|
|
SmallWindow::~SmallWindow()
|
2016-09-29 04:29:12 +02:00
|
|
|
{
|
2017-11-03 22:57:40 +01:00
|
|
|
// Remove own timer
|
2016-09-29 04:29:12 +02:00
|
|
|
delOwnTimer();
|
|
|
|
}
|
2016-09-27 00:46:05 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-10-02 07:32:33 +02:00
|
|
|
void SmallWindow::adjustSize()
|
2016-09-27 00:46:05 +02:00
|
|
|
{
|
2016-09-29 04:29:12 +02:00
|
|
|
if ( isZoomed() )
|
|
|
|
{
|
2017-09-20 05:44:41 +02:00
|
|
|
*top_right_label = "unzoom";
|
2016-09-29 04:29:12 +02:00
|
|
|
bottom_label->hide();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-09-20 05:44:41 +02:00
|
|
|
*top_right_label = "zoom";
|
2016-09-29 04:29:12 +02:00
|
|
|
bottom_label->setVisible();
|
|
|
|
}
|
|
|
|
|
2016-09-27 00:46:05 +02:00
|
|
|
FDialog::adjustSize();
|
2016-09-29 04:29:12 +02:00
|
|
|
right_arrow->setGeometry (getWidth() - 1, 2, 1, 1);
|
|
|
|
top_right_label->setGeometry (getClientWidth() - 5, 1, 6, 1);
|
|
|
|
bottom_label->setGeometry (1, getClientHeight() - 2, getClientWidth(), 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-10-02 07:32:33 +02:00
|
|
|
void SmallWindow::onShow (FShowEvent*)
|
2016-09-29 04:29:12 +02:00
|
|
|
{
|
|
|
|
addTimer(1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-10-02 07:32:33 +02:00
|
|
|
void SmallWindow::onTimer (FTimerEvent*)
|
2016-09-29 04:29:12 +02:00
|
|
|
{
|
|
|
|
left_arrow->unsetEmphasis();
|
|
|
|
left_arrow->redraw();
|
|
|
|
right_arrow->unsetEmphasis();
|
|
|
|
right_arrow->redraw();
|
|
|
|
top_left_label->unsetEmphasis();
|
|
|
|
top_left_label->redraw();
|
|
|
|
top_right_label->unsetEmphasis();
|
|
|
|
top_right_label->redraw();
|
|
|
|
bottom_label->unsetEmphasis();
|
|
|
|
bottom_label->redraw();
|
|
|
|
updateTerminal();
|
|
|
|
delOwnTimer();
|
2016-09-27 00:46:05 +02:00
|
|
|
}
|
|
|
|
|
2016-07-31 20:28:45 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class Window
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
#pragma pack(push)
|
|
|
|
#pragma pack(1)
|
|
|
|
|
|
|
|
class Window : public FDialog
|
|
|
|
{
|
2017-09-11 03:06:02 +02:00
|
|
|
public:
|
|
|
|
// Constructor
|
|
|
|
explicit Window (FWidget* = 0);
|
|
|
|
|
|
|
|
// Destructor
|
|
|
|
~Window();
|
|
|
|
|
|
|
|
private:
|
2018-01-28 19:54:52 +01:00
|
|
|
// Typedefs
|
|
|
|
typedef void (Window::*WindowCallback)(FWidget*, data_ptr);
|
|
|
|
typedef void (FApplication::*FAppCallback)(FWidget*, data_ptr);
|
2017-09-11 03:06:02 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
2017-11-03 22:57:40 +01:00
|
|
|
bool is_open;
|
2017-09-11 03:06:02 +02:00
|
|
|
FString* title;
|
2017-11-03 22:57:40 +01:00
|
|
|
SmallWindow* dgl;
|
2017-09-11 03:06:02 +02:00
|
|
|
}
|
|
|
|
win_data;
|
|
|
|
|
|
|
|
// Disable copy constructor
|
|
|
|
Window (const Window&);
|
|
|
|
|
|
|
|
// Disable assignment operator (=)
|
|
|
|
Window& operator = (const Window&);
|
|
|
|
|
|
|
|
// Method
|
2018-01-28 19:54:52 +01:00
|
|
|
void createFileMenuItems (FMenu*);
|
|
|
|
void createDialogButtons();
|
2017-09-11 03:06:02 +02:00
|
|
|
void activateWindow (FDialog*);
|
|
|
|
void adjustSize();
|
2018-01-28 19:54:52 +01:00
|
|
|
void addClickedCallback (FWidget*, WindowCallback);
|
|
|
|
void addClickedCallback (FWidget*, FAppCallback);
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Event handlers
|
|
|
|
void onClose (FCloseEvent*);
|
|
|
|
|
|
|
|
// Callback methods
|
|
|
|
void cb_createWindows (FWidget*, data_ptr);
|
|
|
|
void cb_closeWindows (FWidget*, data_ptr);
|
|
|
|
void cb_next (FWidget*, data_ptr);
|
|
|
|
void cb_previous (FWidget*, data_ptr);
|
|
|
|
void cb_destroyWindow (FWidget*, data_ptr);
|
|
|
|
|
|
|
|
// Data Members
|
|
|
|
std::vector<win_data*> windows;
|
2016-07-31 20:28:45 +02:00
|
|
|
};
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
Window::Window (FWidget* parent)
|
|
|
|
: FDialog(parent)
|
|
|
|
, windows()
|
|
|
|
{
|
2018-01-28 19:54:52 +01:00
|
|
|
FMenu* File;
|
|
|
|
FDialogListMenu* DglList;
|
2016-11-20 21:15:43 +01:00
|
|
|
FString drop_down_symbol;
|
2018-01-28 19:54:52 +01:00
|
|
|
FMenuBar* Menubar;
|
|
|
|
FStatusBar* statusbar;
|
|
|
|
|
|
|
|
// Menu bar
|
|
|
|
Menubar = new FMenuBar (this);
|
2016-07-31 20:28:45 +02:00
|
|
|
|
2018-01-28 19:54:52 +01:00
|
|
|
// Menu bar item
|
|
|
|
File = new FMenu ("&File", Menubar);
|
2016-07-31 20:28:45 +02:00
|
|
|
File->setStatusbarMessage ("File management commands");
|
|
|
|
|
2018-01-28 19:54:52 +01:00
|
|
|
// Dialog list menu item
|
2017-04-05 00:30:52 +02:00
|
|
|
drop_down_symbol = wchar_t(fc::BlackDownPointingTriangle);
|
2018-01-28 19:54:52 +01:00
|
|
|
DglList = new FDialogListMenu (drop_down_symbol, Menubar);
|
2016-07-31 20:28:45 +02:00
|
|
|
DglList->setStatusbarMessage ("List of all the active dialogs");
|
|
|
|
|
2018-01-28 19:54:52 +01:00
|
|
|
// File menu items
|
|
|
|
createFileMenuItems (File);
|
|
|
|
|
|
|
|
// Dialog buttons
|
|
|
|
createDialogButtons();
|
|
|
|
|
|
|
|
// Statusbar at the bottom
|
|
|
|
statusbar = new FStatusBar (this);
|
|
|
|
statusbar->setMessage("Status bar message");
|
|
|
|
|
|
|
|
// Generate data vector for the windows
|
|
|
|
for (int n = 1; n <= 6; n++)
|
|
|
|
{
|
|
|
|
win_data* win_dat = new win_data;
|
|
|
|
win_dat->is_open = false;
|
|
|
|
win_dat->title = new FString();
|
|
|
|
win_dat->title->sprintf("Window %d", n);
|
|
|
|
windows.push_back(win_dat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
Window::~Window()
|
|
|
|
{
|
|
|
|
std::vector<win_data*>::iterator iter;
|
|
|
|
iter = windows.begin();
|
|
|
|
|
|
|
|
while ( iter != windows.end() )
|
|
|
|
{
|
|
|
|
win_data* win_dat = *iter;
|
|
|
|
|
|
|
|
// Remove all callbacks before Window::cb_destroyWindow() will be called
|
|
|
|
if ( win_dat->is_open && win_dat->dgl )
|
|
|
|
win_dat->dgl->delCallbacks();
|
|
|
|
|
|
|
|
delete win_dat->title;
|
|
|
|
delete win_dat;
|
|
|
|
iter = windows.erase(iter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void Window::createFileMenuItems (FMenu* File)
|
|
|
|
{
|
2016-07-31 20:28:45 +02:00
|
|
|
// "File" menu item
|
|
|
|
FMenuItem* New = new FMenuItem ("&New", File);
|
|
|
|
New->setStatusbarMessage ("Create the windows");
|
|
|
|
|
|
|
|
FMenuItem* Close = new FMenuItem ("&Close", File);
|
|
|
|
Close->setStatusbarMessage ("Close the windows");
|
|
|
|
|
|
|
|
FMenuItem* Line1 = new FMenuItem (File);
|
|
|
|
Line1->setSeparator();
|
|
|
|
|
|
|
|
FMenuItem* Next = new FMenuItem ("Ne&xt window", File);
|
2017-09-11 03:06:02 +02:00
|
|
|
Next->addAccelerator (fc::Fmkey_npage); // Meta/Alt + PgDn
|
2016-07-31 20:28:45 +02:00
|
|
|
Next->setStatusbarMessage ("Switch to the next window");
|
|
|
|
|
|
|
|
FMenuItem* Previous = new FMenuItem ("&Previous window", File);
|
2017-09-11 03:06:02 +02:00
|
|
|
Previous->addAccelerator (fc::Fmkey_ppage); // Meta/Alt + PgUp
|
2016-07-31 20:28:45 +02:00
|
|
|
Previous->setStatusbarMessage ("Switch to the previous window");
|
|
|
|
|
|
|
|
FMenuItem* Line2 = new FMenuItem (File);
|
|
|
|
Line2->setSeparator();
|
|
|
|
|
|
|
|
FMenuItem* Quit = new FMenuItem ("&Quit", File);
|
2017-09-11 03:06:02 +02:00
|
|
|
Quit->addAccelerator (fc::Fmkey_x); // Meta/Alt + X
|
2016-07-31 20:28:45 +02:00
|
|
|
Quit->setStatusbarMessage ("Exit the program");
|
|
|
|
|
2018-01-28 19:54:52 +01:00
|
|
|
// Add menu item callback
|
|
|
|
addClickedCallback (New, &Window::cb_createWindows);
|
|
|
|
addClickedCallback (Close, &Window::cb_closeWindows);
|
|
|
|
addClickedCallback (Next, &Window::cb_next);
|
|
|
|
addClickedCallback (Previous, &Window::cb_previous);
|
|
|
|
addClickedCallback (Quit, &FApplication::cb_exitApp);
|
|
|
|
}
|
2016-07-31 20:28:45 +02:00
|
|
|
|
2018-01-28 19:54:52 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void Window::createDialogButtons()
|
|
|
|
{
|
|
|
|
// Dialog buttons
|
2016-07-31 20:28:45 +02:00
|
|
|
FButton* CreateButton = new FButton (this);
|
|
|
|
CreateButton->setGeometry(2, 2, 9, 1);
|
|
|
|
CreateButton->setText (L"&Create");
|
|
|
|
|
|
|
|
FButton* CloseButton = new FButton (this);
|
|
|
|
CloseButton->setGeometry(15, 2, 9, 1);
|
|
|
|
CloseButton->setText (L"C&lose");
|
|
|
|
|
|
|
|
FButton* QuitButton = new FButton (this);
|
|
|
|
QuitButton->setGeometry(28, 2, 9, 1);
|
|
|
|
QuitButton->setText (L"&Quit");
|
|
|
|
|
|
|
|
// Add button callback
|
2018-01-28 19:54:52 +01:00
|
|
|
addClickedCallback (CreateButton, &Window::cb_createWindows);
|
|
|
|
addClickedCallback (CloseButton, &Window::cb_closeWindows);
|
|
|
|
addClickedCallback (QuitButton, &FApplication::cb_exitApp);
|
2016-07-31 20:28:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void Window::activateWindow (FDialog* win)
|
|
|
|
{
|
2016-10-17 08:44:38 +02:00
|
|
|
if ( ! win || win->isWindowHidden() || win->isWindowActive() )
|
|
|
|
return;
|
2016-07-31 20:28:45 +02:00
|
|
|
|
2016-10-17 08:44:38 +02:00
|
|
|
bool has_raised = FWindow::raiseWindow(win);
|
|
|
|
win->activateDialog();
|
2016-07-31 20:28:45 +02:00
|
|
|
|
2016-10-17 08:44:38 +02:00
|
|
|
if ( has_raised )
|
|
|
|
win->redraw();
|
|
|
|
|
|
|
|
updateTerminal();
|
2016-07-31 20:28:45 +02:00
|
|
|
}
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void Window::adjustSize()
|
|
|
|
{
|
2017-09-17 01:50:41 +02:00
|
|
|
std::vector<win_data*>::const_iterator iter, first;
|
2017-10-02 07:32:33 +02:00
|
|
|
int w = getRootWidget()->getWidth()
|
|
|
|
, h = getRootWidget()->getHeight()
|
|
|
|
, X = int(1 + (w - 40) / 2)
|
|
|
|
, Y = int(1 + (h - 22) / 2)
|
|
|
|
, dx = ( w > 80 ) ? (w - 80) / 2 : 0
|
|
|
|
, dy = ( h > 24 ) ? (h - 24) / 2 : 0;
|
|
|
|
|
|
|
|
if ( Y < 2 )
|
2016-11-02 00:37:58 +01:00
|
|
|
Y = 2;
|
|
|
|
|
|
|
|
setPos (X, Y);
|
2017-09-17 01:50:41 +02:00
|
|
|
iter = first = windows.begin();
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
while ( iter != windows.end() )
|
|
|
|
{
|
|
|
|
if ( (*iter)->is_open )
|
|
|
|
{
|
2017-10-02 07:32:33 +02:00
|
|
|
int n = int(std::distance(first, iter))
|
|
|
|
, x = dx + 5 + (n % 3) * 25 + int(n / 3) * 3
|
|
|
|
, y = dy + 11 + int(n / 3) * 3;
|
2016-11-02 00:37:58 +01:00
|
|
|
(*iter)->dgl->setPos (x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
|
|
|
|
FDialog::adjustSize();
|
|
|
|
}
|
|
|
|
|
2018-01-28 19:54:52 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void Window::addClickedCallback (FWidget* widget, WindowCallback call)
|
|
|
|
{
|
|
|
|
FMemberCallback callback
|
|
|
|
= reinterpret_cast<FWidget::FMemberCallback>(call);
|
|
|
|
|
|
|
|
widget->addCallback
|
|
|
|
(
|
|
|
|
"clicked",
|
|
|
|
F_METHOD_CALLBACK (this, callback)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void Window::addClickedCallback (FWidget* widget, FAppCallback call)
|
|
|
|
{
|
|
|
|
FMemberCallback callback
|
|
|
|
= reinterpret_cast<FWidget::FMemberCallback>(call);
|
|
|
|
|
|
|
|
widget->addCallback
|
|
|
|
(
|
|
|
|
"clicked",
|
|
|
|
F_METHOD_CALLBACK (this, callback)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-07-31 20:28:45 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void Window::onClose (FCloseEvent* ev)
|
|
|
|
{
|
2017-10-30 20:56:00 +01:00
|
|
|
FApplication::closeConfirmationDialog (this, ev);
|
2016-07-31 20:28:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-02-24 00:30:07 +01:00
|
|
|
void Window::cb_createWindows (FWidget*, data_ptr)
|
2016-07-31 20:28:45 +02:00
|
|
|
{
|
2017-09-17 01:50:41 +02:00
|
|
|
std::vector<win_data*>::const_iterator iter, first;
|
|
|
|
iter = first = windows.begin();
|
2017-10-02 07:32:33 +02:00
|
|
|
int w = getRootWidget()->getWidth()
|
|
|
|
, h = getRootWidget()->getHeight()
|
|
|
|
, dx = ( w > 80 ) ? (w - 80) / 2 : 0
|
|
|
|
, dy = ( h > 24 ) ? (h - 24) / 2 : 0;
|
2016-07-31 20:28:45 +02:00
|
|
|
|
|
|
|
while ( iter != windows.end() )
|
|
|
|
{
|
|
|
|
if ( ! (*iter)->is_open )
|
|
|
|
{
|
|
|
|
win_data* win_dat = *iter;
|
2017-11-03 22:57:40 +01:00
|
|
|
SmallWindow* win = new SmallWindow(this);
|
2016-07-31 20:28:45 +02:00
|
|
|
win_dat->dgl = win;
|
|
|
|
win_dat->is_open = true;
|
|
|
|
win->setText(*(win_dat)->title);
|
2017-10-02 07:32:33 +02:00
|
|
|
int n = int(std::distance(first, iter))
|
|
|
|
, x = dx + 5 + (n % 3) * 25 + int(n / 3) * 3
|
|
|
|
, y = dy + 11 + int(n / 3) * 3;
|
2016-07-31 20:28:45 +02:00
|
|
|
win->setGeometry (x, y, 20, 8);
|
2016-09-25 23:53:48 +02:00
|
|
|
win->setMinimumSize (20, 8);
|
2016-09-11 16:48:39 +02:00
|
|
|
win->setResizeable();
|
2016-07-31 20:28:45 +02:00
|
|
|
win->show();
|
|
|
|
|
|
|
|
win->addCallback
|
|
|
|
(
|
|
|
|
"destroy",
|
2017-04-09 20:08:53 +02:00
|
|
|
F_METHOD_CALLBACK (this, &Window::cb_destroyWindow),
|
2016-07-31 20:28:45 +02:00
|
|
|
static_cast<FWidget::data_ptr>(win_dat)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
|
|
|
|
activateWindow(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-02-24 00:30:07 +01:00
|
|
|
void Window::cb_closeWindows (FWidget*, data_ptr)
|
2016-07-31 20:28:45 +02:00
|
|
|
{
|
|
|
|
if ( ! dialog_list || dialog_list->empty() )
|
|
|
|
return;
|
|
|
|
|
2017-09-17 01:50:41 +02:00
|
|
|
widgetList::const_iterator iter, first;
|
2016-07-31 20:28:45 +02:00
|
|
|
iter = dialog_list->end();
|
2017-09-17 01:50:41 +02:00
|
|
|
first = dialog_list->begin();
|
2016-07-31 20:28:45 +02:00
|
|
|
activateWindow(this);
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
--iter;
|
|
|
|
|
|
|
|
if ( (*iter) != this )
|
|
|
|
(*iter)->close();
|
|
|
|
}
|
2017-09-17 01:50:41 +02:00
|
|
|
while ( iter != first );
|
2016-07-31 20:28:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-02-24 00:30:07 +01:00
|
|
|
void Window::cb_next (FWidget*, data_ptr)
|
2016-07-31 20:28:45 +02:00
|
|
|
{
|
|
|
|
if ( ! dialog_list || dialog_list->empty() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
widgetList::const_iterator iter;
|
|
|
|
iter = dialog_list->begin();
|
|
|
|
|
|
|
|
while ( iter != dialog_list->end() )
|
|
|
|
{
|
2016-10-11 04:57:36 +02:00
|
|
|
if ( static_cast<FWindow*>(*iter)->isWindowActive() )
|
2016-07-31 20:28:45 +02:00
|
|
|
{
|
|
|
|
FDialog* next;
|
|
|
|
widgetList::const_iterator next_element;
|
|
|
|
next_element = iter;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
++next_element;
|
|
|
|
|
|
|
|
if ( next_element == dialog_list->end() )
|
|
|
|
next_element = dialog_list->begin();
|
|
|
|
|
|
|
|
next = static_cast<FDialog*>(*next_element);
|
2016-12-18 23:34:11 +01:00
|
|
|
} while ( ! next->isEnabled()
|
2017-11-26 22:37:18 +01:00
|
|
|
|| ! next->acceptFocus()
|
|
|
|
|| ! next->isVisible()
|
|
|
|
|| ! next->isWindowWidget() );
|
2016-07-31 20:28:45 +02:00
|
|
|
|
|
|
|
activateWindow(next);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-02-24 00:30:07 +01:00
|
|
|
void Window::cb_previous (FWidget*, data_ptr)
|
2016-07-31 20:28:45 +02:00
|
|
|
{
|
|
|
|
if ( ! dialog_list || dialog_list->empty() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
widgetList::const_iterator iter;
|
|
|
|
iter = dialog_list->end();
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
--iter;
|
|
|
|
|
2016-09-25 23:53:48 +02:00
|
|
|
if ( (*iter)->isDialogWidget()
|
2017-11-26 22:37:18 +01:00
|
|
|
&& static_cast<FWindow*>(*iter)->isWindowActive() )
|
2016-07-31 20:28:45 +02:00
|
|
|
{
|
|
|
|
FDialog* prev;
|
|
|
|
widgetList::const_iterator prev_element;
|
|
|
|
prev_element = iter;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if ( prev_element == dialog_list->begin() )
|
|
|
|
prev_element = dialog_list->end();
|
|
|
|
|
|
|
|
--prev_element;
|
|
|
|
prev = static_cast<FDialog*>(*prev_element);
|
2016-12-18 23:34:11 +01:00
|
|
|
} while ( ! prev->isEnabled()
|
2017-11-26 22:37:18 +01:00
|
|
|
|| ! prev->acceptFocus()
|
|
|
|
|| ! prev->isVisible()
|
|
|
|
|| ! prev->isWindowWidget() );
|
2016-07-31 20:28:45 +02:00
|
|
|
|
|
|
|
activateWindow(prev);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while ( iter != dialog_list->begin() );
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-02-24 00:30:07 +01:00
|
|
|
void Window::cb_destroyWindow (FWidget*, data_ptr data)
|
2016-07-31 20:28:45 +02:00
|
|
|
{
|
2017-02-24 00:30:07 +01:00
|
|
|
win_data* win_dat = static_cast<win_data*>(data);
|
2016-09-30 04:55:28 +02:00
|
|
|
|
2016-07-31 20:28:45 +02:00
|
|
|
if ( win_dat )
|
2018-01-28 19:54:52 +01:00
|
|
|
{
|
2016-07-31 20:28:45 +02:00
|
|
|
win_dat->is_open = false;
|
2018-01-28 19:54:52 +01:00
|
|
|
win_dat->dgl = 0;
|
|
|
|
}
|
2016-07-31 20:28:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// main part
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
int main (int argc, char* argv[])
|
|
|
|
{
|
2017-09-19 06:18:03 +02:00
|
|
|
// Create the application object
|
2016-07-31 20:28:45 +02:00
|
|
|
FApplication app (argc, argv);
|
|
|
|
|
2017-09-19 06:18:03 +02:00
|
|
|
// Create main dialog object
|
2016-07-31 20:28:45 +02:00
|
|
|
Window main_dlg (&app);
|
|
|
|
main_dlg.setText ("Main window");
|
2017-08-27 09:50:30 +02:00
|
|
|
main_dlg.setGeometry (int(1 + (app.getWidth() - 40) / 2), 2, 40, 6);
|
2016-07-31 20:28:45 +02:00
|
|
|
|
2017-09-19 06:18:03 +02:00
|
|
|
// Set dialog main_dlg as main widget
|
2016-07-31 20:28:45 +02:00
|
|
|
app.setMainWidget (&main_dlg);
|
|
|
|
|
2017-09-19 06:18:03 +02:00
|
|
|
// Show and start the application
|
|
|
|
main_dlg.show();
|
2016-07-31 20:28:45 +02:00
|
|
|
return app.exec();
|
|
|
|
}
|