[773] | 1 | // |
---|
| 2 | // |
---|
| 3 | // |
---|
| 4 | // single line input field with predefined choices via popup menu |
---|
| 5 | // |
---|
| 6 | // Copyright 2002 by Bill Spitzak and others. |
---|
| 7 | // |
---|
| 8 | // This library is free software; you can redistribute it and/or |
---|
| 9 | // modify it under the terms of the GNU Library General Public |
---|
| 10 | // License as published by the Free Software Foundation; either |
---|
| 11 | // version 2 of the License, or (at your option) any later version. |
---|
| 12 | // |
---|
| 13 | // This library is distributed in the hope that it will be useful, |
---|
| 14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 16 | // Library General Public License for more details. |
---|
| 17 | // |
---|
| 18 | // You should have received a copy of the GNU Library General Public |
---|
| 19 | // License along with this library; if not, write to the Free Software |
---|
| 20 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
---|
| 21 | // USA. |
---|
| 22 | // |
---|
| 23 | // Please report all bugs and problems to "fltk-bugs@fltk.org". |
---|
| 24 | // |
---|
| 25 | |
---|
| 26 | #ifndef fltk_ComboBox_h |
---|
| 27 | #define fltk_ComboBox_h |
---|
| 28 | |
---|
| 29 | #include "Choice.h" |
---|
| 30 | #include "Input.h" |
---|
| 31 | |
---|
| 32 | namespace fltk { |
---|
| 33 | |
---|
| 34 | class FL_API ComboBox : public Choice { |
---|
| 35 | public: |
---|
| 36 | ComboBox(int,int,int,int,const char * = 0); |
---|
| 37 | ~ComboBox(); |
---|
| 38 | static NamedStyle* default_style; |
---|
| 39 | |
---|
| 40 | void draw(); |
---|
| 41 | void layout(); |
---|
| 42 | int handle(int); |
---|
| 43 | int popup(const Rectangle&,const char* title=0,bool menubar=false); |
---|
| 44 | |
---|
| 45 | int choice(int v); |
---|
| 46 | int choice() const; |
---|
| 47 | int find_choice() const; |
---|
| 48 | bool value(const char *txt) |
---|
| 49 | { return text_changed_(input_->value(txt)); } |
---|
| 50 | bool value(const char *txt, int n) |
---|
| 51 | { return text_changed_(input_->value(txt, n)); } |
---|
| 52 | bool static_value(const char *txt) |
---|
| 53 | { return text_changed_(input_->static_value(txt)); } |
---|
| 54 | bool static_value(const char *txt, int n) |
---|
| 55 | { return text_changed_(input_->static_value(txt, n)); } |
---|
| 56 | const char* value() const { return input_->value();} |
---|
| 57 | char at(int i) const { return input_->at(i); } |
---|
| 58 | |
---|
| 59 | int size(bool ofText) const |
---|
| 60 | { return ofText ? input_->size() : Choice::size(); } |
---|
| 61 | |
---|
| 62 | int position() const { return input_->position();} |
---|
| 63 | int mark() const { return input_->mark();} |
---|
| 64 | void position(int p, int m) |
---|
| 65 | { input_->position(p, m); text_changed_(); } |
---|
| 66 | void position(int p) { position(p, p); } |
---|
| 67 | void up_down_position(int p, bool m) |
---|
| 68 | { input_->up_down_position(p, m); text_changed_(); } |
---|
| 69 | void mark(int m) { position(position(), m);} |
---|
| 70 | |
---|
| 71 | virtual bool replace(int a, int b, const char *c, int d) |
---|
| 72 | { return text_changed_(input_->replace(a, b, c, d)); } |
---|
| 73 | bool cut() {return replace(position(), mark(), 0, 0);} |
---|
| 74 | bool cut(int n) {return replace(position(), position()+n, 0, 0);} |
---|
| 75 | bool cut(int a, int b) {return replace(a, b, 0, 0);} |
---|
| 76 | bool insert(const char* t, int l=0) |
---|
| 77 | { return replace(input_->position(), input_->mark(), t, l); } |
---|
| 78 | bool replace(int a, int b, char c) { return replace(a,b,&c,1); } |
---|
| 79 | bool copy(bool clipboard = true) { return input_->copy(clipboard); } |
---|
| 80 | bool undo() { return text_changed_(input_->undo()); } |
---|
| 81 | |
---|
| 82 | int word_start(int i) const { return input_->word_start(i); } |
---|
| 83 | int word_end(int i) const { return input_->word_end(i); } |
---|
| 84 | int line_start(int i) const { return input_->line_start(i); } |
---|
| 85 | int line_end(int i) const { return input_->line_end(i); } |
---|
| 86 | int mouse_position(const Rectangle& r) const |
---|
| 87 | { return input_->mouse_position(r); } |
---|
| 88 | int xscroll() const { return input_->xscroll();} |
---|
| 89 | int yscroll() const { return input_->yscroll();} |
---|
| 90 | |
---|
| 91 | uchar when() const { return input_->when(); } |
---|
| 92 | void when(uchar w) { input_->when(w); } |
---|
| 93 | |
---|
| 94 | protected: |
---|
| 95 | bool text_changed_(bool ret=true); |
---|
| 96 | |
---|
| 97 | private: |
---|
| 98 | class ComboInput : public Input { |
---|
| 99 | public: |
---|
| 100 | ComboInput(int,int,int,int,ComboBox*); |
---|
| 101 | int handle(int); |
---|
| 102 | private: |
---|
| 103 | ComboBox *combo_; |
---|
| 104 | }; |
---|
| 105 | ComboInput *input_; |
---|
| 106 | #ifdef _WIN32 |
---|
| 107 | public: |
---|
| 108 | #endif |
---|
| 109 | static void input_callback_(Widget*,void*); |
---|
| 110 | }; |
---|
| 111 | |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | #endif |
---|
| 115 | |
---|
| 116 | // |
---|
| 117 | // |
---|
| 118 | // |
---|