list_box.h

Go to the documentation of this file.
00001 #ifndef LIST_BOX_CLASS
00002 #define LIST_BOX_CLASS
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : list_box                                                          *
00007 *  Author : Chris Koeritz                                                     *
00008 *                                                                             *
00009 *  Purpose:                                                                   *
00010 *                                                                             *
00011 *    Shows the user a set of text strings in a box, which may optionally      *
00012 *  trigger an event function for that item.                                   *
00013 *                                                                             *
00014 *******************************************************************************
00015 * Copyright (c) 1991-$now By Author.  This program is free software; you can  *
00016 * redistribute it and/or modify it under the terms of the GNU General Public  *
00017 * License as published by the Free Software Foundation; either version 2 of   *
00018 * the License or (at your option) any later version.  This is online at:      *
00019 *     http://www.fsf.org/copyleft/gpl.html                                    *
00020 * Please send any updates to: fred@gruntose.com                               *
00021 \*****************************************************************************/
00022 
00023 // Model:
00024 //
00025 //   The origin of the list_box is the lower left corner.  List_box objects'
00026 //   origins are measured in universal coordinates.
00027 
00028 #include "dll_wp_active.h"
00029 
00030 #include <basis/istring.h>
00031 
00032 #include <wp_passive/worker.h>
00033 
00034 enum list_box_kinds { DISPLAY_ONLY, SINGLE_SELECTION, MULTIPLE_SELECTION };
00035   // These are the different types of list_boxes that can be created.
00036   // DISPLAY_ONLY means that the items are visible but that no action occurs
00037   // when the user selects an item.  SINGLE_SELECTION means that the user
00038   // is allowed to select one item, the selection of which causes the list_
00039   // box's event function to be invoked.  only one item is allowed to be
00040   // selected at once.  MULTIPLE_SELECTION allows more than one item to be
00041   // selected; the event function is called for each item as it is selected
00042 
00043 class WP_ACTIVE_CLASS_STYLE list_box : public worker, private array<istring>
00044 {
00045 public:
00046   list_box(manager &parent, const c_point &origin, int entries,
00047           list_box_kinds type, const color &foreground = colors::WHITE,
00048           const color &background = colors::BLACK);
00049     // creates a list_box capable of holding "entries" items.
00050   
00051   ~list_box();
00052 
00053   IMPLEMENT_CLASS_NAME("list_box");
00054 
00055   istring contents(int index) const;
00056     // returns a string containing the contents of the box at "index".  an
00057     // empty string is returned if the index is not valid.
00058   void contents(int index, const istring &to_show);
00059     // sets the contents of the list_box to "to_show".  the call is ignored if
00060     // index is invalid.
00061 
00062   const array<istring> &items() const;
00063     // returns a reference to the list of items.
00064 
00065   virtual void selection_event(int index_selected);
00066     // called when the user selects an item.
00067 
00068   virtual void draw();
00069     // call when the contents have been completely set up.
00070 
00071   static void list_box_callback(window_handle h, list_box *me,
00072           XmListCallbackStruct *calldata);
00073     // invoked when motif notices a change in the list.
00074 
00075 private:
00076   istring _contents;
00077   list_box_kinds _kind;
00078 
00079   window_handle create_handle();
00080 };
00081 
00082 #endif
00083 

Generated on Thu Nov 20 04:28:50 2008 for HOOPLE Libraries by  doxygen 1.5.1