Exemple #1
0
bool
TimeEntryDialog(const TCHAR *caption, RoughTime &value,
                RoughTimeDelta time_zone, bool nullable)
{
  /* create the dialog */

  const DialogLook &look = UIGlobals::GetDialogLook();

  WidgetDialog dialog(look);
  dialog.CreatePreliminary(UIGlobals::GetMainWindow(), caption);

  ContainerWindow &client_area = dialog.GetClientAreaWindow();

  /* create the input control */

  WindowStyle control_style;
  control_style.Hide();
  control_style.TabStop();

  DigitEntry entry(look);
  entry.CreateTime(client_area, client_area.GetClientRect(), control_style);
  entry.Resize(entry.GetRecommendedSize());
  entry.SetValue(value + time_zone);
  entry.SetActionListener(dialog, mrOK);

  /* create buttons */

  dialog.AddButton(_("OK"), dialog, mrOK);
  dialog.AddButton(_("Cancel"), dialog, mrCancel);

  auto now_listener = MakeLambdaActionListener([&entry, time_zone](unsigned){
      const BrokenTime bt = BrokenDateTime::NowUTC();
      RoughTime now_utc = RoughTime(bt.hour, bt.minute);
      entry.SetValue(now_utc + time_zone);
    });
  dialog.AddButton(_("Now"), now_listener, 0);

  auto clear_listener = MakeLambdaActionListener([&entry](unsigned){
      entry.SetInvalid();
    });
  if (nullable)
    dialog.AddButton(_("Clear"), clear_listener, 0);

  /* run it */

  FixedWindowWidget widget(&entry);
  dialog.FinishPreliminary(&widget);

  bool result = dialog.ShowModal() == mrOK;
  dialog.StealWidget();
  if (!result)
    return false;

  value = entry.GetTimeValue() - time_zone;
  return true;
}
Exemple #2
0
void dlgConfigurationShowModal()
{
  const DialogLook &look = UIGlobals::GetDialogLook();

  WidgetDialog dialog(look);

  auto on_close = MakeLambdaActionListener([&dialog](unsigned id) {
      OnCloseClicked(dialog);
    });

  pager = new ArrowPagerWidget(on_close, look.button,
                               new ConfigurationExtraButtons(look));

  TabMenuDisplay *menu = new TabMenuDisplay(*pager, look);
  pager->Add(new CreateWindowWidget([menu](ContainerWindow &parent,
                                           const PixelRect &rc,
                                           WindowStyle style) {
                                      style.TabStop();
                                      menu->Create(parent, rc, style);
                                      return menu;
                                    }));

  menu->InitMenu(pages, ARRAY_SIZE(pages),
                 main_menu_captions, ARRAY_SIZE(main_menu_captions));

  /* restore last selected menu item */
  menu->SetCursor(current_page);

  dialog.CreateFull(UIGlobals::GetMainWindow(), _("Configuration"), pager);

  pager->SetPageFlippedCallback([&dialog, menu](){
      OnPageFlipped(dialog, *menu);
    });

  dialog.ShowModal();

  /* save page number for next time this dialog is opened */
  current_page = menu->GetCursor();

  bool changed = false;
  pager->Save(changed);
  if (changed) {
    Profile::Save();
    LogDebug(_T("Configuration: Changes saved"));
    if (require_restart)
      ShowMessageBox(_("Changes to configuration saved.  Restart XCSoar to apply changes."),
                  _T(""), MB_OK);
  }
}
Exemple #3
0
bool
TouchTextEntry(TCHAR *text, size_t width,
               const TCHAR *caption,
               AllowedCharacters accb,
               bool default_shift_state)
{
  if (width == 0)
    width = MAX_TEXTENTRY;

  max_width = std::min(MAX_TEXTENTRY, width);

  const DialogLook &look = UIGlobals::GetDialogLook();
  WndForm form(look);
  form.Create(UIGlobals::GetMainWindow(), caption);
  form.SetKeyDownFunction(FormKeyDown);
  form.SetCharacterFunction(FormCharacter);

  ContainerWindow &client_area = form.GetClientAreaWindow();
  const PixelRect rc = client_area.GetClientRect();

  const PixelScalar client_height = rc.bottom - rc.top;

  const PixelScalar padding = Layout::Scale(2);
  const PixelScalar backspace_width = Layout::Scale(36);
  const PixelScalar backspace_left = rc.right - padding - backspace_width;
  const PixelScalar editor_height = Layout::Scale(22);
  const PixelScalar editor_bottom = padding + editor_height;
  const PixelScalar button_height = Layout::Scale(40);
  constexpr unsigned keyboard_rows = 5;
  const PixelScalar keyboard_top = editor_bottom + padding;
  const PixelScalar keyboard_height = keyboard_rows * button_height;
  const PixelScalar keyboard_bottom = keyboard_top + keyboard_height;

  const bool vertical = client_height >= keyboard_bottom + button_height;

  const PixelScalar button_top = vertical
    ? rc.bottom - button_height
    : keyboard_bottom - button_height;
  const PixelScalar button_bottom = vertical
    ? rc.bottom
    : keyboard_bottom;

  const PixelScalar ok_left = vertical ? 0 : padding;
  const PixelScalar ok_right = vertical
    ? rc.right / 3
    : ok_left + Layout::Scale(80);

  const PixelScalar cancel_left = vertical
    ? ok_right
    : Layout::Scale(175);
  const PixelScalar cancel_right = vertical
    ? rc.right * 2 / 3
    : cancel_left + Layout::Scale(60);

  const PixelScalar clear_left = vertical
    ? cancel_right
    : Layout::Scale(235);
  const PixelScalar clear_right = vertical
    ? rc.right
    : clear_left + Layout::Scale(50);

  WndProperty _editor(client_area, look, _T(""),
                      { 0, padding, backspace_left - padding, editor_bottom },
                      0, WindowStyle());
  _editor.SetReadOnly();
  editor = &_editor;

  ButtonWindowStyle button_style;
  button_style.TabStop();

  WndButton ok_button(client_area, look.button, _("OK"),
                      { ok_left, button_top, ok_right, button_bottom },
                      button_style, form, mrOK);

  WndButton cancel_button(client_area, look.button, _("Cancel"),
                          { cancel_left, button_top,
                              cancel_right, button_bottom },
                          button_style, form, mrCancel);

  auto clear_listener = MakeLambdaActionListener([](unsigned id){
      ClearText();
    });
  WndButton clear_button(client_area, look.button, _("Clear"),
                         { clear_left, button_top,
                             clear_right, button_bottom },
                         button_style, clear_listener, 0);

  KeyboardWidget keyboard(look.button, FormCharacter, !accb,
                          default_shift_state);

  const PixelRect keyboard_rc = {
    padding, keyboard_top,
    rc.right - padding, keyboard_bottom
  };

  keyboard.Initialise(client_area, keyboard_rc);
  keyboard.Prepare(client_area, keyboard_rc);
  keyboard.Show(keyboard_rc);

  kb = &keyboard;

  auto backspace_listener = MakeLambdaActionListener([](unsigned id){
      OnBackspace();
    });
  WndButton backspace_button(client_area, look.button, _T("<-"),
                             { backspace_left, padding, rc.right - padding,
                                 editor_bottom },
                             button_style, backspace_listener, 0);

  AllowedCharactersCallback = accb;

  cursor = 0;
  ClearText();

  if (!StringIsEmpty(text)) {
    CopyString(edittext, text, width);
    cursor = _tcslen(text);
  }

  UpdateTextboxProp();
  bool result = form.ShowModal() == mrOK;

  keyboard.Hide();
  keyboard.Unprepare();

  if (result) {
    CopyString(text, edittext, width);
  }

  return result;
}