* 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
+171 -204
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();
@@ -76,28 +77,29 @@ 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,
~Shortcut(); BMessage* message, BHandler* target);
~Shortcut();
bool Matches(uint32 key, uint32 modifiers) const; bool Matches(uint32 key, uint32 modifiers) const;
BMenuItem* MenuItem() const { return fMenuItem; } BMenuItem* MenuItem() const { return fMenuItem; }
BMessage* Message() const { return fMessage; } BMessage* Message() const { return fMessage; }
BHandler* Target() const { return fTarget; } BHandler* Target() const { return fTarget; }
static uint32 AllowedModifiers(); static uint32 AllowedModifiers();
static uint32 PrepareKey(uint32 key); static uint32 PrepareKey(uint32 key);
static uint32 PrepareModifiers(uint32 modifiers); static uint32 PrepareModifiers(uint32 modifiers);
private: private:
uint32 fKey; uint32 fKey;
uint32 fModifiers; uint32 fModifiers;
BMenuItem* fMenuItem; BMenuItem* fMenuItem;
BMessage* fMessage; BMessage* fMessage;
BHandler* fTarget; BHandler* fTarget;
}; };
@@ -193,7 +195,7 @@ static value_info sWindowValueInfo[] = {
void void
_set_menu_sem_(BWindow *window, sem_id sem) _set_menu_sem_(BWindow* window, sem_id sem)
{ {
if (window != NULL) if (window != NULL)
window->fMenuSem = sem; window->fMenuSem = sem;
@@ -310,20 +312,20 @@ BWindow::BWindow(BMessage* data)
{ {
data->FindRect("_frame", &fFrame); data->FindRect("_frame", &fFrame);
const char *title; const char* title;
data->FindString("_title", &title); data->FindString("_title", &title);
window_look look; window_look look;
data->FindInt32("_wlook", (int32 *)&look); data->FindInt32("_wlook", (int32*)&look);
window_feel feel; window_feel feel;
data->FindInt32("_wfeel", (int32 *)&feel); data->FindInt32("_wfeel", (int32*)&feel);
if (data->FindInt32("_flags", (int32 *)&fFlags) != B_OK) if (data->FindInt32("_flags", (int32*)&fFlags) != B_OK)
fFlags = 0; fFlags = 0;
uint32 workspaces; uint32 workspaces;
data->FindInt32("_wspace", (int32 *)&workspaces); data->FindInt32("_wspace", (int32*)&workspaces);
uint32 type; uint32 type;
if (data->FindInt32("_type", (int32*)&type) == B_OK) if (data->FindInt32("_type", (int32*)&type) == B_OK)
@@ -349,9 +351,8 @@ BWindow::BWindow(BMessage* data)
BMessage msg; BMessage msg;
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);
} }
} }
@@ -368,7 +369,7 @@ BWindow::BWindow(BRect frame, int32 bitmapToken)
BWindow::~BWindow() BWindow::~BWindow()
{ {
if (BMenu *menu = dynamic_cast<BMenu *>(fFocus)) { if (BMenu* menu = dynamic_cast<BMenu*>(fFocus)) {
MenuPrivate(menu).QuitTracking(); MenuPrivate(menu).QuitTracking();
} }
@@ -419,8 +420,8 @@ BWindow::~BWindow()
} }
BArchivable * BArchivable*
BWindow::Instantiate(BMessage *data) BWindow::Instantiate(BMessage* data)
{ {
if (!validate_instantiation(data , "BWindow")) if (!validate_instantiation(data , "BWindow"))
return NULL; return NULL;
@@ -492,7 +493,7 @@ void
BWindow::Quit() BWindow::Quit()
{ {
if (!IsLocked()) { if (!IsLocked()) {
const char *name = Name(); const char* name = Name();
if (!name) if (!name)
name = "no-name"; name = "no-name";
@@ -518,7 +519,7 @@ BWindow::Quit()
void void
BWindow::AddChild(BView *child, BView *before) BWindow::AddChild(BView* child, BView* before)
{ {
BAutolock locker(this); BAutolock locker(this);
if (locker.IsLocked()) if (locker.IsLocked())
@@ -527,7 +528,7 @@ BWindow::AddChild(BView *child, BView *before)
bool bool
BWindow::RemoveChild(BView *child) BWindow::RemoveChild(BView* child)
{ {
BAutolock locker(this); BAutolock locker(this);
if (!locker.IsLocked()) if (!locker.IsLocked())
@@ -548,7 +549,7 @@ BWindow::CountChildren() const
} }
BView * BView*
BWindow::ChildAt(int32 index) const BWindow::ChildAt(int32 index) const
{ {
BAutolock locker(const_cast<BWindow*>(this)); BAutolock locker(const_cast<BWindow*>(this));
@@ -577,7 +578,7 @@ BWindow::Minimize(bool minimize)
status_t status_t
BWindow::SendBehind(const BWindow *window) BWindow::SendBehind(const BWindow* window)
{ {
if (!window || !Lock()) if (!window || !Lock())
return B_ERROR; return B_ERROR;
@@ -598,9 +599,9 @@ BWindow::SendBehind(const BWindow *window)
void void
BWindow::Flush() const BWindow::Flush() const
{ {
if (const_cast<BWindow *>(this)->Lock()) { if (const_cast<BWindow*>(this)->Lock()) {
fLink->Flush(); fLink->Flush();
const_cast<BWindow *>(this)->Unlock(); const_cast<BWindow*>(this)->Unlock();
} }
} }
@@ -683,7 +684,7 @@ BWindow::IsFront() const
void void
BWindow::MessageReceived(BMessage *msg) BWindow::MessageReceived(BMessage* msg)
{ {
if (!msg->HasSpecifiers()) { if (!msg->HasSpecifiers()) {
if (msg->what == B_KEY_DOWN) if (msg->what == B_KEY_DOWN)
@@ -697,7 +698,7 @@ BWindow::MessageReceived(BMessage *msg)
BMessage specifier; BMessage specifier;
int32 what; int32 what;
const char *prop; const char* prop;
int32 index; int32 index;
if (msg->GetCurrentSpecifier(&index, &specifier, &what, &prop) != B_OK) if (msg->GetCurrentSpecifier(&index, &specifier, &what, &prop) != B_OK)
@@ -723,7 +724,7 @@ BWindow::MessageReceived(BMessage *msg)
handled = true; handled = true;
} else { } else {
uint32 newFeel; uint32 newFeel;
if (msg->FindInt32("data", (int32 *)&newFeel) == B_OK) { if (msg->FindInt32("data", (int32*)&newFeel) == B_OK) {
SetFeel((window_feel)newFeel); SetFeel((window_feel)newFeel);
handled = true; handled = true;
} }
@@ -735,7 +736,7 @@ BWindow::MessageReceived(BMessage *msg)
handled = true; handled = true;
} else { } else {
uint32 newFlags; uint32 newFlags;
if (msg->FindInt32("data", (int32 *)&newFlags) == B_OK) { if (msg->FindInt32("data", (int32*)&newFlags) == B_OK) {
SetFlags(newFlags); SetFlags(newFlags);
handled = true; handled = true;
} }
@@ -776,7 +777,7 @@ BWindow::MessageReceived(BMessage *msg)
handled = true; handled = true;
} else { } else {
uint32 newLook; uint32 newLook;
if (msg->FindInt32("data", (int32 *)&newLook) == B_OK) { if (msg->FindInt32("data", (int32*)&newLook) == B_OK) {
SetLook((window_look)newLook); SetLook((window_look)newLook);
handled = true; handled = true;
} }
@@ -787,7 +788,7 @@ BWindow::MessageReceived(BMessage *msg)
replyMsg.AddString("result", Title()); replyMsg.AddString("result", Title());
handled = true; handled = true;
} else { } else {
const char *newTitle = NULL; const char* newTitle = NULL;
if (msg->FindString("data", &newTitle) == B_OK) { if (msg->FindString("data", &newTitle) == B_OK) {
SetTitle(newTitle); SetTitle(newTitle);
handled = true; handled = true;
@@ -800,7 +801,7 @@ BWindow::MessageReceived(BMessage *msg)
handled = true; handled = true;
} else { } else {
uint32 newWorkspaces; uint32 newWorkspaces;
if (msg->FindInt32("data", (int32 *)&newWorkspaces) == B_OK) { if (msg->FindInt32("data", (int32*)&newWorkspaces) == B_OK) {
SetWorkspaces(newWorkspaces); SetWorkspaces(newWorkspaces);
handled = true; handled = true;
} }
@@ -835,7 +836,7 @@ BWindow::MessageReceived(BMessage *msg)
void void
BWindow::DispatchMessage(BMessage *msg, BHandler *target) BWindow::DispatchMessage(BMessage* msg, BHandler* target)
{ {
if (!msg) if (!msg)
return; return;
@@ -986,7 +987,7 @@ FrameMoved(origin);
BRect frame; BRect frame;
uint32 mode; uint32 mode;
if (msg->FindRect("frame", &frame) == B_OK if (msg->FindRect("frame", &frame) == B_OK
&& msg->FindInt32("mode", (int32 *)&mode) == B_OK) && msg->FindInt32("mode", (int32*)&mode) == B_OK)
ScreenChanged(frame, (color_space)mode); ScreenChanged(frame, (color_space)mode);
} else } else
target->MessageReceived(msg); target->MessageReceived(msg);
@@ -996,7 +997,7 @@ FrameMoved(origin);
if (target == this) { if (target == this) {
uint32 workspace; uint32 workspace;
bool active; bool active;
if (msg->FindInt32("workspace", (int32 *)&workspace) == B_OK if (msg->FindInt32("workspace", (int32*)&workspace) == B_OK
&& msg->FindBool("active", &active) == B_OK) && msg->FindBool("active", &active) == B_OK)
WorkspaceActivated(workspace, active); WorkspaceActivated(workspace, active);
} else } else
@@ -1006,8 +1007,8 @@ FrameMoved(origin);
case B_WORKSPACES_CHANGED: case B_WORKSPACES_CHANGED:
if (target == this) { if (target == this) {
uint32 oldWorkspace, newWorkspace; uint32 oldWorkspace, newWorkspace;
if (msg->FindInt32("old", (int32 *)&oldWorkspace) == B_OK if (msg->FindInt32("old", (int32*)&oldWorkspace) == B_OK
&& msg->FindInt32("new", (int32 *)&newWorkspace) == B_OK) && msg->FindInt32("new", (int32*)&newWorkspace) == B_OK)
WorkspacesChanged(oldWorkspace, newWorkspace); WorkspacesChanged(oldWorkspace, newWorkspace);
} else } else
target->MessageReceived(msg); target->MessageReceived(msg);
@@ -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
@@ -1044,7 +1045,7 @@ FrameMoved(origin);
case B_KEY_UP: case B_KEY_UP:
{ {
const char *string = NULL; const char* string = NULL;
msg->FindString("bytes", &string); msg->FindString("bytes", &string);
// TODO: same as above // TODO: same as above
@@ -1057,11 +1058,11 @@ FrameMoved(origin);
case B_MOUSE_DOWN: case B_MOUSE_DOWN:
{ {
BView *view = dynamic_cast<BView *>(target); BView* view = dynamic_cast<BView*>(target);
// Close an eventually opened menu // Close an eventually opened menu
// unless the target is the menu itself // unless the target is the menu itself
BMenu *menu = dynamic_cast<BMenu *>(fFocus); BMenu* menu = dynamic_cast<BMenu*>(fFocus);
MenuPrivate privMenu(menu); MenuPrivate privMenu(menu);
if (menu != NULL && menu != view if (menu != NULL && menu != view
&& privMenu.State() != MENU_STATE_CLOSED) { && privMenu.State() != MENU_STATE_CLOSED) {
@@ -1081,7 +1082,7 @@ FrameMoved(origin);
case B_MOUSE_UP: case B_MOUSE_UP:
{ {
if (BView *view = dynamic_cast<BView *>(target)) { if (BView* view = dynamic_cast<BView*>(target)) {
BPoint where; BPoint where;
msg->FindPoint("be:view_where", &where); msg->FindPoint("be:view_where", &where);
view->fMouseEventOptions = 0; view->fMouseEventOptions = 0;
@@ -1094,8 +1095,7 @@ 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;
@@ -1125,11 +1125,12 @@ FrameMoved(origin);
|| (dropIfLate && (system_time() - eventTime > 20000))) { || (dropIfLate && (system_time() - eventTime > 20000))) {
// filter out older mouse moved messages in the queue // filter out older mouse moved messages in the queue
_DequeueAll(); _DequeueAll();
BMessageQueue *queue = MessageQueue(); BMessageQueue* queue = MessageQueue();
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;
@@ -1620,7 +1621,7 @@ BWindow::PulseRate() const
void void
BWindow::AddShortcut(uint32 key, uint32 modifiers, BMenuItem *item) BWindow::AddShortcut(uint32 key, uint32 modifiers, BMenuItem* item)
{ {
Shortcut* shortcut = new(std::nothrow) Shortcut(key, modifiers, item); Shortcut* shortcut = new(std::nothrow) Shortcut(key, modifiers, item);
if (shortcut == NULL) if (shortcut == NULL)
@@ -1634,7 +1635,7 @@ BWindow::AddShortcut(uint32 key, uint32 modifiers, BMenuItem *item)
void void
BWindow::AddShortcut(uint32 key, uint32 modifiers, BMessage *message) BWindow::AddShortcut(uint32 key, uint32 modifiers, BMessage* message)
{ {
AddShortcut(key, modifiers, message, this); AddShortcut(key, modifiers, message, this);
} }
@@ -1673,7 +1674,7 @@ BWindow::RemoveShortcut(uint32 key, uint32 modifiers)
} }
BButton * BButton*
BWindow::DefaultButton() const BWindow::DefaultButton() const
{ {
// TODO: What about locking?!? // TODO: What about locking?!?
@@ -1682,7 +1683,7 @@ BWindow::DefaultButton() const
void void
BWindow::SetDefaultButton(BButton *button) BWindow::SetDefaultButton(BButton* button)
{ {
// TODO: What about locking?!? // TODO: What about locking?!?
if (fDefaultButton == button) if (fDefaultButton == button)
@@ -1690,7 +1691,7 @@ BWindow::SetDefaultButton(BButton *button)
if (fDefaultButton != NULL) { if (fDefaultButton != NULL) {
// tell old button it's no longer the default one // tell old button it's no longer the default one
BButton *oldDefault = fDefaultButton; BButton* oldDefault = fDefaultButton;
oldDefault->MakeDefault(false); oldDefault->MakeDefault(false);
oldDefault->Invalidate(); oldDefault->Invalidate();
} }
@@ -1708,7 +1709,7 @@ BWindow::SetDefaultButton(BButton *button)
bool bool
BWindow::NeedsUpdate() const BWindow::NeedsUpdate() const
{ {
if (!const_cast<BWindow *>(this)->Lock()) if (!const_cast<BWindow*>(this)->Lock())
return false; return false;
fLink->StartMessage(AS_NEEDS_UPDATE); fLink->StartMessage(AS_NEEDS_UPDATE);
@@ -1716,7 +1717,7 @@ BWindow::NeedsUpdate() const
int32 code = B_ERROR; int32 code = B_ERROR;
fLink->FlushWithReply(code); fLink->FlushWithReply(code);
const_cast<BWindow *>(this)->Unlock(); const_cast<BWindow*>(this)->Unlock();
return code == B_OK; return code == B_OK;
} }
@@ -1731,7 +1732,7 @@ BWindow::UpdateIfNeeded()
// if the queue is already locked we are called recursivly // if the queue is already locked we are called recursivly
// from our own dispatched update message // from our own dispatched update message
if (((const BMessageQueue *)MessageQueue())->IsLocked()) if (((const BMessageQueue*)MessageQueue())->IsLocked())
return; return;
if (!Lock()) if (!Lock())
@@ -1745,7 +1746,7 @@ BWindow::UpdateIfNeeded()
// all messages that are pending on the port. // all messages that are pending on the port.
_DequeueAll(); _DequeueAll();
BMessageQueue *queue = MessageQueue(); BMessageQueue* queue = MessageQueue();
// First process and remove any _UPDATE_ message in the queue // First process and remove any _UPDATE_ message in the queue
// With the current design, there can only be one at a time // With the current design, there can only be one at a time
@@ -1753,7 +1754,7 @@ BWindow::UpdateIfNeeded()
while (true) { while (true) {
queue->Lock(); queue->Lock();
BMessage *message = queue->FindMessage(_UPDATE_, 0); BMessage* message = queue->FindMessage(_UPDATE_, 0);
queue->RemoveMessage(message); queue->RemoveMessage(message);
queue->Unlock(); queue->Unlock();
@@ -1769,8 +1770,8 @@ BWindow::UpdateIfNeeded()
} }
BView * BView*
BWindow::FindView(const char *viewName) const BWindow::FindView(const char* viewName) const
{ {
BAutolock locker(const_cast<BWindow*>(this)); BAutolock locker(const_cast<BWindow*>(this));
if (!locker.IsLocked()) if (!locker.IsLocked())
@@ -1780,7 +1781,7 @@ BWindow::FindView(const char *viewName) const
} }
BView * BView*
BWindow::FindView(BPoint point) const BWindow::FindView(BPoint point) const
{ {
BAutolock locker(const_cast<BWindow*>(this)); BAutolock locker(const_cast<BWindow*>(this));
@@ -1793,7 +1794,7 @@ BWindow::FindView(BPoint point) const
} }
BView * BView*
BWindow::CurrentFocus() const BWindow::CurrentFocus() const
{ {
return fFocus; return fFocus;
@@ -1828,7 +1829,7 @@ BWindow::WindowActivated(bool state)
void void
BWindow::ConvertToScreen(BPoint *point) const BWindow::ConvertToScreen(BPoint* point) const
{ {
point->x += fFrame.left; point->x += fFrame.left;
point->y += fFrame.top; point->y += fFrame.top;
@@ -1843,7 +1844,7 @@ BWindow::ConvertToScreen(BPoint point) const
void void
BWindow::ConvertFromScreen(BPoint *point) const BWindow::ConvertFromScreen(BPoint* point) const
{ {
point->x -= fFrame.left; point->x -= fFrame.left;
point->y -= fFrame.top; point->y -= fFrame.top;
@@ -1858,7 +1859,7 @@ BWindow::ConvertFromScreen(BPoint point) const
void void
BWindow::ConvertToScreen(BRect *rect) const BWindow::ConvertToScreen(BRect* rect) const
{ {
rect->OffsetBy(fFrame.LeftTop()); rect->OffsetBy(fFrame.LeftTop());
} }
@@ -1926,7 +1927,7 @@ BWindow::DecoratorFrame() const
} }
const char * const char*
BWindow::Title() const BWindow::Title() const
{ {
return fTitle; return fTitle;
@@ -1934,7 +1935,7 @@ BWindow::Title() const
void void
BWindow::SetTitle(const char *title) BWindow::SetTitle(const char* title)
{ {
if (title == NULL) if (title == NULL)
title = ""; title = "";
@@ -1962,13 +1963,13 @@ BWindow::IsActive() const
void void
BWindow::SetKeyMenuBar(BMenuBar *bar) BWindow::SetKeyMenuBar(BMenuBar* bar)
{ {
fKeyMenuBar = bar; fKeyMenuBar = bar;
} }
BMenuBar * BMenuBar*
BWindow::KeyMenuBar() const BWindow::KeyMenuBar() const
{ {
return fKeyMenuBar; return fKeyMenuBar;
@@ -1995,7 +1996,7 @@ BWindow::IsFloating() const
status_t status_t
BWindow::AddToSubset(BWindow *window) BWindow::AddToSubset(BWindow* window)
{ {
if (window == NULL || window->Feel() != B_NORMAL_WINDOW_FEEL if (window == NULL || window->Feel() != B_NORMAL_WINDOW_FEEL
|| (fFeel != B_MODAL_SUBSET_WINDOW_FEEL || (fFeel != B_MODAL_SUBSET_WINDOW_FEEL
@@ -2017,7 +2018,7 @@ BWindow::AddToSubset(BWindow *window)
status_t status_t
BWindow::RemoveFromSubset(BWindow *window) BWindow::RemoveFromSubset(BWindow* window)
{ {
if (window == NULL || window->Feel() != B_NORMAL_WINDOW_FEEL if (window == NULL || window->Feel() != B_NORMAL_WINDOW_FEEL
|| (fFeel != B_MODAL_SUBSET_WINDOW_FEEL || (fFeel != B_MODAL_SUBSET_WINDOW_FEEL
@@ -2192,18 +2193,18 @@ BWindow::SetWindowAlignment(window_alignment mode,
status_t status_t
BWindow::GetWindowAlignment(window_alignment *mode, BWindow::GetWindowAlignment(window_alignment* mode,
int32 *h, int32 *hOffset, int32 *width, int32 *widthOffset, int32* h, int32* hOffset, int32* width, int32* widthOffset,
int32 *v, int32 *vOffset, int32 *height, int32 *heightOffset) const int32* v, int32* vOffset, int32* height, int32* heightOffset) const
{ {
if (!const_cast<BWindow *>(this)->Lock()) if (!const_cast<BWindow*>(this)->Lock())
return B_ERROR; return B_ERROR;
fLink->StartMessage(AS_GET_ALIGNMENT); fLink->StartMessage(AS_GET_ALIGNMENT);
status_t status; status_t status;
if (fLink->FlushWithReply(status) == B_OK && status == B_OK) { if (fLink->FlushWithReply(status) == B_OK && status == B_OK) {
fLink->Read<int32>((int32 *)mode); fLink->Read<int32>((int32*)mode);
fLink->Read<int32>(h); fLink->Read<int32>(h);
fLink->Read<int32>(hOffset); fLink->Read<int32>(hOffset);
fLink->Read<int32>(width); fLink->Read<int32>(width);
@@ -2214,7 +2215,7 @@ BWindow::GetWindowAlignment(window_alignment *mode,
fLink->Read<int32>(heightOffset); fLink->Read<int32>(heightOffset);
} }
const_cast<BWindow *>(this)->Unlock(); const_cast<BWindow*>(this)->Unlock();
return status; return status;
} }
@@ -2222,7 +2223,7 @@ BWindow::GetWindowAlignment(window_alignment *mode,
uint32 uint32
BWindow::Workspaces() const BWindow::Workspaces() const
{ {
if (!const_cast<BWindow *>(this)->Lock()) if (!const_cast<BWindow*>(this)->Lock())
return 0; return 0;
uint32 workspaces = 0; uint32 workspaces = 0;
@@ -2233,7 +2234,7 @@ BWindow::Workspaces() const
if (fLink->FlushWithReply(status) == B_OK && status == B_OK) if (fLink->FlushWithReply(status) == B_OK && status == B_OK)
fLink->Read<uint32>(&workspaces); fLink->Read<uint32>(&workspaces);
const_cast<BWindow *>(this)->Unlock(); const_cast<BWindow*>(this)->Unlock();
return workspaces; return workspaces;
} }
@@ -2254,7 +2255,7 @@ BWindow::SetWorkspaces(uint32 workspaces)
} }
BView * BView*
BWindow::LastMouseMovedView() const BWindow::LastMouseMovedView() const
{ {
return fLastMouseMovedView; return fLastMouseMovedView;
@@ -2440,7 +2441,7 @@ BWindow::InvalidateLayout(bool descendants)
status_t status_t
BWindow::GetSupportedSuites(BMessage *data) BWindow::GetSupportedSuites(BMessage* data)
{ {
if (data == NULL) if (data == NULL)
return B_BAD_VALUE; return B_BAD_VALUE;
@@ -2458,9 +2459,9 @@ BWindow::GetSupportedSuites(BMessage *data)
} }
BHandler * BHandler*
BWindow::ResolveSpecifier(BMessage *msg, int32 index, BMessage *specifier, BWindow::ResolveSpecifier(BMessage* msg, int32 index, BMessage* specifier,
int32 what, const char *property) int32 what, const char* property)
{ {
if (msg->what == B_WINDOW_MOVE_BY if (msg->what == B_WINDOW_MOVE_BY
|| msg->what == B_WINDOW_MOVE_TO) || msg->what == B_WINDOW_MOVE_TO)
@@ -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;
} }
@@ -2656,7 +2659,7 @@ BWindow::_InitData(BRect frame, const char* title, window_look look,
//! Rename the handler and its thread //! Rename the handler and its thread
void void
BWindow::_SetName(const char *title) BWindow::_SetName(const char* title)
{ {
if (title == NULL) if (title == NULL)
title = ""; title = "";
@@ -2691,7 +2694,7 @@ BWindow::_DequeueAll()
int32 count = port_count(fMsgPort); int32 count = port_count(fMsgPort);
for (int32 i = 0; i < count; i++) { for (int32 i = 0; i < count; i++) {
BMessage *message = MessageFromPort(0); BMessage* message = MessageFromPort(0);
if (message != NULL) if (message != NULL)
fDirectTarget->Queue()->AddMessage(message); fDirectTarget->Queue()->AddMessage(message);
} }
@@ -2756,7 +2759,7 @@ BWindow::task_looper()
// Get the target handler // Get the target handler
BMessage::Private messagePrivate(fLastMessage); BMessage::Private messagePrivate(fLastMessage);
bool usePreferred = messagePrivate.UsePreferredTarget(); bool usePreferred = messagePrivate.UsePreferredTarget();
BHandler *handler = NULL; BHandler* handler = NULL;
bool dropMessage = false; bool dropMessage = false;
if (usePreferred) { if (usePreferred) {
@@ -2765,7 +2768,7 @@ BWindow::task_looper()
handler = this; handler = this;
} else { } else {
gDefaultTokens.GetToken(messagePrivate.GetTarget(), gDefaultTokens.GetToken(messagePrivate.GetTarget(),
B_HANDLER_TOKEN, (void **)&handler); B_HANDLER_TOKEN, (void**)&handler);
// if this handler doesn't belong to us, we drop the message // if this handler doesn't belong to us, we drop the message
if (handler != NULL && handler->Looper() != this) { if (handler != NULL && handler->Looper() != this) {
@@ -2860,8 +2863,8 @@ BWindow::_ComposeType(window_look look, window_feel feel) const
void void
BWindow::_DecomposeType(window_type type, window_look *_look, BWindow::_DecomposeType(window_type type, window_look* _look,
window_feel *_feel) const window_feel* _feel) const
{ {
switch (type) { switch (type) {
case B_DOCUMENT_WINDOW: case B_DOCUMENT_WINDOW:
@@ -2946,7 +2949,7 @@ BWindow::_AdoptResize()
void void
BWindow::_SetFocus(BView *focusView, bool notifyInputServer) BWindow::_SetFocus(BView* focusView, bool notifyInputServer)
{ {
if (fFocus == focusView) if (fFocus == focusView)
return; return;
@@ -2975,8 +2978,8 @@ BWindow::_SetFocus(BView *focusView, bool notifyInputServer)
\brief Determines the target of a message received for the \brief Determines the target of a message received for the
focus view. focus view.
*/ */
BHandler * BHandler*
BWindow::_DetermineTarget(BMessage *message, BHandler *target) BWindow::_DetermineTarget(BMessage* message, BHandler* target)
{ {
if (target == NULL) if (target == NULL)
target = this; target = this;
@@ -3334,7 +3337,7 @@ BWindow::_HandleKeyDown(BMessage* event)
if (!_IsFocusMessage(event)) if (!_IsFocusMessage(event))
return false; return false;
const char *string = NULL; const char* string = NULL;
if (event->FindString("bytes", &string) != B_OK) if (event->FindString("bytes", &string) != B_OK)
return false; return false;
@@ -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;
} }
} }
@@ -3499,11 +3466,11 @@ BWindow::_HandleKeyDown(BMessage* event)
void void
BWindow::_KeyboardNavigation() BWindow::_KeyboardNavigation()
{ {
BMessage *message = CurrentMessage(); BMessage* message = CurrentMessage();
if (message == NULL) if (message == NULL)
return; return;
const char *bytes; const char* bytes;
uint32 modifiers; uint32 modifiers;
if (message->FindString("bytes", &bytes) != B_OK if (message->FindString("bytes", &bytes) != B_OK
|| bytes[0] != B_TAB) || bytes[0] != B_TAB)
@@ -3511,7 +3478,7 @@ BWindow::_KeyboardNavigation()
message->FindInt32("modifiers", (int32*)&modifiers); message->FindInt32("modifiers", (int32*)&modifiers);
BView *nextFocus; BView* nextFocus;
int32 jumpGroups = modifiers & B_CONTROL_KEY ? B_NAVIGABLE_JUMP : B_NAVIGABLE; int32 jumpGroups = modifiers & B_CONTROL_KEY ? B_NAVIGABLE_JUMP : B_NAVIGABLE;
if (modifiers & B_SHIFT_KEY) if (modifiers & B_SHIFT_KEY)
nextFocus = _FindPreviousNavigable(fFocus, jumpGroups); nextFocus = _FindPreviousNavigable(fFocus, jumpGroups);
@@ -3524,14 +3491,14 @@ BWindow::_KeyboardNavigation()
} }
BMessage * BMessage*
BWindow::ConvertToMessage(void *raw, int32 code) BWindow::ConvertToMessage(void* raw, int32 code)
{ {
return BLooper::ConvertToMessage(raw, code); return BLooper::ConvertToMessage(raw, code);
} }
BWindow::Shortcut * BWindow::Shortcut*
BWindow::_FindShortcut(uint32 key, uint32 modifiers) BWindow::_FindShortcut(uint32 key, uint32 modifiers)
{ {
int32 count = fShortcuts.CountItems(); int32 count = fShortcuts.CountItems();
@@ -3540,7 +3507,7 @@ BWindow::_FindShortcut(uint32 key, uint32 modifiers)
modifiers = Shortcut::PrepareModifiers(modifiers); modifiers = Shortcut::PrepareModifiers(modifiers);
for (int32 index = 0; index < count; index++) { for (int32 index = 0; index < count; index++) {
Shortcut *shortcut = (Shortcut *)fShortcuts.ItemAt(index); Shortcut* shortcut = (Shortcut*)fShortcuts.ItemAt(index);
if (shortcut->Matches(key, modifiers)) if (shortcut->Matches(key, modifiers))
return shortcut; return shortcut;
@@ -3550,7 +3517,7 @@ BWindow::_FindShortcut(uint32 key, uint32 modifiers)
} }
BView * BView*
BWindow::_FindView(int32 token) BWindow::_FindView(int32 token)
{ {
BHandler* handler; BHandler* handler;
@@ -3634,7 +3601,7 @@ BWindow::_FindNextNavigable(BView* focus, uint32 flags)
} }
BView * BView*
BWindow::_FindPreviousNavigable(BView* focus, uint32 flags) BWindow::_FindPreviousNavigable(BView* focus, uint32 flags)
{ {
if (focus == NULL) if (focus == NULL)
@@ -3669,11 +3636,11 @@ BWindow::_FindPreviousNavigable(BView* focus, uint32 flags)
Returns the last child in a view hierarchy. Returns the last child in a view hierarchy.
Needed only by _FindPreviousNavigable(). Needed only by _FindPreviousNavigable().
*/ */
BView * BView*
BWindow::_LastViewChild(BView *parent) BWindow::_LastViewChild(BView* parent)
{ {
while (true) { while (true) {
BView *last = parent->fFirstChild; BView* last = parent->fFirstChild;
if (last == NULL) if (last == NULL)
return parent; return parent;