|
|
Home » Developing U++ » U++ Developers corner » Proposed change to U++ to allow owning children.
Re: Proposed change to U++ to allow owning children. [message #31641 is a reply to message #31638] |
Fri, 18 March 2011 16:22   |
Lance
Messages: 656 Registered: March 2007
|
Contributor |
|
|
Now we have a much cleaner solution thanks to Kohait00's input.
Brief list of changes to the current libary code:
In CtrlCore.h
Added to Ctrl class
bool owned : 1;
And 2 public members
bool IsOwned()const{ return owned; }
Ctrl& Owned(bool v=true){ owned=v; return *this; }
In Ctrl.cpp, initialized owned flag to false
Ctrl::Ctrl() {
GuiLock __;
LLOG("Ctrl::Ctrl");
destroying = false;
owned = false; // <-----This line is added
parent = prev = next = firstchild = lastchild = NULL;
top = NULL;
exitcode = 0;
frame.Add().frame = &NullFrame();
enabled = visible = wantfocus = initfocus = true;
editable = true;
// GLX = false;
#ifdef PLATFORM_WIN32
activex = false;
isdhctrl = false;
#endif
backpaint = IsCompositedGui() ? FULLBACKPAINT : TRANSPARENTBACKPAINT;
inframe = false;
ignoremouse = transparent = false;
caretcx = caretcy = caretx = carety = 0;
SetRect(Rect(0, 0, 0, 0));
inloop = popup = isopen = false;
modify = false;
unicode = false;
popupgrab = false;
fullrefresh = false;
akv = false;
hasdhctrl = false;
}
And in CtrlChild.cpp
// @param: q , the child to be added
// q, an existing child to precede p
void Ctrl::AddChild(Ctrl *q, Ctrl *p)
{
GuiLock __;
ASSERT(q);
LLOG("Add " << UPP::Name(q) << " to: " << Name());
if(p == q) return;
bool updaterect = true;
// remember and change
bool owned=q->owned;
q->Owned(false); // that way it's guarenteed not to be
// accidently delete'd when possibly changing parents
if(q->parent) {
ASSERT(!q->inframe);
if(q->parent == this) {
RemoveChild0(q);
updaterect = false;
}
else
q->parent->RemoveChild(q);
}
q->parent = this;
if(p) {
ASSERT(p->parent == this);
q->prev = p;
q->next = p->next;
if(p == lastchild)
lastchild = q;
else
p->next->prev = q;
p->next = q;
}
else
if(firstchild) {
q->prev = NULL;
q->next = firstchild;
firstchild->prev = q;
firstchild = q;
}
else {
ASSERT(lastchild == NULL);
firstchild = lastchild = q;
q->prev = q->next = NULL;
}
// succesfully added as children of *this, now
// it's perfect time to restore saved owned flag
q->Owned(owned);
q->CancelModeDeep();
if(updaterect)
q->UpdateRect();
ChildAdded(q);
q->ParentChange();
if(updaterect && GetTopCtrl()->IsOpen())
q->StateH(OPEN);
if(dynamic_cast<DHCtrl *>(q))
SyncDHCtrl();
}
.....
void Ctrl::RemoveChild0(Ctrl *q)
{
GuiLock __;
ChildRemoved(q);
q->DoRemove();
q->parent = NULL;
if(q == firstchild)
firstchild = firstchild->next;
if(q == lastchild)
lastchild = lastchild->prev;
if(q->prev)
q->prev->next = q->next;
if(q->next)
q->next->prev = q->prev;
q->next = q->prev = NULL;
if(dynamic_cast<DHCtrl *>(q))
SyncDHCtrl();
// code added to allowed owned child****
if(q->owned)
delete q;
// end code added by Lance
}
void Ctrl::RemoveChild(Ctrl *q)
{
GuiLock __;
if(q->parent != this) return;
q->RefreshFrame();
bool owned=q->IsOwned();
q->Owned(false); // we still need it to be alive
RemoveChild0(q);
q->ParentChange();
if(GetTopCtrl()->IsOpen())
q->StateH(CLOSE);
if( owned )
{
delete q; // this is why the new'd-only requirement.
}
// no need to restore q's owned flag, it's either destroyed or
// its owned flag is correctly set
}
-
Attachment: CtrlCore.rar
(Size: 20.38KB, Downloaded 338 times)
|
|
|
 |
|
Proposed change to U++ to allow owning children.
By: Lance on Wed, 16 March 2011 17:18
|
 |
|
Re: Proposed change to U++ to allow owning children.
By: kohait00 on Wed, 16 March 2011 17:26
|
 |
|
Re: Proposed change to U++ to allow owning children.
By: Lance on Wed, 16 March 2011 17:29
|
 |
|
Re: Proposed change to U++ to allow owning children.
By: Lance on Wed, 16 March 2011 17:30
|
 |
|
Re: Proposed change to U++ to allow owning children.
By: Lance on Wed, 16 March 2011 17:39
|
 |
|
Re: Proposed change to U++ to allow owning children.
By: kohait00 on Wed, 16 March 2011 18:01
|
 |
|
Re: Proposed change to U++ to allow owning children.
By: Lance on Wed, 16 March 2011 18:10
|
 |
|
Re: Proposed change to U++ to allow owning children.
By: Lance on Wed, 16 March 2011 18:29
|
 |
|
Re: Proposed change to U++ to allow owning children.
By: Lance on Wed, 16 March 2011 18:35
|
 |
|
Re: Proposed change to U++ to allow owning children.
By: Lance on Wed, 16 March 2011 18:43
|
 |
|
Re: Proposed change to U++ to allow owning children.
By: Lance on Wed, 16 March 2011 19:24
|
 |
|
Re: Proposed change to U++ to allow owning children.
By: Lance on Fri, 18 March 2011 02:13
|
 |
|
Re: Proposed change to U++ to allow owning children.
By: kohait00 on Fri, 18 March 2011 11:01
|
 |
|
Re: Proposed change to U++ to allow owning children.
By: Lance on Fri, 18 March 2011 14:39
|
 |
|
Re: Proposed change to U++ to allow owning children.
By: Lance on Fri, 18 March 2011 15:21
|
 |
|
Re: Proposed change to U++ to allow owning children.
By: Lance on Fri, 18 March 2011 15:40
|
 |
|
Re: Proposed change to U++ to allow owning children.
By: Lance on Fri, 18 March 2011 16:22
|
 |
|
Re: Proposed change to U++ to allow owning children.
By: Lance on Fri, 18 March 2011 16:34
|
 |
|
Re: Proposed change to U++ to allow owning children.
By: mirek on Fri, 18 March 2011 19:35
|
 |
|
Re: Proposed change to U++ to allow owning children.
By: mirek on Fri, 18 March 2011 19:32
|
 |
|
Re: Proposed change to U++ to allow owning children.
By: Lance on Fri, 18 March 2011 23:02
|
 |
|
Re: Proposed change to U++ to allow owning children.
By: mirek on Fri, 18 March 2011 23:18
|
 |
|
Re: Proposed change to U++ to allow owning children.
By: Lance on Fri, 18 March 2011 23:34
|
 |
|
Re: Proposed change to U++ to allow owning children.
By: mirek on Fri, 18 March 2011 23:40
|
 |
|
Re: Proposed change to U++ to allow owning children.
By: Lance on Sat, 19 March 2011 00:02
|
 |
|
Re: Proposed change to U++ to allow owning children.
By: mirek on Sat, 19 March 2011 00:37
|
 |
|
Re: Proposed change to U++ to allow owning children.
By: Lance on Sat, 19 March 2011 01:30
|
 |
|
Re: Proposed change to U++ to allow owning children.
By: Lance on Sat, 19 March 2011 01:35
|
 |
|
Re: Proposed change to U++ to allow owning children.
By: mirek on Sat, 19 March 2011 10:59
|
 |
|
Re: Proposed change to U++ to allow owning children.
By: kohait00 on Sun, 20 March 2011 10:32
|
 |
|
Re: Proposed change to U++ to allow owning children.
By: Lance on Sun, 20 March 2011 14:07
|
 |
|
Re: Proposed change to U++ to allow owning children.
By: Lance on Sun, 20 March 2011 14:11
|
 |
|
Re: Proposed change to U++ to allow owning children.
By: Lance on Sun, 20 March 2011 14:28
|
 |
|
Re: Proposed change to U++ to allow owning children.
By: kohait00 on Fri, 25 March 2011 13:26
|
 |
|
Re: Proposed change to U++ to allow owning children.
By: Lance on Sun, 27 March 2011 15:33
|
 |
|
Re: Proposed change to U++ to allow owning children.
By: kohait00 on Sun, 17 April 2011 17:25
|
 |
|
Re: Proposed change to U++ to allow owning children.
By: Lance on Tue, 19 April 2011 06:00
|
 |
|
Re: Proposed change to U++ to allow owning children.
By: kohait00 on Tue, 19 April 2011 09:14
|
 |
|
Re: Proposed change to U++ to allow owning children.
By: Lance on Tue, 19 April 2011 14:09
|
 |
|
Re: Proposed change to U++ to allow owning children.
By: kohait00 on Tue, 19 April 2011 18:05
|
 |
|
Re: Proposed change to U++ to allow owning children.
By: Lance on Wed, 20 April 2011 02:44
|
 |
|
Re: Proposed change to U++ to allow owning children.
By: kohait00 on Wed, 20 April 2011 08:51
|
 |
|
Re: Proposed change to U++ to allow owning children.
By: Lance on Wed, 20 April 2011 19:24
|
 |
|
Re: Proposed change to U++ to allow owning children.
By: Lance on Wed, 20 April 2011 21:17
|
 |
|
Re: Proposed change to U++ to allow owning children.
By: Lance on Wed, 20 April 2011 21:23
|
 |
|
Re: Proposed change to U++ to allow owning children.
By: Lance on Wed, 20 April 2011 21:38
|
 |
|
Re: Proposed change to U++ to allow owning children.
By: kohait00 on Thu, 28 April 2011 16:32
|
 |
|
revised ownership change
By: kohait00 on Thu, 28 April 2011 18:28
|
 |
|
Re: revised ownership change
By: Lance on Thu, 28 April 2011 21:45
|
 |
|
Re: revised ownership change
By: kohait00 on Thu, 28 April 2011 21:57
|
 |
|
Re: revised ownership change
By: Lance on Thu, 28 April 2011 23:18
|
 |
|
Re: revised ownership change
By: Lance on Thu, 28 April 2011 23:31
|
 |
|
Re: revised ownership change
By: Lance on Thu, 28 April 2011 23:54
|
 |
|
Re: revised ownership change
|
 |
|
Re: revised ownership change
|
 |
|
Re: revised ownership change
|
 |
|
Re: revised ownership change
By: Lance on Mon, 06 June 2011 05:11
|
 |
|
Re: revised ownership change
By: Lance on Mon, 06 June 2011 05:05
|
Goto Forum:
Current Time: Tue Jul 01 11:01:25 CEST 2025
Total time taken to generate the page: 0.04045 seconds
|
|
|