- /* special treatment for text and number input gadgets */
- if (anyTextInputGadgetActive() && button != 0 && !motion_status)
- {
- struct GadgetInfo *gi = last_gi;
-
- if (new_gi == last_gi)
- {
- int old_cursor_position = gi->textinput.cursor_position;
-
- /* if mouse button pressed inside activated text gadget, set cursor */
- gi->textinput.cursor_position =
- (mx - gi->x - gi->border.xsize) / getFontWidth(gi->font);
-
- if (gi->textinput.cursor_position < 0)
- gi->textinput.cursor_position = 0;
- else if (gi->textinput.cursor_position > strlen(gi->textinput.value))
- gi->textinput.cursor_position = strlen(gi->textinput.value);
-
- if (gi->textinput.cursor_position != old_cursor_position)
- DrawGadget(gi, DG_PRESSED, gi->direct_draw);
- }
- else
- {
- /* if mouse button pressed outside text input gadget, deactivate it */
- CheckRangeOfNumericInputGadget(gi);
- DrawGadget(gi, DG_UNPRESSED, gi->direct_draw);
-
- gi->event.type = GD_EVENT_TEXT_LEAVING;
-
- if (gi->event_mask & GD_EVENT_TEXT_LEAVING)
- gi->callback_action(gi);
-
- last_gi = NULL;
- }
- }
-
- /* special treatment for text area gadgets */
- if (anyTextAreaGadgetActive() && button != 0 && !motion_status)
- {
- struct GadgetInfo *gi = last_gi;
-
- if (new_gi == last_gi)
- {
- int old_cursor_position = gi->textarea.cursor_position;
- int x = (mx - gi->x - gi->border.xsize) / getFontWidth(gi->font);
- int y = (my - gi->y - gi->border.ysize) / getFontHeight(gi->font);
-
- x = (x < 0 ? 0 : x >= gi->textarea.xsize ? gi->textarea.xsize - 1 : x);
- y = (y < 0 ? 0 : y >= gi->textarea.ysize ? gi->textarea.ysize - 1 : y);
-
- setTextAreaCursorXY(gi, x, y);
-
-#if 0
- printf("::: %d -----> %d\n",
- old_cursor_position,
- gi->textarea.cursor_position);
-#endif
-
- if (gi->textarea.cursor_position != old_cursor_position)
- DrawGadget(gi, DG_PRESSED, gi->direct_draw);
- }
- else
- {
- /* if mouse button pressed outside text input gadget, deactivate it */
- DrawGadget(gi, DG_UNPRESSED, gi->direct_draw);
-
- gi->event.type = GD_EVENT_TEXT_LEAVING;
-
- if (gi->event_mask & GD_EVENT_TEXT_LEAVING)
- gi->callback_action(gi);
-
- last_gi = NULL;
- }
- }
-
- /* special treatment for selectbox gadgets */
- if (anySelectboxGadgetActive() && button != 0 && !motion_status)
- {
- struct GadgetInfo *gi = last_gi;
-
- if (new_gi == last_gi)
- {
- int old_index = gi->selectbox.current_index;
-
- /* if mouse button pressed inside activated selectbox, select value */
- if (my >= gi->selectbox.y && my < gi->selectbox.y + gi->selectbox.height)
- gi->selectbox.current_index =
- (my - gi->selectbox.y - gi->border.ysize) / getFontHeight(gi->font);
-
- if (gi->selectbox.current_index < 0)
- gi->selectbox.current_index = 0;
- else if (gi->selectbox.current_index > gi->selectbox.num_values - 1)
- gi->selectbox.current_index = gi->selectbox.num_values - 1;
-
- if (gi->selectbox.current_index != old_index)
- DrawGadget(gi, DG_PRESSED, gi->direct_draw);
- }
- else
- {
- /* if mouse button pressed outside selectbox gadget, deactivate it */
- DrawGadget(gi, DG_UNPRESSED, gi->direct_draw);
-
- gi->event.type = GD_EVENT_TEXT_LEAVING;
-
- if (gi->event_mask & GD_EVENT_TEXT_LEAVING)
- gi->callback_action(gi);
-
- last_gi = NULL;
- }
- }
-
-#endif
-
- gadget_pressed =
- (button != 0 && last_gi == NULL && new_gi != NULL && press_event);
- gadget_pressed_repeated =
- (button != 0 && last_gi != NULL && new_gi == last_gi);