OSDN Git Service

add menu item for subject option open/close.
[bbk/bchanl.git] / src / bchanl_menus.c
1 /*
2  * bchanl_menus.c
3  *
4  * Copyright (c) 2011 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 3
44 #define BCHANL_MAINMENU_ITEMNUM_GADGET (BCHANL_MAINMENU_ITEMNUM_WINDOW + 1)
45
46 EXPORT W bchanl_mainmenu_setup(bchanl_mainmenu_t *mainmenu, Bool subectjoptionenable)
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         wget_dmn(&(mainmenu->mnitem[BCHANL_MAINMENU_ITEMNUM_WINDOW].ptr));
56         mset_itm(mainmenu->mnid, BCHANL_MAINMENU_ITEMNUM_WINDOW, mainmenu->mnitem+BCHANL_MAINMENU_ITEMNUM_WINDOW);
57         oget_men(0, NULL, &(mainmenu->mnitem[BCHANL_MAINMENU_ITEMNUM_GADGET].ptr), NULL, NULL);
58         mset_itm(mainmenu->mnid, BCHANL_MAINMENU_ITEMNUM_GADGET, mainmenu->mnitem+BCHANL_MAINMENU_ITEMNUM_GADGET);
59
60         return 0; /* tmp */
61 }
62
63 LOCAL W bchanl_mainmenu_select(bchanl_mainmenu_t *mainmenu, W i)
64 {
65         W ret;
66
67         switch(i >> 8) {
68         case 0: /* [½ªÎ»] */
69                 ret = BCHANL_MAINMENU_SELECT_CLOSE;
70                 break;
71         case 1: /* [ɽ¼¨] */
72                 switch(i & 0xff) {
73                 case 1: /* [ºÆɽ¼¨] */
74                         ret = BCHANL_MAINMENU_SELECT_REDISPLAY;
75                         break;
76                 case 2: /* [¥¹¥ì°ìÍ÷ÀßÄê] */
77                         ret = BCHANL_MAINMENU_SELECT_SUBJECTOPTION;
78                         break;
79                 default:
80                         ret = BCHANL_MAINMENU_SELECT_NOSELECT;
81                         break;
82                 }
83                 break;
84         case 2: /* [Áàºî] */
85                 switch(i & 0xff) {
86                 case 1: /* [ÈÄ°ìÍ÷ºÆ¼èÆÀ] */
87                         ret = BCHANL_MAINMENU_SELECT_BBSMENUFETCH;
88                         break;
89                 default:
90                         ret = BCHANL_MAINMENU_SELECT_NOSELECT;
91                         break;
92                 }
93                 break;
94         case BCHANL_MAINMENU_ITEMNUM_WINDOW: /* [¥¦¥£¥ó¥É¥¦] */
95                 wexe_dmn(i);
96                 ret = BCHANL_MAINMENU_SELECT_NOSELECT;
97                 break;
98         case BCHANL_MAINMENU_ITEMNUM_GADGET: /* [¾®Êª] */
99             oexe_apg(0, i);
100                 ret = BCHANL_MAINMENU_SELECT_NOSELECT;
101                 break;
102         default:
103                 ret = BCHANL_MAINMENU_SELECT_NOSELECT;
104                 break;
105         }
106
107         return ret;
108 }
109
110 EXPORT W bchanl_mainmenu_popup(bchanl_mainmenu_t *mainmenu, PNT pos)
111 {
112         W i;
113         gset_ptr(PS_SELECT, NULL, -1, -1);
114         i = msel_men(mainmenu->mnid, pos);
115         if (i < 0) {
116                 DP_ER("msel_men error:", i);
117                 return i;
118         }
119         if (i == 0) {
120                 return BCHANL_MAINMENU_SELECT_NOSELECT;
121         }
122         return bchanl_mainmenu_select(mainmenu, i);
123 }
124
125 EXPORT W bchanl_mainmenu_keyselect(bchanl_mainmenu_t *mainmenu, TC keycode)
126 {
127         W i;
128         i = mfnd_key(mainmenu->mnid, keycode);
129         if (i < 0) {
130                 DP_ER("mfnd_key error:", i);
131                 return i;
132         }
133         if (i == 0) {
134                 return BCHANL_MAINMENU_SELECT_NOSELECT;
135         }
136         return bchanl_mainmenu_select(mainmenu, i);
137 }
138
139 EXPORT W bchanl_mainmenu_initialize(bchanl_mainmenu_t *mainmenu, W dnum)
140 {
141         MENUITEM *mnitem_dbx, *mnitem;
142         MNID mnid;
143         W len, err;
144
145         err = dget_dtp(8, dnum, (void**)&mnitem_dbx);
146         if (err < 0) {
147                 DP_ER("dget_dtp error:", err);
148                 return err;
149         }
150         len = dget_siz((B*)mnitem_dbx);
151         mnitem = malloc(len);
152         if (mnitem == NULL) {
153                 DP_ER("mallod error", err);
154                 return -1;
155         }
156         memcpy(mnitem, mnitem_dbx, len);
157         mnid = mcre_men(BCHANL_MAINMENU_ITEMNUM_WINDOW+2, mnitem, NULL);
158         if (mnid < 0) {
159                 DP_ER("mcre_men error", mnid);
160                 free(mnitem);
161                 return -1;
162         }
163
164         mainmenu->mnid = mnid;
165         mainmenu->mnitem = mnitem;
166
167         return 0;
168 }
169
170 EXPORT VOID bchanl_mainmenu_finalize(bchanl_mainmenu_t *mainmenu)
171 {
172         mdel_men(mainmenu->mnid);
173         free(mainmenu->mnitem);
174 }