]> git.vomp.tv Git - vompclient.git/blob - woptionpane.cc
Switch trunk code to new boxes
[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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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 "remote.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, Colour::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 = surface->getFontHeight();
64
65   options.resize(numOptions+1);
66   options[numOptions] = option;
67   
68   WTextbox* tb = new WTextbox();
69   tb->setPosition(4, 4 + (numOptions * 30));
70   tb->setSize(300, fontHeight);
71   tb->setText(tr(option->displayText));
72   tb->setTextPos(0, 0);
73   add(tb);
74   
75   textBoxes.resize(numOptions+1);
76   textBoxes[numOptions] = tb;
77
78   WOptionBox* ob = new WOptionBox();
79   ob->setPosition(310, 4 + (numOptions * 30));
80   ob->setSize(190, fontHeight);  
81   add(ob);
82   
83   optionBoxes.resize(numOptions+1);
84   optionBoxes[numOptions] = ob;
85   
86   if (option->optionType == Option::TYPE_TEXT)
87   {
88     for (UINT j = 0; j < option->numChoices; j++)
89     {
90       Log::getInstance()->log("Options", Log::DEBUG, "Add option: %s", option->options[j]);
91       ob->addOption(tr(option->options[j]));
92     }
93
94     // Set the selected choice
95     ob->setSelected(tr(option->options[option->configChoice]));
96   }
97   else
98   {
99     // int mode
100     ob->setIntMode(option->startInt, option->numChoices);
101     ob->setSelected(option->configChoice);
102   }
103
104   numOptions++;
105   
106 }
107
108 int WOptionPane::handleCommand(int command)
109 {
110   switch(command)
111   {
112     case Remote::DF_UP:
113     case Remote::UP:
114     {
115       if (selectedOption > 0)
116       {
117         optionBoxes[selectedOption]->setActive(0);
118         --selectedOption;
119         optionBoxes[selectedOption]->setActive(1);
120         return 1;
121       }
122       else
123       {
124         optionBoxes[selectedOption--]->setActive(0);
125         return 4; // Signal return control to parent
126       }
127     }
128     case Remote::DF_DOWN:
129     case Remote::DOWN:
130     {
131       if (selectedOption < (numOptions - 1))
132       {
133         if (selectedOption != -1) optionBoxes[selectedOption]->setActive(0);
134         ++selectedOption;
135         optionBoxes[selectedOption]->setActive(1);
136         return 1;
137       }
138       else if (selectedOption == (numOptions - 1))
139       {
140         optionBoxes[selectedOption]->setActive(0);
141         selectedOption = -1;
142         return 4; // Signal return control to parent
143       }
144     }
145     case Remote::DF_LEFT:
146     case Remote::LEFT:
147     {
148       optionBoxes[selectedOption]->left();
149       return 1;
150     }
151     case Remote::DF_RIGHT:
152     case Remote::RIGHT:
153     {
154       optionBoxes[selectedOption]->right();
155       return 1;
156     }
157     case Remote::OK:
158     {
159       optionBoxes[selectedOption]->cycle();
160       return 1;
161     }
162   }
163
164   return 0;
165 }
166
167
168
169