-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChooseKeymapMenu.c
190 lines (161 loc) · 6.36 KB
/
ChooseKeymapMenu.c
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
//#define MDEBUG
#include <proto/intuition.h>
#include <proto/exec.h>
#include <proto/keymap.h>
//#include <proto/graphics.h>
//#include <proto/diskfont.h>
#include <classes/popupmenu.h>
//#include <images/label.h>
//#include <graphics/rpattr.h>
#include "dockybase.h"
#include "DockWindow.h"
#include "KeyMapSwitcher_rev.h"
extern struct ExecIFace *IExec;
extern struct KeymapIFace *IKeymap;
extern struct IntuitionIFace *IIntuition;
//extern struct GraphicsIFace *IGraphics;
//extern struct DiskfontIFace *IDiskfont;
extern Object *Objects[LAST_NUM];
#define OBJ(x) Objects[x]
#define GAD(x) (struct Gadget *)Objects[x]
extern BOOL WinMode, KM3;
extern char keymap0Flag[1024], keymap1Flag[1024], keymap2Flag[1024];
extern void SetKeyMapFlag(char *, char *);
extern BOOL PrefsWindow_NP(struct DockyIFace *, struct DockyData *);
#ifdef NEWPROC
extern int32 OpenPrefsWindow(CONST_STRPTR, LONG, struct ExecBase *);
#else
extern int32 OpenPrefsWindow(struct DockyData *);
#endif
uint32 MenuHandlerFunc(struct Hook *hook, Object *o, APTR reserved);
void OpenDockMenu(struct DockyIFace *Self)
{
struct DockyData *dd = (struct DockyData *)((uint32)Self - Self->Data.NegativeSize);
Object *chooseMenu;
struct Hook *MenuHandler;
char KeymapLocalName[3][64];
STRPTR keymapdesc;
APTR KM_handle;
int32 i, KM_cs[3];
for(i = 0; KM3? i<3:i<2; i++)
{
if( (KM_handle=IKeymap->OpenKeyMapHandle(dd->KeymapName[i], NULL)) )
{
IKeymap->ObtainKeyMapInfo(KM_handle, KEYMAPINFO_INFOTEXT_LOCAL,&keymapdesc,
KEYMAPINFO_INFOTEXT_CHARSET,&KM_cs[i], TAG_END);
IUtility->Strlcpy(KeymapLocalName[i], keymapdesc, 64);
IKeymap->ReleaseKeyMapInfo(KM_handle, KEYMAPINFO_INFOTEXT_LOCAL,&keymapdesc,
KEYMAPINFO_INFOTEXT_CHARSET,&KM_cs[i], TAG_END);
IKeymap->CloseKeyMapHandle(KM_handle);
}
else
IUtility->Strlcpy(KeymapLocalName[i], dd->KeymapName[i], 64);
//IDOS->Printf("KEYMAP%ld='%s' / %ld\n",i+1,KeymapLocalName[i],KM_cs[i]);
}
MenuHandler = (struct Hook *)IExec->AllocSysObjectTags(ASOT_HOOK,
ASOHOOK_Entry, MenuHandlerFunc,
ASOHOOK_Data, Self,
TAG_DONE);
chooseMenu = IIntuition->NewObject(PopupMenuClass, NULL,// "popupmenu.class",
PMA_MenuHandler,MenuHandler, TAG_DONE);
Object *item1 = IIntuition->NewObject(NULL, "popupmenuitem.class",
PMIA_ID, MENU_OPT1,
PMIA_Title, dd->alt_menunames? KeymapLocalName[0]:dd->KeymapName[0],
PMIA_Icon, OBJ(GID_BITMAP1) = IIntuition->NewObject(NULL, "bitmap.image",
BITMAP_SourceFile, keymap0Flag,
BITMAP_Screen, dd->scr,
BITMAP_Masking, TRUE,
TAG_DONE),
TAG_END);
Object *item2 = IIntuition->NewObject(NULL, "popupmenuitem.class",
PMIA_ID, MENU_OPT2,
PMIA_Title, dd->alt_menunames? KeymapLocalName[1]:dd->KeymapName[1],
//PMIA_Image, IMG_desc,
PMIA_Icon, OBJ(GID_BITMAP2) = IIntuition->NewObject(NULL, "bitmap.image",
BITMAP_SourceFile, keymap1Flag,
BITMAP_Screen, dd->scr,
BITMAP_Masking, TRUE,
TAG_DONE),
TAG_END);
Object *item3 = IIntuition->NewObject(NULL, "popupmenuitem.class",
PMIA_ID, MENU_OPT3,
PMIA_Title, dd->alt_menunames? KeymapLocalName[2]:dd->KeymapName[2],
PMIA_Icon, OBJ(GID_BITMAP3) = IIntuition->NewObject(NULL, "bitmap.image",
BITMAP_SourceFile, keymap2Flag,
BITMAP_Screen, dd->scr,
BITMAP_Masking, TRUE,
TAG_DONE),
TAG_END);
Object *itemS = IIntuition->NewObject(NULL, "popupmenuitem.class",
PMIA_Title, GetString(&li, MSG_DOCKY_SETTINGS),
PMIA_ID, MENU_PREFS,
TAG_END);
Object *itemBar = IIntuition->NewObject(NULL, "popupmenuitem.class", PMIA_Title,~0, TAG_END);
// language2 NOT valid/available
if( !OBJ(GID_BITMAP2) )
IIntuition->SetAttrs(item2, PMIA_Disabled,TRUE, TAG_DONE);
IIntuition->IDoMethod(chooseMenu, OM_ADDMEMBER, item1); // lang1
IIntuition->IDoMethod(chooseMenu, OM_ADDMEMBER, item2); // lang2
if(OBJ(GID_BITMAP3) && KM3)
IIntuition->IDoMethod(chooseMenu, OM_ADDMEMBER, item3); // lang3
if(!WinMode)
{
IIntuition->IDoMethod(chooseMenu, OM_ADDMEMBER, itemBar); // separator
IIntuition->IDoMethod(chooseMenu, OM_ADDMEMBER, itemS); // Settings...
}
IIntuition->IDoMethod(chooseMenu, PM_OPEN, dd->win); // show PopUp Menu
IIntuition->DisposeObject(chooseMenu);
IExec->FreeSysObject(ASOT_HOOK, MenuHandler);
}
uint32 MenuHandlerFunc(struct Hook *hook, Object *o, APTR reserved)
{
struct DockyIFace *Self = (struct DockyIFace *)hook->h_Data;
struct DockyData *dd = (struct DockyData *)((uint32)Self - Self->Data.NegativeSize);
uint32 item_ID = 0;
if( IIntuition->GetAttr(PMIA_ID, o, &item_ID) )
{
#ifdef MDEBUG
IDOS->Printf("Choosed: ");
#endif
switch(item_ID)
{
case MENU_OPT1:
#ifdef MDEBUG
IDOS->Printf("'%s'\n",dd->KeymapName[0]);
#endif
dd->km_pos = 1;
//ChangeKeymap(dd, dd->KeymapName[0]);
//IUtility->Strlcpy( dd->keymapSel, dd->KeymapName[0], sizeof(dd->keymapSel) );
break;
case MENU_OPT2:
#ifdef MDEBUG
IDOS->Printf("'%s'\n",dd->KeymapName[1]);
#endif
dd->km_pos = 2;
//ChangeKeymap(dd, dd->KeymapName[1]);
//IUtility->Strlcpy( dd->keymapSel, dd->KeymapName[1], sizeof(dd->keymapSel) );
break;
case MENU_OPT3:
#ifdef MDEBUG
IDOS->Printf("'%s'\n",dd->KeymapName[2]);
#endif
dd->km_pos = 3;
//ChangeKeymap(dd, dd->KeymapName[2]);
//IUtility->Strlcpy( dd->keymapSel, dd->KeymapName[2], sizeof(dd->keymapSel) );
break;
case MENU_PREFS:
{
#ifdef MDEBUG
IDOS->Printf("Settings...\n");
#endif
#ifdef NEWPROC
PrefsWindow_NP(Self, dd);
#else
OpenPrefsWindow(dd);
#endif
}
break;
}
}
return(0);
}