From: Angus Leeming Date: Fri, 4 Apr 2003 14:01:37 +0000 (+0000) Subject: * Ensure that the formatting conforms to xforms style. X-Git-Tag: 1.6.10~17050 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=99f8c40778889a0ca7f162cb573c2cfa09123e42;p=features.git * Ensure that the formatting conforms to xforms style. * Add all major authors. * Squash bug in initial selection of the first line of the browser. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6717 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index 7f9b084e00..d401586e66 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,12 @@ +2003-04-03 Angus Leeming + + * combox.[ch]: + * freebrowser.[ch]: ensure that the formatting conforms to xforms + style. Add all major authors. + + combox.c (fl_addto_combox): squash bug in initial selection + of the first line of the browser. + 2003-04-03 Angus Leeming * freebrowser.[ch] (fl_get_freebrowser_browser): removed spurious diff --git a/src/frontends/xforms/combox.c b/src/frontends/xforms/combox.c index a889e4481a..b13a2c73ea 100644 --- a/src/frontends/xforms/combox.c +++ b/src/frontends/xforms/combox.c @@ -4,6 +4,8 @@ * Licence details can be found in the file COPYING. * * \author Alejandro Aguilar Sierra + * \author Lars Gullik Bjønnes + * \author Jean-Marc Lasgouttes * \author Angus Leeming * * Full author contact details are available in file CREDITS @@ -64,9 +66,10 @@ static void set_state_label(COMBOX_SPEC * sp, int state); static void attrib_change(COMBOX_SPEC * sp); -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_OBJECT * +fl_create_combox(FL_COMBOX_TYPE type, + FL_Coord x, FL_Coord y, FL_Coord w, FL_Coord h, + char const * label) { FL_OBJECT * ob; FL_OBJECT * button; @@ -122,9 +125,10 @@ FL_OBJECT * fl_create_combox(FL_COMBOX_TYPE 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 * +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; @@ -138,7 +142,8 @@ FL_OBJECT * fl_add_combox(FL_COMBOX_TYPE type, } -void fl_set_combox_browser_height(FL_OBJECT * ob, int bh) +void +fl_set_combox_browser_height(FL_OBJECT * ob, int bh) { COMBOX_SPEC * sp; @@ -150,7 +155,8 @@ void fl_set_combox_browser_height(FL_OBJECT * ob, int bh) } -void fl_set_combox_position(FL_OBJECT * ob, FL_COMBOX_POSITION position) +void +fl_set_combox_position(FL_OBJECT * ob, FL_COMBOX_POSITION position) { COMBOX_SPEC * sp; @@ -165,7 +171,8 @@ void fl_set_combox_position(FL_OBJECT * ob, FL_COMBOX_POSITION position) } -void fl_clear_combox(FL_OBJECT * ob) +void +fl_clear_combox(FL_OBJECT * ob) { COMBOX_SPEC * sp; FL_OBJECT * browser; @@ -181,7 +188,8 @@ void fl_clear_combox(FL_OBJECT * ob) } -void fl_addto_combox(FL_OBJECT * ob, char const * text) +void +fl_addto_combox(FL_OBJECT * ob, char const * text) { COMBOX_SPEC * sp; FL_OBJECT * browser; @@ -207,15 +215,16 @@ void fl_addto_combox(FL_OBJECT * ob, char const * text) } } - if (j != 0) - { + if (j != 0) { line[j] = '\0'; fl_add_browser_line(browser, line); - } + } /* By default the first item is selected */ - if (!fl_get_browser(browser)) { - fl_set_object_label(sp->button_chosen, text); + if (fl_get_browser_maxline(browser)) { + char const * const label = fl_get_browser_line(browser, 1); + fl_set_object_label(sp->button_chosen, label); + fl_select_browser_line(browser, 1); set_activation(sp->button_chosen, ACTIVATE); if (sp->button_state) set_activation(sp->button_state, ACTIVATE); @@ -223,7 +232,8 @@ void fl_addto_combox(FL_OBJECT * ob, char const * text) } -void fl_set_combox(FL_OBJECT * ob, int sel) +void +fl_set_combox(FL_OBJECT * ob, int sel) { COMBOX_SPEC * sp; FL_OBJECT * browser; @@ -242,7 +252,8 @@ void fl_set_combox(FL_OBJECT * ob, int sel) } -int fl_get_combox(FL_OBJECT * ob) +int +fl_get_combox(FL_OBJECT * ob) { COMBOX_SPEC * sp; FL_OBJECT * browser; @@ -256,7 +267,8 @@ int fl_get_combox(FL_OBJECT * ob) } -char const * fl_get_combox_text(FL_OBJECT * ob) +char const * +fl_get_combox_text(FL_OBJECT * ob) { COMBOX_SPEC * sp; @@ -268,7 +280,8 @@ char const * fl_get_combox_text(FL_OBJECT * ob) } -char const * fl_get_combox_line(FL_OBJECT * ob, int line) +char const * +fl_get_combox_line(FL_OBJECT * ob, int line) { COMBOX_SPEC * sp; FL_OBJECT * browser; @@ -288,7 +301,8 @@ char const * fl_get_combox_line(FL_OBJECT * ob, int line) } -int fl_get_combox_maxitems(FL_OBJECT * ob) +int +fl_get_combox_maxitems(FL_OBJECT * ob) { COMBOX_SPEC * sp; FL_OBJECT * browser; @@ -302,7 +316,8 @@ int fl_get_combox_maxitems(FL_OBJECT * ob) } -void fl_show_combox_browser(FL_OBJECT * ob) +void +fl_show_combox_browser(FL_OBJECT * ob) { if (!ob || ob->objclass != FL_COMBOX) return; @@ -311,7 +326,8 @@ void fl_show_combox_browser(FL_OBJECT * ob) } -void fl_hide_combox_browser(FL_OBJECT * ob) +void +fl_hide_combox_browser(FL_OBJECT * ob) { COMBOX_SPEC * sp; @@ -323,8 +339,9 @@ void fl_hide_combox_browser(FL_OBJECT * ob) } -static int combox_pre(FL_OBJECT * ob, int ev, FL_Coord mx, FL_Coord my, - int key, void *xev) +static int +combox_pre(FL_OBJECT * ob, int ev, FL_Coord mx, FL_Coord my, int key, + void * xev) { COMBOX_SPEC * sp = ob->u_vdata; FL_OBJECT * combox = sp->combox; @@ -334,8 +351,9 @@ static int combox_pre(FL_OBJECT * ob, int ev, FL_Coord mx, FL_Coord my, } -static int combox_post(FL_OBJECT * ob, int ev, FL_Coord mx, FL_Coord my, - int key, void *xev) +static int +combox_post(FL_OBJECT * ob, int ev, FL_Coord mx, FL_Coord my, int key, + void * xev) { COMBOX_SPEC * sp = ob->u_vdata; FL_OBJECT * combox = sp->combox; @@ -345,8 +363,9 @@ static int combox_post(FL_OBJECT * ob, int ev, FL_Coord mx, FL_Coord my, } -static int combox_handle(FL_OBJECT * ob, int event, FL_Coord mx, FL_Coord my, - int key, void * ev) +static int +combox_handle(FL_OBJECT * ob, int event, FL_Coord mx, FL_Coord my, int key, + void * ev) { if (!ob || ob->objclass != FL_COMBOX) return 0; @@ -374,7 +393,8 @@ static int combox_handle(FL_OBJECT * ob, int event, FL_Coord mx, FL_Coord my, } -static void set_activation(FL_OBJECT * ob, int activation) +static void +set_activation(FL_OBJECT * ob, int activation) { switch (activation) { case ACTIVATE: @@ -388,7 +408,8 @@ static void set_activation(FL_OBJECT * ob, int activation) } -static void show_browser(COMBOX_SPEC * sp) +static void +show_browser(COMBOX_SPEC * sp) { FL_OBJECT * ob = sp->combox; @@ -406,19 +427,22 @@ static void show_browser(COMBOX_SPEC * sp) } -static void state_cb(FL_OBJECT * ob, long data) +static void +state_cb(FL_OBJECT * ob, long data) { show_browser(ob->u_vdata); } -static void chosen_cb(FL_OBJECT * ob, long data) +static void +chosen_cb(FL_OBJECT * ob, long data) { show_browser(ob->u_vdata); } -static void update_button_chosen(FL_FREEBROWSER * fb, int action) +static void +update_button_chosen(FL_FREEBROWSER * fb, int action) { COMBOX_SPEC * sp = fb->parent; @@ -437,7 +461,8 @@ static void update_button_chosen(FL_FREEBROWSER * fb, int action) } -static void set_state_label(COMBOX_SPEC * sp, int state) +static void +set_state_label(COMBOX_SPEC * sp, int state) { char const * const up = "@2<-"; char const * const down = "@2->"; @@ -456,7 +481,8 @@ static void set_state_label(COMBOX_SPEC * sp, int state) } -static void attrib_change(COMBOX_SPEC * sp) +static void +attrib_change(COMBOX_SPEC * sp) { FL_OBJECT * parent = sp->combox; FL_OBJECT * button = sp->button_chosen; diff --git a/src/frontends/xforms/combox.h b/src/frontends/xforms/combox.h index eda47bb4cd..110c49fe36 100644 --- a/src/frontends/xforms/combox.h +++ b/src/frontends/xforms/combox.h @@ -53,50 +53,60 @@ fl_create_combox(FL_COMBOX_TYPE type, * \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, +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); +FL_EXPORT void +fl_set_combox_browser_height(FL_OBJECT * ob, int bh); /** 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, - FL_COMBOX_POSITION 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); +FL_EXPORT void +fl_clear_combox(FL_OBJECT * ob); /** Add a line to the combox browser.*/ -FL_EXPORT void fl_addto_combox(FL_OBJECT * ob, char const * text); +FL_EXPORT void +fl_addto_combox(FL_OBJECT * ob, char const * text); /** Set the combox to return line \param choice of the combox browser. */ -FL_EXPORT void fl_set_combox(FL_OBJECT * ob, int choice); +FL_EXPORT void +fl_set_combox(FL_OBJECT * ob, int choice); /** \return the currently selected line of the combox browser. */ -FL_EXPORT int fl_get_combox(FL_OBJECT * ob); +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); +FL_EXPORT char const * +fl_get_combox_text(FL_OBJECT * ob); /** \return the contents of \param line of the combox browser. */ -FL_EXPORT char const * fl_get_combox_line(FL_OBJECT * ob, int line); +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); +FL_EXPORT int +fl_get_combox_maxitems(FL_OBJECT * ob); /** Show the browser */ -void fl_show_combox_browser(FL_OBJECT * ob); +FL_EXPORT void +fl_show_combox_browser(FL_OBJECT * ob); /** Hide the browser */ -void fl_hide_combox_browser(FL_OBJECT * ob); +FL_EXPORT void +fl_hide_combox_browser(FL_OBJECT * ob); #if defined(__cplusplus) } #endif -#endif +#endif /* not FL_COMBOX_H */ diff --git a/src/frontends/xforms/freebrowser.c b/src/frontends/xforms/freebrowser.c index 0c51c1788b..e429eecbba 100644 --- a/src/frontends/xforms/freebrowser.c +++ b/src/frontends/xforms/freebrowser.c @@ -4,6 +4,8 @@ * Licence details can be found in the file COPYING. * * \author Alejandro Aguilar Sierra + * \author Lars Gullik Bjønnes + * \author Jean-Marc Lasgouttes * \author Angus Leeming * * Full author contact details are available in file CREDITS @@ -23,7 +25,8 @@ static void browser_cb(FL_OBJECT * ob, long data); static int peek_event(FL_FORM * form, void * xev); -FL_FREEBROWSER * fl_create_freebrowser(void * parent) +FL_FREEBROWSER * +fl_create_freebrowser(void * parent) { FL_FORM * current_form = fl_current_form; FL_FREEBROWSER * fb = fl_calloc(1, sizeof(FL_FREEBROWSER)); @@ -60,7 +63,8 @@ FL_FREEBROWSER * fl_create_freebrowser(void * parent) } -void fl_free_freebrowser(FL_FREEBROWSER * fb) +void +fl_free_freebrowser(FL_FREEBROWSER * fb) { if (!fb) return; @@ -73,8 +77,9 @@ void fl_free_freebrowser(FL_FREEBROWSER * fb) } -void fl_show_freebrowser(FL_FREEBROWSER * fb, - FL_Coord x, FL_Coord y, FL_Coord w, FL_Coord h) +void +fl_show_freebrowser(FL_FREEBROWSER * fb, + FL_Coord x, FL_Coord y, FL_Coord w, FL_Coord h) { int tmp; int const pos = fl_get_browser(fb->browser); @@ -99,7 +104,8 @@ void fl_show_freebrowser(FL_FREEBROWSER * fb, } -void fl_hide_freebrowser(FL_FREEBROWSER * fb) +void +fl_hide_freebrowser(FL_FREEBROWSER * fb) { XUngrabPointer(fl_get_display(), 0); XFlush(fl_get_display()); @@ -116,7 +122,8 @@ void fl_hide_freebrowser(FL_FREEBROWSER * fb) } -static void browser_cb(FL_OBJECT * ob, long data) +static void +browser_cb(FL_OBJECT * ob, long data) { FL_FREEBROWSER * fb = ob->u_vdata; fl_hide_freebrowser(fb); @@ -125,7 +132,30 @@ static void browser_cb(FL_OBJECT * ob, long data) } -static int peek_event(FL_FORM * form, void * ev) +static int +eventWithinObj(XEvent * xev, FL_OBJECT * ob) +{ + int result = 0; + if (xev && ob) { + int const xev_x = (int)(xev->xbutton.x); + int const xev_y = (int)(xev->xbutton.y); + int const ob_x = (int)(ob->x); + int const ob_y = (int)(ob->y); + int const ob_w = (int)(ob->w); + int const ob_h = (int)(ob->h); + + int const dx = xev_x - ob_x; + int const dy = xev_y - ob_y; + + /* result is true if the event occurred within the ob */ + result = !(dx < 0 || dx > ob_w || dy < 0 || dy > ob_h); + } + return result; +} + + +static int +peek_event(FL_FORM * form, void * ev) { XEvent * xev = ev; FL_FREEBROWSER * fb = form->u_vdata; @@ -134,11 +164,7 @@ static int peek_event(FL_FORM * form, void * ev) fb->last_printable = 0; fl_hide_tooltip(); - if (xev->type == ButtonPress && - ((int)(xev->xbutton.x) - (int)(browser->x) < 0 || - (int)(xev->xbutton.x) - (int)(browser->x) > (int)(browser->w) || - (int)(xev->xbutton.y) - (int)(browser->y) < 0 || - (int)(xev->xbutton.y) - (int)(browser->y) > (int)(browser->h))) { + if (xev->type == ButtonPress && !eventWithinObj(xev, browser)) { fl_hide_freebrowser(fb); return 1; } diff --git a/src/frontends/xforms/freebrowser.h b/src/frontends/xforms/freebrowser.h index b59b7c45df..3b9319d348 100644 --- a/src/frontends/xforms/freebrowser.h +++ b/src/frontends/xforms/freebrowser.h @@ -50,24 +50,27 @@ typedef struct fl_freebrowser_ { } FL_FREEBROWSER; -/** A function to create a freebrowser widget, "owned" by widget \param parent. - */ -FL_EXPORT FL_FREEBROWSER * fl_create_freebrowser(void * parent); +/** A function to create a freebrowser widget, "owned" by \param parent. */ +FL_EXPORT FL_FREEBROWSER * +fl_create_freebrowser(void * parent); -FL_EXPORT void fl_free_freebrowser(FL_FREEBROWSER *); +/** Free all memory allocated to \param ptr and to its components. */ +FL_EXPORT void +fl_free_freebrowser(FL_FREEBROWSER * ptr); /** \param abs_x, \param abs_y are the coordinates of the top left corner * of the browser relative to the top left hand corner of the _screen_. * \param w, \param h are the browser dimensions. */ -FL_EXPORT void fl_show_freebrowser(FL_FREEBROWSER *, - FL_Coord abs_x, FL_Coord abs_y, - FL_Coord w, FL_Coord h); +FL_EXPORT void +fl_show_freebrowser(FL_FREEBROWSER *, + FL_Coord abs_x, FL_Coord abs_y, FL_Coord w, FL_Coord h); -FL_EXPORT void fl_hide_freebrowser(FL_FREEBROWSER *); +FL_EXPORT void +fl_hide_freebrowser(FL_FREEBROWSER *); #if defined(__cplusplus) } #endif -#endif +#endif /* not FL_FREEBROWSER_H */