| 1 | /* $Id: win32wndchild.cpp,v 1.1 1999-07-16 11:32:09 sandervl Exp $ */
|
|---|
| 2 | /*
|
|---|
| 3 | * Win32 Child/Parent window class for OS/2
|
|---|
| 4 | *
|
|---|
| 5 | *
|
|---|
| 6 | * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
|
|---|
| 7 | *
|
|---|
| 8 | *
|
|---|
| 9 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 10 | *
|
|---|
| 11 | */
|
|---|
| 12 | #include <os2win.h>
|
|---|
| 13 | #include <win32wndchild.h>
|
|---|
| 14 | #include <misc.h>
|
|---|
| 15 |
|
|---|
| 16 | //******************************************************************************
|
|---|
| 17 | //******************************************************************************
|
|---|
| 18 | ChildWindow::ChildWindow()
|
|---|
| 19 | {
|
|---|
| 20 | parent = 0;
|
|---|
| 21 | nextchild = 0;
|
|---|
| 22 | children = 0;
|
|---|
| 23 | }
|
|---|
| 24 | //******************************************************************************
|
|---|
| 25 | //******************************************************************************
|
|---|
| 26 | ChildWindow::~ChildWindow()
|
|---|
| 27 | {
|
|---|
| 28 | if(parent) {
|
|---|
| 29 | parent->RemoveChild(this);
|
|---|
| 30 | }
|
|---|
| 31 | if(children != 0) {
|
|---|
| 32 | dprintf(("ChildWindow::~ChildWindow children not yet destroyed!!"));
|
|---|
| 33 | DestroyChildren();
|
|---|
| 34 | }
|
|---|
| 35 | }
|
|---|
| 36 | //******************************************************************************
|
|---|
| 37 | //LIFO insertion
|
|---|
| 38 | //******************************************************************************
|
|---|
| 39 | BOOL ChildWindow::AddChild(ChildWindow *child)
|
|---|
| 40 | {
|
|---|
| 41 | mutex.enter();
|
|---|
| 42 |
|
|---|
| 43 | child->SetNextChild(children);
|
|---|
| 44 | children = child;
|
|---|
| 45 |
|
|---|
| 46 | mutex.leave();
|
|---|
| 47 | return TRUE;
|
|---|
| 48 | }
|
|---|
| 49 | //******************************************************************************
|
|---|
| 50 | //Remove child from linked list. Doesn't delete it!
|
|---|
| 51 | //******************************************************************************
|
|---|
| 52 | BOOL ChildWindow::RemoveChild(ChildWindow *child)
|
|---|
| 53 | {
|
|---|
| 54 | ChildWindow *curchild = children;
|
|---|
| 55 |
|
|---|
| 56 | mutex.enter();
|
|---|
| 57 |
|
|---|
| 58 | if(curchild == child) {
|
|---|
| 59 | children = child->GetNextChild();
|
|---|
| 60 | }
|
|---|
| 61 | else {
|
|---|
| 62 | if(curchild == NULL) {
|
|---|
| 63 | dprintf(("ChildWindow::RemoveChild, children == NULL"));
|
|---|
| 64 | DebugInt3();
|
|---|
| 65 | mutex.leave();
|
|---|
| 66 | return FALSE;
|
|---|
| 67 | }
|
|---|
| 68 | while(curchild->GetNextChild() != child) {
|
|---|
| 69 | curchild = curchild->GetNextChild();
|
|---|
| 70 | if(curchild == NULL) {
|
|---|
| 71 | dprintf(("ChildWindow::RemoveChild, curchild == NULL"));
|
|---|
| 72 | DebugInt3();
|
|---|
| 73 | mutex.leave();
|
|---|
| 74 | return FALSE;
|
|---|
| 75 | }
|
|---|
| 76 | }
|
|---|
| 77 | curchild->SetNextChild(child->GetNextChild());
|
|---|
| 78 | }
|
|---|
| 79 | mutex.leave();
|
|---|
| 80 | return TRUE;
|
|---|
| 81 | }
|
|---|
| 82 | //******************************************************************************
|
|---|
| 83 | //******************************************************************************
|
|---|
| 84 | BOOL ChildWindow::DestroyChildren()
|
|---|
| 85 | {
|
|---|
| 86 | while(children) {
|
|---|
| 87 | delete children; //child dtor removes itself from the linked list
|
|---|
| 88 | }
|
|---|
| 89 | return TRUE;
|
|---|
| 90 | }
|
|---|
| 91 | //******************************************************************************
|
|---|
| 92 | //******************************************************************************
|
|---|