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} / include / elements / CEGUIItemListBase.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-07-10  |  11.7 KB  |  428 lines

  1. /************************************************************************
  2.     filename:     CEGUIItemListBase.h
  3.     created:    31/3/2005
  4.     author:        Tomas Lindquist Olsen (based on original Listbox code by Paul D Turner)
  5.     
  6.     purpose:    Interface to base class for ItemListBase widgets
  7. *************************************************************************/
  8. /*************************************************************************
  9.     Crazy Eddie's GUI System (http://www.cegui.org.uk)
  10.     Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
  11.  
  12.     This library is free software; you can redistribute it and/or
  13.     modify it under the terms of the GNU Lesser General Public
  14.     License as published by the Free Software Foundation; either
  15.     version 2.1 of the License, or (at your option) any later version.
  16.  
  17.     This library is distributed in the hope that it will be useful,
  18.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  20.     Lesser General Public License for more details.
  21.  
  22.     You should have received a copy of the GNU Lesser General Public
  23.     License along with this library; if not, write to the Free Software
  24.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  25. *************************************************************************/
  26. #ifndef _CEGUIItemListBase_h_
  27. #define _CEGUIItemListBase_h_
  28.  
  29. #include "CEGUIBase.h"
  30. #include "CEGUIWindow.h"
  31. #include "elements/CEGUIItemListBaseProperties.h"
  32. #include "elements/CEGUIItemEntry.h"
  33.  
  34. #include <vector>
  35.  
  36.  
  37. #if defined(_MSC_VER)
  38. #    pragma warning(push)
  39. #    pragma warning(disable : 4251)
  40. #endif
  41.  
  42.  
  43. // Start of CEGUI namespace section
  44. namespace CEGUI
  45. {
  46.  
  47. /*!
  48. \brief
  49.     Base class for item list widgets.
  50. */
  51. class CEGUIEXPORT ItemListBase : public Window
  52. {
  53. public:
  54.     static const String EventNamespace;                //!< Namespace for global events
  55.  
  56.  
  57.     /*************************************************************************
  58.         Constants
  59.     *************************************************************************/
  60.     // event names
  61.     static const String EventListContentsChanged;            //!< Event triggered when the contents of the list is changed.
  62.  
  63.  
  64.     /*************************************************************************
  65.         Accessor Methods
  66.     *************************************************************************/
  67.     /*!
  68.     \brief
  69.         Return number of items attached to the list
  70.  
  71.     \return
  72.         the number of items currently attached to this list.
  73.     */
  74.     size_t    getItemCount(void) const        {return d_listItems.size();}
  75.  
  76.  
  77.     /*!
  78.     \brief
  79.         Return the item at index position \a index.
  80.  
  81.     \param index
  82.         Zero based index of the item to be returned.
  83.  
  84.     \return
  85.         Pointer to the ItemEntry at index position \a index in the list.
  86.  
  87.     \exception    InvalidRequestException    thrown if \a index is out of range.
  88.     */
  89.     ItemEntry*    getItemFromIndex(size_t index) const;
  90.  
  91.  
  92.     /*!
  93.     \brief
  94.         Return the index of ItemEntry \a item
  95.  
  96.     \param item
  97.         Pointer to a ItemEntry whos zero based index is to be returned.
  98.  
  99.     \return
  100.         Zero based index indicating the position of ItemEntry \a item in the list.
  101.  
  102.     \exception    InvalidRequestException    thrown if \a item is not attached to this list.
  103.     */
  104.     size_t    getItemIndex(const ItemEntry* item) const;
  105.  
  106.  
  107.     /*!
  108.     \brief
  109.         Search the list for an item with the specified text
  110.  
  111.     \param text
  112.         String object containing the text to be searched for.
  113.  
  114.     \param start_item
  115.         ItemEntry where the search is to begin, the search will not include \a item.  If \a item is
  116.         NULL, the search will begin from the first item in the list.
  117.  
  118.     \return
  119.         Pointer to the first ItemEntry in the list after \a item that has text matching \a text.  If
  120.         no item matches the criteria NULL is returned.
  121.  
  122.     \exception    InvalidRequestException    thrown if \a item is not attached to this list box.
  123.     */
  124.     ItemEntry*    findItemWithText(const String& text, const ItemEntry* start_item);
  125.  
  126.  
  127.     /*!
  128.     \brief
  129.         Return whether the specified ItemEntry is in the List
  130.  
  131.     \return
  132.         true if ItemEntry \a item is in the list, false if ItemEntry \a item is not in the list.
  133.     */
  134.     bool    isItemInList(const ItemEntry* item) const;
  135.  
  136.  
  137.     /*!
  138.     \brief
  139.         Return wheter this window is automatically resized to fit its content.
  140.  
  141.     \return
  142.         true if automatic resizing is enabled, false if it is disabled.
  143.     */
  144.     bool isAutoResizeEnabled() const        {return d_autoResize;}
  145.  
  146.  
  147.     /*************************************************************************
  148.         Manipulator Methods
  149.     *************************************************************************/
  150.     /*!
  151.     \brief
  152.         Initialise the Window based object ready for use.
  153.  
  154.     \note
  155.         This must be called for every window created.  Normally this is handled automatically by the WindowFactory for each Window type.
  156.  
  157.     \return
  158.         Nothing
  159.     */
  160.     virtual void    initialise(void);
  161.  
  162.  
  163.     /*!
  164.     \brief
  165.         Remove all items from the list.
  166.  
  167.         Note that this will cause 'AutoDelete' items to be deleted.
  168.     */
  169.     void    resetList(void);
  170.  
  171.  
  172.     /*!
  173.     \brief
  174.         Add the given ItemEntry to the list.
  175.  
  176.     \param item
  177.         Pointer to the ItemEntry to be added to the list.  Note that it is the passed object that is added to the
  178.         list, a copy is not made.  If this parameter is NULL, nothing happens.
  179.  
  180.     \return
  181.         Nothing.
  182.     */
  183.     void    addItem(ItemEntry* item);
  184.  
  185.  
  186.     /*!
  187.     \brief
  188.         Insert an item into the list after a specified item already in the list.
  189.  
  190.         Note that if the list is sorted, the item may not end up in the requested position.
  191.  
  192.     \param item
  193.         Pointer to the ItemEntry to be inserted.  Note that it is the passed object that is added to the
  194.         list, a copy is not made.  If this parameter is NULL, nothing happens.
  195.  
  196.     \param position
  197.         Pointer to a ItemEntry that \a item is to be inserted after.  If this parameter is NULL, the item is
  198.         inserted at the start of the list.
  199.  
  200.     \return
  201.         Nothing.
  202.     */
  203.     void    insertItem(ItemEntry* item, const ItemEntry* position);
  204.  
  205.  
  206.     /*!
  207.     \brief
  208.         Removes the given item from the list.  If the item is has the auto delete state set, the item will be deleted.
  209.  
  210.     \param item
  211.         Pointer to the ItemEntry that is to be removed.  If \a item is not attached to this list then nothing
  212.         will happen.
  213.  
  214.     \return
  215.         Nothing.
  216.     */
  217.     void    removeItem(ItemEntry* item);
  218.  
  219.  
  220.     /*!
  221.     \brief
  222.         Causes the list to update it's internal state after changes have been made to one or more
  223.         attached ItemEntry objects.
  224.  
  225.         Client code must call this whenever it has made any changes to ItemEntry objects already attached to the
  226.         list.  If you are just adding items, or removed items to update them prior to re-adding them, there is
  227.         no need to call this method.
  228.  
  229.     \return
  230.         Nothing.
  231.     */
  232.     void    handleUpdatedItemData(void);
  233.  
  234.  
  235.     /*!
  236.     \brief
  237.         Set whether or not this ItemListBase widget should automatically resize to fit its content.
  238.  
  239.     \param setting
  240.         Boolean value that if true enables automatic resizing, if false disables automatic resizing.
  241.  
  242.     \return
  243.         Nothing.
  244.     */
  245.     void setAutoResizeEnabled(bool setting);
  246.  
  247.  
  248.     /*!
  249.     \brief
  250.     Resize the ItemListBase to exactly fit the content that is attached to it.
  251.     Return a Rect object describing, in un-clipped pixels, the window relative area
  252.     that is to be used for rendering items.
  253.  
  254.     \return
  255.     Nothing
  256.     */
  257.     virtual    void    sizeToContent(void)        {sizeToContent_impl();}
  258.  
  259.  
  260.     /*************************************************************************
  261.         Construction and Destruction
  262.     *************************************************************************/
  263.     /*!
  264.     \brief
  265.         Constructor for ItemListBase base class.
  266.     */
  267.     ItemListBase(const String& type, const String& name);
  268.  
  269.  
  270.     /*!
  271.     \brief
  272.         Destructor for ItemListBase base class.
  273.     */
  274.     virtual ~ItemListBase(void);
  275.  
  276.  
  277. protected:
  278.     /*************************************************************************
  279.         Abstract Implementation Functions (must be provided by derived class)
  280.     *************************************************************************/
  281.     /*!
  282.     \brief
  283.         Resize the ItemListBase to exactly fit the content that is attached to it.
  284.         Return a Rect object describing, in un-clipped pixels, the window relative area
  285.         that is to be used for rendering items.
  286.  
  287.     \return
  288.         Nothing
  289.     */
  290.     virtual    void    sizeToContent_impl(void)        = 0;
  291.  
  292.  
  293.     /*!
  294.     \brief
  295.         Returns the Size in unclipped pixels of the content attached to this ItemListBase that is attached to it.
  296.  
  297.     \return
  298.         Nothing.
  299.     */
  300.     virtual Size getContentSize()        = 0;
  301.  
  302.  
  303.     /*!
  304.     \brief
  305.         Return a Rect object describing, in un-clipped pixels, the window relative area
  306.         that is to be used for rendering list items.
  307.  
  308.     \return
  309.         Rect object describing the window relative area of the that is to be used for rendering
  310.         the items.
  311.     */
  312.     virtual    Rect    getItemRenderArea(void) const        = 0;
  313.  
  314.  
  315.     /*!
  316.     \brief
  317.         Setup size and position for the item widgets attached to this ItemListBase
  318.  
  319.     \return
  320.         Nothing.
  321.     */
  322.     virtual void    layoutItemWidgets()    = 0;
  323.  
  324.  
  325.     /*!
  326.     \brief
  327.         Perform the actual rendering for this Window.
  328.  
  329.     \return
  330.         Nothing
  331.     */
  332.     virtual    void    populateRenderCache() = 0;
  333.  
  334.  
  335.     /*************************************************************************
  336.         Implementation Functions
  337.     *************************************************************************/
  338.     /*!
  339.     \brief
  340.         Add list box specific events
  341.     */
  342.     void    addItemListBaseEvents(void);
  343.  
  344.  
  345.     /*!
  346.     \brief
  347.         Remove all items from the list.
  348.  
  349.     \note
  350.         Note that this will cause 'AutoDelete' items to be deleted.
  351.  
  352.     \return
  353.         - true if the list contents were changed.
  354.         - false if the list contents were not changed (list already empty).
  355.     */
  356.     bool    resetList_impl(void);
  357.  
  358.  
  359.     /*!
  360.     \brief
  361.         Return whether this window was inherited from the given class name at some point in the inheritance heirarchy.
  362.  
  363.     \param class_name
  364.         The class name that is to be checked.
  365.  
  366.     \return
  367.         true if this window was inherited from \a class_name. false if not.
  368.     */
  369.     virtual bool    testClassName_impl(const String& class_name) const
  370.     {
  371.         if (class_name==(const utf8*)"ItemListBase")    return true;
  372.         return Window::testClassName_impl(class_name);
  373.     }
  374.  
  375.     /*************************************************************************
  376.         New event handlers
  377.     *************************************************************************/
  378.     /*!
  379.     \brief
  380.         Handler called internally when the list contents are changed
  381.     */
  382.     virtual    void    onListContentsChanged(WindowEventArgs& e);
  383.  
  384.  
  385.     /*************************************************************************
  386.         Overridden Event handlers
  387.     *************************************************************************/
  388.     virtual void    onSized(WindowEventArgs& e);
  389.  
  390.  
  391.     /*************************************************************************
  392.         Implementation Data
  393.     *************************************************************************/
  394.     typedef    std::vector<ItemEntry*>    ItemEntryList;
  395.     ItemEntryList    d_listItems;        //!< list of items in the list.
  396.  
  397.     // boolean telling if this ItemListBase widget should automatically resize to fit its content.
  398.     bool d_autoResize;
  399.  
  400. private:
  401.     /*************************************************************************
  402.     Static Properties for this class
  403.     *************************************************************************/
  404.     static ItemListBaseProperties::AutoResizeEnabled    d_autoResizeEnabledProperty;
  405.  
  406.  
  407.     /*************************************************************************
  408.         Private methods
  409.     *************************************************************************/
  410.     void    addItemListBaseProperties(void);
  411.  
  412.  
  413.     /*!
  414.     \brief
  415.         Add given window to child list at an appropriate position
  416.     */
  417.     virtual void    addChild_impl(Window* wnd);
  418. };
  419.  
  420. } // End of  CEGUI namespace section
  421.  
  422.  
  423. #if defined(_MSC_VER)
  424. #    pragma warning(pop)
  425. #endif
  426.  
  427. #endif    // end of guard _CEGUIItemListBase_h_
  428.