-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChooseKeymapMenu2.c
244 lines (210 loc) · 8.73 KB
/
ChooseKeymapMenu2.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
//#define MDEBUG
#include "dockybase.h"
#include <proto/keymap.h>
#include "DockWindow.h"
//#include <proto/graphics.h>
//#include <graphics/composite.h>
#include "KeyMapSwitcher_rev.h"
extern struct ExecIFace *IExec;
extern struct KeymapIFace *IKeymap;
extern struct IntuitionIFace *IIntuition;
extern struct DataTypesIFace *IDataTypes;
//extern struct GraphicsIFace *IGraphics;
//extern struct DiskfontIFace *IDiskfont;
// the class pointer
extern Class *PopupMenuClass, *LabelClass, *BitMapClass;
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, *imageM[3], *item1 = NULL, *item2 = NULL, *item3 = NULL;
struct Hook *MenuHandler;
char KeymapLocalName[3][64];
STRPTR keymapdesc;
APTR KM_handle;
int32 i, KM_cs;
for(i = 0; KM3? i<3:i<2; i++)
{
if( (KM_handle=IKeymap->OpenKeyMapHandle(dd->KeymapName[i], NULL))!=NULL )
{
IKeymap->ObtainKeyMapInfo(KM_handle, KEYMAPINFO_INFOTEXT_LOCAL,&keymapdesc,
KEYMAPINFO_INFOTEXT_CHARSET,&KM_cs, TAG_END);
IUtility->Strlcpy(KeymapLocalName[i], keymapdesc, 64);
if(KM_cs == 8) // ISO_8859-5 font charset
{
imageM[i] = IIntuition->NewObject(LabelClass, NULL, //LABEL_DisposeImage,TRUE,
IA_Font,&dd->fiso[2].tta, LABEL_Underscore,0,
LABEL_Text,keymapdesc, TAG_END);
}
else
if(KM_cs == 5) // ISO_8859-2 font charset
{
imageM[i] = IIntuition->NewObject(LabelClass, NULL, //LABEL_DisposeImage,TRUE,
IA_Font,&dd->fiso[1].tta, LABEL_Underscore,0,
LABEL_Text,keymapdesc, TAG_END);
}
else // ISO_8859-15 font charset
{
imageM[i] = IIntuition->NewObject(LabelClass, NULL, //LABEL_DisposeImage,TRUE,
IA_Font,&dd->fiso[0].tta, LABEL_Underscore,0,
LABEL_Text,keymapdesc, TAG_END);
}
IKeymap->ReleaseKeyMapInfo(KM_handle, KEYMAPINFO_INFOTEXT_LOCAL,&keymapdesc,
KEYMAPINFO_INFOTEXT_CHARSET,&KM_cs, TAG_END);
IKeymap->CloseKeyMapHandle(KM_handle);
}
else
IUtility->Strlcpy(KeymapLocalName[i], dd->KeymapName[i], 64);
#ifdef MDEBUG
IDOS->Printf("KEYMAP%ld='%s' / %ld\n",i+1,KeymapLocalName[i],KM_cs);
#endif
IDOS->Printf("KEYMAP%ld='%s' / %ld (0x%lx)\n",i+1,KeymapLocalName[i],KM_cs,imageM[i]);
}
MenuHandler = (struct Hook *)IExec->AllocSysObjectTags(ASOT_HOOK,
ASOHOOK_Entry, MenuHandlerFunc,
ASOHOOK_Data, Self,
TAG_DONE);
chooseMenu = IIntuition->NewObject(PopupMenuClass, NULL,
PMA_MenuHandler,MenuHandler, TAG_DONE);
if(dd->alt_menunames)
{
item1 = IIntuition->NewObject(NULL, "popupmenuitem.class",
PMIA_ID, MENU_OPT1,
PMIA_SelectImage, OBJ(GID_BITMAP1) = IIntuition->NewObject(BitMapClass, NULL,
BITMAP_SourceFile, keymap0Flag,
BITMAP_Screen, dd->scr,
BITMAP_Masking, TRUE,
TAG_DONE),
//PMIA_Title, dd->alt_menunames? NULL : dd->KeymapName[0],
PMIA_Image, imageM[0],
TAG_END);
item2 = IIntuition->NewObject(NULL, "popupmenuitem.class",
PMIA_ID, MENU_OPT2,
PMIA_SelectImage, OBJ(GID_BITMAP2) = IIntuition->NewObject(BitMapClass, NULL,
BITMAP_SourceFile, keymap1Flag,
BITMAP_Screen, dd->scr,
BITMAP_Masking, TRUE,
TAG_DONE),
PMIA_Image, imageM[1],
TAG_END);
item3 = IIntuition->NewObject(NULL, "popupmenuitem.class",
PMIA_ID, MENU_OPT3,
PMIA_SelectImage, OBJ(GID_BITMAP3) = IIntuition->NewObject(BitMapClass, NULL,
BITMAP_SourceFile, keymap2Flag,
BITMAP_Screen, dd->scr,
BITMAP_Masking, TRUE,
TAG_DONE),
PMIA_Image, imageM[2],
TAG_END);
}
else
{
item1 = IIntuition->NewObject(NULL, "popupmenuitem.class",
PMIA_ID, MENU_OPT1,
PMIA_Icon, OBJ(GID_BITMAP1) = IIntuition->NewObject(BitMapClass, NULL,
BITMAP_SourceFile, keymap0Flag,
BITMAP_Screen, dd->scr,
BITMAP_Masking, TRUE,
TAG_DONE),
PMIA_Title, dd->KeymapName[0],
TAG_END);
item2 = IIntuition->NewObject(NULL, "popupmenuitem.class",
PMIA_ID, MENU_OPT2,
PMIA_Icon, OBJ(GID_BITMAP2) = IIntuition->NewObject(BitMapClass, NULL,
BITMAP_SourceFile, keymap1Flag,
BITMAP_Screen, dd->scr,
BITMAP_Masking, TRUE,
TAG_DONE),
PMIA_Title, dd->KeymapName[1],
TAG_END);
item3 = IIntuition->NewObject(NULL, "popupmenuitem.class",
PMIA_ID, MENU_OPT3,
PMIA_Icon, OBJ(GID_BITMAP3) = IIntuition->NewObject(BitMapClass, NULL,
BITMAP_SourceFile, keymap2Flag,
BITMAP_Screen, dd->scr,
BITMAP_Masking, TRUE,
TAG_DONE),
PMIA_Title, dd->KeymapName[2],
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);
// if(!item2) 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(item3 && 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;
break;
case MENU_OPT2:
#ifdef MDEBUG
IDOS->Printf("'%s'\n",dd->KeymapName[1]);
#endif
dd->km_pos = 2;
break;
case MENU_OPT3:
#ifdef MDEBUG
IDOS->Printf("'%s'\n",dd->KeymapName[2]);
#endif
dd->km_pos = 3;
break;
case MENU_PREFS:
{
#ifdef MDEBUG
IDOS->Printf("Settings...\n");
#endif
#ifdef NEWPROC
PrefsWindow_NP(Self, dd);
#else
OpenPrefsWindow(dd);
#endif
}
break;
}
}
return(0);
}