@@ -20,22 +20,60 @@ 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+ case OPTION_ITEM_CHECK :
46+ super -> currentBar = this -> checkboxFuBar ;
47+ break ;
48+ defaut :
49+ assert (0 ); // Unknown option type
50+ }
51+ FunctionBar_draw (super -> currentBar );
52+ }
53+
3254static HandlerResult DisplayOptionsPanel_eventHandler (Panel * super , int ch ) {
3355 DisplayOptionsPanel * this = (DisplayOptionsPanel * ) super ;
3456
3557 HandlerResult result = IGNORED ;
3658 OptionItem * selected = (OptionItem * ) Panel_getSelected (super );
3759
3860 switch (ch ) {
61+ case KEY_UP : {
62+ int selected_index = Panel_getSelectedIndex (super );
63+ if (selected_index > 1 ) {
64+ OptionItem * next_to_select = (OptionItem * ) Panel_get (super , selected_index - 1 );
65+ DisplayOptionsPanel_setFunctionBar (this , next_to_select );
66+ }
67+ break ;
68+ }
69+ case KEY_DOWN : {
70+ int selected_index = Panel_getSelectedIndex (super );
71+ if (selected_index < Panel_size (super ) - 1 ) {
72+ OptionItem * next_to_select = (OptionItem * ) Panel_get (super , selected_index + 1 );
73+ DisplayOptionsPanel_setFunctionBar (this , next_to_select );
74+ }
75+ break ;
76+ }
3977 case '\n' :
4078 case '\r' :
4179 case KEY_ENTER :
@@ -90,11 +128,15 @@ const PanelClass DisplayOptionsPanel_class = {
90128DisplayOptionsPanel * DisplayOptionsPanel_new (Settings * settings , ScreenManager * scr ) {
91129 DisplayOptionsPanel * this = AllocThis (DisplayOptionsPanel );
92130 Panel * super = (Panel * ) this ;
93- FunctionBar * fuBar = FunctionBar_new (DisplayOptionsFunctions , NULL , NULL );
94- Panel_init (super , 1 , 1 , 1 , 1 , Class (OptionItem ), true, fuBar );
131+ FunctionBar * checkboxFuBar = FunctionBar_new (CheckboxDisplayOptionsFunctions , CheckboxDisplayOptionsKeys , CheckboxDisplayOptionsEvents );
132+ FunctionBar * numericFuBar = FunctionBar_new (NumericDisplayOptionsFunctions , NumericDisplayOptionsKeys , NumericDisplayOptionsEvents );
133+ FunctionBar * emptyFuBar = FunctionBar_new (NULL , NULL , NULL );
134+ Panel_init (super , 1 , 1 , 1 , 1 , Class (OptionItem ), true, emptyFuBar );
95135
96136 this -> settings = settings ;
97137 this -> scr = scr ;
138+ this -> numericFuBar = numericFuBar ;
139+ this -> checkboxFuBar = checkboxFuBar ;
98140
99141 Panel_setHeader (super , "Display options" );
100142 Panel_add (super , (Object * ) CheckItem_newByRef ("Tree view" , & (settings -> treeView )));
@@ -141,5 +183,9 @@ DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager*
141183 #ifdef HAVE_LIBHWLOC
142184 Panel_add (super , (Object * ) CheckItem_newByRef ("Show topology when selecting affinity by default" , & (settings -> topologyAffinity )));
143185 #endif
186+
187+ OptionItem * defaultSelected = (OptionItem * ) Panel_getSelected (super );
188+ DisplayOptionsPanel_setFunctionBar (this , defaultSelected );
189+
144190 return this ;
145191}
0 commit comments