OSDN Git Service

implement menu handling logic.
[bbk/bchanl.git] / src / bchanl_menus.c
1 /*
2  * bchanl_menus.c
3  *
4  * Copyright (c) 2011-2012 project bchan
5  *
6  * This software is provided 'as-is', without any express or implied
7  * warranty. In no event will the authors be held liable for any damages
8  * arising from the use of this software.
9  *
10  * Permission is granted to anyone to use this software for any purpose,
11  * including commercial applications, and to alter it and redistribute it
12  * freely, subject to the following restrictions:
13  *
14  * 1. The origin of this software must not be misrepresented; you must not
15  *    claim that you wrote the original software. If you use this software
16  *    in a product, an acknowledgment in the product documentation would be
17  *    appreciated but is not required.
18  *
19  * 2. Altered source versions must be plainly marked as such, and must not be
20  *    misrepresented as being the original software.
21  *
22  * 3. This notice may not be removed or altered from any source
23  *    distribution.
24  *
25  */
26
27 #include    "bchanl_menus.h"
28
29 #include        <basic.h>
30 #include        <bstdio.h>
31 #include        <bstdlib.h>
32 #include        <btron/hmi.h>
33 #include        <btron/vobj.h>
34
35 #ifdef BCHANL_CONFIG_DEBUG
36 # define DP(arg) printf arg
37 # define DP_ER(msg, err) printf("%s (%d/%x)\n", msg, err>>16, err)
38 #else
39 # define DP(arg) /**/
40 # define DP_ER(msg, err) /**/
41 #endif
42
43 #define BCHANL_MAINMENU_ITEMNUM_WINDOW 4
44 #define BCHANL_MAINMENU_ITEMNUM_GADGET (BCHANL_MAINMENU_ITEMNUM_WINDOW + 1)
45
46 EXPORT W bchanl_mainmenu_setup(bchanl_mainmenu_t *mainmenu, Bool subectjoptionenable, Bool extbbsmanageropen, Bool extbbsselected)
47 {
48         /* [ɽ¼¨] -> [¥¹¥ì°ìÍ÷ÀßÄê] */
49         if (subectjoptionenable == False) {
50                 mchg_atr(mainmenu->mnid, (1 << 8)|2, M_NOSEL);
51         } else {
52                 mchg_atr(mainmenu->mnid, (1 << 8)|2, M_SEL);
53         }
54
55         /* [³°ÉôÈÄ] -> [³°ÉôÈÄ´ÉÍý] */
56         if (extbbsmanageropen == False) {
57                 mchg_atr(mainmenu->mnid, (3 << 8)|1, M_NOSEL);
58         } else {
59                 mchg_atr(mainmenu->mnid, (3 << 8)|1, M_SEL);
60         }
61
62         /* [³°ÉôÈÄ] -> [ÈÄÄɲÃ] */
63         if (extbbsmanageropen != False) {
64                 mchg_atr(mainmenu->mnid, (3 << 8)|3, M_ACT);
65         } else {
66                 mchg_atr(mainmenu->mnid, (3 << 8)|3, M_INACT);
67         }
68         /* [³°ÉôÈÄ] -> [°ì¤Ä¾å¤²¤ë] */
69         /* [³°ÉôÈÄ] -> [°ì¤Ä²¼¤²¤ë] */
70         /* [³°ÉôÈÄ] -> [ºï½ü] */
71         if (extbbsselected == False) {
72                 mchg_atr(mainmenu->mnid, (3 << 8)|4, M_INACT);
73                 mchg_atr(mainmenu->mnid, (3 << 8)|5, M_INACT);
74                 mchg_atr(mainmenu->mnid, (3 << 8)|6, M_INACT);
75         } else {
76                 mchg_atr(mainmenu->mnid, (3 << 8)|4, M_ACT);
77                 mchg_atr(mainmenu->mnid, (3 << 8)|5, M_ACT);
78                 mchg_atr(mainmenu->mnid, (3 << 8)|6, M_ACT);
79         }
80
81         wget_dmn(&(mainmenu->mnitem[BCHANL_MAINMENU_ITEMNUM_WINDOW].ptr));
82         mset_itm(mainmenu->mnid, BCHANL_MAINMENU_ITEMNUM_WINDOW, mainmenu->mnitem+BCHANL_MAINMENU_ITEMNUM_WINDOW);
83         oget_men(0, NULL, &(mainmenu->mnitem[BCHANL_MAINMENU_ITEMNUM_GADGET].ptr), NULL, NULL);
84         mset_itm(mainmenu->mnid, BCHANL_MAINMENU_ITEMNUM_GADGET, mainmenu->mnitem+BCHANL_MAINMENU_ITEMNUM_GADGET);
85
86         return 0; /* tmp */
87 }
88
89 LOCAL W bchanl_mainmenu_select(bchanl_mainmenu_t *mainmenu, W i)
90 {
91         W ret;
92
93         switch(i >> 8) {
94         case 0: /* [½ªÎ»] */
95                 ret = BCHANL_MAINMENU_SELECT_CLOSE;
96                 break;
97         case 1: /* [ɽ¼¨] */
98                 switch (i & 0xff) {
99                 case 1: /* [ºÆɽ¼¨] */
100                         ret = BCHANL_MAINMENU_SELECT_REDISPLAY;
101                         break;
102                 case 2: /* [¥¹¥ì°ìÍ÷ÀßÄê] */
103                         ret = BCHANL_MAINMENU_SELECT_SUBJECTOPTION;
104                         break;
105                 default:
106                         ret = BCHANL_MAINMENU_SELECT_NOSELECT;
107                         break;
108                 }
109                 break;
110         case 2: /* [Áàºî] */
111                 switch (i & 0xff) {
112                 case 1: /* [ÈÄ°ìÍ÷ºÆ¼èÆÀ] */
113                         ret = BCHANL_MAINMENU_SELECT_BBSMENUFETCH;
114                         break;
115                 default:
116                         ret = BCHANL_MAINMENU_SELECT_NOSELECT;
117                         break;
118                 }
119                 break;
120         case 3: /* [³°ÉôÈÄ] */
121                 switch (i & 0xff) {
122                 case 1: /* [³°ÉôÈÄ´ÉÍý] */
123                         ret = BCHANL_MAINMENU_SELECT_EXTBBS_MANAGER;
124                         break;
125                 case 3: /* [ÈÄÄɲÃ] */
126                         ret = BCHANL_MAINMENU_SELECT_EXTBBS_REGISTER;
127                         break;
128                 case 4: /* [°ì¤Ä¾å¤²¤ë] */
129                         ret = BCHANL_MAINMENU_SELECT_EXTBBS_UP;
130                         break;
131                 case 5: /* [°ì¤Ä²¼¤²¤ë] */
132                         ret = BCHANL_MAINMENU_SELECT_EXTBBS_DOWN;
133                         break;
134                 case 6: /* [ºï½ü] */
135                         ret = BCHANL_MAINMENU_SELECT_EXTBBS_DELETE;
136                         break;
137                 default:
138                         ret = BCHANL_MAINMENU_SELECT_NOSELECT;
139                         break;
140                 }
141                 break;
142         case BCHANL_MAINMENU_ITEMNUM_WINDOW: /* [¥¦¥£¥ó¥É¥¦] */
143                 wexe_dmn(i);
144                 ret = BCHANL_MAINMENU_SELECT_NOSELECT;
145                 break;
146         case BCHANL_MAINMENU_ITEMNUM_GADGET: /* [¾®Êª] */
147             oexe_apg(0, i);
148                 ret = BCHANL_MAINMENU_SELECT_NOSELECT;
149                 break;
150         default:
151                 ret = BCHANL_MAINMENU_SELECT_NOSELECT;
152                 break;
153         }
154
155         return ret;
156 }
157
158 EXPORT W bchanl_mainmenu_popup(bchanl_mainmenu_t *mainmenu, PNT pos)
159 {
160         W i;
161         gset_ptr(PS_SELECT, NULL, -1, -1);
162         i = msel_men(mainmenu->mnid, pos);
163         if (i < 0) {
164                 DP_ER("msel_men error:", i);
165                 return i;
166         }
167         if (i == 0) {
168                 return BCHANL_MAINMENU_SELECT_NOSELECT;
169         }
170         return bchanl_mainmenu_select(mainmenu, i);
171 }
172
173 EXPORT W bchanl_mainmenu_keyselect(bchanl_mainmenu_t *mainmenu, TC keycode)
174 {
175         W i;
176         i = mfnd_key(mainmenu->mnid, keycode);
177         if (i < 0) {
178                 DP_ER("mfnd_key error:", i);
179                 return i;
180         }
181         if (i == 0) {
182                 return BCHANL_MAINMENU_SELECT_NOSELECT;
183         }
184         return bchanl_mainmenu_select(mainmenu, i);
185 }
186
187 EXPORT W bchanl_mainmenu_initialize(bchanl_mainmenu_t *mainmenu, W dnum)
188 {
189         MENUITEM *mnitem_dbx, *mnitem;
190         MNID mnid;
191         W len, err;
192
193         err = dget_dtp(8, dnum, (void**)&mnitem_dbx);
194         if (err < 0) {
195                 DP_ER("dget_dtp error:", err);
196                 return err;
197         }
198         len = dget_siz((B*)mnitem_dbx);
199         mnitem = malloc(len);
200         if (mnitem == NULL) {
201                 DP_ER("mallod error", err);
202                 return -1;
203         }
204         memcpy(mnitem, mnitem_dbx, len);
205         mnid = mcre_men(BCHANL_MAINMENU_ITEMNUM_WINDOW+2, mnitem, NULL);
206         if (mnid < 0) {
207                 DP_ER("mcre_men error", mnid);
208                 free(mnitem);
209                 return -1;
210         }
211
212         mainmenu->mnid = mnid;
213         mainmenu->mnitem = mnitem;
214
215         return 0;
216 }
217
218 EXPORT VOID bchanl_mainmenu_finalize(bchanl_mainmenu_t *mainmenu)
219 {
220         mdel_men(mainmenu->mnid);
221         free(mainmenu->mnitem);
222 }