Date: Wed, 22 Feb 95 13:08:52 CST From: brian@lim.com (Brian G. Benton) To: oi-users@freefall.cdrom.com Cc: brian@lim.com Subject: Problems with unparent() and layout_associated_object() Message-ID: <9502221908.AA01220@limbgb.lim.com>
index | next in thread | raw e-mail
I have some questions concerning unparent(), layout_associated_object(),
and Modal Dialogs. Thanks.
My hierarchy:
OI_dialog -> Dialog -> ModalDialog -> AttributeDialog (the dialog object below)
-> ModelessDialog
The problem exhibited is the following. I have a modal dialog contains
two OI_box objects. These OI_box objects are retrieved via the call
GetOIIndicatorsSubwindow() and GetOISecuritiesSubwindow(). Only one
of these OI_box objects is visible at any given time. I have an
exclusive check menu (retrieved via GetOISymbolTypeMenu()) that allows
the user to choose which OI_box is currently visible. When the "Securities"
menu cell is selected, the SecuritiesCB() callback member function is called
and proceeds to unparent() the GetOIIndicatorsSubwindow() OI_box while
calling layout_associated_object() on the GetOISecuritiesSubwindow() OI_box.
When the "Indicators & Misc." cell is selected, the opposite occurs.
This AttributeDialog object is created by an owner class and is invoked by calling
PopupDialog(). PopupDialog() is a virtual member function defined in
both ModalDialog and ModelessDialog. The ModalDialog version calls wait_button()
while the Modeless version calls popup(). Since AttributeDialog is a modal
dialog, wait_button() is called to invoke the dialog. Everything works ok
after the first call to wait_button(). The two OI_boxes can be unparented
and re-installed (layout_associated_object()) successfully. The problem arises
after the dialog is brought down and an OI_box has been reassigned to the
orphanage.
If the dialog is brought back up again and one of the OI_box objects was
unparented in the previous invocation and LEFT THAT WAY WHEN THE DIALOG
WAS BROUGHT DOWN, the child objects of that OI_box are inactive (but visible)
once that OI_box is re-installed in the latest invocation of the dialog.
I attempted to solve this problem by writing the LayoutObject() member
function below. It not only calls layout_associated_object() but also
sets the state for each child object. Thus I can then interact with
my child objects. It works for child objects of the OI_box.
But my scroll_menu still has its menu cells inactive
because they are not children of the OI_box. I could rewrite this method to
account for all descendants, but we are getting to
be real innefficient as my scroll list has a plethora of menu cells.
There must be a better way.
As a side note, dies anyone know why the destructor for OI_menu declared as non virtual
protected? I have some OI_menu objects (OI_scroll_menu, OI_excl_check_menu, etc.)
that I had declared as OI_menu objects in order to be generic as possible.
However, when I go to delete this objects in the destructor, I don't
have access to the destructor. Hence, I must declare them as OI_scroll_menu
objects. I suspect that delete_all() might do the trick, but it seems like
you should be able to use the C++ delete operator. I need to delete the
objects in my destructor because I don't want the objects to be declared as
internal objects (where OI will automatically delete them). The allow_internal_object()
call causes adverse effects on the objects for which it is called.
Ex. I override the set_state() method in OI_d_tech so that it sets the
state not only on the object for which it is called, but for its child
objects as well. If allow_internal_object() is called on a particular
child object, the set_state() method will not get called on that object.
Hence, I don't use allow_internal_object() (another OI bug).
Also, if I use the C++ operator delete() on an OI object (ex. scroll menu),
will its menu cells get deleted? If I call the C++ operator delete() on
an OI_box, will its children get deleted? Or do they have to be set as
internal objects?
The following are snippets of code concerning the unparent() and
layout_associated_object() problems.
// This callback installs the Indicators OI_box and uninstalls
// the Securities OI_box.
void
AttributeDialog::IndicatorsCB(OI_menu_cell *cell,
void *,
OI_number)
{
if (!cell->selected())
return;
if (!GetOIIndicatorsSubwindow()) {
GetParent()->set_working();
SetOIIndicatorsSubwindow(CreateOIIndicatorsSubwindow("indicators_subwindow"));
GetParent()->clear_working();
}
freeze();
// Make sure that the ColumnsSubwindow is not visible since it makes
// no sense in this context.
if (GetOIColumnsSubwindow())
GetOIColumnsSubwindow()->unparent();
// Unparent SecuritiesSubwindow if it exists
if (GetOISecuritiesSubwindow())
GetOISecuritiesSubwindow()->unparent();
if (!GetOIIndicatorsSubwindow()->is_laid_out_child())
LayoutObject(GetOIIndicatorsSubwindow(),
20,
60,
OI_active);
/*
GetOIIndicatorsSubwindow()->layout_associated_object(this,
(OI_number) 20, // Column
(OI_number) 60, // Row
OI_active);
*/
unfreeze();
} /* IndicatorsCB() */
void
AttributeDialog::LayoutObject(OI_d_tech *object,
OI_number column,
OI_number row,
OI_state state)
{
OI_d_tech *child = NULL;
object->layout_associated_object(this,
column,
row,
state);
while(child = object->next_child(child))
child->set_state(state);
} /* LayoutObject() */
// This callback installs the Securities OI_box and uninstalls
// the Indicators OI_box.
void
AttributeDialog::SecuritiesCB(OI_menu_cell *cell,
void *,
OI_number)
{
if (!cell->selected())
return;
freeze();
// Make sure that the ColumnsSubwindow is not visible. It will become visible
// once again when a security is selected.
if (GetOIColumnsSubwindow())
GetOIColumnsSubwindow()->unparent();
// Unparent IndicatorsSubwindow if it exists
if (GetOIIndicatorsSubwindow())
GetOIIndicatorsSubwindow()->unparent();
if (!GetOISecuritiesSubwindow()->is_laid_out_child())
LayoutObject(GetOISecuritiesSubwindow(),
20,
60,
OI_active);
/*
GetOISecuritiesSubwindow()->layout_associated_object(this,
(OI_number) 20, // Column
(OI_number) 60, // Row
OI_active);
*/
unfreeze();
} /* SecuritiesCB() */
Thanks,
+----------------------------------------------------------------------------+
| Brian Benton | Phone: (512) 346-5464 x21 |
| Sr. MTS | Fax: (512) 346-5386 |
| LIM International | Email: brian@lim.com |
| 9390 Research Blvd., Kaleido II, #300 |------------------------------------|
| Austin, TX 78759 | GO BRONCOS! GEAUX CAJUNS! |
+----------------------------------------------------------------------------+
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?9502221908.AA01220>
