2017-11-04 07:03:53 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* fmessagebox.cpp - Widget FMessageBox (a text message window) *
|
|
|
|
* *
|
|
|
|
* This file is part of the Final Cut widget toolkit *
|
|
|
|
* *
|
2018-01-31 23:37:03 +01:00
|
|
|
* Copyright 2014-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/>. *
|
|
|
|
***********************************************************************/
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
#include <algorithm>
|
|
|
|
|
2017-09-17 21:32:46 +02:00
|
|
|
#include "final/fapplication.h"
|
|
|
|
#include "final/fmessagebox.h"
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
|
2017-03-17 22:59:06 +01:00
|
|
|
static const char* const button_text[] =
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
|
|
|
0,
|
|
|
|
"&OK",
|
|
|
|
"&Cancel",
|
|
|
|
"&Yes",
|
|
|
|
"&No",
|
|
|
|
"&Abort",
|
|
|
|
"&Retry",
|
|
|
|
"&Ignore",
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class FMessageBox
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// constructors and destructor
|
|
|
|
//----------------------------------------------------------------------
|
2016-10-01 23:18:49 +02:00
|
|
|
FMessageBox::FMessageBox (FWidget* parent)
|
2015-09-22 04:18:20 +02:00
|
|
|
: FDialog(parent)
|
|
|
|
, headline_text()
|
|
|
|
, text()
|
|
|
|
, text_components(0)
|
|
|
|
, text_split()
|
2016-09-27 00:46:05 +02:00
|
|
|
, max_line_width(0)
|
2015-09-22 04:18:20 +02:00
|
|
|
, center_text(false)
|
|
|
|
, emphasis_color(wc.dialog_emphasis_fg)
|
2016-09-27 00:46:05 +02:00
|
|
|
, num_buttons(0)
|
2015-09-22 04:18:20 +02:00
|
|
|
, text_num_lines(0)
|
|
|
|
, button_digit()
|
|
|
|
, button()
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2015-09-22 04:18:20 +02:00
|
|
|
setTitlebarText("Message for you");
|
|
|
|
init(FMessageBox::Ok, 0, 0);
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2015-09-22 04:18:20 +02:00
|
|
|
FMessageBox::FMessageBox (const FMessageBox& mbox)
|
2016-07-03 20:08:39 +02:00
|
|
|
: FDialog(mbox.getParentWidget())
|
2015-09-22 04:18:20 +02:00
|
|
|
, headline_text(mbox.headline_text)
|
|
|
|
, text(mbox.text)
|
|
|
|
, text_components(mbox.text_components)
|
|
|
|
, text_split(mbox.text_split)
|
2016-09-27 00:46:05 +02:00
|
|
|
, max_line_width(mbox.max_line_width)
|
2015-09-22 04:18:20 +02:00
|
|
|
, center_text(mbox.center_text)
|
|
|
|
, emphasis_color(mbox.emphasis_color)
|
2016-09-27 00:46:05 +02:00
|
|
|
, num_buttons(mbox.num_buttons)
|
2015-09-22 04:18:20 +02:00
|
|
|
, text_num_lines(mbox.text_num_lines)
|
|
|
|
, button_digit()
|
|
|
|
, button()
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2015-09-22 04:18:20 +02:00
|
|
|
setTitlebarText (mbox.getTitlebarText());
|
2017-08-12 20:10:27 +02:00
|
|
|
init ( mbox.button_digit[0]
|
|
|
|
, mbox.button_digit[1]
|
|
|
|
, mbox.button_digit[2] );
|
2015-09-22 04:18:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FMessageBox::FMessageBox ( const FString& caption
|
|
|
|
, const FString& message
|
|
|
|
, int button0
|
|
|
|
, int button1
|
|
|
|
, int button2
|
|
|
|
, FWidget* parent )
|
|
|
|
: FDialog(parent)
|
|
|
|
, headline_text()
|
|
|
|
, text(message)
|
|
|
|
, text_components(0)
|
|
|
|
, text_split()
|
2016-09-27 00:46:05 +02:00
|
|
|
, max_line_width(0)
|
2015-09-22 04:18:20 +02:00
|
|
|
, center_text(false)
|
|
|
|
, emphasis_color(wc.dialog_emphasis_fg)
|
2016-09-27 00:46:05 +02:00
|
|
|
, num_buttons(0)
|
2015-09-22 04:18:20 +02:00
|
|
|
, text_num_lines(0)
|
|
|
|
, button_digit()
|
|
|
|
, button()
|
|
|
|
{
|
|
|
|
setTitlebarText(caption);
|
|
|
|
init(button0, button1, button2);
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FMessageBox::~FMessageBox() // destructor
|
|
|
|
{
|
2018-01-31 23:37:03 +01:00
|
|
|
deallocation();
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
// public methods of FMessageBox
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FMessageBox& FMessageBox::operator = (const FMessageBox& mbox)
|
|
|
|
{
|
|
|
|
if ( &mbox == this )
|
|
|
|
{
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-27 09:50:30 +02:00
|
|
|
for (uInt n = 0; n < num_buttons; n++)
|
2016-11-02 00:37:58 +01:00
|
|
|
delete button[n];
|
|
|
|
|
|
|
|
if ( mbox.getParentWidget() )
|
|
|
|
mbox.getParentWidget()->addChild (this);
|
|
|
|
|
|
|
|
headline_text = mbox.headline_text;
|
|
|
|
text = mbox.text;
|
|
|
|
text_components = mbox.text_components;
|
|
|
|
text_split = mbox.text_split;
|
|
|
|
max_line_width = mbox.max_line_width;
|
|
|
|
center_text = mbox.center_text;
|
|
|
|
emphasis_color = mbox.emphasis_color;
|
|
|
|
num_buttons = mbox.num_buttons;
|
|
|
|
text_num_lines = mbox.text_num_lines;
|
|
|
|
|
|
|
|
setTitlebarText (mbox.getTitlebarText());
|
2017-08-12 20:10:27 +02:00
|
|
|
init ( mbox.button_digit[0]
|
|
|
|
, mbox.button_digit[1]
|
|
|
|
, mbox.button_digit[2] );
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FMessageBox::setHeadline (const FString& headline)
|
|
|
|
{
|
|
|
|
headline_text = headline;
|
|
|
|
setHeight(getHeight() + 2, true);
|
|
|
|
|
2017-08-27 09:50:30 +02:00
|
|
|
for (uInt n = 0; n < num_buttons; n++)
|
|
|
|
button[n]->setY (getHeight() - 4, false);
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
uInt len = headline_text.getLength();
|
|
|
|
|
|
|
|
if ( len > max_line_width )
|
|
|
|
max_line_width = len;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FMessageBox::setText (const FString& txt)
|
|
|
|
{
|
|
|
|
text = txt;
|
|
|
|
calculateDimensions();
|
2017-08-27 09:50:30 +02:00
|
|
|
button[0]->setY (getHeight() - 4, false);
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2017-08-12 20:10:27 +02:00
|
|
|
if ( button_digit[1] != 0 )
|
2017-08-27 09:50:30 +02:00
|
|
|
button[1]->setY (getHeight() - 4, false);
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2017-08-12 20:10:27 +02:00
|
|
|
if ( button_digit[2] != 0 )
|
2017-08-27 09:50:30 +02:00
|
|
|
button[2]->setY (getHeight() - 4, false);
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
adjustButtons();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
int FMessageBox::info ( FWidget* parent
|
|
|
|
, const FString& caption
|
|
|
|
, const FString& message
|
|
|
|
, int button0
|
|
|
|
, int button1
|
|
|
|
, int button2 )
|
|
|
|
{
|
|
|
|
int reply;
|
2017-08-12 22:55:29 +02:00
|
|
|
FMessageBox* mbox;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
mbox = new FMessageBox ( caption, message
|
|
|
|
, button0, button1, button2
|
|
|
|
, parent );
|
|
|
|
}
|
|
|
|
catch (const std::bad_alloc& ex)
|
|
|
|
{
|
|
|
|
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
|
|
|
|
return FDialog::Reject;
|
|
|
|
}
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
reply = mbox->exec();
|
|
|
|
delete mbox;
|
|
|
|
return reply;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
int FMessageBox::info ( FWidget* parent
|
|
|
|
, const FString& caption
|
|
|
|
, int num
|
|
|
|
, int button0
|
|
|
|
, int button1
|
|
|
|
, int button2 )
|
|
|
|
{
|
|
|
|
int reply;
|
2017-08-12 22:55:29 +02:00
|
|
|
FMessageBox* mbox;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
mbox = new FMessageBox ( caption
|
2017-09-20 02:51:17 +02:00
|
|
|
, FString() << num
|
2017-08-12 22:55:29 +02:00
|
|
|
, button0, button1, button2
|
|
|
|
, parent );
|
|
|
|
}
|
|
|
|
catch (const std::bad_alloc& ex)
|
|
|
|
{
|
|
|
|
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
|
|
|
|
return FDialog::Reject;
|
|
|
|
}
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
reply = mbox->exec();
|
|
|
|
delete mbox;
|
|
|
|
return reply;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
int FMessageBox::error ( FWidget* parent
|
|
|
|
, const FString& message
|
|
|
|
, int button0
|
|
|
|
, int button1
|
|
|
|
, int button2 )
|
|
|
|
{
|
|
|
|
int reply;
|
2017-03-26 20:40:04 +02:00
|
|
|
const FString& caption = "Error message";
|
2017-08-12 22:55:29 +02:00
|
|
|
FMessageBox* mbox;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
mbox = new FMessageBox ( caption, message
|
|
|
|
, button0, button1, button2
|
|
|
|
, parent );
|
|
|
|
}
|
|
|
|
catch (const std::bad_alloc& ex)
|
|
|
|
{
|
|
|
|
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
|
|
|
|
return FDialog::Reject;
|
|
|
|
}
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
mbox->beep();
|
|
|
|
mbox->setHeadline("Warning:");
|
|
|
|
mbox->setCenterText();
|
|
|
|
mbox->setForegroundColor(mbox->wc.error_box_fg);
|
|
|
|
mbox->setBackgroundColor(mbox->wc.error_box_bg);
|
|
|
|
mbox->emphasis_color = mbox->wc.error_box_emphasis_fg;
|
|
|
|
reply = mbox->exec();
|
|
|
|
delete mbox;
|
|
|
|
return reply;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// protected methods of FMessageBox
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FMessageBox::adjustSize()
|
|
|
|
{
|
2017-10-02 07:32:33 +02:00
|
|
|
int X
|
|
|
|
, Y
|
|
|
|
, max_width
|
|
|
|
, max_height;
|
2016-11-02 00:37:58 +01:00
|
|
|
FWidget* root_widget = getRootWidget();
|
|
|
|
|
|
|
|
if ( root_widget )
|
|
|
|
{
|
|
|
|
max_width = root_widget->getClientWidth();
|
|
|
|
max_height = root_widget->getClientHeight();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-07-03 16:56:32 +02:00
|
|
|
// fallback to xterm default size
|
2016-11-02 00:37:58 +01:00
|
|
|
max_width = 80;
|
|
|
|
max_height = 24;
|
|
|
|
}
|
|
|
|
|
2017-08-27 09:50:30 +02:00
|
|
|
X = 1 + int((max_width - getWidth()) / 2);
|
|
|
|
Y = 1 + int((max_height - getHeight()) / 3);
|
2016-11-02 00:37:58 +01:00
|
|
|
setPos(X, Y, false);
|
|
|
|
FDialog::adjustSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-02-24 00:30:07 +01:00
|
|
|
void FMessageBox::cb_processClick (FWidget*, data_ptr data)
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2017-02-24 00:30:07 +01:00
|
|
|
int* reply = static_cast<int*>(data);
|
2016-11-02 00:37:58 +01:00
|
|
|
done (*reply);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
// private methods of FMessageBox
|
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FMessageBox::init (int button0, int button1, int button2)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-09-27 00:46:05 +02:00
|
|
|
calculateDimensions();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
if ( (button2 && ! button1) || (button1 && ! button0) )
|
|
|
|
{
|
|
|
|
button0 = button1 = button2 = 0;
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( button0 == 0 )
|
|
|
|
button0 = FMessageBox::Ok;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( button1 == 0 && button2 == 0 )
|
2016-09-27 00:46:05 +02:00
|
|
|
num_buttons = 1;
|
2015-05-23 13:35:12 +02:00
|
|
|
else if ( button2 == 0 )
|
2016-09-27 00:46:05 +02:00
|
|
|
num_buttons = 2;
|
2015-05-23 13:35:12 +02:00
|
|
|
else
|
2016-09-27 00:46:05 +02:00
|
|
|
num_buttons = 3;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-08-12 20:10:27 +02:00
|
|
|
button_digit[0] = button0;
|
|
|
|
button_digit[1] = button1;
|
|
|
|
button_digit[2] = button2;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2018-01-31 23:37:03 +01:00
|
|
|
allocation (button0, button1, button2);
|
|
|
|
resizeButtons();
|
|
|
|
adjustButtons();
|
|
|
|
initCallbacks();
|
|
|
|
setModal();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FMessageBox::allocation (int button0, int button1, int button2)
|
|
|
|
{
|
2017-08-12 22:55:29 +02:00
|
|
|
try
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2017-08-12 22:55:29 +02:00
|
|
|
button[0] = new FButton (this);
|
|
|
|
button[0]->setText(button_text[button0]);
|
2017-08-27 09:50:30 +02:00
|
|
|
button[0]->setPos(3, getHeight() - 4, false);
|
2017-08-12 22:55:29 +02:00
|
|
|
button[0]->setWidth(1, false);
|
|
|
|
button[0]->setHeight(1, false);
|
|
|
|
button[0]->setFocus();
|
|
|
|
|
|
|
|
if ( button1 > 0 )
|
|
|
|
{
|
|
|
|
button[1] = new FButton(this);
|
|
|
|
button[1]->setText(button_text[button1]);
|
2017-08-27 09:50:30 +02:00
|
|
|
button[1]->setPos(17, getHeight() - 4, false);
|
2017-08-12 22:55:29 +02:00
|
|
|
button[1]->setWidth(0, false);
|
|
|
|
button[1]->setHeight(1, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( button2 > 0 )
|
|
|
|
{
|
|
|
|
button[2] = new FButton(this);
|
|
|
|
button[2]->setText(button_text[button2]);
|
2017-08-27 09:50:30 +02:00
|
|
|
button[2]->setPos(32, getHeight() - 4, false);
|
2017-08-12 22:55:29 +02:00
|
|
|
button[2]->setWidth(0, false);
|
|
|
|
button[2]->setHeight(1, false);
|
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
2017-08-12 22:55:29 +02:00
|
|
|
catch (const std::bad_alloc& ex)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2017-08-12 22:55:29 +02:00
|
|
|
std::cerr << "not enough memory to alloc " << ex.what() << std::endl;
|
|
|
|
return;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
2018-01-31 23:37:03 +01:00
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2018-01-31 23:37:03 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FMessageBox::deallocation()
|
|
|
|
{
|
|
|
|
for (uInt n = 0; n < num_buttons; n++)
|
|
|
|
delete button[n];
|
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2018-01-31 23:37:03 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FMessageBox::initCallbacks()
|
|
|
|
{
|
2017-08-12 20:10:27 +02:00
|
|
|
if ( button_digit[0] != 0 )
|
2016-07-09 00:01:59 +02:00
|
|
|
{
|
2015-05-23 13:35:12 +02:00
|
|
|
button[0]->addCallback
|
|
|
|
(
|
|
|
|
"clicked",
|
2017-04-09 20:08:53 +02:00
|
|
|
F_METHOD_CALLBACK (this, &FMessageBox::cb_processClick),
|
2017-08-12 20:10:27 +02:00
|
|
|
static_cast<FWidget::data_ptr>(&button_digit[0])
|
2015-05-23 13:35:12 +02:00
|
|
|
);
|
2016-07-09 00:01:59 +02:00
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-08-12 20:10:27 +02:00
|
|
|
if ( button_digit[1] != 0 )
|
2016-07-09 00:01:59 +02:00
|
|
|
{
|
2015-05-23 13:35:12 +02:00
|
|
|
button[1]->addCallback
|
|
|
|
(
|
|
|
|
"clicked",
|
2017-04-09 20:08:53 +02:00
|
|
|
F_METHOD_CALLBACK (this, &FMessageBox::cb_processClick),
|
2017-08-12 20:10:27 +02:00
|
|
|
static_cast<FWidget::data_ptr>(&button_digit[1])
|
2015-05-23 13:35:12 +02:00
|
|
|
);
|
2016-07-09 00:01:59 +02:00
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-08-12 20:10:27 +02:00
|
|
|
if ( button_digit[2] != 0 )
|
2016-07-09 00:01:59 +02:00
|
|
|
{
|
2015-05-23 13:35:12 +02:00
|
|
|
button[2]->addCallback
|
|
|
|
(
|
|
|
|
"clicked",
|
2017-04-09 20:08:53 +02:00
|
|
|
F_METHOD_CALLBACK (this, &FMessageBox::cb_processClick),
|
2017-08-12 20:10:27 +02:00
|
|
|
static_cast<FWidget::data_ptr>(&button_digit[2])
|
2015-05-23 13:35:12 +02:00
|
|
|
);
|
2016-07-09 00:01:59 +02:00
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2016-09-27 00:46:05 +02:00
|
|
|
void FMessageBox::calculateDimensions()
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
|
|
|
int x, y, w, h;
|
|
|
|
int headline_height = 0;
|
2016-08-21 21:27:44 +02:00
|
|
|
FWidget* parent_widget = getParentWidget();
|
2015-05-23 13:35:12 +02:00
|
|
|
text_split = text.split("\n");
|
|
|
|
text_num_lines = uInt(text_split.size());
|
|
|
|
text_components = &text_split[0];
|
2016-09-27 00:46:05 +02:00
|
|
|
max_line_width = 0;
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
if ( ! headline_text.isNull() )
|
|
|
|
headline_height = 2;
|
|
|
|
|
2017-08-27 09:50:30 +02:00
|
|
|
for (uInt i = 0; i < text_num_lines; i++)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
|
|
|
uInt len = text_components[i].getLength();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-09-27 00:46:05 +02:00
|
|
|
if ( len > max_line_width )
|
|
|
|
max_line_width = len;
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
h = int(text_num_lines) + 8 + headline_height;
|
2016-09-27 00:46:05 +02:00
|
|
|
w = int(max_line_width + 4);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( w < 20 )
|
|
|
|
w = 20;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-08-21 21:27:44 +02:00
|
|
|
if ( parent_widget )
|
|
|
|
{
|
2017-08-27 09:50:30 +02:00
|
|
|
x = 1 + int((parent_widget->getWidth() - w) / 2);
|
|
|
|
y = 1 + int((parent_widget->getHeight() - h) / 3);
|
2016-08-21 21:27:44 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
x = y = 1;
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
setGeometry (x, y, w, h);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FMessageBox::draw()
|
|
|
|
{
|
|
|
|
FDialog::draw();
|
|
|
|
|
|
|
|
int head_offset = 0;
|
|
|
|
int center_x = 0;
|
2017-09-11 03:06:02 +02:00
|
|
|
// center the whole block
|
|
|
|
int msg_x = int((getWidth() - int(max_line_width)) / 2);
|
2015-10-11 21:56:16 +02:00
|
|
|
|
|
|
|
if ( isMonochron() )
|
|
|
|
setReverse(true);
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( ! headline_text.isNull() )
|
|
|
|
{
|
2016-09-25 23:53:48 +02:00
|
|
|
setColor(emphasis_color, getBackgroundColor());
|
2015-05-23 13:35:12 +02:00
|
|
|
uInt headline_length = headline_text.getLength();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( center_text ) // center one line
|
2016-09-27 00:46:05 +02:00
|
|
|
center_x = int((max_line_width - headline_length) / 2);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-10-11 04:57:36 +02:00
|
|
|
setPrintPos (1 + msg_x + center_x, 4);
|
2015-05-23 13:35:12 +02:00
|
|
|
print (headline_text);
|
|
|
|
head_offset = 2;
|
|
|
|
}
|
|
|
|
|
2016-09-25 23:53:48 +02:00
|
|
|
setColor();
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-08-27 09:50:30 +02:00
|
|
|
for (int i = 0; i < int(text_num_lines); i++)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
|
|
|
uInt line_length = text_components[i].getLength();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( center_text ) // center one line
|
2016-09-27 00:46:05 +02:00
|
|
|
center_x = int((max_line_width - line_length) / 2);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-10-11 04:57:36 +02:00
|
|
|
setPrintPos (1 + msg_x + center_x, 4 + head_offset + i);
|
2015-05-23 13:35:12 +02:00
|
|
|
print(text_components[i]);
|
|
|
|
}
|
2015-10-11 21:56:16 +02:00
|
|
|
|
|
|
|
if ( isMonochron() )
|
|
|
|
setReverse(false);
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FMessageBox::resizeButtons()
|
|
|
|
{
|
|
|
|
uInt len[3], max_size;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-08-27 09:50:30 +02:00
|
|
|
for (uInt n = 0; n < num_buttons; n++)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
|
|
|
len[n] = button[n]->getText().getLength();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( button[n]->getText().includes('&') )
|
|
|
|
len[n]--;
|
|
|
|
}
|
|
|
|
|
2016-09-27 00:46:05 +02:00
|
|
|
if ( num_buttons == 1 )
|
2015-05-23 13:35:12 +02:00
|
|
|
max_size = len[0];
|
|
|
|
else
|
|
|
|
{
|
2016-09-27 00:46:05 +02:00
|
|
|
assert ( num_buttons > 1 );
|
2015-05-23 13:35:12 +02:00
|
|
|
max_size = std::max(len[0], len[1]);
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-09-27 00:46:05 +02:00
|
|
|
if ( num_buttons == 3 )
|
2015-05-23 13:35:12 +02:00
|
|
|
max_size = std::max(max_size, len[2]);
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
if ( max_size < 7 )
|
|
|
|
max_size = 7;
|
|
|
|
|
2017-08-27 09:50:30 +02:00
|
|
|
for (uInt n = 0; n < num_buttons; n++)
|
2015-05-23 13:35:12 +02:00
|
|
|
button[n]->setWidth(int(max_size + 3), false);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FMessageBox::adjustButtons()
|
|
|
|
{
|
2017-07-03 16:56:32 +02:00
|
|
|
static const int gap = 4;
|
|
|
|
int btn_width = 0;
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2017-08-27 09:50:30 +02:00
|
|
|
for (uInt n = 0; n < num_buttons; n++)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2017-08-27 09:50:30 +02:00
|
|
|
if ( n == num_buttons - 1 )
|
2015-05-23 13:35:12 +02:00
|
|
|
btn_width += button[n]->getWidth();
|
|
|
|
else
|
|
|
|
btn_width += button[n]->getWidth() + gap;
|
|
|
|
}
|
|
|
|
|
2017-08-27 09:50:30 +02:00
|
|
|
if ( btn_width >= getWidth() - 4 )
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
2016-08-21 21:27:44 +02:00
|
|
|
int max_width;
|
|
|
|
FWidget* root_widget = getRootWidget();
|
2015-05-23 13:35:12 +02:00
|
|
|
setWidth(btn_width + 5);
|
2016-08-21 21:27:44 +02:00
|
|
|
max_width = ( root_widget ) ? root_widget->getClientWidth() : 80;
|
2017-08-27 09:50:30 +02:00
|
|
|
setX (int((max_width - getWidth()) / 2));
|
2015-05-23 13:35:12 +02:00
|
|
|
}
|
|
|
|
|
2017-08-27 09:50:30 +02:00
|
|
|
int btn_x = int((getWidth() - btn_width) / 2);
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-08-27 09:50:30 +02:00
|
|
|
for (uInt n = 0; n < num_buttons; n++)
|
2015-05-23 13:35:12 +02:00
|
|
|
{
|
|
|
|
if ( n == 0 )
|
|
|
|
button[n]->setX(btn_x);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int btn_size = button[n]->getWidth();
|
|
|
|
button[n]->setX( btn_x + int(n) * (btn_size + gap) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|