When a PtWindow is built with these resources set:
Ph_WM_RENDER_TITLE, Ph_WM_RENDER_CLOSE, and Ph_WM_CLOSE
you get the friendly red X in the window’s upper right hand corner.
Click on it and the window closes as expected.
Question: What is the built-in callback that accomplishes this? Code
details, if possible.
When you click on the Close button, the window manager sends a
Ph_WM_CLOSE event to the application. PtWindow’s event handler checks
the widget’s managed flags and if Ph_WM_CLOSE is set, it either closes
the window using PtDestroyWidget(), or exist using PtExit(), depending
on whether that was the application’s last window.
Background for the curious:
I’m implementing a PhAB application that has compiled-in windows but
also invokes another widget from a DLL using the dlopen() and dlsym()
We need a much larger “close window” button because user will probably
be wearing gloves. In the main app, I use a big button whose
“activate” callback is the handy “Done:” or “Cancel” option. But
when trying to implement such a button in the DLL-based window, the
“Done” callback closes everything. However, the “native” close
widget (little red X, upper RH corner) works as I would like.
Do you mean the Done callback causes the entire application to exit? It
should only do that when the button is in the base window. Is it?
If you want the callback to just close the window, and it indeed is a
base window, use a Cancel callback instead. Or just a code callback
that calls PtDestroyWidget(). Keep in mind that if you destroy your
base window, the library may pick a window module that you subsequently
open, and consider it a new base window. The rules for when it happens
are somewhat convoluted.
Even more detail:
I tried implementing a big-close-button callback using
PtForwardWindowEvent() with an event of Ph_WM_CLOSE after finding the
region ID of the button’s parent window. This did not work in the
DLL-based window. A variation of this technique (Ph_WM_HELP) used in
the main PhAB app does work – but, again, not in my DLL widget.
Since all the code involved is running within the process that owns the
window, the best way to close the window is by calling
PtDestroyWidget(). Forwarding a Ph_WM_CLOSE event means asking PWM to
politely ask the owner of the window to close it, possibly involving an
“Are you sure” dialog; if the window is yours and you know you want to
close it, there’s no need to ask pwm to ask you.