⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 flve_combo.cxx

📁 PIXIL is a small footprint operating environment, complete with PDA PIM applications, a browser and
💻 CXX
📖 第 1 页 / 共 2 页
字号:
    int X, Y, W, H, bx;    // modified to allow a zero length string string in input widget    //  if input widget is modifiable    if (list_only() == true)	if (*(input->value()) == 0)	    input->value(item[item.index()].item());    if ((damage() & FL_DAMAGE_ALL) != 0)	draw_box();    X = x() + (Fl::box_dx(box()));    Y = y() + (Fl::box_dy(box()));    W = w() - (Fl::box_dw(box()));    H = h() - (Fl::box_dh(box()));    bx = X + W - BUTTON_WIDTH;#if FL_MAJOR_VERSION == 2    FL_UP_BOX->draw(bx + 1, Y, BUTTON_WIDTH, H,		    (Fl_Color) (FL_GRAY_RAMP + 17));#else    draw_box(FL_UP_BOX, bx + 1, Y, BUTTON_WIDTH, H,	     (Fl_Color) (FL_GRAY_RAMP + 17));#endif    fl_draw_symbol("@#2>", bx + 3, Y, BUTTON_WIDTH - 5, H, FL_BLACK);    fl_color((Fl_Color) (FL_GRAY_RAMP + 17));    fl_yxline(bx, Y, Y + H);    input->draw();}voidFlve_Combo::open_list(){    int W, H, r;    Fl_Window *win;    Flvw_Drop *lst;    fl_font(text_font(), text_size());    fl_measure("X", W, H);    r = item.count();    if (vlist_title)	r++;    if (r > display_rows())	r = display_rows();    list = lst = new Flvw_Drop(w(), H * r + 4 + (vlist_title ? 4 : 0));    list->box(FL_DOWN_BOX);    list->end();    // This is a horrible hack .. This should have a parent of the root to allow    // it to pop up over the application window, instead of being contained    // within it. However, the screentop and window managers pick up this window    // and do Bad Things (TM) with it. Therefore, I've made the temporary change     // to make this a child of the application, and thus, it may look weird.    // This need's fixed.    // -Anonymous (anon@fixthisyourself.net)    list->parent(parent());    //      list->parent(NULL);    lst->drop_list->rows(item.count());    if (vlist_title)	lst->drop_list->label(vlist_title);    list->clear_border();    list->set_modal();    lst->drop_list->combo = this;    lst->combo = this;    // highlight the present contents of the input widget    // if input contains a value and it can be found in the list    // added by Dave Freese (dfreese@intrepid.net)    if (item.findi(input->value()) > -1)	lst->drop_list->row(item.index());    else	lst->drop_list->row(0);    lst->drop_list->last_row = lst->drop_list->row();    // end hightlight code    win = window();    int nx = win->x();    int ny = win->y();    while (win && win->parent()) {	win = win->window();	nx += win->x();	ny += win->y();    }    if (win)	list->position(nx + x(), ny + y() + h() - 3);    Fl::grab(list);    list->show();    while (list->shown())	Fl::wait();    Fl::release();    take_focus();    // ****//  if (((Flvw_Drop *)list)->key)    value(item[item.index()].item());    do_callback();    if (win && ((Flvw_Drop *) list)->key)	Fl::handle(FL_KEYBOARD, win);    delete list;    list = 0;}const char *Flve_Combo::value(){    return input->value();}voidFlve_Combo::value(const char *v){    input->value(v);    input->set_changed();    input->mark(256);//      input->position(0, input->size() );}voidFlve_Combo::display_rows(int v){    vdisplay_rows = v;}//      =================================================================//      Flv_Combo_Item//      =================================================================Flv_Combo_Item::Flv_Combo_Item(){    vitem = 0;    vvalue = 0;}Flv_Combo_Item::~Flv_Combo_Item(){    if (vitem)	delete vitem;}const char *Flv_Combo_Item::item(void){    return (vitem ? vitem : "");}voidFlv_Combo_Item::item(const char *v){    if (vitem)	delete vitem;    vitem = 0;    if (v) {	vitem = new char[strlen(v) + 1];	strcpy(vitem, v);    }}longFlv_Combo_Item::value(void){    return vvalue;}voidFlv_Combo_Item::value(long v){    vvalue = v;}//      =================================================================//      Flv_Combo_Items//      =================================================================Flv_Combo_Items::Flv_Combo_Items(){    list = 0;    vcount = 0;    vallocated = 0;    vcurrent = 0;    nodups = true;}Flv_Combo_Items::~Flv_Combo_Items(){    clear();}voidFlv_Combo_Items::add(const char *item, long v){    Flv_Combo_Item *i;    if (vcount == vallocated)	make_room_for(vallocated + 10);    if (vcount == vallocated)	return;    if (strlen(item) == 0)	return;    if (nodups)	if (find(item) != -1)	    return;    i = new Flv_Combo_Item();    i->item(item);    i->value(v);    list[vcount++] = i;}voidFlv_Combo_Items::insert(int index, const char *item, long v){    int t;    Flv_Combo_Item *i;    if (vcount == vallocated)	make_room_for(vallocated + 10);    if (vcount == vallocated)	return;    if (strlen(item) == 0)	return;    if (nodups)	if (find(item) != -1)	    return;    i = new Flv_Combo_Item();    i->item(item);    i->value(v);    if (index < 0)	index = 0;    if (index > vcount)	index = vcount;    for (t = vcount; t > index; t--)	list[t] = list[t - 1];    list[index] = i;    vcount++;}voidFlv_Combo_Items::remove(int index){    int t;    if (index < 0 || index >= vcount)	return;    if (list[index])	delete list[index];    for (t = index; t < vcount - 1; t++)	list[t] = list[t + 1];    list[t] = 0;    vcount--;    if (vcurrent >= vcount && vcurrent)	vcurrent--;}voidFlv_Combo_Items::change(int i, const char *item, long v){    if (i < 0 || i > vcount)	return;    list[i]->item(item);    list[i]->value(v);}voidFlv_Combo_Items::change(int i, const char *item){    if (i < 0 || i > vcount)	return;    list[i]->item(item);}voidFlv_Combo_Items::change(int i, long v){    if (i < 0 || i > vcount)	return;    list[i]->value(v);}#define C(x) ((Flv_Combo_Item *)(x))static intcmp(const void *a, const void *b){    Flv_Combo_Item *ai = *((Flv_Combo_Item **) (a)),	*bi = *((Flv_Combo_Item **) (b));    const char *a_item = ai->item(), *b_item = bi->item();    long a_value = ai->value(), b_value = bi->value();    int status = STRCASECMP(a_item, b_item);    if (status)	return status;    return (a_value - b_value);}voidFlv_Combo_Items::sort(void)	//      Sort list{    if (list && vcount > 1)	qsort(list, vcount, sizeof(Flv_Combo_Item *), cmp);}voidFlv_Combo_Items::clear(void)	//      Clear list{    int t;    for (t = 0; t < vcount; t++)	if (list[t])	    delete list[t];    if (list)	delete[]list;    list = 0;    vallocated = 0;    vcount = 0;    vcurrent = 0;}voidFlv_Combo_Items::index(int i)	//      Set current index{    if (i < 0 || i >= vcount)	return;    vcurrent = i;}intFlv_Combo_Items::findi(const char *v)	//      Find text return index (-1 not found){    int t;    // added for case where v is zero length    if (*v == 0)	return -1;    for (t = 0; t < vcount; t++) {	if (STRNCASECMP(list[t]->item(), v, strlen(v)) == 0) {	    vcurrent = t;	    return t;	}    }    return -1;}intFlv_Combo_Items::find(const char *v)	//      Find text return index (-1 not found){    int t;    // added for case where v is zero length    if (*v == 0)	return -1;    for (t = 0; t < vcount; t++) {	if (STRCASECMP(list[t]->item(), v) == 0) {	    vcurrent = t;	    return t;	}    }    return -1;}intFlv_Combo_Items::find(long v)	//      Find value return index (-1 not found){    int t;    for (t = 0; t < vcount; t++) {	if (list[t]->value() == v) {	    vcurrent = t;	    return t;	}    }    return -1;}Flv_Combo_Item *Flv_Combo_Items::current(void){    if (list)	return list[vcurrent];    return NULL;}Flv_Combo_Item & Flv_Combo_Items::operator[](int index) {    static Flv_Combo_Item	x;    if (index < 0 || index >= vcount)	return x;    return *(list[index]);}voidFlv_Combo_Items::make_room_for(int n){    if (n >= vallocated) {	Flv_Combo_Item **a = new Flv_Combo_Item *[n];	if (!a)	    return;	//      Wasted CPU cycles, but list is pretty	memset(a, 0, sizeof(Flv_Style *) * (vallocated + ADDSIZE));	if (vcount)	    memcpy(a, list, sizeof(Flv_Combo_Item *) * vcount);	vallocated += ADDSIZE;	if (list)	    delete[]list;	list = a;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -