]> git.vomp.tv Git - vompclient.git/blob - woptionpane.cc
10 CWFs
[vompclient.git] / woptionpane.cc
1 /*
2     Copyright 2007 Chris Tallon
3
4     This file is part of VOMP.
5
6     VOMP is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     VOMP is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with VOMP; if not, write to the Free Software
18     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19 */
20
21 #include "woptionpane.h"
22 #include "wtextbox.h"
23 #include "i18n.h"
24 #include "woptionbox.h"
25 #include "log.h"
26 #include "vdr.h"
27 #include "input.h"
28 #include "option.h"
29
30 WOptionPane::WOptionPane()
31 {
32   numOptions = 0;
33   selectedOption = -1;
34 }
35
36 WOptionPane::~WOptionPane()
37 {
38   for(int i = 0; i < numOptions; i++)
39   {
40     delete textBoxes[i];
41     delete optionBoxes[i];
42   }
43 }
44
45 void WOptionPane::draw()
46 {
47   Boxx::draw();
48   drawText(tr("Press back to exit, <, > or [ok] to change"), 10, area.h - 30, DrawStyle::LIGHTTEXT);
49 }
50
51 void WOptionPane::saveOpts()
52 {
53   // Due to the way the pane is constructed, options[0] corresponds to textBoxes[0] and optionBoxes[0] etc
54   
55   for(int i = 0; i < numOptions; i++)
56   {
57     options[i]->userSetChoice = optionBoxes[i]->getSelectedIndex();
58   }
59 }
60
61 void WOptionPane::addOptionLine(Option* option)
62 {
63   int fontHeight = getFontHeight();
64
65
66   options.resize(numOptions+1);
67   options[numOptions] = option;
68
69   WTextbox* tb = new WTextbox();
70   tb->setPosition(4, 4 + (numOptions * 30));
71   tb->setSize(300, fontHeight + 6);
72   tb->setText(tr(option->displayText));
73   tb->setTextPos(0, 0);
74   add(tb);
75
76   textBoxes.resize(numOptions+1);
77   textBoxes[numOptions] = tb;
78
79   WOptionBox* ob = new WOptionBox();
80   ob->setPosition(310, 4 + (numOptions * 30));
81   ob->setSize(190, fontHeight);  
82   add(ob);
83
84   optionBoxes.resize(numOptions+1);
85   optionBoxes[numOptions] = ob;
86
87   if (option->optionType == Option::TYPE_TEXT ||
88       option->optionType == Option::TYPE_KEYED_TEXT)
89   {
90     for (UINT j = 0; j < option->numChoices; j++)
91     {
92       Log::getInstance()->log("Options", Log::DEBUG, "Add option: %s", option->options[j]);
93       ob->addOption(tr(option->options[j]));
94     }
95
96     // Set the selected choice
97     ob->setSelected(tr(option->options[option->configChoice]));
98   }
99   else
100   {
101     // int mode
102     ob->setIntMode(option->startInt, option->numChoices);
103     ob->setSelected(option->configChoice);
104   }
105
106   numOptions++;
107   
108 }
109
110 void WOptionPane::deactivateAllControls()
111 {
112     if (selectedOption >= 0) {
113         optionBoxes[selectedOption]->setActive(0);
114         selectedOption = -1;
115     }
116 }
117
118
119 int WOptionPane::handleCommand(int command)
120 {
121   switch(command)
122   {
123     case Input::UP:
124     {
125       if (selectedOption > 0)
126       {
127         optionBoxes[selectedOption]->setActive(0);
128         --selectedOption;
129         optionBoxes[selectedOption]->setActive(1);
130         return 1;
131       }
132       else if (selectedOption == 0)
133       {
134         optionBoxes[selectedOption--]->setActive(0);
135         return 4; // Signal return control to parent
136       }
137       else if (selectedOption == -1) // Allow UP when inactive, start at the last optionBox
138       {
139         selectedOption = numOptions - 1;
140         optionBoxes[selectedOption]->setActive(1);
141         return 1;
142       }
143     }
144     case Input::DOWN:
145     {
146       if (selectedOption < (numOptions - 1))
147       {
148         if (selectedOption != -1) optionBoxes[selectedOption]->setActive(0);
149         ++selectedOption;
150         optionBoxes[selectedOption]->setActive(1);
151         return 1;
152       }
153       else if (selectedOption == (numOptions - 1))
154       {
155         optionBoxes[selectedOption]->setActive(0);
156         selectedOption = -1;
157         return 4; // Signal return control to parent
158       }
159     }
160     case Input::LEFT:
161     {
162       optionBoxes[selectedOption]->left();
163       return 1;
164     }
165     case Input::RIGHT:
166     {
167       optionBoxes[selectedOption]->right();
168       return 1;
169     }
170     case Input::OK:
171     {
172       optionBoxes[selectedOption]->cycle();
173       return 1;
174     }
175   }
176
177   return 0;
178 }
179
180 bool WOptionPane::mouseMove(int x, int y)
181 {
182     UINT i;
183     for (i=0;i<optionBoxes.size();i++) {
184         if (optionBoxes[i]->mouseMove(x,y)) {
185             if ( selectedOption!=(int)i) {
186                 if (selectedOption != -1 ) optionBoxes[selectedOption]->setActive(0);
187                 selectedOption=i;
188                 return true;
189             } else {
190                 return false;
191             }
192         }
193     }
194
195     return false;
196 }
197
198 bool WOptionPane::mouseLBDOWN(int x, int y)
199 {
200     UINT i;
201     for (i=0;i<optionBoxes.size();i++) {
202         if (optionBoxes[i]->mouseLBDOWN(x,y)) {
203             if ( selectedOption==(int)i) {
204                 optionBoxes[selectedOption]->cycle();
205                 return true;
206             } else {
207                 return false;
208             }
209         }
210     }
211     return false;
212 }
213
214
215
216