return id;
}
-#if 0
-void DUMP_GADGET_MAP_STATE()
-{
- struct GadgetInfo *gi = gadget_list_first_entry;
-
- while (gi != NULL)
- {
- printf("-XXX-1-> '%s': %s\n",
- gi->info_text, (gi->mapped ? "mapped" : "not mapped"));
-
- gi = gi->next;
- }
-}
-#endif
-
static struct GadgetInfo *getGadgetInfoFromMousePosition(int mx, int my)
{
struct GadgetInfo *gi;
static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct)
{
+ struct GadgetDesign *gd;
int state = (pressed ? GD_BUTTON_PRESSED : GD_BUTTON_UNPRESSED);
- struct GadgetDesign *gd = (!gi->active ? &gi->alt_design[state] :
- gi->checked ? &gi->alt_design[state] :
- &gi->design[state]);
boolean redraw_selectbox = FALSE;
+ if (gi == NULL)
+ return;
+
+ gd = (!gi->active ? &gi->alt_design[state] :
+ gi->checked ? &gi->alt_design[state] : &gi->design[state]);
+
switch (gi->type)
{
case GD_TYPE_NORMAL_BUTTON:
{
int tag = first_tag;
+ if (gi == NULL)
+ return;
+
while (tag != GDI_END)
{
switch(tag)
break;
case GDI_TYPE:
- gi->type = va_arg(ap, unsigned long);
+ gi->type = va_arg(ap, unsigned int);
break;
case GDI_STATE:
- gi->state = va_arg(ap, unsigned long);
+ gi->state = va_arg(ap, unsigned int);
break;
case GDI_ACTIVE:
break;
case GDI_RADIO_NR:
- gi->radio_nr = va_arg(ap, unsigned long);
+ gi->radio_nr = va_arg(ap, unsigned int);
break;
case GDI_NUMBER_VALUE:
- gi->textinput.number_value = va_arg(ap, long);
+ gi->textinput.number_value = va_arg(ap, int);
sprintf(gi->textinput.value, "%d", gi->textinput.number_value);
+ strcpy(gi->textinput.last_value, gi->textinput.value);
gi->textinput.cursor_position = strlen(gi->textinput.value);
break;
case GDI_NUMBER_MIN:
- gi->textinput.number_min = va_arg(ap, long);
+ gi->textinput.number_min = va_arg(ap, int);
if (gi->textinput.number_value < gi->textinput.number_min)
{
gi->textinput.number_value = gi->textinput.number_min;
sprintf(gi->textinput.value, "%d", gi->textinput.number_value);
+ strcpy(gi->textinput.last_value, gi->textinput.value);
}
break;
case GDI_NUMBER_MAX:
- gi->textinput.number_max = va_arg(ap, long);
+ gi->textinput.number_max = va_arg(ap, int);
if (gi->textinput.number_value > gi->textinput.number_max)
{
gi->textinput.number_value = gi->textinput.number_max;
sprintf(gi->textinput.value, "%d", gi->textinput.number_value);
+ strcpy(gi->textinput.last_value, gi->textinput.value);
}
break;
max_textsize = MIN(gi->textinput.size, MAX_GADGET_TEXTSIZE - 1);
strncpy(gi->textinput.value, va_arg(ap, char *), max_textsize);
+ strcpy(gi->textinput.last_value, gi->textinput.value);
+
gi->textinput.value[max_textsize] = '\0';
gi->textinput.cursor_position = strlen(gi->textinput.value);
/* same tag also used for other gadget definitions */
strcpy(gi->textbutton.value, gi->textinput.value);
strcpy(gi->textarea.value, gi->textinput.value);
+ strcpy(gi->textarea.last_value, gi->textinput.value);
}
break;
gi->textinput.size = max_textsize;
gi->textinput.value[max_textsize] = '\0';
+ strcpy(gi->textinput.last_value, gi->textinput.value);
/* same tag also used for other gadget definitions */
- strcpy(gi->textbutton.value, gi->textinput.value);
- gi->textbutton.size = gi->textinput.size;
+
+ gi->textarea.size = max_textsize;
+ gi->textarea.value[max_textsize] = '\0';
+ strcpy(gi->textarea.last_value, gi->textinput.value);
+
+ gi->textbutton.size = max_textsize;
+ gi->textbutton.value[max_textsize] = '\0';
+
gi->selectbox.size = gi->textinput.size;
}
break;
break;
case GDI_EVENT_MASK:
- gi->event_mask = va_arg(ap, unsigned long);
+ gi->event_mask = va_arg(ap, unsigned int);
break;
case GDI_AREA_SIZE:
getFontCharSource(font_nr, FONT_ASCII_CURSOR, &src_bitmap, &src_x, &src_y);
src_x += font_width / 2;
src_y += font_height / 2;
- gi->selectbox.inverse_color = GetPixel(src_bitmap, src_x, src_y);
+
+ /* there may be esoteric cases with missing or too small font bitmap */
+ if (src_bitmap != NULL &&
+ src_x < src_bitmap->width && src_y < src_bitmap->height)
+ gi->selectbox.inverse_color = GetPixel(src_bitmap, src_x, src_y);
/* always start with closed selectbox */
gi->selectbox.open = FALSE;
if (gi->type & GD_TYPE_SCROLLBAR)
{
struct GadgetScrollbar *gs = &gi->scrollbar;
+ int scrollbar_size_cmp;
if (gi->width == 0 || gi->height == 0 ||
gs->items_max == 0 || gs->items_visible == 0)
Error(ERR_EXIT, "scrollbar gadget incomplete (missing tags)");
/* calculate internal scrollbar values */
+ gs->size_min = (gi->type == GD_TYPE_SCROLLBAR_VERTICAL ?
+ gi->width : gi->height);
gs->size_max = (gi->type == GD_TYPE_SCROLLBAR_VERTICAL ?
gi->height : gi->width);
- gs->size = gs->size_max * gs->items_visible / gs->items_max;
- gs->position = gs->size_max * gs->item_position / gs->items_max;
+
+ scrollbar_size_cmp = gs->size_max * gs->items_visible / gs->items_max;
+ gs->size = MAX(scrollbar_size_cmp, gs->size_min);
+ gs->size_max_cmp = (gs->size_max - (gs->size - scrollbar_size_cmp));
+
+ gs->position = gs->size_max_cmp * gs->item_position / gs->items_max;
gs->position_max = gs->size_max - gs->size;
gs->correction = gs->size_max / gs->items_max / 2;
void RedrawGadget(struct GadgetInfo *gi)
{
+ if (gi == NULL)
+ return;
+
if (gi->mapped)
DrawGadget(gi, gi->state, gi->direct_draw);
}
MultiMapGadgets(MULTIMAP_ALL | MULTIMAP_REMAP);
}
-static boolean anyTextInputGadgetActive()
+boolean anyTextInputGadgetActive()
{
return (last_gi && (last_gi->type & GD_TYPE_TEXT_INPUT) && last_gi->mapped);
}
-static boolean anyTextAreaGadgetActive()
+boolean anyTextAreaGadgetActive()
{
return (last_gi && (last_gi->type & GD_TYPE_TEXT_AREA) && last_gi->mapped);
}
-static boolean anySelectboxGadgetActive()
+boolean anySelectboxGadgetActive()
{
return (last_gi && (last_gi->type & GD_TYPE_SELECTBOX) && last_gi->mapped);
}
+boolean anyScrollbarGadgetActive()
+{
+ return (last_gi && (last_gi->type & GD_TYPE_SCROLLBAR) && last_gi->mapped);
+}
+
+boolean anyTextGadgetActive()
+{
+ return (anyTextInputGadgetActive() ||
+ anyTextAreaGadgetActive() ||
+ anySelectboxGadgetActive());
+}
+
static boolean insideSelectboxLine(struct GadgetInfo *gi, int mx, int my)
{
return(gi != NULL &&
my >= gi->selectbox.y && my < gi->selectbox.y + gi->selectbox.height);
}
-boolean anyTextGadgetActive()
-{
- return (anyTextInputGadgetActive() ||
- anyTextAreaGadgetActive() ||
- anySelectboxGadgetActive());
-}
-
void ClickOnGadget(struct GadgetInfo *gi, int button)
{
+ if (!gi->mapped)
+ return;
+
/* simulate releasing mouse button over last gadget, if still pressed */
if (button_status)
HandleGadgets(-1, -1, 0);
insideSelectboxLine(new_gi, mx, my));
/* if mouse button pressed outside text or selectbox gadget, deactivate it */
-#if 1
if (anyTextGadgetActive() &&
(gadget_pressed_off_borders ||
(gadget_pressed_inside_select_line && !mouse_inside_select_area)))
-#else
- if (anyTextGadgetActive() &&
- button != 0 && !motion_status && new_gi != last_gi)
-#endif
{
- CheckRangeOfNumericInputGadget(last_gi); /* in case of numeric gadget */
+ struct GadgetInfo *gi = last_gi;
+ boolean gadget_changed = (gi->event_mask & GD_EVENT_TEXT_LEAVING);
- DrawGadget(last_gi, DG_UNPRESSED, last_gi->direct_draw);
+ /* check if text gadget has changed its value */
+ if (gi->type & GD_TYPE_TEXT_INPUT)
+ {
+ CheckRangeOfNumericInputGadget(gi);
+
+ if (strcmp(gi->textinput.value, gi->textinput.last_value) != 0)
+ strcpy(gi->textinput.last_value, gi->textinput.value);
+ else
+ gadget_changed = FALSE;
+ }
+
+ /* selectbox does not change its value when closed by clicking outside */
+ if (gi->type & GD_TYPE_SELECTBOX)
+ gadget_changed = FALSE;
- last_gi->event.type = GD_EVENT_TEXT_LEAVING;
+ DrawGadget(gi, DG_UNPRESSED, gi->direct_draw);
- if (last_gi->event_mask & GD_EVENT_TEXT_LEAVING)
- last_gi->callback_action(last_gi);
+ gi->event.type = GD_EVENT_TEXT_LEAVING;
+
+ if (gadget_changed && !(gi->type & GD_TYPE_SELECTBOX))
+ gi->callback_action(gi);
last_gi = NULL;
/* when handling selectbox, set additional state values */
if (gadget_released_inside && (last_gi->type & GD_TYPE_SELECTBOX))
{
- struct GadgetInfo *gi = last_gi;
-
-#if 1
- gadget_released_inside_select_line = insideSelectboxLine(gi, mx, my);
- gadget_released_inside_select_area = insideSelectboxArea(gi, mx, my);
-#else
- gadget_released_inside_select_line =
- (mx >= gi->x && mx < gi->x + gi->width &&
- my >= gi->y && my < gi->y + gi->height);
- gadget_released_inside_select_area =
- (mx >= gi->selectbox.x && mx < gi->selectbox.x + gi->selectbox.width &&
- my >= gi->selectbox.y && my < gi->selectbox.y + gi->selectbox.height);
-#endif
+ gadget_released_inside_select_line = insideSelectboxLine(last_gi, mx, my);
+ gadget_released_inside_select_area = insideSelectboxArea(last_gi, mx, my);
}
else
{
/* if mouse button released, no gadget needs to be handled anymore */
if (gadget_released)
{
-#if 1
if (gi->type & GD_TYPE_SELECTBOX &&
(mouse_released_where_pressed ||
!gadget_released_inside_select_area)) /* selectbox stays open */
pressed_mx = 0;
pressed_my = 0;
}
-#else
- if (gi->type & GD_TYPE_SELECTBOX &&
- (gadget_released_inside_select_line ||
- gadget_released_off_borders)) /* selectbox stays open */
- gi->selectbox.stay_open = TRUE;
-#endif
else if (!(gi->type & GD_TYPE_TEXT_INPUT ||
gi->type & GD_TYPE_TEXT_AREA)) /* text input stays open */
last_gi = NULL;
if (gs->item_position < 0)
gs->item_position = 0;
- if (gs->item_position > gs->items_max - gs->items_visible)
+ else if (gs->item_position > gs->items_max - gs->items_visible)
gs->item_position = gs->items_max - gs->items_visible;
if (old_item_position != gs->item_position)
gs->position = scrollbar_mouse_pos - gs->drag_position;
- if (gs->position < 0)
+ /* make sure to always precisely reach end positions when dragging */
+ if (gs->position <= 0)
+ {
gs->position = 0;
- if (gs->position > gs->position_max)
+ gs->item_position = 0;
+ }
+ else if (gs->position >= gs->position_max)
+ {
gs->position = gs->position_max;
-
- gs->item_position =
- gs->items_max * (gs->position + gs->correction) / gs->size_max;
+ gs->item_position = gs->items_max - gs->items_visible;
+ }
+ else
+ {
+ gs->item_position =
+ gs->items_max * (gs->position + gs->correction) / gs->size_max_cmp;
+ }
if (gs->item_position < 0)
gs->item_position = 0;
if (gadget_released_inside)
{
boolean deactivate_gadget = TRUE;
+ boolean gadget_changed = TRUE;
if (gi->type & GD_TYPE_SELECTBOX)
{
-#if 1
if (mouse_released_where_pressed ||
!gadget_released_inside_select_area) /* selectbox stays open */
+ {
deactivate_gadget = FALSE;
-#else
- if (gadget_released_inside_select_line ||
- gadget_released_off_borders) /* selectbox stays open */
- deactivate_gadget = FALSE;
-#endif
- else
+ gadget_changed = FALSE;
+ }
+ else if (gi->selectbox.index != gi->selectbox.current_index)
gi->selectbox.index = gi->selectbox.current_index;
+ else
+ gadget_changed = FALSE;
}
if (deactivate_gadget &&
gi->state = GD_BUTTON_UNPRESSED;
gi->event.type = GD_EVENT_RELEASED;
- if ((gi->event_mask & GD_EVENT_RELEASED) && deactivate_gadget)
+ if ((gi->event_mask & GD_EVENT_RELEASED) && gadget_changed)
+ {
gi->callback_action(gi);
+ }
}
if (gadget_released_off_borders)
if (key == KSYM_Return) /* valid for both text input and selectbox */
{
+ boolean gadget_changed = (gi->event_mask & GD_EVENT_TEXT_RETURN);
+
if (gi->type & GD_TYPE_TEXT_INPUT)
+ {
CheckRangeOfNumericInputGadget(gi);
+
+ if (strcmp(gi->textinput.value, gi->textinput.last_value) != 0)
+ strcpy(gi->textinput.last_value, gi->textinput.value);
+ else
+ gadget_changed = FALSE;
+ }
else if (gi->type & GD_TYPE_SELECTBOX)
- gi->selectbox.index = gi->selectbox.current_index;
+ {
+ if (gi->selectbox.index != gi->selectbox.current_index)
+ gi->selectbox.index = gi->selectbox.current_index;
+ else
+ gadget_changed = FALSE;
+ }
if (gi->type & GD_TYPE_TEXT_AREA)
{
last_gi = NULL;
}
- if (gi->event_mask & GD_EVENT_TEXT_RETURN)
+ if (gadget_changed)
gi->callback_action(gi);
}
else if (gi->type & GD_TYPE_TEXT_INPUT) /* only valid for text input */