MouseWindow::MouseWindow(BRect _rect) : BWindow(_rect, TR("Mouse"), B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS) { // Add the main settings view fSettingsView = new SettingsView(fSettings); fSettingsBox = new BBox("main box"); fSettingsBox->AddChild(fSettingsView); // Add the "Default" button fDefaultsButton = new BButton(TR("Defaults"), new BMessage(kMsgDefaults)); fDefaultsButton->SetEnabled(fSettings.IsDefaultable()); // Add the "Revert" button fRevertButton = new BButton(TR("Revert"), new BMessage(kMsgRevert)); fRevertButton->SetEnabled(false); SetPulseRate(100000); // we are using the pulse rate to scan pressed mouse // buttons and draw the selected imagery // Build the layout SetLayout(new BGroupLayout(B_VERTICAL)); AddChild(BGroupLayoutBuilder(B_VERTICAL, 10) .Add(fSettingsBox) .AddGroup(B_HORIZONTAL, 5) .Add(fDefaultsButton) .Add(fRevertButton) .AddGlue() .End() .SetInsets(10, 10, 10, 10) ); // check if the window is on screen BRect rect = BScreen().Frame(); rect.InsetBySelf(20, 20); BPoint position = fSettings.WindowPosition(); BRect windowFrame = Frame().OffsetToSelf(position); if (!rect.Contains(windowFrame)) { // center window on screen as it doesn't fit on the saved position position.x = (rect.Width() - windowFrame.Width()) / 2; position.y = (rect.Height() - windowFrame.Height()) / 2; if (position.x < 0) position.x = 0; if (position.y < 0) position.y = 15; } MoveTo(position); }
/*! * \brief Default constructor * \param[in] frame The rectangle enclosing the view * \param[in] name Name of the view. Will be passed to BView's constructor. * */ CalendarModulePreferencesView::CalendarModulePreferencesView( BRect frame ) : BView( BRect( frame.left, frame.top, frame.right, frame.bottom-10 ), "Calendar Module Preferences", B_FOLLOW_LEFT | B_FOLLOW_TOP, B_NAVIGABLE | B_WILL_DRAW | B_FRAME_EVENTS ) { BRect tempFrame = this->Bounds(); // Got the boundaries this->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) ); tempFrame.InsetBySelf( 5, 5 ); tempFrame.bottom -= 10; /* Add the chooser for the calendar modules */ BGroupLayout* groupLayout = new BGroupLayout( B_VERTICAL ); if ( !groupLayout ) { /* Panic! */ exit( 1 ); } groupLayout->SetSpacing( 2 ); this->SetLayout( groupLayout ); // Create the menu with all supported calendar modules calendarModules = PopulateModulesMenu(); if ( ! calendarModules ) { /* Panic! */ exit ( 1 ); } calendarModuleSelector = new BMenuField( BRect( 0, 0, this->Bounds().Width() - 10, 1 ), "Calendar Modules selector", "Calendar module:", calendarModules, B_FOLLOW_H_CENTER | B_FOLLOW_TOP ); if ( !calendarModuleSelector ) { /* Panic! */ exit ( 1 ); } calendarModuleSelector->ResizeToPreferred(); // Add the menu with all calendar modules to the layout BLayoutItem* layoutItem = groupLayout->AddView( 0, calendarModuleSelector, 1 ); if ( layoutItem ) { layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_CENTER, B_ALIGN_TOP ) ); } // Relayout groupLayout->Relayout(); } // <-- end of constructor for CalendarModulePreferencesView
/*! \function CategoryMenuItem::CreateIcon * \brief Create the square icon filled with submitted color. * \param[in] color The color of the requested icon. * \param[in] toChange If there is an allocated item, it may be changed. * If the submitted pointer is not NULL (which is default), * this BBitmap is tested for dimensions match, and if dimensions * allow, its contents are replaced with new icon. Else, old icon * is deleted, and a new is created. In this case, both the * "toChange" pointer and returned pointer point to the same * BBitmap. */ BBitmap* CategoryMenuItem::CreateIcon( const rgb_color color, BBitmap* toChange ) { BBitmap* toReturn = NULL; //!< This is the value to be returned. BRect tempRect; float width, height, squareSide; // Get size of the square this->GetContentSize( &width, &height ); squareSide = ceilf( height ) - 2; // Compare submitted bitmap to calculated size if ( toChange ) { tempRect = toChange->Bounds(); if ( ( tempRect.Width() != squareSide ) || ( tempRect.Height() != squareSide ) ) { // Dimensions don't match - need to delete the bitmap and reallocate it delete toChange; tempRect.Set( 0, 0, squareSide, squareSide ); toChange = new BBitmap( tempRect, B_RGB32, true ); if ( !toChange ) { /* Panic! */ exit(1); } toReturn = toChange; } else { /*! \note Note about color spaces * Actually, even if the dimensions are correct, the existing * BBitmap may be not suitable due to incorrect color space. * However, BBitmap may change the color space on its own, (and * probably will, since there's no much sense in having 32 bits * per pixel for bitmap with only 2 colors - black for the frame * and Category's color for the inside). Therefore, color space is * not checked. It's assumed that existing color space is good enough. */ // Dimensions match, color space is not checked - continuing toReturn = toChange; } } else // No bitmap is submitted { toReturn = new BBitmap( tempRect, B_RGB32, true ); if ( !toReturn ) { /* Panic! */ exit(1); } } /* Here toReturn is already set. */ // Add the drawing view to the bitmap tempRect.Set( 0, 0, squareSide, squareSide ); BView* drawing = new BView (tempRect, "Drawer", B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW); if (!drawing || !toReturn) { /* Panic! */ return NULL; } toReturn->AddChild(drawing); if (toReturn->Lock()) { // Clean the area drawing->SetHighColor( ui_color( B_MENU_BACKGROUND_COLOR ) ); drawing->FillRect( tempRect ); // Draw the black square drawing->SetHighColor( ui_color( B_MENU_ITEM_TEXT_COLOR ) ); drawing->SetPenSize( 1 ); drawing->StrokeRect( tempRect ); // Fill the inside of the square drawing->SetHighColor( color ); drawing->FillRect( tempRect.InsetBySelf( 1, 1 ) ); // Flush the actions to BBitmap drawing->Sync(); toReturn->Unlock(); } toReturn->RemoveChild( drawing ); delete drawing; return toReturn; } // <-- end of function "CategoryMenuItem::CreateIcon"
/*! \function ColorUpdateWindow::MessageReceived * \brief Main function */ void ColorUpdateWindow::MessageReceived( BMessage* in ) { BAlert* al = NULL; DebuggerPrintout* deb = NULL; BTextView* textView = NULL; BView* background = NULL; BMessenger* mesg = NULL; status_t errorCode = B_OK; BString currentString( this->originalString ); rgb_color previousHighColor; BRect tempRect; switch ( in->what ) { case kColorSelected: /* The user had make his choise. */ /* Checking if the color has changed... */ if ( colorControl ) { currentColor = colorControl->ValueAsColor(); if ( currentColor != originalColor ) { this->dirty = true; } } /* Checking if the string has changed... */ if ( enableEditingLabel ) { if ( labelView ) { // textView = ( BTextView* )labelView; // For matter of simplicity only currentString.SetTo( ( ( BTextControl* )labelView )->Text() ); if ( currentString != originalString ) // If there were changes { if ( ! utl_CheckStringValidity( currentString ) ) { // User has changed the string to an invalid one - // he must correct it before proceeding al = new BAlert("Error detected!", "The string you've entered is invalid. Please correct.", "Ok", NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT ); if ( al ) { al->Go(); break; // Returning to main window } else { /* Panic! */ exit(1); } } // <-- end of "if (string is not valid) " else { // String is valid - verify it's different if ( currentString != originalString ) { this->dirty = true; } } } // <-- end of "if (user changed the string) } // <-- end of "if ( BTextView exists )" } // <-- end of "if (user has possibility to change the string)" // If anything has changed, send the update message. Else, send revert message. if ( ! messageToSend ) { if ( this->dirty ) { this->messageToSend = new BMessage( kColorSelected ); } else { this->messageToSend = new BMessage( kColorReverted ); } if ( ! this->messageToSend ) { /* Panic! */ exit(1); } } // Stuff the message with needed data messageToSend->AddBool( "Dirty", this->dirty ); messageToSend->AddString ( "Original string", this->originalString ); if ( this->dirty ) { messageToSend->AddString("New string", currentString ); } messageToSend->AddInt32( "Original color", RepresentColorAsUint32( this->originalColor ) ); messageToSend->AddInt32( "New color", RepresentColorAsUint32( this->currentColor ) ); // Send the message and close current window // mesg = new BMessenger( (BHandler* )target, NULL, &errorCode ); mesg = new BMessenger( "application/x-vnd.Hitech.Skeleton", -1, &errorCode ); if ( errorCode == B_OK ) { mesg->SendMessage( messageToSend, ( BHandler* )NULL ); deb = new DebuggerPrintout( "Message was sent" ); } else { deb = new DebuggerPrintout( "Message wasn't sent" ); } this->Quit(); break; case kColorReverted: /* Returning to original settings */ if ( colorControl ) { colorControl->SetValue( originalColor ); colorControl->Invoke(); } if ( enableEditingLabel && this->labelView ) { ( (BTextControl*)this->labelView )->SetText( this->originalString.String() ); ( (BTextControl*)this->labelView )->MakeFocus( false ); // Prevent accidental change of text } break; case kColorChanged: // We need to reflect the change in color. // We'll do it using the current view's high color. For this, we need to // back up current high color in order to restore it later. background = this->FindView( "Background" ); if ( ! background ) { deb = new DebuggerPrintout( "Didn't find background!" ); return; } previousHighColor = background->HighColor(); background->SetHighColor( 0, 0, 1 ); // almost black tempRect = BRect( ( revertButton->Frame() ).right + 10, ( revertButton->Frame() ).top, ( okButton->Frame() ).left - 10, ( revertButton->Frame() ).bottom ); // Actual drawing if ( this->Lock() ) { background->SetPenSize( 1 ); // Create border background->StrokeRoundRect( tempRect.InsetBySelf( 1, 1 ), 4, 4 ); // Fill the rectangle background->SetHighColor( colorControl->ValueAsColor() ); background->FillRoundRect( tempRect.InsetBySelf( 1, 1 ), 4, 4 ); background->Flush(); this->Flush(); this->Unlock(); } background->SetHighColor( previousHighColor ); break; default: BWindow::MessageReceived( in ); }; } // <-- end of function "ColorUpdateWindow::MessageReceived"
AboutWindow::AboutWindow () : BWindow (BRect (0, 0, 300, 200), "About", B_MODAL_WINDOW, B_NOT_ZOOMABLE | B_NOT_MINIMIZABLE | B_NOT_RESIZABLE) { PRINT (("AboutWindow::AboutWindow ()\n")); SetFeel (B_MODAL_APP_WINDOW_FEEL); SetLook (B_MODAL_WINDOW_LOOK); /* Create the BBitmap objects and set its data with error checking */ BBitmap *appIcon = new BBitmap (BRect (0, 0, kLargeIconWidth - 1, kLargeIconHeight - 1), B_COLOR_8_BIT); appIcon->SetBits (iconBits, 32 * 32 * 8, 0, B_COLOR_8_BIT); BBitmap *bmp = BTranslationUtils::GetBitmap ('PNG ', "Image:AboutTitle"); if (bmp == NULL) { BAlert *err = new BAlert ("Error", "An error was encountered while " "trying to load the resource element \"Image:AboutTitle\"\n", "Hmm..", NULL, NULL, B_WIDTH_AS_USUAL, B_OFFSET_SPACING, B_STOP_ALERT); err->Go(); Hide(); Quit(); QuitRequested(); return; } /* Yet another annoying control rendering section :( */ BRect bounds (Bounds()); backView = new BView (bounds.InsetBySelf (1, 1), "AboutWindow:BackView", B_FOLLOW_ALL_SIDES, B_WILL_DRAW); AddChild (backView); iconView = new BView (BRect (1.5 * DialogMargin + 3, 1.5 * DialogMargin, 1.5 * DialogMargin + kLargeIconWidth - 1 + 3, 1.5 * DialogMargin + kLargeIconWidth - 1), "AboutWindow:IconView", B_FOLLOW_LEFT, B_WILL_DRAW); backView->AddChild (iconView); iconView->SetViewBitmap (appIcon); float left = DialogMargin + kLargeIconWidth + 1.5 * ButtonSpacing - 3; float top = DialogMargin / 2.0; titleView = new BView (BRect (left, top, 214 + left, 58 + top), "AboutWindow:TitleView", B_FOLLOW_LEFT, B_WILL_DRAW); backView->AddChild (titleView); titleView->SetViewBitmap (bmp); lineView = new BView (BRect (0, titleView->Frame().bottom + 3, bounds.right, titleView->Frame().bottom + 3), "AboutWindow:LineView", B_FOLLOW_LEFT, B_WILL_DRAW); lineView->SetViewColor (128, 128, 128); backView->AddChild (lineView); textView = new MarqueeView (BRect (2, lineView->Frame().bottom + ButtonSpacing / 2 + 2, bounds.right - DialogMargin - 1, bounds.bottom - 2 - ButtonSpacing / 2), "AboutWindow:CreditsView", BRect (0, 0, bounds.right - DialogMargin, 0), B_FOLLOW_LEFT, B_WILL_DRAW); backView->AddChild (textView); textView->SetStylable (true); textView->MakeSelectable (false); textView->MakeEditable (false); textView->SetAlignment (B_ALIGN_CENTER); textView->SetViewColor (BePureWhite); backView->SetViewColor (BePureWhite); textView->SetFontAndColor (be_plain_font, B_FONT_ALL, &BeJetBlack); /* Calculate no of '\n's to leave to make the text go to the bottom, calculate the no. of lines */ font_height fntHt; textView->GetFontHeight (&fntHt); int32 noOfLines = (int32)(textView->Frame().Height() / fntHt.ascent) - 1; for (int32 i = 1; i < (int32)noOfLines; i++) lineFeeds << "\n"; creditsText = "Freeware, Version " AppVersion "\n" "Copyright " B_UTF8_COPYRIGHT " 2002 Ramshankar\n\n\n" CODING "\nRamshankar\n([email protected])\n\n* * *\n\n\n\n\n\n\n\n\n" THANKS_TO "\n\n" BUBBLEHELP "\nMarco Nelissen\n\n" BESHARE "\nJeremy Friesner\n\n" "Thank you all for your\n" "contributions with the code...\n\n* * *\n\n\n\n\n\n\n\n\n" "Also thanks to\n\n" "John Trujillo\nSebastian Benner\nM Floro\n\n" "for your support and contributions...\n\n* * *\n\n\n\n\n\n\n\n\n" "A special round of applause\n" "to BeShare members (in no\n" "particular order) :\n\n" "lillo\nshatty\nProcton\n" "Bryan\nPahtz\nmmu_man\nBeMikko\nNeil\nskiBUM\nand " "others\n\n" "for being so good... :)\n\n* * *\n\n\n\n\n\n\n\n\n" LEGAL_MUMBO_JUMBO "\n\n" "This program is distributed under\n" "its own license, and the gist of\n" "the license is attached to each\n" "source file of this program\n\n" "For third party code, the license's\n" "terms and conditions are explicitly\n" "stated and the author disclaimed of\n" "any and all liabilities\n\n" "For the full license read the\n" "file \"License.txt\" and for\n" "information on how to use this\n" "program read \"Readme.txt\"\n\n* * *\n\n\n\n\n\n\n\n\n" DISCLAIMER "\n\n" "Because the software is licensed\n" "free of charge, there is no warranty\n" "for the software. The copyright\n" "holders and/or other parties provide\n" "the software \"AS IS\" without warranty\n" "of any kind, either expressed or\n" "implied, including, but not limited to,\n" "the implied warranties of merchantability\n" "and fitness for a particular purpose.\n" "The entire risk as to the quality and\n" "performance of the software is with you.\n" "Should the software prove defective, you\n" "assume the cost of all necessary\n" "servicing, repair or correction.\n\n" "In no event will the copyright holder,\n" "or any other party who may modify and/or\n" "redistribute the software as permitted\n" "above, be liable to you for damages,\n" "including any general, special, incidental\n" "or consequential damages arising out of\n" "the use or inability to use the software\n" "(including but not limited to the loss of\n" "data or data being rendered inaccurate or\n" "losses sustained by you or third parties\n" "or a failure of the software to operate\n" "with any other programs), even if such\n" "holder or other party has been advised\n" "of the possibility of such damages.\n\n\n\n\n\n\n\n\n" FINAL_THANKS "\n\n" "Be, Inc., for making this OS\n" "in the first place\n\n" "OpenBeOS for their efforts to\n" "keep BeOS alive\n\n" "BeBits.com, BeGroovy.com, BeZip.de and\n" "other BeOS related sites for their\n" "continued enthusiasm and effort!\n\n" "BeOS programmers, designers, artists for\n" "their contributions to the OS' growth\n\n" "and a big applause goes to the Be\n" "community (it includes me too :)\n\n* * *\n\n\n\n\n\n\n\n\n" "OK... you can close this window now :)\n\n\n\n\n\n"; textView->SetText (lineFeeds.String()); textView->Insert (lineFeeds.Length(), creditsText, strlen(creditsText)); int32 nSubHeadings = 4; BString subHeadings[] = { CODING, // 0 BUBBLEHELP, // 2 BESHARE, // 3 DISCLAIMER // 4 }; int32 nMainHeadings = 3; BString mainHeadings[] = { THANKS_TO, // 0 LEGAL_MUMBO_JUMBO, // 1 FINAL_THANKS // 2 }; /* Search and color sub headings */ BString temp = textView->Text(); int32 strt; for (int32 i = 0; i < nSubHeadings; i++) { if ((strt = temp.FindFirst (subHeadings[i].String())) != B_ERROR) { textView->SetFontAndColor (strt, strt + strlen(subHeadings[i].String()), be_plain_font, B_FONT_ALL, &TreeLabelColor); } } /* Search and color main headings */ for (int32 i = 0; i < nMainHeadings; i++) { if ((strt = temp.FindFirst (mainHeadings[i].String())) != B_ERROR) { textView->SetFontAndColor (strt, strt + strlen(mainHeadings[i].String()), be_plain_font, B_FONT_ALL, &(rgb_color){0, 0, 200}); } } /* Center window on-screen */ BRect screen_rect (BScreen().Frame()); MoveTo (screen_rect.Width() / 2 - Frame().Width() / 2, screen_rect.Height() / 2 - Frame().Height() / 2); /* Delete unwanted stuff */ delete appIcon; delete bmp; /* Spawn & resume the scroller thread now */ PRINT ((" >> spawning_thread: Magic_Scroll\n")); thread_id tid = spawn_thread (ScrollIt, "Magic_Scroll", B_NORMAL_PRIORITY, (void*)this); resume_thread (tid); }
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(®ion); 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(®ion); fOffscreen->UnlockLooper(); Invalidate(®ion); 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(®ion, pattern); else { BGradient *gradient; if (message.ReadGradient(&gradient) != B_OK) continue; offscreen->FillRegion(®ion, *gradient); delete gradient; } invalidRegion.Include(®ion); 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); } } }
BView * DefaultMediaTheme::MakeViewFor(BParameterGroup& group, const BRect* hintRect) { CALLED(); if (group.Flags() & B_HIDDEN_PARAMETER) return NULL; BRect rect; if (hintRect != NULL) rect = *hintRect; GroupView *view = new GroupView(rect, group.Name()); // Create the parameter views - but don't add them yet rect.OffsetTo(B_ORIGIN); rect.InsetBySelf(5, 5); BList views; for (int32 i = 0; i < group.CountParameters(); i++) { BParameter *parameter = group.ParameterAt(i); if (parameter == NULL) continue; BView *parameterView = MakeSelfHostingViewFor(*parameter, hintRect ? &rect : NULL); if (parameterView == NULL) continue; parameterView->SetViewColor(view->ViewColor()); // ToDo: dunno why this is needed, but the controls // sometimes (!) have a white background without it views.AddItem(parameterView); } // Identify a title view, and add it at the top if present TitleView *titleView = dynamic_cast<TitleView *>((BView *)views.ItemAt(0)); if (titleView != NULL) { view->AddChild(titleView); rect.OffsetBy(0, titleView->Bounds().Height()); } // Add the sub-group views rect.right = rect.left + 20; rect.bottom = rect.top + 20; float lastHeight = 0; for (int32 i = 0; i < group.CountGroups(); i++) { BParameterGroup *subGroup = group.GroupAt(i); if (subGroup == NULL) continue; BView *groupView = MakeViewFor(*subGroup, &rect); if (groupView == NULL) continue; if (i > 0) { // add separator view BRect separatorRect(groupView->Frame()); separatorRect.left -= 3; separatorRect.right = separatorRect.left + 1; if (lastHeight > separatorRect.Height()) separatorRect.bottom = separatorRect.top + lastHeight; view->AddChild(new SeparatorView(separatorRect)); } view->AddChild(groupView); rect.OffsetBy(groupView->Bounds().Width() + 5, 0); lastHeight = groupView->Bounds().Height(); if (lastHeight > rect.Height()) rect.bottom = rect.top + lastHeight - 1; } view->ResizeTo(rect.left + 10, rect.bottom + 5); view->SetContentBounds(view->Bounds()); if (group.CountParameters() == 0) return view; // add the parameter views part of the group if (group.CountGroups() > 0) { rect.top = rect.bottom + 10; rect.bottom = rect.top + 20; } bool center = false; for (int32 i = 0; i < views.CountItems(); i++) { BView *parameterView = static_cast<BView *>(views.ItemAt(i)); if (parameterView->Bounds().Width() + 5 > rect.Width()) rect.right = parameterView->Bounds().Width() + rect.left + 5; // we don't need to add the title view again if (parameterView == titleView) continue; // if there is a BChannelSlider (ToDo: or any vertical slider?) // the views will be centered if (dynamic_cast<BChannelSlider *>(parameterView) != NULL) center = true; parameterView->MoveTo(parameterView->Frame().left, rect.top); view->AddChild(parameterView); rect.OffsetBy(0, parameterView->Bounds().Height() + 5); } if (views.CountItems() > (titleView != NULL ? 1 : 0)) view->ResizeTo(rect.right + 5, rect.top + 5); // center the parameter views if needed, and tweak some views float width = view->Bounds().Width(); for (int32 i = 0; i < views.CountItems(); i++) { BView *subView = static_cast<BView *>(views.ItemAt(i)); BRect frame = subView->Frame(); if (center) subView->MoveTo((width - frame.Width()) / 2, frame.top); else { // tweak the PopUp views to look better if (dynamic_cast<BOptionPopUp *>(subView) != NULL) subView->ResizeTo(width, frame.Height()); } } view->SetContentBounds(view->Bounds()); return view; }
/*! \brief Builds the interface for a selected calendar module. * \param[in] id Name of the calendar module to build the interface for. * \details If the interface for a module already exists, this function * deletes it without affecting the already set preferences. */ void CalendarModulePreferencesView::BuildInterfaceForModule( const BString& id ) { BGroupLayout* layout = ( BGroupLayout* )( BView::GetLayout() ); BLayoutItem* layoutItem = NULL; BBox* tempBBox = NULL; if ( !this->Window() || this->Window()->Lock() ) { // First, clean up old interface items if they existed this->ClearOldInterface(); // Prepare the frame for the BBox for weekends selection BRect r = this->Bounds(); r.InsetBySelf( 5, 5 ); r.right -= 10; r.bottom -= 10; if ( calendarModuleSelector ) r.top += ( calendarModuleSelector->Bounds().Height() + 10 ); // Build weekend selection tempBBox = CreateWeekendSelectionBox( r, id ); if ( tempBBox ) { // After the call, the BBox is resized to minimal required size. layoutItem = layout->AddView( 1, tempBBox, 0 ); layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_CENTER, B_ALIGN_TOP ) ); } else { utl_Deb = new DebuggerPrintout( "Error - Weekend selection box is NULL." ); } // Start day chooser BMenuField* startDayChooser = CreateWeekStartDayChooser( r, id ); if ( startDayChooser ) { layoutItem = layout->AddView( 2, startDayChooser, 0 ); if ( layoutItem ) layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_LEFT, B_ALIGN_TOP ) ); } // Day-month-year order BMenuField* dmyChooser = CreateDayMonthYearOrderChooser( r, id ); if ( dmyChooser ) { layoutItem = layout->AddView( 3, dmyChooser, 0 ); if ( layoutItem ) layoutItem->SetExplicitAlignment( BAlignment( B_ALIGN_LEFT, B_ALIGN_TOP ) ); } // Colors selection tempBBox = BuildColorSelectors( r, id ); if ( tempBBox ) { layoutItem = layout->AddView( 4, tempBBox, 0 ); } /* At the end, all children are targetted at current window */ UpdateTargetting(); if ( this->Window() ) { this->Window()->Unlock(); } } // <-- end of lock-only section } // <-- end of function CalendarModulePreferencesView::BuildInterfaceForModule