OSDN Git Service

change and add menu item for external bbs.
[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)
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                 case 2: /* [³°ÉôÈĤÎÄɲÃ] */
90                         ret = BCHANL_MAINMENU_SELECT_REGISTEREXTBBS;
91                         break;
92                 default:
93                         ret = BCHANL_MAINMENU_SELECT_NOSELECT;
94                         break;
95                 }
96                 break;
97         case BCHANL_MAINMENU_ITEMNUM_WINDOW: /* [¥¦¥£¥ó¥É¥¦] */
98                 wexe_dmn(i);
99                 ret = BCHANL_MAINMENU_SELECT_NOSELECT;
100                 break;
101         case BCHANL_MAINMENU_ITEMNUM_GADGET: /* [¾®Êª] */
102             oexe_apg(0, i);
103                 ret = BCHANL_MAINMENU_SELECT_NOSELECT;
104                 break;
105         default:
106                 ret = BCHANL_MAINMENU_SELECT_NOSELECT;
107                 break;
108         }
109
110         return ret;
111 }
112
113 EXPORT W bchanl_mainmenu_popup(bchanl_mainmenu_t *mainmenu, PNT pos)
114 {
115         W i;
116         gset_ptr(PS_SELECT, NULL, -1, -1);
117         i = msel_men(mainmenu->mnid, pos);
118         if (i < 0) {
119                 DP_ER("msel_men error:", i);
120                 return i;
121         }
122         if (i == 0) {
123                 return BCHANL_MAINMENU_SELECT_NOSELECT;
124         }
125         return bchanl_mainmenu_select(mainmenu, i);
126 }
127
128 EXPORT W bchanl_mainmenu_keyselect(bchanl_mainmenu_t *mainmenu, TC keycode)
129 {
130         W i;
131         i = mfnd_key(mainmenu->mnid, keycode);
132         if (i < 0) {
133                 DP_ER("mfnd_key error:", i);
134                 return i;
135         }
136         if (i == 0) {
137                 return BCHANL_MAINMENU_SELECT_NOSELECT;
138         }
139         return bchanl_mainmenu_select(mainmenu, i);
140 }
141
142 EXPORT W bchanl_mainmenu_initialize(bchanl_mainmenu_t *mainmenu, W dnum)
143 {
144         MENUITEM *mnitem_dbx, *mnitem;
145         MNID mnid;
146         W len, err;
147
148         err = dget_dtp(8, dnum, (void**)&mnitem_dbx);
149         if (err < 0) {
150                 DP_ER("dget_dtp error:", err);
151                 return err;
152         }
153         len = dget_siz((B*)mnitem_dbx);
154         mnitem = malloc(len);
155         if (mnitem == NULL) {
156                 DP_ER("mallod error", err);
157                 return -1;
158         }
159         memcpy(mnitem, mnitem_dbx, len);
160         mnid = mcre_men(BCHANL_MAINMENU_ITEMNUM_WINDOW+2, mnitem, NULL);
161         if (mnid < 0) {
162                 DP_ER("mcre_men error", mnid);
163                 free(mnitem);
164                 return -1;
165         }
166
167         mainmenu->mnid = mnid;
168         mainmenu->mnitem = mnitem;
169
170         return 0;
171 }
172
173 EXPORT VOID bchanl_mainmenu_finalize(bchanl_mainmenu_t *mainmenu)
174 {
175         mdel_men(mainmenu->mnid);
176         free(mainmenu->mnitem);
177 }