home *** CD-ROM | disk | FTP | other *** search
/ Borland Programmer's Resource / Borland_Programmers_Resource_CD_1995.iso / code / wxwin140 / include / wx_item.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-19  |  9.2 KB  |  357 lines

  1. /*
  2.  * File:     wx_item.h
  3.  * Purpose:  Declares panel items (controls/widgets)
  4.  *
  5.  *                       wxWindows 1.40
  6.  * Copyright (c) 1993 Artificial Intelligence Applications Institute,
  7.  *                   The University of Edinburgh
  8.  *
  9.  *                     Author: Julian Smart
  10.  *                       Date: 18-4-93
  11.  *
  12.  * Permission to use, copy, modify, and distribute this software and its
  13.  * documentation for any purpose is hereby granted without fee, provided
  14.  * that the above copyright notice, author statement and this permission
  15.  * notice appear in all copies of this software and related documentation.
  16.  *
  17.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, EXPRESS,
  18.  * IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF
  19.  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
  20.  *
  21.  * IN NO EVENT SHALL THE ARTIFICIAL INTELLIGENCE APPLICATIONS INSTITUTE OR THE
  22.  * UNIVERSITY OF EDINBURGH BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT OR
  23.  * CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER RESULTING FROM
  24.  * LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF THE POSSIBILITY OF
  25.  * DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH
  26.  * THE USE OR PERFORMANCE OF THIS SOFTWARE.
  27.  */
  28.  
  29. #ifndef wx_itemh
  30. #define wx_itemh
  31.  
  32. #include "common.h"
  33. #include "wx_win.h"
  34. #include "wx_panel.h"
  35.  
  36. #ifdef wx_msw
  37. #include <windows.h>
  38. #endif
  39. #ifdef wx_motif
  40. #include <Xm/Label.h>
  41. #include <Xm/Form.h>
  42. #endif
  43. #ifdef wx_xview
  44. #include <xview/openmenu.h>
  45. #endif
  46.  
  47. // General item class
  48. class wxItem: public wxWindow
  49. {
  50.  public:
  51.     wxItem(void);
  52.    ~wxItem(void);
  53. #ifdef wx_motif
  54.    // Each item is a form/rowcol widget, optional label widget, plus a specific
  55.    // widget
  56.    Widget formWidget;
  57.    Widget labelWidget;
  58.    int itemOrientation;
  59.    void AttachWidget(wxPanel *panel, Widget formWidget,
  60.                      int x, int y, int width, int height);
  61. #endif
  62.    int labelPosition;
  63.  
  64.    void GetSize(int *width, int *height);
  65.    void GetPosition(int *x, int *y);
  66.    void SetSize(int x, int y, int width, int height);
  67.    void SetClientSize(int width, int height);
  68.    void SetFocus(void);
  69.    virtual void SetDefault(void);
  70.    virtual void SetLabel(char *label);
  71.    virtual char *GetLabel(void);
  72.  
  73.    void Show(Bool show);
  74.    float GetTextHeight(void);
  75.    float GetTextWidth(void);
  76.    void GetTextExtent(char *string, float *x, float *y);
  77.    int GetLabelPosition(void);
  78.    void SetLabelPosition(int pos);
  79.  
  80.   // Places item in centre of panel - so can't be used BEFORE panel->Fit()
  81.   void Centre(int direction = wxHORIZONTAL);
  82. };
  83.  
  84. // Pushbutton
  85. class wxButton: public wxItem
  86. {
  87.  public:
  88.   wxButton(wxPanel *panel, wxFunction func, char *label, int x = -1, int y = -1,
  89.            int width = -1, int height = -1);
  90.   ~wxButton(void);
  91.   void SetSize(int x, int y, int width, int height);
  92.   void SetFocus(void);
  93.   void SetDefault(void);
  94.   void SetLabel(char *);
  95.   char *GetLabel(void);
  96. #ifdef wx_msw
  97.   virtual BOOL Command(UINT param);
  98. #endif
  99. };
  100.  
  101. class wxMenuBar;
  102.  
  103. #ifdef wx_motif
  104. class wxMenuItem: public wxObject
  105. {
  106.  public:
  107.   Widget buttonWidget; // The actual string, so we can grey it etc.
  108.   wxMenuBar *menuBar;
  109.   int itemId;
  110.   char *itemName;
  111.   wxMenu *subMenu;
  112.   wxMenuItem(void) { itemName = NULL; subMenu = NULL; }
  113.   ~wxMenuItem(void) { if (itemName) delete itemName; }
  114. };
  115.  
  116. #endif
  117.  
  118. // Menu
  119. class wxMenu: public wxItem
  120. {
  121.   int no_items;
  122.  public:
  123.   char *title;
  124.   wxMenu *top_level_menu;
  125.   wxMenuBar *menu_bar;
  126.  
  127. #ifdef wx_motif
  128.   Widget buttonWidget; // The actual string, so we can grey it etc.
  129.   wxList menuItems;
  130.   int menuId;
  131. #endif
  132.  
  133.   wxMenu(char *Title = NULL, wxFunction func = NULL);
  134.   ~wxMenu(void);
  135.   virtual void AppendSeparator(void);
  136.   virtual void Append(int Id, char *Label);
  137.   virtual void Append(int Id, char *Label, wxMenu *SubMenu);
  138.   virtual void Enable(int Id, Bool Flag);
  139.   virtual void Check(int Id, Bool Flag);
  140. #ifdef wx_motif
  141.   Widget CreateMenu(wxMenuBar *menu_bar, Widget parent, char *title);
  142.   Widget FindMenuItem(int Id);
  143. #endif
  144. #ifdef wx_xview
  145.   Menu_item FindMenuItem(int Id);
  146. #endif
  147. };
  148.  
  149. // Menu Bar (a la Windows)
  150. #define MENU_BAR_PANEL_HEIGHT 30
  151. class wxFrame;
  152. class wxMenuBar:public wxItem
  153. {
  154.  public:
  155.   int n;
  156.   wxMenu **menus;
  157.   char **titles;
  158.   wxFrame *menu_bar_frame;
  159.  
  160.   wxMenuBar(void);
  161.   wxMenuBar(int n, wxMenu *menus[], char *Titles[]);
  162.   ~wxMenuBar(void);
  163.  
  164.   virtual void Append(wxMenu *menu, char *title);
  165.   // Must only be used AFTER menu has been attached to frame,
  166.   // otherwise use individual menus to enable/disable items
  167.   virtual void Enable(int Id, Bool Flag);
  168.   virtual void Check(int Id, Bool Flag);
  169. };
  170.  
  171. // Checkbox item (single checkbox)
  172. class wxCheckBox: public wxItem
  173. {
  174.  public:
  175.   wxCheckBox(wxPanel *panel, wxFunction func, char *Title,
  176.              int x = -1, int y = -1, int width = -1, int height = -1);
  177.   ~wxCheckBox(void);
  178.   virtual void SetValue(Bool);
  179.   virtual Bool GetValue(void);
  180.   void SetSize(int x, int y, int width, int height);
  181. #ifdef wx_msw
  182.   virtual BOOL Command(UINT param);
  183. #endif
  184. };
  185.  
  186. // Choice item
  187. class wxChoice: public wxItem
  188. {
  189.   int no_strings;
  190.  public:
  191. #ifdef wx_motif
  192.   Widget menuWidget;
  193.   Widget buttonWidget;
  194.   Widget messageWidget;
  195.   Widget rowWidget;
  196.   wxStringList stringList;
  197. #endif
  198. #ifdef wx_msw
  199.   HWND static_label;
  200. #endif
  201.  
  202.   wxChoice(wxPanel *panel, wxFunction func, char *Title,
  203.            int x = -1, int y = -1, int width = -1, int height = -1,
  204.            int N = 0, char **Choices = NULL);
  205.   ~wxChoice(void);
  206.   virtual void Append(char *Item);
  207.   virtual void Clear(void);
  208.   virtual int GetSelection(void);
  209.   virtual void SetSelection(int n);
  210.   virtual int FindString(char *s);
  211.   virtual char *GetStringSelection(void);
  212.   virtual Bool SetStringSelection(char *s);
  213.   virtual char *String(int n);
  214.   void SetSize(int x, int y, int width, int height);
  215.   void GetSize(int *x, int *y);
  216.   void GetPosition(int *x, int *y);
  217.   char *GetLabel(void);
  218.   void SetLabel(char *label);
  219. #ifdef wx_msw
  220.   Bool Command(UINT param);
  221. #endif
  222. };
  223.  
  224. // List box item
  225. class wxListBox: public wxItem
  226. {
  227.   int no_items;
  228.   int selected;
  229.   int *selections;
  230. #ifdef wx_motif
  231.   wxList clientDataList; // List mapping positions->client data
  232. #endif
  233. #ifdef wx_msw
  234.   HWND static_label;
  235. #endif
  236.  public:
  237.   int multiple;
  238.  
  239.   wxListBox(wxPanel *panel, wxFunction func, char *Title, Bool Multiple = FALSE,
  240.              int x = -1, int y = -1, int width = -1, int height = -1,
  241.              int N = 0, char **Choices = NULL);
  242.   ~wxListBox(void);
  243. #ifdef wx_msw
  244.   virtual BOOL Command(UINT param);
  245. #endif
  246.   virtual void Append(char *Item);
  247.   virtual void Append(char *Item, char *Client_data);
  248.   virtual void Set(int N, char *Choices[]);
  249.   int FindString(char *s);
  250.   virtual void Clear(void);
  251.   virtual void SetSelection(int N);
  252.   // Get client data
  253.   virtual char *GetClientData(int N);
  254.  
  255.   virtual void Deselect(int N);
  256.  
  257.   // For single choice list item only
  258.   virtual int GetSelection(void);
  259.   virtual char *GetStringSelection(void);
  260.   virtual Bool SetStringSelection(char *s);
  261.  
  262.   virtual int Number(void);
  263.   virtual void Delete(int N);
  264.  
  265.   // For single or multiple choice list item
  266.   virtual int GetSelections(int **list_selections);
  267.   virtual char *String(int N);
  268.   void SetSize(int x, int y, int width, int height);
  269.   void GetSize(int *x, int *y);
  270.   void GetPosition(int *x, int *y);
  271.   char *GetLabel(void);
  272.   void SetLabel(char *label);
  273. };
  274.  
  275.  
  276. // Message item
  277. class wxMessage: public wxItem
  278. {
  279.  public:
  280.   wxMessage(wxPanel *panel, char *message, int x = -1, int y = -1);
  281.   ~wxMessage(void);
  282.   void SetSize(int x, int y, int width, int height);
  283. };
  284.  
  285. // Single-line text item
  286. class wxText: public wxItem
  287. {
  288.  public:
  289. #ifdef wx_msw
  290.   HWND static_label;
  291. #endif
  292.   wxText(void);
  293.   wxText(wxPanel *panel, wxFunction func, char *label, char *value = "",
  294.          int x = -1, int y = -1, int width = -1, int height = -1);
  295.   ~wxText(void);
  296.   virtual char *GetValue(void);
  297.   virtual char *GetLabel(void);
  298.   virtual void SetValue(char *value);
  299.   virtual void SetLabel(char *label);
  300.   void GetSize(int *x, int *y);
  301.   void SetSize(int x, int y, int width, int height);
  302.   void GetPosition(int *x, int *y);
  303.   void SetFocus(void);
  304. #ifdef wx_msw
  305.   virtual BOOL Command(UINT param);
  306. #endif
  307. };
  308.  
  309. // Multi-line text item
  310. class wxMultiText: public wxText
  311. {
  312.  public:
  313.   wxMultiText(wxPanel *panel, wxFunction func, char *label, char *value = "",
  314.          int x = -1, int y = -1, int width = -1, int height = 50);
  315.   char *GetValue(void);
  316.   void GetValue(char *buffer, int maxLen);
  317.   void SetSize(int x, int y, int width, int height);
  318. };
  319.  
  320. // Slider
  321. class wxSlider: public wxItem
  322. {
  323.  public:
  324. #ifdef wx_msw
  325.   HWND static_label;
  326.   HWND static_min;
  327.   HWND static_max;
  328.   HWND edit_value;
  329.  
  330.   int s_min;
  331.   int s_max;
  332.   int page_size;
  333.  
  334. #endif
  335.   wxSlider(wxPanel *panel, wxFunction func, char *label, int value,
  336.            int min_value, int max_value, int width, int x = -1, int y = -1);
  337.   ~wxSlider(void);
  338.   virtual int GetValue(void);
  339.   virtual char *GetLabel(void);
  340.   virtual void SetValue(int);
  341.   virtual void SetLabel(char *label);
  342.   void GetSize(int *x, int *y);
  343.   void SetSize(int x, int y, int width, int height);
  344.   void GetPosition(int *x, int *y);
  345. };
  346.  
  347. #ifdef wx_x
  348. // For stripping out Windows-specific accelerator codes
  349. // from menu items
  350. void wxStripMenuCodes(char *in, char *out);
  351.  
  352. // Find the letter corresponding to the mnemonic, for Motif
  353. char wxFindMnemonic(char *s);
  354. #endif
  355.  
  356. #endif // wx_itemh
  357.