On Saturday 24 March 2001 08:37, Kalle Dalheimer wrote:
> Hi,
>
> I have converted the first dialog, the Copyright dialog in the Qt2 frontend
> to the new MVC architecture (ok, so it's not the most sophisticated dialog
-
> that's why I started with that one). I have a memory-related crash at the
> end, that's probably because the dialog is currently deleted prematurely, I
> can fix that.
>
> But I would need some help on what the control flow is when the user clicks
> on a button. The xforms frontend has some nasty looking callbacks that I do
> not really seem to grasp.
>
> If somebody (Angus?) could give me a short description ("if the user clicks
> OK, the code goes here, here, here, and here"), I would be very grateful
(or
> point me to a document, if there is any; the GUII description did not cover
> this).
Note that I have introduced a bug with one of my last commits so that I can't
create a new (say citation) inset. Will sort that out now. Also the xforms
citation dialog takes an age to build the first time it is shown. No doubt
I've done something stupid!
I've put the description below in controllers/README.
How the code works.
===============
I'll describe Inset-type dialogs (eg, the Citation dialog). Non-inset-type
dialogs (eg the Document dialog) have similar flow, but the important
controller functions are to be found in ControlDialogs.h, not ControlInset.h.
Let's use the citation dialog as an example.
The dialog is launched by :
a) clicking on an existing inset, emitting the showCitation() (Dialogs.h)
signel, connected to the showInset() slot (controllers/ControlInset.h).
b) request a new inset (eg from the menubar), emitting a createCitation()
signal (Dialogs.h) connected to the createInset() slot
(controllers/ControlInset.h).
The user presses the Ok, Apply, Cancel or Restore buttons. In xforms these
are connected to the button controller (xforms/FormCitation.C: build)so:
bc().setOK(dialog_->button_ok);
bc().setApply(dialog_->button_apply);
bc().setCancel(dialog_->button_cancel);
bc().setUndoAll(dialog_->button_restore);
The button controller alters the state of the buttons (active/inactive).
xforms works by callbacks, so clicking on say the button_ok button causes a
callback event to (see FormBase.C)
extern "C" void C_FormBaseOKCB(FL_OBJECT * ob, long)
{
GetForm(ob)->OKButton();
}
GetForm() extracts the actual instance of FormCitation that caused the event
and calls OKButton() (see controllers/ViewBase.h) which in turn calls the
controller's OKButton method. (The ViewBase method exists only because :
/** These shortcuts allow (e.g. xform's) global callback functions
access to the buttons without making the whole controller_ public. */
So, ultimately, pressing button_ok on the Citation dialog calls
ControlBase::OKButton().
void ControlBase::OKButton()
{
apply();
hide();
bc().ok();
}
apply() and hide() are pure virtual methods, instantiated in ControlInset.h
because the Citation dialog is an inset dialog and all insets are
functionally identical.
template <class Inset, class Params>
void ControlInset<Inset, Params>::apply()
{
if (lv_.buffer()->isReadonly() || !inset_)
return;
view().apply();
if (inset_) {
if (params() != getParams(*inset_))
applyParamsToInset();
} else
applyParamsNoInset();
}
applyParamsToInset() and applyParamsNoInset(); are to be found in
FormCommand.[Ch] because the citation inset is derived from InsetCommand and
this subset of insets have identical internal structure and so the params can
be applied in the same way.
The tour ends here!
Best wishes,
Angus