StyledEdit: Make default window size depend on font size.
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2010, Haiku, Inc. All Rights Reserved.
|
* Copyright 2002-2016, Haiku, Inc. All Rights Reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -32,7 +32,9 @@
|
|||||||
using namespace BPrivate;
|
using namespace BPrivate;
|
||||||
|
|
||||||
|
|
||||||
BRect gWindowRect(7 - 15, 26 - 15, 507, 426);
|
static BRect sWindowRect(7, 26, 507, 426);
|
||||||
|
static float sCascadeOffset = 15;
|
||||||
|
static BPoint sTopLeft = BPoint(7, 26);
|
||||||
|
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
@@ -42,15 +44,15 @@ namespace
|
|||||||
{
|
{
|
||||||
BScreen screen;
|
BScreen screen;
|
||||||
BRect screenBorder = screen.Frame();
|
BRect screenBorder = screen.Frame();
|
||||||
float left = gWindowRect.left + 15;
|
float left = sWindowRect.left + sCascadeOffset;
|
||||||
if (left + gWindowRect.Width() > screenBorder.right)
|
if (left + sWindowRect.Width() > screenBorder.right)
|
||||||
left = 7;
|
left = sTopLeft.x;
|
||||||
|
|
||||||
float top = gWindowRect.top + 15;
|
float top = sWindowRect.top + sCascadeOffset;
|
||||||
if (top + gWindowRect.Height() > screenBorder.bottom)
|
if (top + sWindowRect.Height() > screenBorder.bottom)
|
||||||
top = 26;
|
top = sTopLeft.y;
|
||||||
|
|
||||||
gWindowRect.OffsetTo(BPoint(left, top));
|
sWindowRect.OffsetTo(BPoint(left, top));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -60,19 +62,19 @@ namespace
|
|||||||
BScreen screen;
|
BScreen screen;
|
||||||
BRect screenBorder = screen.Frame();
|
BRect screenBorder = screen.Frame();
|
||||||
|
|
||||||
float left = gWindowRect.left - 15;
|
float left = sWindowRect.left - sCascadeOffset;
|
||||||
if (left < 7) {
|
if (left < sTopLeft.x) {
|
||||||
left = screenBorder.right - gWindowRect.Width() - 7;
|
left = screenBorder.right - sWindowRect.Width() - sTopLeft.x;
|
||||||
left = left - ((int)left % 15) + 7;
|
left = left - ((int)left % (int)sCascadeOffset) + sTopLeft.x;
|
||||||
}
|
}
|
||||||
|
|
||||||
float top = gWindowRect.top - 15;
|
float top = sWindowRect.top - sCascadeOffset;
|
||||||
if (top < 26) {
|
if (top < sTopLeft.y) {
|
||||||
top = screenBorder.bottom - gWindowRect.Height() - 26;
|
top = screenBorder.bottom - sWindowRect.Height() - sTopLeft.y;
|
||||||
top = top - ((int)left % 15) + 26;
|
top = top - ((int)left % (int)sCascadeOffset) + sTopLeft.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
gWindowRect.OffsetTo(BPoint(left, top));
|
sWindowRect.OffsetTo(BPoint(left, top));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,6 +132,16 @@ StyledEditApp::StyledEditApp()
|
|||||||
fWindowCount = 0;
|
fWindowCount = 0;
|
||||||
fNextUntitledWindow = 1;
|
fNextUntitledWindow = 1;
|
||||||
fBadArguments = false;
|
fBadArguments = false;
|
||||||
|
|
||||||
|
float factor = be_plain_font->Size() / 12.0f;
|
||||||
|
sCascadeOffset *= factor;
|
||||||
|
sTopLeft.x *= factor;
|
||||||
|
sTopLeft.y *= factor;
|
||||||
|
sWindowRect.left *= factor;
|
||||||
|
sWindowRect.top *= factor;
|
||||||
|
sWindowRect.right *= factor;
|
||||||
|
sWindowRect.bottom *= factor;
|
||||||
|
sWindowRect.PrintToStream();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -171,8 +183,8 @@ StyledEditApp::MessageReceived(BMessage* message)
|
|||||||
void
|
void
|
||||||
StyledEditApp::OpenDocument()
|
StyledEditApp::OpenDocument()
|
||||||
{
|
{
|
||||||
|
new StyledEditWindow(sWindowRect, fNextUntitledWindow++, fOpenAsEncoding);
|
||||||
cascade();
|
cascade();
|
||||||
new StyledEditWindow(gWindowRect, fNextUntitledWindow++, fOpenAsEncoding);
|
|
||||||
fWindowCount++;
|
fWindowCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -224,8 +236,8 @@ StyledEditApp::OpenDocument(entry_ref* ref, BMessage* message)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
document = new StyledEditWindow(sWindowRect, ref, fOpenAsEncoding);
|
||||||
cascade();
|
cascade();
|
||||||
document = new StyledEditWindow(gWindowRect, ref, fOpenAsEncoding);
|
|
||||||
|
|
||||||
if (message != NULL)
|
if (message != NULL)
|
||||||
document->PostMessage(message);
|
document->PostMessage(message);
|
||||||
|
|||||||
Reference in New Issue
Block a user