home *** CD-ROM | disk | FTP | other *** search
/ Game Programming in C++ - Start to Finish / GameProgrammingS.iso / developer_install / CEGUISDK-0.4.1-VC6-Native.exe / {app} / Samples / Demo6 / src / Sample_Demo6.cpp next >
Encoding:
C/C++ Source or Header  |  2005-08-27  |  28.2 KB  |  724 lines

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