Flve_Combo.H 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. // ======================================================================
  2. // File: Flve_Combo.h - Flve_Combo implementation
  3. // Library: flvw - FLTK Widget
  4. // Version: 0.1.0
  5. // Started: 01/12/2000
  6. //
  7. // Copyright (C) 1999 Laurence Charlton
  8. //
  9. // Description:
  10. // Flve_Combo implements combo box functionality
  11. // Included are select from list, text with list, incremental search
  12. //
  13. // This library is free software; you can redistribute it and/or
  14. // modify it under the terms of the GNU Library General Public
  15. // License as published by the Free Software Foundation; either
  16. // version 2 of the License, or (at your option) any later version.
  17. //
  18. // This library is distributed in the hope that it will be useful,
  19. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  21. // Library General Public License for more details.
  22. //
  23. // You should have received a copy of the GNU Library General Public
  24. // License along with this library; if not, write to the Free Software
  25. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  26. // USA.
  27. // ======================================================================
  28. #ifndef FLVE_COMBO_H
  29. #define FLVE_COMBO_H
  30. #include <FL/Fl_Widget.H>
  31. #include <FL/Fl_Window.H>
  32. #include <FL/Fl_Input.H>
  33. #include <FL/Flv_List.H>
  34. #define flv_ctrl(x) ((x>='a' && x<='z'?x-('a'-'A'):x)|0x100)
  35. #define flv_alt(x) ((x>='a' && x<='z'?x-('a'-'A'):x)|0x200)
  36. #define flv_shift(x) ((x>='a' && x<='z'?x-('a'-'A'):x)|0x400)
  37. class FL_EXPORT Flv_Combo_Item
  38. {
  39. public:
  40. Flv_Combo_Item();
  41. virtual ~Flv_Combo_Item();
  42. const char *item(void);
  43. void item(const char *v);
  44. long value(void);
  45. void value(long v);
  46. protected:
  47. char *vitem;
  48. long vvalue;
  49. };
  50. class Flv_Combo_Items
  51. {
  52. public:
  53. Flv_Combo_Items();
  54. ~Flv_Combo_Items();
  55. int count(void) // # of styles
  56. {
  57. return vcount;
  58. }
  59. void add( const char *item, long v=0L );
  60. void insert( int index, const char *item, long v=0L );
  61. void remove( int index );
  62. void change( int i, const char *item, long v );
  63. void change( int i, const char *item );
  64. void change( int i, long v );
  65. void sort(void); // Sort list
  66. void clear(void); // Clear list
  67. int index(void) // Get current index
  68. {
  69. return vcurrent;
  70. };
  71. void index(int i); // Set current index
  72. int findi( const char *v ); // Find starting with v (-1 not found)
  73. int find( const char *v ); // Find text return index (-1 not found)
  74. int find( long v ); // Find value return index (-1 not found)
  75. Flv_Combo_Item *current(void);
  76. Flv_Combo_Item &operator[](int index);
  77. private:
  78. void make_room_for( int n );
  79. Flv_Combo_Item **list; // Array of item pointers
  80. int vcount; // # of item pointers defined
  81. int vallocated; // # of item pointers allocated
  82. int vcurrent; // Current item index
  83. };
  84. class Flve_Combo : public Fl_Group
  85. {
  86. public:
  87. Flve_Combo(int x, int y, int w, int h, const char *l );
  88. ~Flve_Combo();
  89. virtual void resize(int x, int y, int w, int h);
  90. void list_title(const char *v);
  91. void open_list(void);
  92. const char *value();
  93. void value(const char *v);
  94. int display_rows()
  95. {
  96. return vdisplay_rows;
  97. };
  98. void display_rows(int v);
  99. int drop_key(void)
  100. {
  101. return vdrop_key;
  102. }
  103. int drop_key( int v )
  104. {
  105. return vdrop_key = v;
  106. }
  107. bool incremental_search(void)
  108. {
  109. return vincremental_search;
  110. }
  111. bool incremental_search(bool v)
  112. {
  113. return (vincremental_search=v);
  114. }
  115. bool list_only(void)
  116. {
  117. return vlist_only;
  118. }
  119. bool list_only(bool v);
  120. Flv_Combo_Items item;
  121. Fl_Window *list;
  122. DECLARE_CLASS_CHEAP_RTTI_2(Flve_Combo, Fl_Group)
  123. protected:
  124. int vdrop_key;
  125. char *vlist_title;
  126. int vdisplay_rows;
  127. int handle(int event);
  128. void draw(void);
  129. Fl_Input *input;
  130. bool vincremental_search;
  131. bool vlist_only;
  132. };
  133. #endif