ui_node_option.c
Go to the documentation of this file.00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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"
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
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 }