Exemplo n.º 1
0
	protected virtual void OnVisibleChanged(EventArgs e)
			{
				// Map or unmap the toolkit window.
				if(toolkitWindow != null)
				{
					toolkitWindow.IsMapped = visible && height > 0 && width > 0;

					// May as well release the double buffer resource if its being used.
					if(!visible && buffer != null)
					{
						buffer.Dispose();
						buffer = null;
					}
				}
				else if(visible && !GetControlFlag(ControlFlags.Disposed) &&
				        (parent == null || parent.IsHandleCreated))
				{
					// Create the toolkit window for the first time.
					// This will also map the toolkit window to the screen.
					CreateControl();

					// Force PerformLayout to be called on all the children in the heirarchy.
					ForceLayout();
				}

				// Invoke the event handler.
				EventHandler handler;
				handler = (EventHandler)(GetHandler(EventId.VisibleChanged));
				if(handler != null)
				{
					handler(this, e);
				}

				// Pass the change notification to the children.
				for(int posn = (numChildren - 1); posn >= 0; --posn)
				{
					children[posn].OnParentVisibleChanged(e);
				}
			}
Exemplo n.º 2
0
	}; // class ControlCollectionEnumerator

	// Toolkit event that is emitted for an expose on this window.
	void IToolkitEventSink.ToolkitExpose(Graphics graphics)
			{
				// Must we double buffer?
				bool doubleBuffer = GetStyle(ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint);

				// The paint only allows drawing in the client area.
				Rectangle clientRectangle = new Rectangle(ClientOrigin - new Size(ToolkitDrawOrigin), ClientSize);
				Rectangle clipBounds = Rectangle.Truncate(graphics.ClipBounds);
				clipBounds.Offset(clientRectangle.Location);

				// Create or destroy the buffer as needed.
				if (doubleBuffer)
				{
					if (buffer == null)
					{
						buffer = ToolkitManager.Toolkit.CreateWindowBuffer(toolkitWindow);
					}
				}
				else if (buffer != null)
				{
					buffer.Dispose();
					buffer = null;
				}

				// If we are double buffering, we need to create a Graphics of a bitmap, do all the drawing on that and then write that to the screen in one go.
				if (doubleBuffer && buffer != null)
				{
					Graphics gFull = null;
					Graphics g = null;
					IToolkitGraphics toolkitGraphics = buffer.BeginDoubleBuffer();
					try
					{
						if (borderStyle != BorderStyle.None)
						{
							gFull = ToolkitManager.CreateGraphics(toolkitGraphics);
							DrawBorders(gFull);
						}
					
						g = ToolkitManager.CreateGraphics(toolkitGraphics, clientRectangle);

						PaintEventArgs e = new PaintEventArgs(g, clipBounds);
						if (GetStyle(ControlStyles.AllPaintingInWmPaint))
						{
							GraphicsState state = graphics.Save();
							OnPaintBackground(e);
							g.Restore(state);
						}
						OnPaint(e);
						buffer.EndDoubleBuffer();
					}
					finally
					{
						if (gFull != null)
						{
							gFull.Dispose();
						}
						if (g != null)
						{
							g.Dispose();
						}
					}

				}
				else //!doubleBuffer
				{
					if (!GetStyle(ControlStyles.Opaque))
					{
						// We must erase the background.
						using (Brush brush = CreateBackgroundBrush())
						{
							graphics.FillRectangle(brush, 0, 0, width, height);
						}
					}

					DrawBorders(graphics);
					// Create the graphics of the client area.
					using (Graphics g = ToolkitManager.CreateGraphics(graphics, clientRectangle))
					{
				
						PaintEventArgs e = new PaintEventArgs(g, clipBounds);
						if (GetStyle(ControlStyles.AllPaintingInWmPaint))
						{
							GraphicsState state = g.Save();
							OnPaintBackground(e);
							g.Restore(state);
						}
						OnPaint(e);
					}
				}
			}
Exemplo n.º 3
0
	protected virtual void DestroyHandle()
			{
				// Bail out if we don't have a handle.
				if(toolkitWindow == null)
				{
					return;
				}
				
				// process all pending InvokeEvents 
				// it could be that a BeginInvoke is waiting for EndInvoke.
				this.ProcessInvokeEvent( IntPtr.Zero );
				
				// Destroy all of the child controls.
				int child;
				for(child = 0; child < numChildren; ++child)
				{
					children[child].DestroyHandle();
				}

				// Destroy the toolkit window.
				if(toolkitWindow != null)
				{
					toolkitWindow.Destroy();
					toolkitWindow = null;
				}
				
				// Dispose DoubleBuffer too here
				if( buffer != null ) {
					buffer.Dispose();
					buffer = null;
				}
				
				// Notify event handlers that the handle is destroyed.
				OnHandleDestroyed(EventArgs.Empty);
			}