Make windows in tests non-closable
[centerim5.git] / tests / label.cpp
blobadec08a81d2d81ede15e681554f806b39bbcd3a4
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();
14 virtual ~TestWindow() {}
16 protected:
18 private:
19 TestWindow(const TestWindow&);
20 TestWindow& operator=(const TestWindow&);
23 TestWindow::TestWindow()
24 : CppConsUI::Window(0, 0, AUTOSIZE, AUTOSIZE)
26 setClosable(false);
28 CppConsUI::Label *label;
30 label = new CppConsUI::Label(
31 20, // width
32 1, // height
33 "Press F10 to quit."); // text
34 /* Add label to container, container takes widget ownership and deletes it
35 * when necessary. */
36 addWidget(*label, 1, 1);
38 label = new CppConsUI::Label(20, 1,
39 "Too wide string, too wide string, too wide string");
40 addWidget(*label, 1, 3);
42 label = new CppConsUI::Label(20, 3,
43 "Multiline label, multiline label, multiline label");
44 addWidget(*label, 1, 5);
46 label = new CppConsUI::Label(
47 "Auto multiline label,\nauto multiline label,\nauto multiline label");
48 addWidget(*label, 1, 9);
50 // unicode test
51 label = new CppConsUI::Label(30, 3,
52 "\x56\xc5\x99\x65\xc5\xa1\x74\xc3\xad\x63\xc3\xad\x20\x70\xc5\x99"
53 "\xc3\xad\xc5\xa1\x65\x72\x79\x20\x73\x65\x20\x64\x6f\xc5\xbe\x61"
54 "\x64\x6f\x76\x61\x6c\x79\x20\xc3\xba\x70\x6c\x6e\xc4\x9b\x20\xc4"
55 "\x8d\x65\x72\x73\x74\x76\xc3\xbd\x63\x68\x20\xc5\x99\xc3\xad\x7a"
56 "\x65\xc4\x8d\x6b\xc5\xaf\x2e\x0a");
57 addWidget(*label, 1, 13);
59 label = new CppConsUI::Label("Autosize");
60 addWidget(*label, 1, 17);
62 const gchar *long_text = "Lorem ipsum dolor sit amet, consectetur"
63 "adipiscing elit. Duis dui dui, interdum eget tempor auctor, viverra"
64 "suscipit velit. Phasellus vel magna odio. Duis rutrum tortor at nisi"
65 "auctor tincidunt. Mauris libero neque, faucibus sit amet semper in, "
66 "dictum ut tortor. Duis lacinia justo non lorem blandit ultrices."
67 "Nullam vel purus erat, eget aliquam massa. Aenean eget mi a nunc"
68 "lacinia consectetur sed a neque. Cras varius, dolor nec rhoncus"
69 "ultricies, leo ipsum adipiscing mi, vel feugiat ipsum urna id "
70 "metus. Cras non pulvinar nisi. Vivamus nisi lorem, tempor tristique"
71 "cursus sit amet, ultricies interdum metus. Nullam tortor tortor, "
72 "iaculis sed tempor non, tincidunt ac mi. Quisque id diam vitae diam"
73 "dictum facilisis eget ac lacus. Vivamus at gravida felis. Curabitur"
74 "fermentum mattis eros, ut auctor urna tincidunt vitae. Praesent"
75 "tincidunt laoreet lobortis.";
77 label = new CppConsUI::Label(AUTOSIZE, 10, long_text);
78 addWidget(*label, 42, 17);
80 label = new CppConsUI::Label(40, AUTOSIZE, long_text);
81 addWidget(*label, 1, 28);
83 label = new CppConsUI::Label(AUTOSIZE, AUTOSIZE, long_text);
84 addWidget(*label, 42, 28);
87 // TestApp class
88 class TestApp
89 : public CppConsUI::InputProcessor
91 public:
92 TestApp();
93 virtual ~TestApp() {}
95 void run();
97 // ignore every message
98 static void g_log_func_(const gchar * /*log_domain*/,
99 GLogLevelFlags /*log_level*/, const gchar * /*message*/,
100 gpointer /*user_data*/)
103 protected:
105 private:
106 TestApp(const TestApp&);
107 TestApp& operator=(const TestApp&);
110 TestApp::TestApp()
112 KEYCONFIG->loadDefaultKeyConfig();
113 KEYCONFIG->bindKey("testapp", "quit", "F10");
115 g_log_set_default_handler(g_log_func_, this);
117 declareBindable("testapp", "quit", sigc::mem_fun(COREMANAGER,
118 &CppConsUI::CoreManager::quitMainLoop),
119 InputProcessor::BINDABLE_OVERRIDE);
122 void TestApp::run()
124 TestWindow *win = new TestWindow;
125 win->show();
127 COREMANAGER->setTopInputProcessor(*this);
128 COREMANAGER->enableResizing();
129 COREMANAGER->startMainLoop();
132 // main function
133 int main()
135 setlocale(LC_ALL, "");
137 // initialize CppConsUI
138 int consui_res = CppConsUI::initializeConsUI();
139 if (consui_res) {
140 fprintf(stderr, "CppConsUI initialization failed.\n");
141 return consui_res;
144 TestApp *app = new TestApp;
145 app->run();
146 delete app;
148 // finalize CppConsUI
149 consui_res = CppConsUI::finalizeConsUI();
150 if (consui_res) {
151 fprintf(stderr, "CppConsUI deinitialization failed.\n");
152 return consui_res;
155 return 0;
158 /* vim: set tabstop=2 shiftwidth=2 textwidth=78 expandtab : */