- static struct GadgetInfo *last_info_gi = NULL;
- static unsigned long pressed_delay = 0;
- static int last_button = 0;
- static int last_mx = 0, last_my = 0;
- int scrollbar_mouse_pos = 0;
- struct GadgetInfo *new_gi, *gi;
- boolean press_event;
- boolean release_event;
- boolean mouse_moving;
- boolean gadget_pressed;
- boolean gadget_pressed_repeated;
- boolean gadget_moving;
- boolean gadget_moving_inside;
- boolean gadget_moving_off_borders;
- boolean gadget_released;
+ return (anyTextInputGadgetActive() ||
+ anyTextAreaGadgetActive() ||
+ anySelectboxGadgetActive());
+}
+
+static boolean insideSelectboxLine(struct GadgetInfo *gi, int mx, int my)
+{
+ return (gi != NULL &&
+ gi->type & GD_TYPE_SELECTBOX &&
+ mx >= gi->x && mx < gi->x + gi->width &&
+ my >= gi->y && my < gi->y + gi->height);
+}
+
+static boolean insideSelectboxArea(struct GadgetInfo *gi, int mx, int my)
+{
+ return (gi != NULL &&
+ gi->type & GD_TYPE_SELECTBOX &&
+ mx >= gi->selectbox.x && mx < gi->selectbox.x + gi->selectbox.width &&
+ my >= gi->selectbox.y && my < gi->selectbox.y + gi->selectbox.height);
+}
+
+void ClickOnGadget(struct GadgetInfo *gi, int button)
+{
+ if (gi == NULL || gi->deactivated || !gi->mapped)
+ return;
+
+ // simulate releasing mouse button over last gadget, if still pressed
+ 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(x, y, button);
+
+ // simulate releasing mouse button over specified gadget
+ HandleGadgets(x, y, 0);
+}
+
+boolean HandleGadgets(int mx, int my, int button)
+{
+ static unsigned int pressed_delay = 0;
+ static unsigned int pressed_delay_value = GADGET_FRAME_DELAY;
+ static int last_button = 0;
+ static int last_mx = 0, last_my = 0;
+ static int pressed_mx = 0, pressed_my = 0;
+ static boolean keep_selectbox_open = FALSE;
+ static boolean gadget_stopped = FALSE;
+ int scrollbar_mouse_pos = 0;
+ struct GadgetInfo *new_gi, *gi;
+ boolean press_event;
+ boolean release_event;
+ boolean mouse_moving;
+ boolean mouse_inside_select_line;
+ boolean mouse_inside_select_area;
+ boolean mouse_released_where_pressed;
+ boolean gadget_pressed;
+ boolean gadget_pressed_repeated;
+ boolean gadget_pressed_off_borders;
+ boolean gadget_pressed_inside_select_line;
+ boolean gadget_pressed_delay_reached;
+ boolean gadget_moving;
+ boolean gadget_moving_inside;
+ boolean gadget_moving_off_borders;
+ boolean gadget_draggable;
+ boolean gadget_dragging;
+ boolean gadget_released;