<malloc.h> -> <stdlib.h>

Style fixes, no functional change


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36502 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
DarkWyrm
2010-04-27 12:27:29 +00:00
parent c497ec3773
commit 09a03cb827
15 changed files with 413 additions and 447 deletions
+1
View File
@@ -7,6 +7,7 @@
*/
#include "App.h"
#include "ResWindow.h"
#include <Entry.h>
int
+128 -172
View File
@@ -1,13 +1,13 @@
#include "BitmapView.h"
#include <Alert.h>
#include <BitmapStream.h>
#include <Clipboard.h>
#include <Font.h>
#include <MenuItem.h>
#include <Entry.h>
#include <TranslationUtils.h>
#include <TranslatorRoster.h>
#include <TranslatorFormats.h>
#include <Clipboard.h>
#include <BitmapStream.h>
#include <MenuItem.h>
#include <Font.h>
#include <Alert.h>
// TODO: Add support for labels
@@ -22,12 +22,14 @@ enum
CLIP_PRODUCTIVE = 3
};
inline void SetRGBColor(rgb_color *col, uint8 r, uint8 g, uint8 b, uint8 a = 255);
void SetRGBColor(rgb_color *col,uint8 r, uint8 g, uint8 b, uint8 a)
{
if(col)
void
SetRGBColor(rgb_color *col, uint8 r, uint8 g, uint8 b, uint8 a)
{
if (col) {
col->red = r;
col->green = g;
col->blue = b;
@@ -35,6 +37,7 @@ void SetRGBColor(rgb_color *col,uint8 r, uint8 g, uint8 b, uint8 a)
}
}
BitmapView::BitmapView(BRect frame, const char *name, BMessage *mod, BBitmap *bitmap,
const char *label, border_style borderstyle, int32 resize, int32 flags)
: BView(frame, name, resize, flags)
@@ -85,36 +88,39 @@ BitmapView::BitmapView(BRect frame, const char *name, BMessage *mod, BBitmap *bi
float totalheight = fh.ascent + fh.descent + fh.leading;
float yoffset = (Bounds().Height() - 10 - (totalheight * 4)) / 2;
fNoPhotoOffsets[0].Set((Bounds().Width() - fNoPhotoWidths[0]) / 2, totalheight + yoffset);
fNoPhotoOffsets[1].Set( (Bounds().Width()-fNoPhotoWidths[1])/2,fNoPhotoOffsets[0].y+totalheight);
fNoPhotoOffsets[2].Set( (Bounds().Width()-fNoPhotoWidths[2])/2,fNoPhotoOffsets[1].y+totalheight);
fNoPhotoOffsets[3].Set( (Bounds().Width()-fNoPhotoWidths[3])/2,fNoPhotoOffsets[2].y+totalheight);
fNoPhotoOffsets[1].Set((Bounds().Width() - fNoPhotoWidths[1]) / 2,
fNoPhotoOffsets[0].y + totalheight);
fNoPhotoOffsets[2].Set((Bounds().Width() - fNoPhotoWidths[2]) / 2,
fNoPhotoOffsets[1].y + totalheight);
fNoPhotoOffsets[3].Set((Bounds().Width() - fNoPhotoWidths[3]) / 2,
fNoPhotoOffsets[2].y + totalheight);
}
BitmapView::~BitmapView(void)
{
delete fPopUpMenu;
}
void BitmapView::AttachedToWindow(void)
void
BitmapView::AttachedToWindow(void)
{
SetTarget((BHandler*)Window());
fPopUpMenu->SetTargetForItems(this);
}
void BitmapView::SetBitmap(BBitmap *bitmap)
{
if(bitmap && bitmap->IsValid())
void
BitmapView::SetBitmap(BBitmap *bitmap)
{
if (bitmap && bitmap->IsValid()) {
if (fBitmap == bitmap)
return;
fBitmap = bitmap;
}
else
{
if(fBitmap==NULL)
} else {
if (!fBitmap)
return;
fBitmap = NULL;
}
@@ -123,20 +129,22 @@ void BitmapView::SetBitmap(BBitmap *bitmap)
Invalidate();
}
void BitmapView::SetEnabled(bool value)
{
if(fEnabled!=value)
void
BitmapView::SetEnabled(bool value)
{
if (fEnabled != value) {
fEnabled = value;
Invalidate();
}
}
/*
void BitmapView::SetLabel(const char *label)
{
if(fLabel.Compare(label)!=0)
void
BitmapView::SetLabel(const char *label)
{
if (fLabel.Compare(label) != 0) {
fLabel = label;
CalculateBitmapRect();
@@ -146,10 +154,11 @@ void BitmapView::SetLabel(const char *label)
}
*/
void BitmapView::SetStyle(border_style style)
{
if(fBorderStyle!=style)
void
BitmapView::SetStyle(border_style style)
{
if (fBorderStyle != style) {
fBorderStyle = style;
CalculateBitmapRect();
@@ -158,10 +167,11 @@ void BitmapView::SetStyle(border_style style)
}
}
void BitmapView::SetFixedSize(bool isfixed)
{
if(fFixedSize!=isfixed)
void
BitmapView::SetFixedSize(bool isfixed)
{
if (fFixedSize != isfixed) {
fFixedSize = isfixed;
CalculateBitmapRect();
@@ -170,16 +180,15 @@ void BitmapView::SetFixedSize(bool isfixed)
}
}
void BitmapView::MessageReceived(BMessage *msg)
{
if(msg->WasDropped() && AcceptsDrops())
void
BitmapView::MessageReceived(BMessage *msg)
{
if (msg->WasDropped() && AcceptsDrops()) {
// We'll handle two types of drops: those from Tracker and those from ShowImage
if(msg->what==B_SIMPLE_DATA)
{
if (msg->what == B_SIMPLE_DATA) {
int32 actions;
if(msg->FindInt32("be:actions",&actions)==B_OK)
{
if (msg->FindInt32("be:actions", &actions) == B_OK) {
// ShowImage drop. This is a negotiated drag&drop, so send a reply
BMessage reply(B_COPY_TARGET), response;
reply.AddString("be:types", "image/jpeg");
@@ -188,17 +197,17 @@ void BitmapView::MessageReceived(BMessage *msg)
msg->SendReply(&reply, &response);
// now, we've gotten the response
if(response.what==B_MIME_DATA)
{
if (response.what == B_MIME_DATA) {
// Obtain and translate the received data
uint8 *imagedata;
ssize_t datasize;
// Try JPEG first
if(response.FindData("image/jpeg",B_MIME_DATA,(const void **)&imagedata,&datasize)!=B_OK)
{
if (response.FindData("image/jpeg", B_MIME_DATA,
(const void **)&imagedata, &datasize) != B_OK) {
// Try PNG next and piddle out if unsuccessful
if(response.FindData("image/png",B_PNG_FORMAT,(const void **)&imagedata,&datasize)!=B_OK)
if (response.FindData("image/png", B_PNG_FORMAT,
(const void **)&imagedata, &datasize) != B_OK)
return;
}
@@ -212,12 +221,10 @@ void BitmapView::MessageReceived(BMessage *msg)
BBitmap *bmp;
if (bstream.DetachBitmap(&bmp) != B_OK)
return;
SetBitmap(bmp);
if (fConstrainDrops)
ConstrainBitmap();
Invoke();
}
}
@@ -225,17 +232,14 @@ void BitmapView::MessageReceived(BMessage *msg)
}
entry_ref ref;
if(msg->FindRef("refs",&ref)==B_OK)
{
if (msg->FindRef("refs", &ref) == B_OK) {
// Tracker drop
BBitmap *bmp = BTranslationUtils::GetBitmap(&ref);
if(bmp)
{
if (bmp) {
SetBitmap(bmp);
if (fConstrainDrops)
ConstrainBitmap();
Invoke();
}
}
@@ -245,17 +249,14 @@ void BitmapView::MessageReceived(BMessage *msg)
switch (msg->what)
{
case M_REMOVE_IMAGE:
{
BAlert *alert=new BAlert("Mr. Peeps!","This cannot be undone. Remove the image?","Remove",
"Cancel");
case M_REMOVE_IMAGE: {
BAlert *alert = new BAlert("Mr. Peeps!", "This cannot be undone. Remove the image?",
"Remove", "Cancel");
int32 value = alert->Go();
if(value==0)
{
if (value == 0) {
SetBitmap(NULL);
if(Target())
{
if (Target()) {
BMessenger msgr(Target());
msgr.SendMessage(new BMessage(M_BITMAP_REMOVED));
@@ -266,19 +267,19 @@ void BitmapView::MessageReceived(BMessage *msg)
case M_PASTE_IMAGE:
{
PasteBitmap();
Invoke();
}
}
BView::MessageReceived(msg);
}
void BitmapView::Draw(BRect rect)
void
BitmapView::Draw(BRect rect)
{
if (fBitmap)
DrawBitmap(fBitmap, fBitmap->Bounds(), fBitmapRect);
else
{
else {
SetHighColor(0, 0, 0, 80);
SetDrawingMode(B_OP_ALPHA);
DrawString("Drop", fNoPhotoOffsets[0]);
@@ -288,8 +289,7 @@ void BitmapView::Draw(BRect rect)
SetDrawingMode(B_OP_COPY);
}
if(fBorderStyle==B_FANCY_BORDER)
{
if (fBorderStyle == B_FANCY_BORDER) {
rgb_color base= { 216, 216, 216, 255 };
rgb_color work;
@@ -346,23 +346,22 @@ void BitmapView::Draw(BRect rect)
SetHighColor(tint_color(base, B_DARKEN_2_TINT));
StrokeRect(r);
}
else
{
} else {
// Plain border
SetHighColor(0, 0, 0);
StrokeRect(fBitmapRect);
}
}
void BitmapView::MouseDown(BPoint pt)
void
BitmapView::MouseDown(BPoint pt)
{
BPoint mousept;
uint32 buttons;
GetMouse(&mousept, &buttons);
if(buttons & B_SECONDARY_MOUSE_BUTTON)
{
if (buttons & B_SECONDARY_MOUSE_BUTTON) {
ConvertToScreen(&mousept);
mousept.x= (mousept.x>5) ? mousept.x-5 : 0;
@@ -382,97 +381,60 @@ void BitmapView::MouseDown(BPoint pt)
}
}
void BitmapView::FrameResized(float w, float h)
void
BitmapView::FrameResized(float w, float h)
{
CalculateBitmapRect();
}
void BitmapView::CalculateBitmapRect(void)
{
if(!fBitmap || fFixedSize)
void
BitmapView::CalculateBitmapRect(void)
{
if (!fBitmap || fFixedSize) {
fBitmapRect = Bounds().InsetByCopy(1, 1);
return;
}
/* // Dynamic sizing algorithm
// 1) Check to see if either dimension is bigger than the view's display area
// 2) If smaller along both axes, make bitmap rect centered and return
// 3) Check to see if scaling is to be horizontal or vertical on basis of longer axis
// 4) Calculate scaling factor
// 5) Scale both axes down by scaling factor, accounting for border width
// 6) Center the rectangle in the direction of the smaller axis
uint8 borderwidth=(fBorderStyle==B_FANCY_BORDER)?5:1;
BRect r(Bounds());
r.InsetBy(borderwidth,borderwidth);
if( (fBitmap->Bounds().Width()<=r.Width()) &&
(fBitmap->Bounds().Height()<=r.Height()) )
{
// Smaller than view, so just center and return
fBitmapRect=fBitmap->Bounds();
fBitmapRect.OffsetBy( borderwidth+
((r.Width()-fBitmapRect.Width()-(borderwidth<<2))/2),
((r.Height()-fBitmapRect.Height()-(borderwidth<<2))/2) );
return;
}
float multiplier=fBitmap->Bounds().Width()/fBitmap->Bounds().Height();
float offset;
if(multiplier>1)
{
// Landscape orientation
// Scale rectangle to bounds width and center height
r.bottom=r.top+(r.Width()/multiplier);
offset= ((Bounds().Height()-(borderwidth<<1)) - r.Height())/2;
r.OffsetBy(0,offset);
}
else
{
// Portrait orientation
// Scale rectangle to bounds height and center width
r.right=r.left+(r.Height()*multiplier);
offset= ((Bounds().Width()-(borderwidth<<1)) - r.Width())/2;
r.OffsetBy(offset,0);
}
fBitmapRect=r;
*/
uint8 borderwidth = (fBorderStyle == B_FANCY_BORDER) ? 5 : 1;
BRect r(Bounds());
fBitmapRect= ScaleRectToFit(fBitmap->Bounds(), r.InsetByCopy(borderwidth, borderwidth));
}
void BitmapView::SetAcceptDrops(bool accept)
void
BitmapView::SetAcceptDrops(bool accept)
{
fAcceptDrops = accept;
}
void BitmapView::SetAcceptPaste(bool accept)
void
BitmapView::SetAcceptPaste(bool accept)
{
fAcceptPaste = accept;
}
void BitmapView::SetConstrainDrops(bool value)
void
BitmapView::SetConstrainDrops(bool value)
{
fConstrainDrops = value;
}
void BitmapView::MaxBitmapSize(float *width, float *height) const
void
BitmapView::MaxBitmapSize(float *width, float *height) const
{
*width = fMaxWidth;
*height = fMaxHeight;
}
void BitmapView::SetMaxBitmapSize(const float &width, const float &height)
void
BitmapView::SetMaxBitmapSize(const float &width, const float &height)
{
fMaxWidth = width;
fMaxHeight = height;
@@ -480,12 +442,16 @@ void BitmapView::SetMaxBitmapSize(const float &width, const float &height)
ConstrainBitmap();
}
void BitmapView::SetBitmapRemovable(bool isremovable)
void
BitmapView::SetBitmapRemovable(bool isremovable)
{
fRemovableBitmap = isremovable;
}
void BitmapView::ConstrainBitmap(void)
void
BitmapView::ConstrainBitmap(void)
{
if (!fBitmap || fMaxWidth < 1 || fMaxHeight < 1)
return;
@@ -505,30 +471,28 @@ void BitmapView::ConstrainBitmap(void)
fBitmap = new BBitmap(scaled, false);
}
bool BitmapView::ClipboardHasBitmap(void)
bool
BitmapView::ClipboardHasBitmap(void)
{
BMessage *clip = NULL, flattened;
uint8 clipval = CLIP_NONE;
bool returnval;
if(be_clipboard->Lock())
{
if (be_clipboard->Lock()) {
clip = be_clipboard->Data();
if(!clip->IsEmpty())
{
if (!clip->IsEmpty()) {
returnval = (clip->FindMessage("image/bitmap", &flattened) == B_OK);
if (returnval)
clipval = CLIP_BEOS;
else
{
else {
BString string;
returnval = (clip->FindString("class", &string) == B_OK && string == "BBitmap");
// Try method Gobe Productive uses if that, too, didn't work
if (returnval)
clipval = CLIP_SHOWIMAGE;
else
{
else {
returnval = (clip->FindMessage("image/x-vnd.Be-bitmap", &flattened) == B_OK);
if (returnval)
clipval = CLIP_SHOWIMAGE;
@@ -542,7 +506,9 @@ bool BitmapView::ClipboardHasBitmap(void)
return (clipval != CLIP_NONE)?true:false;
}
BBitmap *BitmapView::BitmapFromClipboard(void)
BBitmap *
BitmapView::BitmapFromClipboard(void)
{
BMessage *clip = NULL, flattened;
BBitmap *bitmap;
@@ -560,16 +526,14 @@ BBitmap *BitmapView::BitmapFromClipboard(void)
status_t status = clip->FindMessage("image/bitmap", &flattened);
// If that didn't work, try ShowImage-style
if(status!=B_OK)
{
if (status != B_OK) {
BString string;
status = clip->FindString("class", &string);
// Try method Gobe Productive uses if that, too, didn't work
if (status == B_OK && string == "BBitmap")
clipval = CLIP_SHOWIMAGE;
else
{
else {
status = clip->FindMessage("image/x-vnd.Be-bitmap", &flattened);
if (status == B_OK)
clipval = CLIP_PRODUCTIVE;
@@ -582,10 +546,8 @@ BBitmap *BitmapView::BitmapFromClipboard(void)
be_clipboard->Unlock();
switch(clipval)
{
case CLIP_SHOWIMAGE:
{
switch (clipval) {
case CLIP_SHOWIMAGE: {
// Showimage does it a slightly different way -- it dumps the BBitmap
// data directly to the clipboard message instead of packaging it in
// a bitmap like everyone else.
@@ -614,22 +576,19 @@ BBitmap *BitmapView::BitmapFromClipboard(void)
bitmap = new BBitmap(frame, cspace, true);
status = datamsg.FindData("_data", B_RAW_TYPE, (const void **)&buffer, &bufferLength);
if(status!=B_OK)
{
if (status != B_OK) {
delete bitmap;
return NULL;
}
memcpy(bitmap->Bits(), buffer, bufferLength);
return bitmap;
}
case CLIP_PRODUCTIVE:
// Productive doesn't name the packaged BBitmap data message the same, but
// uses exactly the same data format.
case CLIP_BEOS:
{
case CLIP_BEOS: {
const void *buffer;
int32 bufferLength;
@@ -647,14 +606,12 @@ BBitmap *BitmapView::BitmapFromClipboard(void)
bitmap = new BBitmap(frame, cspace, true);
status = flattened.FindData("_data", B_RAW_TYPE, (const void **)&buffer, &bufferLength);
if(status!=B_OK)
{
if (status != B_OK) {
delete bitmap;
return NULL;
}
memcpy(bitmap->Bits(), buffer, bufferLength);
return bitmap;
}
default:
@@ -665,7 +622,9 @@ BBitmap *BitmapView::BitmapFromClipboard(void)
return NULL;
}
BRect ScaleRectToFit(const BRect &from, const BRect &to)
BRect
ScaleRectToFit(const BRect &from, const BRect &to)
{
// Dynamic sizing algorithm
// 1) Check to see if either dimension is bigger than the view's display area
@@ -682,9 +641,7 @@ BRect ScaleRectToFit(const BRect &from, const BRect &to)
BRect r(to);
if( (from.Width()<=r.Width()) &&
(from.Height()<=r.Height()) )
{
if ((from.Width() <= r.Width()) && (from.Height() <= r.Height())) {
// Smaller than view, so just center and return
r = from;
r.OffsetBy((to.Width() - r.Width()) / 2, (to.Height() - r.Height()) / 2);
@@ -692,33 +649,32 @@ BRect ScaleRectToFit(const BRect &from, const BRect &to)
}
float multiplier = from.Width()/from.Height();
if(multiplier>1)
{
if (multiplier > 1) {
// Landscape orientation
// Scale rectangle to bounds width and center height
r.bottom = r.top + (r.Width() / multiplier);
r.OffsetBy(0, (to.Height() - r.Height()) / 2);
}
else
{
} else {
// Portrait orientation
// Scale rectangle to bounds height and center width
r.right = r.left + (r.Height() * multiplier);
r.OffsetBy((to.Width() - r.Width()) / 2, 0);
}
return r;
}
void BitmapView::RemoveBitmap(void)
void
BitmapView::RemoveBitmap(void)
{
SetBitmap(NULL);
}
void BitmapView::PasteBitmap(void)
void
BitmapView::PasteBitmap(void)
{
BBitmap *bmp = BitmapFromClipboard();
if (bmp)
+2 -2
View File
@@ -1,12 +1,12 @@
#ifndef BMPVIEW_H
#define BMPVIEW_H
#include <Message.h>
#include <Bitmap.h>
#include <Message.h>
#include <Invoker.h>
#include <PopUpMenu.h>
#include <String.h>
#include <View.h>
#include <PopUpMenu.h>
enum
{
+3 -2
View File
@@ -5,11 +5,12 @@
* Author:
* DarkWyrm <[email protected]>
*/
#include "InternalEditors.h"
#include "BitmapView.h"
#include "InternalEditors.h"
#include "ResourceData.h"
#include <TranslationUtils.h>
#include <DataIO.h>
#include <TranslationUtils.h>
#define M_IMAGE_CHANGED 'imch'
+3 -3
View File
@@ -6,8 +6,9 @@
* DarkWyrm <[email protected]>
*/
#include "InlineEditor.h"
#include <MessageFilter.h>
#include <Handler.h>
#include <MessageFilter.h>
class EditFilter : public BMessageFilter
{
@@ -54,8 +55,7 @@ InlineEditor::InlineEditor(BMessenger target, const BRect &frame,
fCommand(M_INLINE_TEXT)
{
fTextBox = new BTextControl(BRect(0, 0, 1, 1), "inlinebox", NULL, text,
new BMessage(fCommand), B_FOLLOW_ALL,
B_WILL_DRAW);
new BMessage(fCommand), B_FOLLOW_ALL, B_WILL_DRAW);
AddChild(fTextBox);
fTextBox->SetDivider(0);
fTextBox->MakeFocus(true);
+2 -2
View File
@@ -8,9 +8,9 @@
#ifndef INLINE_EDITOR
#define INLINE_EDITOR
#include <Window.h>
#include <TextControl.h>
#include <Messenger.h>
#include <TextControl.h>
#include <Window.h>
#define M_INLINE_TEXT 'intx'
+3 -1
View File
@@ -7,9 +7,11 @@
*/
#include "InternalEditors.h"
#include "ResourceData.h"
#include <Messenger.h>
#include <Message.h>
#include <Messenger.h>
#include <String.h>
#include <stdlib.h>
StringEditor::StringEditor(const BRect &frame, ResourceData *data,
+3 -1
View File
@@ -7,9 +7,11 @@
*/
#include "InternalEditors.h"
#include "ResourceData.h"
#include <Messenger.h>
#include <Message.h>
#include <Messenger.h>
#include <String.h>
#include <stdlib.h>
DoubleEditor::DoubleEditor(const BRect &frame, ResourceData *data,
+1
View File
@@ -7,6 +7,7 @@
*/
#include "PreviewColumn.h"
#include "ResFields.h"
#include <stdio.h>
PreviewColumn::PreviewColumn(const char *title, float width,
+1
View File
@@ -7,6 +7,7 @@
*/
#include "ResFields.h"
#include "ResourceData.h"
#include <DataIO.h>
#include <TranslationUtils.h>
+4 -3
View File
@@ -10,15 +10,16 @@
#include <Application.h>
#include <File.h>
#include <ScrollView.h>
#include <malloc.h>
#include <Menu.h>
#include <MenuItem.h>
#include <stdio.h>
#include <TranslatorRoster.h>
#include <TypeConstants.h>
#include "ColumnTypes.h"
#include <stdio.h>
#include <stdlib.h>
#include "App.h"
#include "ColumnTypes.h"
#include "ResourceData.h"
#include "ResFields.h"
#include "ResListView.h"
+2 -2
View File
@@ -6,8 +6,9 @@
* DarkWyrm <[email protected]>
*/
#include "ResWindow.h"
#include "ResView.h"
#include "App.h"
#include "ResView.h"
static int32 sWindowCount = 0;
@@ -38,7 +39,6 @@ ResWindow::QuitRequested(void)
if (sWindowCount == 0)
be_app->PostMessage(B_QUIT_REQUESTED);
// be_app->PostMessage(M_UNREGISTER_WINDOW);
return true;
}
+3 -3
View File
@@ -8,10 +8,10 @@
#ifndef RESOURCE_DATA_H
#define RESOURCE_DATA_H
#include <Resources.h>
#include <String.h>
#include <Node.h>
#include <fs_attr.h>
#include <Resources.h>
#include <Node.h>
#include <String.h>
class ResourceData
{
+10 -9
View File
@@ -6,17 +6,18 @@
* DarkWyrm <[email protected]>
*/
#include "ResourceRoster.h"
#include <Roster.h>
#include <Entry.h>
#include <Path.h>
#include <image.h>
#include <Application.h>
#include <String.h>
#include <Directory.h>
#include <Bitmap.h>
#include "ResourceData.h"
#include <Application.h>
#include <Bitmap.h>
#include <Directory.h>
#include <Entry.h>
#include <image.h>
#include <Path.h>
#include <Roster.h>
#include <String.h>
#include "InternalEditors.h"
#include "ResourceData.h"
#include "ResFields.h"
// For the MakeFieldForType temp code