1 /***********************************************************************
2     created:    20/8/2005
3     author:     Paul D Turner
4 *************************************************************************/
5 /***************************************************************************
6  *   Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
7  *
8  *   Permission is hereby granted, free of charge, to any person obtaining
9  *   a copy of this software and associated documentation files (the
10  *   "Software"), to deal in the Software without restriction, including
11  *   without limitation the rights to use, copy, modify, merge, publish,
12  *   distribute, sublicense, and/or sell copies of the Software, and to
13  *   permit persons to whom the Software is furnished to do so, subject to
14  *   the following conditions:
15  *
16  *   The above copyright notice and this permission notice shall be
17  *   included in all copies or substantial portions of the Software.
18  *
19  *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20  *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21  *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22  *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23  *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24  *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25  *   OTHER DEALINGS IN THE SOFTWARE.
26  ***************************************************************************/
27 #include "Sample_Demo6.h"
28 #include "CEGUI/CEGUI.h"
29 
30 #include <stdlib.h>
31 #include <stdio.h>
32 #include <string>
33 
34 using namespace CEGUI;
35 
36 /*************************************************************************
37 Sample specific initialisation goes here.
38 *************************************************************************/
initialise(CEGUI::GUIContext * guiContext)39 bool Demo6Sample::initialise(CEGUI::GUIContext* guiContext)
40 {
41     d_usedFiles = CEGUI::String(__FILE__);
42 
43     // we will use of the WindowManager.
44     WindowManager& winMgr = WindowManager::getSingleton();
45 
46     // load scheme and set up defaults
47     SchemeManager::getSingleton().createFromFile("TaharezLook.scheme");
48     guiContext->getMouseCursor().setDefaultImage("TaharezLook/MouseArrow");
49 
50 
51     // load font and setup default if not loaded via scheme
52     Font& defaultFont = FontManager::getSingleton().createFromFile("DejaVuSans-12.font");
53     // Set default font for the gui context
54     guiContext->setDefaultFont(&defaultFont);
55 
56     // load an image to use as a background
57     if( !ImageManager::getSingleton().isDefined("SpaceBackgroundImage") )
58         ImageManager::getSingleton().addFromImageFile("SpaceBackgroundImage", "SpaceBackground.jpg");
59 
60     // here we will use a StaticImage as the root, then we can use it to place a background image
61     Window* background = winMgr.createWindow("TaharezLook/StaticImage", "root_wnd");
62     // set position and size
63     background->setPosition(UVector2(cegui_reldim(0), cegui_reldim( 0)));
64     background->setSize(USize(cegui_reldim(1), cegui_reldim(1)));
65     // disable frame and standard background
66     background->setProperty("FrameEnabled", "false");
67     background->setProperty("BackgroundEnabled", "false");
68     // set the background image
69     background->setProperty("Image", "SpaceBackgroundImage");
70     // install this as the root GUI sheet
71     guiContext->setRootWindow(background);
72 
73     // do demo stuff
74     createDemoWindows(background);
75     initDemoEventWiring(background);
76 
77     // success!
78     return true;
79 }
80 
81 /*************************************************************************
82     Cleans up resources allocated in the initialiseSample call.
83 *************************************************************************/
deinitialise()84 void Demo6Sample::deinitialise()
85 {
86     // nothing to do here!
87 }
88 
89 /*************************************************************************
90     Create the windows and widgets for the demo
91 *************************************************************************/
createDemoWindows(CEGUI::Window * root)92 void Demo6Sample::createDemoWindows(CEGUI::Window* root)
93 {
94     using namespace CEGUI;
95     ListboxTextItem* itm;
96 
97     WindowManager& winMgr = WindowManager::getSingleton();
98 
99     // create the main list.
100     MultiColumnList* mcl = static_cast<MultiColumnList*>(winMgr.createWindow("TaharezLook/MultiColumnList", "MainList"));
101     root->addChild(mcl);
102     mcl->setPosition(UVector2(cegui_reldim(0.01f), cegui_reldim( 0.1f)));
103     mcl->setSize(USize(cegui_reldim(0.5f), cegui_reldim( 0.8f)));
104 
105     // create frame window for control panel
106     FrameWindow* fwnd = static_cast<FrameWindow*>(winMgr.createWindow("TaharezLook/FrameWindow", "ControlPanel"));
107     root->addChild(fwnd);
108     fwnd->setPosition(UVector2(cegui_reldim(0.53f), cegui_reldim( 0.03f)));
109     fwnd->setMaxSize(USize(cegui_reldim(1.0f), cegui_reldim( 1.0f)));
110     fwnd->setSize(USize(cegui_reldim(0.44f), cegui_reldim( 0.94f)));
111     fwnd->setText("Demo 6 - Control Panel");
112 
113     // create combo-box.
114     Combobox* cbbo = static_cast<Combobox*>(winMgr.createWindow("TaharezLook/Combobox", "SelModeBox"));
115     fwnd->addChild(cbbo);
116     cbbo->setPosition(UVector2(cegui_reldim(0.04f), cegui_reldim( 0.06f)));
117     cbbo->setSize(USize(cegui_reldim(0.66f), cegui_reldim( 0.33f)));
118     //cbbo->setSortingEnabled(true);
119 
120     // populate combobox with possible selection modes
121     const CEGUI::Image* sel_img = &ImageManager::getSingleton().get("TaharezLook/MultiListSelectionBrush");
122     itm = new ListboxTextItem("Full Row (Single)", 0);
123     itm->setSelectionBrushImage(sel_img);
124     cbbo->addItem(itm);
125     itm = new ListboxTextItem("Full Row (Multiple)", 1);
126     itm->setSelectionBrushImage(sel_img);
127     cbbo->addItem(itm);
128     itm = new ListboxTextItem("Full Column (Single)", 2);
129     itm->setSelectionBrushImage(sel_img);
130     cbbo->addItem(itm);
131     itm = new ListboxTextItem("Full Column (Multiple)", 3);
132     itm->setSelectionBrushImage(sel_img);
133     cbbo->addItem(itm);
134     itm = new ListboxTextItem("Single Cell (Single)", 4);
135     itm->setSelectionBrushImage(sel_img);
136     cbbo->addItem(itm);
137     itm = new ListboxTextItem("Single Cell (Multiple)", 5);
138     itm->setSelectionBrushImage(sel_img);
139     cbbo->addItem(itm);
140     itm = new ListboxTextItem("Nominated Column (Single)", 6);
141     itm->setSelectionBrushImage(sel_img);
142     cbbo->addItem(itm);
143     itm = new ListboxTextItem("Nominated Column (Multiple)", 7);
144     itm->setSelectionBrushImage(sel_img);
145     cbbo->addItem(itm);
146     ListboxTextItem* pStore = itm;
147     itm = new ListboxTextItem("Nominated Row (Single)", 8);
148     itm->setSelectionBrushImage(sel_img);
149     cbbo->addItem(itm);
150     itm = new ListboxTextItem("Nominated Row (Multiple)", 9);
151     itm->setSelectionBrushImage(sel_img);
152     cbbo->addItem(itm);
153     cbbo->setReadOnly(true);
154     // Now change the text to test the sorting
155     pStore->setText("Abracadabra");
156     //cbbo->setSortingEnabled(false);
157     cbbo->setSortingEnabled(true);
158     //cbbo->handleUpdatedListItemData();
159 
160     // column control section
161     Window* st = winMgr.createWindow("TaharezLook/StaticText", "ColumnPanel");
162     fwnd->addChild(st);
163     st->setPosition(UVector2(cegui_reldim(0.02f), cegui_reldim( 0.12f)));
164     st->setSize(USize(cegui_reldim(0.96f), cegui_reldim( 0.25f)));
165     st->setText("Column Control");
166     st->setProperty("VertFormatting", "TopAligned");
167 
168     Window* label = winMgr.createWindow("TaharezLook/StaticText", "Label1");
169     st->addChild(label);
170     label->setProperty("FrameEnabled", "false");
171     label->setProperty("BackgroundEnabled", "false");
172     label->setPosition(UVector2(cegui_reldim(0.02f), cegui_reldim( 0.2f)));
173     label->setSize(USize(cegui_reldim(0.2f), cegui_reldim( 0.12f)));
174     label->setText("ID Code:");
175 
176     label = winMgr.createWindow("TaharezLook/StaticText", "Label2");
177     st->addChild(label);
178     label->setProperty("FrameEnabled", "false");
179     label->setProperty("BackgroundEnabled", "false");
180     label->setPosition(UVector2(cegui_reldim(0.23f), cegui_reldim( 0.2f)));
181     label->setSize(USize(cegui_reldim(0.2f), cegui_reldim( 0.12f)));
182     label->setText("Width:");
183 
184     label = winMgr.createWindow("TaharezLook/StaticText", "Label3");
185     st->addChild(label);
186     label->setProperty("FrameEnabled", "false");
187     label->setProperty("BackgroundEnabled", "false");
188     label->setPosition(UVector2(cegui_reldim(0.44f), cegui_reldim( 0.2f)));
189     label->setSize(USize(cegui_reldim(0.2f), cegui_reldim( 0.12f)));
190     label->setText("Caption:");
191 
192     PushButton* btn = static_cast<PushButton*>(winMgr.createWindow("TaharezLook/Button", "AddColButton"));
193     st->addChild(btn);
194     btn->setPosition(UVector2(cegui_reldim(0.81f), cegui_reldim( 0.32f)));
195     btn->setSize(USize(cegui_reldim(0.15f), cegui_reldim( 0.2f)));
196     btn->setText("Add");
197 
198     Editbox* ebox = static_cast<Editbox*>(winMgr.createWindow("TaharezLook/Editbox", "NewColIDBox"));
199     st->addChild(ebox);
200     ebox->setPosition(UVector2(cegui_reldim(0.02f), cegui_reldim( 0.32f)));
201     ebox->setSize(USize(cegui_reldim(0.2f), cegui_reldim( 0.2f)));
202     ebox->setValidationString("\\d*");
203     ebox->setText("Test -- ");
204 
205     ebox = static_cast<Editbox*>(winMgr.createWindow("TaharezLook/Editbox", "NewColWidthBox"));
206     st->addChild(ebox);
207     ebox->setPosition(UVector2(cegui_reldim(0.23f), cegui_reldim( 0.32f)));
208     ebox->setSize(USize(cegui_reldim(0.2f), cegui_reldim( 0.2f)));
209     ebox->setValidationString("\\d*");
210 
211     ebox = static_cast<Editbox*>(winMgr.createWindow("TaharezLook/Editbox", "NewColTextBox"));
212     st->addChild(ebox);
213     ebox->setPosition(UVector2(cegui_reldim(0.44f), cegui_reldim( 0.32f)));
214     ebox->setSize(USize(cegui_reldim(0.36f), cegui_reldim( 0.2f)));
215     ebox->setValidationString(".*");
216 
217     label = winMgr.createWindow("TaharezLook/StaticText", "Label4");
218     st->addChild(label);
219     label->setProperty("FrameEnabled", "false");
220     label->setProperty("BackgroundEnabled", "false");
221     label->setPosition(UVector2(cegui_reldim(0.02f), cegui_reldim( 0.55f)));
222     label->setSize(USize(cegui_reldim(0.2f), cegui_reldim( 0.12f)));
223     label->setText("ID Code:");
224 
225     ebox = static_cast<Editbox*>(winMgr.createWindow("TaharezLook/Editbox", "DelColIDBox"));
226     st->addChild(ebox);
227     ebox->setPosition(UVector2(cegui_reldim(0.02f), cegui_reldim( 0.67f)));
228     ebox->setSize(USize(cegui_reldim(0.2f), cegui_reldim( 0.2f)));
229     ebox->setValidationString("\\d*");
230 
231     btn = static_cast<PushButton*>(winMgr.createWindow("TaharezLook/Button", "DelColButton"));
232     st->addChild(btn);
233     btn->setPosition(UVector2(cegui_reldim(0.25f), cegui_reldim( 0.67f)));
234     btn->setSize(USize(cegui_reldim(0.4f), cegui_reldim( 0.2f)));
235     btn->setText("Delete Column");
236 
237     // Row control box
238     st = winMgr.createWindow("TaharezLook/StaticText", "RowControl");
239     fwnd->addChild(st);
240     st->setPosition(UVector2(cegui_reldim(0.02f), cegui_reldim( 0.38f)));
241     st->setSize(USize(cegui_reldim(0.96f), cegui_reldim( 0.25f)));
242     st->setText("Row Control");
243     st->setProperty("VertFormatting", "TopAligned");
244 
245     label = winMgr.createWindow("TaharezLook/StaticText", "Label5");
246     st->addChild(label);
247     label->setProperty("FrameEnabled", "false");
248     label->setProperty("BackgroundEnabled", "false");
249     label->setPosition(UVector2(cegui_reldim(0.02f), cegui_reldim( 0.2f)));
250     label->setSize(USize(cegui_reldim(0.2f), cegui_reldim( 0.12f)));
251     label->setText("Col ID:");
252 
253     label = winMgr.createWindow("TaharezLook/StaticText", "Label6");
254     st->addChild(label);
255     label->setProperty("FrameEnabled", "false");
256     label->setProperty("BackgroundEnabled", "false");
257     label->setPosition(UVector2(cegui_reldim(0.23f), cegui_reldim( 0.2f)));
258     label->setSize(USize(cegui_reldim(0.55f), cegui_reldim( 0.12f)));
259     label->setText("Item Text:");
260 
261     ebox = static_cast<Editbox*>(winMgr.createWindow("TaharezLook/Editbox", "RowColIDBox"));
262     st->addChild(ebox);
263     ebox->setPosition(UVector2(cegui_reldim(0.02f), cegui_reldim( 0.32f)));
264     ebox->setSize(USize(cegui_reldim(0.2f), cegui_reldim( 0.2f)));
265     ebox->setValidationString("\\d*");
266 
267     ebox = static_cast<Editbox*>(winMgr.createWindow("TaharezLook/Editbox", "RowTextBox"));
268     st->addChild(ebox);
269     ebox->setPosition(UVector2(cegui_reldim(0.23f), cegui_reldim( 0.32f)));
270     ebox->setSize(USize(cegui_reldim(0.55f), cegui_reldim( 0.2f)));
271     ebox->setValidationString(".*");
272 
273     btn = static_cast<PushButton*>(winMgr.createWindow("TaharezLook/Button", "AddRowButton"));
274     st->addChild(btn);
275     btn->setPosition(UVector2(cegui_reldim(0.81f), cegui_reldim( 0.32f)));
276     btn->setSize(USize(cegui_reldim(0.15f), cegui_reldim( 0.2f)));
277     btn->setText("Add");
278 
279     label = winMgr.createWindow("TaharezLook/StaticText", "Label7");
280     st->addChild(label);
281     label->setProperty("FrameEnabled", "false");
282     label->setProperty("BackgroundEnabled", "false");
283     label->setPosition(UVector2(cegui_reldim(0.02f), cegui_reldim( 0.55f)));
284     label->setSize(USize(cegui_reldim(0.2f), cegui_reldim( 0.12f)));
285     label->setText("Row Idx:");
286 
287     ebox = static_cast<Editbox*>(winMgr.createWindow("TaharezLook/Editbox", "DelRowIdxBox"));
288     st->addChild(ebox);
289     ebox->setPosition(UVector2(cegui_reldim(0.02f), cegui_reldim( 0.67f)));
290     ebox->setSize(USize(cegui_reldim(0.2f), cegui_reldim( 0.2f)));
291     ebox->setValidationString("\\d*");
292 
293     btn = static_cast<PushButton*>(winMgr.createWindow("TaharezLook/Button", "DelRowButton"));
294     st->addChild(btn);
295     btn->setPosition(UVector2(cegui_reldim(0.25f), cegui_reldim( 0.67f)));
296     btn->setSize(USize(cegui_reldim(0.4f), cegui_reldim( 0.2f)));
297     btn->setText("Delete Row");
298 
299     // set item box
300     st = winMgr.createWindow("TaharezLook/StaticText", "SetItemPanel");
301     fwnd->addChild(st);
302     st->setPosition(UVector2(cegui_reldim(0.02f), cegui_reldim( 0.65f)));
303     st->setSize(USize(cegui_reldim(0.96f), cegui_reldim( 0.25f)));
304     st->setText("Item Modification");
305     st->setProperty("VertFormatting", "TopAligned");
306 
307     label = winMgr.createWindow("TaharezLook/StaticText", "Label8");
308     st->addChild(label);
309     label->setProperty("FrameEnabled", "false");
310     label->setProperty("BackgroundEnabled", "false");
311     label->setPosition(UVector2(cegui_reldim(0.02f), cegui_reldim( 0.2f)));
312     label->setSize(USize(cegui_reldim(0.2f), cegui_reldim( 0.12f)));
313     label->setText("Row Idx:");
314 
315     label = winMgr.createWindow("TaharezLook/StaticText", "Label9");
316     st->addChild(label);
317     label->setProperty("FrameEnabled", "false");
318     label->setProperty("BackgroundEnabled", "false");
319     label->setPosition(UVector2(cegui_reldim(0.23f), cegui_reldim( 0.2f)));
320     label->setSize(USize(cegui_reldim(0.2f), cegui_reldim( 0.12f)));
321     label->setText("Col ID:");
322 
323     label = winMgr.createWindow("TaharezLook/StaticText", "Label10");
324     st->addChild(label);
325     label->setProperty("FrameEnabled", "false");
326     label->setProperty("BackgroundEnabled", "false");
327     label->setPosition(UVector2(cegui_reldim(0.44f), cegui_reldim( 0.2f)));
328     label->setSize(USize(cegui_reldim(0.2f), cegui_reldim( 0.12f)));
329     label->setText("Item Text:");
330 
331     ebox = static_cast<Editbox*>(winMgr.createWindow("TaharezLook/Editbox", "SetItemRowBox"));
332     st->addChild(ebox);
333     ebox->setPosition(UVector2(cegui_reldim(0.02f), cegui_reldim( 0.32f)));
334     ebox->setSize(USize(cegui_reldim(0.2f), cegui_reldim( 0.2f)));
335     ebox->setValidationString("\\d*");
336 
337     ebox = static_cast<Editbox*>(winMgr.createWindow("TaharezLook/Editbox", "SetItemIDBox"));
338     st->addChild(ebox);
339     ebox->setPosition(UVector2(cegui_reldim(0.23f), cegui_reldim( 0.32f)));
340     ebox->setSize(USize(cegui_reldim(0.2f), cegui_reldim( 0.2f)));
341     ebox->setValidationString("\\d*");
342 
343     ebox = static_cast<Editbox*>(winMgr.createWindow("TaharezLook/Editbox", "SetItemTextBox"));
344     st->addChild(ebox);
345     ebox->setPosition(UVector2(cegui_reldim(0.44f), cegui_reldim( 0.32f)));
346     ebox->setSize(USize(cegui_reldim(0.36f), cegui_reldim( 0.2f)));
347     ebox->setValidationString(".*");
348 
349     btn = static_cast<PushButton*>(winMgr.createWindow("TaharezLook/Button", "SetItemButton"));
350     st->addChild(btn);
351     btn->setPosition(UVector2(cegui_reldim(0.81f), cegui_reldim( 0.32f)));
352     btn->setSize(USize(cegui_reldim(0.15f), cegui_reldim( 0.2f)));
353     btn->setText("Set");
354 
355     label = winMgr.createWindow("TaharezLook/StaticText", "RowCount");
356     st->addChild(label);
357     label->setProperty("FrameEnabled", "false");
358     label->setProperty("BackgroundEnabled", "false");
359     label->setPosition(UVector2(cegui_reldim(0.02f), cegui_reldim( 0.55f)));
360     label->setSize(USize(cegui_reldim(1.0f), cegui_reldim( 0.12f)));
361     label->setText("Current Row Count:");
362 
363     label = winMgr.createWindow("TaharezLook/StaticText", "ColCount");
364     st->addChild(label);
365     label->setProperty("FrameEnabled", "false");
366     label->setProperty("BackgroundEnabled", "false");
367     label->setPosition(UVector2(cegui_reldim(0.02f), cegui_reldim( 0.67f)));
368     label->setSize(USize(cegui_reldim(1.0f), cegui_reldim( 0.12f)));
369     label->setText("Current Column Count:");
370 
371     label = winMgr.createWindow("TaharezLook/StaticText", "SelCount");
372     st->addChild(label);
373     label->setProperty("FrameEnabled", "false");
374     label->setProperty("BackgroundEnabled", "false");
375     label->setPosition(UVector2(cegui_reldim(0.02f), cegui_reldim( 0.79f)));
376     label->setSize(USize(cegui_reldim(1.0f), cegui_reldim( 0.12f)));
377     label->setText("Current Selected Count:");
378 
379     btn = static_cast<PushButton*>(winMgr.createWindow("TaharezLook/Button", "QuitButton"));
380     fwnd->addChild(btn);
381     btn->setPosition(UVector2(cegui_reldim(0.25f), cegui_reldim( 0.93f)));
382     btn->setSize(USize(cegui_reldim(0.50f), cegui_reldim( 0.05f)));
383     btn->setText("Quit This Demo!");
384 }
385 
386 
initDemoEventWiring(CEGUI::Window * root)387 void Demo6Sample::initDemoEventWiring(CEGUI::Window* root)
388 {
389     using namespace CEGUI;
390 
391     // subscribe handler that adds a new column
392     root->getChild("ControlPanel/ColumnPanel/AddColButton")->
393         subscribeEvent(PushButton::EventClicked, Event::Subscriber(&Demo6Sample::handleAddColumn, this));
394 
395     // subscribe handler that deletes a column
396     root->getChild("ControlPanel/ColumnPanel/DelColButton")->
397         subscribeEvent(PushButton::EventClicked, Event::Subscriber(&Demo6Sample::handleDeleteColumn, this));
398 
399     // subscribe handler that adds a new row
400     root->getChild("ControlPanel/RowControl/AddRowButton")->
401         subscribeEvent(PushButton::EventClicked, Event::Subscriber(&Demo6Sample::handleAddRow, this));
402 
403     // subscribe handler that deletes a row
404     root->getChild("ControlPanel/RowControl/DelRowButton")->
405         subscribeEvent(PushButton::EventClicked, Event::Subscriber(&Demo6Sample::handleDeleteRow, this));
406 
407     // subscribe handler that sets the text for an existing item
408     root->getChild("ControlPanel/SetItemPanel/SetItemButton")->
409         subscribeEvent(PushButton::EventClicked, Event::Subscriber(&Demo6Sample::handleSetItem, this));
410 
411     // subscribe handler that quits the application
412    root->getChild("ControlPanel/QuitButton")->
413        subscribeEvent(PushButton::EventClicked, Event::Subscriber(&Demo6Sample::handleQuit, this));
414 
415     // subscribe handler that processes a change in the 'selection mode' combobox
416     root->getChild("ControlPanel/SelModeBox")->
417         subscribeEvent(Combobox::EventListSelectionAccepted, Event::Subscriber(&Demo6Sample::handleSelectModeChanged, this));
418 
419     // subscribe handler that processes a change in the item(s) selected in the list
420     root->getChild("MainList")->
421         subscribeEvent(MultiColumnList::EventSelectionChanged, Event::Subscriber(&Demo6Sample::handleSelectChanged, this));
422 
423     // subscribe handler that processes a change in the list content.
424     root->getChild("MainList")->
425         subscribeEvent(MultiColumnList::EventListContentsChanged, Event::Subscriber(&Demo6Sample::handleContentsChanged, this));
426 }
427 
handleQuit(const CEGUI::EventArgs &)428 bool Demo6Sample::handleQuit(const CEGUI::EventArgs&)
429 {
430 
431     // event was handled
432     return true;
433 }
434 
handleAddColumn(const CEGUI::EventArgs & args)435 bool Demo6Sample::handleAddColumn(const CEGUI::EventArgs& args)
436 {
437     using namespace CEGUI;
438 
439     // get access to the widgets that contain details about the column to add
440     MultiColumnList* mcl = static_cast<MultiColumnList*>(static_cast<const WindowEventArgs&>(args).window->getRootWindow()->getChild("MainList"));
441     Editbox* idbox = static_cast<Editbox*>(static_cast<const WindowEventArgs&>(args).window->getRootWindow()->getChild("ControlPanel/ColumnPanel/NewColIDBox"));
442     Editbox* widthbox = static_cast<Editbox*>(static_cast<const WindowEventArgs&>(args).window->getRootWindow()->getChild("ControlPanel/ColumnPanel/NewColWidthBox"));
443     Editbox* textbox = static_cast<Editbox*>(static_cast<const WindowEventArgs&>(args).window->getRootWindow()->getChild("ControlPanel/ColumnPanel/NewColTextBox"));
444 
445     // get ID for new column
446     CEGUI::uint id = atoi(idbox->getText().c_str());
447     // get width to use for new column (in pixels)
448     float width = static_cast<float>(atof(widthbox->getText().c_str()));
449     // get column label text
450     String text = textbox->getText();
451 
452     // re-set the widget contents
453     idbox->setText("");
454     widthbox->setText("");
455     textbox->setText("");
456 
457     // ensure a minimum width of 10 pixels
458     if (width < 10.0f)
459         width = 10.0f;
460 
461     // finally, add the new column to the list.
462     mcl->addColumn(text, id, cegui_absdim(width));
463 
464     // event was handled.
465     return true;
466 }
467 
handleDeleteColumn(const CEGUI::EventArgs & args)468 bool Demo6Sample::handleDeleteColumn(const CEGUI::EventArgs& args)
469 {
470     using namespace CEGUI;
471 
472     // get access to the widgets that contain details about the column to delete
473     MultiColumnList* mcl = static_cast<MultiColumnList*>(static_cast<const WindowEventArgs&>(args).window->getRootWindow()->getChild("MainList"));
474     Editbox* idbox = static_cast<Editbox*>(static_cast<const WindowEventArgs&>(args).window->getRootWindow()->getChild("ControlPanel/ColumnPanel/DelColIDBox"));
475 
476     // obtain the id of the column to be deleted
477     CEGUI::uint id = atoi(idbox->getText().c_str());
478 
479     // attempt to delete the column, ignoring any errors.
480     CEGUI_TRY
481     {
482         mcl->removeColumnWithID(id);
483     }
484     CEGUI_CATCH (InvalidRequestException)
485     {}
486 
487     // reset the delete column ID box.
488     idbox->setText("");
489 
490     // event was handled.
491     return true;
492 }
493 
handleAddRow(const CEGUI::EventArgs & args)494 bool Demo6Sample::handleAddRow(const CEGUI::EventArgs& args)
495 {
496     using namespace CEGUI;
497 
498     // get access to the widgets that contain details about the row to add
499     MultiColumnList* mcl = static_cast<MultiColumnList*>(static_cast<const WindowEventArgs&>(args).window->getRootWindow()->getChild("MainList"));
500     Editbox* idbox = static_cast<Editbox*>(static_cast<const WindowEventArgs&>(args).window->getRootWindow()->getChild("ControlPanel/RowControl/RowColIDBox"));
501     Editbox* textbox = static_cast<Editbox*>(static_cast<const WindowEventArgs&>(args).window->getRootWindow()->getChild("ControlPanel/RowControl/RowTextBox"));
502 
503     // get the ID of the initial column item to set
504     CEGUI::uint id = atoi(idbox->getText().c_str());
505     // get the text that is to be set initially into the specified column of the new row
506     String text = textbox->getText();
507 
508     // reset input boxes
509     idbox->setText("");
510     textbox->setText("");
511 
512     // construct a new ListboxTextItem with the required string
513     ListboxTextItem* item = new ListboxTextItem(text);
514     // set the selection brush to use for this item.
515     item->setSelectionBrushImage("TaharezLook/MultiListSelectionBrush");
516 
517     // attempt to add a new row, using the new ListboxTextItem as the initial content for one of the columns
518     CEGUI_TRY
519     {
520         mcl->addRow(item, id);
521     }
522     // something went wrong, so cleanup the ListboxTextItem
523     CEGUI_CATCH (InvalidRequestException)
524     {
525         delete item;
526     }
527 
528     // event was handled.
529     return true;
530 }
531 
handleDeleteRow(const CEGUI::EventArgs & args)532 bool Demo6Sample::handleDeleteRow(const CEGUI::EventArgs& args)
533 {
534     using namespace CEGUI;
535 
536     // get access to the widgets that contain details about the row to delete.
537     MultiColumnList* mcl = static_cast<MultiColumnList*>(static_cast<const WindowEventArgs&>(args).window->getRootWindow()->getChild("MainList"));
538     Editbox* idxbox = static_cast<Editbox*>(static_cast<const WindowEventArgs&>(args).window->getRootWindow()->getChild("ControlPanel/RowControl/DelRowIdxBox"));
539 
540     // get index of row to delete.
541     CEGUI::uint idx = atoi(idxbox->getText().c_str());
542 
543     // attempt to delete the row, ignoring any errors.
544     CEGUI_TRY
545     {
546         mcl->removeRow(idx);
547     }
548     CEGUI_CATCH (InvalidRequestException)
549     {}
550 
551     // clear the row index box
552     idxbox->setText("");
553 
554     // event was handled.
555     return true;
556 }
557 
handleSetItem(const CEGUI::EventArgs & args)558 bool Demo6Sample::handleSetItem(const CEGUI::EventArgs& args)
559 {
560     using namespace CEGUI;
561 
562     // get access to the widgets that contain details about the item to be modified
563     MultiColumnList* mcl = static_cast<MultiColumnList*>(static_cast<const WindowEventArgs&>(args).window->getRootWindow()->getChild("MainList"));
564     Editbox* idbox = static_cast<Editbox*>(static_cast<const WindowEventArgs&>(args).window->getRootWindow()->getChild("ControlPanel/SetItemPanel/SetItemIDBox"));
565     Editbox* rowbox = static_cast<Editbox*>(static_cast<const WindowEventArgs&>(args).window->getRootWindow()->getChild("ControlPanel/SetItemPanel/SetItemRowBox"));
566     Editbox* textbox = static_cast<Editbox*>(static_cast<const WindowEventArgs&>(args).window->getRootWindow()->getChild("ControlPanel/SetItemPanel/SetItemTextBox"));
567 
568     // get ID of column to be affected
569     CEGUI::uint id = atoi(idbox->getText().c_str());
570     // get index of row to be affected
571     CEGUI::uint row = atoi(rowbox->getText().c_str());
572     // get new text for item
573     String text = textbox->getText();
574 
575     // reset input boxes
576     idbox->setText("");
577     rowbox->setText("");
578     textbox->setText("");
579 
580     // create a new ListboxTextItem using the new text string
581     ListboxTextItem* item = new ListboxTextItem(text);
582     // set the selection brush to be used for this item.
583     item->setSelectionBrushImage("TaharezLook/MultiListSelectionBrush");
584 
585     // attempt to set the new item in place
586     CEGUI_TRY
587     {
588         mcl->setItem(item, id, row);
589     }
590     // something went wrong, so cleanup the ListboxTextItem.
591     CEGUI_CATCH (InvalidRequestException)
592     {
593         delete item;
594     }
595 
596     // event was handled.
597     return true;
598 }
599 
handleSelectChanged(const CEGUI::EventArgs & args)600 bool Demo6Sample::handleSelectChanged(const CEGUI::EventArgs& args)
601 {
602     using namespace CEGUI;
603 
604     // Get access to the list
605     MultiColumnList* mcl = static_cast<MultiColumnList*>(static_cast<const WindowEventArgs&>(args).window->getRootWindow()->getChild("MainList"));
606 
607     // update the selected count
608     std::string tmp("Current Selected Count: ");
609 
610     char buff[16];
611     sprintf(buff, "%d", mcl->getSelectedCount());
612 
613     tmp += buff;
614 
615     static_cast<const WindowEventArgs&>(args).window->getRootWindow()->getChild("ControlPanel/SetItemPanel/SelCount")->setText(tmp.c_str());
616 
617     // event was handled.
618     return true;
619 }
620 
handleSelectModeChanged(const CEGUI::EventArgs & args)621 bool Demo6Sample::handleSelectModeChanged(const CEGUI::EventArgs& args)
622 {
623     using namespace CEGUI;
624 
625     // get access to list
626     MultiColumnList* mcl = static_cast<MultiColumnList*>(static_cast<const WindowEventArgs&>(args).window->getRootWindow()->getChild("MainList"));
627     // get access to the combobox
628     Combobox* combo = static_cast<Combobox*>(static_cast<const WindowEventArgs&>(args).window->getRootWindow()->getChild("ControlPanel/SelModeBox"));
629 
630     // find the selected item in the combobox
631     ListboxItem* item = combo->findItemWithText(combo->getText(), 0);
632 
633     // set new selection mode according to ID of selected ListboxItem
634     if (item)
635     {
636         switch (item->getID())
637         {
638         case 0:
639             mcl->setSelectionMode(MultiColumnList::RowSingle);
640             break;
641 
642         case 1:
643             mcl->setSelectionMode(MultiColumnList::RowMultiple);
644             break;
645 
646         case 2:
647             mcl->setSelectionMode(MultiColumnList::ColumnSingle);
648             break;
649 
650         case 3:
651             mcl->setSelectionMode(MultiColumnList::ColumnMultiple);
652             break;
653 
654         case 4:
655             mcl->setSelectionMode(MultiColumnList::CellSingle);
656             break;
657 
658         case 5:
659             mcl->setSelectionMode(MultiColumnList::CellMultiple);
660             break;
661 
662         case 6:
663             mcl->setSelectionMode(MultiColumnList::NominatedColumnSingle);
664             break;
665 
666         case 7:
667             mcl->setSelectionMode(MultiColumnList::NominatedColumnMultiple);
668             break;
669 
670         case 8:
671             mcl->setSelectionMode(MultiColumnList::NominatedRowSingle);
672             break;
673 
674         case 9:
675             mcl->setSelectionMode(MultiColumnList::NominatedRowMultiple);
676             break;
677 
678         default:
679             mcl->setSelectionMode(MultiColumnList::RowSingle);
680             break;
681 
682         }
683     }
684 
685     // event was handled.
686     return true;
687 }
688 
handleContentsChanged(const CEGUI::EventArgs & args)689 bool Demo6Sample::handleContentsChanged(const CEGUI::EventArgs& args)
690 {
691     using namespace CEGUI;
692 
693     // get access to required widgets
694     MultiColumnList* mcl = static_cast<MultiColumnList*>(static_cast<const WindowEventArgs&>(args).window->getRootWindow()->getChild("MainList"));
695     Window* colText = static_cast<const WindowEventArgs&>(args).window->getRootWindow()->getChild("ControlPanel/SetItemPanel/ColCount");
696     Window* rowText = static_cast<const WindowEventArgs&>(args).window->getRootWindow()->getChild("ControlPanel/SetItemPanel/RowCount");
697 
698     std::string tmp;
699     char buff[16];
700 
701     // update the column count
702     tmp = "Current Column Count: ";
703     sprintf(buff, "%d", mcl->getColumnCount());
704     tmp += buff;
705     colText->setText(tmp.c_str());
706 
707     // update the row count
708     tmp = "Current Row Count: ";
709     sprintf(buff, "%d", mcl->getRowCount());
710     tmp += buff;
711     rowText->setText(tmp.c_str());
712 
713     // event was handled.
714     return true;
715 }
716 
717 /*************************************************************************
718     Define the module function that returns an instance of the sample
719 *************************************************************************/
getSampleInstance()720 extern "C" SAMPLE_EXPORT Sample& getSampleInstance()
721 {
722     static Demo6Sample sample;
723     return sample;
724 }