Пример #1
0
void
WorkspacesView::_ExcludeFromParentClipping()
{
	// Prevent the parent view to draw over us. Do so in a way that allows
	// restoring the parent to the previous state.
	fParentWhichDrawsOnChildren->PushState();

	BRegion clipping(fParentWhichDrawsOnChildren->Bounds());
	clipping.Exclude(Frame());
	fParentWhichDrawsOnChildren->ConstrainClippingRegion(&clipping);
}
Пример #2
0
BBitmap *DragonView::_MakeDragBitmap( void )
{
	// If the currently displayed bitmap is too large to drag around,
	// we'll just drag around a rectangle.

	BRect drag_rect = _bits->Bounds();

	if( drag_rect.Width() > _drag_max_size.x ||
		drag_rect.Height() > _drag_max_size.y ) return NULL;

	// If we've got a PNG image, we'll assume that it's got
	// "interesting" alpha information.  The ones that are built
	// into DragonDrop's resources all have "interesting" alpha
	// channels.
			
	if( _image_is_png ) {
		BBitmap *drag_me = new BBitmap( _bits );
		memcpy( drag_me->Bits(), _bits->Bits(), _bits->BitsLength() );
		
		return drag_me;
	}

	// If you've made it here, we'll need to build a semi-transparent image
	// to drag around.  This magic is from Pavel Cisler, and it ensures that
	// you've got a drag bitmap that's translucent.
	
	BRect rect( _bits->Bounds() );
	BBitmap *bitmap = new BBitmap( rect, B_RGBA32, true );
	BView *view = new BView( rect, "drag view", B_FOLLOW_NONE, 0 );

	bitmap->Lock();
	bitmap->AddChild( view );
	
	BRegion new_clip;
	new_clip.Set( rect );
	view->ConstrainClippingRegion( &new_clip );
	
	view->SetHighColor( 0, 0, 0, 0 );
	view->FillRect( rect );
	view->SetDrawingMode( B_OP_ALPHA );
	
	view->SetHighColor( 0, 0, 0, 128 );
	view->SetBlendingMode( B_CONSTANT_ALPHA, B_ALPHA_COMPOSITE );
	
	view->DrawBitmap( _bits );
	
	view->Sync();
	
	bitmap->Unlock();

	return bitmap;
}
Пример #3
0
void
RemoteView::_DrawThread()
{
	RemoteMessage reply(NULL, fSendBuffer);
	RemoteMessage message(fReceiveBuffer, NULL);

	// cursor
	BPoint cursorHotSpot(0, 0);

	while (!fStopThread) {
		uint16 code;
		status_t status = message.NextMessage(code);
		if (status != B_OK) {
			TRACE_ERROR("failed to read message from receiver\n");
			break;
		}

		TRACE("code %u with %ld bytes data\n", code, message.DataLeft());

		BAutolock locker(this->Looper());
		if (!locker.IsLocked())
			break;

		// handle stuff that doesn't go to a specicifc engine
		switch (code) {
			case RP_INIT_CONNECTION:
			{
				uint16 port;
				status_t result = message.Read(port);
				if (result != B_OK) {
					TRACE_ERROR("failed to read remote port\n");
					continue;
				}

				BNetEndpoint *endpoint = fReceiver->Endpoint();
				if (endpoint == NULL) {
					TRACE_ERROR("receiver not connected anymore\n");
					continue;
				}

				in_addr remoteHost;
				char hostName[MAXHOSTNAMELEN + 1];
				BNetAddress address(endpoint->RemoteAddr());
				address.GetAddr(remoteHost);
				address.GetAddr(hostName, NULL);
				address.SetTo(remoteHost, port);

				TRACE("connecting to host \"%s\" port %u\n", hostName, port);
				result = fSendEndpoint->Connect(address);
				if (result != B_OK) {
					TRACE_ERROR("failed to connect to host \"%s\" port %u\n",
						hostName, port);
					continue;
				}

				BRect bounds = fOffscreenBitmap->Bounds();
				reply.Start(RP_UPDATE_DISPLAY_MODE);
				reply.Add(bounds.IntegerWidth() + 1);
				reply.Add(bounds.IntegerHeight() + 1);
				if (reply.Flush() == B_OK)
					fIsConnected = true;

				continue;
			}

			case RP_CLOSE_CONNECTION:
			{
				be_app->PostMessage(B_QUIT_REQUESTED);
				continue;
			}

			case RP_CREATE_STATE:
			case RP_DELETE_STATE:
			{
				uint32 token;
				message.Read(token);

				if (code == RP_CREATE_STATE)
					_CreateState(token);
				else
					_DeleteState(token);

				continue;
			}

			case RP_SET_CURSOR:
			{
				BBitmap *bitmap;
				BPoint oldHotSpot = cursorHotSpot;
				message.Read(cursorHotSpot);
				if (message.ReadBitmap(&bitmap) != B_OK)
					continue;

				delete fCursorBitmap;
				fCursorBitmap = bitmap;

				Invalidate(fCursorFrame);

				BRect bounds = fCursorBitmap->Bounds();
				fCursorFrame.right = fCursorFrame.left
					+ bounds.IntegerWidth() + 1;
				fCursorFrame.bottom = fCursorFrame.bottom
					+ bounds.IntegerHeight() + 1;

				fCursorFrame.OffsetBy(oldHotSpot - cursorHotSpot);

				Invalidate(fCursorFrame);
				continue;
			}

			case RP_SET_CURSOR_VISIBLE:
			{
				bool wasVisible = fCursorVisible;
				message.Read(fCursorVisible);
				if (wasVisible != fCursorVisible)
					Invalidate(fCursorFrame);
				continue;
			}

			case RP_MOVE_CURSOR_TO:
			{
				BPoint position;
				message.Read(position);

				if (fCursorVisible)
					Invalidate(fCursorFrame);

				fCursorFrame.OffsetTo(position - cursorHotSpot);

				Invalidate(fCursorFrame);
				continue;
			}

			case RP_INVALIDATE_RECT:
			{
				BRect rect;
				if (message.Read(rect) != B_OK)
					continue;

				Invalidate(rect);
				continue;
			}

			case RP_INVALIDATE_REGION:
			{
				BRegion region;
				if (message.ReadRegion(region) != B_OK)
					continue;

				Invalidate(&region);
				continue;
			}

			case RP_FILL_REGION_COLOR_NO_CLIPPING:
			{
				BRegion region;
				rgb_color color;

				message.ReadRegion(region);
				if (message.Read(color) != B_OK)
					continue;

				fOffscreen->LockLooper();
				fOffscreen->SetHighColor(color);
				fOffscreen->FillRegion(&region);
				fOffscreen->UnlockLooper();
				Invalidate(&region);
				continue;
			}

			case RP_COPY_RECT_NO_CLIPPING:
			{
				int32 xOffset, yOffset;
				BRect rect;

				message.Read(xOffset);
				message.Read(yOffset);
				if (message.Read(rect) != B_OK)
					continue;

				BRect dest = rect.OffsetByCopy(xOffset, yOffset);
				fOffscreen->LockLooper();
				fOffscreen->CopyBits(rect, dest);
				fOffscreen->UnlockLooper();
				continue;
			}
		}

		uint32 token;
		message.Read(token);

		engine_state *state = _FindState(token);
		if (state == NULL) {
			TRACE_ERROR("didn't find state for token %lu\n", token);
			continue;
		}

		BView *offscreen = state->view;
		::pattern &pattern = state->pattern;
		BRegion &clippingRegion = state->clipping_region;
		float &penSize = state->pen_size;
		bool &syncDrawing = state->sync_drawing;
		BRegion invalidRegion;

		BAutolock offscreenLocker(offscreen->Looper());
		if (!offscreenLocker.IsLocked())
			break;

		switch (code) {
			case RP_ENABLE_SYNC_DRAWING:
				syncDrawing = true;
				continue;

			case RP_DISABLE_SYNC_DRAWING:
				syncDrawing = false;
				continue;

			case RP_SET_OFFSETS:
			{
				int32 xOffset, yOffset;
				message.Read(xOffset);
				if (message.Read(yOffset) != B_OK)
					continue;

				offscreen->MovePenTo(xOffset, yOffset);
				break;
			}

			case RP_SET_HIGH_COLOR:
			case RP_SET_LOW_COLOR:
			{
				rgb_color color;
				if (message.Read(color) != B_OK)
					continue;

				if (code == RP_SET_HIGH_COLOR)
					offscreen->SetHighColor(color);
				else
					offscreen->SetLowColor(color);

				break;
			}

			case RP_SET_PEN_SIZE:
			{
				float newPenSize;
				if (message.Read(newPenSize) != B_OK)
					continue;

				offscreen->SetPenSize(newPenSize);
				penSize = newPenSize / 2;
				break;
			}

			case RP_SET_STROKE_MODE:
			{
				cap_mode capMode;
				join_mode joinMode;
				float miterLimit;

				message.Read(capMode);
				message.Read(joinMode);
				if (message.Read(miterLimit) != B_OK)
					continue;

				offscreen->SetLineMode(capMode, joinMode, miterLimit);
				break;
			}

			case RP_SET_BLENDING_MODE:
			{
				source_alpha sourceAlpha;
				alpha_function alphaFunction;

				message.Read(sourceAlpha);
				if (message.Read(alphaFunction) != B_OK)
					continue;

				offscreen->SetBlendingMode(sourceAlpha, alphaFunction);
				break;
			}

			case RP_SET_PATTERN:
			{
				if (message.Read(pattern) != B_OK)
					continue;
				break;
			}

			case RP_SET_DRAWING_MODE:
			{
				drawing_mode drawingMode;
				if (message.Read(drawingMode) != B_OK)
					continue;

				offscreen->SetDrawingMode(drawingMode);
				break;
			}

			case RP_SET_FONT:
			{
				BFont font;
				if (message.ReadFontState(font) != B_OK)
					continue;

				offscreen->SetFont(&font);
				break;
			}

			case RP_CONSTRAIN_CLIPPING_REGION:
			{
				if (message.ReadRegion(clippingRegion) != B_OK)
					continue;

				offscreen->ConstrainClippingRegion(&clippingRegion);
				break;
			}

			case RP_INVERT_RECT:
			{
				BRect rect;
				if (message.Read(rect) != B_OK)
					continue;

				offscreen->InvertRect(rect);
				invalidRegion.Include(rect);
				break;
			}

			case RP_DRAW_BITMAP:
			{
				BBitmap *bitmap;
				BRect bitmapRect, viewRect;
				uint32 options;

				message.Read(bitmapRect);
				message.Read(viewRect);
				message.Read(options);
				if (message.ReadBitmap(&bitmap) != B_OK || bitmap == NULL)
					continue;

				offscreen->DrawBitmap(bitmap, bitmapRect, viewRect, options);
				invalidRegion.Include(viewRect);
				delete bitmap;
				break;
			}

			case RP_DRAW_BITMAP_RECTS:
			{
				color_space colorSpace;
				int32 rectCount;
				uint32 flags, options;

				message.Read(options);
				message.Read(colorSpace);
				message.Read(flags);
				message.Read(rectCount);
				for (int32 i = 0; i < rectCount; i++) {
					BBitmap *bitmap;
					BRect viewRect;

					message.Read(viewRect);
					if (message.ReadBitmap(&bitmap, true, colorSpace,
							flags) != B_OK || bitmap == NULL) {
						continue;
					}

					offscreen->DrawBitmap(bitmap, bitmap->Bounds(), viewRect,
						options);
					invalidRegion.Include(viewRect);
					delete bitmap;
				}

				break;
			}

			case RP_STROKE_ARC:
			case RP_FILL_ARC:
			case RP_FILL_ARC_GRADIENT:
			{
				BRect rect;
				float angle, span;

				message.Read(rect);
				message.Read(angle);
				if (message.Read(span) != B_OK)
					continue;

				if (code == RP_STROKE_ARC) {
					offscreen->StrokeArc(rect, angle, span, pattern);
					rect.InsetBy(-penSize, -penSize);
				} else if (code == RP_FILL_ARC)
					offscreen->FillArc(rect, angle, span, pattern);
				else {
					BGradient *gradient;
					if (message.ReadGradient(&gradient) != B_OK)
						continue;

					offscreen->FillArc(rect, angle, span, *gradient);
					delete gradient;
				}

				invalidRegion.Include(rect);
				break;
			}

			case RP_STROKE_BEZIER:
			case RP_FILL_BEZIER:
			case RP_FILL_BEZIER_GRADIENT:
			{
				BPoint points[4];
				if (message.ReadList(points, 4) != B_OK)
					continue;

				BRect bounds = _BuildInvalidateRect(points, 4);
				if (code == RP_STROKE_BEZIER) {
					offscreen->StrokeBezier(points, pattern);
					bounds.InsetBy(-penSize, -penSize);
				} else if (code == RP_FILL_BEZIER)
					offscreen->FillBezier(points, pattern);
				else {
					BGradient *gradient;
					if (message.ReadGradient(&gradient) != B_OK)
						continue;

					offscreen->FillBezier(points, *gradient);
					delete gradient;
				}

				invalidRegion.Include(bounds);
				break;
			}

			case RP_STROKE_ELLIPSE:
			case RP_FILL_ELLIPSE:
			case RP_FILL_ELLIPSE_GRADIENT:
			{
				BRect rect;
				if (message.Read(rect) != B_OK)
					continue;

				if (code == RP_STROKE_ELLIPSE) {
					offscreen->StrokeEllipse(rect, pattern);
					rect.InsetBy(-penSize, -penSize);
				} else if (code == RP_FILL_ELLIPSE)
					offscreen->FillEllipse(rect, pattern);
				else {
					BGradient *gradient;
					if (message.ReadGradient(&gradient) != B_OK)
						continue;

					offscreen->FillEllipse(rect, *gradient);
					delete gradient;
				}

				invalidRegion.Include(rect);
				break;
			}

			case RP_STROKE_POLYGON:
			case RP_FILL_POLYGON:
			case RP_FILL_POLYGON_GRADIENT:
			{
				BRect bounds;
				bool closed;
				int32 numPoints;

				message.Read(bounds);
				message.Read(closed);
				if (message.Read(numPoints) != B_OK)
					continue;

				BPoint points[numPoints];
				for (int32 i = 0; i < numPoints; i++)
					message.Read(points[i]);

				if (code == RP_STROKE_POLYGON) {
					offscreen->StrokePolygon(points, numPoints, bounds, closed,
						pattern);
					bounds.InsetBy(-penSize, -penSize);
				} else if (code == RP_FILL_POLYGON)
					offscreen->FillPolygon(points, numPoints, bounds, pattern);
				else {
					BGradient *gradient;
					if (message.ReadGradient(&gradient) != B_OK)
						continue;

					offscreen->FillPolygon(points, numPoints, bounds,
						*gradient);
					delete gradient;
				}

				invalidRegion.Include(bounds);
				break;
			}

			case RP_STROKE_RECT:
			case RP_FILL_RECT:
			case RP_FILL_RECT_GRADIENT:
			{
				BRect rect;
				if (message.Read(rect) != B_OK)
					continue;

				if (code == RP_STROKE_RECT) {
					offscreen->StrokeRect(rect, pattern);
					rect.InsetBy(-penSize, -penSize);
				} else if (code == RP_FILL_RECT)
					offscreen->FillRect(rect, pattern);
				else {
					BGradient *gradient;
					if (message.ReadGradient(&gradient) != B_OK)
						continue;

					offscreen->FillRect(rect, *gradient);
					delete gradient;
				}

				invalidRegion.Include(rect);
				break;
			}

			case RP_STROKE_ROUND_RECT:
			case RP_FILL_ROUND_RECT:
			case RP_FILL_ROUND_RECT_GRADIENT:
			{
				BRect rect;
				float xRadius, yRadius;

				message.Read(rect);
				message.Read(xRadius);
				if (message.Read(yRadius) != B_OK)
					continue;

				if (code == RP_STROKE_ROUND_RECT) {
					offscreen->StrokeRoundRect(rect, xRadius, yRadius,
						pattern);
					rect.InsetBy(-penSize, -penSize);
				} else if (code == RP_FILL_ROUND_RECT)
					offscreen->FillRoundRect(rect, xRadius, yRadius, pattern);
				else {
					BGradient *gradient;
					if (message.ReadGradient(&gradient) != B_OK)
						continue;

					offscreen->FillRoundRect(rect, xRadius, yRadius,
						*gradient);
					delete gradient;
				}

				invalidRegion.Include(rect);
				break;
			}

			case RP_STROKE_SHAPE:
			case RP_FILL_SHAPE:
			case RP_FILL_SHAPE_GRADIENT:
			{
				BRect bounds;
				int32 opCount, pointCount;

				message.Read(bounds);
				if (message.Read(opCount) != B_OK)
					continue;

				BMessage archive;
				for (int32 i = 0; i < opCount; i++) {
					int32 op;
					message.Read(op);
					archive.AddInt32("ops", op);
				}

				if (message.Read(pointCount) != B_OK)
					continue;

				for (int32 i = 0; i < pointCount; i++) {
					BPoint point;
					message.Read(point);
					archive.AddPoint("pts", point);
				}

				BPoint offset;
				message.Read(offset);

				float scale;
				if (message.Read(scale) != B_OK)
					continue;

				offscreen->PushState();
				offscreen->MovePenTo(offset);
				offscreen->SetScale(scale);

				BShape shape(&archive);
				if (code == RP_STROKE_SHAPE) {
					offscreen->StrokeShape(&shape, pattern);
					bounds.InsetBy(-penSize, -penSize);
				} else if (code == RP_FILL_SHAPE)
					offscreen->FillShape(&shape, pattern);
				else {
					BGradient *gradient;
					if (message.ReadGradient(&gradient) != B_OK) {
						offscreen->PopState();
						continue;
					}

					offscreen->FillShape(&shape, *gradient);
					delete gradient;
				}

				offscreen->PopState();
				invalidRegion.Include(bounds);
				break;
			}

			case RP_STROKE_TRIANGLE:
			case RP_FILL_TRIANGLE:
			case RP_FILL_TRIANGLE_GRADIENT:
			{
				BRect bounds;
				BPoint points[3];

				message.ReadList(points, 3);
				if (message.Read(bounds) != B_OK)
					continue;

				if (code == RP_STROKE_TRIANGLE) {
					offscreen->StrokeTriangle(points[0], points[1], points[2],
						bounds, pattern);
					bounds.InsetBy(-penSize, -penSize);
				} else if (code == RP_FILL_TRIANGLE) {
					offscreen->FillTriangle(points[0], points[1], points[2],
						bounds, pattern);
				} else {
					BGradient *gradient;
					if (message.ReadGradient(&gradient) != B_OK)
						continue;

					offscreen->FillTriangle(points[0], points[1], points[2],
						bounds, *gradient);
					delete gradient;
				}

				invalidRegion.Include(bounds);
				break;
			}

			case RP_STROKE_LINE:
			{
				BPoint points[2];
				if (message.ReadList(points, 2) != B_OK)
					continue;

				offscreen->StrokeLine(points[0], points[1], pattern);

				BRect bounds = _BuildInvalidateRect(points, 2);
				invalidRegion.Include(bounds.InsetBySelf(-penSize, -penSize));
				break;
			}

			case RP_STROKE_LINE_ARRAY:
			{
				int32 numLines;
				if (message.Read(numLines) != B_OK)
					continue;

				BRect bounds;
				offscreen->BeginLineArray(numLines);
				for (int32 i = 0; i < numLines; i++) {
					rgb_color color;
					BPoint start, end;
					message.ReadArrayLine(start, end, color);
					offscreen->AddLine(start, end, color);

					bounds.left = min_c(bounds.left, min_c(start.x, end.x));
					bounds.top = min_c(bounds.top, min_c(start.y, end.y));
					bounds.right = max_c(bounds.right, max_c(start.x, end.x));
					bounds.bottom = max_c(bounds.bottom, max_c(start.y, end.y));
				}

				offscreen->EndLineArray();
				invalidRegion.Include(bounds);
				break;
			}

			case RP_FILL_REGION:
			case RP_FILL_REGION_GRADIENT:
			{
				BRegion region;
				if (message.ReadRegion(region) != B_OK)
					continue;

				if (code == RP_FILL_REGION)
					offscreen->FillRegion(&region, pattern);
				else {
					BGradient *gradient;
					if (message.ReadGradient(&gradient) != B_OK)
						continue;

					offscreen->FillRegion(&region, *gradient);
					delete gradient;
				}

				invalidRegion.Include(&region);
				break;
			}

			case RP_STROKE_POINT_COLOR:
			{
				BPoint point;
				rgb_color color;

				message.Read(point);
				if (message.Read(color) != B_OK)
					continue;

				rgb_color oldColor = offscreen->HighColor();
				offscreen->SetHighColor(color);
				offscreen->StrokeLine(point, point);
				offscreen->SetHighColor(oldColor);

				invalidRegion.Include(
					BRect(point, point).InsetBySelf(-penSize, -penSize));
				break;
			}

			case RP_STROKE_LINE_1PX_COLOR:
			{
				BPoint points[2];
				rgb_color color;

				message.ReadList(points, 2);
				if (message.Read(color) != B_OK)
					continue;

				float oldSize = offscreen->PenSize();
				rgb_color oldColor = offscreen->HighColor();
				drawing_mode oldMode = offscreen->DrawingMode();
				offscreen->SetPenSize(1);
				offscreen->SetHighColor(color);
				offscreen->SetDrawingMode(B_OP_OVER);

				offscreen->StrokeLine(points[0], points[1]);

				offscreen->SetDrawingMode(oldMode);
				offscreen->SetHighColor(oldColor);
				offscreen->SetPenSize(oldSize);

				invalidRegion.Include(_BuildInvalidateRect(points, 2));
				break;
			}

			case RP_STROKE_RECT_1PX_COLOR:
			case RP_FILL_RECT_COLOR:
			{
				BRect rect;
				rgb_color color;

				message.Read(rect);
				if (message.Read(color) != B_OK)
					continue;

				rgb_color oldColor = offscreen->HighColor();
				offscreen->SetHighColor(color);

				if (code == RP_STROKE_RECT_1PX_COLOR) {
					float oldSize = PenSize();
					offscreen->SetPenSize(1);
					offscreen->StrokeRect(rect);
					offscreen->SetPenSize(oldSize);
				} else
					offscreen->FillRect(rect);

				offscreen->SetHighColor(oldColor);
				invalidRegion.Include(rect);
				break;
			}

			case RP_DRAW_STRING:
			{
				BPoint point;
				size_t length;
				char *string;
				bool hasDelta;

				message.Read(point);
				message.ReadString(&string, length);
				if (message.Read(hasDelta) != B_OK) {
					free(string);
					continue;
				}

				if (hasDelta) {
					escapement_delta delta[length];
					message.ReadList(delta, length);
					offscreen->DrawString(string, point, delta);
				} else
					offscreen->DrawString(string, point);

				free(string);
				reply.Start(RP_DRAW_STRING_RESULT);
				reply.Add(token);
				reply.Add(offscreen->PenLocation());
				reply.Flush();

				font_height height;
				offscreen->GetFontHeight(&height);

				BRect bounds(point, offscreen->PenLocation());
				bounds.top -= height.ascent;
				bounds.bottom += height.descent;
				invalidRegion.Include(bounds);
				break;
			}

			case RP_DRAW_STRING_WITH_OFFSETS:
			{
				size_t length;
				char *string;
				message.ReadString(&string, length);
				int32 count = UTF8CountChars(string, length);

				BPoint offsets[count];
				if (message.ReadList(offsets, count) != B_OK) {
					free(string);
					continue;
				}

				offscreen->DrawString(string, offsets, count);

				free(string);
				reply.Start(RP_DRAW_STRING_RESULT);
				reply.Add(token);
				reply.Add(offscreen->PenLocation());
				reply.Flush();

				BFont font;
				offscreen->GetFont(&font);

				BRect boxes[count];
				font.GetBoundingBoxesAsGlyphs(string, count, B_SCREEN_METRIC,
					boxes);

				font_height height;
				offscreen->GetFontHeight(&height);

				for (int32 i = 0; i < count; i++) {
					// TODO: validate
					boxes[i].OffsetBy(offsets[i] + BPoint(0, -height.ascent));
					invalidRegion.Include(boxes[i]);
				}

				break;
			}

			case RP_READ_BITMAP:
			{
				BRect bounds;
				bool drawCursor;

				message.Read(bounds);
				if (message.Read(drawCursor) != B_OK)
					continue;

				// TODO: support the drawCursor flag
				BBitmap bitmap(bounds, B_BITMAP_NO_SERVER_LINK, B_RGB32);
				bitmap.ImportBits(fOffscreenBitmap, bounds.LeftTop(),
					BPoint(0, 0), bounds.IntegerWidth() + 1,
					bounds.IntegerHeight() + 1);

				reply.Start(RP_READ_BITMAP_RESULT);
				reply.Add(token);
				reply.AddBitmap(&bitmap);
				reply.Flush();
				break;
			}

			default:
				TRACE_ERROR("unknown protocol code: %u\n", code);
				break;
		}

		if (syncDrawing) {
			offscreen->Sync();
			Invalidate(&invalidRegion);
		}
	}
}
Пример #4
0
void
EBePrivateWin::DispatchMessage(BMessage *bMsg, BHandler *handler)
{
	bool handled = true;

	if(bMsg->what == 'etk_')
	{
		int32 what = 0;
		bMsg->FindInt32("etk:what", &what);

		switch(what)
		{
			case ETK_BEOS_QUIT:
				doQuit = true;
				PostMessage(B_QUIT_REQUESTED);
				break;

			case ETK_BEOS_CONTACT_TO:
				{
					fContactor = EMessenger();
					const char *buffer = NULL;
					ssize_t size = -1;
					if(bMsg->FindData("etk:messenger", B_ANY_TYPE, (const void**)&buffer, &size) != B_OK) break;
					if(buffer == NULL || size <= 0) break;
					fContactor.Unflatten(buffer, (size_t)size);
				}
				break;

			case ETK_BEOS_SET_BACKGROUND:
				{
					rgb_color bkColor;
					if(bMsg->FindInt32("background", (int32*)&bkColor) != B_OK) break;
					fTopView->SetViewColor(bkColor);
					fTopView->Invalidate();
				}
				break;

			case ETK_BEOS_SET_LOOK:
				{
					int8 look;
					if(bMsg->FindInt8("look", &look) != B_OK) break;
					switch((e_window_look)look)
					{
						case E_BORDERED_WINDOW_LOOK:
							SetLook(B_BORDERED_WINDOW_LOOK);
							break;

						case E_NO_BORDER_WINDOW_LOOK:
							SetLook(B_NO_BORDER_WINDOW_LOOK);
							break;

						case E_TITLED_WINDOW_LOOK:
							SetLook(B_TITLED_WINDOW_LOOK);
							break;

						case E_DOCUMENT_WINDOW_LOOK:
							SetLook(B_DOCUMENT_WINDOW_LOOK);
							break;

						case E_MODAL_WINDOW_LOOK:
							SetLook(B_MODAL_WINDOW_LOOK);
							break;

						case E_FLOATING_WINDOW_LOOK:
							SetLook(B_FLOATING_WINDOW_LOOK);
							break;

						default:
							break;
					}
				}
				break;

			case ETK_BEOS_SET_TITLE:
				{
					const char *title = NULL;
					if(bMsg->FindString("title", &title) != B_OK) break;
					SetTitle(title);
				}
				break;

			case ETK_BEOS_SET_WORKSPACES:
				{
					uint32 workspaces = 0;
					if(bMsg->FindInt32("workspaces", (int32*)&workspaces) != B_OK) break;
					if(workspaces == 0) workspaces = current_workspace() + 1;
					SetWorkspaces(workspaces);
				}
				break;

			case ETK_BEOS_GET_WORKSPACES:
				{
					uint32 workspaces = Workspaces();
					bMsg->AddInt32("workspaces", *((int32*)&workspaces));
				}
				break;

			case ETK_BEOS_ICONIFY:
				if(!IsMinimized()) Minimize(true);
				break;

			case ETK_BEOS_SHOW:
				if(IsHidden())
				{
					uint32 oldFlags = Flags();
					SetFlags(oldFlags | B_AVOID_FOCUS);
					Show();
					if(Look() != B_NO_BORDER_WINDOW_LOOK) SetFlags(oldFlags);
				}
				break;

			case ETK_BEOS_HIDE:
				if(!IsHidden()) Hide();
				break;

			case ETK_BEOS_RAISE:
				if(!IsFront())
				{
					uint32 oldFlags = Flags();
					SetFlags(oldFlags | B_AVOID_FOCUS);
					Activate(true);
					if(Look() != B_NO_BORDER_WINDOW_LOOK) SetFlags(oldFlags);
				}
				break;

			case ETK_BEOS_LOWER:
				{
					BHandler *_frontWin = NULL;
					if(bMsg->FindPointer("front", (void**)&_frontWin) != B_OK) break;
					BWindow *frontWin = e_cast_as(_frontWin, BWindow);
					if(frontWin == NULL) break;
					SendBehind(frontWin);
					bMsg->AddBool("done", true);
				}
				break;

			case ETK_BEOS_ACTIVATE:
				{
					bool state;
					if(bMsg->FindBool("state", &state) != B_OK || state == IsActive()) break;
					Activate(state);
				}
				break;

			case ETK_BEOS_GET_ACTIVATED_STATE:
				bMsg->AddBool("state", IsActive());
				break;

			case ETK_BEOS_MOVE_RESIZE:
				{
					if(bMsg->HasPoint("where"))
					{
						BPoint pt;
						if(bMsg->FindPoint("where", &pt) == B_OK) MoveTo(pt);
					}

					if(bMsg->HasFloat("width") && bMsg->HasFloat("height"))
					{
						float w = -1, h = -1;
						bMsg->FindFloat("width", &w);
						bMsg->FindFloat("height", &h);
						if(w < 0 || h < 0) break;
						ResizeTo(w, h);
					}
				}
				break;

			case ETK_BEOS_DRAW_BITMAP:
				{
					BBitmap *bitmap = NULL;
					BRect srcRect, destRect;
					const ERegion *clipping = NULL;

					if(bMsg->FindPointer("bitmap", (void**)&bitmap) != B_OK || bitmap == NULL) break;
					bMsg->FindRect("src", &srcRect);
					bMsg->FindRect("dest", &destRect);
					if(srcRect.IsValid() == false || destRect.IsValid() == false) break;
					bMsg->FindPointer("clipping", (void**)&clipping); 

					BRegion beRegion;
					__etk_convert_region(clipping, &beRegion, fTopView->Bounds());
					fTopView->ConstrainClippingRegion(&beRegion);
					fTopView->DrawBitmap(bitmap, srcRect, destRect);
				}
				break;

			case ETK_BEOS_GRAB_MOUSE:
			case ETK_BEOS_UNGRAB_MOUSE:
				{
					uint32 options = (what == ETK_BEOS_GRAB_MOUSE ? B_LOCK_WINDOW_FOCUS : 0);
					if(fTopView->SetEventMask(B_POINTER_EVENTS, options) != B_OK) break;
					bMsg->AddBool("state", what == ETK_BEOS_GRAB_MOUSE);
				}
				break;

			case ETK_BEOS_GRAB_KEYBOARD:
			case ETK_BEOS_UNGRAB_KEYBOARD:
				{
					uint32 options = (what == ETK_BEOS_GRAB_KEYBOARD ? B_LOCK_WINDOW_FOCUS : 0);
					if(fTopView->SetEventMask(B_KEYBOARD_EVENTS, options) != B_OK) break;
					bMsg->AddBool("state", what == ETK_BEOS_GRAB_KEYBOARD);
				}
				break;

			case ETK_BEOS_QUERY_MOUSE:
				{
					BPoint pt;
					uint32 btns = 0;
					fTopView->GetMouse(&pt, &btns, false);
					bMsg->AddInt32("x", (int32)pt.x);
					bMsg->AddInt32("y", (int32)pt.y);
					bMsg->AddInt32("buttons", (int32)btns);
				}
				break;

			case ETK_BEOS_SET_SIZE_LIMITS:
				{
					BRect r;
					if(bMsg->FindRect("limits", &r) != B_OK) break;
					SetSizeLimits(r.left, r.right, r.top, r.bottom);
					bMsg->AddBool("done", true);
				}
				break;

			case ETK_BEOS_GET_SIZE_LIMITS:
				{
					BRect r(-1, -1, -1, -1);
					GetSizeLimits(&(r.left), &(r.right), &(r.top), &(r.bottom));
					bMsg->AddRect("limits", r);
				}
				break;

			default:
				handled = false;
				break;
		}

		if(handled)
		{
			BMessage aMsg(*bMsg);
			bMsg->SendReply(&aMsg);
			return;
		}
	}

	switch(bMsg->what)
	{
		case B_WINDOW_ACTIVATED:
			{
				handled = false;

				if(fContactor.IsValid() == false) break;
				EMessage message(E_WINDOW_ACTIVATED);
				message.AddBool("etk:msg_from_gui", true);
				message.AddInt64("when", e_real_time_clock_usecs());
				fContactor.SendMessage(&message);
			}
			break;

		case B_MOUSE_DOWN:
		case B_MOUSE_UP:
		case B_MOUSE_MOVED:
			{
				if(fContactor.IsValid() == false) break;

				BPoint where;
				int32 buttons = 0;

				bMsg->FindPoint("where", &where);
				if(bMsg->what != B_MOUSE_UP) bMsg->FindInt32("buttons", &buttons);

				int32 clicks = 1;
				if(bMsg->what == B_MOUSE_DOWN)
				{
#if 0
					bMsg->FindInt32("clicks", &clicks);
#else
					bigtime_t eventTime;
					if(bMsg->FindInt64("when", &eventTime) == B_OK)
					{
						if(eventTime - fPrevMouseDownTime <= CLICK_TIMEOUT)
							clicks = (fPrevMouseDownCount += 1);
						else
							clicks = fPrevMouseDownCount = 1;
						fPrevMouseDownTime = eventTime;
					}
#endif
				}

				EMessage message;
				if(bMsg->what == B_MOUSE_DOWN) message.what = E_MOUSE_DOWN;
				else if(bMsg->what == B_MOUSE_UP) message.what = E_MOUSE_UP;
				else message.what = E_MOUSE_MOVED;

				message.AddBool("etk:msg_from_gui", true);
				message.AddInt64("when", e_real_time_clock_usecs());
				if(bMsg->what != B_MOUSE_UP) message.AddInt32("buttons", buttons);
				if(bMsg->what == B_MOUSE_DOWN) message.AddInt32("clicks", clicks);
				message.AddPoint("where", EPoint(where.x, where.y));
				ConvertToScreen(&where);
				message.AddPoint("screen_where", EPoint(where.x, where.y));

				// TODO: modifiers

				message.AddMessenger("etk:msg_for_target", fContactor);

				etk_app->PostMessage(&message);
			}
			break;

		case B_KEY_DOWN:
		case B_KEY_UP:
		case B_UNMAPPED_KEY_DOWN:
		case B_UNMAPPED_KEY_UP:
			{
				if(fContactor.IsValid() == false) break;

				int8 byte[4];
				const char *bytes = NULL;
				int32 numBytes = 0;
				int32 key = 0;
				int32 key_repeat = 0;
				int32 beModifiers = 0;
				eint32 modifiers = 0;

				bMsg->FindInt32("key", &key);
				bMsg->FindInt32("modifiers", &beModifiers);
				bzero(byte, sizeof(int8) * 4);

				if(bMsg->what == B_KEY_DOWN || bMsg->what == B_KEY_UP)
				{
					for(int32 i = 0; i < 3; i++) bMsg->FindInt8("byte", i, &byte[i]);
					if(bMsg->FindString("bytes", &bytes) == B_OK) numBytes = strlen(bytes);
//					if(bMsg->what == B_KEY_DOWN) bMsg->FindInt32("be:key_repeat", &key_repeat);
				}
				else
				{
					etk_beos_get_byte(beModifiers, key, (char*)byte);
				}

				if(beModifiers & B_SHIFT_KEY) modifiers |= E_SHIFT_KEY;
				if(beModifiers & B_CONTROL_KEY) modifiers |= E_CONTROL_KEY;
				if(beModifiers & B_COMMAND_KEY) modifiers |= E_COMMAND_KEY;

				EMessage message;
				if(bMsg->what == B_KEY_DOWN) message.what = E_KEY_DOWN;
				else if(bMsg->what == B_KEY_UP) message.what = E_KEY_UP;
				else if(bMsg->what == B_UNMAPPED_KEY_DOWN) message.what = E_UNMAPPED_KEY_DOWN;
				else message.what = E_UNMAPPED_KEY_UP;

				message.AddBool("etk:msg_from_gui", true);
				message.AddInt64("when", e_real_time_clock_usecs());
				message.AddInt32("key", key);
				message.AddInt32("modifiers", modifiers);

				if(bMsg->what == B_KEY_DOWN || bMsg->what == B_KEY_UP)
				{
					if(bMsg->what == B_KEY_DOWN) message.AddInt32("etk:key_repeat", key_repeat);
					for(int32 i = 0; i < 3; i++) message.AddInt8("byte", byte[i]);
					if(!(numBytes != 1 || *bytes != byte[0]))
					{
						etk_beos_get_byte(beModifiers, key, (char*)byte);
						message.AddString("bytes", (char*)byte);
					}
					else if(numBytes > 0)
					{
						message.AddString("bytes", bytes);
					}
				}
				else if(byte[0] != 0)
				{
					message.AddInt8("byte", byte[0]);
					message.AddString("bytes", (char*)byte);
				}

				message.AddMessenger("etk:msg_for_target", fContactor);

				etk_app->PostMessage(&message);
			}
			break;

		case B_MODIFIERS_CHANGED:
			{
				if(fContactor.IsValid() == false) break;

				eint32 modifiers = 0;
				eint32 old_modifiers = 0;
				int32 beModifiers = 0;
				int32 old_beModifiers = 0;

				bMsg->FindInt32("modifiers", &beModifiers);
				bMsg->FindInt32("be:old_modifiers", &old_beModifiers);

				if(beModifiers & B_SHIFT_KEY) modifiers |= E_SHIFT_KEY;
				if(beModifiers & B_CONTROL_KEY) modifiers |= E_CONTROL_KEY;
				if(beModifiers & B_COMMAND_KEY) modifiers |= E_COMMAND_KEY;

				if(old_beModifiers & B_SHIFT_KEY) old_modifiers |= E_SHIFT_KEY;
				if(old_beModifiers & B_CONTROL_KEY) old_modifiers |= E_CONTROL_KEY;
				if(old_beModifiers & B_COMMAND_KEY) old_modifiers |= E_COMMAND_KEY;

				EMessage message(E_MODIFIERS_CHANGED);

				message.AddBool("etk:msg_from_gui", true);
				message.AddInt64("when", e_real_time_clock_usecs());
				message.AddInt32("modifiers", modifiers);
				message.AddInt32("etk:old_modifiers", old_modifiers);

				message.AddMessenger("etk:msg_for_target", fContactor);

				etk_app->PostMessage(&message);
			}
			break;

		default:
			handled = false;
			break;
	}

	if(!handled) BWindow::DispatchMessage(bMsg, handler);
}
Пример #5
0
// This function returns the number of pixels of the text that
// were clipped if the text does not fit into the clipping rect.
// If the text all fit, it returns 0.
int
BeOSCanvas::RenderText( int iFontHeight, Rect& oClipRect,
                        string& oText, AlignEnum eAlign,
                        Font* pFont, const Color& oColor,
                        bool bBold, bool bItalic, bool bUnderline )
{
    Erase( oClipRect );

    BView* v = m_pBufferBitmap->OffscreenView();
    if ( !v ) return 0;

    BBitmap* bitmap = m_pBufferBitmap->GetBBitmap();
    assert( bitmap );

    BFont font;
    font_height fontHeight;
    BRect clipRect( float(oClipRect.x1), float(oClipRect.y1),
                    float(oClipRect.x2-1), float(oClipRect.y2-1) );
    BRegion clipRegion;
    clipRegion.Set( clipRect );

    if ( !bitmap->Lock() )
    {
        puts( "lock failed" );
        return 0;
    }

    v->ConstrainClippingRegion( &clipRegion );
    v->SetDrawingMode( B_OP_OVER );
    if ( bBold )
    {
        v->SetFont( be_bold_font );
    }
    else
    {
        v->SetFont( be_plain_font );
    }
    v->SetFontSize( (float)iFontHeight - 1 );
    v->GetFont( &font );
    font.GetHeight( &fontHeight );
    
    float width = v->StringWidth(oText.c_str(), oText.size());
    
    if(eAlign == eCenter)
        v->MovePenTo( float(oClipRect.x1) +
                      (float(oClipRect.x2 - oClipRect.x1) - width)/2,
                      float(oClipRect.y2-fontHeight.descent) );	
    else if (eAlign == eRight)
        v->MovePenTo( float(oClipRect.x2) - width,
                      float(oClipRect.y2-fontHeight.descent) );
    else
        v->MovePenTo( float(oClipRect.x1),
                      float(oClipRect.y2-fontHeight.descent) );

    v->DrawString( oText.c_str() );
    v->Sync();

    bitmap->Unlock();

    Invalidate( oClipRect );

    return (width < oClipRect.Width()) ? 0 : int(width - oClipRect.Width());
}
Пример #6
0
int
BeOSCanvas::RenderOffsetText( int iFontHeight, Rect& oClipRect,
                              string& oText, int iOffset,
                              Font* pFont, const Color& oColor,
                              bool bBold, bool bItalic,
                              bool bUnderline )
{
    Erase( oClipRect );

    BView* v = m_pBufferBitmap->OffscreenView();
    if ( !v ) return 0;

    BBitmap* bitmap = m_pBufferBitmap->GetBBitmap();

    BFont font;
    font_height fontHeight;
    BRect clipRect( float(oClipRect.x1), float(oClipRect.y1),
                    float(oClipRect.x2-1), float(oClipRect.y2-1) );
    BRegion clipRegion;
    clipRegion.Set( clipRect );

    if ( !bitmap->Lock() )
    {
        puts( "Lock Failed" );
        return 0;
    }

    v->ConstrainClippingRegion( &clipRegion );
    if ( bBold )
    {
        v->SetFont( be_bold_font );
    }
    else
    {
        v->SetFont( be_plain_font );
    }
    v->SetFontSize( (float)iFontHeight - 1 );
    v->GetFont( &font );
    font.GetHeight( &fontHeight );

    float width = v->StringWidth(oText.c_str(), oText.size());
    width += iMarqueeSpacer;

    if ( iOffset > width )
    {
        bitmap->Unlock();
        return int( width ) - iOffset;
    }

    v->MovePenTo( float(oClipRect.x1 - iOffset),
                  float(oClipRect.y2 - fontHeight.descent) );
    v->DrawString( oText.c_str() );
    int ret = int( width ) - iOffset - oClipRect.Width();
    if ( ret < 0 )
    {
        v->MovePenTo( float(oClipRect.x1 - iOffset + width),
                      float(oClipRect.y2 - fontHeight.descent) );
        v->DrawString( oText.c_str() );
    }

    v->Sync();
    bitmap->Unlock();

    Invalidate( oClipRect );

    return MAX( 0, ret );
}