Prepare CenterIM 5.0.0 Beta2
[centerim5.git] / tests / window.cpp
blob71af37a10a6fc12f8d30244639cc44f9ceee1e6c
1 #include <cppconsui/CoreManager.h>
2 #include <cppconsui/KeyConfig.h>
3 #include <cppconsui/Label.h>
4 #include <cppconsui/Window.h>
6 #include <stdio.h>
8 // TestWindow class
9 class TestWindow
10 : public CppConsUI::Window
12 public:
13 TestWindow(int number, int x, int y, int w, int h);
14 virtual ~TestWindow() {}
16 protected:
18 private:
19 TestWindow(const TestWindow&);
20 TestWindow& operator=(const TestWindow&);
23 TestWindow::TestWindow(int number, int x, int y, int w, int h)
24 : CppConsUI::Window(x, y, w, h)
26 CppConsUI::Label *label;
28 gchar *t = g_strdup_printf("Win %d", number);
29 label = new CppConsUI::Label(w - 4, 1, t);
30 g_free(t);
31 addWidget(*label, 2, 1);
33 if (number == 1) {
34 label = new CppConsUI::Label("Press F10 to quit.");
35 addWidget(*label, 2, 2);
37 label = new CppConsUI::Label("Press ESC to close a focused window.");
38 addWidget(*label, 2, 3);
42 // TestApp class
43 class TestApp
44 : public CppConsUI::InputProcessor
46 public:
47 TestApp();
48 virtual ~TestApp() {}
50 void run();
52 // ignore every message
53 static void g_log_func_(const gchar * /*log_domain*/,
54 GLogLevelFlags /*log_level*/, const gchar * /*message*/,
55 gpointer /*user_data*/)
58 protected:
60 private:
61 TestApp(const TestApp&);
62 TestApp& operator=(const TestApp&);
65 TestApp::TestApp()
67 KEYCONFIG->loadDefaultKeyConfig();
68 KEYCONFIG->bindKey("testapp", "quit", "F10");
70 g_log_set_default_handler(g_log_func_, this);
72 declareBindable("testapp", "quit", sigc::mem_fun(COREMANAGER,
73 &CppConsUI::CoreManager::quitMainLoop),
74 InputProcessor::BINDABLE_OVERRIDE);
77 void TestApp::run()
79 for (int i = 1; i <= 4; i++) {
80 TestWindow *win = new TestWindow(i, (i - 1) % 2 * 40, (i - 1) / 2 * 10,
81 40, 10);
82 win->show();
85 COREMANAGER->setTopInputProcessor(*this);
86 COREMANAGER->enableResizing();
87 COREMANAGER->startMainLoop();
90 // main function
91 int main()
93 setlocale(LC_ALL, "");
95 // initialize CppConsUI
96 int consui_res = CppConsUI::initializeConsUI();
97 if (consui_res) {
98 fprintf(stderr, "CppConsUI initialization failed.\n");
99 return consui_res;
102 TestApp *app = new TestApp;
103 app->run();
104 delete app;
106 // finalize CppConsUI
107 consui_res = CppConsUI::finalizeConsUI();
108 if (consui_res) {
109 fprintf(stderr, "CppConsUI deinitialization failed.\n");
110 return consui_res;
113 return 0;
116 /* vim: set tabstop=2 shiftwidth=2 textwidth=78 expandtab : */