/**
* \file combox.c
+ * 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
+ *
* This is a rewrite of Alejandro's C++ Combox class, originally written
* for LyX in 1996. The rewrite turns it into a native xforms widget.
*/
#include "combox.h"
#include "freebrowser.h"
-
extern void fl_add_child(FL_OBJECT *, FL_OBJECT *);
extern void fl_addto_freelist(void *);
static void attrib_change(COMBOX_SPEC * sp);
-FL_OBJECT * fl_create_combox(int type,
+FL_OBJECT * fl_create_combox(FL_COMBOX_TYPE type,
FL_Coord x, FL_Coord y, FL_Coord w, FL_Coord h,
char const * label)
{
FL_Coord const ws = 0.7 * h;
FL_Coord const xs = x + w - ws;
+ /* The width of button_chosen */
+ FL_Coord const wc = (type == FL_DROPLIST_COMBOX) ? (w - ws) : w;
+
ob = fl_make_object(FL_COMBOX, type, x, y, w, h, label, combox_handle);
ob->align = FL_ALIGN_LEFT;
sp->browser = fl_create_freebrowser(sp);
sp->browser->callback = update_button_chosen;
- sp->button_state = fl_add_button(FL_NORMAL_BUTTON, xs, y, ws, h, "");
+ sp->button_state = 0;
+ if (type == FL_DROPLIST_COMBOX) {
+ sp->button_state = fl_add_button(FL_NORMAL_BUTTON, xs, y, ws, h, "");
- button = sp->button_state;
- fl_set_object_lalign(button, FL_ALIGN_CENTER|FL_ALIGN_INSIDE);
- fl_set_object_callback(button, state_cb, 0);
- fl_set_object_posthandler(button, combox_post);
- fl_set_object_prehandler(button, combox_pre);
- set_state_label(sp, COMBOX_CLOSED);
+ button = sp->button_state;
+ fl_set_object_lalign(button, FL_ALIGN_CENTER|FL_ALIGN_INSIDE);
+ fl_set_object_callback(button, state_cb, 0);
+ fl_set_object_posthandler(button, combox_post);
+ fl_set_object_prehandler(button, combox_pre);
+ set_state_label(sp, COMBOX_CLOSED);
- set_activation(button, DEACTIVATE);
- button->parent = ob;
- button->u_vdata = sp;
+ set_activation(button, DEACTIVATE);
+ button->parent = ob;
+ button->u_vdata = sp;
+ }
- sp->button_chosen = fl_add_button(FL_NORMAL_TEXT, x, y, (w - ws), h, "");
+ sp->button_chosen = fl_add_button(FL_NORMAL_TEXT, x, y, wc, h, "");
button = sp->button_chosen;
fl_set_object_boxtype(button, FL_FRAME_BOX);
}
-FL_OBJECT * fl_add_combox(int type,
+FL_OBJECT * fl_add_combox(FL_COMBOX_TYPE type,
FL_Coord x, FL_Coord y, FL_Coord w, FL_Coord h,
char const * label)
{
FL_OBJECT * ob = fl_create_combox(type, x, y, w, h, label);
COMBOX_SPEC * sp = ob->spec;
- fl_add_child(ob, sp->button_state);
+ if (sp->button_state)
+ fl_add_child(ob, sp->button_state);
fl_add_child(ob, sp->button_chosen);
fl_add_object(fl_current_form, ob);
}
-void fl_set_combox_position(FL_OBJECT * ob, int position)
+void fl_set_combox_position(FL_OBJECT * ob, FL_COMBOX_POSITION position)
{
COMBOX_SPEC * sp;
return;
sp = ob->spec;
- sp->browser_position = (position == FL_FREEBROWSER_ABOVE) ?
+ sp->browser_position = (position == FL_COMBOX_ABOVE) ?
FL_FREEBROWSER_ABOVE : FL_FREEBROWSER_BELOW;
set_state_label(sp, COMBOX_CLOSED);
if (!fl_get_browser(browser)) {
fl_set_object_label(sp->button_chosen, text);
set_activation(sp->button_chosen, ACTIVATE);
- set_activation(sp->button_state, ACTIVATE);
+ if (sp->button_state)
+ set_activation(sp->button_state, ACTIVATE);
}
}
char const * const up = "@2<-";
char const * const down = "@2->";
char const * label = 0;
+
+ if (!sp->button_state)
+ return;
+
if (sp->browser_position == FL_FREEBROWSER_BELOW) {
label = (state == COMBOX_OPEN) ? up : down;
} else {
button->col2 = parent->col2;
button->bw = parent->bw;
- button = sp->button_state;
+ if (sp->button_state) {
+ button = sp->button_state;
- /* The boxtype is not changed */
- button->col1 = parent->col1;
- button->col2 = parent->col2;
- button->bw = parent->bw;
+ /* The boxtype is not changed */
+ button->col1 = parent->col1;
+ button->col2 = parent->col2;
+ button->bw = parent->bw;
+ }
}
/**
* \file combox.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
* \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.
*/
FL_COMBOX = 200
};
-/** The types of combox. At the moment, there's only one. */
-enum {
+/** 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 label: the widget's label as it appears on the GUI.
*/
FL_EXPORT FL_OBJECT *
-fl_create_combox(int type, FL_Coord x, FL_Coord y, FL_Coord w, FL_Coord h,
+fl_create_combox(FL_COMBOX_TYPE type,
+ FL_Coord x, FL_Coord y, FL_Coord w, FL_Coord h,
char const * label);
/** 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(int type, FL_Coord x, FL_Coord y, FL_Coord w, FL_Coord h,
+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. */
/** The browser will be displayed either below or above the button,
* dependent upon \param position.
*/
-FL_EXPORT void fl_set_combox_position(FL_OBJECT * ob, int position);
+FL_EXPORT void fl_set_combox_position(FL_OBJECT * ob,
+ FL_COMBOX_POSITION position);
/** Empty the browser and the combox, \param ob. */
FL_EXPORT void fl_clear_combox(FL_OBJECT * ob);