summaryrefslogtreecommitdiff
path: root/debug_aewl.c
blob: 64fa49cd90e962c0daa92c1dba56f2ad0d0d4d99 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include "debug_aewl.h"

#include "aewl/aewl.h"
#include "aewl/form.h"
#include "aewl/button.h"
#include "aewl/listbox.h"
#include "aewl/field.h"
#include "aewl/label.h"

#include "keys.h"
#include "filedlg.h"

#include <ncurses.h>
#include <stdbool.h>

static int curses_attr_for_pair(int fg, int bg, bool bold) {
   short int cp = bg * 8 + 7 - fg;
   if (!cp) return bold ? A_BOLD : A_NORMAL;
   return COLOR_PAIR(cp) | (bold ? A_BOLD : 0);
}

void debug_aewl() {
   char *s = filedlg_show("Test Dialog");
   clear();

   printw("Answer: '%s'\n", s);
   getch();
}

void debug_aewl_OLD() {
   AewlWidget *b1, *b2, *b3, *lbl;
   AewlListBox *lb;
   AewlWidget *fld;
   AewlForm *f;
   int r;

   AewlAttrSettings ats = {
      {
         curses_attr_for_pair(7, 0, false), /* text */
         curses_attr_for_pair(7, 0, true),  /* text focus */
         curses_attr_for_pair(1, 0, false), /* text shortcut */
         curses_attr_for_pair(1, 0, true)   /* text shortcut focus */
      },

      {
         curses_attr_for_pair(7, 4, false), /* button */
         curses_attr_for_pair(7, 2, true),  /* button focus */
         curses_attr_for_pair(1, 4, false), /* button shortcut */
         curses_attr_for_pair(1, 2, true)   /* button shortcut focus */
      },

      {
         curses_attr_for_pair(7, 0, false), /* frame */
         curses_attr_for_pair(7, 0, true),  /* frame focus */
         curses_attr_for_pair(1, 0, false), /* frame shortcut */
         curses_attr_for_pair(1, 0, true)   /* frame shortcut focus */
      },

      {
         curses_attr_for_pair(7, 0, false), /* field */
         curses_attr_for_pair(7, 0, true),  /* field focus */
         curses_attr_for_pair(7, 4, false), /* field selection */
         curses_attr_for_pair(7, 1, true)   /* field selection focus */
      },

      curses_attr_for_pair(0, 0, true)      /* field pad char */
   };

   aewl_init(&ats);

   clear();
   refresh();
   f = aewl_form_create(stdscr);

   b1 = aewl_button_create(10, 10, 20, KEY_ALT_A, 1, "Button &Ay One");
   b2 = aewl_button_create(10, 12, 20, KEY_ALT_B, 2, "Button &Bee Two");
   b3 = aewl_button_create(10, 14, 20, KEY_ALT_C, 3, "Button &Cee Three");
   lb = (AewlListBox*) 
        aewl_listbox_create(40, 10, 30, 10, KEY_ALT_L, "My &List", 123);
   fld = aewl_field_create(10, 20, 20, KEY_ALT_T, 4, "Test field");
   lbl = aewl_label_create(4, 20, -1, "&Text:");

   aewl_listbox_add(lb, "Ut queant laxis");
   aewl_listbox_add(lb, "Resonare fibris");
   aewl_listbox_add(lb, "Mira gestorum");
   aewl_listbox_add(lb, "Famuli tuorum");
   aewl_listbox_add(lb, "Solve polluti");
   aewl_listbox_add(lb, "Labii reatum");
   aewl_listbox_add(lb, "Sancte Ioannes");
   aewl_listbox_add(lb, "Lacrymosa dies illa");
   aewl_listbox_add(lb, "Qua resurget ex favilla");
   aewl_listbox_add(lb, "Iudicandus homo reus");
   aewl_listbox_add(lb, "Huic ergo parce Deus");
   aewl_listbox_add(lb, "Pie iesu domine");
   aewl_listbox_add(lb, "Dona eis requiem");
   aewl_listbox_add(lb, "Stabat mater dolorosa");
   aewl_listbox_add(lb, "Iuxta crucem lacrymosam");
   aewl_listbox_add(lb, "Dum pendebat filius");
   aewl_listbox_add(lb, "Quis est homo qui non fleret");
   aewl_listbox_add(lb, "Matrem Christi se videret");
   aewl_listbox_add(lb, "In tanto suplicio?");

   aewl_form_add_widget(f, b1);
   aewl_form_add_widget(f, b2);
   aewl_form_add_widget(f, b3);
   aewl_form_add_widget(f, (AewlWidget*) lb);
   aewl_form_add_widget(f, fld);
   aewl_form_add_widget(f, lbl);
   
   aewl_form_paint(f, true);
   while (0 == (r = aewl_form_dispatch_key(f, getch())));
   aewl_form_destroy(f);

   clear();
   refresh();
   printw("Selected value %d", r);
   getch();
   
   clear();
   refresh();
}