2017-11-04 07:03:53 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* windows.cpp - Shows window handling *
|
|
|
|
* *
|
2020-07-08 21:32:47 +02:00
|
|
|
* This file is part of the FINAL CUT widget toolkit *
|
2017-11-04 07:03:53 +01:00
|
|
|
* *
|
2020-02-02 22:34:27 +01:00
|
|
|
* Copyright 2016-2020 Markus Gans *
|
2017-11-04 07:03:53 +01:00
|
|
|
* *
|
2020-07-08 21:32:47 +02:00
|
|
|
* 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 *
|
2017-11-04 07:03:53 +01:00
|
|
|
* the License, or (at your option) any later version. *
|
|
|
|
* *
|
2020-07-08 21:32:47 +02:00
|
|
|
* FINAL CUT is distributed in the hope that it will be useful, but *
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
2017-11-04 07:03:53 +01:00
|
|
|
* 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
|
|
|
|
2020-08-23 00:32:41 +02:00
|
|
|
#include <utility>
|
2017-09-11 03:06:02 +02:00
|
|
|
#include <vector>
|
2020-08-23 00:32:41 +02:00
|
|
|
|
2017-10-31 00:41:59 +01:00
|
|
|
#include <final/final.h>
|
2016-07-31 20:28:45 +02:00
|
|
|
|
2019-04-26 21:06:04 +02:00
|
|
|
namespace fc = finalcut::fc;
|
2019-01-21 03:42:18 +01:00
|
|
|
using finalcut::FPoint;
|
|
|
|
using finalcut::FSize;
|
|
|
|
|
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
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2020-04-14 23:46:42 +02:00
|
|
|
class SmallWindow final : public finalcut::FDialog
|
2016-09-27 00:46:05 +02:00
|
|
|
{
|
2017-09-11 03:06:02 +02:00
|
|
|
public:
|
|
|
|
// Constructor
|
2018-12-10 01:48:26 +01:00
|
|
|
explicit SmallWindow (finalcut::FWidget* = nullptr);
|
2018-12-24 18:11:16 +01:00
|
|
|
|
2018-12-09 22:04:55 +01:00
|
|
|
// Disable copy constructor
|
|
|
|
SmallWindow (const SmallWindow&) = delete;
|
2018-12-24 18:11:16 +01:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Destructor
|
2020-02-19 21:59:13 +01:00
|
|
|
~SmallWindow() override;
|
2016-09-27 00:46:05 +02:00
|
|
|
|
2020-04-15 23:44:08 +02:00
|
|
|
// Disable copy assignment operator (=)
|
2018-12-09 22:04:55 +01:00
|
|
|
SmallWindow& operator = (const SmallWindow&) = delete;
|
2016-09-30 04:55:28 +02:00
|
|
|
|
2018-12-09 22:04:55 +01:00
|
|
|
private:
|
2017-09-11 03:06:02 +02:00
|
|
|
// Method
|
2019-08-06 23:45:28 +02:00
|
|
|
void adjustSize() override;
|
2016-09-30 04:55:28 +02:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Event handlers
|
2019-08-06 23:45:28 +02:00
|
|
|
void onShow (finalcut::FShowEvent*) override;
|
|
|
|
void onTimer (finalcut::FTimerEvent*) override;
|
2016-09-27 00:46:05 +02:00
|
|
|
|
2019-09-04 23:57:31 +02:00
|
|
|
// Data members
|
2018-12-03 03:22:36 +01:00
|
|
|
finalcut::FLabel left_arrow{this};
|
|
|
|
finalcut::FLabel right_arrow{this};
|
|
|
|
finalcut::FLabel top_left_label{this};
|
|
|
|
finalcut::FLabel top_right_label{this};
|
|
|
|
finalcut::FLabel bottom_label{this};
|
2016-09-27 00:46:05 +02:00
|
|
|
};
|
2019-09-08 02:04:24 +02:00
|
|
|
|
2016-09-27 00:46:05 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-09-20 23:59:01 +02:00
|
|
|
SmallWindow::SmallWindow (finalcut::FWidget* parent)
|
2020-05-24 23:55:08 +02:00
|
|
|
: finalcut::FDialog{parent}
|
2016-09-27 00:46:05 +02:00
|
|
|
{
|
2020-05-26 21:37:39 +02:00
|
|
|
const auto& wc = getColorTheme();
|
2020-02-02 22:34:27 +01:00
|
|
|
const wchar_t arrow_up = fc::BlackUpPointingTriangle;
|
|
|
|
const wchar_t arrow_down = fc::BlackDownPointingTriangle;
|
2016-09-30 04:55:28 +02:00
|
|
|
|
2018-10-03 22:23:55 +02:00
|
|
|
left_arrow = arrow_up;
|
2020-05-26 21:37:39 +02:00
|
|
|
left_arrow.setForegroundColor (wc->label_inactive_fg);
|
2018-10-03 22:23:55 +02:00
|
|
|
left_arrow.setEmphasis();
|
|
|
|
left_arrow.ignorePadding();
|
2020-05-02 00:07:35 +02:00
|
|
|
left_arrow.setGeometry (FPoint{2, 2}, FSize{1, 1});
|
2018-10-03 22:23:55 +02:00
|
|
|
|
|
|
|
right_arrow = arrow_up;
|
2020-05-26 21:37:39 +02:00
|
|
|
right_arrow.setForegroundColor (wc->label_inactive_fg);
|
2018-10-03 22:23:55 +02:00
|
|
|
right_arrow.setEmphasis();
|
|
|
|
right_arrow.ignorePadding();
|
2020-05-02 00:07:35 +02:00
|
|
|
right_arrow.setGeometry (FPoint{int(getWidth()) - 1, 2}, FSize{1, 1});
|
2018-10-03 22:23:55 +02:00
|
|
|
|
2020-06-07 18:21:59 +02:00
|
|
|
top_left_label.setText("menu");
|
2020-05-26 21:37:39 +02:00
|
|
|
top_left_label.setForegroundColor (wc->label_inactive_fg);
|
2018-10-03 22:23:55 +02:00
|
|
|
top_left_label.setEmphasis();
|
2020-05-02 00:07:35 +02:00
|
|
|
top_left_label.setGeometry (FPoint{1, 1}, FSize{6, 1});
|
2018-10-03 22:23:55 +02:00
|
|
|
|
2020-06-07 18:21:59 +02:00
|
|
|
top_right_label.setText("zoom");
|
2019-04-26 21:06:04 +02:00
|
|
|
top_right_label.setAlignment (fc::alignRight);
|
2020-05-26 21:37:39 +02:00
|
|
|
top_right_label.setForegroundColor (wc->label_inactive_fg);
|
2018-10-03 22:23:55 +02:00
|
|
|
top_right_label.setEmphasis();
|
2020-05-02 00:07:35 +02:00
|
|
|
top_right_label.setGeometry (FPoint{int(getClientWidth()) - 5, 1}, FSize{6, 1});
|
2016-09-29 04:29:12 +02:00
|
|
|
|
2020-05-02 00:07:35 +02:00
|
|
|
finalcut::FString bottom_label_text { "resize\n"
|
|
|
|
"corner\n" };
|
2016-09-30 04:55:28 +02:00
|
|
|
bottom_label_text += arrow_down;
|
2018-10-03 22:23:55 +02:00
|
|
|
bottom_label = bottom_label_text;
|
2019-04-26 21:06:04 +02:00
|
|
|
bottom_label.setAlignment (fc::alignRight);
|
2020-05-26 21:37:39 +02:00
|
|
|
bottom_label.setForegroundColor (wc->label_inactive_fg);
|
2018-10-03 22:23:55 +02:00
|
|
|
bottom_label.setEmphasis();
|
2020-05-02 00:07:35 +02:00
|
|
|
bottom_label.setGeometry (FPoint{13, 3}, FSize{6, 3});
|
2016-09-27 00:46:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-10-02 07:32:33 +02:00
|
|
|
SmallWindow::~SmallWindow()
|
2020-04-13 12:40:11 +02:00
|
|
|
{ }
|
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() )
|
|
|
|
{
|
2018-10-03 22:23:55 +02:00
|
|
|
top_right_label = "unzoom";
|
|
|
|
bottom_label.hide();
|
2016-09-29 04:29:12 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-10-03 22:23:55 +02:00
|
|
|
top_right_label = "zoom";
|
2020-09-25 00:48:58 +02:00
|
|
|
bottom_label.show();
|
2016-09-29 04:29:12 +02:00
|
|
|
}
|
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FDialog::adjustSize();
|
2020-05-02 00:07:35 +02:00
|
|
|
right_arrow.setGeometry ( FPoint{int(getWidth()) - 1, 2}
|
|
|
|
, FSize{1, 1} );
|
|
|
|
top_right_label.setGeometry ( FPoint{int(getClientWidth()) - 5, 1}
|
|
|
|
, FSize{6, 1} );
|
|
|
|
bottom_label.setGeometry ( FPoint{1, int(getClientHeight()) - 2}
|
|
|
|
, FSize{getClientWidth(), 3} );
|
2016-09-29 04:29:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-09-20 23:59:01 +02:00
|
|
|
void SmallWindow::onShow (finalcut::FShowEvent*)
|
2016-09-29 04:29:12 +02:00
|
|
|
{
|
|
|
|
addTimer(1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-09-20 23:59:01 +02:00
|
|
|
void SmallWindow::onTimer (finalcut::FTimerEvent*)
|
2016-09-29 04:29:12 +02:00
|
|
|
{
|
2018-10-03 22:23:55 +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();
|
2016-09-29 04:29:12 +02:00
|
|
|
updateTerminal();
|
2020-07-19 14:15:02 +02:00
|
|
|
delOwnTimers();
|
2016-09-27 00:46:05 +02:00
|
|
|
}
|
|
|
|
|
2016-07-31 20:28:45 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class Window
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2020-04-14 23:46:42 +02:00
|
|
|
class Window final : public finalcut::FDialog
|
2016-07-31 20:28:45 +02:00
|
|
|
{
|
2017-09-11 03:06:02 +02:00
|
|
|
public:
|
|
|
|
// Constructor
|
2018-12-10 01:48:26 +01:00
|
|
|
explicit Window (finalcut::FWidget* = nullptr);
|
2018-12-24 18:11:16 +01:00
|
|
|
|
2020-04-15 00:28:18 +02:00
|
|
|
// Disable copy constructor
|
|
|
|
Window (const Window&) = delete;
|
2018-12-24 18:11:16 +01:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Destructor
|
2020-02-19 21:59:13 +01:00
|
|
|
~Window() override;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
2020-04-15 23:44:08 +02:00
|
|
|
// Disable copy assignment operator (=)
|
2020-04-15 00:28:18 +02:00
|
|
|
Window& operator = (const Window&) = delete;
|
2018-12-09 22:04:55 +01:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
private:
|
2018-12-09 22:04:55 +01:00
|
|
|
struct win_data
|
2017-09-11 03:06:02 +02:00
|
|
|
{
|
2018-12-09 22:04:55 +01:00
|
|
|
// Constructor
|
2018-12-10 01:48:26 +01:00
|
|
|
win_data() = default;
|
2018-12-09 22:04:55 +01:00
|
|
|
// Disable copy constructor
|
|
|
|
win_data (const win_data&) = delete;
|
|
|
|
|
2020-04-15 23:44:08 +02:00
|
|
|
// Disable copy assignment operator (=)
|
2018-12-09 22:04:55 +01:00
|
|
|
win_data& operator = (const win_data&) = delete;
|
2018-10-03 22:23:55 +02:00
|
|
|
|
2019-09-04 23:57:31 +02:00
|
|
|
// Data members
|
2018-12-10 01:48:26 +01:00
|
|
|
bool is_open{false};
|
|
|
|
finalcut::FString title{};
|
|
|
|
SmallWindow* dgl{nullptr};
|
2018-10-03 22:23:55 +02:00
|
|
|
};
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Method
|
2018-10-03 22:23:55 +02:00
|
|
|
void configureFileMenuItems();
|
|
|
|
void configureDialogButtons();
|
2020-08-23 14:00:53 +02:00
|
|
|
void activateWindow (finalcut::FDialog*) const;
|
2019-08-06 23:45:28 +02:00
|
|
|
void adjustSize() override;
|
2020-09-18 17:13:52 +02:00
|
|
|
template <typename InstanceT
|
|
|
|
, typename CallbackT
|
|
|
|
, typename... Args>
|
2020-08-11 23:04:46 +02:00
|
|
|
void addClickedCallback ( finalcut::FWidget*
|
|
|
|
, InstanceT&&, CallbackT&&, Args&&... );
|
2020-04-13 12:40:11 +02:00
|
|
|
template <typename IteratorT>
|
|
|
|
finalcut::FDialog* getNext (IteratorT);
|
|
|
|
template <typename IteratorT>
|
|
|
|
finalcut::FDialog* getPrevious (IteratorT iter);
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Event handlers
|
2019-08-06 23:45:28 +02:00
|
|
|
void onClose (finalcut::FCloseEvent*) override;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Callback methods
|
2020-08-11 23:04:46 +02:00
|
|
|
void cb_createWindows();
|
|
|
|
void cb_closeWindows();
|
|
|
|
void cb_next();
|
|
|
|
void cb_previous();
|
|
|
|
void cb_destroyWindow (win_data*) const;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
2019-09-04 23:57:31 +02:00
|
|
|
// Data members
|
2018-12-03 03:22:36 +01:00
|
|
|
std::vector<win_data*> windows{};
|
2019-04-26 21:06:04 +02:00
|
|
|
finalcut::FString drop_down_symbol{fc::BlackDownPointingTriangle};
|
2018-12-03 03:22:36 +01:00
|
|
|
finalcut::FMenuBar Menubar{this};
|
|
|
|
finalcut::FMenu File{"&File", &Menubar};
|
|
|
|
finalcut::FDialogListMenu DglList{drop_down_symbol, &Menubar};
|
|
|
|
finalcut::FStatusBar Statusbar{this};
|
|
|
|
finalcut::FMenuItem New{"&New", &File};
|
|
|
|
finalcut::FMenuItem Close{"&Close", &File};
|
|
|
|
finalcut::FMenuItem Line1{&File};
|
|
|
|
finalcut::FMenuItem Next{"Ne&xt window", &File};
|
|
|
|
finalcut::FMenuItem Previous{"&Previous window", &File};
|
|
|
|
finalcut::FMenuItem Line2{&File};
|
|
|
|
finalcut::FMenuItem Quit{"&Quit", &File};
|
|
|
|
finalcut::FButton CreateButton{this};
|
|
|
|
finalcut::FButton CloseButton{this};
|
|
|
|
finalcut::FButton QuitButton{this};
|
2016-07-31 20:28:45 +02:00
|
|
|
};
|
2019-09-08 02:04:24 +02:00
|
|
|
|
2016-07-31 20:28:45 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-09-20 23:59:01 +02:00
|
|
|
Window::Window (finalcut::FWidget* parent)
|
2020-05-24 23:55:08 +02:00
|
|
|
: finalcut::FDialog{parent}
|
2016-07-31 20:28:45 +02:00
|
|
|
{
|
2020-10-04 02:55:15 +02:00
|
|
|
FDialog::setSize ({40, 6});
|
2020-10-04 00:59:21 +02:00
|
|
|
|
2018-01-28 19:54:52 +01:00
|
|
|
// Menu bar item
|
2018-10-03 22:23:55 +02:00
|
|
|
File.setStatusbarMessage ("File management commands");
|
2016-07-31 20:28:45 +02:00
|
|
|
|
2018-01-28 19:54:52 +01:00
|
|
|
// Dialog list menu item
|
2018-10-03 22:23:55 +02:00
|
|
|
DglList.setStatusbarMessage ("List of all the active dialogs");
|
2016-07-31 20:28:45 +02:00
|
|
|
|
2018-01-28 19:54:52 +01:00
|
|
|
// File menu items
|
2018-10-03 22:23:55 +02:00
|
|
|
configureFileMenuItems();
|
2018-01-28 19:54:52 +01:00
|
|
|
|
|
|
|
// Dialog buttons
|
2018-10-03 22:23:55 +02:00
|
|
|
configureDialogButtons();
|
2018-01-28 19:54:52 +01:00
|
|
|
|
|
|
|
// Statusbar at the bottom
|
2018-10-03 22:23:55 +02:00
|
|
|
Statusbar.setMessage("Status bar message");
|
2018-01-28 19:54:52 +01:00
|
|
|
|
|
|
|
// Generate data vector for the windows
|
2019-08-25 22:16:00 +02:00
|
|
|
for (int n{1}; n <= 6; n++)
|
2018-01-28 19:54:52 +01:00
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto win_dat = new win_data;
|
2018-11-05 23:19:03 +01:00
|
|
|
win_dat->title.sprintf("Window %1d", n);
|
2018-01-28 19:54:52 +01:00
|
|
|
windows.push_back(win_dat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
Window::~Window()
|
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto iter = windows.begin();
|
2018-01-28 19:54:52 +01:00
|
|
|
|
|
|
|
while ( iter != windows.end() )
|
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto win_dat = *iter;
|
2018-01-28 19:54:52 +01:00
|
|
|
|
|
|
|
// Remove all callbacks before Window::cb_destroyWindow() will be called
|
|
|
|
if ( win_dat->is_open && win_dat->dgl )
|
2020-08-11 23:04:46 +02:00
|
|
|
win_dat->dgl->delCallback();
|
2018-01-28 19:54:52 +01:00
|
|
|
|
|
|
|
delete win_dat;
|
|
|
|
iter = windows.erase(iter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-10-03 22:23:55 +02:00
|
|
|
void Window::configureFileMenuItems()
|
2018-01-28 19:54:52 +01:00
|
|
|
{
|
2018-10-03 22:23:55 +02:00
|
|
|
// "File" menu item setting
|
|
|
|
New.setStatusbarMessage ("Create the windows");
|
|
|
|
Close.setStatusbarMessage ("Close the windows");
|
|
|
|
Line1.setSeparator();
|
2019-04-26 21:06:04 +02:00
|
|
|
Next.addAccelerator (fc::Fmkey_npage); // Meta/Alt + PgDn
|
2018-10-03 22:23:55 +02:00
|
|
|
Next.setStatusbarMessage ("Switch to the next window");
|
2019-04-26 21:06:04 +02:00
|
|
|
Previous.addAccelerator (fc::Fmkey_ppage); // Meta/Alt + PgUp
|
2018-10-03 22:23:55 +02:00
|
|
|
Previous.setStatusbarMessage ("Switch to the previous window");
|
|
|
|
Line2.setSeparator();
|
2019-04-26 21:06:04 +02:00
|
|
|
Quit.addAccelerator (fc::Fmkey_x); // Meta/Alt + X
|
2018-10-03 22:23:55 +02:00
|
|
|
Quit.setStatusbarMessage ("Exit the program");
|
2016-07-31 20:28:45 +02:00
|
|
|
|
2018-01-28 19:54:52 +01:00
|
|
|
// Add menu item callback
|
2020-08-11 23:04:46 +02:00
|
|
|
addClickedCallback (&New, this, &Window::cb_createWindows);
|
|
|
|
addClickedCallback (&Close, this, &Window::cb_closeWindows);
|
|
|
|
addClickedCallback (&Next, this, &Window::cb_next);
|
|
|
|
addClickedCallback (&Previous, this, &Window::cb_previous);
|
|
|
|
addClickedCallback ( &Quit
|
|
|
|
, finalcut::getFApplication()
|
|
|
|
, &finalcut::FApplication::cb_exitApp
|
|
|
|
, this );
|
2018-01-28 19:54:52 +01:00
|
|
|
}
|
2016-07-31 20:28:45 +02:00
|
|
|
|
2018-01-28 19:54:52 +01:00
|
|
|
//----------------------------------------------------------------------
|
2018-10-03 22:23:55 +02:00
|
|
|
void Window::configureDialogButtons()
|
2018-01-28 19:54:52 +01:00
|
|
|
{
|
|
|
|
// Dialog buttons
|
2020-05-02 00:07:35 +02:00
|
|
|
CreateButton.setGeometry (FPoint{2, 2}, FSize{9, 1});
|
2018-10-03 22:23:55 +02:00
|
|
|
CreateButton.setText (L"&Create");
|
2020-05-02 00:07:35 +02:00
|
|
|
CloseButton.setGeometry (FPoint{15, 2}, FSize{9, 1});
|
2018-10-03 22:23:55 +02:00
|
|
|
CloseButton.setText (L"C&lose");
|
2020-05-02 00:07:35 +02:00
|
|
|
QuitButton.setGeometry (FPoint{28, 2}, FSize{9, 1});
|
2018-10-03 22:23:55 +02:00
|
|
|
QuitButton.setText (L"&Quit");
|
2016-07-31 20:28:45 +02:00
|
|
|
|
|
|
|
// Add button callback
|
2020-08-11 23:04:46 +02:00
|
|
|
addClickedCallback (&CreateButton, this, &Window::cb_createWindows);
|
|
|
|
addClickedCallback (&CloseButton, this, &Window::cb_closeWindows);
|
|
|
|
addClickedCallback ( &QuitButton
|
|
|
|
, finalcut::getFApplication()
|
|
|
|
, &finalcut::FApplication::cb_exitApp
|
|
|
|
, this );
|
2016-07-31 20:28:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2020-08-23 14:00:53 +02:00
|
|
|
void Window::activateWindow (finalcut::FDialog* win) const
|
2016-07-31 20:28:45 +02:00
|
|
|
{
|
2016-10-17 08:44:38 +02:00
|
|
|
if ( ! win || win->isWindowHidden() || win->isWindowActive() )
|
|
|
|
return;
|
2016-07-31 20:28:45 +02:00
|
|
|
|
2020-02-02 22:34:27 +01:00
|
|
|
const bool has_raised = finalcut::FWindow::raiseWindow(win);
|
2016-10-17 08:44:38 +02:00
|
|
|
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()
|
|
|
|
{
|
2020-10-04 00:59:21 +02:00
|
|
|
finalcut::FDialog::adjustSize();
|
|
|
|
|
2020-02-02 22:34:27 +01:00
|
|
|
const std::size_t w = getDesktopWidth();
|
|
|
|
const std::size_t h = getDesktopHeight();
|
2020-10-04 02:55:15 +02:00
|
|
|
const auto X = int(1 + (w - 40) / 2);
|
|
|
|
auto Y = int(1 + (h - 22) / 2);
|
2020-02-02 22:34:27 +01:00
|
|
|
const int dx = ( w > 80 ) ? int(w - 80) / 2 : 0;
|
|
|
|
const int dy = ( h > 24 ) ? int(h - 24) / 2 : 0;
|
2017-10-02 07:32:33 +02:00
|
|
|
|
|
|
|
if ( Y < 2 )
|
2016-11-02 00:37:58 +01:00
|
|
|
Y = 2;
|
|
|
|
|
2020-05-02 00:07:35 +02:00
|
|
|
setPos (FPoint{X, Y});
|
2020-02-02 22:34:27 +01:00
|
|
|
const auto& first = windows.begin();
|
2018-12-15 00:50:09 +01:00
|
|
|
auto iter = first;
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
while ( iter != windows.end() )
|
|
|
|
{
|
|
|
|
if ( (*iter)->is_open )
|
|
|
|
{
|
2020-10-04 02:55:15 +02:00
|
|
|
const auto n = int(std::distance(first, iter));
|
2020-02-02 22:34:27 +01:00
|
|
|
const int x = dx + 5 + (n % 3) * 25 + int(n / 3) * 3;
|
|
|
|
const int y = dy + 11 + int(n / 3) * 3;
|
2020-05-02 00:07:35 +02:00
|
|
|
(*iter)->dgl->setPos (FPoint{x, y});
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-28 19:54:52 +01:00
|
|
|
//----------------------------------------------------------------------
|
2020-09-18 17:13:52 +02:00
|
|
|
template <typename InstanceT
|
|
|
|
, typename CallbackT
|
|
|
|
, typename... Args>
|
2018-09-20 23:59:01 +02:00
|
|
|
void Window::addClickedCallback ( finalcut::FWidget* widget
|
2020-08-11 23:04:46 +02:00
|
|
|
, InstanceT&& instance
|
|
|
|
, CallbackT&& callback
|
|
|
|
, Args&&... args )
|
2018-01-28 19:54:52 +01:00
|
|
|
{
|
|
|
|
widget->addCallback
|
|
|
|
(
|
|
|
|
"clicked",
|
2020-08-11 23:04:46 +02:00
|
|
|
std::bind ( std::forward<CallbackT>(callback)
|
|
|
|
, std::forward<InstanceT>(instance)
|
|
|
|
, std::forward<Args>(args)... )
|
2018-01-28 19:54:52 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-04-13 12:40:11 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
template <typename IteratorT>
|
|
|
|
finalcut::FDialog* Window::getNext (IteratorT iter)
|
|
|
|
{
|
|
|
|
auto next_element = iter;
|
|
|
|
finalcut::FDialog* next{nullptr};
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
++next_element;
|
|
|
|
|
|
|
|
if ( next_element == getDialogList()->end() )
|
|
|
|
next_element = getDialogList()->begin();
|
|
|
|
|
|
|
|
next = static_cast<finalcut::FDialog*>(*next_element);
|
|
|
|
} while ( ! next->isEnabled()
|
|
|
|
|| ! next->acceptFocus()
|
|
|
|
|| ! next->isVisible()
|
|
|
|
|| ! next->isWindowWidget() );
|
|
|
|
|
|
|
|
return next;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
template <typename IteratorT>
|
|
|
|
finalcut::FDialog* Window::getPrevious (IteratorT iter)
|
|
|
|
{
|
|
|
|
auto prev_element = iter;
|
|
|
|
finalcut::FDialog* prev;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if ( prev_element == getDialogList()->begin() )
|
|
|
|
prev_element = getDialogList()->end();
|
|
|
|
|
|
|
|
--prev_element;
|
|
|
|
prev = static_cast<finalcut::FDialog*>(*prev_element);
|
|
|
|
} while ( ! prev->isEnabled()
|
|
|
|
|| ! prev->acceptFocus()
|
|
|
|
|| ! prev->isVisible()
|
|
|
|
|| ! prev->isWindowWidget() );
|
|
|
|
|
|
|
|
return prev;
|
|
|
|
}
|
|
|
|
|
2016-07-31 20:28:45 +02:00
|
|
|
//----------------------------------------------------------------------
|
2018-09-20 23:59:01 +02:00
|
|
|
void Window::onClose (finalcut::FCloseEvent* ev)
|
2016-07-31 20:28:45 +02:00
|
|
|
{
|
2018-09-20 23:59:01 +02:00
|
|
|
finalcut::FApplication::closeConfirmationDialog (this, ev);
|
2016-07-31 20:28:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2020-08-11 23:04:46 +02:00
|
|
|
void Window::cb_createWindows()
|
2016-07-31 20:28:45 +02:00
|
|
|
{
|
2020-02-02 22:34:27 +01:00
|
|
|
const auto& first = windows.begin();
|
2018-12-15 00:50:09 +01:00
|
|
|
auto iter = first;
|
2020-02-02 22:34:27 +01:00
|
|
|
const auto w = getRootWidget()->getWidth();
|
|
|
|
const auto h = getRootWidget()->getHeight();
|
|
|
|
const int dx = ( w > 80 ) ? int(w - 80) / 2 : 0;
|
|
|
|
const int dy = ( h > 24 ) ? int(h - 24) / 2 : 0;
|
2016-07-31 20:28:45 +02:00
|
|
|
|
|
|
|
while ( iter != windows.end() )
|
|
|
|
{
|
|
|
|
if ( ! (*iter)->is_open )
|
|
|
|
{
|
2018-12-15 00:50:09 +01:00
|
|
|
auto win_dat = *iter;
|
|
|
|
auto win = new SmallWindow(this);
|
2016-07-31 20:28:45 +02:00
|
|
|
win_dat->dgl = win;
|
|
|
|
win_dat->is_open = true;
|
2018-10-03 22:23:55 +02:00
|
|
|
win->setText(win_dat->title);
|
2020-10-04 02:55:15 +02:00
|
|
|
const auto n = int(std::distance(first, iter));
|
2020-02-02 22:34:27 +01:00
|
|
|
const int x = dx + 5 + (n % 3) * 25 + int(n / 3) * 3;
|
|
|
|
const int y = dy + 11 + int(n / 3) * 3;
|
2020-05-02 00:07:35 +02:00
|
|
|
win->setGeometry (FPoint{x, y}, FSize{20, 8});
|
|
|
|
win->setMinimumSize (FSize{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",
|
2020-08-11 23:04:46 +02:00
|
|
|
this, &Window::cb_destroyWindow,
|
|
|
|
win_dat
|
2016-07-31 20:28:45 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
|
|
|
|
activateWindow(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2020-08-11 23:04:46 +02:00
|
|
|
void Window::cb_closeWindows()
|
2016-07-31 20:28:45 +02:00
|
|
|
{
|
2019-09-01 23:29:27 +02:00
|
|
|
if ( ! getDialogList() || getDialogList()->empty() )
|
2016-07-31 20:28:45 +02:00
|
|
|
return;
|
|
|
|
|
2019-09-01 23:29:27 +02:00
|
|
|
auto iter = getDialogList()->end();
|
2020-02-02 22:34:27 +01:00
|
|
|
const auto& first = getDialogList()->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
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2020-08-11 23:04:46 +02:00
|
|
|
void Window::cb_next()
|
2016-07-31 20:28:45 +02:00
|
|
|
{
|
2019-09-01 23:29:27 +02:00
|
|
|
if ( ! getDialogList() || getDialogList()->empty() )
|
2016-07-31 20:28:45 +02:00
|
|
|
return;
|
|
|
|
|
2019-09-01 23:29:27 +02:00
|
|
|
auto iter = getDialogList()->begin();
|
2016-07-31 20:28:45 +02:00
|
|
|
|
2019-09-01 23:29:27 +02:00
|
|
|
while ( iter != getDialogList()->end() )
|
2016-07-31 20:28:45 +02:00
|
|
|
{
|
2018-09-20 23:59:01 +02:00
|
|
|
if ( static_cast<finalcut::FWindow*>(*iter)->isWindowActive() )
|
2016-07-31 20:28:45 +02:00
|
|
|
{
|
2020-04-13 12:40:11 +02:00
|
|
|
activateWindow(getNext(iter));
|
2016-07-31 20:28:45 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2020-08-11 23:04:46 +02:00
|
|
|
void Window::cb_previous()
|
2016-07-31 20:28:45 +02:00
|
|
|
{
|
2019-09-01 23:29:27 +02:00
|
|
|
if ( ! getDialogList() || getDialogList()->empty() )
|
2016-07-31 20:28:45 +02:00
|
|
|
return;
|
|
|
|
|
2019-09-01 23:29:27 +02:00
|
|
|
auto iter = getDialogList()->end();
|
2016-07-31 20:28:45 +02:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
--iter;
|
|
|
|
|
2016-09-25 23:53:48 +02:00
|
|
|
if ( (*iter)->isDialogWidget()
|
2018-09-20 23:59:01 +02:00
|
|
|
&& static_cast<finalcut::FWindow*>(*iter)->isWindowActive() )
|
2016-07-31 20:28:45 +02:00
|
|
|
{
|
2020-04-13 12:40:11 +02:00
|
|
|
activateWindow(getPrevious(iter));
|
2016-07-31 20:28:45 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-09-01 23:29:27 +02:00
|
|
|
while ( iter != getDialogList()->begin() );
|
2016-07-31 20:28:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2020-08-11 23:04:46 +02:00
|
|
|
void Window::cb_destroyWindow (win_data* win_dat) const
|
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-12-10 01:48:26 +01:00
|
|
|
win_dat->dgl = nullptr;
|
2018-01-28 19:54:52 +01:00
|
|
|
}
|
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
|
2020-05-02 00:07:35 +02:00
|
|
|
finalcut::FApplication app {argc, argv};
|
2016-07-31 20:28:45 +02:00
|
|
|
|
2017-09-19 06:18:03 +02:00
|
|
|
// Create main dialog object
|
2020-05-02 00:07:35 +02:00
|
|
|
Window main_dlg {&app};
|
2016-07-31 20:28:45 +02:00
|
|
|
main_dlg.setText ("Main window");
|
|
|
|
|
2017-09-19 06:18:03 +02:00
|
|
|
// Set dialog main_dlg as main widget
|
2020-04-13 12:40:11 +02:00
|
|
|
finalcut::FWidget::setMainWidget (&main_dlg);
|
2016-07-31 20:28:45 +02:00
|
|
|
|
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();
|
|
|
|
}
|