ui_node_option.c

Go to the documentation of this file.
00001 
00005 /*
00006 Copyright (C) 2002-2010 UFO: Alien Invasion.
00007 
00008 This program is free software; you can redistribute it and/or
00009 modify it under the terms of the GNU General Public License
00010 as published by the Free Software Foundation; either version 2
00011 of the License, or (at your option) any later version.
00012 
00013 This program is distributed in the hope that it will be useful,
00014 but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00016 
00017 See the GNU General Public License for more details.
00018 
00019 You should have received a copy of the GNU General Public License
00020 along with this program; if not, write to the Free Software
00021 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 
00023 */
00024 
00025 #include "../ui_main.h"
00026 #include "../ui_parse.h"
00027 #include "ui_node_abstractnode.h"
00028 #include "ui_node_option.h"
00029 
00030 #include "../../client.h" /* gettext _() */
00031 
00035 const uiBehaviour_t *ui_optionBehaviour = NULL;
00036 
00037 #define EXTRADATA_TYPE optionExtraData_t
00038 #define EXTRADATA(node) UI_EXTRADATA(node, EXTRADATA_TYPE)
00039 #define EXTRADATACONST(node) UI_EXTRADATACONST(node, EXTRADATA_TYPE)
00040 
00041 static const value_t *propertyCollapsed;
00042 
00043 
00049 int UI_OptionUpdateCache (uiNode_t* option)
00050 {
00051     int count = 0;
00052     while (option) {
00053         int localCount = 0;
00054         assert(option->behaviour == ui_optionBehaviour);
00055         if (option->invis) {
00056             option = option->next;
00057             continue;
00058         }
00059         if (OPTIONEXTRADATA(option).collapsed) {
00060             OPTIONEXTRADATA(option).childCount = 0;
00061             option = option->next;
00062             count++;
00063             continue;
00064         }
00065         if (option->firstChild)
00066             localCount = UI_OptionUpdateCache(option->firstChild);
00067         OPTIONEXTRADATA(option).childCount = localCount;
00068         count += 1 + localCount;
00069         option = option->next;
00070     }
00071     return count;
00072 }
00073 
00074 static void UI_OptionDoLayout (uiNode_t *node) {
00075     uiNode_t *child = node->firstChild;
00076     int count = 0;
00077 
00078     while(child && child->behaviour == ui_optionBehaviour) {
00079         UI_Validate(child);
00080         if (!child->invis) {
00081             if (EXTRADATA(child).collapsed)
00082                 count += 1 + EXTRADATA(child).childCount;
00083             else
00084                 count += 1;
00085         }
00086         child = child->next;
00087     }
00088     EXTRADATA(node).childCount = count;
00089     node->invalidated = qfalse;
00090 }
00091 
00092 static void UI_OptionPropertyChanged (uiNode_t *node, const value_t *property)
00093 {
00094     if (property == propertyCollapsed) {
00095         UI_Invalidate(node);
00096         return;
00097     }
00098     ui_optionBehaviour->super->propertyChanged(node, property);
00099 }
00100 
00102 static const value_t properties[] = {
00106     {"label", V_STRING, UI_EXTRADATA_OFFSETOF(EXTRADATA_TYPE, label), 0},
00107 
00111     {"value", V_STRING, UI_EXTRADATA_OFFSETOF(EXTRADATA_TYPE, value), 0},
00112 
00116     {"collapsed", V_BOOL, UI_EXTRADATA_OFFSETOF(EXTRADATA_TYPE, collapsed), MEMBER_SIZEOF(EXTRADATA_TYPE, collapsed)},
00117 
00118     /* Icon used to display the node
00119      */
00120     {"icon", V_UI_ICONREF, UI_EXTRADATA_OFFSETOF(EXTRADATA_TYPE, icon), MEMBER_SIZEOF(EXTRADATA_TYPE, icon)},
00121 
00122     {NULL, V_NULL, 0, 0},
00123 };
00124 
00125 void UI_RegisterOptionNode (uiBehaviour_t *behaviour)
00126 {
00127     behaviour->name = "option";
00128     behaviour->properties = properties;
00129     behaviour->extraDataSize = sizeof(EXTRADATA_TYPE);
00130     behaviour->doLayout = UI_OptionDoLayout;
00131     behaviour->propertyChanged = UI_OptionPropertyChanged;
00132 
00133     propertyCollapsed = UI_GetPropertyFromBehaviour(behaviour, "collapsed");
00134 
00135     ui_optionBehaviour = behaviour;
00136 }

Generated by  doxygen 1.6.2