|
View:
New views
6 Messages
—
Rating Filter:
Alert me
|
|
|
What the usage of tryHandle and handleHello all, What the usage of tryHandle and handle is? And, when I should use it? // Somebody wants our the selection long FXWindow::onSelectionRequest(FXObject*,FXSelector,void* ptr){ return target && target->tryHandle(this,FXSEL(SEL_SELECTION_REQUEST,message),ptr); } // Update Alpha text fields long FXColorSelector::onUpdAlphaText(FXObject* sender,FXSelector,void*){ FXString value; if(isOpaqueOnly()){ sender->handle(this,FXSEL(SEL_COMMAND,ID_HIDE),NULL); } else{ ... } return 1; } Thank you -Feng ------------------------------------------------------------------------------ _______________________________________________ Foxgui-users mailing list Foxgui-users@... https://lists.sourceforge.net/lists/listinfo/foxgui-users |
|
|
Re: What the usage of tryHandle and handleOn Tuesday 23 June 2009, Feng Feng wrote:
> Hello all, > > What the usage of tryHandle and handle is? All the widgets call the handlers through tryHandle(), not handle(). The reason is that we don't know what the handler code does; it MAY throw an exception. If it does throw an exception, tryHandle() catches the exception and then returns normally. Why is this done? Because the logic of many widgets requires that code surrounding the target->tryHandle() gets executed, in order to leave the widget in a known state. If we were to let an exception unroll without executing the surrounding code, we'd risk leaving the widget in an intermediate state, and this would typically cause problems later on. At any rate, the idea is that prior to calling the handler, everything was still OK, and thus trapping off the exception would be simply picking things up at the last known-good state anyway. Putting it in other words: if there is something you'd want to do when an exception is thrown, you'd better do it prior to returning from the handler, or FOX will do the exception processing for you. The exception [pun intended] is we're only doing this with exceptions derived from FXException. Other types of exceptions are not caught by FOX, and would typically cause your application to simply bomb. - Jeroen ------------------------------------------------------------------------------ _______________________________________________ Foxgui-users mailing list Foxgui-users@... https://lists.sourceforge.net/lists/listinfo/foxgui-users |
|
|
Re: What the usage of tryHandle and handleOn Tuesday 23 June 2009, Feng Feng wrote:
> Hello all, > > What the usage of tryHandle and handle is? > > And, when I should use it? > > // Somebody wants our the selection > long FXWindow::onSelectionRequest(FXObject*,FXSelector,void* ptr){ > return target && target->tryHandle(this,FXSEL(SEL_SELECTION_REQUEST,message),ptr); > } > > // Update Alpha text fields > long FXColorSelector::onUpdAlphaText(FXObject* sender,FXSelector,void*){ > FXString value; > if(isOpaqueOnly()){ > sender->handle(this,FXSEL(SEL_COMMAND,ID_HIDE),NULL); > } > else{ > ... > } > return 1; > } To elaborate slightly on the exception issue: When FOX widgets call handlers in YOUR code, we do so with tryHandle(). When YOUR code invokes a update handler in FOX, you can use handle() since FOX won't throw an exception anyway. It is totally OK to call tryHandle() if it pleases you, but it is not necessary... - Jeroen ------------------------------------------------------------------------------ _______________________________________________ Foxgui-users mailing list Foxgui-users@... https://lists.sourceforge.net/lists/listinfo/foxgui-users |
|
|
|
|
|
Re: What the usage of tryHandle and handleOn Jun 23, 2009, at 3:46 PM, Feng Feng wrote:
------------------------------------------------------------------------------ _______________________________________________ Foxgui-users mailing list Foxgui-users@... https://lists.sourceforge.net/lists/listinfo/foxgui-users |
|
|
Re: What the usage of tryHandle and handleOn Tuesday 23 June 2009, Feng Feng wrote:
> Hello Lyle, > > Thank you for your excellent explanation for what the difference is. > > Now, I have one more question related to the usage of the function, > > For the code, > sender->handle(this,FXSEL(SEL_COMMAND,ID_HIDE),NULL); > > Does it mean the following? > > Use sender's handle to deliver the message SEL_COMMAND to object which is created with ID_HIDE. > > If > FXMAPFUNC(SEL_COMMAND, XXX::ID_HIDE, XXX::onHide), > > Then the function onHide will be called. > > Is this correct? Yes, that's correct. All widgets support a few standard messages, like ID_HIDE, ID_SHOW, ID_ENABLE, ID_DISABLE. These messages can be sent back from SEL_UPDATE handlers. Valuator controls like FXSlider also understand messages like ID_INTVALUE, etc. which allows setting value from SEL_UPDATE handlers and FXDataTarget. This is a neat feature because the update handler code doesn't know what kind of widget invoked the handler. Thus, different widget types may get updated by the same handler code. This is basically how FXDataTarget works. - Jeroen ------------------------------------------------------------------------------ _______________________________________________ Foxgui-users mailing list Foxgui-users@... https://lists.sourceforge.net/lists/listinfo/foxgui-users |
| Free embeddable forum powered by Nabble | Forum Help |