Hi all,

I put together the following code for test purposes, it is not a full 
implementation with error checking etc or a final design, it just lets me 
practice with some of the elements i will need. it compiles fine  i just 
renamed some of the variables before posting, i can't compile and test in work, 
so excuse any typos i will update any that remain but i think it's ok.

Anyway, the issues i found were:

With the inputCb_i() function:
When the variable 'longI' was made a member of the Class itself, instead of 
local to the callback, then the input fields were only responsive once,
i.e. if i entered the value into inputA, then released the field, the other 
field (effectively the callback i suppose since they both share the same) 
stopped responding, i could not click into it, why is that? When i made the 
variable local again, it worked fine.

The other thing i quickly did before closing down last night:

Each input field is deactived after input for now as i thought it would be 
easiest, if a mistake is made the user just has to click reset to reactivate 
all fields and re-enter data.
The counter incremented in the inputCb() is a placeholder for now to flag when 
all valid entries are received and user can continue.
I realise probably there would be a bool member variable to flag this 'ready' 
state also but i not coded it in yet.

So i want the user to then be able to click 'reset' and reactive all fields.
It compiles without warnings
However i get a seg fault at the call to 'activate()' in reset() function.
I only ever clicked the button after the fields have been deactivated first, 
and i know i should have coded in to prevent reset() being called unless the 
fields were first deactivated anyway, but like i say i just added these lines 
last thing.

some of the identation has come out a bit weird on pasting code in here...>

class SetupTest
{
    public:
    Fl_Window* SetupWindow;
    Fl_Button* Reset;
    Fl_Int_Input *inputA;
    Fl_Int_Input *inputB;

    bool state;
    int valCount;
    void InputCb_i(Fl_Widget* wgt, void* v);
    static void InputCb(Fl_Widget* wgt, void* v);

        void ButtonCb_i(Fl_Widget* wgt, void* v);
    static void ButtonCb(Fl_Widget* wgt, void* v);

        void Reset();

    SetupTest();
};

SetupTest::SetupTest()
{
    SetupWindow = new Fl_Window(300, 200);
    Reset = new Fl_Button(226, 20, 64, 20, "Reset");
    inputA = new Fl_Int_Input(215, 50, 20, 24, "InputA");
    inputA->tooltip("enter number A");
    inputA->type(2);
    inputA->when(FL_WHEN_RELEASE);
    inputB = new Fl_Int_Input(215, 80, 20, 24, "InputB");
    inputB->tooltip("enter number B");
    inputB->type(2);
    inputB->when(FL_WHEN_RELEASE);

    valCount = 0;
    state = false;

    inputA->callback((Fl_Callback*) InputCb);
    inputB->callback((Fl_Callback*) InputCb);
    Reset->callback((Fl_Callback*) ButtonCb);

    SetupWindow->end ();
    SetupWindow->show ();
}

void SetupTest::InputCb_i(Fl_Widget* w, void* v)
{
    Fl_Int_Input* inp = (Fl_Int_Input*) w;
    char* p;
    long int longI = 0;

    if (inp->changed())
    {
        inp->clear_changed();
        longI = strtol(inp->value(), &p, 10);
        printf("%s '%s'\n",inp->label(),inp->value());

        printf("%ld\n",longI);
        inp->deactivate();
        valCount++;
    }

    if(valCount == 2)
    {
        printf("READY");
        valCount = 0;
    }

}
void SetupTest::InputCb(Fl_Widget* wgt, void* v)
{
    ((SetupTest*)(wgt->parent()))->InputCb_i(wgt, v);
}
void SetupTest::ButtonCb_i(Fl_Widget* w, void* v)
{
    Fl_Button* button = (Fl_Button*) w;
    if(!state)
    {
        Reset();
        state = true;
    }
        else
                state = false;
}
void SetupTest::ButtonCb(Fl_Widget* wgt, void* v)
{
    ((SetupTest*)(wgt->parent()))->ButtonCb_i(wgt, v);
}
void SetupTest::Reset()
{
        inputB->activate();
        inputA->activate();
}
int main (int argc, char ** argv)
{
    SetupTest testObj;

  return(Fl::run());
}

_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to