@@ -20,22 +20,64 @@ in the source distribution for its full text.
2020#include "ProvideCurses.h"
2121
2222
23- static const char * const DisplayOptionsFunctions [] = {" " , " " , " " , " " , " " , " " , " " , " " , " " , "Done " , NULL };
23+ static const char * const CheckboxDisplayOptionsFunctions [] = {"Select " , "Done " , NULL };
24+ static const char * const CheckboxDisplayOptionsKeys [] = {"Enter" , "F10" };
25+ static const int CheckboxDisplayOptionsEvents [] = {KEY_ENTER , KEY_F (10 )};
26+ static const char * const NumericDisplayOptionsFunctions [] = {"Decrement " , "Increment " , "Done " , NULL };
27+ static const char * const NumericDisplayOptionsKeys [] = {"-" , "+" , "F10" };
28+ static const int NumericDisplayOptionsEvents [] = {'-' , '+' , KEY_F (10 )};
2429
2530static void DisplayOptionsPanel_delete (Object * object ) {
2631 Panel * super = (Panel * ) object ;
2732 DisplayOptionsPanel * this = (DisplayOptionsPanel * ) object ;
33+ FunctionBar_delete (this -> numericFuBar );
34+ FunctionBar_delete (this -> checkboxFuBar );
2835 Panel_done (super );
2936 free (this );
3037}
3138
39+ static void DisplayOptionsPanel_setFunctionBar (DisplayOptionsPanel * this , OptionItem * item ) {
40+ Panel * super = (Panel * ) this ;
41+ switch (OptionItem_kind (item )) {
42+ case OPTION_ITEM_NUMBER : {
43+ super -> currentBar = this -> numericFuBar ;
44+ break ;
45+ }
46+ case OPTION_ITEM_CHECK : {
47+ super -> currentBar = this -> checkboxFuBar ;
48+ break ;
49+ }
50+ default : {
51+ super -> currentBar = this -> checkboxFuBar ;
52+ break ;
53+ }
54+ }
55+ FunctionBar_draw (super -> currentBar );
56+ }
57+
3258static HandlerResult DisplayOptionsPanel_eventHandler (Panel * super , int ch ) {
3359 DisplayOptionsPanel * this = (DisplayOptionsPanel * ) super ;
3460
3561 HandlerResult result = IGNORED ;
3662 OptionItem * selected = (OptionItem * ) Panel_getSelected (super );
3763
3864 switch (ch ) {
65+ case KEY_UP : {
66+ int selected_index = Panel_getSelectedIndex (super );
67+ if (selected_index > 1 ) {
68+ OptionItem * next_to_select = (OptionItem * ) Panel_get (super , selected_index - 1 );
69+ DisplayOptionsPanel_setFunctionBar (this , next_to_select );
70+ }
71+ break ;
72+ }
73+ case KEY_DOWN : {
74+ int selected_index = Panel_getSelectedIndex (super );
75+ if (selected_index < Panel_size (super ) - 1 ) {
76+ OptionItem * next_to_select = (OptionItem * ) Panel_get (super , selected_index + 1 );
77+ DisplayOptionsPanel_setFunctionBar (this , next_to_select );
78+ }
79+ break ;
80+ }
3981 case '\n' :
4082 case '\r' :
4183 case KEY_ENTER :
@@ -90,11 +132,15 @@ const PanelClass DisplayOptionsPanel_class = {
90132DisplayOptionsPanel * DisplayOptionsPanel_new (Settings * settings , ScreenManager * scr ) {
91133 DisplayOptionsPanel * this = AllocThis (DisplayOptionsPanel );
92134 Panel * super = (Panel * ) this ;
93- FunctionBar * fuBar = FunctionBar_new (DisplayOptionsFunctions , NULL , NULL );
94- Panel_init (super , 1 , 1 , 1 , 1 , Class (OptionItem ), true, fuBar );
135+ FunctionBar * checkboxFuBar = FunctionBar_new (CheckboxDisplayOptionsFunctions , CheckboxDisplayOptionsKeys , CheckboxDisplayOptionsEvents );
136+ FunctionBar * numericFuBar = FunctionBar_new (NumericDisplayOptionsFunctions , NumericDisplayOptionsKeys , NumericDisplayOptionsEvents );
137+ FunctionBar * emptyFuBar = FunctionBar_new (NULL , NULL , NULL );
138+ Panel_init (super , 1 , 1 , 1 , 1 , Class (OptionItem ), true, emptyFuBar );
95139
96140 this -> settings = settings ;
97141 this -> scr = scr ;
142+ this -> numericFuBar = numericFuBar ;
143+ this -> checkboxFuBar = checkboxFuBar ;
98144
99145 Panel_setHeader (super , "Display options" );
100146 Panel_add (super , (Object * ) CheckItem_newByRef ("Tree view" , & (settings -> treeView )));
@@ -141,5 +187,9 @@ DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager*
141187 #ifdef HAVE_LIBHWLOC
142188 Panel_add (super , (Object * ) CheckItem_newByRef ("Show topology when selecting affinity by default" , & (settings -> topologyAffinity )));
143189 #endif
190+
191+ OptionItem * defaultSelected = (OptionItem * ) Panel_getSelected (super );
192+ DisplayOptionsPanel_setFunctionBar (this , defaultSelected );
193+
144194 return this ;
145195}
0 commit comments