|
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
|
#include <Wt/WAbstractTableModel.h>
|
|
#pragma GCC diagnostic pop
|
|
#include <Wt/WApplication.h>
|
|
#include <Wt/WBootstrap5Theme.h>
|
|
#include <Wt/WContainerWidget.h>
|
|
#include <Wt/WGridLayout.h>
|
|
#include <Wt/WHBoxLayout.h>
|
|
#include <Wt/WMenuItem.h>
|
|
#include <Wt/WPanel.h>
|
|
#include <Wt/WPopupMenu.h>
|
|
#include <Wt/WPushButton.h>
|
|
#include <Wt/WServer.h>
|
|
#include <Wt/WTableView.h>
|
|
#include <Wt/WTabWidget.h>
|
|
#include <Wt/WText.h>
|
|
#include <Wt/WVBoxLayout.h>
|
|
|
|
using namespace std;
|
|
using namespace Wt;
|
|
using namespace Wt::cpp17;
|
|
|
|
#define SET_BS5THEME 1
|
|
|
|
// Always apply theme before creating widgets!
|
|
class CThemedApplication : public WApplication
|
|
{
|
|
public:
|
|
CThemedApplication(const WEnvironment& rcEnv)
|
|
: WApplication{rcEnv}
|
|
{
|
|
#if SET_BS5THEME
|
|
setTheme(make_shared<WBootstrap5Theme>());
|
|
#endif
|
|
}
|
|
};
|
|
|
|
class CFixedTableModel : public WAbstractTableModel
|
|
{
|
|
public:
|
|
CFixedTableModel(const int rowCount, const int colCount)
|
|
: _rowCount{rowCount}
|
|
, _colCount{colCount}
|
|
{ }
|
|
|
|
any headerData(const int section, const Orientation orientation, const ItemDataRole role) const
|
|
{
|
|
if (orientation != Orientation::Horizontal) throw invalid_argument("orientation");
|
|
switch (role.value())
|
|
{
|
|
default: return {};
|
|
case ItemDataRole::Display: return format("C{}", section);
|
|
}
|
|
}
|
|
|
|
any data(const WModelIndex& index, const ItemDataRole role) const override
|
|
{
|
|
if (!index.isValid()) return {};
|
|
switch (role.value())
|
|
{
|
|
default: return {};
|
|
case ItemDataRole::Display: return format("{}, {}", index.row(), index.column());
|
|
}
|
|
}
|
|
|
|
int columnCount(const WModelIndex& index) const override { return index.isValid() ? 0 : _colCount; }
|
|
int rowCount (const WModelIndex& index) const override { return index.isValid() ? 0 : _rowCount; }
|
|
|
|
const int _rowCount;
|
|
const int _colCount;
|
|
};
|
|
|
|
template<typename T, typename... TArgs>
|
|
constexpr inline
|
|
std::unique_ptr<T> create(std::function<void (T&)>&& fInitialize, TArgs&&... args)
|
|
{
|
|
std::unique_ptr<T> Ptr{std::make_unique<T>(std::forward<TArgs>(args)...)};
|
|
fInitialize(*Ptr);
|
|
return Ptr;
|
|
}
|
|
|
|
inline void setAccessKey(WInteractWidget& widget, const char mnemonic) { widget.setAttributeValue("accesskey", string(1, tolower(mnemonic))); }
|
|
|
|
class CApplication final : public CThemedApplication
|
|
{
|
|
public:
|
|
CApplication(const WEnvironment& rcEnv);
|
|
|
|
private:
|
|
WServer& _Server; //!< The associated WServer instance, needed for async operations.
|
|
|
|
WContainerWidget& _cntRoot{*root()};
|
|
WBoxLayout& _lytRoot{*_cntRoot.setLayout(make_unique<WVBoxLayout>())};
|
|
|
|
WPushButton& _btnP{*_lytRoot.addWidget(make_unique<WPushButton>("Top placeholder"))};
|
|
|
|
WTabWidget& _tbwMain{*_lytRoot.addWidget(make_unique<WTabWidget>(), /*stretch*/ 100)};
|
|
WMenuItem& _tabA{*_tbwMain.addTab(make_unique<WContainerWidget>(), "A", ContentLoading::Eager)};
|
|
WContainerWidget& _cntA{dynamic_cast<WContainerWidget&>(*_tbwMain.widget(_tbwMain.count() - 1))};
|
|
WBoxLayout& _lytA{*_cntA.setLayout(make_unique<WHBoxLayout>())};
|
|
WTableView& _tvNarrow{*_lytA.addWidget(make_unique<WTableView>())};
|
|
WTableView& _tvA{*_lytA.addWidget(make_unique<WTableView>())};
|
|
WMenuItem& _tabB{*_tbwMain.addTab(make_unique<WTableView>(), "B", ContentLoading::Eager)};
|
|
WTableView& _tvB{dynamic_cast<WTableView&>(*_tbwMain.widget(_tbwMain.count() - 1))};
|
|
|
|
WPanel& _pnlBottom{*_lytRoot.addWidget(make_unique<WPanel>())};
|
|
WContainerWidget& _cntBottom{*_pnlBottom.setCentralWidget(make_unique<WContainerWidget>())};
|
|
WBoxLayout& _lytBottom{*_cntBottom.setLayout(make_unique<WHBoxLayout>())};
|
|
|
|
WPushButton& _btnA{*_lytBottom.addWidget(make_unique<WPushButton>("Bottom placeholder"))};
|
|
|
|
shared_ptr<CFixedTableModel> _mdlNarrow1Ptr{make_shared<CFixedTableModel>(100, 2)};
|
|
shared_ptr<CFixedTableModel> _mdlNarrow2Ptr{make_shared<CFixedTableModel>( 10, 2)};
|
|
shared_ptr<CFixedTableModel> _mdlAPtr {make_shared<CFixedTableModel>(100, 50)};
|
|
shared_ptr<CFixedTableModel> _mdlBPtr {make_shared<CFixedTableModel>(200, 100)};
|
|
};
|
|
|
|
CApplication::CApplication(const WEnvironment& rcEnv)
|
|
: CThemedApplication{rcEnv}
|
|
, _Server{*environment().server()}
|
|
{
|
|
setTitle("bug repro " WT_VERSION_STR);
|
|
|
|
const auto initTable = [this](WTableView& tv, const shared_ptr<CFixedTableModel>& mdlPtr)
|
|
{
|
|
tv.setRowHeaderCount(1);
|
|
tv.setSelectionBehavior(SelectionBehavior::Items);
|
|
tv.setSelectionMode(SelectionMode::Single);
|
|
tv.setSortingEnabled(false);
|
|
tv.setCanReceiveFocus(true);
|
|
tv.setEditTriggers(EditTrigger::None);
|
|
tv.setAlternatingRowColors(true);
|
|
tv.setModel(mdlPtr);
|
|
|
|
tv.keyWentDown().connect([this, &tv] { log("trace") << "key in " << (void*)&tv; });
|
|
|
|
tv.selectionChanged().connect([this, &tv]
|
|
{
|
|
const WModelIndexSet selectedIndexes{tv.selectionModel()->selectedIndexes()};
|
|
switch (selectedIndexes.size())
|
|
{
|
|
case 0: break;
|
|
case 1: tv.scrollTo(*selectedIndexes.cbegin()); break;
|
|
default: throw logic_error("multi-selection unexpected");
|
|
}
|
|
});
|
|
|
|
tv.select(mdlPtr->index(0, 1));
|
|
};
|
|
initTable(_tvNarrow, _mdlNarrow2Ptr);
|
|
initTable(_tvA, _mdlNarrow1Ptr);
|
|
for (int i = 0; i < 5; ++i)
|
|
{
|
|
initTable(*_lytA.addWidget(make_unique<WTableView>()), _mdlNarrow2Ptr);
|
|
}
|
|
initTable(_tvB, _mdlBPtr);
|
|
|
|
_lytBottom.setContentsMargins(0, 0, 0, 0);
|
|
_lytBottom.addStretch(100);
|
|
_lytA.addStretch(100);
|
|
|
|
_Server.schedule(300ms, sessionId(), [this]
|
|
{
|
|
_tabB.select();
|
|
triggerUpdate();
|
|
});
|
|
_Server.schedule(1000ms, sessionId(), [this]
|
|
{
|
|
_tabA.select();
|
|
_tabA.setFirstFocus(); // Why doesn't this have any effect?!?
|
|
_tvA.setFocus();
|
|
triggerUpdate();
|
|
});
|
|
|
|
// final action after creating the UI
|
|
enableUpdates();
|
|
}
|
|
|
|
int main(int argc, char* argv[])
|
|
{
|
|
return WRun(argc, argv, [](const WEnvironment& rcEnv)
|
|
{
|
|
try
|
|
{
|
|
return make_unique<CApplication>(rcEnv);
|
|
}
|
|
catch (const std::exception& rcException)
|
|
{
|
|
cerr << "exception " << typeid(remove_cvref<decltype(rcException)>::type).name() << ": " << rcException.what() << endl;
|
|
|
|
#if DEBUG
|
|
exit(-1);
|
|
#endif
|
|
throw;
|
|
}
|
|
});
|
|
}
|