4 * Copyright (c) 2011-2012 project bchan
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.
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:
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.
19 * 2. Altered source versions must be plainly marked as such, and must not be
20 * misrepresented as being the original software.
22 * 3. This notice may not be removed or altered from any source
27 #include "bchanl_menus.h"
32 #include <btron/hmi.h>
33 #include <btron/vobj.h>
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)
40 # define DP_ER(msg, err) /**/
43 #define BCHANL_MAINMENU_ITEMNUM_WINDOW 4
44 #define BCHANL_MAINMENU_ITEMNUM_GADGET (BCHANL_MAINMENU_ITEMNUM_WINDOW + 1)
46 EXPORT W bchanl_mainmenu_setup(bchanl_mainmenu_t *mainmenu, Bool subectjoptionenable)
48 /* [ɽ¼¨] -> [¥¹¥ì°ìÍ÷ÀßÄê] */
49 if (subectjoptionenable == False) {
50 mchg_atr(mainmenu->mnid, (1 << 8)|2, M_NOSEL);
52 mchg_atr(mainmenu->mnid, (1 << 8)|2, M_SEL);
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);
63 LOCAL W bchanl_mainmenu_select(bchanl_mainmenu_t *mainmenu, W i)
69 ret = BCHANL_MAINMENU_SELECT_CLOSE;
73 case 1: /* [ºÆɽ¼¨] */
74 ret = BCHANL_MAINMENU_SELECT_REDISPLAY;
76 case 2: /* [¥¹¥ì°ìÍ÷ÀßÄê] */
77 ret = BCHANL_MAINMENU_SELECT_SUBJECTOPTION;
80 ret = BCHANL_MAINMENU_SELECT_NOSELECT;
86 case 1: /* [ÈÄ°ìÍ÷ºÆ¼èÆÀ] */
87 ret = BCHANL_MAINMENU_SELECT_BBSMENUFETCH;
89 case 2: /* [³°ÉôÈĤÎÄɲÃ] */
90 ret = BCHANL_MAINMENU_SELECT_REGISTEREXTBBS;
93 ret = BCHANL_MAINMENU_SELECT_NOSELECT;
97 case BCHANL_MAINMENU_ITEMNUM_WINDOW: /* [¥¦¥£¥ó¥É¥¦] */
99 ret = BCHANL_MAINMENU_SELECT_NOSELECT;
101 case BCHANL_MAINMENU_ITEMNUM_GADGET: /* [¾®Êª] */
103 ret = BCHANL_MAINMENU_SELECT_NOSELECT;
106 ret = BCHANL_MAINMENU_SELECT_NOSELECT;
113 EXPORT W bchanl_mainmenu_popup(bchanl_mainmenu_t *mainmenu, PNT pos)
116 gset_ptr(PS_SELECT, NULL, -1, -1);
117 i = msel_men(mainmenu->mnid, pos);
119 DP_ER("msel_men error:", i);
123 return BCHANL_MAINMENU_SELECT_NOSELECT;
125 return bchanl_mainmenu_select(mainmenu, i);
128 EXPORT W bchanl_mainmenu_keyselect(bchanl_mainmenu_t *mainmenu, TC keycode)
131 i = mfnd_key(mainmenu->mnid, keycode);
133 DP_ER("mfnd_key error:", i);
137 return BCHANL_MAINMENU_SELECT_NOSELECT;
139 return bchanl_mainmenu_select(mainmenu, i);
142 EXPORT W bchanl_mainmenu_initialize(bchanl_mainmenu_t *mainmenu, W dnum)
144 MENUITEM *mnitem_dbx, *mnitem;
148 err = dget_dtp(8, dnum, (void**)&mnitem_dbx);
150 DP_ER("dget_dtp error:", err);
153 len = dget_siz((B*)mnitem_dbx);
154 mnitem = malloc(len);
155 if (mnitem == NULL) {
156 DP_ER("mallod error", err);
159 memcpy(mnitem, mnitem_dbx, len);
160 mnid = mcre_men(BCHANL_MAINMENU_ITEMNUM_WINDOW+2, mnitem, NULL);
162 DP_ER("mcre_men error", mnid);
167 mainmenu->mnid = mnid;
168 mainmenu->mnitem = mnitem;
173 EXPORT VOID bchanl_mainmenu_finalize(bchanl_mainmenu_t *mainmenu)
175 mdel_men(mainmenu->mnid);
176 free(mainmenu->mnitem);