00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 @import <Foundation/CPArray.j>
00024 @import <Foundation/CPObject.j>
00025
00026 #include "CPDOMDisplayServer.h"
00027
00028
00029 @implementation CPDOMWindowLayer : CPObject
00030 {
00031 int _level;
00032 CPArray _windows;
00033 DOMElement _DOMElement;
00034 }
00035
00036 - (id)initWithLevel:(int)aLevel
00037 {
00038 self = [super init];
00039
00040 if (self)
00041 {
00042 _level = aLevel;
00043
00044 _windows = [];
00045
00046 _DOMElement = document.createElement("div");
00047 _DOMElement.style.position = "absolute";
00048 _DOMElement.style.top = "0px";
00049 _DOMElement.style.left = "0px";
00050 _DOMElement.style.width = "1px";
00051 _DOMElement.style.height = "1px";
00052 }
00053
00054 return self;
00055 }
00056
00057 - (int)level
00058 {
00059 return _level;
00060 }
00061
00062 - (void)removeWindow:(CPWindow)aWindow
00063 {
00064 if (!aWindow._isVisible)
00065 return;
00066
00067 var index = aWindow._index,
00068 count = _windows.length - 1;
00069
00070 CPDOMDisplayServerRemoveChild(_DOMElement, aWindow._DOMElement);
00071
00072 [_windows removeObjectAtIndex:aWindow._index];
00073
00074 for (; index < count; ++index)
00075 {
00076 _windows[index]._index = index;
00077 _windows[index]._DOMElement.style.zIndex = index;
00078 }
00079
00080 aWindow._isVisible = NO;
00081 }
00082
00083 - (void)insertWindow:(CPWindow)aWindow atIndex:(unsigned)anIndex
00084 {
00085
00086 var count = [_windows count],
00087 zIndex = (anIndex == CPNotFound ? count : anIndex),
00088 isVisible = aWindow._isVisible;
00089
00090
00091 if (isVisible)
00092 {
00093 zIndex = MIN(zIndex, aWindow._index);
00094 [_windows removeObjectAtIndex:aWindow._index];
00095 }
00096 else
00097 ++count;
00098
00099 if (anIndex == CPNotFound || anIndex >= count)
00100 [_windows addObject:aWindow];
00101 else
00102 [_windows insertObject:aWindow atIndex:anIndex];
00103
00104
00105 for (; zIndex < count; ++zIndex)
00106 {
00107 _windows[zIndex]._index = zIndex;
00108 _windows[zIndex]._DOMElement.style.zIndex = zIndex;
00109 }
00110
00111 if (!isVisible)
00112 {
00113 CPDOMDisplayServerAppendChild(_DOMElement, aWindow._DOMElement);
00114
00115 aWindow._isVisible = YES;
00116
00117 if ([aWindow isFullBridge])
00118 [aWindow setFrame:[aWindow._bridge visibleFrame]];
00119 }
00120 }
00121
00122 - (CPArray)orderedWindows
00123 {
00124 return _windows;
00125 }
00126
00127 @end