* Style cleanups.

* Removed former dead print-screen code.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31797 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2009-07-27 10:50:53 +00:00
parent e5a19b2505
commit f09d0bff87
+62 -95
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2001-2008, Haiku. * Copyright 2001-2009, Haiku.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -63,6 +63,7 @@
void do_minimize_team(BRect zoomRect, team_id team, bool zoom); void do_minimize_team(BRect zoomRect, team_id team, bool zoom);
struct BWindow::unpack_cookie { struct BWindow::unpack_cookie {
unpack_cookie(); unpack_cookie();
@@ -77,9 +78,10 @@ struct BWindow::unpack_cookie {
class BWindow::Shortcut { class BWindow::Shortcut {
public: public:
Shortcut(uint32 key, uint32 modifiers, BMenuItem* item); Shortcut(uint32 key, uint32 modifiers,
Shortcut(uint32 key, uint32 modifiers, BMessage* message, BMenuItem* item);
BHandler* target); Shortcut(uint32 key, uint32 modifiers,
BMessage* message, BHandler* target);
~Shortcut(); ~Shortcut();
bool Matches(uint32 key, uint32 modifiers) const; bool Matches(uint32 key, uint32 modifiers) const;
@@ -350,8 +352,7 @@ BWindow::BWindow(BMessage* data)
int32 i = 0; int32 i = 0;
while (data->FindMessage("_views", i++, &msg) == B_OK) { while (data->FindMessage("_views", i++, &msg) == B_OK) {
BArchivable* obj = instantiate_object(&msg); BArchivable* obj = instantiate_object(&msg);
BView *child = dynamic_cast<BView *>(obj); if (BView* child = dynamic_cast<BView*>(obj))
if (child)
AddChild(child); AddChild(child);
} }
} }
@@ -1030,10 +1031,10 @@ FrameMoved(origin);
{ {
if (!_HandleKeyDown(msg)) { if (!_HandleKeyDown(msg)) {
if (BView* view = dynamic_cast<BView*>(target)) { if (BView* view = dynamic_cast<BView*>(target)) {
// TODO: cannot use "string" here if we support having different // TODO: cannot use "string" here if we support having
// font encoding per view (it's supposed to be converted by // different font encoding per view (it's supposed to be
// _HandleKeyDown() one day) // converted by _HandleKeyDown() one day)
const char *string = NULL; const char* string;
if (msg->FindString("bytes", &string) == B_OK) if (msg->FindString("bytes", &string) == B_OK)
view->KeyDown(string, strlen(string)); view->KeyDown(string, strlen(string));
} else } else
@@ -1095,7 +1096,6 @@ FrameMoved(origin);
case B_MOUSE_MOVED: case B_MOUSE_MOVED:
{ {
if (BView* view = dynamic_cast<BView*>(target)) { if (BView* view = dynamic_cast<BView*>(target)) {
uint32 eventOptions = view->fEventOptions uint32 eventOptions = view->fEventOptions
| view->fMouseEventOptions; | view->fMouseEventOptions;
bool noHistory = eventOptions & B_NO_POINTER_HISTORY; bool noHistory = eventOptions & B_NO_POINTER_HISTORY;
@@ -1129,7 +1129,8 @@ FrameMoved(origin);
queue->Lock(); queue->Lock();
BMessage* moved; BMessage* moved;
for (int32 i = 0; (moved = queue->FindMessage(i)) != NULL; i++) { for (int32 i = 0; (moved = queue->FindMessage(i)) != NULL;
i++) {
if (moved != msg && moved->what == B_MOUSE_MOVED) { if (moved != msg && moved->what == B_MOUSE_MOVED) {
// there is a newer mouse moved message in the // there is a newer mouse moved message in the
// queue, just ignore the current one, the newer one // queue, just ignore the current one, the newer one
@@ -1149,7 +1150,8 @@ FrameMoved(origin);
BMessage* dragMessage = NULL; BMessage* dragMessage = NULL;
if (msg->HasMessage("be:drag_message")) { if (msg->HasMessage("be:drag_message")) {
dragMessage = new BMessage(); dragMessage = new BMessage();
if (msg->FindMessage("be:drag_message", dragMessage) != B_OK) { if (msg->FindMessage("be:drag_message", dragMessage)
!= B_OK) {
delete dragMessage; delete dragMessage;
dragMessage = NULL; dragMessage = NULL;
} }
@@ -1410,14 +1412,18 @@ BWindow::SetSizeLimits(float minWidth, float maxWidth,
void void
BWindow::GetSizeLimits(float *minWidth, float *maxWidth, BWindow::GetSizeLimits(float* _minWidth, float* _maxWidth, float* _minHeight,
float *minHeight, float *maxHeight) float* _maxHeight)
{ {
// TODO: What about locking?!? // TODO: What about locking?!?
*minHeight = fMinHeight; if (_minHeight != NULL)
*minWidth = fMinWidth; *_minHeight = fMinHeight;
*maxHeight = fMaxHeight; if (_minWidth != NULL)
*maxWidth = fMaxWidth; *_minWidth = fMinWidth;
if (_maxHeight != NULL)
*_maxHeight = fMaxHeight;
if (_maxWidth != NULL)
*_maxWidth = fMaxWidth;
} }
@@ -1430,28 +1436,27 @@ BWindow::SetDecoratorSettings(const BMessage& settings)
int32 size = settings.FlattenedSize(); int32 size = settings.FlattenedSize();
char buffer[size]; char buffer[size];
status_t ret = settings.Flatten(buffer, size); status_t status = settings.Flatten(buffer, size);
if (status != B_OK)
if (ret < B_OK) return status;
return ret;
if (!Lock()) if (!Lock())
return B_ERROR; return B_ERROR;
ret = fLink->StartMessage(AS_SET_DECORATOR_SETTINGS); status = fLink->StartMessage(AS_SET_DECORATOR_SETTINGS);
if (ret == B_OK) if (status == B_OK)
ret = fLink->Attach<int32>(size); status = fLink->Attach<int32>(size);
if (ret == B_OK) if (status == B_OK)
ret = fLink->Attach(buffer, size); status = fLink->Attach(buffer, size);
if (ret == B_OK) if (status == B_OK)
ret = fLink->Flush(); status = fLink->Flush();
Unlock(); Unlock();
return ret; return status;
} }
@@ -1464,30 +1469,30 @@ BWindow::GetDecoratorSettings(BMessage* settings) const
if (!const_cast<BWindow*>(this)->Lock()) if (!const_cast<BWindow*>(this)->Lock())
return B_ERROR; return B_ERROR;
status_t ret = fLink->StartMessage(AS_GET_DECORATOR_SETTINGS); status_t status = fLink->StartMessage(AS_GET_DECORATOR_SETTINGS);
if (ret == B_OK) { if (status == B_OK) {
int32 code; int32 code;
ret = fLink->FlushWithReply(code); status = fLink->FlushWithReply(code);
if (ret == B_OK && code != B_OK) if (status == B_OK && code != B_OK)
ret = code; status = code;
} }
if (ret == B_OK) { if (status == B_OK) {
int32 size; int32 size;
ret = fLink->Read<int32>(&size); status = fLink->Read<int32>(&size);
if (ret == B_OK) { if (status == B_OK) {
char buffer[size]; char buffer[size];
ret = fLink->Read(buffer, size); status = fLink->Read(buffer, size);
if (ret == B_OK) { if (status == B_OK) {
ret = settings->Unflatten(buffer); status = settings->Unflatten(buffer);
} }
} }
} }
const_cast<BWindow*>(this)->Unlock(); const_cast<BWindow*>(this)->Unlock();
return ret; return status;
} }
@@ -1521,17 +1526,10 @@ void
BWindow::Zoom() BWindow::Zoom()
{ {
// TODO: What about locking?!? // TODO: What about locking?!?
/*
from BeBook:
However, if the window's rectangle already matches these "zoom" dimensions
(give or take a few pixels), Zoom() passes the window's previous
("non-zoomed") size and location. (??????)
*/
/* From BeBook: // From BeBook:
The dimensions that non-virtual Zoom() passes to hook Zoom() are deduced from // The dimensions that non-virtual Zoom() passes to hook Zoom() are deduced
the smallest of three rectangles: // from the smallest of three rectangles:
*/
float borderWidth; float borderWidth;
float tabHeight; float tabHeight;
@@ -1560,18 +1558,20 @@ BWindow::Zoom()
BPoint zoomedLeftTop = screen.Frame().LeftTop() + BPoint(borderWidth, BPoint zoomedLeftTop = screen.Frame().LeftTop() + BPoint(borderWidth,
tabHeight + borderWidth); tabHeight + borderWidth);
// UN-ZOOM: // Un-Zoom
if (fPreviousFrame.IsValid() if (fPreviousFrame.IsValid()
// NOTE: don't check for fFrame.LeftTop() == zoomedLeftTop // NOTE: don't check for fFrame.LeftTop() == zoomedLeftTop
// -> makes it easier on the user to get a window back into place // -> makes it easier on the user to get a window back into place
&& fFrame.Width() == zoomedWidth && fFrame.Width() == zoomedWidth
&& fFrame.Height() == zoomedHeight) { && fFrame.Height() == zoomedHeight) {
// already zoomed! // already zoomed!
Zoom(fPreviousFrame.LeftTop(), fPreviousFrame.Width(), fPreviousFrame.Height()); Zoom(fPreviousFrame.LeftTop(), fPreviousFrame.Width(),
fPreviousFrame.Height());
return; return;
} }
// ZOOM: // Zoom
// remember fFrame for later "unzooming" // remember fFrame for later "unzooming"
fPreviousFrame = fFrame; fPreviousFrame = fFrame;
@@ -1591,7 +1591,8 @@ void
BWindow::SetPulseRate(bigtime_t rate) BWindow::SetPulseRate(bigtime_t rate)
{ {
// TODO: What about locking?!? // TODO: What about locking?!?
if (rate < 0 || (rate == fPulseRate && !((rate == 0) ^ (fPulseRunner == NULL)))) if (rate < 0
|| (rate == fPulseRate && !((rate == 0) ^ (fPulseRunner == NULL))))
return; return;
fPulseRate = rate; fPulseRate = rate;
@@ -2478,7 +2479,8 @@ BWindow::ResolveSpecifier(BMessage *msg, int32 index, BMessage *specifier,
} else { } else {
BMessage replyMsg(B_MESSAGE_NOT_UNDERSTOOD); BMessage replyMsg(B_MESSAGE_NOT_UNDERSTOOD);
replyMsg.AddInt32("error", B_NAME_NOT_FOUND); replyMsg.AddInt32("error", B_NAME_NOT_FOUND);
replyMsg.AddString("message", "This window doesn't have a main MenuBar"); replyMsg.AddString("message",
"This window doesn't have a main MenuBar");
msg->SendReply(&replyMsg); msg->SendReply(&replyMsg);
return NULL; return NULL;
} }
@@ -2500,7 +2502,8 @@ BWindow::_InitData(BRect frame, const char* title, window_look look,
STRACE(("BWindow::InitData()\n")); STRACE(("BWindow::InitData()\n"));
if (be_app == NULL) { if (be_app == NULL) {
debugger("You need a valid BApplication object before interacting with the app_server"); debugger("You need a valid BApplication object before interacting with "
"the app_server");
return; return;
} }
@@ -3388,7 +3391,6 @@ BWindow::_HandleKeyDown(BMessage* event)
// Check for Print Screen // Check for Print Screen
int32 rawKey; int32 rawKey;
if (event->FindInt32("key", &rawKey) == B_OK && rawKey == B_PRINT_KEY) { if (event->FindInt32("key", &rawKey) == B_OK && rawKey == B_PRINT_KEY) {
#ifdef __HAIKU__
BMessage message(B_REFS_RECEIVED); BMessage message(B_REFS_RECEIVED);
message.AddBool("silent", true); message.AddBool("silent", true);
@@ -3400,41 +3402,6 @@ BWindow::_HandleKeyDown(BMessage* event)
be_roster->Launch("application/x-vnd.haiku-screenshot", &message); be_roster->Launch("application/x-vnd.haiku-screenshot", &message);
return true; return true;
#else
// Get filename
BPath homePath;
if (find_directory(B_USER_DIRECTORY, &homePath) != B_OK) {
fprintf(stderr, "failed to find user home directory\n");
return true;
}
BPath path;
BEntry entry;
int32 index = 1;
do {
char filename[32];
sprintf(filename, "screen%ld.png", index++);
path = homePath;
path.Append(filename);
entry.SetTo(path.Path());
} while (entry.Exists());
// Get the screen bitmap
BScreen screen(this);
BBitmap* screenDump;
screen.GetBitmap(&screenDump, false);
// Dump to PNG
SaveToPNG(path.Path(), screen.Frame(), screenDump->ColorSpace(),
screenDump->Bits(),
screenDump->BitsLength(),
screenDump->BytesPerRow());
// Free the bitmap allocated by BScreen.GetBitmap
delete screenDump;
#endif
return true;
} }
} }