* Replaced some "new" with new(std::nothrow) where appropriate in our base

classes (BView, BWindow, BAlert, BButton - BTextView should be part of this,
  too, to make BAlerts work).
* However, it's not that simple, because there is often no way to return an
  error. Most of that code obviously assumes to be able to throw exceptions
  (it's just not communicated to the caller). Maybe we should just start
  documenting exceptions for R1 (and properly use exceptions later on).
* Automatic white space cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28646 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2008-11-14 10:23:38 +00:00
parent d662196ed0
commit eaccfb9dd0
4 changed files with 161 additions and 132 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2001-2006, Haiku.
* Copyright 2001-2008, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
@ -73,7 +73,7 @@ icon_layout_scale()
#ifdef __HAIKU__
return max_c(1, ((int32)be_plain_font->Size() + 15) / 16);
#endif
return 1;
return 1;
}
@ -182,7 +182,7 @@ BAlert::BAlert(BMessage* data)
if (data->FindInt32("_but_width", &temp) == B_OK)
fButtonWidth = (button_width)temp;
AddCommonFilter(new _BAlertFilter_(this));
AddCommonFilter(new(std::nothrow) _BAlertFilter_(this));
}
@ -192,7 +192,7 @@ BAlert::Instantiate(BMessage* data)
if (!validate_instantiation(data, "BAlert"))
return NULL;
return new BAlert(data);
return new(std::nothrow) BAlert(data);
}
@ -440,7 +440,7 @@ void BAlert::_ReservedAlert2() {}
void BAlert::_ReservedAlert3() {}
void
void
BAlert::_InitObject(const char* text, const char* button0, const char* button1,
const char* button2, button_width buttonWidth, button_spacing spacing,
alert_type type)
@ -455,7 +455,10 @@ BAlert::_InitObject(const char* text, const char* button0, const char* button1,
fButtonWidth = buttonWidth;
// Set up the "_master_" view
TAlertView* view = new TAlertView(Bounds());
TAlertView* view = new(std::nothrow) TAlertView(Bounds());
if (view == NULL)
return;
AddChild(view);
view->SetBitmap(_InitIcon());
@ -541,9 +544,12 @@ BAlert::_InitObject(const char* text, const char* button0, const char* button1,
textViewRect.left = (kWindowIconOffset
+ kIconStripeWidth) * iconLayoutScale - 2;
fTextView = new BTextView(textViewRect, "_tv_",
fTextView = new(std::nothrow) BTextView(textViewRect, "_tv_",
textViewRect.OffsetByCopy(B_ORIGIN),
B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW);
if (fTextView == NULL)
return;
fTextView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
rgb_color textColor = ui_color(B_PANEL_TEXT_COLOR);
fTextView->SetFontAndColor(be_plain_font, B_FONT_ALL, &textColor);
@ -562,7 +568,7 @@ BAlert::_InitObject(const char* text, const char* button0, const char* button1,
textViewRect.bottom += textHeight;
fTextView->SetTextRect(textViewRect);
AddCommonFilter(new _BAlertFilter_(this));
AddCommonFilter(new(std::nothrow) _BAlertFilter_(this));
MoveTo(AlertPosition(Frame().Width(), Frame().Height()));
}
@ -602,7 +608,7 @@ BAlert::_InitIcon()
strerror(status)));
return NULL;
}
// Which icon are we trying to load?
const char* iconName = ""; // Don't want any seg faults
switch (alertType) {
@ -627,7 +633,7 @@ BAlert::_InitIcon()
int32 iconSize = 32 * icon_layout_scale();
// Allocate the icon bitmap
icon = new (std::nothrow) BBitmap(BRect(0, 0, iconSize - 1, iconSize - 1),
icon = new(std::nothrow) BBitmap(BRect(0, 0, iconSize - 1, iconSize - 1),
0, B_RGBA32);
if (icon == NULL || icon->InitCheck() < B_OK) {
FTRACE((stderr, "BAlert::_InitIcon() - No memory for bitmap\n"));
@ -693,7 +699,7 @@ BAlert::_CreateButton(int32 which, const char* label)
char name[32];
snprintf(name, sizeof(name), "_b%ld_", which);
BButton* button = new (std::nothrow) BButton(rect, name, label, message,
BButton* button = new(std::nothrow) BButton(rect, name, label, message,
B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
if (button == NULL)
return NULL;
@ -742,7 +748,7 @@ TAlertView::Instantiate(BMessage* archive)
if (!validate_instantiation(archive, "TAlertView"))
return NULL;
return new TAlertView(archive);
return new(std::nothrow) TAlertView(archive);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2001-2005, Haiku.
* Copyright 2001-2008, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
@ -13,6 +13,8 @@
#include <Button.h>
#include <new>
#include <Font.h>
#include <LayoutUtils.h>
#include <String.h>
@ -21,12 +23,12 @@
#include <binary_compatibility/Interface.h>
BButton::BButton(BRect frame, const char *name, const char *label, BMessage *message,
uint32 resizingMode, uint32 flags)
: BControl(frame, name, label, message, resizingMode,
BButton::BButton(BRect frame, const char* name, const char* label,
BMessage* message, uint32 resizingMode, uint32 flags)
: BControl(frame, name, label, message, resizingMode,
flags | B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE),
fPreferredSize(-1, -1),
fDrawAsDefault(false)
fPreferredSize(-1, -1),
fDrawAsDefault(false)
{
// Resize to minimum height if needed
font_height fh;
@ -37,21 +39,21 @@ BButton::BButton(BRect frame, const char *name, const char *label, BMessage *mes
}
BButton::BButton(const char* name, const char* label, BMessage *message,
uint32 flags)
: BControl(name, label, message,
BButton::BButton(const char* name, const char* label, BMessage* message,
uint32 flags)
: BControl(name, label, message,
flags | B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE),
fPreferredSize(-1, -1),
fDrawAsDefault(false)
fPreferredSize(-1, -1),
fDrawAsDefault(false)
{
}
BButton::BButton(const char* label, BMessage *message)
: BControl(NULL, label, message,
BButton::BButton(const char* label, BMessage* message)
: BControl(NULL, label, message,
B_WILL_DRAW | B_NAVIGABLE | B_FULL_UPDATE_ON_RESIZE),
fPreferredSize(-1, -1),
fDrawAsDefault(false)
fPreferredSize(-1, -1),
fDrawAsDefault(false)
{
}
@ -61,9 +63,9 @@ BButton::~BButton()
}
BButton::BButton(BMessage *archive)
: BControl(archive),
fPreferredSize(-1, -1)
BButton::BButton(BMessage* archive)
: BControl(archive),
fPreferredSize(-1, -1)
{
if (archive->FindBool("_default", &fDrawAsDefault) != B_OK)
fDrawAsDefault = false;
@ -72,11 +74,11 @@ BButton::BButton(BMessage *archive)
}
BArchivable *
BButton::Instantiate(BMessage *archive)
BArchivable*
BButton::Instantiate(BMessage* archive)
{
if (validate_instantiation(archive, "BButton"))
return new BButton(archive);
return new(std::nothrow) BButton(archive);
return NULL;
}
@ -89,7 +91,7 @@ BButton::Archive(BMessage* archive, bool deep) const
if (err != B_OK)
return err;
if (IsDefault())
err = archive->AddBool("_default", true);
@ -102,10 +104,10 @@ BButton::Draw(BRect updateRect)
{
font_height fh;
GetFontHeight(&fh);
const BRect bounds = Bounds();
BRect rect = bounds;
const bool enabled = IsEnabled();
const bool pushed = Value() == B_CONTROL_ON;
#if 0
@ -119,49 +121,49 @@ BButton::Draw(BRect updateRect)
fillArea.InsetBy(3.0f, 3.0f);
BString text = Label();
#if 1
// Label truncation
// Label truncation
BFont font;
GetFont(&font);
font.TruncateString(&text, B_TRUNCATE_END, fillArea.Width());
#endif
// Label position
const float stringWidth = StringWidth(text.String());
const float stringWidth = StringWidth(text.String());
const float x = (bounds.right - stringWidth) / 2.0f;
const float labelY = bounds.top
+ ((bounds.Height() - fh.ascent - fh.descent) / 2.0f)
+ fh.ascent + 1.0f;
const float labelY = bounds.top
+ ((bounds.Height() - fh.ascent - fh.descent) / 2.0f)
+ fh.ascent + 1.0f;
const float focusLineY = labelY + fh.descent;
/* speed trick:
if the focus changes but the button is not pressed then we can
redraw only the focus line,
if the focus changes and the button is pressed invert the internal rect
this block takes care of all the focus changes
redraw only the focus line,
if the focus changes and the button is pressed invert the internal rect
this block takes care of all the focus changes
*/
if (IsFocusChanging()) {
if (IsFocusChanging()) {
if (pushed) {
rect.InsetBy(2.0, 2.0);
InvertRect(rect);
} else
} else
DrawFocusLine(x, focusLineY, stringWidth, IsFocus() && Window()->IsActive());
return;
}
// Colors
// Colors
const rgb_color panelBgColor = ui_color(B_PANEL_BACKGROUND_COLOR);
const rgb_color buttonBgColor=tint_color(panelBgColor, B_LIGHTEN_1_TINT);
const rgb_color maxLightColor=tint_color(panelBgColor, B_LIGHTEN_MAX_TINT);
const rgb_color maxShadowColor=tint_color(panelBgColor, B_DARKEN_MAX_TINT);
const rgb_color darkBorderColor = tint_color(panelBgColor,
const rgb_color buttonBgColor=tint_color(panelBgColor, B_LIGHTEN_1_TINT);
const rgb_color maxLightColor=tint_color(panelBgColor, B_LIGHTEN_MAX_TINT);
const rgb_color maxShadowColor=tint_color(panelBgColor, B_DARKEN_MAX_TINT);
const rgb_color darkBorderColor = tint_color(panelBgColor,
enabled ? B_DARKEN_4_TINT : B_DARKEN_2_TINT);
const rgb_color firstBevelColor = enabled ? tint_color(panelBgColor, B_DARKEN_2_TINT)
const rgb_color firstBevelColor = enabled ? tint_color(panelBgColor, B_DARKEN_2_TINT)
: panelBgColor;
const rgb_color cornerColor = IsDefault() ? firstBevelColor : panelBgColor;
// Fill the button area
SetHighColor(buttonBgColor);
FillRect(fillArea);
@ -169,7 +171,7 @@ BButton::Draw(BRect updateRect)
// external border
SetHighColor(darkBorderColor);
StrokeRect(rect);
BeginLineArray(14);
// Corners
@ -179,30 +181,30 @@ BButton::Draw(BRect updateRect)
AddLine(rect.RightBottom(), rect.RightBottom(), cornerColor);
rect.InsetBy(1.0f,1.0f);
// Shadow
AddLine(rect.LeftBottom(), rect.RightBottom(), firstBevelColor);
AddLine(rect.RightBottom(), rect.RightTop(), firstBevelColor);
// Light
AddLine(rect.LeftTop(), rect.LeftBottom(),buttonBgColor);
AddLine(rect.LeftTop(), rect.RightTop(), buttonBgColor);
AddLine(rect.LeftTop(), rect.RightTop(), buttonBgColor);
rect.InsetBy(1.0f, 1.0f);
// Shadow
AddLine(rect.LeftBottom(), rect.RightBottom(), panelBgColor);
AddLine(rect.RightBottom(), rect.RightTop(), panelBgColor);
// Light
AddLine(rect.LeftTop(), rect.LeftBottom(),maxLightColor);
AddLine(rect.LeftTop(), rect.RightTop(), maxLightColor);
AddLine(rect.LeftTop(), rect.RightTop(), maxLightColor);
rect.InsetBy(1.0f,1.0f);
// Light
AddLine(rect.LeftTop(), rect.LeftBottom(),maxLightColor);
AddLine(rect.LeftTop(), rect.RightTop(), maxLightColor);
EndLineArray();
AddLine(rect.LeftTop(), rect.RightTop(), maxLightColor);
EndLineArray();
// Invert if clicked
if (enabled && pushed) {
@ -216,12 +218,12 @@ BButton::Draw(BRect updateRect)
SetHighColor(maxLightColor);
SetLowColor(maxShadowColor);
} else {
SetHighColor(maxShadowColor);
SetHighColor(maxShadowColor);
SetLowColor(tint_color(panelBgColor, B_LIGHTEN_2_TINT));
}
} else {
SetHighColor(tint_color(panelBgColor, B_DISABLED_LABEL_TINT));
SetLowColor(tint_color(panelBgColor, B_LIGHTEN_2_TINT));
SetLowColor(tint_color(panelBgColor, B_LIGHTEN_2_TINT));
}
// Draw the label
@ -239,16 +241,16 @@ BButton::Draw(BRect updateRect)
fillArea.InsetBy(3.0, 3.0);
BString text = Label();
#if 1
// Label truncation
// Label truncation
BFont font;
GetFont(&font);
font.TruncateString(&text, B_TRUNCATE_END, fillArea.Width() - 4);
#endif
// Label position
const float stringWidth = StringWidth(text.String());
const float stringWidth = StringWidth(text.String());
const float x = (rect.right - stringWidth) / 2.0;
const float labelY = bounds.top
+ ((bounds.Height() - fh.ascent - fh.descent) / 2.0)
@ -257,11 +259,11 @@ BButton::Draw(BRect updateRect)
/* speed trick:
if the focus changes but the button is not pressed then we can
redraw only the focus line,
if the focus changes and the button is pressed invert the internal rect
this block takes care of all the focus changes
redraw only the focus line,
if the focus changes and the button is pressed invert the internal rect
this block takes care of all the focus changes
*/
if (IsFocusChanging()) {
if (IsFocusChanging()) {
if (pushed) {
rect.InsetBy(2.0, 2.0);
InvertRect(rect);
@ -269,16 +271,16 @@ BButton::Draw(BRect updateRect)
DrawFocusLine(x, focusLineY, stringWidth, IsFocus()
&& Window()->IsActive());
}
return;
}
// colors
// colors
rgb_color panelBgColor = ui_color(B_PANEL_BACKGROUND_COLOR);
rgb_color buttonBgColor = tint_color(panelBgColor, B_LIGHTEN_1_TINT);
rgb_color buttonBgColor = tint_color(panelBgColor, B_LIGHTEN_1_TINT);
rgb_color lightColor;
rgb_color maxLightColor;
rgb_color maxShadowColor = tint_color(panelBgColor, B_DARKEN_MAX_TINT);
rgb_color maxLightColor;
rgb_color maxShadowColor = tint_color(panelBgColor, B_DARKEN_MAX_TINT);
rgb_color dark1BorderColor;
rgb_color dark2BorderColor;
@ -292,11 +294,11 @@ BButton::Draw(BRect updateRect)
if (enabled) {
lightColor = tint_color(panelBgColor, B_LIGHTEN_2_TINT);
maxLightColor = tint_color(panelBgColor, B_LIGHTEN_MAX_TINT);
maxLightColor = tint_color(panelBgColor, B_LIGHTEN_MAX_TINT);
dark1BorderColor = tint_color(panelBgColor, B_DARKEN_3_TINT);
dark2BorderColor = tint_color(panelBgColor, B_DARKEN_4_TINT);
bevelColor1 = tint_color(panelBgColor, B_DARKEN_2_TINT);
bevelColor2 = panelBgColor;
@ -311,7 +313,7 @@ BButton::Draw(BRect updateRect)
+ panelBgColor.green) / 2;
borderBevelLight.blue = (borderBevelLight.blue
+ panelBgColor.blue) / 2;
dark1BorderColor = tint_color(dark1BorderColor, B_DARKEN_3_TINT);
dark2BorderColor = tint_color(dark1BorderColor, B_DARKEN_4_TINT);
@ -325,11 +327,11 @@ BButton::Draw(BRect updateRect)
}
} else {
lightColor = tint_color(panelBgColor, B_LIGHTEN_2_TINT);
maxLightColor = tint_color(panelBgColor, B_LIGHTEN_1_TINT);
maxLightColor = tint_color(panelBgColor, B_LIGHTEN_1_TINT);
dark1BorderColor = tint_color(panelBgColor, B_DARKEN_1_TINT);
dark2BorderColor = tint_color(panelBgColor, B_DARKEN_2_TINT);
bevelColor1 = panelBgColor;
bevelColor2 = buttonBgColor;
@ -376,7 +378,7 @@ BButton::Draw(BRect updateRect)
BPoint(rect.left + 1, rect.bottom), dark2BorderColor);
rect.InsetBy(1.0, 1.0);
// Light
AddLine(BPoint(rect.left, rect.top),
BPoint(rect.left, rect.top), buttonBgColor);
@ -385,9 +387,9 @@ BButton::Draw(BRect updateRect)
AddLine(BPoint(rect.left, rect.bottom),
BPoint(rect.left, rect.bottom), bevelColor2);
AddLine(BPoint(rect.left + 1, rect.top),
BPoint(rect.right - 1, rect.top), lightColor);
BPoint(rect.right - 1, rect.top), lightColor);
AddLine(BPoint(rect.right, rect.top),
BPoint(rect.right, rect.top), bevelColor2);
BPoint(rect.right, rect.top), bevelColor2);
// Shadow
AddLine(BPoint(rect.left + 1, rect.bottom),
BPoint(rect.right - 1, rect.bottom), bevelColor1);
@ -395,27 +397,27 @@ BButton::Draw(BRect updateRect)
BPoint(rect.right, rect.bottom), bevelColorRBCorner);
AddLine(BPoint(rect.right, rect.bottom - 1),
BPoint(rect.right, rect.top + 1), bevelColor1);
rect.InsetBy(1.0, 1.0);
// Light
AddLine(BPoint(rect.left, rect.top),
BPoint(rect.left, rect.bottom - 1), maxLightColor);
AddLine(BPoint(rect.left, rect.bottom),
BPoint(rect.left, rect.bottom), buttonBgColor);
AddLine(BPoint(rect.left + 1, rect.top),
BPoint(rect.right - 1, rect.top), maxLightColor);
BPoint(rect.right - 1, rect.top), maxLightColor);
AddLine(BPoint(rect.right, rect.top),
BPoint(rect.right, rect.top), buttonBgColor);
BPoint(rect.right, rect.top), buttonBgColor);
// Shadow
AddLine(BPoint(rect.left + 1, rect.bottom),
BPoint(rect.right, rect.bottom), bevelColor2);
AddLine(BPoint(rect.right, rect.bottom - 1),
BPoint(rect.right, rect.top + 1), bevelColor2);
rect.InsetBy(1.0,1.0);
EndLineArray();
EndLineArray();
// Invert if clicked
if (enabled && pushed) {
@ -436,7 +438,7 @@ BButton::Draw(BRect updateRect)
}
} else {
SetHighColor(tint_color(panelBgColor, B_DISABLED_LABEL_TINT));
SetLowColor(buttonBgColor);
SetLowColor(buttonBgColor);
}
// Draw the label
@ -445,7 +447,7 @@ BButton::Draw(BRect updateRect)
// Focus line
if (enabled && IsFocus() && Window()->IsActive() && !pushed)
DrawFocusLine(x, focusLineY, stringWidth, true);
#endif
#endif
}
@ -520,7 +522,7 @@ BButton::MakeDefault(bool flag)
{
BButton *oldDefault = NULL;
BWindow *window = Window();
if (window)
oldDefault = window->DefaultButton();
@ -601,7 +603,7 @@ BButton::MouseUp(BPoint point)
if (Bounds().Contains(point))
Invoke();
SetTracking(false);
}
@ -646,7 +648,7 @@ BButton::Invoke(BMessage *message)
{
Sync();
snooze(50000);
status_t err = BControl::Invoke(message);
SetValue(B_CONTROL_OFF);
@ -815,7 +817,7 @@ BButton::DrawDefault(BRect bounds, bool enabled)
rgb_color no_tint = ui_color(B_PANEL_BACKGROUND_COLOR),
lighten1 = tint_color(no_tint, B_LIGHTEN_1_TINT),
darken1 = tint_color(no_tint, B_DARKEN_1_TINT);
rgb_color borderColor;
if (enabled)
borderColor = tint_color(no_tint, B_DARKEN_4_TINT);
@ -847,9 +849,9 @@ BButton::DrawDefault(BRect bounds, bool enabled)
float inset = enabled? 2.0f : 3.0f;
SetHighColor(lighten1);
FillRect(BRect(bounds.left, bounds.top,
FillRect(BRect(bounds.left, bounds.top,
bounds.right, bounds.top+inset-1.0f));
FillRect(BRect(bounds.left, bounds.bottom-inset+1.0f,
FillRect(BRect(bounds.left, bounds.bottom-inset+1.0f,
bounds.right, bounds.bottom));
FillRect(BRect(bounds.left, bounds.top+inset-1.0f,
bounds.left+inset-1.0f, bounds.bottom-inset+1.0f));
@ -902,7 +904,7 @@ BButton::DrawFocusLine(float x, float y, float width, bool visible)
// Blue Line
StrokeLine(BPoint(x, y), BPoint(x + width, y));
if (visible)
if (visible)
SetHighColor(255, 255, 255);
// White Line
StrokeLine(BPoint(x, y + 1.0f), BPoint(x + width, y + 1.0f));
@ -926,7 +928,7 @@ BButton::_ValidatePreferredSize()
// height
font_height fontHeight;
GetFontHeight(&fontHeight);
fPreferredSize.height
= ceilf((fontHeight.ascent + fontHeight.descent) * 1.8)
+ (fDrawAsDefault ? 6.0f : 0);

View File

@ -482,7 +482,7 @@ BView::Instantiate(BMessage *data)
if (!validate_instantiation(data , "BView"))
return NULL;
return new BView(data);
return new(std::nothrow) BView(data);
}
@ -1265,11 +1265,14 @@ BView::DragMessage(BMessage *message, BRect dragRect, BHandler *replyTo)
return;
}
// TODO: that's not really what should happen - the app_server should take the chance
// *NOT* to need to drag a whole bitmap around but just a frame.
// TODO: that's not really what should happen - the app_server should take
// the chance *NOT* to need to drag a whole bitmap around but just a frame.
// create a drag bitmap for the rect
BBitmap *bitmap = new BBitmap(dragRect, B_RGBA32);
BBitmap *bitmap = new(std::nothrow) BBitmap(dragRect, B_RGBA32);
if (bitmap == NULL)
return;
uint32 *bits = (uint32*)bitmap->Bits();
uint32 bytesPerRow = bitmap->BytesPerRow();
uint32 width = dragRect.IntegerWidth() + 1;
@ -1316,7 +1319,7 @@ BView::DragMessage(BMessage *message, BBitmap *image,
if (image == NULL) {
// TODO: workaround for drags without a bitmap - should not be necessary if
// we move the rectangle dragging into the app_server
image = new (nothrow) BBitmap(BRect(0, 0, 0, 0), B_RGBA32);
image = new(std::nothrow) BBitmap(BRect(0, 0, 0, 0), B_RGBA32);
if (image == NULL)
return;
}
@ -1348,8 +1351,8 @@ BView::DragMessage(BMessage *message, BBitmap *image,
// TODO: create area and flatten message into that area!
// send area info over port, not the actual message!
int32 bufferSize = privateMessage.NativeFlattenedSize();
char* buffer = new (nothrow) char[bufferSize];
if (buffer) {
char* buffer = new(std::nothrow) char[bufferSize];
if (buffer != NULL) {
privateMessage.NativeFlatten(buffer, bufferSize);
fOwner->fLink->StartMessage(AS_VIEW_DRAG_IMAGE);
@ -3373,12 +3376,14 @@ BView::BeginLineArray(int32 count)
// not fatal, but it helps during
// development of your app and is in
// line with R5...
delete [] fCommArray->array;
delete[] fCommArray->array;
delete fCommArray;
}
// TODO: since this method cannot return failure, and further AddLine()
// calls with a NULL fCommArray would drop into the debugger anyway,
// we allow the possible std::bad_alloc exceptions here...
fCommArray = new _array_data_;
fCommArray->maxCount = count;
fCommArray->count = 0;
fCommArray->array = new _array_hdr_[count];
@ -4631,7 +4636,7 @@ BView::_InitData(BRect frame, const char *name, uint32 resizingMode,
// BView constructor. This does not cause problems under BeOS as it just
// ors the two fields to one 32bit flag.
// For now we do the same but print the above warning message.
// ToDo: this should be removed at some point and the original
// TODO: this should be removed at some point and the original
// version restored:
// fFlags = (resizingMode & _RESIZE_MASK_) | (flags & ~_RESIZE_MASK_);
fFlags = resizingMode | flags;
@ -4662,6 +4667,8 @@ BView::_InitData(BRect frame, const char *name, uint32 resizingMode,
fIsPrinting = false;
fAttached = false;
// TODO: Since we cannot communicate failure, we don't use std::nothrow here
// TODO: Maybe we could auto-delete those views on AddChild() instead?
fState = new BPrivate::ViewState;
fBounds = frame.OffsetToCopy(B_ORIGIN);
@ -4744,19 +4751,22 @@ BView::_ClipToPicture(BPicture *picture, BPoint where,
bounds.right = bounds.left + ((bounds.IntegerWidth() + 1) / 32 + 1) * 32 - 1;
// TODO: I used a RGBA32 bitmap because drawing on a GRAY8 doesn't work.
BBitmap *bitmap = new BBitmap(bounds, B_RGBA32, true);
if (bitmap && bitmap->InitCheck() == B_OK && bitmap->Lock()) {
BView *view = new BView(bounds, "drawing view", B_FOLLOW_NONE, 0);
bitmap->AddChild(view);
view->DrawPicture(picture, where);
view->Sync();
BBitmap *bitmap = new(std::nothrow) BBitmap(bounds, B_RGBA32, true);
if (bitmap != NULL && bitmap->InitCheck() == B_OK && bitmap->Lock()) {
BView *view = new(std::nothrow) BView(bounds, "drawing view",
B_FOLLOW_NONE, 0);
if (view != NULL) {
bitmap->AddChild(view);
view->DrawPicture(picture, where);
view->Sync();
}
bitmap->Unlock();
}
BRegion region;
int32 width = bounds.IntegerWidth() + 1;
int32 height = bounds.IntegerHeight() + 1;
if (bitmap->LockBits() == B_OK) {
if (bitmap != NULL && bitmap->LockBits() == B_OK) {
uint32 bit = 0;
uint32 *bits = (uint32 *)bitmap->Bits();
clipping_rect rect;

View File

@ -424,7 +424,7 @@ BWindow::Instantiate(BMessage *data)
if (!validate_instantiation(data , "BWindow"))
return NULL;
return new BWindow(data);
return new(std::nothrow) BWindow(data);
}
@ -1225,7 +1225,7 @@ FrameMoved(origin);
status_t error = fLink->Read<int32>(&token);
if (error < B_OK || token == B_NULL_TOKEN)
break;
ViewUpdateInfo* info = new (std::nothrow) ViewUpdateInfo;
ViewUpdateInfo* info = new(std::nothrow) ViewUpdateInfo;
if (info == NULL || !infos.AddItem(info)) {
delete info;
break;
@ -1596,7 +1596,7 @@ BWindow::SetPulseRate(bigtime_t rate)
if (rate > 0) {
if (fPulseRunner == NULL) {
BMessage message(B_PULSE);
fPulseRunner = new BMessageRunner(BMessenger(this),
fPulseRunner = new(std::nothrow) BMessageRunner(BMessenger(this),
&message, rate);
} else {
fPulseRunner->SetInterval(rate);
@ -1619,7 +1619,9 @@ BWindow::PulseRate() const
void
BWindow::AddShortcut(uint32 key, uint32 modifiers, BMenuItem *item)
{
Shortcut* shortcut = new Shortcut(key, modifiers, item);
Shortcut* shortcut = new(std::nothrow) Shortcut(key, modifiers, item);
if (shortcut == NULL)
return;
// removes the shortcut if it already exists!
RemoveShortcut(key, modifiers);
@ -1636,12 +1638,16 @@ BWindow::AddShortcut(uint32 key, uint32 modifiers, BMessage *message)
void
BWindow::AddShortcut(uint32 key, uint32 modifiers, BMessage *message, BHandler *target)
BWindow::AddShortcut(uint32 key, uint32 modifiers, BMessage* message,
BHandler* target)
{
if (message == NULL)
return;
Shortcut* shortcut = new Shortcut(key, modifiers, message, target);
Shortcut* shortcut = new(std::nothrow) Shortcut(key, modifiers, message,
target);
if (shortcut == NULL)
return;
// removes the shortcut if it already exists!
RemoveShortcut(key, modifiers);
@ -2569,8 +2575,12 @@ BWindow::_InitData(BRect frame, const char* title, window_look look,
STRACE(("BWindow::InitData(): contacting app_server...\n"));
// let app_server know that a window has been created.
fLink = new BPrivate::PortLink(
fLink = new(std::nothrow) BPrivate::PortLink(
BApplication::Private::ServerLink()->SenderPort(), receivePort);
if (fLink == NULL) {
// Zombie!
return;
}
{
BPrivate::AppServerLink lockLink;
@ -2873,6 +2883,7 @@ BWindow::_CreateTopView()
STRACE(("_CreateTopView(): enter\n"));
BRect frame = fFrame.OffsetToCopy(B_ORIGIN);
// TODO: what to do here about std::nothrow?
fTopView = new BView(frame, "fTopView",
B_FOLLOW_ALL, B_WILL_DRAW);
fTopView->fTopLevelView = true;
@ -3505,7 +3516,7 @@ BView*
BWindow::_FindView(BView* view, BPoint point) const
{
// point is assumed to be already in view's coordinates
if (!view->IsHidden() && view->Bounds().Contains(point)) {
if (!view->IsHidden() && view->Bounds().Contains(point)) {
if (!view->fFirstChild)
return view;
else {