コード例 #1
0
ファイル: widget-window.c プロジェクト: Nazg-Gul/fm
/**
 * Handle a keydown callback
 *
 * @param __window - window received a callback
 * @param __ch - received character
 * @return zero if callback hasn't handled received character
 *   non-zero otherwise
 */
static int
window_keydown (w_window_t *__window, wint_t __ch)
{
  widget_t *focused;

  /* Call user's callback */
  _WIDGET_CALL_USER_CALLBACK (__window, keydown, __window, __ch);

  /* If user's callback hadn't processed this callback, */
  /* make this stuff */

  if ((focused = __window->focused_widget))
    {
      /* If there is focused widget, try to redirect callback to it */
      int res = 0;
      if (WIDGET_CALLBACK (focused, keydown) &&
          (res = WIDGET_CALLBACK (focused, keydown) (focused, __ch)))
        {
          return res;
        }
    }

  switch (__ch)
    {
    /* Navigation */
    case KEY_DOWN:
    case KEY_RIGHT:
    case KEY_TAB:
      widget_set_focus (widget_next_focused (__window->focused_widget));
      return TRUE;

    case KEY_UP:
    case KEY_LEFT:
      widget_set_focus (widget_prev_focused (__window->focused_widget));
      return TRUE;

    default:
      {
        WIDGET_CONTAINER_ACTION_ITERONLY (__window, SHORTCUT_CHECKER,
                                          towlower (__ch));
        break;
      }
    }

  return FALSE;
}
コード例 #2
0
ファイル: widget-button.c プロジェクト: Nazg-Gul/fm
 /**
  * Handle a shortcut callback
  *
  * @param __button - button for which this callback was sent
  * @return zero if callback hasn't handled received character,
  *   non-zero otherwise
  */
static int
button_shortcut (w_button_t *__button)
{
  /* Try to call user's handler of shortcut.. */
  _WIDGET_CALL_USER_CALLBACK (__button, shortcut, __button);

  /* .. if we are still here emulate clicking in the button */
  widget_set_focus (WIDGET (__button));
  return button_keydown (__button, KEY_RETURN);
}
コード例 #3
0
ファイル: widget-window.c プロジェクト: Nazg-Gul/fm
/**
 * Default part of window showing stuff
 *
 * @param __window - window to be shown
 * @param _show_mode - mode in which window have to be shown.
 *   Possible values:
 *     WSM_NORLAM - Normal window
 *     WSM_MODAL  - Modal window
 * @return zero or modal result of window on success.
 *   Less-zero value on failure.
 */
static int
window_show_entry (w_window_t *__window, int __show_mode)
{
  if (!__window)
    {
      return -1;
    }

  /* Window is now visible */
  WIDGET_POSITION (__window).z = 1;
  __window->focused = TRUE;

  panel_show (__window->panel);

  widget_add_root (WIDGET (__window));
  widget_push_context (WIDGET (__window));

  __window->show_mode = __show_mode;
  __window->modal_result = MR_NONE;

  /* widget_set_current_widget (WIDGET (__window)); */

  /* Is it okay if we think that showing of window */
  /* is the same as focusing of window? */
  WIDGET_CALL_CALLBACK (__window, focused, __window);

  /* Set focus to first widget in window */
  if (WIDGET_CONTAINER_LENGTH (__window))
    {
      widget_t *w;

      if (!WIDGET_CONTAINER_FOCUSED (__window))
        {
          w = widget_first_focusable (WIDGET_CONTAINER (__window));
        }
      else
        {
          w = WIDGET_CONTAINER_FOCUSED (__window);
          w->focused = FALSE;
        }

      if (w)
        {
          widget_set_focus (w);
        }
    }

  /* Draw window */
  widget_redraw (WIDGET (__window));

  if (__show_mode == WSM_MODAL)
    {
      widget_t *w;
      window_proc (__window);

      if (!__window->mode_changing)
        {
          if ((w = __window->focused_widget))
            {
              WIDGET_CALL_CALLBACK (w, blured, w);
            }

          w_window_hide (__window);
          return __window->modal_result;
        }
    }

  return 0;
}
コード例 #4
0
void widget_new_trait_info_window(trait_t trait, bool enable_controls)
{
  struct trait * traitdata;
  
  traitdata = trait_get(trait);
  if(traitdata != NULL)
    {
      char buf[128];
      struct widget * window;

      snprintf(buf, sizeof buf, "%s: %s", gettext("Trait"), trait_get_name(trait));
      window = widget_new_window(widget_root(), 420, 200, buf);
      assert(window != NULL);
      if(window != NULL)
        {
          int y;

          widget_set_modal(window);
          widget_set_image_pointer(window, "raw_image", gfx_image(traitdata->image_id));
          widget_set_widget_pointer(window, "previously_selected_object", widget_focus());

          y = 40 + font_height();

          char ** description;
          char fn[1024];
          
          snprintf(fn, sizeof fn, "data/trait-%s", traitdata->filename);
          description = read_localized_text_file(get_data_filename(fn));
          if(description != NULL)
            {
              for(int i = 0; description[i] != NULL; i++)
                {
                  widget_new_text(window, 10, y, description[i]);
                  free(description[i]);
                  y += font_height();
                }
              free(description);
            }

          y += font_height() * 2;

          struct widget * prev;
          
          prev = NULL;
          if(enable_controls)
            {
              if(traits_get_active() & trait)
                {
                  struct widget * t;

                  t = widget_new_text(window, 10, y, gettext("You have this trait."));
                  if(traits_get_active() & TRAIT_RECYCLER)
                    {
                      struct widget * b;

                      snprintf(buf + 1, (sizeof buf) - 1, gettext("Recycle for %lu"), (long unsigned) traitdata->cost * 90 / 100);
                      buf[0] = ' '; snprintf(buf + strlen(buf), sizeof buf - strlen(buf), " "); /* Pad with spaces */
                      b = widget_new_button(window, widget_x(t) + widget_width(t) + 10, y, buf);
                      widget_set_on_release(b, on_recycle_trait_clicked);
                      widget_set_ulong(b, "trait", trait);
                      y += widget_height(b);
                      prev = b;
                    }
                  y += font_height();

                  if(trait == TRAIT_EDIT)
                    {
                      struct widget * b;

                      y += font_height();
                      snprintf(buf, sizeof buf, " %s ", gettext("Edit cave"));
                      b = widget_new_button(window, 0, y, buf);
                      widget_set_on_release(b, on_edit_trait_clicked);
                      widget_center_horizontally(b);
                      y += widget_height(b);
                      if(prev != NULL)
                        widget_set_navigation_updown(prev, b);
                      prev = b;
                    }
              
                  y += font_height();
                }
              else if(traits_get_available() & trait)
                {
                  struct widget * t;
                  
                  t = widget_new_text(window, 10, y, gettext("You don't have this trait."));
                  if(traits_get_score() >= traitdata->cost)
                    {
                      struct widget * b;

                      snprintf(buf, sizeof buf, " %s ", gettext("Buy"));
                      b = widget_new_button(window, widget_x(t) + widget_width(t) + 10, y, buf);
                      widget_set_on_release(b, on_buy_trait_clicked);
                      widget_set_ulong(b, "trait", trait);
                      if(prev != NULL)
                        widget_set_navigation_updown(prev, b);
                      prev = b;
                    }
                  y += font_height();
                  
                  widget_new_text(window, 10, y, gettext("Cost:"));
                  snprintf(buf, sizeof buf, "%u", (unsigned int) traitdata->cost);
                  widget_new_text(window, 100, y, buf);
                  y += font_height();
                  
                  widget_new_text(window, 10, y, gettext("You have:"));
                  snprintf(buf, sizeof buf, "%u", (unsigned int) traits_get_score());
                  if( ! (traits_get_active() & trait) )
                    if(traits_get_score() < traitdata->cost)
                      snprintf(buf + strlen(buf), sizeof buf - strlen(buf), gettext(" [need %u more]"), (unsigned int) (traitdata->cost - traits_get_score()));
                  widget_new_text(window, 100, y, buf);
                  y += font_height();
                }
              else
                {
                  unsigned int level;
                  
                  level = traitdata->cave_level;
                  if(level == 0)
                    level = get_cave_level_count(traitdata->cave_name);
                  snprintf(buf, sizeof buf, gettext("Level required: %u"), level);
                  widget_new_text(window, 10, y, buf);
                  y += font_height();
                }

              y += font_height();
            }

          struct widget * closebutton;

          snprintf(buf, sizeof buf, "  %s  ", gettext("Close"));
          closebutton = widget_new_button(window, 0, y, buf);
          widget_set_x(closebutton, (widget_width(window) - widget_width(closebutton)) / 2);
          widget_set_focus(closebutton);
          y += widget_height(closebutton);
          if(prev != NULL)
            widget_set_navigation_updown(prev, closebutton);


          widget_resize_to_fit_children(window);
          widget_set_width(window, widget_width(window) + 10);
          widget_set_height(window, widget_height(window) + 10);
          widget_center(window);

          ui_wait_for_window_close(window, closebutton);
        }
    }
}