Callback on Canvas, AddMenu and menu parent DBE

Hi,

When I create a Menu on a Canvas DBE the callback defined of this Canvas DBE with 

void set(DBE canvas, void callback(DBE canv,{char key|int button}, bool controlDown, int x,int y)) 

... is never triggered even for a left click !!!

Bug or feature ????

The consequence of that is that I'm not able to know from which Canvas DBE a menu has been called; the menu callback has only one parameter (the menu index) and I don't know if it is possible to get the parent DBE of a menu.

Does someone has an experience in solving that kind of DXL issue ?

Many thanks.

Joseph.

 


jaracic - Wed Jan 22 09:45:19 EST 2014

Re: Callback on Canvas, AddMenu and menu parent DBE
Mathias Mamsch - Thu Jan 30 08:06:23 EST 2014

Hey Joseph, I am not sure I got what you want. The canvas callback for keyboard and mouse actions does not apply to menus (which is no bug in my opinion). The only way I know of to create a menu on a canvas, is the one like in the example. So let me put some example code here:

DB test = centered ("Hallo");

void draw(DBE art){

} 

string entries[] = {"Size", ">Small", ">Normal", ">Large",
                    "Style", ">Bold", ">Italic"} 
char mn[]        = {'S','m','N','L','t','B','I'} 

char hot[]       = {ddbNone,ddbNone,ddbNone,ddbNone,ddbNone,ddbNone,ddbNone} 

string help[]    = {"Set size","Small fonts","Normal fonts","Large fonts",
                    "Bold font","Set style","Italic font"} 

string inactive[]= {"Never","Never","Never","Never","Never","Never","Never"} 


DBE cv1 = canvas(test, 200, 300, draw) 
DBE cv2 = canvas(test, 200, 300, draw) 


void cb(int nr, int index) {
    infoBox "Menu " help[index] " activated from Canvas " nr "!"
}

void cb1(int index) { cb(0,index) } 
void cb2(int index) { cb(1,index) } 

Sensitivity sensitive(int index) {
    if (index == 2 || index == 6) return ddbChecked
    return ddbAvailable
} 

addMenu(cv1, "Format", 'F', entries, mn, hot, help, inactive, sensitive, cb1) 
addMenu(cv2, "Format", 'F', entries, mn, hot,help, inactive, sensitive, cb2) 


show test

Does something like this solve your problem? I.e. that you have a callback for all your canvases in which you know which canvas triggered the menu item?

Regards, Mathias

Re: Callback on Canvas, AddMenu and menu parent DBE
jaracic - Thu Jan 30 09:06:12 EST 2014

Mathias Mamsch - Thu Jan 30 08:06:23 EST 2014

Hey Joseph, I am not sure I got what you want. The canvas callback for keyboard and mouse actions does not apply to menus (which is no bug in my opinion). The only way I know of to create a menu on a canvas, is the one like in the example. So let me put some example code here:

DB test = centered ("Hallo");

void draw(DBE art){

} 

string entries[] = {"Size", ">Small", ">Normal", ">Large",
                    "Style", ">Bold", ">Italic"} 
char mn[]        = {'S','m','N','L','t','B','I'} 

char hot[]       = {ddbNone,ddbNone,ddbNone,ddbNone,ddbNone,ddbNone,ddbNone} 

string help[]    = {"Set size","Small fonts","Normal fonts","Large fonts",
                    "Bold font","Set style","Italic font"} 

string inactive[]= {"Never","Never","Never","Never","Never","Never","Never"} 


DBE cv1 = canvas(test, 200, 300, draw) 
DBE cv2 = canvas(test, 200, 300, draw) 


void cb(int nr, int index) {
    infoBox "Menu " help[index] " activated from Canvas " nr "!"
}

void cb1(int index) { cb(0,index) } 
void cb2(int index) { cb(1,index) } 

Sensitivity sensitive(int index) {
    if (index == 2 || index == 6) return ddbChecked
    return ddbAvailable
} 

addMenu(cv1, "Format", 'F', entries, mn, hot, help, inactive, sensitive, cb1) 
addMenu(cv2, "Format", 'F', entries, mn, hot,help, inactive, sensitive, cb2) 


show test

Does something like this solve your problem? I.e. that you have a callback for all your canvases in which you know which canvas triggered the menu item?

Regards, Mathias

Hi Mathias,

Thank you for your response, but I actually already considered (very briefly) that solution but it is not applicable to me because I create dynamically my canvases (The number of canvas, their placement and their content depend on a configuration file.... it is something like a "graphical dashboard generator").

For me the solution comes through using a global variable to define which is the right canvas to consider, but since the set function does not work on a Canvas if a menu has been defined on it, I don't how to proceed...

 

Once again Thank you Matthias.

Joseph

Re: Callback on Canvas, AddMenu and menu parent DBE
Mathias Mamsch - Thu Jan 30 09:25:06 EST 2014

jaracic - Thu Jan 30 09:06:12 EST 2014

Hi Mathias,

Thank you for your response, but I actually already considered (very briefly) that solution but it is not applicable to me because I create dynamically my canvases (The number of canvas, their placement and their content depend on a configuration file.... it is something like a "graphical dashboard generator").

For me the solution comes through using a global variable to define which is the right canvas to consider, but since the set function does not work on a Canvas if a menu has been defined on it, I don't how to proceed...

 

Once again Thank you Matthias.

Joseph

From a very brief test, It seems you can use the hasFocus(DBE) perm to determine from which canvas the menu was selected. So, store all your canvases in a Skip list and call the hasFocus function on each of them to determine which one is selected. Does this solve your problem? Regards, Mathias

Re: Callback on Canvas, AddMenu and menu parent DBE
jaracic - Thu Jan 30 09:45:37 EST 2014

Mathias Mamsch - Thu Jan 30 09:25:06 EST 2014

From a very brief test, It seems you can use the hasFocus(DBE) perm to determine from which canvas the menu was selected. So, store all your canvases in a Skip list and call the hasFocus function on each of them to determine which one is selected. Does this solve your problem? Regards, Mathias

Hi,

Many thanks !!

Maybe it solves my problem (of course my canvases are in a skip list)... I'll have to test.

Actually I already looked for a hasFocus function, but the IBM reference indicates it only for toolbars

hasFocus Declaration

bool hasFocus(DBE toolbar) Operation

Returns true if the supplied toolbar DBE contains an element that currently has the keyboard focus. Otherwise, returns false. 

But I just found now another function to test :

setGotFocus Declaration

void setGotFocus(DBE element, void callback(DBE element))

DXL Reference Manual

Operation

Sets the callback function to call when element gets input focus. Currently, element must be a list view or tree view on a Windows platform. 

 

... may be the described constrainsts are not so "hard"....

Re: Callback on Canvas, AddMenu and menu parent DBE
Mathias Mamsch - Sun Feb 02 05:48:46 EST 2014

jaracic - Thu Jan 30 09:45:37 EST 2014

Hi,

Many thanks !!

Maybe it solves my problem (of course my canvases are in a skip list)... I'll have to test.

Actually I already looked for a hasFocus function, but the IBM reference indicates it only for toolbars

hasFocus Declaration

bool hasFocus(DBE toolbar) Operation

Returns true if the supplied toolbar DBE contains an element that currently has the keyboard focus. Otherwise, returns false. 

But I just found now another function to test :

setGotFocus Declaration

void setGotFocus(DBE element, void callback(DBE element))

DXL Reference Manual

Operation

Sets the callback function to call when element gets input focus. Currently, element must be a list view or tree view on a Windows platform. 

 

... may be the described constrainsts are not so "hard"....

Never trust the DXL manual 100% ;-) Always try out stuff ... As I said from a brief check with the above code it seemed to work fine on the canvas. Regards, Mathias