From 5ae495716e752ab5edeea0ce118dba255399a41b Mon Sep 17 00:00:00 2001 From: Thilo Graf Date: Tue, 26 Aug 2014 23:05:49 +0200 Subject: [PATCH] CComponentsFooter: expand button label structs Allows assigning of result, msg and alias values with label struct. NOTE: Old button label struct are compatible but limited only and not recommended for usage! Old parameters 'struct button_label' doesn't provide newer parameters. Missing parameters are filled with default values and must be assigned afterward, if required. --- src/gui/components/cc_frm_footer.cpp | 40 +++++++++++++++++++++++++--- src/gui/components/cc_frm_footer.h | 26 +++++++++++++----- 2 files changed, 55 insertions(+), 11 deletions(-) diff --git a/src/gui/components/cc_frm_footer.cpp b/src/gui/components/cc_frm_footer.cpp index ee60bf084..8769b1013 100644 --- a/src/gui/components/cc_frm_footer.cpp +++ b/src/gui/components/cc_frm_footer.cpp @@ -141,6 +141,9 @@ void CComponentsFooter::setButtonLabels(const struct button_label_s * const cont CComponentsButton *btn = new CComponentsButton(0, CC_CENTERED, w_btn_min, height-height/4, txt, btn_name); btn->setButtonFont(ccf_btn_font); btn->doPaintBg(btn_contour); + btn->setButtonEventMsg(content[i].btn_msg); + btn->setButtonResult(content[i].btn_result); + btn->setButtonAlias(content[i].btn_alias); if (btn_name == NEUTRINO_ICON_BUTTON_RED) btn->setColorFrame(COL_DARK_RED); @@ -187,6 +190,9 @@ void CComponentsFooter::setButtonLabels(const struct button_label_l * const cont for (size_t i= 0; i< label_count; i++){ buttons[i].button = content[i].button; buttons[i].text = content[i].locale != NONEXISTANT_LOCALE ? g_Locale->getText(content[i].locale) : ""; + buttons[i].btn_msg = content[i].btn_msg; + buttons[i].btn_result = content[i].btn_result; + buttons[i].btn_alias = content[i].btn_alias; } setButtonLabels(buttons, label_count, chain_width, label_width); @@ -194,7 +200,18 @@ void CComponentsFooter::setButtonLabels(const struct button_label_l * const cont void CComponentsFooter::setButtonLabels(const struct button_label * const content, const size_t& label_count, const int& chain_width, const int& label_width) { - setButtonLabels((button_label_l*)content, label_count, chain_width, label_width); + //conversion for compatibility with older paintButtons() methode, find in /gui/widget/buttons.h + button_label_l buttons[label_count]; + for (size_t i = 0; i< label_count; i++){ + buttons[i].button = content[i].button; + buttons[i].locale = content[i].locale; + //NOTE: here are used default values, because old button label struct don't know about this, + //if it possible, don't use this methode! + buttons[i].btn_msg = CRCInput::RC_nokey; + buttons[i].btn_result = -1; + buttons[i].btn_alias = -1; + } + setButtonLabels(buttons, label_count, chain_width, label_width); } void CComponentsFooter::setButtonLabels(const vectorv_content, const int& chain_width, const int& label_width) @@ -205,6 +222,9 @@ void CComponentsFooter::setButtonLabels(const vectorv_content, c for (size_t i= 0; i< label_count; i++){ buttons[i].button = v_content[i].button; buttons[i].locale = v_content[i].locale; + buttons[i].btn_msg = v_content[i].btn_msg; + buttons[i].btn_result = v_content[i].btn_result; + buttons[i].btn_alias = v_content[i].btn_alias; } setButtonLabels(buttons, label_count, chain_width, label_width); @@ -218,26 +238,32 @@ void CComponentsFooter::setButtonLabels(const vectorv_content, c for (size_t i= 0; i< label_count; i++){ buttons[i].button = v_content[i].button; buttons[i].text = v_content[i].text; + buttons[i].btn_msg = v_content[i].btn_msg; + buttons[i].btn_result = v_content[i].btn_result; + buttons[i].btn_alias = v_content[i].btn_alias; } setButtonLabels(buttons, label_count, chain_width, label_width); } -void CComponentsFooter::setButtonLabel(const char *button_icon, const std::string& text, const int& chain_width, const int& label_width) +void CComponentsFooter::setButtonLabel(const char *button_icon, const std::string& text, const int& chain_width, const int& label_width, const neutrino_msg_t& msg, const int& result_value, const int& alias_value) { button_label_s button[1]; button[0].button = button_icon; button[0].text = text; + button[0].btn_msg = msg; + button[0].btn_result = result_value; + button[0].btn_alias = alias_value; setButtonLabels(button, 1, chain_width, label_width); } -void CComponentsFooter::setButtonLabel(const char *button_icon, const neutrino_locale_t& locale, const int& chain_width, const int& label_width) +void CComponentsFooter::setButtonLabel(const char *button_icon, const neutrino_locale_t& locale, const int& chain_width, const int& label_width, const neutrino_msg_t& msg, const int& result_value, const int& alias_value) { string txt = locale != NONEXISTANT_LOCALE ? g_Locale->getText(locale) : ""; - setButtonLabel(button_icon, txt, chain_width, label_width); + setButtonLabel(button_icon, txt, chain_width, label_width, msg, result_value, alias_value); } void CComponentsFooter::showButtonContour(bool show) @@ -264,6 +290,12 @@ int CComponentsFooter::getSelectedButton() return ret; } +CComponentsButton* CComponentsFooter::getSelectedButtonObject() +{ + CComponentsButton* ret = static_cast(chain->getSelectedItemObject()); + return ret; +} + void CComponentsFooter::paintButtons(const int& x_pos, const int& y_pos, diff --git a/src/gui/components/cc_frm_footer.h b/src/gui/components/cc_frm_footer.h index 01d93f6c1..2606a1cca 100644 --- a/src/gui/components/cc_frm_footer.h +++ b/src/gui/components/cc_frm_footer.h @@ -24,7 +24,6 @@ #ifndef __CC_FORM_FOOTER_H__ #define __CC_FORM_FOOTER_H__ - #include "cc_frm_header.h" #include "cc_frm_button.h" #include //for compatibility with 'button_label' type @@ -34,17 +33,28 @@ typedef struct button_label_s { const char * button; std::string text; + neutrino_msg_t btn_msg; + int btn_result; + int btn_alias; } button_label_s_struct; typedef struct button_label_l { - const char * button; - neutrino_locale_t locale; + const char * button; + neutrino_locale_t locale; + neutrino_msg_t btn_msg; + int btn_result; + int btn_alias; } button_label_l_struct; /*! CComponentsFooter, sub class of CComponentsHeader provides prepared container for footer -Is mostly usable like a header but without caption, and context button icons. +It's usable like a header but without caption, and context button icons as default. +Additional implemented is a button container (chain) and some methods which can add +buttons via struct, vector or text and icon parameters. Also a compatible but limited methode +to add button labels known by older button handler, to find in gui/widget/buttons.h/cpp. +functionality. Why limited ?: old parameter 'struct button_label' doesn't provide newer parameters. +Missing parameters are filled with default values and must be assigned afterward, if required. */ class CComponentsFooter : public CComponentsHeader { @@ -86,13 +96,13 @@ class CComponentsFooter : public CComponentsHeader void setButtonLabels(const std::vectorv_content, const int& chain_width, const int& label_width); ///add button labels with old label type, count as size_t, chain_width as int, label width as int - ///NOTE: for compatibility with older button handler find in gui/widget/buttons.h + ///NOTE: for compatibility with older button handler find in gui/widget/buttons.h, if possible, don't use this void setButtonLabels(const struct button_label * const content, const size_t& label_count, const int& chain_width = 0, const int& label_width = 0); ///add single button label with string label type as content, chain_width as int, label width as int - void setButtonLabel(const char *button_icon, const std::string& text, const int& chain_width = 0, const int& label_width = 0); + void setButtonLabel(const char *button_icon, const std::string& text, const int& chain_width = 0, const int& label_width = 0, const neutrino_msg_t& msg = CRCInput::RC_nokey, const int& result_value = -1, const int& alias_value = -1); ///add single button label with locale label type as content, chain_width as int, label width as int - void setButtonLabel(const char *button_icon, const neutrino_locale_t& locale, const int& chain_width = 0, const int& label_width = 0); + void setButtonLabel(const char *button_icon, const neutrino_locale_t& locale, const int& chain_width = 0, const int& label_width = 0, const neutrino_msg_t& msg = CRCInput::RC_nokey, const int& result_value = -1, const int& alias_value = -1); ///causes show/hide countour of button frame and background, parameter bool show, default= true void showButtonContour(bool show = true); @@ -101,6 +111,8 @@ class CComponentsFooter : public CComponentsHeader void setSelectedButton(size_t item_id); ///returns id of select button, return value as int, -1 = nothing is selected int getSelectedButton(); + ///returns selected button object, return value as pointer to object, NULL means nothing is selected + CComponentsButton* getSelectedButtonObject(); ///property: set font for label caption, parameter as font object, value NULL causes usage of dynamic font void setButtonFont(Font* font){ccf_btn_font = font;};