finalcut/src/include/final/fdialog.h

297 lines
11 KiB
C
Raw Normal View History

2017-11-04 07:03:53 +01:00
/***********************************************************************
* fdialog.h - Widget FDialog *
* *
* This file is part of the FINAL CUT widget toolkit *
2017-11-04 07:03:53 +01:00
* *
2020-01-20 21:40:00 +01:00
* Copyright 2012-2020 Markus Gans *
2017-11-04 07:03:53 +01: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. *
* *
* 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/>. *
***********************************************************************/
/* Inheritance diagram
*
*
*
* FVTerm FObject
*
*
*
*
*
*
* FWidget
*
*
*
*
* FWindow
*
*
*
*
* FDialog
*
*/
2015-05-23 13:35:12 +02:00
#ifndef FDIALOG_H
#define FDIALOG_H
#if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT)
#error "Only <final/final.h> can be included directly."
#endif
#include "final/fmenu.h"
#include "final/fwindow.h"
2015-05-23 13:35:12 +02:00
namespace finalcut
{
2015-05-23 13:35:12 +02:00
// class forward declaration
class FToolTip;
2015-05-23 13:35:12 +02:00
//----------------------------------------------------------------------
// class FDialog
//----------------------------------------------------------------------
class FDialog : public FWindow
{
2017-09-11 03:06:02 +02:00
public:
// Using-declaration
2017-09-11 03:06:02 +02:00
using FWindow::setResizeable;
// Enumeration
enum DialogCode
{
Reject = 0,
Accept = 1
};
// Constructors
explicit FDialog (FWidget* = nullptr);
explicit FDialog (const FString&, FWidget* = nullptr);
// Disable copy constructor
FDialog (const FDialog&) = delete;
2017-09-11 03:06:02 +02:00
// Destructor
2020-02-19 21:59:13 +01:00
~FDialog() override;
2017-09-11 03:06:02 +02:00
// Disable copy assignment operator (=)
FDialog& operator = (const FDialog&) = delete;
2017-09-11 03:06:02 +02:00
// Accessors
2020-04-18 13:33:42 +02:00
const FString getClassName() const override;
virtual const FString getText() const;
2017-09-11 03:06:02 +02:00
// Mutators
2020-04-18 13:33:42 +02:00
bool setDialogWidget (bool);
bool setDialogWidget();
bool unsetDialogWidget();
bool setModal (bool);
bool setModal();
bool unsetModal();
bool setResizeable (bool) override;
bool setScrollable (bool);
bool setScrollable();
bool unsetScrollable();
bool setBorder (bool);
bool setBorder();
bool unsetBorder();
2020-05-30 23:27:42 +02:00
void resetColors() override;
2020-04-18 13:33:42 +02:00
virtual void setText (const FString&);
2017-09-11 03:06:02 +02:00
// Inquiries
2020-04-18 13:33:42 +02:00
bool isModal() const;
bool isScrollable() const;
bool hasBorder() const;
2017-09-11 03:06:02 +02:00
// Methods
2020-04-18 13:33:42 +02:00
void show() override;
void hide() override;
int exec();
void setPos (const FPoint&, bool = true) override;
void move (const FPoint&) override;
bool moveUp (int);
bool moveDown (int);
bool moveLeft (int);
bool moveRight (int);
void setSize (const FSize&, bool = true) override;
bool reduceHeight (int);
bool expandHeight (int);
bool reduceWidth (int);
bool expandWidth (int);
void activateDialog();
2017-09-11 03:06:02 +02:00
// Event handlers
2020-04-18 13:33:42 +02:00
void onKeyPress (FKeyEvent*) override;
void onMouseDown (FMouseEvent*) override;
void onMouseUp (FMouseEvent*) override;
void onMouseMove (FMouseEvent*) override;
void onMouseDoubleClick (FMouseEvent*) override;
void onAccel (FAccelEvent*) override;
void onWindowActive (FEvent*) override;
void onWindowInactive (FEvent*) override;
void onWindowRaised (FEvent*) override;
void onWindowLowered (FEvent*) override;
2017-09-11 03:06:02 +02:00
protected:
// Methods
2020-04-18 13:33:42 +02:00
virtual void done (int);
void draw() override;
void drawDialogShadow();
2017-09-11 03:06:02 +02:00
// Event handlers
2020-04-18 13:33:42 +02:00
void onClose (FCloseEvent*) override;
2017-09-11 03:06:02 +02:00
private:
// Typedef
typedef struct
{
int mouse_x;
int mouse_y;
FPoint termPos;
std::size_t zoom_btn;
bool mouse_over_menu;
} mouseStates;
// Constant
2018-12-26 23:41:49 +01:00
static constexpr std::size_t MENU_BTN = 3;
static constexpr bool PRINT_WIN_NUMBER = false; // Only for debug
2017-09-11 03:06:02 +02:00
// Methods
2020-04-18 13:33:42 +02:00
void init();
void initDialogMenu();
void initMoveSizeMenuItem (FMenu*);
void initZoomMenuItem (FMenu*);
void initCloseMenuItem (FMenu*);
void drawBorder() override;
void drawTitleBar();
void drawBarButton();
void drawZoomButton();
void drawRestoreSizeButton();
void drawZoomedButton();
void drawTextBar();
void restoreOverlaidWindows();
void setCursorToFocusWidget();
void leaveMenu();
void openMenu();
void selectFirstMenuItem();
void setZoomItem();
std::size_t getZoomButtonWidth();
void activateZoomButton (const mouseStates&);
void deactivateZoomButton();
void leaveZoomButton (const mouseStates&);
void pressZoomButton (const mouseStates&);
bool isMouseOverMenu (const FPoint&) const;
2020-04-18 13:33:42 +02:00
void passEventToSubMenu (const mouseStates&, const FMouseEvent*);
void moveSizeKey (FKeyEvent*);
void raiseActivateDialog();
void lowerActivateDialog();
bool isOutsideTerminal (const FPoint&) const;
bool isLowerRightResizeCorner (const mouseStates&) const;
2020-04-18 13:33:42 +02:00
void resizeMouseDown (const mouseStates&);
void resizeMouseUpMove (const mouseStates&, bool = false);
void cancelMouseResize();
void acceptMoveSize();
void cancelMoveSize();
static void addDialog (FWidget*);
static void delDialog (const FWidget*);
2017-09-11 03:06:02 +02:00
// Callback methods
2020-04-18 13:33:42 +02:00
void cb_move (const FWidget*, const FDataPtr);
void cb_zoom (const FWidget*, const FDataPtr);
void cb_close (const FWidget*, const FDataPtr);
2017-09-11 03:06:02 +02:00
// Data members
2020-04-18 13:33:42 +02:00
FString tb_text{}; // title bar text
int result_code{FDialog::Reject};
bool zoom_button_pressed{false};
bool zoom_button_active{false};
bool setPos_error{false};
bool setSize_error{false};
FPoint titlebar_click_pos{};
FPoint resize_click_pos{};
FRect save_geometry{}; // required by keyboard move/size
FMenu* dialog_menu{nullptr};
FMenuItem* dgl_menuitem{nullptr};
FMenuItem* move_size_item{nullptr};
FMenuItem* zoom_item{nullptr};
FMenuItem* close_item{nullptr};
FToolTip* tooltip{nullptr};
2017-09-11 03:06:02 +02:00
// Friend function from FMenu
friend void FMenu::hideSuperMenus();
2015-05-23 13:35:12 +02:00
};
// FDialog inline functions
//----------------------------------------------------------------------
2019-10-05 23:20:07 +02:00
inline const FString FDialog::getClassName() const
2015-05-23 13:35:12 +02:00
{ return "FDialog"; }
//----------------------------------------------------------------------
2020-04-18 13:33:42 +02:00
inline const FString FDialog::getText() const
{ return tb_text; }
//----------------------------------------------------------------------
inline bool FDialog::setDialogWidget()
{ return setDialogWidget(true); }
//----------------------------------------------------------------------
inline bool FDialog::unsetDialogWidget()
{ return setDialogWidget(false); }
2015-05-23 13:35:12 +02:00
//----------------------------------------------------------------------
inline bool FDialog::setModal()
{ return setModal(true); }
//----------------------------------------------------------------------
inline bool FDialog::unsetModal()
{ return setModal(false); }
//----------------------------------------------------------------------
inline bool FDialog::setScrollable()
{ return setScrollable(true); }
//----------------------------------------------------------------------
inline bool FDialog::unsetScrollable()
{ return setScrollable(false); }
//----------------------------------------------------------------------
inline bool FDialog::setBorder()
{ return setBorder(true); }
//----------------------------------------------------------------------
inline bool FDialog::unsetBorder()
{ return setBorder(false); }
2015-05-23 13:35:12 +02:00
//----------------------------------------------------------------------
inline void FDialog::setText (const FString& txt)
2019-08-25 22:16:00 +02:00
{ tb_text.setString(txt); }
2015-05-23 13:35:12 +02:00
//----------------------------------------------------------------------
inline bool FDialog::isModal() const
{ return getFlags().modal; }
2015-05-23 13:35:12 +02:00
//----------------------------------------------------------------------
inline bool FDialog::isScrollable() const
{ return getFlags().scrollable; }
//----------------------------------------------------------------------
inline bool FDialog::hasBorder() const
{ return ! getFlags().no_border; }
} // namespace finalcut
2015-05-23 13:35:12 +02:00
#endif // FDIALOG_H