diff options
author | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2006-11-26 17:22:42 +0100 |
---|---|---|
committer | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2006-11-26 17:22:42 +0100 |
commit | 2aaf6d31566df56d30ee492418562e04732c8059 (patch) | |
tree | 3062dd55798ec76edb095c4f83abecd27c7da328 /src/Fl_Search_Chooser.cxx | |
parent | ceec61fe9614b7fb631781c3f9d21894e084077b (diff) | |
parent | a10646b1c87e6abc1651ae7160ddd2c7fd1753bc (diff) |
merge with mainline
Diffstat (limited to 'src/Fl_Search_Chooser.cxx')
-rw-r--r-- | src/Fl_Search_Chooser.cxx | 144 |
1 files changed, 61 insertions, 83 deletions
diff --git a/src/Fl_Search_Chooser.cxx b/src/Fl_Search_Chooser.cxx index 62aa7d1..d4f93b2 100644 --- a/src/Fl_Search_Chooser.cxx +++ b/src/Fl_Search_Chooser.cxx @@ -1,24 +1,8 @@ // -// Search Chooser widget for the Fast Light Tool Kit (FLTK). -// -// Copyright by Johannes Hofmann -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library General Public -// License as published by the Free Software Foundation; either -// version 2 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Library General Public License for more details. -// -// You should have received a copy of the GNU Library General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 -// USA. -// +// Copyright 2006 Johannes Hofmann <Johannes.Hofmann@gmx.de> // +// This software may be used and distributed according to the terms +// of the GNU General Public License, incorporated herein by reference. #include <stdio.h> #include <string.h> @@ -29,103 +13,97 @@ int Fl_Search_Browser::find_prefix(const char *p) { - int i = find_prefix(p, 1, size()); - if (i == -1) { - return 1; - } else { - deselect(); - middleline(i); - select(i); - return 0; - } + int i = find_prefix(p, 1, size()); + if (i == -1) { + return 1; + } else { + deselect(); + middleline(i); + select(i); + return 0; + } }; int Fl_Search_Browser::find_prefix(const char *p, int s, int e) { - if (s < 0 || e > size() || s > e) { - fprintf(stderr, "Invalid search range %d %d\n", s, e); - return 1; - } else if (e - s <= 1) { - if (strncasecmp(p, text(s), strlen(p)) == 0) { - return s; - } else if (strncasecmp(p, text(e), strlen(p)) == 0){ - return e; - } else { - return -1; - } - } else { - int med = s + (e - s) / 2; - if (strncasecmp(p, text(med), strlen(p)) > 0) { - return find_prefix(p, med, e); - } else { - return find_prefix(p, s, med); - } - } + if (s < 0 || e > size() || s > e) { + fprintf(stderr, "Invalid search range %d %d\n", s, e); + return 1; + } else if (e - s <= 1) { + if (strncasecmp(p, text(s), strlen(p)) == 0) { + return s; + } else if (strncasecmp(p, text(e), strlen(p)) == 0){ + return e; + } else { + return -1; + } + } else { + int med = s + (e - s) / 2; + if (strncasecmp(p, text(med), strlen(p)) > 0) { + return find_prefix(p, med, e); + } else { + return find_prefix(p, s, med); + } + } } static void input_cb(Fl_Input* in, void*c) { - Fl_Search_Browser *sb = ((Fl_Search_Chooser *) c)->sb; - sb->find_prefix(in->value()); + Fl_Search_Browser *sb = ((Fl_Search_Chooser *) c)->sb; + sb->find_prefix(in->value()); } static void ok_cb(Fl_Input* in, void*c) { - Fl_Search_Chooser *sc = (Fl_Search_Chooser *) c; - sc->w->hide(); + Fl_Search_Chooser *sc = (Fl_Search_Chooser *) c; + sc->w->hide(); } static void cancel_cb(Fl_Input* in, void*c) { - Fl_Search_Chooser *sc = (Fl_Search_Chooser *) c; - sc->sb->deselect(); - sc->w->hide(); + Fl_Search_Chooser *sc = (Fl_Search_Chooser *) c; + sc->sb->deselect(); + sc->w->hide(); } Fl_Search_Chooser::Fl_Search_Chooser(const char *title) { - w = new Fl_Window(320, 320, title?title:"Choose"); - Fl_Group *g = new Fl_Group(10, 10, w->w() - 10, w->h() - 10); - sb = new Fl_Search_Browser(g->x(), g->y(), g->w() , g->h() - 100, NULL); - sb->type(FL_HOLD_BROWSER); - Fl_Input *in = new Fl_Input(g->x()+50, g->h()-80, g->w()-80, 20, "Search"); - in->callback((Fl_Callback*) input_cb, this); - in->when(FL_WHEN_CHANGED); - Fl_Button *cancel_b = new Fl_Button(g->w()-200, g->h()-30, 80, 25, "Cancel"); - cancel_b->callback((Fl_Callback*) cancel_cb, this); - Fl_Button *ok_b = new Fl_Button(g->w()-100, g->h()-30, 80, 25, "Ok"); - ok_b->callback((Fl_Callback*) ok_cb, this); - Fl::focus(in); - g->end(); - w->end(); -} - -Fl_Search_Chooser::~Fl_Search_Chooser() { - delete sb; - delete w; + w = new Fl_Window(320, 320, title?title:"Choose"); + Fl_Group *g = new Fl_Group(10, 10, w->w() - 10, w->h() - 10); + sb = new Fl_Search_Browser(g->x(), g->y(), g->w() , g->h() - 100, NULL); + sb->type(FL_HOLD_BROWSER); + Fl_Input *in = new Fl_Input(g->x()+50, g->h()-80, g->w()-80, 20, "Search"); + in->callback((Fl_Callback*) input_cb, this); + in->when(FL_WHEN_CHANGED); + Fl_Button *cancel_b = new Fl_Button(g->w()-200, g->h()-30, 80, 25, "Cancel"); + cancel_b->callback((Fl_Callback*) cancel_cb, this); + Fl_Button *ok_b = new Fl_Button(g->w()-100, g->h()-30, 80, 25, "Ok"); + ok_b->callback((Fl_Callback*) ok_cb, this); + Fl::focus(in); + g->end(); + w->end(); } void Fl_Search_Chooser::add(const char *t, void *d) { - sb->add(t, d); + sb->add(t, d); } void * Fl_Search_Chooser::data() { - int v = sb->value(); - if (v) { - return sb->data(v); - } else { - return NULL; - } + int v = sb->value(); + if (v) { + return sb->data(v); + } else { + return NULL; + } } void Fl_Search_Chooser::show() { - w->show(); + w->show(); } int Fl_Search_Chooser::shown() { - return w->shown(); + return w->shown(); } - |