X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fxforms%2Fcombox.h;h=abdbcda638be2e2dd725626087a48eebeb02d099;hb=37e82a546392d43f787826b85481a11f2a27af15;hp=e7613f23f32d334fd11db479a57be0642546827f;hpb=1eb8155fa0d2253d9504a8d660cb3d666c1224f6;p=lyx.git diff --git a/src/frontends/xforms/combox.h b/src/frontends/xforms/combox.h index e7613f23f3..abdbcda638 100644 --- a/src/frontends/xforms/combox.h +++ b/src/frontends/xforms/combox.h @@ -1,244 +1,117 @@ -// -*- C++ -*- /** * \file combox.h - * Copyright 1996 Alejandro Aguilar Sierra * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * - * \author Alejandro Aguilar Sierra + * \author Angus Leeming * - * Full author contact details are available in file CREDITS - */ - -/* 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: + * Full author contact details are available in file CREDITS. * - * 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. + * A combination of two objects (a button and a browser) is encapsulated to + * get a combobox-like object. */ -#ifndef COMBOX_H -#define COMBOX_H - -#ifdef __GNUG__ -#pragma interface -#endif - -#include FORMS_H_LOCATION -#include -#include "LString.h" - -/// -enum combox_type { - /// - FL_COMBOX_NORMAL, - /// - FL_COMBOX_DROPLIST, - /// - FL_COMBOX_INPUT -}; - -class Combox; - -/// callback prototype -typedef void (*FL_COMBO_CB) (int, void *, Combox *); -/// pre post prototype -typedef void (*FL_COMBO_PRE_POST) (); - - -/// -class Combox { -public: - /// - explicit Combox(combox_type t = FL_COMBOX_NORMAL); - /// - ~Combox(); - - /** To add this object to a form. Note that there are two heights - for normal (button) and expanded (browser) mode each. - The optional tabfolder arguments are needed to overcome an - xforms bug when repositioning a combox in a tab folder. - tabfolder1_ is the folder holding the combox. - If using nested tabfolders, tabfolder2_ is the "base" folder - holding tabfolder1_. - */ - void add(int x, int y, int w, int hmin, int hmax, - FL_OBJECT * tabfolder1_ = 0, FL_OBJECT * tabfolder2_ = 0); - - /// Add lines. Same as for fl_browser object - void addline(string const &); - /// Add lines. Same as for fl_browser object - void addto(string const &); - - /// Returns the selected item - int get() const; - - /// Returns a pointer to the selected line of text - string const getline() const; - - /// Select an arbitrary item - void select(int); - /// - bool select(string const &); - - /// Clear all the list - void clear(); - - /// Is the combox cleared (empty) - bool empty() const { 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 - * function with a int, a void pointer, and a Combox pointer as - * parameters. - */ - 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(); - /// - void shortcut(string const &, int); - /// - void redraw(); - /// - void show(); - /// - static void combo_cb(FL_OBJECT *, long); - /// - static void input_cb(FL_OBJECT *, long); - /// - static int peek_event(FL_FORM *, void *); - protected: - /// At least Hide should not be public - void hide(int who = 0); - /// - FL_OBJECT * browser; - private: - /// - combox_type type; - /// - int bw; - /// - int bh; - /// - int sel; - /// - bool is_empty; - /// - FL_COMBO_CB callback; - /// - void * cb_arg; - /// - FL_COMBO_PRE_POST _pre; - /// - FL_COMBO_PRE_POST _post; - /// - FL_OBJECT * button; - /// - FL_OBJECT * label; - /// - FL_FORM* form; - /// - FL_OBJECT * tabfolder1; - /// - FL_OBJECT * tabfolder2; -}; +#ifndef FL_COMBOX_H +#define FL_COMBOX_H +#include "lyx_forms.h" - -//----------------- Inline methods --------------------------- - -inline -void Combox::addto(string const & text) +#if defined(__cplusplus) +extern "C" { - if (browser) { - fl_addto_browser(browser, text.c_str()); - is_empty = false; - } -} - +#endif -inline -void Combox::resize(unsigned r) -{ - fl_set_object_resize(button, r); - if (label!= button) fl_set_object_resize(label, r); -} +/** This will eventually be moved into the enum of in-built widgets + in forms.h. */ +enum { + FL_COMBOX = 200 +}; +/** The various types of combox. */ +typedef enum { + FL_NORMAL_COMBOX, + FL_DROPLIST_COMBOX +} FL_COMBOX_TYPE; + +/** How the browser should be displayed relative to the buttons. */ +typedef enum { + FL_COMBOX_BELOW, + FL_COMBOX_ABOVE +} FL_COMBOX_POSITION; + +/** A function to create a combox widget. + * \param type is, as yet, unused. there is only one type of combox. + * \param x the x coordinate of the upper left hand corner of the widget, + * relative to the parent form's origin. + * \param y the y coordinate of the upper left hand corner of the widget, + * relative to the parent form's origin. + * \param w the widget's width + * \param h the widget's height + * \param label the widget's label as it appears on the GUI. + */ +FL_EXPORT FL_OBJECT * +fl_create_combox(FL_COMBOX_TYPE type, + FL_Coord x, FL_Coord y, FL_Coord w, FL_Coord h, + char const * label); -inline -void Combox::gravity(unsigned g1, unsigned g2) -{ - fl_set_object_gravity(button, g1, g2); - if (label!= button) fl_set_object_gravity(label, g1, g2); -} +/** A function to create a combox widget and add it to the parent form. + * \see fl_create_combox() for an explanation of the argument list. + */ +FL_EXPORT FL_OBJECT * +fl_add_combox(FL_COMBOX_TYPE type, + FL_Coord x, FL_Coord y, FL_Coord w, FL_Coord h, + char const * label); +/** The combox browser has a default height of 100 pixels. Adjust to suit. */ +FL_EXPORT void +fl_set_combox_browser_height(FL_OBJECT * ob, int bh); -inline -void Combox::shortcut(string const & s, int i) -{ - if (button) - fl_set_object_shortcut(button, s.c_str(), i); -} +/** The browser will be displayed either below or above the button, + * dependent upon \c position. + */ +FL_EXPORT void +fl_set_combox_position(FL_OBJECT * ob, FL_COMBOX_POSITION position); +/** Empty the browser and the combox. */ +FL_EXPORT void +fl_clear_combox(FL_OBJECT * ob); -inline -void Combox::setcallback(FL_COMBO_CB cb, void * a = 0) -{ - callback = cb; - cb_arg = a; -} +/** Add a line to the combox browser. */ +FL_EXPORT void +fl_addto_combox(FL_OBJECT * ob, char const * text); +/** Set the combox to return line \c choice of the combox browser. */ +FL_EXPORT void +fl_set_combox(FL_OBJECT * ob, int choice); -inline -void Combox::setpre(FL_COMBO_PRE_POST cb) -{ - _pre = cb; -} +/** \return the currently selected line of the combox browser. */ +FL_EXPORT int +fl_get_combox(FL_OBJECT * ob); +/** \return the contents of the combox. + * (Also the contents of currently selected line of the combox browser.) + */ +FL_EXPORT char const * +fl_get_combox_text(FL_OBJECT * ob); -inline -void Combox::setpost(FL_COMBO_PRE_POST cb) -{ - _post = cb; -} +/** \return the contents of \c line of the combox browser. */ +FL_EXPORT char const * +fl_get_combox_line(FL_OBJECT * ob, int line); +/** \return the number of items in the combox browser. */ +FL_EXPORT int +fl_get_combox_maxitems(FL_OBJECT * ob); -inline -int Combox::get() const -{ - return sel; -} +/** Show the browser */ +FL_EXPORT void +fl_show_combox_browser(FL_OBJECT * ob); +/** Hide the browser */ +FL_EXPORT void +fl_hide_combox_browser(FL_OBJECT * ob); -inline -string const Combox::getline() const -{ - if (type == FL_COMBOX_INPUT) - return fl_get_input(label); - else - return (browser && sel > 0) ? - string(fl_get_browser_line(browser, sel)) : string(); +#if defined(__cplusplus) } - #endif + +#endif /* NOT FL_COMBOX_H */