Re: XForms: Problem updating sub-form coords in dragged tabfolders?

From: Ivan Powis (Ivan.Powis@nottingham.ac.uk)
Date: Tue Jun 19 2001 - 08:46:06 EDT

  • Next message: Steve Lamont: "Re: XForms: Problem updating sub-form coords in dragged tabfolders?"

    # To subscribers of the xforms list from Ivan Powis <Ivan.Powis@nottingham.ac.uk> :

    >
    > # To subscribers of the xforms list from Steve Lamont <spl@ncmir.ucsd.edu> :
    >
    > > I am writing an application which includes a number of forms contained
    > > in a tabfolder (on the main form). Part of the functionality of these
    > > container (sub-)forms is to put up a cursor readout (via a oneliner
    > > goody) as the mouse passes over various objects on the sub-form. This
    > > is accomplished by event handlers which obtain the object's position
    > > on the form and the form's position on-screen in order to paste the
    > > oneliner at a fixed position in relation to the object viz:
    > > fl_show_oneliner(txt, ob->x + ob->form->x, ob->y+ob->form->y-YC_OFF);
    >
    > I've been on travel to Exotic Pittsburgh, Pennsylvania, and haven't
    > had time to look into this.
    >
    > Can you provide example code?
    >
    >
                                                             spl

    Yes !

    Here goes, you will see that pressing the button on one of the
    tab_folder forms _after_ the parent window has been dragged onscreen
    returns the wrong x,y for the form. It is necessary to de-select then
    re-select the form which was displayed at the time of dragging to get
    correct origin coordinates.

    The same form and code works fine if displayed as a normal window
    rather than in a tab-folder

    #include <stdlib.h>
    #include <stdio.h>
    #include "forms.h"

    /** Callbacks, globals and object handlers **/
    extern void pb_cb(FL_OBJECT *, long);

    /**** Forms and Objects ****/
    typedef struct {
            FL_FORM *fda;
            void *vdata;
            char *cdata;
            long ldata;
    } FD_fda;

    extern FD_fda * create_form_fda(void);

    typedef struct {
            FL_FORM *fdb;
            void *vdata;
            char *cdata;
            long ldata;
            FL_OBJECT *tb_fldr;
    } FD_fdb;

    extern FD_fdb * create_form_fdb(void);

    /*---------------------------------------------------------------------*/
    int main(int argc, char *argv[])
    {
       FD_fda *fd_fda, *sub1, *sub2;
       FD_fdb *fd_fdb;

       fl_initialize(&argc, argv, 0, 0, 0);
       fd_fdb = create_form_fdb(); /* Main form with folder */
       fd_fda = create_form_fda(); /* Free-standing sub-form */
       sub1 = create_form_fda(); /* sub-forms for pasting into folder */
       sub2 = create_form_fda();

       /* fill-in form initialization code */
      fl_addto_tabfolder(fd_fdb->tb_fldr, "One", sub1->fda);
      fl_addto_tabfolder(fd_fdb->tb_fldr, "Two", sub2->fda);

       /* show the first form */
       fl_show_form(fd_fda->fda,FL_PLACE_FREE,FL_FULLBORDER,"fda");
       fl_show_form(fd_fdb->fdb,FL_PLACE_FREE,FL_FULLBORDER,"fdb");
       fl_do_forms();
       return 0;
    }

    /*------------------------------------------------------------------------*/
    /*** callbacks and freeobj handles for form fda ***/
    void pb_cb(FL_OBJECT *ob, long data)
    {
      FL_FORM *frm = ob->form;
      char buff[100];
      
      sprintf(buff,"Form origin x: %d y%d", frm->x, frm->y);
      fl_hide_oneliner();
      fl_show_oneliner(buff,frm->x+10, frm->y+10);
      printf("< %s >\n",buff);
    }

    /*------------------------------------------------------------------------*/
    /* Form definition file generated with fdesign. */

    FD_fda *create_form_fda(void)
    {
      FL_OBJECT *obj;
      FD_fda *fdui = (FD_fda *) fl_calloc(1, sizeof(*fdui));

      fdui->fda = fl_bgn_form(FL_NO_BOX, 320, 250);
      obj = fl_add_box(FL_UP_BOX,0,0,320,250,"");
      obj = fl_add_button(FL_NORMAL_BUTTON,90,100,160,70,"PRESS");
        fl_set_object_lsize(obj,FL_HUGE_SIZE);
        fl_set_object_lstyle(obj,FL_NORMAL_STYLE+FL_ENGRAVED_STYLE);
        fl_set_object_callback(obj,pb_cb,0);
      fl_end_form();

      fdui->fda->fdui = fdui;

      return fdui;
    }
    /*---------------------------------------*/

    FD_fdb *create_form_fdb(void)
    {
      FL_OBJECT *obj;
      FD_fdb *fdui = (FD_fdb *) fl_calloc(1, sizeof(*fdui));

      fdui->fdb = fl_bgn_form(FL_NO_BOX, 440, 400);
      obj = fl_add_box(FL_UP_BOX,0,0,440,400,"");
      fdui->tb_fldr = obj = fl_add_tabfolder(FL_TOP_TABFOLDER,40,40,370,310,"");
        fl_set_object_lsize(obj,FL_MEDIUM_SIZE);
      fl_end_form();

      fdui->fdb->fdui = fdui;

      return fdui;
    }
    /*---------------------------------------*/

    --
    --------------------------------------------------------------------
        ___  ___/   _  __ /   Ivan Powis   [Ivan.Powis@Nottingham.ac.uk]
            /         /   /   School of Chemistry
           /         /  _/    University of Nottingham
          /         ___/      Nottingham NG7 2RD, UK
         /         /     TEL: +44-115-951-3467
        /         /      FAX: +44-115-951-3562
    _______/  ____/      http://www.chem.nott.ac.uk/IP.html
    --------------------------------------------------------------------
    

    _________________________________________________ To unsubscribe, send the message "unsubscribe" to xforms-request@bob.usuhs.mil or see http://bob.usuhs.mil/mailserv/xforms.html XForms Home Page: http://world.std.com/~xforms List Archive: http://bob.usuhs.mil/mailserv/list-archives/



    This archive was generated by hypermail 2b29 : Tue Jun 19 2001 - 08:55:26 EDT