CMsgBox: rework msgbox classes with Window class implementation

Replacing messagebox, hintbox_ext and some derivated parts with
basic class hintbox and derivated class CMsgBox. This should unify
window handling and avoids maintain of multiple classes with quasi
same purpose and adds more functionality.

TODO: fix and optimize details


Origin commit data
------------------
Branch: ni/coolstream
Commit: dde298b1b7
Author: Thilo Graf <dbt@novatux.de>
Date: 2016-04-04 (Mon, 04 Apr 2016)



------------------
This commit was generated by Migit
This commit is contained in:
2016-04-04 21:57:17 +02:00
parent 07f447e0f9
commit 36d8d81fa6
81 changed files with 1981 additions and 1697 deletions

View File

@@ -1,170 +1,272 @@
/*
Neutrino-GUI - DBoxII-Project
Based up Neutrino-GUI - Tuxbox-Project
Copyright (C) 2001 by Steffen Hehn 'McClean
Homepage: http://dbox.cyberphoria.org/
Kommentar:
Diese GUI wurde von Grund auf neu programmiert und sollte nun vom
Aufbau und auch den Ausbaumoeglichkeiten gut aussehen. Neutrino basiert
auf der Client-Server Idee, diese GUI ist also von der direkten DBox-
Steuerung getrennt. Diese wird dann von Daemons uebernommen.
Initial implementation as an interface of the CMsgBox class
Copyright (C) 2005 Günther
Günther@tuxbox.berlios.org
Implementation of CComponent Window class.
Copyright (C) 2014-2015 Thilo Graf 'dbt'
License: GPL
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This program 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 General Public License for more details.
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
***********************************************************
Module Name: msgbox.h .
Description: interface of the CMsgBox class
Date: Nov 2005
Author: Günther@tuxbox.berlios.org
based on code of Steffen Hehn 'McClean'
Revision History:
Date Author Change Description
Nov 2005 Günther initial implementation
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#if !defined(MSGBOX_H)
#define MSGBOX_H
#ifndef __C_MSGBOX__
#define __C_MSGBOX__
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <string>
#include "textbox.h"
#include "hintbox.h"
#include <gui/widget/drawable.h>
#include <driver/fb_window.h>
#define MSGBOX_MIN_WIDTH HINTBOX_MIN_WIDTH
#define MSGBOX_MIN_HEIGHT HINTBOX_MIN_HEIGHT + 75
class CMsgBox
//! Sub class of CHintBox. Shows a window as a messagebox
/*!
CMsgBox provides a small window with header, text and footer
with predefined buttons.
Optional you can add an icon in the header and/or beside left of
text and context buttons on the right site of header.
CMsgBox objects return predefined result values of type msg_result_t.
Button combinations are defined with button_define_t
*/
class CMsgBox : public CHintBox
{
public:
/* enum definition */
enum result_
enum msg_result_t
{
mbrYes = 0,
mbrNo = 1,
mbrCancel = 2,
mbrBack = 3
mbrBack = 3,
mbrOk = 4,
mbrTimeout = 5,
mbrNone = -1
};
enum buttons_
enum button_define_t
{
mbYes = 0x01,
mbNo = 0x02,
mbCancel = 0x04,
mbAll = 0x07,
mbBack = 0x08
mbYes = 0x01,
mbNo = 0x02,
mbCancel = 0x04,
mbBack = 0x08,
mbOk = 0x10,
mbOKCancel = 0x20,
mbYesNoCancel = 0x40,
mbYesNo = 0x80,
mbAll = 0x100,
//unused allign stuff, only for compatibility
mbBtnAlignCenter1 = 0x0400, /* centered, large distances */
mbBtnAlignCenter2 = 0x0800, /* centered, small distances */
mbBtnAlignLeft = 0x1000,
mbBtnAlignRight = 0x2000
};
enum modes
enum modes //TODO
{
AUTO_WIDTH = 0x01,
AUTO_HIGH = 0x02,
SCROLL = 0x04,
TITLE = 0x08,
FOOT = 0x10,
BORDER = 0x20,
CENTER = 0x40,
NO_AUTO_LINEBREAK= 0x80
AUTO_WIDTH = CTextBox::AUTO_WIDTH,
AUTO_HIGH = CTextBox::AUTO_HIGH,
SCROLL = CTextBox::SCROLL,
// TITLE = 0x08,
// FOOT = 0x10,
// BORDER = 0x20,
CENTER = CTextBox::CENTER,
NO_AUTO_LINEBREAK = CTextBox::NO_AUTO_LINEBREAK
};
private:
/* Functions */
void initVar(void);
void initFramesRel(void);
void init(const int& Height = -1, const int& ShowButtons = -1, const msg_result_t& Default_result = mbrNone);
void refreshFoot(void);
void refreshTitle(void);
void refreshText(void);
void refreshBorder(void);
int mb_show_button;
/* Variables */
std::string m_cIcon;
std::string m_cTitle;
///current result value of selected button, see also getResult()
msg_result_t result;
///defined default result, independently from current selected button result, see also setDefaultResult(), getDefaultResult()
msg_result_t default_result;
///enable/disable default result on timeout
bool enable_timeout_result;
///initialize basic timeout
void initTimeOut();
CBox m_cBoxFrame;
CBox m_cBoxFrameText;
CBox m_cBoxFrameTitleRel;
CBox m_cBoxFrameFootRel;
///alternate button text
std::string btn_text_ok, btn_text_yes, btn_text_no, btn_text_cancel, btn_text_back;
///assigned button captions
std::string BTN_TEXT(const int& showed_button);
int m_nMode;
int m_nWindowFrameBorderWidth;
Font* m_pcFontTitle;
int m_nFontTitleHeight;
Font* m_pcFontFoot;
int m_nFontFootHeight;
int m_nFootButtons;
CTextBox* m_pcTextBox;
//CFBWindow* m_pcWindow;
CFrameBuffer * m_pcWindow;
result_ m_nResult;
void initButtons();
public:
/* Constructor */
virtual ~CMsgBox();
CMsgBox();
CMsgBox(const char * text);
CMsgBox( const char * text,
Font* fontText,
const int mode,
const CBox* position,
const char * title,
Font* fontTitle,
const char * icon,
int return_button = mbCancel,
const result_ default_result = mbrCancel);
CMsgBox(const char* Text,
const char* Title = NULL,
const char* Icon = NULL,
const char* Picon = NULL,
const int& Width = MSGBOX_MIN_WIDTH,
const int& Height = MSGBOX_MIN_HEIGHT,
const int& ShowButtons = mbCancel,
const msg_result_t& Default_result = mbrCancel,
const int& Text_mode = CMsgBox::CENTER | CTextBox::AUTO_WIDTH | CTextBox::AUTO_HIGH | CTextBox::SCROLL);
/* Functions */
bool paint(void);
bool hide(void);
int exec(int timeout,int returnDefaultOnTimeout = false);
void refresh(void);
void scrollPageDown(const int pages);
void scrollPageUp(const int pages);
int result(void);
CMsgBox(const char* Text,
const neutrino_locale_t locale_Title = NONEXISTANT_LOCALE,
const char* Icon = NULL,
const char* Picon = NULL,
const int& Width = MSGBOX_MIN_WIDTH,
const int& Height = MSGBOX_MIN_HEIGHT,
const int& ShowButtons = mbCancel,
const msg_result_t& Default_result = mbrCancel,
const int& Text_mode = CMsgBox::CENTER | CTextBox::AUTO_WIDTH | CTextBox::AUTO_HIGH | CTextBox::SCROLL);
bool setText(const std::string* newText);
// ~CMsgBox(); //inherited
int exec();
///returns current result as msg_result_t, result corresponds to the current result value of selected button
msg_result_t getResult(){return result;};
///returns current default result as msg_result_t, independently from current selected button result
msg_result_t getDefaultResult(){return default_result;};
///sets current default result as msg_result_t, independently from current selected button result
void setDefaultResult(const msg_result_t& Default_result){default_result = Default_result;}
/*!
Sets the displayed buttons.
This member allows to set and overrides already defined buttons from constructor,
parameter ''ShowButtons'' accepts given types, find under button_define_t enumeration
mbYes
mbNo
mbCancel
mbBack
mbOk
mbOKCancel
mbYesNoCancel
mbYesNo
mbAll
*/
void setShowedButtons(const int& ShowButtons){mb_show_button = ShowButtons; initButtons();}
///define timeout, timeout is enabled if parmeter 1 > -1, otherwise it will be disabled,
void setTimeOut(const int& Timeout){timeout = Timeout;};
///enable/disable defined timeout, otherwise it will be ignored, parameter 1: bool default = true
void enableDefaultResultOnTimeOut(bool enable = true);
/*!
Default defined button text is already predefiend with parameter 'ShowButtons' from constructor.
This member allows to define an alternate text for an already defined button,
1st parameter ''showed button'' accepts
mbYes
mbNo
mbCancel
mbBack
mbOk
others will be ignored!
2nd parameter sets the new text for button as std::string.
Result values are not touched!
*/
void setButtonText(const int& showed_button, const std::string& text);
// bool setText(const std::string* newText);
};
extern int ShowMsg2UTF( const neutrino_locale_t Caption,
#define DEFAULT_TEXT_MODE (CMsgBox::CENTER | CMsgBox::AUTO_WIDTH | CMsgBox::AUTO_HIGH)
int ShowMsg2UTF( const neutrino_locale_t Title,
const char * const Text,
const CMsgBox::result_ Default,
const CMsgBox::msg_result_t Default,
const uint32_t ShowButtons,
const char * const Icon = NULL,
const int Width = 450,
const int timeout = -1,
bool returnDefaultOnTimeout = false); // UTF-8
const int Width = MSGBOX_MIN_WIDTH,
const int Timeout = -1,
bool returnDefaultOnTimeout = false,
const int& Text_mode = DEFAULT_TEXT_MODE,
fb_pixel_t color_frame = HINTBOX_DEFAULT_FRAME_COLOR); // UTF-8
extern int ShowMsg2UTF( const char * const Title,
int ShowMsg2UTF( const char * const Title,
const char * const Text,
const CMsgBox::result_ Default,
const CMsgBox::msg_result_t Default,
const uint32_t ShowButtons,
const char * const Icon = NULL,
const int Width = 450,
const int timeout = -1,
bool returnDefaultOnTimeout = false); // UTF-8
const int Width = MSGBOX_MIN_WIDTH,
const int Timeout = -1,
bool returnDefaultOnTimeout = false,
const int& Text_mode = DEFAULT_TEXT_MODE,
fb_pixel_t color_frame = HINTBOX_DEFAULT_FRAME_COLOR); // UTF-8
int ShowMsg( const neutrino_locale_t Title,
const char * const Text,
const CMsgBox::msg_result_t Default,
const uint32_t ShowButtons,
const char * const Icon = NULL,
const int Width = MSGBOX_MIN_WIDTH,
const int Timeout = -1,
bool returnDefaultOnTimeout = false,
const int& Text_mode = DEFAULT_TEXT_MODE,
fb_pixel_t color_frame = HINTBOX_DEFAULT_FRAME_COLOR); // UTF-8
int ShowMsg( const char * const Title,
const char * const Text,
const CMsgBox::msg_result_t Default,
const uint32_t ShowButtons,
const char * const Icon = NULL,
const int Width = MSGBOX_MIN_WIDTH,
const int Timeout = -1,
bool returnDefaultOnTimeout = false,
const int& Text_mode = DEFAULT_TEXT_MODE,
fb_pixel_t color_frame = HINTBOX_DEFAULT_FRAME_COLOR); // UTF-8
int ShowMsg( const neutrino_locale_t Title,
const std::string & Text,
const CMsgBox::msg_result_t Default,
const uint32_t ShowButtons,
const char * const Icon = NULL,
const int Width = MSGBOX_MIN_WIDTH,
const int Timeout = -1,
bool returnDefaultOnTimeout = false,
const int& Text_mode = DEFAULT_TEXT_MODE,
fb_pixel_t color_frame = HINTBOX_DEFAULT_FRAME_COLOR); // UTF-8
int ShowMsg( const neutrino_locale_t Title,
const neutrino_locale_t Text,
const CMsgBox::msg_result_t Default,
const uint32_t ShowButtons,
const char * const Icon = NULL,
const int Width = MSGBOX_MIN_WIDTH,
const int Timeout = -1,
bool returnDefaultOnTimeout = false,
const int& Text_mode = DEFAULT_TEXT_MODE,
fb_pixel_t color_frame = HINTBOX_DEFAULT_FRAME_COLOR); // UTF-8
int ShowMsg( const std::string & Title,
const std::string & Text,
const CMsgBox::msg_result_t Default,
const uint32_t ShowButtons,
const char * const Icon = NULL,
const int Width = MSGBOX_MIN_WIDTH,
const int Timeout = -1,
bool returnDefaultOnTimeout = false,
const int& Text_mode = DEFAULT_TEXT_MODE,
fb_pixel_t color_frame = HINTBOX_DEFAULT_FRAME_COLOR); // UTF-8
void DisplayErrorMessage(const char * const ErrorMsg, const int& Text_mode = DEFAULT_TEXT_MODE); // UTF-8
void DisplayErrorMessage(const char * const ErrorMsg, const neutrino_locale_t& caption, const int& Text_mode = DEFAULT_TEXT_MODE); // UTF-8
void DisplayErrorMessage(const char * const ErrorMsg, const std::string& caption, const int& Text_mode = DEFAULT_TEXT_MODE); // UTF-8
void DisplayInfoMessage(const char * const InfoMsg, const int& Text_mode = DEFAULT_TEXT_MODE, fb_pixel_t color_frame = COL_DARK_GRAY); // UTF-8
void DisplayInfoMessage(const char * const InfoMsg, const neutrino_locale_t& caption, const int& Text_mode = DEFAULT_TEXT_MODE, fb_pixel_t color_frame = COL_DARK_GRAY); // UTF-8
void DisplayInfoMessage(const char * const InfoMsg, const std::string& caption, const int& Text_mode = DEFAULT_TEXT_MODE, fb_pixel_t color_frame = COL_DARK_GRAY); // UTF-8
#endif