Make windows in tests non-closable
[centerim5.git] / tests / treeview.cpp
blobfa59dcc05d425ef2c565257f6b31e0c10cc6d1ac
1 #include <cppconsui/Button.h>
2 #include <cppconsui/CoreManager.h>
3 #include <cppconsui/Label.h>
4 #include <cppconsui/KeyConfig.h>
5 #include <cppconsui/TreeView.h>
6 #include <cppconsui/Window.h>
8 #include <stdio.h>
10 // TestWindow class
11 class TestWindow
12 : public CppConsUI::Window
14 public:
15 TestWindow();
16 virtual ~TestWindow() {}
18 protected:
20 private:
21 TestWindow(const TestWindow&);
22 TestWindow& operator=(const TestWindow&);
25 TestWindow::TestWindow()
26 : Window(0, 0, AUTOSIZE, AUTOSIZE)
28 setClosable(false);
30 CppConsUI::TreeView *tree;
31 CppConsUI::TreeView::NodeReference node;
32 CppConsUI::TreeView::NodeReference node2;
34 addWidget(*(new CppConsUI::Label(20, 1, "Press F10 to quit.")), 1, 1);
36 tree = new CppConsUI::TreeView(30, 12);
37 addWidget(*tree, 1, 3);
38 setInputChild(*tree);
40 node = tree->appendNode(tree->getRootNode(),
41 *(new CppConsUI::Button("Button node A")));
42 node2 = tree->appendNode(node, *(new CppConsUI::Button("Button node A-1")));
43 tree->appendNode(node2, *(new CppConsUI::Button("Button node A-1-a")));
44 tree->appendNode(node2, *(new CppConsUI::Button("Button node A-1-b")));
45 tree->appendNode(node2, *(new CppConsUI::Button("Button node A-1-c")));
46 tree->appendNode(node, *(new CppConsUI::Button("Button node A-2")));
47 tree->appendNode(node, *(new CppConsUI::Button("Button node A-3")));
49 node = tree->appendNode(tree->getRootNode(),
50 *(new CppConsUI::Label("Label node B")));
51 tree->appendNode(node, *(new CppConsUI::Label("Label node B-1")));
52 tree->appendNode(node, *(new CppConsUI::Label("Label node B-2")));
53 tree->appendNode(node, *(new CppConsUI::Label("Label node B-3")));
55 node = tree->appendNode(tree->getRootNode(),
56 *(new CppConsUI::Button("Button node C")));
57 tree->appendNode(node, *(new CppConsUI::Button("Button node C-1")));
58 tree->appendNode(node, *(new CppConsUI::Button("Button node C-2")));
59 tree->appendNode(node, *(new CppConsUI::Button("Button node C-3")));
62 // TestApp class
63 class TestApp
64 : public CppConsUI::InputProcessor
66 public:
67 TestApp();
68 virtual ~TestApp() {}
70 void run();
72 // ignore every message
73 static void g_log_func_(const gchar * /*log_domain*/,
74 GLogLevelFlags /*log_level*/, const gchar * /*message*/,
75 gpointer /*user_data*/)
78 protected:
80 private:
81 TestApp(const TestApp&);
82 TestApp& operator=(const TestApp&);
85 TestApp::TestApp()
87 KEYCONFIG->loadDefaultKeyConfig();
88 KEYCONFIG->bindKey("testapp", "quit", "F10");
90 g_log_set_default_handler(g_log_func_, this);
92 declareBindable("testapp", "quit", sigc::mem_fun(COREMANAGER,
93 &CppConsUI::CoreManager::quitMainLoop),
94 InputProcessor::BINDABLE_OVERRIDE);
97 void TestApp::run()
99 TestWindow *win = new TestWindow;
100 win->show();
102 COREMANAGER->setTopInputProcessor(*this);
103 COREMANAGER->enableResizing();
104 COREMANAGER->startMainLoop();
107 // main function
108 int main()
110 setlocale(LC_ALL, "");
112 // initialize CppConsUI
113 int consui_res = CppConsUI::initializeConsUI();
114 if (consui_res) {
115 fprintf(stderr, "CppConsUI initialization failed.\n");
116 return consui_res;
119 TestApp *app = new TestApp;
120 app->run();
121 delete app;
123 // finalize CppConsUI
124 consui_res = CppConsUI::finalizeConsUI();
125 if (consui_res) {
126 fprintf(stderr, "CppConsUI deinitialization failed.\n");
127 return consui_res;
130 return 0;
133 /* vim: set tabstop=2 shiftwidth=2 textwidth=78 expandtab : */