internal override IntPtr CreateWindow(CreateParams cp) {
Hwnd hwnd;
Hwnd parent_hwnd = null;
int X;
int Y;
int Width;
int Height;
IntPtr ParentHandle;
IntPtr WindowHandle;
IntPtr WholeWindow;
IntPtr ClientWindow;
IntPtr WholeWindowTracking;
IntPtr ClientWindowTracking;
hwnd = new Hwnd ();
X = cp.X;
Y = cp.Y;
Width = cp.Width;
Height = cp.Height;
ParentHandle = IntPtr.Zero;
WindowHandle = IntPtr.Zero;
WholeWindow = IntPtr.Zero;
ClientWindow = IntPtr.Zero;
WholeWindowTracking = IntPtr.Zero;
ClientWindowTracking = IntPtr.Zero;
if (Width < 1) Width = 1;
if (Height < 1) Height = 1;
if (cp.Parent != IntPtr.Zero) {
parent_hwnd = Hwnd.ObjectFromHandle (cp.Parent);
ParentHandle = parent_hwnd.client_window;
} else {
if (StyleSet (cp.Style, WindowStyles.WS_CHILD)) {
HIViewFindByID (HIViewGetRoot (FosterParent), new Carbon.HIViewID (Carbon.EventHandler.kEventClassWindow, 1), ref ParentHandle);
}
}
Point next;
if (cp.control is Form) {
next = Hwnd.GetNextStackedFormLocation (cp, parent_hwnd);
X = next.X;
Y = next.Y;
}
hwnd.x = X;
hwnd.y = Y;
hwnd.width = Width;
hwnd.height = Height;
hwnd.Parent = Hwnd.ObjectFromHandle (cp.Parent);
hwnd.initial_style = cp.WindowStyle;
hwnd.initial_ex_style = cp.WindowExStyle;
hwnd.visible = false;
if (StyleSet (cp.Style, WindowStyles.WS_DISABLED)) {
hwnd.enabled = false;
}
ClientWindow = IntPtr.Zero;
Size QWindowSize = TranslateWindowSizeToQuartzWindowSize (cp);
Rectangle QClientRect = TranslateClientRectangleToQuartzClientRectangle (hwnd, cp.control);
SetHwndStyles(hwnd, cp);
/* FIXME */
if (ParentHandle == IntPtr.Zero) {
IntPtr WindowView = IntPtr.Zero;
IntPtr GrowBox = IntPtr.Zero;
Carbon.WindowClass windowklass = Carbon.WindowClass.kOverlayWindowClass;
Carbon.WindowAttributes attributes = Carbon.WindowAttributes.kWindowCompositingAttribute | Carbon.WindowAttributes.kWindowStandardHandlerAttribute;
if (StyleSet (cp.Style, WindowStyles.WS_MINIMIZEBOX)) {
attributes |= Carbon.WindowAttributes.kWindowCollapseBoxAttribute;
}
if (StyleSet (cp.Style, WindowStyles.WS_MAXIMIZEBOX)) {
attributes |= Carbon.WindowAttributes.kWindowResizableAttribute | Carbon.WindowAttributes.kWindowHorizontalZoomAttribute | Carbon.WindowAttributes.kWindowVerticalZoomAttribute;
}
if (StyleSet (cp.Style, WindowStyles.WS_SYSMENU)) {
attributes |= Carbon.WindowAttributes.kWindowCloseBoxAttribute;
}
if (StyleSet (cp.Style, WindowStyles.WS_CAPTION)) {
windowklass = Carbon.WindowClass.kDocumentWindowClass;
}
if (hwnd.border_style == FormBorderStyle.FixedToolWindow) {
windowklass = Carbon.WindowClass.kUtilityWindowClass;
} else if (hwnd.border_style == FormBorderStyle.SizableToolWindow) {
attributes |= Carbon.WindowAttributes.kWindowResizableAttribute;
windowklass = Carbon.WindowClass.kUtilityWindowClass;
}
if (windowklass == Carbon.WindowClass.kOverlayWindowClass) {
attributes = Carbon.WindowAttributes.kWindowCompositingAttribute | Carbon.WindowAttributes.kWindowStandardHandlerAttribute;
}
attributes |= Carbon.WindowAttributes.kWindowLiveResizeAttribute;
Carbon.Rect rect = new Carbon.Rect ();
if (StyleSet (cp.Style, WindowStyles.WS_POPUP)) {
SetRect (ref rect, (short)X, (short)(Y), (short)(X + QWindowSize.Width), (short)(Y + QWindowSize.Height));
} else {
SetRect (ref rect, (short)X, (short)(Y + MenuBarHeight), (short)(X + QWindowSize.Width), (short)(Y + MenuBarHeight + QWindowSize.Height));
}
CreateNewWindow (windowklass, attributes, ref rect, ref WindowHandle);
Carbon.EventHandler.InstallWindowHandler (WindowHandle);
HIViewFindByID (HIViewGetRoot (WindowHandle), new Carbon.HIViewID (Carbon.EventHandler.kEventClassWindow, 1), ref WindowView);
HIViewFindByID (HIViewGetRoot (WindowHandle), new Carbon.HIViewID (Carbon.EventHandler.kEventClassWindow, 7), ref GrowBox);
HIGrowBoxViewSetTransparent (GrowBox, true);
SetAutomaticControlDragTrackingEnabledForWindow (WindowHandle, true);
ParentHandle = WindowView;
}
HIObjectCreate (__CFStringMakeConstantString ("com.novell.mwfview"), 0, ref WholeWindow);
HIObjectCreate (__CFStringMakeConstantString ("com.novell.mwfview"), 0, ref ClientWindow);
Carbon.EventHandler.InstallControlHandler (WholeWindow);
Carbon.EventHandler.InstallControlHandler (ClientWindow);
// Enable embedding on controls
HIViewChangeFeatures (WholeWindow, 1<<1, 0);
HIViewChangeFeatures (ClientWindow, 1<<1, 0);
HIViewNewTrackingArea (WholeWindow, IntPtr.Zero, (UInt64)WholeWindow, ref WholeWindowTracking);
HIViewNewTrackingArea (ClientWindow, IntPtr.Zero, (UInt64)ClientWindow, ref ClientWindowTracking);
Carbon.HIRect WholeRect;
if (WindowHandle != IntPtr.Zero) {
WholeRect = new Carbon.HIRect (0, 0, QWindowSize.Width, QWindowSize.Height);
} else {
WholeRect = new Carbon.HIRect (X, Y, QWindowSize.Width, QWindowSize.Height);
}
Carbon.HIRect ClientRect = new Carbon.HIRect (QClientRect.X, QClientRect.Y, QClientRect.Width, QClientRect.Height);
HIViewSetFrame (WholeWindow, ref WholeRect);
HIViewSetFrame (ClientWindow, ref ClientRect);
HIViewAddSubview (ParentHandle, WholeWindow);
HIViewAddSubview (WholeWindow, ClientWindow);
hwnd.WholeWindow = WholeWindow;
hwnd.ClientWindow = ClientWindow;
if (WindowHandle != IntPtr.Zero) {
WindowMapping [hwnd.Handle] = WindowHandle;
HandleMapping [WindowHandle] = hwnd.Handle;
if (hwnd.border_style == FormBorderStyle.FixedToolWindow || hwnd.border_style == FormBorderStyle.SizableToolWindow) {
UtilityWindows.Add (WindowHandle);
}
}
// Allow dnd on controls
Dnd.SetAllowDrop (hwnd, true);
Text (hwnd.Handle, cp.Caption);
SendMessage (hwnd.Handle, Msg.WM_CREATE, (IntPtr)1, IntPtr.Zero /* XXX unused */);
SendParentNotify (hwnd.Handle, Msg.WM_CREATE, int.MaxValue, int.MaxValue);
if (StyleSet (cp.Style, WindowStyles.WS_VISIBLE)) {
if (WindowHandle != IntPtr.Zero) {
if (Control.FromHandle(hwnd.Handle) is Form) {
Form f = Control.FromHandle(hwnd.Handle) as Form;
if (f.WindowState == FormWindowState.Normal) {
SendMessage(hwnd.Handle, Msg.WM_SHOWWINDOW, (IntPtr)1, IntPtr.Zero);
}
}
ShowWindow (WindowHandle);
WaitForHwndMessage (hwnd, Msg.WM_SHOWWINDOW);
}
HIViewSetVisible (WholeWindow, true);
HIViewSetVisible (ClientWindow, true);
hwnd.visible = true;
if (!(Control.FromHandle(hwnd.Handle) is Form)) {
SendMessage(hwnd.Handle, Msg.WM_SHOWWINDOW, (IntPtr)1, IntPtr.Zero);
}
}
if (StyleSet (cp.Style, WindowStyles.WS_MINIMIZE)) {
SetWindowState(hwnd.Handle, FormWindowState.Minimized);
} else if (StyleSet (cp.Style, WindowStyles.WS_MAXIMIZE)) {
SetWindowState(hwnd.Handle, FormWindowState.Maximized);
}
return hwnd.Handle;
}