Skip to content

Commit

Permalink
Mail: sizing/placing cleanup.
Browse files Browse the repository at this point in the history
* Don't set a default fixed font size - just use the default fixed font.
* The preferences and signature window no longer have a default size,
  and position, either. Instead, they are placed over the active window.
* Fixed spacing in the preferences window.
* Converted the signature window to use the layout API.
* Minor cleanup.
  • Loading branch information
axeld committed Nov 16, 2015
1 parent 6548454 commit 67c3eee
Show file tree
Hide file tree
Showing 8 changed files with 208 additions and 271 deletions.
104 changes: 51 additions & 53 deletions src/apps/mail/MailApp.cpp
Expand Up @@ -122,25 +122,22 @@ TMailApp::TMailApp()
fPeopleGroups(fPeopleQueryList)
{
// set default values
fContentFont.SetSize(12.0);
fAutoMarkRead = true;
fSignature = (char*)malloc(strlen(B_TRANSLATE("None")) + 1);
strcpy(fSignature, B_TRANSLATE("None"));
fReplyPreamble = strdup(B_TRANSLATE("%e wrote:\\n"));

fMailWindowFrame.Set(0, 0, 0, 0);
fSignatureWindowFrame.Set(6, TITLE_BAR_HEIGHT, 6 + kSigWidth,
TITLE_BAR_HEIGHT + kSigHeight);
fPrefsWindowPos.Set(6, TITLE_BAR_HEIGHT);

const BCharacterSet *defaultComposeEncoding =
BCharacterSetRoster::FindCharacterSetByName(
B_TRANSLATE_COMMENT("UTF-8", "This string is used as a key to set "
"default message compose encoding. It must be correct IANA name from "
"http://cgit.haiku-os.org/haiku/tree/src/kits/textencoding"
"/character_sets.cpp Translate it only if you want to change default "
"message compose encoding for your locale. If you don't know what is "
"it and why it may needs changing, just leave \"UTF-8\"."));

const BCharacterSet* defaultComposeEncoding
= BCharacterSetRoster::FindCharacterSetByName(B_TRANSLATE_COMMENT(
"UTF-8", "This string is used as a key to set default message "
"compose encoding. It must be correct IANA name from "
"http://cgit.haiku-os.org/haiku/tree/src/kits/textencoding"
"/character_sets.cpp Translate it only if you want to change "
"default message compose encoding for your locale. If you don't "
"know what is it and why it may needs changing, just leave "
"\"UTF-8\"."));
if (defaultComposeEncoding != NULL)
fMailCharacterSet = defaultComposeEncoding->GetConversionID();

Expand Down Expand Up @@ -325,26 +322,30 @@ TMailApp::MessageReceived(BMessage *msg)
if (fPrefsWindow)
fPrefsWindow->Activate(true);
else {
fPrefsWindow = new TPrefsWindow(BRect(fPrefsWindowPos.x,
fPrefsWindowPos.y, fPrefsWindowPos.x + PREF_WIDTH,
fPrefsWindowPos.y + PREF_HEIGHT),
fPrefsWindow = new TPrefsWindow(fPrefsWindowPos,
&fContentFont, NULL, &fWrapMode, &fAttachAttributes,
&fColoredQuotes, &fDefaultAccount, &fUseAccountFrom,
&fReplyPreamble, &fSignature, &fMailCharacterSet,
&fWarnAboutUnencodableCharacters,
&fStartWithSpellCheckOn, &fAutoMarkRead,
&fShowToolBar);
if (fPrefsWindowPos.x <= 0 || fPrefsWindowPos.y <= 0) {
TMailWindow* window = _ActiveWindow();
if (window != NULL)
fPrefsWindow->CenterIn(window->Frame());
else
fPrefsWindow->CenterOnScreen();
}
fPrefsWindow->MoveOnScreen();
fPrefsWindow->Show();
}
break;

case PREFS_CHANGED:
{
// Notify all Mail windows
TMailWindow *window;
for (int32 i = 0; (window=(TMailWindow *)fWindowList.ItemAt(i))
!= NULL; i++)
{
for (int32 i = 0; i < fWindowList.CountItems(); i++) {
TMailWindow* window = (TMailWindow*)fWindowList.ItemAt(i);
window->Lock();
window->UpdatePreferences();
window->UpdateViews();
Expand All @@ -358,10 +359,18 @@ TMailApp::MessageReceived(BMessage *msg)
break;

case M_EDIT_SIGNATURE:
if (fSigWindow)
if (fSigWindow != NULL)
fSigWindow->Activate(true);
else {
fSigWindow = new TSignatureWindow(fSignatureWindowFrame);
if (!fSignatureWindowFrame.IsValid()) {
TMailWindow* window = _ActiveWindow();
if (window != NULL)
fSigWindow->CenterIn(window->Frame());
else
fSigWindow->CenterOnScreen();
}
fSigWindow->MoveOnScreen();
fSigWindow->Show();
}
break;
Expand All @@ -372,7 +381,7 @@ TMailApp::MessageReceived(BMessage *msg)

case REFS_RECEIVED:
if (msg->HasPointer("window")) {
msg->FindPointer("window", (void **)&window);
msg->FindPointer("window", (void**)&window);
BMessage message(*msg);
window->PostMessage(&message, window);
}
Expand All @@ -382,8 +391,8 @@ TMailApp::MessageReceived(BMessage *msg)
switch (msg->FindInt32("kind")) {
case MAIL_WINDOW:
{
TMailWindow *window;
if( msg->FindPointer( "window", (void **)&window ) == B_OK )
TMailWindow* window;
if( msg->FindPointer("window", (void**)&window) == B_OK)
fWindowList.RemoveItem(window);
fWindowCount--;
break;
Expand Down Expand Up @@ -739,6 +748,18 @@ TMailApp::_CheckForSpamFilterExistence()
}


TMailWindow*
TMailApp::_ActiveWindow()
{
for (int32 i = 0; i < fWindowList.CountItems(); i++) {
TMailWindow* window = (TMailWindow*)fWindowList.ItemAt(i);
if (window->IsActive())
return window;
}
return NULL;
}


void
TMailApp::SetPrintSettings(const BMessage* printSettings)
{
Expand Down Expand Up @@ -1091,42 +1112,18 @@ TMailWindow*
TMailApp::NewWindow(const entry_ref* ref, const char* to, bool resend,
BMessenger* trackerMessenger)
{
BScreen screen(B_MAIN_SCREEN_ID);
BRect screenFrame = screen.Frame();

float fontFactor = be_plain_font->Size() / 12.0f;
BRect r;
if (fMailWindowFrame.Width() < 64 || fMailWindowFrame.Height() < 20) {
// default size
r.Set(6, TITLE_BAR_HEIGHT, 6 + WIND_WIDTH,
TITLE_BAR_HEIGHT + WIND_HEIGHT);
r.Set(40 * fontFactor, 40 * fontFactor, fontFactor * (40 + WIND_WIDTH),
fontFactor * (40 + WIND_HEIGHT));
} else
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
r.OffsetBy(((fWindowCount + 5) % 10) * 15 - 75,
((fWindowCount + 5) % 10) * 15 - 75);

// make sure the window is still on screen
if (r.left - 6 < screenFrame.left)
r.OffsetTo(screenFrame.left + 8, r.top);

if (r.left + 20 > screenFrame.right)
r.OffsetTo(6, r.top);

if (r.top - 26 < screenFrame.top)
r.OffsetTo(r.left, screenFrame.top + 26);

if (r.top + 20 > screenFrame.bottom)
r.OffsetTo(r.left, TITLE_BAR_HEIGHT);

if (r.Width() < WIND_WIDTH)
r.right = r.left + WIND_WIDTH;
r.OffsetBy(fontFactor * (((fWindowCount + 5) % 10) * 15 - 75),
fontFactor * (((fWindowCount + 5) % 10) * 15 - 75));

fWindowCount++;

Expand All @@ -1148,6 +1145,7 @@ TMailApp::NewWindow(const entry_ref* ref, const char* to, bool resend,
&fContentFont, resend, trackerMessenger);
fWindowList.AddItem(window);

window->MoveOnScreen();
return window;
}

Expand Down
1 change: 1 addition & 0 deletions src/apps/mail/MailApp.h
Expand Up @@ -104,6 +104,7 @@ class TMailApp : public BApplication {
private:
void _ClearPrintSettings();
void _CheckForSpamFilterExistence();
TMailWindow* _ActiveWindow();

status_t GetSettingsPath(BPath &path);
status_t LoadOldSettings();
Expand Down
4 changes: 1 addition & 3 deletions src/apps/mail/MailSupport.h
Expand Up @@ -39,10 +39,8 @@ All rights reserved.


#define MAX_DICTIONARIES 8
#define TITLE_BAR_HEIGHT 25
#define WIND_WIDTH 457
#define WIND_HEIGHT 400
#define RIGHT_BOUNDARY 8191
#define WIND_HEIGHT 500
#define SEPARATOR_MARGIN 7
#define QUOTE "> "

Expand Down
57 changes: 24 additions & 33 deletions src/apps/mail/Prefs.cpp
Expand Up @@ -64,26 +64,14 @@ using namespace BPrivate;

#define B_TRANSLATION_CONTEXT "Mail"

#define BUTTON_WIDTH 70
#define BUTTON_HEIGHT 20
#define ITEM_SPACE 6

#define OK_BUTTON_X1 (PREF_WIDTH - BUTTON_WIDTH - 6)
#define OK_BUTTON_X2 (OK_BUTTON_X1 + BUTTON_WIDTH)

#define REVERT_BUTTON_X1 8
#define REVERT_BUTTON_X2 (REVERT_BUTTON_X1 + BUTTON_WIDTH)

enum P_MESSAGES {P_OK = 128, P_CANCEL, P_REVERT, P_FONT,
P_SIZE, P_LEVEL, P_WRAP, P_ATTACH_ATTRIBUTES,
P_SIG, P_ENC, P_WARN_UNENCODABLE,
P_SPELL_CHECK_START_ON, P_BUTTON_BAR,
P_ACCOUNT, P_REPLYTO, P_REPLY_PREAMBLE,
P_COLORED_QUOTES, P_MARK_READ};

extern BPoint prefs_window;

//#pragma mark -
enum P_MESSAGES {
P_OK = 128, P_CANCEL, P_REVERT, P_FONT,
P_SIZE, P_LEVEL, P_WRAP, P_ATTACH_ATTRIBUTES,
P_SIG, P_ENC, P_WARN_UNENCODABLE,
P_SPELL_CHECK_START_ON, P_BUTTON_BAR,
P_ACCOUNT, P_REPLYTO, P_REPLY_PREAMBLE,
P_COLORED_QUOTES, P_MARK_READ
};


static inline void
Expand All @@ -96,12 +84,17 @@ add_menu_to_layout(BMenuField* menu, BGridLayout* layout, int32& row)
}


TPrefsWindow::TPrefsWindow(BRect rect, BFont* font, int32* level, bool* wrap,
bool* attachAttributes, bool* cquotes, int32* account, int32* replyTo,
char** preamble, char** sig, uint32* encoding, bool* warnUnencodable,
bool* spellCheckStartOn, bool* autoMarkRead, uint8* buttonBar)
// #pragma mark -


TPrefsWindow::TPrefsWindow(BPoint leftTop, BFont* font, int32* level,
bool* wrap, bool* attachAttributes, bool* cquotes, int32* account,
int32* replyTo, char** preamble, char** sig, uint32* encoding,
bool* warnUnencodable, bool* spellCheckStartOn, bool* autoMarkRead,
uint8* buttonBar)
:
BWindow(rect, B_TRANSLATE("Mail preferences"),
BWindow(BRect(leftTop.x, leftTop.y, leftTop.x + 100, leftTop.y + 100),
B_TRANSLATE("Mail preferences"),
B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE
| B_AUTO_UPDATE_SIZE_LIMITS),

Expand Down Expand Up @@ -149,16 +142,14 @@ TPrefsWindow::TPrefsWindow(BRect rect, BFont* font, int32* level, bool* wrap,

// group boxes

const float kSpacing = 8;

BGridView* interfaceView = new BGridView(kSpacing, kSpacing);
BGridView* interfaceView = new BGridView();
BGridLayout* interfaceLayout = interfaceView->GridLayout();
interfaceLayout->SetInsets(kSpacing, kSpacing, kSpacing, kSpacing);
BGridView* mailView = new BGridView(kSpacing, kSpacing);
BGridView* mailView = new BGridView();
BGridLayout* mailLayout = mailView->GridLayout();
mailLayout->SetInsets(kSpacing, kSpacing, kSpacing, kSpacing);

interfaceLayout->SetInsets(B_USE_DEFAULT_SPACING);
interfaceLayout->AlignLayoutWith(mailLayout, B_HORIZONTAL);
mailLayout->SetInsets(B_USE_DEFAULT_SPACING);

BBox* interfaceBox = new BBox(B_FANCY_BORDER, interfaceView);
interfaceBox->SetLabel(B_TRANSLATE("User interface"));
Expand Down Expand Up @@ -266,12 +257,12 @@ TPrefsWindow::TPrefsWindow(BRect rect, BFont* font, int32* level, bool* wrap,
BLayoutBuilder::Group<>(this, B_VERTICAL)
.Add(interfaceBox)
.Add(mailBox)
.AddGroup(B_HORIZONTAL, 0)
.AddGroup(B_HORIZONTAL)
.Add(fRevert)
.AddGlue()
.Add(cancelButton)
.Add(okButton)
.End()
.End()
.SetInsets(B_USE_WINDOW_SPACING);

Show();
Expand Down
6 changes: 2 additions & 4 deletions src/apps/mail/Prefs.h
Expand Up @@ -47,8 +47,6 @@ class BTextControl;
#define ACCOUNT_USE_DEFAULT 0
#define ACCOUNT_FROM_MAIL 1

#define PREF_WIDTH 340
#define PREF_HEIGHT 330

struct EncodingItem {
char* name;
Expand All @@ -60,7 +58,7 @@ extern const EncodingItem kEncodings[];

class TPrefsWindow : public BWindow {
public:
TPrefsWindow(BRect rect, BFont* font,
TPrefsWindow(BPoint leftTop, BFont* font,
int32* level, bool* warp,
bool* attachAttributes, bool* cquotes,
int32* account, int32* replyTo,
Expand Down Expand Up @@ -91,7 +89,7 @@ class TPrefsWindow : public BWindow {
BPopUpMenu* _BuildAutoMarkReadMenu(
bool autoMarkRead);
BPopUpMenu* _BuildButtonBarMenu(uint8 show);

BPopUpMenu* _BuildBoolMenu(uint32 msg,
const char* boolItem, bool isTrue);

Expand Down
1 change: 0 additions & 1 deletion src/apps/mail/Settings.cpp
Expand Up @@ -79,7 +79,6 @@ Settings::Settings()
fMailCharacterSet(B_MS_WINDOWS_CONVERSION),
fContentFont(be_fixed_font)
{
fContentFont.SetSize(12.0);
fSignature = B_TRANSLATE("None");

LoadSettings();
Expand Down

0 comments on commit 67c3eee

Please sign in to comment.