-
Notifications
You must be signed in to change notification settings - Fork 0
/
ChooseKeymapWin.c
257 lines (223 loc) · 7.54 KB
/
ChooseKeymapWin.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
244
245
246
247
248
249
250
251
252
253
254
255
256
//#define WDEBUG
#include "dockybase.h"
#include <proto/keymap.h>
#include "DockWindow.h"
#include "KeyMapSwitcher_rev.h"
extern struct ExecIFace *IExec;
extern struct KeymapIFace *IKeymap;
extern struct IntuitionIFace *IIntuition;
// the class pointer
extern Class *ButtonClass, *BitMapClass, *LayoutClass, *WindowClass;
extern Object *Objects[LAST_NUM];
#define OBJ(x) Objects[x]
#define GAD(x) (struct Gadget *)Objects[x]
extern char keymap0Flag[1024], keymap1Flag[1024], keymap2Flag[1024];
extern void DoMessage(char *, char, struct DockyData *);
Object *win2;
struct Window *window2;
uint32 wsignal = 0;
void OpenDockWindow(struct DockyData *dd)
{
//extern BOOL WinBorders;
extern BOOL KM3;
/*
if(dd->scaleflag == 1.0)
{
dd->size.width += 8; // adds space image<->button_frame
dd->size.height += 8; // adds space image<->button_frame
}*/
win2 = IIntuition->NewObject(WindowClass, NULL,
//WA_ScreenTitle, VERS" "DATE,
WA_CustomScreen, (long)dd->scr,
WA_Activate, TRUE,
WA_DepthGadget, FALSE,
WA_DragBar, FALSE,
WA_CloseGadget, FALSE,
WA_SizeGadget, FALSE,
//WA_ToolBox, TRUE,
//WA_SmartRefresh, TRUE,
WINDOW_NewMenu, NULL, // enabling RMB (WMHI_MENUPICK)
//WINDOW_GadgetHelp, TRUE, // gadgethelp on/off
//WA_Borderless, WinBorders,
WINDOW_Position, WPOS_CENTERMOUSE,
WINDOW_Layout, OBJ(OBJ_MAIN) = IIntuition->NewObject(LayoutClass, NULL,
//LAYOUT_Orientation, LAYOUT_ORIENT_VERT,
LAYOUT_SpaceOuter, TRUE,
LAYOUT_InnerSpacing, 6,
LAYOUT_AddChild, OBJ(OBJ_BTN1) = IIntuition->NewObject(ButtonClass, NULL,
GA_ID, OBJ_BTN1,
GA_RelVerify, TRUE,
GA_Underscore, ~0,
BUTTON_BevelStyle, BVS_THIN,
//BUTTON_Transparent, TRUE,
BUTTON_RenderImage, OBJ(GID_KM1) = IIntuition->NewObject(BitMapClass, NULL,
IA_Width, /*dd->size.width*/IMG_W + 8,
IA_Height, /*dd->size.height*/IMG_H + 8,
IA_Scalable, dd->scaleflag > 1.0? TRUE:FALSE,
BITMAP_SourceFile, keymap0Flag,
BITMAP_Screen, dd->scr,
BITMAP_Masking, TRUE,
//BITMAP_Transparent,TRUE,
TAG_DONE),
TAG_DONE),
LAYOUT_AddChild, OBJ(OBJ_BTN2) = IIntuition->NewObject(ButtonClass, NULL,
GA_ID, OBJ_BTN2,
GA_RelVerify, TRUE,
GA_Underscore, ~0,
BUTTON_BevelStyle, BVS_THIN,
//BUTTON_Transparent, TRUE,
BUTTON_RenderImage, OBJ(GID_KM2) = IIntuition->NewObject(BitMapClass, NULL,
IA_Width, /*dd->size.width*/IMG_W + 8,
IA_Height, /*dd->size.height*/IMG_H + 8,
IA_Scalable, dd->scaleflag > 1.0? TRUE:FALSE,
BITMAP_SourceFile, keymap1Flag,
BITMAP_Screen, dd->scr,
BITMAP_Masking, TRUE,
//BITMAP_Transparent,TRUE,
TAG_DONE),
TAG_DONE),
TAG_DONE),
TAG_END);
// languages NOT valid/available
if( !OBJ(GID_KM1) )
IIntuition->SetAttrs(OBJ(OBJ_BTN1), GA_Text,dd->KeymapName[0], GA_Disabled,TRUE, TAG_DONE);
if( !OBJ(GID_KM2) )
IIntuition->SetAttrs(OBJ(OBJ_BTN2), GA_Text,dd->KeymapName[1], GA_Disabled,TRUE, TAG_DONE);
if(KM3) // if set add KEYMAP3 button
{
OBJ(OBJ_BTN3) = IIntuition->NewObject(ButtonClass, NULL,
GA_ID, OBJ_BTN3,
GA_RelVerify, TRUE,
GA_Underscore, ~0,
BUTTON_BevelStyle, BVS_THIN,
//BUTTON_Transparent, TRUE,
BUTTON_RenderImage, OBJ(GID_KM3) = IIntuition->NewObject(BitMapClass, NULL,
IA_Width, /*dd->size.width*/IMG_W + 8,
IA_Height, /*dd->size.height*/IMG_H + 8,
IA_Scalable, dd->scaleflag > 1.0? TRUE:FALSE,
BITMAP_SourceFile, keymap2Flag,
BITMAP_Screen, dd->scr,
BITMAP_Masking, TRUE,
//BITMAP_Transparent,TRUE,
TAG_DONE),
TAG_DONE);
if( !OBJ(GID_KM3) ) // language NOT valid/available
IIntuition->SetAttrs(OBJ(OBJ_BTN3), GA_Text,dd->KeymapName[2], GA_Disabled,TRUE, TAG_DONE);
/*
struct lmAddChild msg;
msg.MethodID = LM_ADDCHILD;
msg.lm_Window = window2;
msg.lm_Object = OBJ(OBJ_BTN3);
msg.lm_ObjectAttrs = NULL;
IIntuition->IDoMethodA(OBJ(OBJ_MAIN), (void*)&msg);
*/
IIntuition->IDoMethod(OBJ(OBJ_MAIN), LM_ADDCHILD, window2, OBJ(OBJ_BTN3), NULL);
}
if(win2)
{
if( (window2=(struct Window *)IIntuition->IDoMethod(win2, WM_OPEN, NULL)) )
{
IIntuition->GetAttr(WINDOW_SigMask, win2, &wsignal); // obtain the window wait signal mask.
// Input Event Loop
while( !ProcessDockWindow(dd) );
IIntuition->IDoMethod(win2, WM_CLOSE, NULL);
} // END if(window2[WID_MAIN])
FreeDockWindow();
} // END if(win[OID_MAIN])
}
void FreeDockWindow(void)
{
IIntuition->DisposeObject( OBJ(GID_KM1) );
IIntuition->DisposeObject( OBJ(GID_KM2) );
IIntuition->DisposeObject( OBJ(GID_KM3) );
OBJ(GID_KM1) = NULL;
OBJ(GID_KM2) = NULL;
OBJ(GID_KM3) = NULL;
IIntuition->DisposeObject(win2);
// if(!window2)
win2 = NULL; // V52.2: give "option" to use RMB with DOCKY_1CLICK=YES
// else
window2 = NULL;
}
BOOL ProcessDockWindow(struct DockyData *dd)
{
uint32 wait = IExec->Wait(wsignal);
if(wait & wsignal)
{
uint32 result = WMHI_LASTMSG;
int16 code = 0;
while( (result = IIntuition->IDoMethod(win2, WM_HANDLEINPUT, &code)) != WMHI_LASTMSG )
{
#ifdef WDEBUG
IDOS->Printf("%08lx code=%ld\n",result,code);
#endif
switch(result & WMHI_CLASSMASK)
{
case WMHI_MENUPICK: // clicked RMB
window2 = NULL; // V52.2: give "option" to use RMB with DOCKY_1CLICK=YES
case WMHI_INACTIVE: // clicked outside DockWindow
#ifdef WDEBUG
IDOS->Printf("WMHI_MENUPICK or WMHI_INACTIVE\n");
#endif
return TRUE;
break;
case WMHI_GADGETUP:
#ifdef WDEBUG
IDOS->Printf("WMHI_GADGETUP (%08lx)\n",result);
#endif
switch(result & WMHI_GADGETMASK)
{
case OBJ_BTN1:
dd->km_pos = 1;
return TRUE;
break;
case OBJ_BTN2:
dd->km_pos = 2;
return TRUE;
break;
case OBJ_BTN3:
dd->km_pos = 3;
return TRUE;
break;
} // END switch(result & WMHI_GADGETMASK)
break;
} // END switch(result & WMHI_CLASSMASK)
} // END while( (result..
} // if(wait & wsignal)
return FALSE;
}
BOOL ChangeKeymap(struct DockyData *dd, STRPTR keymap)
{
APTR KM_handle;
BOOL res = FALSE;
struct KeyMapNode *kmn = NULL;
//IDOS->Printf("ChangeKeymap(%s, %s)\n",keymap,dd->keymapSel);
if(IUtility->Stricmp(keymap, dd->keymapSel) != 0) // only if keymap changed
{
if( (KM_handle = IKeymap->OpenKeyMapHandle(keymap)) )
{
if( IKeymap->ObtainKeyMapInfo(KM_handle, KEYMAPINFO_KEYMAPNODE,&kmn, TAG_END) )
{
#ifdef WDEBUG
IDOS->Printf("Changing keymap from '%s' to '%s'...\n",dd->keymapSel,kmn->kn_Node.ln_Name);
#endif
IKeymap->SetKeyMapDefault( &(kmn->kn_KeyMap) );
//IUtility->Strlcpy( dd->keymapSel, kmn->kn_Node.ln_Name, sizeof(dd->keymapSel) );
res = TRUE;
}
else
{
IUtility->VSNPrintf(textbuf, sizeof(textbuf), GetString(&li, MSG_ERROR_CANTCHANGE),&keymap);
DoMessage(textbuf, REQIMAGE_WARNING, dd);
}
IKeymap->CloseKeyMapHandle(KM_handle);
} // END if( (KM_handle =..
else
{
IUtility->VSNPrintf(textbuf, sizeof(textbuf), GetString(&li, MSG_ERROR_KEYMAP),&keymap);
DoMessage(textbuf, REQIMAGE_ERROR, dd);
}
} // END if(IUtility->Stricmp..
//IDOS->Printf("ChangeKeymap=%ld\n",res);
return(res);
}