-static void DrawGadget(struct GadgetInfo *gi, boolean pressed, boolean direct)
-{
- int state = (pressed ? 1 : 0);
- struct GadgetDesign *gd = (gi->checked ?
- &gi->alt_design[state] :
- &gi->design[state]);
-
- switch (gi->type)
- {
- case GD_TYPE_NORMAL_BUTTON:
- case GD_TYPE_CHECK_BUTTON:
- case GD_TYPE_RADIO_BUTTON:
- XCopyArea(display, gd->pixmap, drawto, gc,
- gd->x, gd->y, gi->width, gi->height, gi->x, gi->y);
- if (gi->deco.design.pixmap)
- XCopyArea(display, gi->deco.design.pixmap, drawto, gc,
- gi->deco.design.x, gi->deco.design.y,
- gi->deco.width, gi->deco.height,
- gi->x + gi->deco.x + (pressed ? gi->deco.xshift : 0),
- gi->y + gi->deco.y + (pressed ? gi->deco.yshift : 0));
- break;
-
- case GD_TYPE_TEXTINPUT_ALPHANUMERIC:
- case GD_TYPE_TEXTINPUT_NUMERIC:
- {
- int i;
- char cursor_letter;
- char cursor_string[3];
- char text[MAX_GADGET_TEXTSIZE + 1];
- int font_color = FC_YELLOW;
- int border = gi->design_border;
- strcpy(text, gi->text.value);
- strcat(text, " ");
-
- /* left part of gadget */
- XCopyArea(display, gd->pixmap, drawto, gc,
- gd->x, gd->y, border, gi->height, gi->x, gi->y);
-
- /* middle part of gadget */
- for (i=0; i<=gi->text.size; i++)
- XCopyArea(display, gd->pixmap, drawto, gc,
- gd->x + border, gd->y, FONT2_XSIZE, gi->height,
- gi->x + border + i * FONT2_XSIZE, gi->y);
-
- /* right part of gadget */
- XCopyArea(display, gd->pixmap, drawto, gc,
- gd->x + ED_WIN_COUNT_XSIZE - border, gd->y,
- border, gi->height, gi->x + gi->width - border, gi->y);
-
- /* gadget text value */
- DrawText(gi->x + border, gi->y + border, text, FS_SMALL, font_color);
-
- cursor_letter = gi->text.value[gi->text.cursor_position];
- cursor_string[0] = '~';
- cursor_string[1] = (cursor_letter != '\0' ? cursor_letter : ' ');
- cursor_string[2] = '\0';
-
- /* draw cursor, if active */
- if (pressed)
- DrawText(gi->x + border + gi->text.cursor_position * FONT2_XSIZE,
- gi->y + border, cursor_string, FS_SMALL, font_color);
- }
- break;
-
- case GD_TYPE_SCROLLBAR_VERTICAL:
- {
- int i;
- int xpos = gi->x;
- int ypos = gi->y + gi->scrollbar.position;
- int design_full = gi->width;
- int design_body = design_full - 2 * gi->design_border;
- int size_full = gi->scrollbar.size;
- int size_body = size_full - 2 * gi->design_border;
- int num_steps = size_body / design_body;
- int step_size_remain = size_body - num_steps * design_body;
-
- /* clear scrollbar area */
- XFillRectangle(display, backbuffer, gc,
- gi->x, gi->y, gi->width, gi->height);
-
- /* upper part of gadget */
- XCopyArea(display, gd->pixmap, drawto, gc,
- gd->x, gd->y,
- gi->width, gi->design_border,
- xpos, ypos);
-
- /* middle part of gadget */
- for (i=0; i<num_steps; i++)
- XCopyArea(display, gd->pixmap, drawto, gc,
- gd->x, gd->y + gi->design_border,
- gi->width, design_body,
- xpos, ypos + gi->design_border + i * design_body);
-
- /* remaining middle part of gadget */
- if (step_size_remain > 0)
- XCopyArea(display, gd->pixmap, drawto, gc,
- gd->x, gd->y + gi->design_border,
- gi->width, step_size_remain,
- xpos, ypos + gi->design_border + num_steps * design_body);
-
- /* lower part of gadget */
- XCopyArea(display, gd->pixmap, drawto, gc,
- gd->x, gd->y + design_full - gi->design_border,
- gi->width, gi->design_border,
- xpos, ypos + size_full - gi->design_border);
- }
- break;
-
- case GD_TYPE_SCROLLBAR_HORIZONTAL:
- {
- int i;
- int xpos = gi->x + gi->scrollbar.position;
- int ypos = gi->y;
- int design_full = gi->height;
- int design_body = design_full - 2 * gi->design_border;
- int size_full = gi->scrollbar.size;
- int size_body = size_full - 2 * gi->design_border;
- int num_steps = size_body / design_body;
- int step_size_remain = size_body - num_steps * design_body;
-
- /* clear scrollbar area */
- XFillRectangle(display, backbuffer, gc,
- gi->x, gi->y, gi->width, gi->height);
-
- /* left part of gadget */
- XCopyArea(display, gd->pixmap, drawto, gc,
- gd->x, gd->y,
- gi->design_border, gi->height,
- xpos, ypos);
-
- /* middle part of gadget */
- for (i=0; i<num_steps; i++)
- XCopyArea(display, gd->pixmap, drawto, gc,
- gd->x + gi->design_border, gd->y,
- design_body, gi->height,
- xpos + gi->design_border + i * design_body, ypos);
-
- /* remaining middle part of gadget */
- if (step_size_remain > 0)
- XCopyArea(display, gd->pixmap, drawto, gc,
- gd->x + gi->design_border, gd->y,
- step_size_remain, gi->height,
- xpos + gi->design_border + num_steps * design_body, ypos);
-
- /* right part of gadget */
- XCopyArea(display, gd->pixmap, drawto, gc,
- gd->x + design_full - gi->design_border, gd->y,
- gi->design_border, gi->height,
- xpos + size_full - gi->design_border, ypos);
- }
- break;
-
- default:
- return;
- }
-
- if (direct)
- XCopyArea(display, drawto, window, gc,
- gi->x, gi->y, gi->width, gi->height, gi->x, gi->y);
- else
- redraw_mask |= REDRAW_ALL;
-}
-
-void ClickOnGadget(struct GadgetInfo *gi)
-{
- /* simulate releasing mouse button over last gadget, if still pressed */
- if (button_status)
- HandleGadgets(-1, -1, 0);
-
- /* simulate pressing mouse button over specified gadget */
- HandleGadgets(gi->x, gi->y, 1);
-
- /* simulate releasing mouse button over specified gadget */
- HandleGadgets(gi->x, gi->y, 0);
-}
-
-void AdjustScrollbar(struct GadgetInfo *gi, int items_max, int item_pos)
-{
- struct GadgetScrollbar *gs = &gi->scrollbar;
-
- gs->items_max = items_max;
- gs->item_position = item_pos;
-
- gs->size = gs->size_max * gs->items_visible / gs->items_max;
- gs->position = gs->size_max * gs->item_position / gs->items_max;
- gs->position_max = gs->size_max - gs->size;
-
- /* finetuning for maximal right/bottom position */
- if (gs->item_position == gs->items_max - gs->items_visible)
- gs->position = gs->position_max;
-
- if (gi->mapped)
- DrawGadget(gi, DG_UNPRESSED, DG_DIRECT);
-}
-
-void ModifyTextInputTextValue(struct GadgetInfo *gi, char *new_text)
-{
- struct GadgetTextInput *text = &gi->text;
- int max_textsize = MAX_GADGET_TEXTSIZE;
-
- if (text->size)
- max_textsize = MIN(text->size, MAX_GADGET_TEXTSIZE - 1);
-
- strncpy(text->value, new_text, max_textsize);
- text->value[max_textsize] = '\0';
- text->cursor_position = strlen(text->value);
-
- if (gi->mapped)
- DrawGadget(gi, DG_UNPRESSED, DG_DIRECT);
-}
-
-void ModifyTextInputNumberValue(struct GadgetInfo *gi, int new_value)
-{
- struct GadgetTextInput *text = &gi->text;
-
- text->number_value = (new_value < text->number_min ? text->number_min :
- new_value > text->number_max ? text->number_max :
- new_value);
-
- sprintf(text->value, "%d", text->number_value);
-
- if (gi->mapped)
- DrawGadget(gi, DG_UNPRESSED, DG_DIRECT);
-}
-