~ubuntu-branches/ubuntu/dapper/htop/dapper

« back to all changes in this revision

Viewing changes to CategoriesListBox.c

  • Committer: Bazaar Package Importer
  • Author(s): Bartosz Fenski
  • Date: 2004-11-27 10:10:17 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20041127101017-vwknw2ipfvxchno4
Tags: 0.5-1
* New upstream version.
  - fixes problem with wrongly displayed CPU bar (Closes: #283212)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
#include "CategoriesListBox.h"
 
3
#include "AvailableMetersListBox.h"
 
4
#include "MetersListBox.h"
 
5
#include "DisplayOptionsListBox.h"
 
6
 
 
7
#include "ListBox.h"
 
8
 
 
9
#include "debug.h"
 
10
#include <assert.h>
 
11
 
 
12
/*{
 
13
 
 
14
typedef struct CategoriesListBox_ {
 
15
   ListBox super;
 
16
 
 
17
   Settings* settings;
 
18
   ScreenManager* scr;
 
19
} CategoriesListBox;
 
20
 
 
21
}*/
 
22
 
 
23
/* private property */
 
24
char* MetersFunctions[10] = {"      ", "      ", "      ", "Type  ", "Add L ", "Add R ", "MoveUp", "MoveDn", "Remove", "Done  "};
 
25
 
 
26
/* private property */
 
27
char* DisplayOptionsFunctions[10] = {"      ", "      ", "      ", "      ", "      ", "      ", "      ", "      ", "      ", "Done  "};
 
28
 
 
29
CategoriesListBox* CategoriesListBox_new(Settings* settings, ScreenManager* scr) {
 
30
   CategoriesListBox* this = (CategoriesListBox*) malloc(sizeof(CategoriesListBox));
 
31
   ListBox* super = (ListBox*) this;
 
32
   ListBox_init(super, 1, 1, 1, 1, LISTITEM_CLASS, true);
 
33
   ((Object*)this)->delete = CategoriesListBox_delete;
 
34
 
 
35
   this->settings = settings;
 
36
   this->scr = scr;
 
37
   super->eventHandler = CategoriesListBox_eventHandler;
 
38
   ListBox_setHeader(super, RichString_quickString(CRT_colors[PANEL_HEADER_FOCUS], "Setup"));
 
39
   ListBox_add(super, (Object*) ListItem_new(String_copy("Meters")));
 
40
   ListBox_add(super, (Object*) ListItem_new(String_copy("Display options")));
 
41
   return this;
 
42
}
 
43
 
 
44
void CategoriesListBox_delete(Object* object) {
 
45
   ListBox* super = (ListBox*) object;
 
46
   CategoriesListBox* this = (CategoriesListBox*) object;
 
47
   ListBox_done(super);
 
48
   free(this);
 
49
}
 
50
 
 
51
HandlerResult CategoriesListBox_eventHandler(ListBox* super, int ch) {
 
52
   CategoriesListBox* this = (CategoriesListBox*) super;
 
53
 
 
54
   HandlerResult result = IGNORED;
 
55
 
 
56
   int previous = ListBox_getSelectedIndex(super);
 
57
 
 
58
   switch (ch) {
 
59
      case KEY_UP:
 
60
      case KEY_DOWN:
 
61
      case KEY_NPAGE:
 
62
      case KEY_PPAGE:
 
63
      case KEY_HOME:
 
64
      case KEY_END: {
 
65
         ListBox_onKey(super, ch);
 
66
         int selected = ListBox_getSelectedIndex(super);
 
67
         if (previous != selected) {
 
68
            int size = ScreenManager_size(this->scr);
 
69
            for (int i = 1; i < size; i++)
 
70
               ScreenManager_remove(this->scr, 1);
 
71
            switch (selected) {
 
72
               case 0:
 
73
                  CategoriesListBox_makeMetersPage(this);
 
74
                  break;
 
75
               case 1:
 
76
                  CategoriesListBox_makeProcessListPage(this);
 
77
                  break;
 
78
            }
 
79
         }
 
80
         result = HANDLED;
 
81
      }
 
82
   }
 
83
 
 
84
   return result;
 
85
}
 
86
 
 
87
void CategoriesListBox_makeMetersPage(CategoriesListBox* this) {
 
88
   FunctionBar* fuBar = FunctionBar_new(10, MetersFunctions, NULL, NULL);
 
89
   ListBox* lbLeftMeters = (ListBox*) MetersListBox_new(this->settings, "Left column", this->settings->header->leftMeters, this->scr);
 
90
   ListBox* lbRightMeters = (ListBox*) MetersListBox_new(this->settings, "Right column", this->settings->header->rightMeters, this->scr);
 
91
   ListBox* lbAvailableMeters = (ListBox*) AvailableMetersListBox_new(this->settings, lbLeftMeters, lbRightMeters, this->scr);
 
92
   ScreenManager_add(this->scr, lbLeftMeters, 20);
 
93
   ScreenManager_add(this->scr, lbRightMeters, 20);
 
94
   ScreenManager_add(this->scr, lbAvailableMeters, -1);
 
95
   ScreenManager_setFunctionBar(this->scr, fuBar);
 
96
}
 
97
 
 
98
void CategoriesListBox_makeProcessListPage(CategoriesListBox* this) {
 
99
   FunctionBar* fuBar = FunctionBar_new(10, DisplayOptionsFunctions, NULL, NULL);
 
100
   ListBox* lbDisplayOptions = (ListBox*) DisplayOptionsListBox_new(this->settings, this->scr);
 
101
   ScreenManager_add(this->scr, lbDisplayOptions, -1);
 
102
   ScreenManager_setFunctionBar(this->scr, fuBar);
 
103
}