1999-09-27 18:44:28 +00:00
|
|
|
// -*- C++ -*-
|
2002-03-11 17:00:41 +00:00
|
|
|
/**
|
|
|
|
* \file combox.h
|
|
|
|
* Copyright 1996 Alejandro Aguilar Sierra
|
2002-09-05 15:14:23 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-11 17:00:41 +00:00
|
|
|
*
|
2002-09-05 14:10:50 +00:00
|
|
|
* \author Alejandro Aguilar Sierra
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS
|
2002-03-11 17:00:41 +00:00
|
|
|
*/
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2002-03-11 17:00:41 +00:00
|
|
|
/* A combination of two objects (a button and a browser) is encapsulated to
|
|
|
|
* get a combobox-like object. All XForms functions are hidden.
|
|
|
|
*
|
|
|
|
* 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.
|
2002-03-21 21:21:28 +00:00
|
|
|
*/
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
#ifndef COMBOX_H
|
|
|
|
#define COMBOX_H
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
#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
|
2002-10-04 10:39:01 +00:00
|
|
|
* for normal (button) and expanded (browser) mode each.
|
|
|
|
*/
|
|
|
|
void add(int x, int y, int w, int hmin, int hmax);
|
2002-03-21 21:21:28 +00:00
|
|
|
|
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 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 &);
|
2002-03-21 21:21:28 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
/// Returns the selected item
|
2000-10-11 21:06:43 +00:00
|
|
|
int get() const;
|
2002-03-21 21:21:28 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
/// Returns a pointer to the selected line of text
|
2000-10-11 21:06:43 +00:00
|
|
|
string const getline() const;
|
2002-03-21 21:21:28 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
/// Select an arbitrary item
|
2000-10-17 09:14:34 +00:00
|
|
|
void select(int);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
2002-03-21 21:21:28 +00:00
|
|
|
bool select(string const &);
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
/// Clear all the list
|
|
|
|
void clear();
|
|
|
|
|
|
|
|
/// Is the combox cleared (empty)
|
2000-10-11 21:06:43 +00:00
|
|
|
bool empty() const { return is_empty; }
|
2002-03-21 21:21:28 +00:00
|
|
|
|
|
|
|
/// Remove the objects from the form they are in.
|
1999-09-27 18:44:28 +00:00
|
|
|
void remove();
|
|
|
|
|
2002-03-21 21:21:28 +00:00
|
|
|
/**
|
2001-08-16 09:42:04 +00:00
|
|
|
* Assign a callback to this object. The callback should be a void
|
2002-03-21 21:21:28 +00:00
|
|
|
* function with a int, a void pointer, and a Combox pointer as
|
2001-08-16 09:42:04 +00:00
|
|
|
* parameters.
|
2000-08-07 20:58:24 +00:00
|
|
|
*/
|
1999-09-27 18:44:28 +00:00
|
|
|
void setcallback(FL_COMBO_CB, void *);
|
2002-03-21 21:21:28 +00:00
|
|
|
|
|
|
|
/// Pre handler
|
1999-09-27 18:44:28 +00:00
|
|
|
void setpre(FL_COMBO_PRE_POST);
|
|
|
|
/// Post handler
|
|
|
|
void setpost(FL_COMBO_PRE_POST);
|
2002-03-21 21:21:28 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
/// XForms attributes
|
|
|
|
void resize(unsigned);
|
|
|
|
///
|
|
|
|
void gravity(unsigned, unsigned);
|
|
|
|
///
|
|
|
|
void activate();
|
|
|
|
///
|
|
|
|
void deactivate();
|
|
|
|
///
|
2002-03-21 21:21:28 +00:00
|
|
|
void shortcut(string const &, int);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
2001-09-06 12:42:47 +00:00
|
|
|
void redraw();
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
2001-09-06 12:42:47 +00:00
|
|
|
void show();
|
1999-10-25 14:18:30 +00:00
|
|
|
///
|
|
|
|
static void combo_cb(FL_OBJECT *, long);
|
|
|
|
///
|
|
|
|
static void input_cb(FL_OBJECT *, long);
|
|
|
|
///
|
2002-03-21 21:21:28 +00:00
|
|
|
static int peek_event(FL_FORM *, void *);
|
1999-09-27 18:44:28 +00:00
|
|
|
protected:
|
2002-03-21 21:21:28 +00:00
|
|
|
/// At least Hide should not be public
|
2001-09-06 12:42:47 +00:00
|
|
|
void hide(int who = 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
2000-02-04 09:38:32 +00:00
|
|
|
FL_OBJECT * browser;
|
1999-09-27 18:44:28 +00:00
|
|
|
private:
|
|
|
|
///
|
|
|
|
combox_type type;
|
|
|
|
///
|
2002-03-21 21:21:28 +00:00
|
|
|
int bw;
|
2001-02-16 09:25:43 +00:00
|
|
|
///
|
|
|
|
int bh;
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
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
|
|
|
///
|
2002-03-21 21:21:28 +00:00
|
|
|
FL_FORM* form;
|
1999-09-27 18:44:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-03-21 21:21:28 +00:00
|
|
|
//----------------- Inline methods ---------------------------
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
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);
|
2002-03-21 21:21:28 +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);
|
2002-03-21 21:21:28 +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
|
2000-10-11 21:06:43 +00:00
|
|
|
int Combox::get() const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
return sel;
|
|
|
|
}
|
|
|
|
|
2000-02-04 09:38:32 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
inline
|
2000-10-11 21:06:43 +00:00
|
|
|
string const Combox::getline() const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2002-03-21 21:21:28 +00:00
|
|
|
if (type == FL_COMBOX_INPUT)
|
1999-09-27 18:44:28 +00:00
|
|
|
return fl_get_input(label);
|
|
|
|
else
|
2000-09-29 18:44:07 +00:00
|
|
|
return (browser && sel > 0) ?
|
2001-01-09 13:58:48 +00:00
|
|
|
string(fl_get_browser_line(browser, sel)) : string();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|