* Changed the window cascading to be more useful with more windows.

* Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26113 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2008-06-23 21:24:38 +00:00
parent 8f0dc0c0d8
commit 8905dde820
2 changed files with 41 additions and 32 deletions
+37 -28
View File
@@ -268,16 +268,14 @@ void
TMailApp::MessageReceived(BMessage *msg) TMailApp::MessageReceived(BMessage *msg)
{ {
TMailWindow *window = NULL; TMailWindow *window = NULL;
entry_ref ref; entry_ref ref;
switch (msg->what) switch (msg->what) {
{
case M_NEW: case M_NEW:
{ {
int32 type; int32 type;
msg->FindInt32("type", &type); msg->FindInt32("type", &type);
switch (type) switch (type) {
{
case M_NEW: case M_NEW:
window = NewWindow(); window = NewWindow();
break; break;
@@ -342,8 +340,7 @@ TMailApp::MessageReceived(BMessage *msg)
case M_PREFS: case M_PREFS:
if (fPrefsWindow) if (fPrefsWindow)
fPrefsWindow->Activate(true); fPrefsWindow->Activate(true);
else else {
{
fPrefsWindow = new TPrefsWindow(BRect(fPrefsWindowPos.x, fPrefsWindow = new TPrefsWindow(BRect(fPrefsWindowPos.x,
fPrefsWindowPos.y, fPrefsWindowPos.x + PREF_WIDTH, fPrefsWindowPos.y, fPrefsWindowPos.x + PREF_WIDTH,
fPrefsWindowPos.y + PREF_HEIGHT), fPrefsWindowPos.y + PREF_HEIGHT),
@@ -391,8 +388,7 @@ TMailApp::MessageReceived(BMessage *msg)
break; break;
case REFS_RECEIVED: case REFS_RECEIVED:
if (msg->HasPointer("window")) if (msg->HasPointer("window")) {
{
msg->FindPointer("window", (void **)&window); msg->FindPointer("window", (void **)&window);
BMessage message(*msg); BMessage message(*msg);
window->PostMessage(&message, window); window->PostMessage(&message, window);
@@ -447,7 +443,7 @@ TMailApp::QuitRequested()
fMailWindowFrame = fLastMailWindowFrame; fMailWindowFrame = fLastMailWindowFrame;
// Last closed window becomes standard window size. // Last closed window becomes standard window size.
// Shut down the spam server if it's still running. If the user has trained it on a message, it will stay // Shut down the spam server if it's still running. If the user has trained it on a message, it will stay
// open. This is actually a good thing if there's quite a bit of spam -- no waiting for the thing to start // open. This is actually a good thing if there's quite a bit of spam -- no waiting for the thing to start
// up for each message, but it has no business staying that way if the user isn't doing anything with e-mail. :) // up for each message, but it has no business staying that way if the user isn't doing anything with e-mail. :)
@@ -1071,31 +1067,44 @@ TMailApp::FontChange()
} }
TMailWindow * TMailWindow*
TMailApp::NewWindow(const entry_ref *ref, const char *to, bool resend, TMailApp::NewWindow(const entry_ref* ref, const char* to, bool resend,
BMessenger *trackerMessenger) BMessenger* trackerMessenger)
{ {
BScreen screen(B_MAIN_SCREEN_ID); BScreen screen(B_MAIN_SCREEN_ID);
BRect screen_frame = screen.Frame(); BRect screenFrame = screen.Frame();
BRect r; BRect r;
if ((fMailWindowFrame.Width() > 1) && (fMailWindowFrame.Height() > 1)) if (fMailWindowFrame.Width() < 64 || fMailWindowFrame.Height() < 20) {
// default size
r.Set(6, TITLE_BAR_HEIGHT, 6 + WIND_WIDTH,
TITLE_BAR_HEIGHT + WIND_HEIGHT);
} else
r = fMailWindowFrame; r = fMailWindowFrame;
// make sure the window is not larger than the screen space
if (r.Height() > screenFrame.Height())
r.bottom = r.top + screenFrame.Height();
if (r.Width() > screenFrame.Width())
r.bottom = r.top + screenFrame.Width();
// cascading windows
if (fWindowCount < 6)
r.OffsetBy(fWindowCount * 20, fWindowCount * 20);
else else
r.Set(6, TITLE_BAR_HEIGHT, 6 + WIND_WIDTH, TITLE_BAR_HEIGHT + WIND_HEIGHT); r.OffsetBy((fWindowCount % 10) * 10 - 50, (fWindowCount % 10) * 10 - 50);
r.OffsetBy(fWindowCount * 20, fWindowCount * 20); // make sure the window is still on screen
if (r.left - 6 < screenFrame.left)
r.OffsetTo(screenFrame.left + 8, r.top);
if ((r.left - 6) < screen_frame.left) if (r.left + 20 > screenFrame.right)
r.OffsetTo(screen_frame.left + 8, r.top);
if ((r.left + 20) > screen_frame.right)
r.OffsetTo(6, r.top); r.OffsetTo(6, r.top);
if ((r.top - 26) < screen_frame.top) if (r.top - 26 < screenFrame.top)
r.OffsetTo(r.left, screen_frame.top + 26); r.OffsetTo(r.left, screenFrame.top + 26);
if ((r.top + 20) > screen_frame.bottom) if (r.top + 20 > screenFrame.bottom)
r.OffsetTo(r.left, TITLE_BAR_HEIGHT); r.OffsetTo(r.left, TITLE_BAR_HEIGHT);
if (r.Width() < WIND_WIDTH) if (r.Width() < WIND_WIDTH)
@@ -1105,19 +1114,19 @@ TMailApp::NewWindow(const entry_ref *ref, const char *to, bool resend,
BString title; BString title;
BFile file; BFile file;
if (!resend && ref && file.SetTo(ref, O_RDONLY) == B_NO_ERROR) { if (!resend && ref && file.SetTo(ref, O_RDONLY) == B_OK) {
BString name; BString name;
if (ReadAttrString(&file, B_MAIL_ATTR_NAME, &name) == B_NO_ERROR) { if (ReadAttrString(&file, B_MAIL_ATTR_NAME, &name) == B_OK) {
title << name; title << name;
BString subject; BString subject;
if (ReadAttrString(&file, B_MAIL_ATTR_SUBJECT, &subject) == B_NO_ERROR) if (ReadAttrString(&file, B_MAIL_ATTR_SUBJECT, &subject) == B_OK)
title << " -> " << subject; title << " -> " << subject;
} }
} }
if (title == "") if (title == "")
title = "Mail"; title = "Mail";
TMailWindow *window = new TMailWindow(r, title.String(), this, ref, to, TMailWindow* window = new TMailWindow(r, title.String(), this, ref, to,
&fContentFont, resend, trackerMessenger); &fContentFont, resend, trackerMessenger);
fWindowList.AddItem(window); fWindowList.AddItem(window);
+4 -4
View File
@@ -1639,11 +1639,11 @@ TMailWindow::QuitRequested()
BMessage message(WINDOW_CLOSED); BMessage message(WINDOW_CLOSED);
message.AddInt32("kind", MAIL_WINDOW); message.AddInt32("kind", MAIL_WINDOW);
message.AddPointer( "window", this ); message.AddPointer("window", this);
be_app->PostMessage(&message); be_app->PostMessage(&message);
if ((CurrentMessage()) && (CurrentMessage()->HasString("status"))) { if (CurrentMessage() && CurrentMessage()->HasString("status")) {
// User explicitly requests a status to set this message to. // User explicitly requests a status to set this message to.
if (!CurrentMessage()->HasString("same")) { if (!CurrentMessage()->HasString("same")) {
const char *status = CurrentMessage()->FindString("status"); const char *status = CurrentMessage()->FindString("status");
if (status != NULL) { if (status != NULL) {
@@ -1655,7 +1655,7 @@ TMailWindow::QuitRequested()
} }
} }
} else if (fRef) { } else if (fRef) {
// ...Otherwise just set the message read // ...Otherwise just set the message read
SetCurrentMessageRead(); SetCurrentMessageRead();
} }