Debian Codegraph @

src/option/SelectLang.cpp

raw
1 /*
2 * Copyright (C) 2004 Ivo Danihelka ([email protected])
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 */
9 #include "SelectLang.h"
10
11 #include "HBox.h"
12 #include "RadioBox.h"
13
14 #include "def-script.h"
15 #include "Path.h"
16 #include "ScriptState.h"
17
18 //-----------------------------------------------------------------
19 inline SelectLang *
20 getSelect(lua_State *L)
21 {
22 return dynamic_cast<SelectLang*>(script_getLeader(L));
23 }
24 //-----------------------------------------------------------------
25 /**
26 * void select_addFlag(value, picture)
27 */
28 int
29 script_select_addFlag(lua_State *L) throw()
30 {
31 BEGIN_NOEXCEPTION;
32 const char *value = luaL_checkstring(L, 1);
33 const char *picture = luaL_checkstring(L, 2);
34
35 getSelect(L)->addFlag(value, Path::dataReadPath(picture));
36 END_NOEXCEPTION;
37 return 0;
38 }
39
40 //-----------------------------------------------------------------
41 /**
42 * Execute script which will add flags.
43 */
44 SelectLang::SelectLang(const std::string &option, const Path &datafile)
45 {
46 m_option = option;
47 m_activeRow = new HBox();
48
49 m_script->registerFunc("select_addFlag", script_select_addFlag);
50 scriptInclude(datafile);
51
52 addWidget(m_activeRow);
53 }
54 //-----------------------------------------------------------------
55 /**
56 * Stack flags in table.
57 */
58 void
59 SelectLang::addFlag(const std::string &value, const Path &picture)
60 {
61 IWidget *flag = new RadioBox(m_option, value, picture);
62 flag->setTip(value);
63 m_activeRow->addWidget(flag);
64 if (m_activeRow->getW() > MAX_WIDTH) {
65 addWidget(m_activeRow);
66 m_activeRow = new HBox();
67 }
68 }
69