| 1 |
// ---------------------------------------------------------------------------- |
| 2 |
// Copyright (C) 2014 |
| 3 |
// David Freese, W1HKJ |
| 4 |
// |
| 5 |
// |
| 6 |
// This is free software; you can redistribute it and/or modify |
| 7 |
// it under the terms of the GNU General Public License as published by |
| 8 |
// the Free Software Foundation; either version 3 of the License, or |
| 9 |
// (at your option) any later version. |
| 10 |
// |
| 11 |
// This software is distributed in the hope that it will be useful, |
| 12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
// GNU General Public License for more details. |
| 15 |
// |
| 16 |
// You should have received a copy of the GNU General Public License |
| 17 |
// along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
// ---------------------------------------------------------------------------- |
| 19 |
|
| 20 |
#ifndef _FL_COMBOBOX_H |
| 21 |
#define _FL_COMBOBOX_H |
| 22 |
|
| 23 |
#include <string> |
| 24 |
|
| 25 |
#include <FL/Fl_Window.H> |
| 26 |
#include <FL/Fl_Group.H> |
| 27 |
#include <FL/Fl_Button.H> |
| 28 |
#include <FL/Fl_Select_Browser.H> |
| 29 |
#include <FL/Fl_Input.H> |
| 30 |
#include <FL/Fl_Return_Button.H> |
| 31 |
#include <FL/Fl_Box.H> |
| 32 |
|
| 33 |
#define FL_COMBO_UNIQUE 1 |
| 34 |
#define FL_COMBO_UNIQUE_NOCASE 2 |
| 35 |
#define FL_COMBO_LIST_INCR 100 |
| 36 |
|
| 37 |
class Fl_ComboBox; |
| 38 |
|
| 39 |
enum {COMBOBOX, LISTBOX}; |
| 40 |
|
| 41 |
struct datambr { |
| 42 |
char *s; |
| 43 |
void *d; |
| 44 |
}; |
| 45 |
|
| 46 |
class Fl_PopBrowser : public Fl_Window { |
| 47 |
|
| 48 |
friend void popbrwsr_cb(Fl_Widget *, long); |
| 49 |
|
| 50 |
Fl_Select_Browser *popbrwsr; |
| 51 |
int hRow; |
| 52 |
int wRow; |
| 53 |
std::string keystrokes; |
| 54 |
|
| 55 |
public: |
| 56 |
Fl_PopBrowser (int x, int y, int w, int h, const char *label); |
| 57 |
~Fl_PopBrowser (); |
| 58 |
void popshow (int, int); |
| 59 |
void pophide (); |
| 60 |
void popbrwsr_cb_i (Fl_Widget *, long); |
| 61 |
|
| 62 |
void add (char *s, void *d = 0); |
| 63 |
void clear (); |
| 64 |
void sort (); |
| 65 |
int handle (int); |
| 66 |
void clear_kbd() { keystrokes.clear(); } |
| 67 |
|
| 68 |
Fl_ComboBox *parentCB; |
| 69 |
Fl_Widget *parentWindow; |
| 70 |
|
| 71 |
}; |
| 72 |
|
| 73 |
class Fl_ComboBox : public Fl_Group { |
| 74 |
friend int DataCompare (const void *, const void *); |
| 75 |
friend class Fl_PopBrowser; |
| 76 |
|
| 77 |
Fl_Button *btn; |
| 78 |
Fl_Box *valbox; |
| 79 |
Fl_Input *val; |
| 80 |
Fl_PopBrowser *Brwsr; |
| 81 |
datambr **datalist; |
| 82 |
int listsize; |
| 83 |
int maxsize; |
| 84 |
int listtype; |
| 85 |
int numrows_; |
| 86 |
int type_; |
| 87 |
|
| 88 |
int width; |
| 89 |
int height; |
| 90 |
void *retdata; |
| 91 |
int idx; |
| 92 |
Fl_Color _color; |
| 93 |
void insert(const char *, void *); |
| 94 |
|
| 95 |
public: |
| 96 |
|
| 97 |
Fl_ComboBox (int x, int y, int w, int h, const char *lbl = 0, |
| 98 |
int wtype = COMBOBOX); |
| 99 |
~Fl_ComboBox(); |
| 100 |
|
| 101 |
const char *value (); |
| 102 |
void value (const char *); |
| 103 |
void put_value( const char *); |
| 104 |
void fl_popbrwsr(Fl_Widget *); |
| 105 |
|
| 106 |
void type (int = 0); |
| 107 |
void add (const char *s, void *d = 0); |
| 108 |
void clear (); |
| 109 |
void sort (); |
| 110 |
int index (); |
| 111 |
void index (int i); |
| 112 |
void *data (); |
| 113 |
void textfont (int); |
| 114 |
void textsize (uchar); |
| 115 |
void textcolor (Fl_Color c); |
| 116 |
void color (Fl_Color c); |
| 117 |
void readonly(bool yes = true); |
| 118 |
int numrows() { return numrows_; } |
| 119 |
void numrows(int n) { numrows_ = n; } |
| 120 |
int lsize() { return listsize; } |
| 121 |
void set_focus() { Fl::focus(btn); }; |
| 122 |
void labelfont(Fl_Font fnt) { Fl_Group::labelfont(fnt); } |
| 123 |
Fl_Font labelfont() { return Fl_Group::labelfont(); } |
| 124 |
void labelsize(Fl_Fontsize n) { Fl_Group::labelsize(n); } |
| 125 |
Fl_Fontsize labelsize() { return Fl_Group::labelsize(); } |
| 126 |
|
| 127 |
int handle(int); |
| 128 |
|
| 129 |
// Custom resize behavior -- input stretches, button doesn't |
| 130 |
inline int val_x() { return x(); } |
| 131 |
inline int val_y() { return y(); } |
| 132 |
inline int val_w() { return w() - h(); } |
| 133 |
inline int val_h() { return h(); } |
| 134 |
|
| 135 |
inline int btn_x() { return x() + w() - h(); } |
| 136 |
inline int btn_y() { return y(); } |
| 137 |
inline int btn_w() { return h(); } |
| 138 |
inline int btn_h() { return h(); } |
| 139 |
|
| 140 |
void resize(int X, int Y, int W, int H) { |
| 141 |
Fl_Group::resize(X,Y,W,H); |
| 142 |
if (type_ == LISTBOX) |
| 143 |
valbox->resize(val_x(), val_y(), val_w(), val_h()); |
| 144 |
else |
| 145 |
val->resize(val_x(), val_y(), val_w(), val_h()); |
| 146 |
btn->resize(btn_x(), btn_y(), btn_w(), btn_h()); |
| 147 |
} |
| 148 |
|
| 149 |
}; |
| 150 |
|
| 151 |
class Fl_ListBox : public Fl_ComboBox { |
| 152 |
public: |
| 153 |
Fl_ListBox (int x, int y, int w, int h, const char *lbl = 0) : |
| 154 |
Fl_ComboBox(x,y,w,h,lbl,LISTBOX) {}; |
| 155 |
~Fl_ListBox() {}; |
| 156 |
}; |
| 157 |
|
| 158 |
#endif |