1999-09-27 18:44:28 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/*
|
|
|
|
* Combox: A combination of two objects (a button and a browser) is
|
|
|
|
* encapsulated to get a combobox-like object. All XForms
|
|
|
|
* functions are hidden.
|
|
|
|
*
|
2000-03-09 03:36:48 +00:00
|
|
|
* GNU Copyleft 1996 Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
|
1999-09-27 18:44:28 +00:00
|
|
|
* and the LyX Team.
|
|
|
|
*
|
|
|
|
* Dependencies: Only XForms, but created to be used with LyX.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Change log:
|
|
|
|
*
|
|
|
|
* 2/06/1996, Alejandro Aguilar Sierra
|
|
|
|
* Created and tested.
|
|
|
|
*
|
|
|
|
* 4/06/1996, Alejandro Aguilar Sierra
|
|
|
|
* Added droplist mode (a button with a black down arrow at right)
|
|
|
|
* and support for middle and right buttons, as XForms choice object.
|
|
|
|
*/
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
#ifndef COMBOX_H
|
|
|
|
#define COMBOX_H
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma interface
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include FORMS_H_LOCATION
|
1999-11-15 12:01:38 +00:00
|
|
|
#include <cstdlib>
|
2000-09-14 17:53:12 +00:00
|
|
|
#include "LString.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
///
|
|
|
|
enum combox_type {
|
|
|
|
///
|
|
|
|
FL_COMBOX_NORMAL,
|
|
|
|
///
|
|
|
|
FL_COMBOX_DROPLIST,
|
|
|
|
///
|
|
|
|
FL_COMBOX_INPUT
|
|
|
|
};
|
|
|
|
|
2000-09-14 14:37:21 +00:00
|
|
|
class Combox;
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
/// callback prototype
|
2000-09-14 14:37:21 +00:00
|
|
|
typedef void (*FL_COMBO_CB) (int, void *, Combox *);
|
1999-09-27 18:44:28 +00:00
|
|
|
/// pre post prototype
|
|
|
|
typedef void (*FL_COMBO_PRE_POST) ();
|
|
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
class Combox {
|
|
|
|
public:
|
|
|
|
///
|
2000-04-08 17:02:02 +00:00
|
|
|
explicit Combox(combox_type t = FL_COMBOX_NORMAL);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
~Combox();
|
|
|
|
|
|
|
|
/** To add this object to a form. Note that there are two heights
|
2000-08-07 20:58:24 +00:00
|
|
|
for normal (button) and expanded (browser) mode each.
|
|
|
|
*/
|
1999-09-27 18:44:28 +00:00
|
|
|
void add(int x, int y, int w, int hmin, int hmax);
|
|
|
|
|
|
|
|
/// Add lines. Same as for fl_browser object
|
2000-09-14 17:53:12 +00:00
|
|
|
void addline(string const &);
|
1999-09-27 18:44:28 +00:00
|
|
|
/// Add lines. Same as for fl_browser object
|
2000-09-14 17:53:12 +00:00
|
|
|
void addto(string const &);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
/// Returns the selected item
|
|
|
|
int get();
|
|
|
|
|
|
|
|
/// Returns a pointer to the selected line of text
|
2000-09-14 17:53:12 +00:00
|
|
|
string const getline();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
/// Select an arbitrary item
|
|
|
|
void select(int);
|
|
|
|
///
|
2000-09-14 17:53:12 +00:00
|
|
|
bool select_text(string const &);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
/// Clear all the list
|
|
|
|
void clear();
|
|
|
|
|
|
|
|
/// Is the combox cleared (empty)
|
|
|
|
bool empty() { return is_empty; }
|
|
|
|
|
|
|
|
/// Remove the objects from the form they are in.
|
|
|
|
void remove();
|
|
|
|
|
|
|
|
/** Assign a callback to this object. The callback should be a void
|
2000-08-07 20:58:24 +00:00
|
|
|
function with a int and a void pointer as parameters.
|
|
|
|
*/
|
1999-09-27 18:44:28 +00:00
|
|
|
void setcallback(FL_COMBO_CB, void *);
|
|
|
|
|
|
|
|
/// Pre handler
|
|
|
|
void setpre(FL_COMBO_PRE_POST);
|
|
|
|
/// Post handler
|
|
|
|
void setpost(FL_COMBO_PRE_POST);
|
|
|
|
|
|
|
|
/// XForms attributes
|
|
|
|
void resize(unsigned);
|
|
|
|
///
|
|
|
|
void gravity(unsigned, unsigned);
|
|
|
|
///
|
|
|
|
void activate();
|
|
|
|
///
|
|
|
|
void deactivate();
|
|
|
|
///
|
2000-09-14 17:53:12 +00:00
|
|
|
void shortcut(string const &, int);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
void Redraw();
|
|
|
|
///
|
|
|
|
void Show();
|
1999-10-25 14:18:30 +00:00
|
|
|
///
|
|
|
|
static void combo_cb(FL_OBJECT *, long);
|
|
|
|
///
|
|
|
|
static void input_cb(FL_OBJECT *, long);
|
|
|
|
///
|
|
|
|
static int peek_event(FL_FORM *, void *);
|
1999-09-27 18:44:28 +00:00
|
|
|
protected:
|
|
|
|
/// At least Hide should not be public
|
|
|
|
void Hide(int who = 0);
|
|
|
|
///
|
2000-02-04 09:38:32 +00:00
|
|
|
FL_OBJECT * browser;
|
1999-09-27 18:44:28 +00:00
|
|
|
private:
|
|
|
|
///
|
|
|
|
combox_type type;
|
|
|
|
///
|
|
|
|
int bw, bh;
|
|
|
|
///
|
|
|
|
int sel;
|
|
|
|
///
|
|
|
|
bool is_empty;
|
|
|
|
///
|
|
|
|
FL_COMBO_CB callback;
|
|
|
|
///
|
2000-02-04 09:38:32 +00:00
|
|
|
void * cb_arg;
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
FL_COMBO_PRE_POST _pre;
|
|
|
|
///
|
|
|
|
FL_COMBO_PRE_POST _post;
|
|
|
|
///
|
2000-02-04 09:38:32 +00:00
|
|
|
FL_OBJECT * button;
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
2000-02-04 09:38:32 +00:00
|
|
|
FL_OBJECT * label;
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
FL_FORM* form;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//----------------- Inline methods ---------------------------
|
|
|
|
|
|
|
|
inline
|
2000-09-14 17:53:12 +00:00
|
|
|
void Combox::addto(string const & text)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
if (browser) {
|
2000-09-14 17:53:12 +00:00
|
|
|
fl_addto_browser(browser, text.c_str());
|
1999-09-27 18:44:28 +00:00
|
|
|
is_empty = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-02-04 09:38:32 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
inline
|
|
|
|
void Combox::resize(unsigned r)
|
|
|
|
{
|
|
|
|
fl_set_object_resize(button, r);
|
1999-11-15 12:01:38 +00:00
|
|
|
if (label!= button) fl_set_object_resize(label, r);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
2000-02-04 09:38:32 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
inline
|
|
|
|
void Combox::gravity(unsigned g1, unsigned g2)
|
|
|
|
{
|
|
|
|
fl_set_object_gravity(button, g1, g2);
|
1999-11-15 12:01:38 +00:00
|
|
|
if (label!= button) fl_set_object_gravity(label, g1, g2);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
2000-02-04 09:38:32 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
inline
|
2000-09-14 17:53:12 +00:00
|
|
|
void Combox::shortcut(string const & s, int i)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
if (button)
|
2000-09-14 17:53:12 +00:00
|
|
|
fl_set_object_shortcut(button, s.c_str(), i);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
2000-02-04 09:38:32 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
inline
|
2000-02-04 09:38:32 +00:00
|
|
|
void Combox::setcallback(FL_COMBO_CB cb, void * a = 0)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
callback = cb;
|
|
|
|
cb_arg = a;
|
|
|
|
}
|
|
|
|
|
2000-02-04 09:38:32 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
inline
|
|
|
|
void Combox::setpre(FL_COMBO_PRE_POST cb)
|
|
|
|
{
|
|
|
|
_pre = cb;
|
|
|
|
}
|
|
|
|
|
2000-02-04 09:38:32 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
inline
|
|
|
|
void Combox::setpost(FL_COMBO_PRE_POST cb)
|
|
|
|
{
|
|
|
|
_post = cb;
|
|
|
|
}
|
|
|
|
|
2000-02-04 09:38:32 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
inline
|
|
|
|
int Combox::get()
|
|
|
|
{
|
|
|
|
return sel;
|
|
|
|
}
|
|
|
|
|
2000-02-04 09:38:32 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
inline
|
2000-09-14 17:53:12 +00:00
|
|
|
string const Combox::getline()
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-15 12:01:38 +00:00
|
|
|
if (type == FL_COMBOX_INPUT)
|
1999-09-27 18:44:28 +00:00
|
|
|
return fl_get_input(label);
|
|
|
|
else
|
2000-09-29 12:14:15 +00:00
|
|
|
return (browser && sel > 0) ? fl_get_browser_line(browser, sel) : string();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|