2002-03-11 17:00:41 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file combox.C
|
|
|
|
|
* Copyright 1996-2002 The LyX Team.
|
|
|
|
|
* Copyright 1996Alejandro Aguilar Sierra
|
|
|
|
|
* See the file COPYING.
|
|
|
|
|
*
|
|
|
|
|
* \author Alejandro Aguilar Sierra
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* A combination of two objects (a button and a browser) is encapsulated to
|
2002-03-21 21:21:28 +00:00
|
|
|
|
* get a combobox-like object. All XForms functions are hidden.
|
|
|
|
|
*
|
|
|
|
|
*/
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
/* Change log:
|
2002-03-21 21:21:28 +00:00
|
|
|
|
*
|
|
|
|
|
* 2/06/1996, Alejandro Aguilar Sierra
|
1999-09-27 18:44:28 +00:00
|
|
|
|
* Created and tested.
|
2002-03-21 21:21:28 +00:00
|
|
|
|
*
|
|
|
|
|
* 4/06/1996, Alejandro Aguilar Sierra
|
1999-09-27 18:44:28 +00:00
|
|
|
|
* Added droplist mode (a button with a black down arrow at right)
|
|
|
|
|
* and support for middle and right buttons, as XForms choice object.
|
|
|
|
|
*
|
|
|
|
|
* 6/06/1996, Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
* Added a combox with an input object. and a pre and a post handle.
|
2002-03-21 21:21:28 +00:00
|
|
|
|
*
|
|
|
|
|
* 22/07/96, Alejandro Aguilar Sierra
|
1999-09-27 18:44:28 +00:00
|
|
|
|
* Assigned to the browser its own popup window. No more need of
|
|
|
|
|
* external pre and post handlers to simulate the wanted behaviour.
|
2002-03-21 21:21:28 +00:00
|
|
|
|
*
|
|
|
|
|
*/
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
|
#pragma implementation
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include "combox.h"
|
2001-05-31 02:23:46 +00:00
|
|
|
|
//#include <cstring>
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
1999-10-07 18:44:17 +00:00
|
|
|
|
#include "debug.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-03-28 02:18:55 +00:00
|
|
|
|
using std::endl;
|
|
|
|
|
|
1999-10-25 14:18:30 +00:00
|
|
|
|
// These are C wrappers around static members of Combox, used as
|
|
|
|
|
// callbacks for xforms.
|
2001-09-09 22:02:19 +00:00
|
|
|
|
extern "C" {
|
2002-03-21 21:21:28 +00:00
|
|
|
|
|
2001-09-09 22:02:19 +00:00
|
|
|
|
static
|
|
|
|
|
void C_Combox_input_cb(FL_OBJECT * ob, long data)
|
|
|
|
|
{
|
|
|
|
|
Combox::input_cb(ob, data);
|
|
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
|
2001-09-09 22:02:19 +00:00
|
|
|
|
static
|
2002-03-21 21:21:28 +00:00
|
|
|
|
void C_Combox_combo_cb(FL_OBJECT * ob, long data)
|
2001-09-09 22:02:19 +00:00
|
|
|
|
{
|
|
|
|
|
Combox::combo_cb(ob, data);
|
|
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
|
2001-09-09 22:02:19 +00:00
|
|
|
|
static
|
|
|
|
|
int C_Combox_peek_event(FL_FORM * form, void *xev)
|
|
|
|
|
{
|
|
|
|
|
return Combox::peek_event(form, xev);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
1999-10-25 14:18:30 +00:00
|
|
|
|
|
2000-10-11 21:06:43 +00:00
|
|
|
|
Combox::Combox(combox_type t)
|
2000-11-29 15:06:42 +00:00
|
|
|
|
: type(t), tabfolder1(0), tabfolder2(0)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
browser = button = 0;
|
|
|
|
|
callback = 0;
|
|
|
|
|
label = 0;
|
|
|
|
|
cb_arg = 0;
|
|
|
|
|
_pre = 0;
|
|
|
|
|
_post = 0;
|
|
|
|
|
sel = 0;
|
|
|
|
|
form = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Combox::~Combox()
|
|
|
|
|
{
|
2002-07-04 17:45:35 +00:00
|
|
|
|
// This is now handled by the XFormsView destructor (Lgb)
|
|
|
|
|
// remove();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Combox::clear()
|
|
|
|
|
{
|
2002-03-21 21:21:28 +00:00
|
|
|
|
if (browser) fl_clear_browser(browser);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
sel = 0;
|
|
|
|
|
if (type == FL_COMBOX_INPUT)
|
|
|
|
|
fl_set_input(label, "");
|
|
|
|
|
else
|
|
|
|
|
fl_set_object_label(label, "");
|
|
|
|
|
is_empty = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Combox::remove()
|
|
|
|
|
{
|
2001-06-27 14:10:35 +00:00
|
|
|
|
lyxerr[Debug::GUI] << "Button: " << button << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (button) {
|
|
|
|
|
fl_delete_object(button);
|
2002-03-21 21:21:28 +00:00
|
|
|
|
fl_free_object(button);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
|
lyxerr[Debug::GUI] << "Label: " << label << endl;
|
2001-02-26 15:17:19 +00:00
|
|
|
|
if (label && label != button) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
fl_delete_object(label);
|
2002-03-21 21:21:28 +00:00
|
|
|
|
fl_free_object(label);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
|
lyxerr[Debug::GUI] << "Form: " << form << endl;
|
|
|
|
|
lyxerr[Debug::GUI] << "Browser: " << browser << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (form && browser) {
|
|
|
|
|
fl_delete_object(browser);
|
|
|
|
|
fl_free_object(browser);
|
|
|
|
|
fl_free_form(form);
|
|
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
button = 0;
|
|
|
|
|
browser = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
label = 0;
|
|
|
|
|
form = 0;
|
|
|
|
|
sel = 0;
|
|
|
|
|
is_empty = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
|
void Combox::addline(string const & text)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
if (!browser) return;
|
2000-09-14 17:53:12 +00:00
|
|
|
|
fl_add_browser_line(browser, text.c_str());
|
2002-03-21 21:21:28 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// By default the first item is selected
|
|
|
|
|
if (!sel) {
|
|
|
|
|
sel = 1;
|
|
|
|
|
if (type == FL_COMBOX_INPUT)
|
2000-09-14 17:53:12 +00:00
|
|
|
|
fl_set_input(label, text.c_str());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
else
|
2002-03-21 21:21:28 +00:00
|
|
|
|
fl_set_object_label(label, text.c_str());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
is_empty = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-09-06 12:42:47 +00:00
|
|
|
|
bool Combox::select(string const & t)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2000-09-14 17:53:12 +00:00
|
|
|
|
if (!browser || t.empty()) return false;
|
|
|
|
|
int const maxline = fl_get_browser_maxline(browser);
|
2002-03-21 21:21:28 +00:00
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
|
for (int i = 1; i <= maxline; ++i) {
|
|
|
|
|
if (t == fl_get_browser_line(browser, i)) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
select(i);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false; // t does not exist in browser
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-10-17 09:14:34 +00:00
|
|
|
|
void Combox::select(int i)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
if (!browser || !button) return;
|
2002-03-21 21:21:28 +00:00
|
|
|
|
if (i > 0 && i <= fl_get_browser_maxline(browser)) sel = i;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
fl_deactivate_object(button);
|
2002-03-21 21:21:28 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (type == FL_COMBOX_INPUT)
|
|
|
|
|
fl_set_input(label, fl_get_browser_line(browser, sel));
|
|
|
|
|
else
|
2002-03-21 21:21:28 +00:00
|
|
|
|
fl_set_object_label(label, fl_get_browser_line(browser, sel));
|
|
|
|
|
fl_activate_object(button);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-11-29 15:06:42 +00:00
|
|
|
|
void Combox::add(int x, int y, int w, int hmin, int hmax,
|
|
|
|
|
FL_OBJECT * tabfolder1_, FL_OBJECT * tabfolder2_)
|
|
|
|
|
{
|
2001-09-06 12:42:47 +00:00
|
|
|
|
// Store these for later use in working round an xforms bug in show()
|
2000-11-29 15:06:42 +00:00
|
|
|
|
tabfolder1 = tabfolder1_;
|
|
|
|
|
tabfolder2 = tabfolder2_;
|
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
|
FL_OBJECT * obj;
|
2002-03-21 21:21:28 +00:00
|
|
|
|
|
2000-11-04 10:00:12 +00:00
|
|
|
|
switch (type) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
case FL_COMBOX_DROPLIST:
|
|
|
|
|
{
|
|
|
|
|
button = obj = fl_add_button(FL_NORMAL_BUTTON,
|
1999-11-15 12:01:38 +00:00
|
|
|
|
x+w-22, y, 22, hmin, "@2->");
|
|
|
|
|
fl_set_object_color(obj, FL_MCOL, FL_MCOL);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
fl_set_object_dblbuffer(obj, 1);
|
1999-11-15 12:01:38 +00:00
|
|
|
|
fl_set_object_callback(obj, C_Combox_combo_cb, 0);
|
2002-03-21 21:21:28 +00:00
|
|
|
|
label = obj = fl_add_button(FL_NORMAL_TEXT, x, y, w-22, hmin, "");
|
1999-11-15 12:01:38 +00:00
|
|
|
|
fl_set_object_boxtype(obj, FL_DOWN_BOX);
|
|
|
|
|
fl_set_object_color(obj, FL_MCOL, FL_BLACK);
|
|
|
|
|
fl_set_object_lalign(obj, FL_ALIGN_CENTER|FL_ALIGN_INSIDE);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
fl_set_object_dblbuffer(obj, 1);
|
1999-11-15 12:01:38 +00:00
|
|
|
|
fl_set_object_callback(obj, C_Combox_combo_cb, 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case FL_COMBOX_NORMAL:
|
|
|
|
|
{
|
1999-11-15 12:01:38 +00:00
|
|
|
|
button = obj = fl_add_button(FL_NORMAL_BUTTON, x, y, w, hmin, "");
|
|
|
|
|
fl_set_object_color(obj, FL_MCOL, FL_MCOL);
|
|
|
|
|
fl_set_object_boxtype(obj, FL_DOWN_BOX);
|
|
|
|
|
fl_set_object_callback(obj, C_Combox_combo_cb, 0);
|
|
|
|
|
fl_set_object_color(obj, FL_MCOL, FL_BLACK);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
label = button;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case FL_COMBOX_INPUT:
|
|
|
|
|
{
|
|
|
|
|
button = obj = fl_add_button(FL_NORMAL_BUTTON,
|
1999-11-15 12:01:38 +00:00
|
|
|
|
x+w-22, y, 22, hmin, "@2->");
|
|
|
|
|
fl_set_object_color(obj, FL_MCOL, FL_MCOL);
|
|
|
|
|
fl_set_object_callback(obj, C_Combox_combo_cb, 0);
|
|
|
|
|
label = obj = fl_add_input(FL_NORMAL_INPUT, x, y, w-22, hmin, "");
|
|
|
|
|
fl_set_object_boxtype(obj, FL_DOWN_BOX);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
fl_set_object_return(obj, FL_RETURN_END_CHANGED);
|
1999-11-15 12:01:38 +00:00
|
|
|
|
fl_set_object_callback(obj, C_Combox_input_cb, 0);
|
|
|
|
|
//fl_set_object_color(obj, FL_MCOL, FL_BLACK);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
//fl_set_object_lalign(obj,FL_ALIGN_CENTER|FL_ALIGN_INSIDE);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} // end of switch
|
|
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
|
label->u_vdata = this;
|
|
|
|
|
button->u_vdata = this;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// Hmm, it seems fl_create_browser is broken in xforms 0.86.
|
|
|
|
|
// We have to work around that by creating the dropped browser form
|
|
|
|
|
// at this point already. However, this means that we have
|
|
|
|
|
// to do a little hacking: (Asger)
|
|
|
|
|
FL_FORM * current_form = fl_current_form;
|
|
|
|
|
fl_end_form();
|
|
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
|
bw = w + 20;
|
|
|
|
|
bh = hmax - hmin - 12;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
form = fl_bgn_form(FL_NO_BOX, bw, bh);
|
1999-11-15 12:01:38 +00:00
|
|
|
|
browser = obj = fl_add_browser(FL_HOLD_BROWSER, 0, 0, bw, bh, "");
|
|
|
|
|
fl_set_object_boxtype(obj, FL_UP_BOX);
|
|
|
|
|
fl_set_object_color(obj, FL_MCOL, FL_YELLOW);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
fl_set_object_gravity(obj, NorthWestGravity, NorthWestGravity);
|
1999-11-15 12:01:38 +00:00
|
|
|
|
fl_set_object_callback(obj, C_Combox_combo_cb, 2);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
fl_end_form();
|
1999-12-13 00:05:34 +00:00
|
|
|
|
browser->u_vdata = this;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
form->u_vdata = browser;
|
2002-03-21 21:21:28 +00:00
|
|
|
|
fl_register_raw_callback(form,
|
1999-10-25 14:18:30 +00:00
|
|
|
|
ButtonPressMask|KeyPressMask,
|
|
|
|
|
C_Combox_peek_event);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// And revert to adding to the old form (Asger)
|
|
|
|
|
fl_addto_form(current_form);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
Window save_window;
|
|
|
|
|
|
|
|
|
|
} // namespace anon
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
2001-09-06 12:42:47 +00:00
|
|
|
|
void Combox::redraw()
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
if (browser) fl_redraw_object(browser);
|
|
|
|
|
if (button) fl_redraw_object(button);
|
|
|
|
|
if (label) fl_redraw_object(label);
|
|
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
|
2001-09-06 12:42:47 +00:00
|
|
|
|
void Combox::show()
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
if (_pre) _pre();
|
2002-03-21 21:21:28 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
int tmp;
|
2000-10-11 21:06:43 +00:00
|
|
|
|
XGetInputFocus(fl_get_display(), &save_window, &tmp); //BUG-Fix Dietmar
|
|
|
|
|
XFlush(fl_get_display());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (button && type != FL_COMBOX_NORMAL) {
|
2002-03-21 21:21:28 +00:00
|
|
|
|
fl_set_object_label(button, "@2<-");
|
1999-09-27 18:44:28 +00:00
|
|
|
|
fl_redraw_object(button);
|
|
|
|
|
}
|
2000-11-29 15:06:42 +00:00
|
|
|
|
|
|
|
|
|
int x = label->x;
|
|
|
|
|
int y = label->y + label->h;
|
|
|
|
|
if (tabfolder1) {
|
|
|
|
|
// This is a bug work around suggested by Steve Lamont on the
|
|
|
|
|
// xforms mailing list. It correctly positions the browser form
|
|
|
|
|
// after the main window has been moved.
|
|
|
|
|
// The bug only occurs in tabbed folders.
|
|
|
|
|
int folder_x, folder_y, folder_w, folder_h;
|
|
|
|
|
fl_get_folder_area( tabfolder1,
|
|
|
|
|
&folder_x, &folder_y,
|
2002-02-16 15:59:55 +00:00
|
|
|
|
&folder_w, &folder_h);
|
2000-11-29 15:06:42 +00:00
|
|
|
|
x += folder_x;
|
|
|
|
|
y += folder_y;
|
|
|
|
|
|
|
|
|
|
if (tabfolder2) {
|
|
|
|
|
fl_get_folder_area( tabfolder2,
|
|
|
|
|
&folder_x, &folder_y,
|
2002-02-16 15:59:55 +00:00
|
|
|
|
&folder_w, &folder_h);
|
2000-11-29 15:06:42 +00:00
|
|
|
|
x += tabfolder2->form->x + folder_x;
|
|
|
|
|
y += tabfolder2->form->y + folder_y;
|
|
|
|
|
} else {
|
|
|
|
|
x += tabfolder1->form->x;
|
|
|
|
|
y += tabfolder1->form->y;
|
|
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
|
2000-11-29 15:06:42 +00:00
|
|
|
|
} else {
|
|
|
|
|
x += label->form->x;
|
|
|
|
|
y += label->form->y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fl_set_form_position(form, x, y);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
fl_show_form(form, FL_PLACE_POSITION, FL_NOBORDER, "");
|
2002-03-21 21:21:28 +00:00
|
|
|
|
if (sel > 0) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
fl_set_browser_topline(browser, sel);
|
|
|
|
|
fl_select_browser_line(browser, sel);
|
|
|
|
|
}
|
2000-10-11 21:06:43 +00:00
|
|
|
|
XGrabPointer(fl_get_display(), form->window, false,
|
1999-09-27 18:44:28 +00:00
|
|
|
|
ButtonPressMask | ButtonReleaseMask | PointerMotionMask,
|
|
|
|
|
GrabModeAsync, GrabModeAsync,
|
1999-11-15 12:01:38 +00:00
|
|
|
|
0, 0, 0);
|
2000-10-11 21:06:43 +00:00
|
|
|
|
XFlush(fl_get_display());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-09-06 12:42:47 +00:00
|
|
|
|
void Combox::hide(int who)
|
2002-03-21 21:21:28 +00:00
|
|
|
|
{
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (!who && browser && label) {
|
|
|
|
|
sel = fl_get_browser(browser);
|
2002-03-21 21:21:28 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (type == FL_COMBOX_INPUT)
|
|
|
|
|
fl_set_input(label, fl_get_browser_line(browser, sel));
|
|
|
|
|
else
|
|
|
|
|
fl_set_object_label(label,
|
2002-03-21 21:21:28 +00:00
|
|
|
|
fl_get_browser_line(browser, sel));
|
2000-09-14 14:37:21 +00:00
|
|
|
|
// if (callback) callback(sel, cb_arg);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
XUngrabPointer(fl_get_display(), 0);
|
2000-10-11 21:06:43 +00:00
|
|
|
|
XFlush(fl_get_display());
|
2002-03-21 21:21:28 +00:00
|
|
|
|
if (form) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
fl_hide_form(form);
|
2000-10-11 21:06:43 +00:00
|
|
|
|
XSetInputFocus(fl_get_display(), save_window,
|
1999-09-27 18:44:28 +00:00
|
|
|
|
RevertToParent, CurrentTime); // BUG-FIX-Dietmar
|
2000-10-11 21:06:43 +00:00
|
|
|
|
XFlush(fl_get_display());
|
2002-03-21 21:21:28 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (button) {
|
2002-03-21 21:21:28 +00:00
|
|
|
|
if (type != FL_COMBOX_NORMAL) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
fl_set_object_label(button, "@2->");
|
|
|
|
|
fl_redraw_object(button);
|
|
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
}
|
2001-09-12 13:12:22 +00:00
|
|
|
|
if (!who && browser && label && callback)
|
|
|
|
|
callback(sel, cb_arg, this);
|
2002-03-21 21:21:28 +00:00
|
|
|
|
if (_post) _post();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Combox::activate()
|
|
|
|
|
{
|
2002-01-20 23:17:17 +00:00
|
|
|
|
if (browser)
|
|
|
|
|
fl_activate_object(browser);
|
|
|
|
|
if (button) {
|
|
|
|
|
fl_activate_object(button);
|
|
|
|
|
fl_set_object_lcol(button, FL_BLACK);
|
|
|
|
|
}
|
|
|
|
|
if (label) {
|
|
|
|
|
fl_activate_object(label);
|
|
|
|
|
fl_set_object_lcol(label, FL_BLACK);
|
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Combox::deactivate()
|
|
|
|
|
{
|
2002-01-20 23:17:17 +00:00
|
|
|
|
if (browser)
|
|
|
|
|
fl_deactivate_object(browser);
|
|
|
|
|
if (button) {
|
|
|
|
|
fl_deactivate_object(button);
|
|
|
|
|
fl_set_object_lcol(button, FL_INACTIVE);
|
|
|
|
|
}
|
|
|
|
|
if (label) {
|
|
|
|
|
fl_deactivate_object(label);
|
|
|
|
|
fl_set_object_lcol(label, FL_INACTIVE);
|
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-10-11 21:06:43 +00:00
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
|
void Combox::input_cb(FL_OBJECT * ob, long)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-12-13 00:05:34 +00:00
|
|
|
|
Combox * combo = static_cast<Combox*>(ob->u_vdata);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
|
char const * text = fl_get_input(ob);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-01-09 13:58:48 +00:00
|
|
|
|
combo->addto(text ? string(text) : string());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
combo->is_empty = false;
|
|
|
|
|
}
|
|
|
|
|
|
2000-10-11 21:06:43 +00:00
|
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
|
void Combox::combo_cb(FL_OBJECT * ob, long data)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-12-13 00:05:34 +00:00
|
|
|
|
Combox * combo = static_cast<Combox*>(ob->u_vdata);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
switch (data) {
|
|
|
|
|
case 0:
|
2002-03-21 21:21:28 +00:00
|
|
|
|
{
|
2000-10-11 21:06:43 +00:00
|
|
|
|
int const i = combo->get();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
switch (fl_get_button_numb(ob)) {
|
2002-03-21 21:21:28 +00:00
|
|
|
|
case 2:
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2002-03-21 21:21:28 +00:00
|
|
|
|
combo->select(i - 1);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (combo->callback)
|
|
|
|
|
combo->callback(combo->sel,
|
2000-09-14 14:37:21 +00:00
|
|
|
|
combo->cb_arg, combo);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
case 3:
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2002-03-21 21:21:28 +00:00
|
|
|
|
combo->select(i + 1);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (combo->callback)
|
|
|
|
|
combo->callback(combo->sel,
|
2000-09-14 14:37:21 +00:00
|
|
|
|
combo->cb_arg, combo);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2001-09-06 12:42:47 +00:00
|
|
|
|
default: combo->show(); break;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 2:
|
2001-09-06 12:42:47 +00:00
|
|
|
|
combo->hide();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
|
int Combox::peek_event(FL_FORM * form, void * xev)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-12-13 00:05:34 +00:00
|
|
|
|
FL_OBJECT * ob = static_cast<FL_OBJECT *>(form->u_vdata);
|
|
|
|
|
Combox * combo = static_cast<Combox*>(ob->u_vdata);
|
2002-03-21 21:21:28 +00:00
|
|
|
|
|
|
|
|
|
// below mouse does not work like we need it
|
2000-02-04 09:38:32 +00:00
|
|
|
|
if (static_cast<XEvent *>(xev)->type == ButtonPress && (
|
|
|
|
|
static_cast<XEvent *>(xev)->xbutton.x - ob->x < 0 ||
|
|
|
|
|
static_cast<XEvent *>(xev)->xbutton.x - ob->x > ob->w ||
|
|
|
|
|
static_cast<XEvent *>(xev)->xbutton.y - ob->y < 0 ||
|
|
|
|
|
static_cast<XEvent *>(xev)->xbutton.y - ob->y > ob->h)) {
|
2002-03-21 21:21:28 +00:00
|
|
|
|
combo->hide(1);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
|
if (static_cast<XEvent*>(xev)->type != KeyPress) return 0;
|
2002-03-21 21:21:28 +00:00
|
|
|
|
|
2000-02-04 09:38:32 +00:00
|
|
|
|
char s_r[10]; s_r[9] = '\0';
|
1999-09-27 18:44:28 +00:00
|
|
|
|
KeySym keysym_return;
|
2002-03-21 21:21:28 +00:00
|
|
|
|
XLookupString(&static_cast<XEvent*>(xev)->xkey, s_r, 10,
|
2000-10-17 09:14:34 +00:00
|
|
|
|
&keysym_return, 0);
|
2000-10-11 21:06:43 +00:00
|
|
|
|
XFlush(fl_get_display());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
switch (keysym_return) {
|
|
|
|
|
case XK_Down:
|
2002-07-10 15:03:25 +00:00
|
|
|
|
#ifdef XK_KP_Down
|
|
|
|
|
case XK_KP_Down:
|
|
|
|
|
#endif
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (fl_get_browser(combo->browser) <
|
|
|
|
|
fl_get_browser_maxline(combo->browser))
|
|
|
|
|
fl_select_browser_line(combo->browser,
|
|
|
|
|
fl_get_browser(combo->browser)+1);
|
2002-03-21 21:21:28 +00:00
|
|
|
|
if (fl_get_browser(combo->browser)>=
|
1999-09-27 18:44:28 +00:00
|
|
|
|
fl_get_browser_topline(combo->browser) +
|
|
|
|
|
fl_get_browser_screenlines(combo->browser))
|
|
|
|
|
fl_set_browser_topline(combo->browser,
|
|
|
|
|
fl_get_browser(combo->browser)
|
|
|
|
|
- fl_get_browser_screenlines(combo->browser)+1);
|
|
|
|
|
if (fl_get_browser(combo->browser)<
|
|
|
|
|
fl_get_browser_topline(combo->browser))
|
|
|
|
|
fl_set_browser_topline(combo->browser,
|
|
|
|
|
fl_get_browser(combo->browser));
|
2002-03-21 21:21:28 +00:00
|
|
|
|
return 1;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
case XK_Up:
|
2002-07-10 15:03:25 +00:00
|
|
|
|
#ifdef XK_KP_Up
|
|
|
|
|
case XK_KP_Up:
|
|
|
|
|
#endif
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (fl_get_browser(combo->browser) > 1)
|
|
|
|
|
fl_select_browser_line(combo->browser,
|
|
|
|
|
fl_get_browser(combo->browser)-1);
|
2002-03-21 21:21:28 +00:00
|
|
|
|
if (fl_get_browser(combo->browser)>=
|
1999-09-27 18:44:28 +00:00
|
|
|
|
fl_get_browser_topline(combo->browser) +
|
|
|
|
|
fl_get_browser_screenlines(combo->browser))
|
|
|
|
|
fl_set_browser_topline(combo->browser,
|
|
|
|
|
fl_get_browser(combo->browser)
|
|
|
|
|
- fl_get_browser_screenlines(combo->browser)+1);
|
|
|
|
|
if (fl_get_browser(combo->browser) <
|
|
|
|
|
fl_get_browser_topline(combo->browser))
|
|
|
|
|
fl_set_browser_topline(combo->browser,
|
|
|
|
|
fl_get_browser(combo->browser));
|
|
|
|
|
return 1;
|
|
|
|
|
case XK_Return:
|
2002-07-10 15:03:25 +00:00
|
|
|
|
#ifdef XK_KP_Enter
|
|
|
|
|
case XK_KP_Enter:
|
|
|
|
|
#endif
|
2001-09-06 12:42:47 +00:00
|
|
|
|
combo->hide();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return 1;
|
|
|
|
|
case XK_Escape:
|
2001-09-06 12:42:47 +00:00
|
|
|
|
combo->hide(1);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
2002-03-21 21:21:28 +00:00
|
|
|
|
return 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
1999-10-25 14:18:30 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
#ifdef TESTCOMBO
|
|
|
|
|
typedef struct {
|
|
|
|
|
FL_FORM *test;
|
|
|
|
|
FL_OBJECT *bar;
|
|
|
|
|
void *vdata;
|
|
|
|
|
long ldata;
|
|
|
|
|
} FD_test;
|
|
|
|
|
|
|
|
|
|
//Combox combo(FL_COMBOX_DROPLIST);
|
|
|
|
|
Combox combo(FL_COMBOX_INPUT);
|
|
|
|
|
|
|
|
|
|
FD_test *fd_test;
|
2002-03-21 21:21:28 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
FD_test *create_form_test(void)
|
|
|
|
|
{
|
|
|
|
|
FL_OBJECT *obj;
|
|
|
|
|
FD_test *fdui = (FD_test *) fl_calloc(1, sizeof(*fdui));
|
2002-03-21 21:21:28 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
fdui->test = fl_bgn_form(FL_NO_BOX, 320, 190);
|
1999-11-15 12:01:38 +00:00
|
|
|
|
obj = fl_add_box(FL_UP_BOX, 0, 0, 320, 190, "");
|
|
|
|
|
obj = fl_add_box(FL_DOWN_BOX, 10, 50, 300, 110, "");
|
|
|
|
|
obj = fl_add_button(FL_NORMAL_BUTTON, 250, 10, 50, 30, _("Done"));
|
2002-03-21 21:21:28 +00:00
|
|
|
|
combo.add(10, 15, 120, 25, 135);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
fl_end_form();
|
|
|
|
|
|
|
|
|
|
return fdui;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void combo_cb(int i)
|
|
|
|
|
{
|
|
|
|
|
fprintf(stderr, "selected %d:%s\n", i, combo.getline());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
|
{
|
|
|
|
|
//int n1;
|
2002-03-21 21:21:28 +00:00
|
|
|
|
|
|
|
|
|
// Same defaults as in lyx
|
1999-09-27 18:44:28 +00:00
|
|
|
|
FL_IOPT cntl;
|
|
|
|
|
cntl.buttonFontSize = FL_NORMAL_SIZE;
|
|
|
|
|
cntl.browserFontSize = FL_NORMAL_SIZE;
|
|
|
|
|
cntl.labelFontSize = FL_NORMAL_SIZE;
|
|
|
|
|
cntl.choiceFontSize = FL_NORMAL_SIZE;
|
|
|
|
|
cntl.inputFontSize = FL_NORMAL_SIZE;
|
|
|
|
|
cntl.borderWidth = -2;
|
2002-03-21 21:21:28 +00:00
|
|
|
|
fl_set_defaults(FL_PDButtonFontSize, &cntl);
|
|
|
|
|
fl_set_defaults(FL_PDBrowserFontSize, &cntl);
|
|
|
|
|
fl_set_defaults(FL_PDLabelFontSize, &cntl);
|
|
|
|
|
fl_set_defaults(FL_PDChoiceFontSize, &cntl);
|
|
|
|
|
fl_set_defaults(FL_PDInputFontSize, &cntl);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
fl_set_defaults(FL_PDBorderWidth, &cntl);
|
|
|
|
|
fl_initialize(&argc, argv, 0, 0, 0);
|
2002-03-21 21:21:28 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
fd_test = create_form_test();
|
|
|
|
|
|
|
|
|
|
/* fill-in form initialization code */
|
|
|
|
|
combo.addline("Title");
|
|
|
|
|
combo.addline("Author");
|
|
|
|
|
combo.addline("Date");
|
|
|
|
|
combo.addline("Abstract");
|
|
|
|
|
combo.addline("Chapter");
|
|
|
|
|
combo.addline("Section");
|
|
|
|
|
combo.addline("Subsection");
|
|
|
|
|
combo.addline("List");
|
|
|
|
|
combo.addline("Description");
|
|
|
|
|
combo.addline("Verse");
|
|
|
|
|
combo.addline("Verbatim");
|
|
|
|
|
combo.setcallback(combo_cb);
|
|
|
|
|
// combo.select(4);
|
2002-03-21 21:21:28 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
/* show the first form */
|
1999-11-15 12:01:38 +00:00
|
|
|
|
fl_show_form(fd_test->test, FL_PLACE_CENTER, FL_FULLBORDER, "test");
|
1999-09-27 18:44:28 +00:00
|
|
|
|
fl_do_forms();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|