home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Divers / lyx-0.13.2.tar.gz / lyx-0.13.2.tar / lyx-0.13.2 / src / combox.h < prev    next >
C/C++ Source or Header  |  1998-04-23  |  4KB  |  216 lines

  1. // -*- C++ -*-
  2. /*
  3.  *  Combox: A combination of two objects (a button and a browser) is
  4.  *          encapsulated to get a combobox-like object. All XForms 
  5.  *          functions are hidden.         
  6.  * 
  7.  *  GNU Copyleft (C) 1996 Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
  8.  *                        and the LyX Team.
  9.  * 
  10.  *  Dependencies:  Only XForms, but created to be used with LyX.
  11.  * 
  12.  */ 
  13.  
  14. /* Change log:
  15.  *  
  16.  *  2/06/1996,   Alejandro Aguilar Sierra 
  17.  *    Created and tested.
  18.  *  
  19.  *  4/06/1996,   Alejandro Aguilar Sierra 
  20.  *    Added droplist mode (a button with a black down arrow at right)
  21.  *    and support for middle and right buttons, as XForms choice object.
  22.  */ 
  23.  
  24. #ifndef _COMBOX_H_
  25. #define _COMBOX_H_
  26.  
  27. #ifdef __GNUG__
  28. #pragma interface
  29. #endif
  30.  
  31. #include FORMS_H_LOCATION
  32. #include <stdlib.h>
  33.  
  34. #include "LString.h"
  35.  
  36. /// callback prototype
  37. typedef void (*FL_COMBO_CB) (int, void*);
  38. /// pre post prototype
  39. typedef void (*FL_COMBO_PRE_POST) ();
  40.  
  41.  
  42. ///
  43. class Combox {
  44. public:
  45.     //
  46.     enum combox_type {
  47.         ///
  48.         FL_COMBOX_NORMAL,
  49.         ///
  50.         FL_COMBOX_DROPLIST,
  51.         ///
  52.         FL_COMBOX_INPUT
  53.     };
  54.     ///
  55.     Combox(combox_type t=FL_COMBOX_NORMAL);
  56.     ///
  57.     ~Combox();
  58.  
  59.     /** To add this object to a form. Note that there are two heights
  60.      for normal (button) and expanded (browser) mode each. */
  61.     void add(int x, int y, int w, int hmin, int hmax);
  62.     
  63.     /// Add lines. Same as for fl_browser object
  64.     void addline(LString const &);
  65.     /// Add lines. Same as for fl_browser object
  66.     void addto(LString const &);
  67.     
  68.     /// Returns the selected item
  69.     int get();
  70.    
  71.     /// Returns a pointer to the selected line of text
  72.     LString getline();
  73.    
  74.     ///  Select an arbitrary item
  75.     void select(int);
  76.     ///
  77.         bool select_text(LString const &);
  78.    
  79.     ///  Clear all the list
  80.     void clear();
  81.  
  82.     /// Is the combox cleared (empty)
  83.     bool empty() { return is_empty; }
  84.     
  85.     /// Remove the objects from the form they are in. 
  86.     void remove();
  87.  
  88.     /**  Assign a callback to this object. The callback should be a void
  89.      function with a int and a void pointer as parameters. */
  90.     void setcallback(FL_COMBO_CB, void *);
  91.    
  92.         ///  Pre handler
  93.     void setpre(FL_COMBO_PRE_POST);
  94.     /// Post handler
  95.     void setpost(FL_COMBO_PRE_POST);
  96.     
  97.     ///  XForms attributes
  98.     void resize(unsigned);
  99.     ///
  100.     void gravity(unsigned, unsigned);
  101.     ///
  102.     void activate();
  103.     ///
  104.     void deactivate();
  105.     ///
  106.         void shortcut(LString const &, int);
  107.     ///
  108.     void Show();
  109.  protected:
  110.         /// At least Hide should not be public
  111.     void Hide(int who = 0);
  112.     ///
  113.     FL_OBJECT *browser;
  114.  private:
  115.     ///
  116.     combox_type type;
  117.     ///
  118.         int bw, bh;
  119.     ///
  120.     int sel;
  121.     ///
  122.     bool is_empty;
  123.     ///
  124.     static void combo_cb(FL_OBJECT *, long);
  125.     ///
  126.     static void input_cb(FL_OBJECT *, long);
  127.     ///
  128.         static int  peek_event(FL_FORM *, void *);
  129.     ///
  130.     FL_COMBO_CB callback;
  131.     ///
  132.     void *cb_arg;
  133.     ///
  134.     FL_COMBO_PRE_POST _pre;
  135.     ///
  136.     FL_COMBO_PRE_POST _post;
  137.     ///
  138.     FL_OBJECT *button;
  139.     ///
  140.     FL_OBJECT *label;
  141.     ///
  142.         FL_FORM* form;
  143. };
  144.  
  145.  
  146.  
  147. //-----------------  Inline methods  --------------------------- 
  148.  
  149. inline
  150. void Combox::addto(LString const &text)
  151. {
  152.     if (browser) {
  153.         fl_addto_browser(browser, text.c_str());
  154.         is_empty = false;
  155.     }
  156. }
  157.  
  158. inline
  159. void Combox::resize(unsigned r)
  160. {
  161.    fl_set_object_resize(button, r);
  162.    if (label!=button) fl_set_object_resize(label, r); 
  163. }
  164.  
  165. inline
  166. void Combox::gravity(unsigned g1, unsigned g2)
  167. {
  168.    fl_set_object_gravity(button, g1, g2);
  169.    if (label!=button) fl_set_object_gravity(label, g1, g2); 
  170. }
  171.  
  172. inline
  173. void Combox::shortcut(LString const &s, int i)
  174. {
  175.    if (button)
  176.       fl_set_object_shortcut(button,s.c_str(),i);
  177. }
  178.  
  179. inline
  180. void Combox::setcallback(FL_COMBO_CB cb, void *a = NULL)
  181. {
  182.    callback = cb;
  183.    cb_arg = a;
  184. }
  185.  
  186. inline
  187. void Combox::setpre(FL_COMBO_PRE_POST cb)
  188. {
  189.     _pre = cb;
  190. }
  191.  
  192. inline
  193. void Combox::setpost(FL_COMBO_PRE_POST cb)
  194. {
  195.     _post = cb;
  196. }
  197.  
  198. inline
  199. int Combox::get()
  200. {
  201.    return sel;
  202. }
  203.  
  204. inline
  205. LString Combox::getline()
  206. {
  207.     if (type==FL_COMBOX_INPUT) 
  208.       return fl_get_input(label);
  209.     else
  210.       return ((browser) ? LString(fl_get_browser_line(browser, sel)): LString());
  211. }
  212.  
  213. #endif
  214.  
  215.  
  216.