return gi;
}
-static int getNewGadgetID()
+static int getNewGadgetID(void)
{
int id = next_free_gadget_id++;
return;
}
+static void DoGadgetCallbackAction(struct GadgetInfo *gi, boolean changed)
+{
+ if (changed || gi->callback_action_always)
+ gi->callback_action(gi);
+}
+
static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct)
{
struct GadgetDesign *gd;
gi->direct_draw = (boolean)va_arg(ap, int);
break;
+ case GDI_CALLBACK_ACTION_ALWAYS:
+ gi->callback_action_always = (boolean)va_arg(ap, int);
+ break;
+
case GDI_CHECKED:
gi->checked = (boolean)va_arg(ap, int);
break;
}
}
-void UnmapAllGadgets()
+void UnmapAllGadgets(void)
{
MultiMapGadgets(MULTIMAP_ALL | MULTIMAP_UNMAP);
}
-void RemapAllGadgets()
+void RemapAllGadgets(void)
{
MultiMapGadgets(MULTIMAP_ALL | MULTIMAP_REMAP);
}
-boolean anyTextInputGadgetActive()
+boolean anyTextInputGadgetActive(void)
{
return (last_gi && (last_gi->type & GD_TYPE_TEXT_INPUT) && last_gi->mapped);
}
-boolean anyTextAreaGadgetActive()
+boolean anyTextAreaGadgetActive(void)
{
return (last_gi && (last_gi->type & GD_TYPE_TEXT_AREA) && last_gi->mapped);
}
-boolean anySelectboxGadgetActive()
+boolean anySelectboxGadgetActive(void)
{
return (last_gi && (last_gi->type & GD_TYPE_SELECTBOX) && last_gi->mapped);
}
-boolean anyScrollbarGadgetActive()
+boolean anyScrollbarGadgetActive(void)
{
return (last_gi && (last_gi->type & GD_TYPE_SCROLLBAR) && last_gi->mapped);
}
-boolean anyTextGadgetActive()
+boolean anyTextGadgetActive(void)
{
return (anyTextInputGadgetActive() ||
anyTextAreaGadgetActive() ||
if (button_status)
HandleGadgets(-1, -1, 0);
+ int x = gi->x;
+ int y = gi->y;
+
+ /* set cursor position to the end of the text for text input gadgets */
+ if (gi->type & GD_TYPE_TEXT_INPUT)
+ x = gi->x + gi->width - 1;
+
/* simulate pressing mouse button over specified gadget */
- HandleGadgets(gi->x, gi->y, button);
+ HandleGadgets(x, y, button);
/* simulate releasing mouse button over specified gadget */
- HandleGadgets(gi->x, gi->y, 0);
+ HandleGadgets(x, y, 0);
}
boolean HandleGadgets(int mx, int my, int button)
gi->event.type = GD_EVENT_TEXT_LEAVING;
- if (gadget_changed && !(gi->type & GD_TYPE_SELECTBOX))
- gi->callback_action(gi);
+ if (!(gi->type & GD_TYPE_SELECTBOX))
+ DoGadgetCallbackAction(gi, gadget_changed);
last_gi = NULL;
gi->event.type = GD_EVENT_MOVING;
gi->event.off_borders = FALSE;
- if (gi->event_mask & GD_EVENT_MOVING && changed_position)
- gi->callback_action(gi);
+ if (gi->event_mask & GD_EVENT_MOVING)
+ DoGadgetCallbackAction(gi, changed_position);
return TRUE;
}
gi->event.type = GD_EVENT_MOVING;
gi->event.off_borders = gadget_moving_off_borders;
- if (gi->event_mask & GD_EVENT_MOVING && changed_position &&
+ if (gi->event_mask & GD_EVENT_MOVING &&
(gadget_moving_inside || gi->event_mask & GD_EVENT_OFF_BORDERS))
- gi->callback_action(gi);
+ DoGadgetCallbackAction(gi, changed_position);
}
if (gadget_released_inside)
gi->state = GD_BUTTON_UNPRESSED;
gi->event.type = GD_EVENT_RELEASED;
- if ((gi->event_mask & GD_EVENT_RELEASED) && gadget_changed)
- {
- gi->callback_action(gi);
- }
+ if ((gi->event_mask & GD_EVENT_RELEASED))
+ DoGadgetCallbackAction(gi, gadget_changed);
}
if (gadget_released_off_borders)
last_gi = NULL;
}
- if (gadget_changed)
- gi->callback_action(gi);
+ DoGadgetCallbackAction(gi, gadget_changed);
}
else if (gi->type & GD_TYPE_TEXT_INPUT) /* only valid for text input */
{
return TRUE;
}
-void DumpGadgetIdentifiers()
+void DumpGadgetIdentifiers(void)
{
struct GadgetInfo *gi;
- printf("Gadgets on current screen (any prefix 'gfx.' can be omitted):\n");
+ Print("Gadgets on current screen:\n");
for (gi = gadget_list_first_entry; gi != NULL; gi = gi->next)
+ {
if (gi->mapped && gi->image_id != -1)
- printf("- '%s'\n", getTokenFromImageID(gi->image_id));
+ {
+ char *token = getTokenFromImageID(gi->image_id);
+ char *prefix = "gfx.";
+
+ if (strPrefix(token, prefix))
+ token = &token[strlen(prefix)];
+
+ Print("- '%s'\n", token);
+ }
+ }
- printf("Done.\n");
+ Print("Done.\n");
}
boolean DoGadgetAction(int image_id)