Fix menu shortcuts.

[GB.GTK]
* BUG: Fix menu shortcuts.

[GB.GTK3]
* BUG: Fix menu shortcuts.
This commit is contained in:
gambas 2020-10-23 01:29:51 +02:00
parent 1be0e488fb
commit abf6b9fbcf
5 changed files with 67 additions and 39 deletions

View file

@ -27,16 +27,17 @@
#include <gdk/gdkkeysyms.h>
#include "gkey.h"
//-------------------------------------------------------------------------
BEGIN_METHOD(Key_get, GB_STRING key)
char *key = GB.ToZeroString(ARG(key));
if (!GB.GetProperty((void *)GB.FindClass("Key"), key))
{
GB.Error(NULL);
GB.ReturnInteger(gKey::fromString(GB.ToZeroString(ARG(key))));
}
int val = KEY_get_keyval_from_name(key);
if (!val)
val = gKey::fromString(key);
GB.ReturnInteger(val);
END_METHOD
@ -104,7 +105,6 @@ BEGIN_PROPERTY(Key_Normal)
END_PROPERTY
GB_DESC CKeyDesc[] =
{
GB_DECLARE("Key", 0), GB_VIRTUAL_CLASS(),
@ -182,3 +182,28 @@ GB_DESC CKeyDesc[] =
GB_END_DECLARE
};
//-------------------------------------------------------------------------
int KEY_get_keyval_from_name(const char *name)
{
const GB_DESC *p;
const char *pname;
if (!name || !*name)
return 0;
if (!name[1])
return gKey::fromString(name);
for(p = &CKeyDesc[3]; (pname = p->name); p++)
{
if (*pname != GB_CONSTANT_ID)
continue;
if (strcasecmp(name, &pname[1]) == 0)
return (int)p->val2;
}
return gKey::fromString(name);
}

View file

@ -30,5 +30,6 @@
extern GB_DESC CKeyDesc[];
#endif
int KEY_get_keyval_from_name(const char *name);
#endif

View file

@ -133,7 +133,7 @@ bool gKey::shift()
return state() & GDK_SHIFT_MASK; // || _event.keyval == GDK_Shift_L || _event.keyval == GDK_Shift_R;
}
int gKey::fromString(char *str)
int gKey::fromString(const char *str)
{
char *lstr;
int key;

View file

@ -38,7 +38,7 @@ public:
static bool normal();
static bool shift();
static int fromString(char* str);
static int fromString(const char *str);
//"Private"
static void disable();

View file

@ -31,6 +31,8 @@
// HTML character entities
#include "kentities.h"
#include "CKey.h"
void stub(const char *function)
{
printf("gb.gtk: warning: %s not yet implemented\n", function);
@ -799,47 +801,47 @@ GdkPixbuf *gt_pixbuf_create_disabled(GdkPixbuf *img)
void gt_shortcut_parse(char *shortcut, guint *key, GdkModifierType *mods)
{
gchar **cads;
gchar *res;
int bucle;
char **tokens;
char *token;
int i;
int m;
res = NULL;
*key = 0;
*mods = (GdkModifierType)0;
m = 0;
if (!shortcut || !*shortcut)
{
*key = 0;
return;
tokens = g_strsplit(shortcut, "+", 0);
i = 0;
while (tokens[i])
{
g_strstrip(tokens[i]);
i++;
}
cads = g_strsplit(shortcut, "+", 0);
bucle = 0;
while (cads[bucle])
for (i = 0; (token = tokens[i]); i++)
{
g_strstrip(cads[bucle]);
bucle++;
}
bucle = 0;
while (cads[bucle])
{
if (!strcasecmp(cads[bucle],"ctrl"))
g_stradd(&res, "<Ctrl>");
else if (!strcasecmp(cads[bucle],"shift"))
g_stradd(&res, "<Shift>");
else if (!strcasecmp(cads[bucle],"alt"))
g_stradd(&res, "<Alt>");
if (!strcasecmp(token, "ctrl") || !strcasecmp(token, "control"))
m |= GDK_CONTROL_MASK;
else if (!strcasecmp(token, "shift"))
m |= GDK_SHIFT_MASK;
else if (!strcasecmp(token, "alt"))
m |= GDK_MOD1_MASK;
else
g_stradd(&res, cads[bucle]);
bucle++;
{
*key = KEY_get_keyval_from_name(token);
*mods = (GdkModifierType)m;
break;
}
}
g_strfreev(cads);
gtk_accelerator_parse(res, key, mods);
g_strfreev(tokens);
if (res)
g_free(res);
//fprintf(stderr, "gt_shortcut_parse: %s -> %d / %d\n", shortcut, *key, m);
}
#define MAX_FREE_LATER 16