コード例 #1
0
ファイル: PagerWidget.cpp プロジェクト: kwtskran/XCSoar
bool
PagerWidget::SetCurrent(unsigned i, bool click)
{
    assert(i < children.size());

    if (!initialised || !prepared) {
        /* quick code path: not yet prepared, quickly switch without
           checks */
        assert(!click);
        current = i;
        return true;
    }

    assert(current < children.size());
    assert(!visible || children[current].prepared);
    assert(!click || visible);

    Child &old_child = children[current];
    Child &new_child = children[i];

    if (i == current) {
        if (click) {
            assert(visible);
            assert(new_child.prepared);
            new_child.widget->ReClick();
            return true;
        } else {
            return true;
        }
    }

    assert(!visible || old_child.prepared);
    if (visible && !old_child.widget->Leave())
        return false;

    if (click && !new_child.widget->Click())
        return false;

    if (visible)
        old_child.widget->Hide();

    current = i;

    if (!new_child.prepared) {
        new_child.prepared = true;
        new_child.widget->Prepare(*parent, position);
    }

    if (visible)
        new_child.widget->Show(position);

    OnPageFlipped();
    return true;
}
コード例 #2
0
ファイル: dlgConfiguration.cpp プロジェクト: DRIZO/xcsoar
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);
  }
}