| 1 | /* $Id: win32wndchild.cpp,v 1.7 2001-06-09 14:50:24 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 | #define DBG_LOCALLOG    DBG_win32wndchild | 
|---|
| 17 | #include "dbglocal.h" | 
|---|
| 18 |  | 
|---|
| 19 | //****************************************************************************** | 
|---|
| 20 | //****************************************************************************** | 
|---|
| 21 | ChildWindow::ChildWindow(CRITICAL_SECTION *pLock) | 
|---|
| 22 | { | 
|---|
| 23 | parent     = 0; | 
|---|
| 24 | nextchild  = 0; | 
|---|
| 25 | children   = 0; | 
|---|
| 26 | pLockChild = pLock; | 
|---|
| 27 | } | 
|---|
| 28 | //****************************************************************************** | 
|---|
| 29 | //****************************************************************************** | 
|---|
| 30 | ChildWindow::~ChildWindow() | 
|---|
| 31 | { | 
|---|
| 32 | if(parent) { | 
|---|
| 33 | parent->removeChild(this); | 
|---|
| 34 | } | 
|---|
| 35 | //SvL: PM sends WM_DESTROY for all the children | 
|---|
| 36 | #if 0 | 
|---|
| 37 | if(children != 0) { | 
|---|
| 38 | dprintf(("ChildWindow::~ChildWindow children not yet destroyed!!")); | 
|---|
| 39 | DestroyChildren(); | 
|---|
| 40 | } | 
|---|
| 41 | #endif | 
|---|
| 42 | } | 
|---|
| 43 | //****************************************************************************** | 
|---|
| 44 | //FIFO insertion | 
|---|
| 45 | //****************************************************************************** | 
|---|
| 46 | BOOL ChildWindow::addChild(ChildWindow *child) | 
|---|
| 47 | { | 
|---|
| 48 | ChildWindow *curchild; | 
|---|
| 49 |  | 
|---|
| 50 | Lock(); | 
|---|
| 51 |  | 
|---|
| 52 | curchild = children; | 
|---|
| 53 | if(curchild == NULL) { | 
|---|
| 54 | children = child; | 
|---|
| 55 | } | 
|---|
| 56 | else { | 
|---|
| 57 | while(curchild->getNextChild()) { | 
|---|
| 58 | curchild = curchild->getNextChild(); | 
|---|
| 59 | } | 
|---|
| 60 | curchild->setNextChild(child); | 
|---|
| 61 | } | 
|---|
| 62 | child->setNextChild(NULL); | 
|---|
| 63 |  | 
|---|
| 64 | Unlock(); | 
|---|
| 65 | return TRUE; | 
|---|
| 66 | } | 
|---|
| 67 | //****************************************************************************** | 
|---|
| 68 | //Remove child from linked list. Doesn't delete it! | 
|---|
| 69 | //****************************************************************************** | 
|---|
| 70 | BOOL ChildWindow::removeChild(ChildWindow *child) | 
|---|
| 71 | { | 
|---|
| 72 | ChildWindow *curchild = children; | 
|---|
| 73 |  | 
|---|
| 74 | Lock(); | 
|---|
| 75 |  | 
|---|
| 76 | if(curchild == child) { | 
|---|
| 77 | children = child->getNextChild(); | 
|---|
| 78 | } | 
|---|
| 79 | else { | 
|---|
| 80 | if(curchild == NULL) { | 
|---|
| 81 | dprintf(("ChildWindow::RemoveChild, children == NULL")); | 
|---|
| 82 | DebugInt3(); | 
|---|
| 83 | Unlock(); | 
|---|
| 84 | return FALSE; | 
|---|
| 85 | } | 
|---|
| 86 | while(curchild->getNextChild() != child) { | 
|---|
| 87 | curchild = curchild->getNextChild(); | 
|---|
| 88 | if(curchild == NULL) { | 
|---|
| 89 | dprintf(("ChildWindow::RemoveChild, curchild == NULL")); | 
|---|
| 90 | DebugInt3(); | 
|---|
| 91 | Unlock(); | 
|---|
| 92 | return FALSE; | 
|---|
| 93 | } | 
|---|
| 94 | } | 
|---|
| 95 | curchild->setNextChild(child->getNextChild()); | 
|---|
| 96 | } | 
|---|
| 97 | Unlock(); | 
|---|
| 98 | return TRUE; | 
|---|
| 99 | } | 
|---|
| 100 | //****************************************************************************** | 
|---|
| 101 | //****************************************************************************** | 
|---|
| 102 | BOOL ChildWindow::destroyChildren() | 
|---|
| 103 | { | 
|---|
| 104 | while(children) { | 
|---|
| 105 | delete children;        //child dtor removes itself from the linked list | 
|---|
| 106 | } | 
|---|
| 107 | return TRUE; | 
|---|
| 108 | } | 
|---|
| 109 | //****************************************************************************** | 
|---|
| 110 | //****************************************************************************** | 
|---|