list_box.cpp

Go to the documentation of this file.
00001 #ifndef LIST_BOX_IMPLEMENTATION_FILE
00002 #define LIST_BOX_IMPLEMENTATION_FILE
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : list_box                                                          *
00007 *  Author : Chris Koeritz                                                     *
00008 *                                                                             *
00009 *******************************************************************************
00010 * Copyright (c) 1991-$now By Author.  This program is free software; you can  *
00011 * redistribute it and/or modify it under the terms of the GNU General Public  *
00012 * License as published by the Free Software Foundation; either version 2 of   *
00013 * the License or (at your option) any later version.  This is online at:      *
00014 *     http://www.fsf.org/copyleft/gpl.html                                    *
00015 * Please send any updates to: fred@gruntose.com                               *
00016 \*****************************************************************************/
00017 
00018 #include "list_box.h"
00019 
00020 #include <basis/function.h>
00021 #include <wp_passive/system_string.h>
00022 #include <wp_passive/wp_implementation.h>
00023 
00024 #ifdef __XWINDOWS__
00025   #include <Xm/List.h>
00026 #endif
00027 
00028 list_box::list_box(manager &parent, const c_point &origin, int entries,
00029     list_box_kinds type, const color &foreground, const color &background)
00030 : worker(parent, c_rectangle(origin, origin), NIL, foreground, background),
00031   array<istring>(entries), _kind(type)
00032 {}
00033 
00034 list_box::~list_box() {}
00035 
00036 void list_box::selection_event(int index)
00037 {
00038   FUNCDEF("selection_event");
00039   LOG(isprintf("blank list_box selection on index %d.", index));
00040 }
00041 
00042 const array<istring> &list_box::items() const { return *this; }
00043 
00044 window_handle list_box::create_handle()
00045 {
00046   FUNCDEF("create_handle");
00047 LOG("create handle in");
00048   array<system_string *> hold_strings(length());
00049   window_string *to_pass_to_X = new window_string[length()];
00050     // deleted at end of function.
00051   for (int i = 0; i < length(); i++) {
00052     hold_strings.put(i, new system_string(get(i)));
00053       // create a string. which is deleted at the end of this function.
00054     to_pass_to_X[i] = window_string(*hold_strings.get(i));
00055       // keep track of the string's address to pass to x.
00056   }
00057 LOG("handle did array");
00058 
00059   argument_list wargs;
00060   wargs.add(XmNitems, XtArgVal(to_pass_to_X));
00061   wargs.add(XmNitemCount, length());
00062 LOG("about to create widg");
00063   window_handle to_return = XtCreateManagedWidget
00064     ("list_box", xmListWidgetClass, root().self(),
00065      wargs.generate(), wargs.number());
00066 LOG("after created");
00067   char *callback_kind = NIL;
00068   bool do_callback = true;
00069   switch (_kind) {
00070   case SINGLE_SELECTION: callback_kind = XmNsingleSelectionCallback; break;
00071   case MULTIPLE_SELECTION: callback_kind = XmNmultipleSelectionCallback; break;
00072   case DISPLAY_ONLY:  // intentional fall-through to default.
00073   default: do_callback = false;
00074   }
00075 LOG("about to add callback");
00076   if (do_callback)
00077     XtAddCallback(to_return, callback_kind, XtCallbackProc(list_box_callback),
00078         XtPointer(this));
00079 LOG("create handle out");
00080   delete to_pass_to_X;
00081   for (int j = 0; j < hold_strings.length(); j++) delete hold_strings.get(j);
00082   return to_return;
00083 }
00084 
00085 void list_box::contents(int index, const istring &to_print)
00086 { put(index, to_print); }
00087 
00088 istring list_box::contents(int index) const { return get(index); }
00089 
00090 void list_box::draw() { if (!self()) self(create_handle()); worker::draw(); }
00091 
00092 void list_box::list_box_callback(window_handle, list_box *me, XmListCallbackStruct *calldata)
00093 {
00094   FUNCDEF("callback");
00095   LOG(isprintf("blank list_box_callback: item chosen=%s",
00096       me->items().get(calldata->item_position).s()));
00097 }
00098 
00099 
00100 #endif //LIST_BOX_IMPLEMENTATION_FILE
00101 

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