2017-11-04 07:03:53 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* fmessagebox.h - Widget FMessageBox (a text message window) *
|
|
|
|
* *
|
|
|
|
* This file is part of the Final Cut widget toolkit *
|
|
|
|
* *
|
2019-07-21 23:31:21 +02:00
|
|
|
* Copyright 2014-2019 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/>. *
|
|
|
|
***********************************************************************/
|
2017-10-02 07:32:33 +02:00
|
|
|
|
|
|
|
/* Inheritance diagram
|
|
|
|
* ═══════════════════
|
|
|
|
*
|
2017-10-29 14:27:50 +01:00
|
|
|
* ▕▔▔▔▔▔▔▔▔▔▏
|
|
|
|
* ▕ FTerm ▏
|
|
|
|
* ▕▁▁▁▁▁▁▁▁▁▏
|
|
|
|
* ▲
|
|
|
|
* │
|
2017-10-02 07:32:33 +02:00
|
|
|
* ▕▔▔▔▔▔▔▔▔▔▏ ▕▔▔▔▔▔▔▔▔▔▏
|
2017-10-29 14:27:50 +01:00
|
|
|
* ▕ FVTerm ▏ ▕ FObject ▏
|
2017-10-02 07:32:33 +02:00
|
|
|
* ▕▁▁▁▁▁▁▁▁▁▏ ▕▁▁▁▁▁▁▁▁▁▏
|
|
|
|
* ▲ ▲
|
|
|
|
* │ │
|
|
|
|
* └─────┬─────┘
|
|
|
|
* │
|
|
|
|
* ▕▔▔▔▔▔▔▔▔▔▏
|
|
|
|
* ▕ FWidget ▏
|
|
|
|
* ▕▁▁▁▁▁▁▁▁▁▏
|
|
|
|
* ▲
|
|
|
|
* │
|
|
|
|
* ▕▔▔▔▔▔▔▔▔▔▏
|
|
|
|
* ▕ FWindow ▏
|
|
|
|
* ▕▁▁▁▁▁▁▁▁▁▏
|
|
|
|
* ▲
|
|
|
|
* │
|
|
|
|
* ▕▔▔▔▔▔▔▔▔▔▏
|
|
|
|
* ▕ FDialog ▏
|
|
|
|
* ▕▁▁▁▁▁▁▁▁▁▏
|
|
|
|
* ▲
|
|
|
|
* │
|
|
|
|
* ▕▔▔▔▔▔▔▔▔▔▔▔▔▔▏
|
|
|
|
* ▕ FMessageBox ▏
|
|
|
|
* ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▏
|
|
|
|
*/
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-04-09 20:08:53 +02:00
|
|
|
#ifndef FMESSAGEBOX_H
|
|
|
|
#define FMESSAGEBOX_H
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-10-31 00:41:59 +01:00
|
|
|
#if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT)
|
|
|
|
#error "Only <final/final.h> can be included directly."
|
|
|
|
#endif
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
#include <cstring>
|
|
|
|
|
2017-09-17 21:32:46 +02:00
|
|
|
#include "final/fdialog.h"
|
2019-07-21 23:31:21 +02:00
|
|
|
#include "final/fwidgetcolors.h"
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
namespace finalcut
|
|
|
|
{
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2019-07-21 23:31:21 +02:00
|
|
|
// class forward declaration
|
|
|
|
class FButton;
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class FMessageBox
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
#pragma pack(push)
|
|
|
|
#pragma pack(1)
|
|
|
|
|
|
|
|
class FMessageBox : public FDialog
|
|
|
|
{
|
2017-09-11 03:06:02 +02:00
|
|
|
public:
|
|
|
|
// Enumeration
|
2018-10-17 22:12:52 +02:00
|
|
|
enum ButtonType
|
2017-09-11 03:06:02 +02:00
|
|
|
{
|
|
|
|
Reject = 0,
|
|
|
|
Ok = 1,
|
|
|
|
Cancel = 2,
|
|
|
|
Yes = 3,
|
|
|
|
No = 4,
|
|
|
|
Abort = 5,
|
|
|
|
Retry = 6,
|
|
|
|
Ignore = 7
|
|
|
|
};
|
|
|
|
|
|
|
|
// Constructors
|
2018-12-10 01:48:26 +01:00
|
|
|
explicit FMessageBox (FWidget* = nullptr);
|
2017-09-11 03:06:02 +02:00
|
|
|
FMessageBox (const FMessageBox&); // copy constructor
|
|
|
|
FMessageBox ( const FString&, const FString&
|
|
|
|
, int, int, int
|
2018-12-10 01:48:26 +01:00
|
|
|
, FWidget* = nullptr );
|
2017-09-11 03:06:02 +02:00
|
|
|
// Destructor
|
2018-09-24 04:02:35 +02:00
|
|
|
virtual ~FMessageBox();
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Assignment operator (=)
|
|
|
|
FMessageBox& operator = (const FMessageBox&);
|
|
|
|
|
|
|
|
// Accessor
|
2019-08-06 23:45:28 +02:00
|
|
|
const char* getClassName() const override;
|
2018-12-31 06:18:39 +01:00
|
|
|
const FString getTitlebarText() const;
|
|
|
|
const FString getHeadline() const;
|
|
|
|
const FString getText() const;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Mutator
|
2018-12-31 06:18:39 +01:00
|
|
|
void setTitlebarText (const FString&);
|
|
|
|
void setHeadline (const FString&);
|
|
|
|
bool setCenterText(bool);
|
|
|
|
bool setCenterText();
|
|
|
|
bool unsetCenterText();
|
|
|
|
void setText (const FString&);
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Methods
|
2018-12-26 23:41:49 +01:00
|
|
|
template <typename messageType>
|
2018-12-31 06:18:39 +01:00
|
|
|
static int info ( FWidget*
|
|
|
|
, const FString&
|
|
|
|
, const messageType&
|
|
|
|
, int = FMessageBox::Ok
|
|
|
|
, int = 0
|
|
|
|
, int = 0 );
|
2017-09-11 03:06:02 +02:00
|
|
|
|
2018-12-26 23:41:49 +01:00
|
|
|
template <typename messageType>
|
2018-12-31 06:18:39 +01:00
|
|
|
static int error ( FWidget*
|
|
|
|
, const messageType&
|
|
|
|
, int = FMessageBox::Ok
|
|
|
|
, int = 0
|
|
|
|
, int = 0 );
|
2017-09-11 03:06:02 +02:00
|
|
|
protected:
|
|
|
|
// Method
|
2019-08-06 23:45:28 +02:00
|
|
|
void adjustSize() override;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Callback method
|
2018-12-31 06:18:39 +01:00
|
|
|
void cb_processClick (FWidget*, FDataPtr);
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
// Methods
|
2018-12-31 06:18:39 +01:00
|
|
|
void init (int, int, int);
|
|
|
|
void allocation (int, int, int);
|
|
|
|
void deallocation();
|
|
|
|
void initCallbacks();
|
|
|
|
void calculateDimensions();
|
2019-08-06 23:45:28 +02:00
|
|
|
void draw() override;
|
2018-12-31 06:18:39 +01:00
|
|
|
void resizeButtons();
|
|
|
|
void adjustButtons();
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Data Members
|
2018-12-03 03:22:36 +01:00
|
|
|
FString headline_text{};
|
|
|
|
FString text{};
|
2018-12-10 01:48:26 +01:00
|
|
|
FString* text_components{nullptr};
|
2018-12-03 03:22:36 +01:00
|
|
|
FStringList text_split{};
|
|
|
|
std::size_t max_line_width{0};
|
|
|
|
bool center_text{false};
|
2019-09-01 23:29:27 +02:00
|
|
|
FColor emphasis_color{getFWidgetColors().dialog_emphasis_fg};
|
2018-12-03 03:22:36 +01:00
|
|
|
uInt num_buttons{0};
|
|
|
|
uInt text_num_lines{0};
|
2018-12-09 18:24:31 +01:00
|
|
|
int button_digit[3]{0};
|
2018-12-10 01:48:26 +01:00
|
|
|
FButton* button[3]{nullptr};
|
2015-05-23 13:35:12 +02:00
|
|
|
};
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
|
|
|
|
|
|
|
// FMessageBox inline functions
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline const char* FMessageBox::getClassName() const
|
|
|
|
{ return "FMessageBox"; }
|
|
|
|
|
2015-09-22 04:18:20 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline const FString FMessageBox::getTitlebarText() const
|
|
|
|
{ return FDialog::getText(); }
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline const FString FMessageBox::getHeadline() const
|
|
|
|
{ return headline_text; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline const FString FMessageBox::getText() const
|
|
|
|
{ return text; }
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FMessageBox::setTitlebarText (const FString& txt)
|
|
|
|
{ return FDialog::setText(txt); }
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
2018-12-22 23:50:10 +01:00
|
|
|
inline bool FMessageBox::setCenterText(bool enable)
|
|
|
|
{ return (center_text = enable); }
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FMessageBox::setCenterText()
|
|
|
|
{ return setCenterText(true); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FMessageBox::unsetCenterText()
|
|
|
|
{ return setCenterText(false); }
|
|
|
|
|
2018-12-26 23:41:49 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
template <typename messageType>
|
|
|
|
int FMessageBox::info ( FWidget* parent
|
|
|
|
, const FString& caption
|
|
|
|
, const messageType& message
|
|
|
|
, int button0
|
|
|
|
, int button1
|
|
|
|
, int button2 )
|
|
|
|
{
|
|
|
|
FMessageBox mbox ( caption
|
|
|
|
, FString() << message
|
|
|
|
, button0, button1, button2
|
|
|
|
, parent );
|
2019-08-25 22:16:00 +02:00
|
|
|
int reply = mbox.exec();
|
2018-12-26 23:41:49 +01:00
|
|
|
return reply;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
template <typename messageType>
|
|
|
|
int FMessageBox::error ( FWidget* parent
|
|
|
|
, const messageType& message
|
|
|
|
, int button0
|
|
|
|
, int button1
|
|
|
|
, int button2 )
|
|
|
|
{
|
2019-08-25 22:16:00 +02:00
|
|
|
const FString caption{"Error message"};
|
2019-09-01 23:29:27 +02:00
|
|
|
|
2018-12-26 23:41:49 +01:00
|
|
|
FMessageBox mbox ( caption
|
|
|
|
, FString() << message
|
|
|
|
, button0, button1, button2
|
|
|
|
, parent );
|
|
|
|
mbox.beep();
|
|
|
|
mbox.setHeadline("Warning:");
|
|
|
|
mbox.setCenterText();
|
2019-09-01 23:29:27 +02:00
|
|
|
const FWidgetColors& wc = mbox.getFWidgetColors();
|
|
|
|
mbox.setForegroundColor(wc.error_box_fg);
|
|
|
|
mbox.setBackgroundColor(wc.error_box_bg);
|
|
|
|
mbox.emphasis_color = wc.error_box_emphasis_fg;
|
2019-08-25 22:16:00 +02:00
|
|
|
int reply = mbox.exec();
|
2018-12-26 23:41:49 +01:00
|
|
|
return reply;
|
|
|
|
}
|
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
} // namespace finalcut
|
|
|
|
|
2017-04-09 20:08:53 +02:00
|
|
|
#endif // FMESSAGEBOX_H
|