Ticket #5285: 0001-Fix-5285-Aesthetic-bug-in-Mail-app.patch

File 0001-Fix-5285-Aesthetic-bug-in-Mail-app.patch, 8.1 KB (added by gbonvehi, 11 years ago)

Calculate base width using widest string

  • src/apps/mail/Header.cpp

    From 0c971b1900421d10ba1f998e41a996c6d0a7a2e2 Mon Sep 17 00:00:00 2001
    From: Guillermo Bonvehi <gbonvehi@gmail.com>
    Date: Fri, 3 Jan 2014 09:01:45 +0000
    Subject: [PATCH] Fix #5285 Aesthetic bug in Mail app
    
    ---
     src/apps/mail/Header.cpp | 72 +++++++++++++++++++++++++++++++++---------------
     1 file changed, 50 insertions(+), 22 deletions(-)
    
    diff --git a/src/apps/mail/Header.cpp b/src/apps/mail/Header.cpp
    index 485c7e6..96bf850 100644
    a b of their respective holders. All rights reserved.  
    5252#include <MenuBar.h>
    5353#include <MenuField.h>
    5454#include <MenuItem.h>
     55#include <ObjectList.h>
    5556#include <PopUpMenu.h>
    5657#include <Query.h>
    5758#include <String.h>
    THeaderView::THeaderView(BRect rect, BRect windowRect, bool incoming,  
    159160    BMenuField* field;
    160161    BMessage* msg;
    161162
    162     float x = StringWidth( /* The longest title string in the header area */
    163         B_TRANSLATE("Attachments: ")) + 9;
     163    BString kAttachments(B_TRANSLATE("Attachments: "));
     164    BString kDecoding(B_TRANSLATE("Decoding:"));
     165    BString kFrom(B_TRANSLATE("From:"));
     166    BString kTo(B_TRANSLATE("To:"));
     167    BString kEncoding(B_TRANSLATE("Encoding:"));
     168    BString kAccount(B_TRANSLATE("Account:"));
     169    BString kCc(B_TRANSLATE("Cc:"));
     170    BString kSubject(B_TRANSLATE("Subject:"));
     171    BString kBcc(B_TRANSLATE("Bcc:"));
     172   
     173    BObjectList<BString> kToCompare;
     174    kToCompare.AddItem(&kAttachments);
     175    kToCompare.AddItem(&kDecoding);
     176    kToCompare.AddItem(&kFrom);
     177    kToCompare.AddItem(&kTo);
     178    kToCompare.AddItem(&kEncoding);
     179    kToCompare.AddItem(&kAccount);
     180    kToCompare.AddItem(&kCc);
     181    kToCompare.AddItem(&kSubject);
     182    kToCompare.AddItem(&kBcc);
     183   
     184    float x = 0;
     185    // Get the longest translated string's width to use when calculating
     186    // horizontal positions
     187    for(int i = 0; i < kToCompare.CountItems(); ++i) {
     188        float stringWidth = StringWidth(kToCompare.ItemAt(i)->String()) + 9;
     189        if (stringWidth > x)
     190            x = stringWidth;
     191    }
    164192    float y = TO_FIELD_V;
    165 
     193   
    166194    BMenuBar* dummy = new BMenuBar(BRect(0, 0, 100, 15), "Dummy");
    167195    AddChild(dummy);
    168196    float width, menuBarHeight;
    THeaderView::THeaderView(BRect rect, BRect windowRect, bool incoming,  
    249277    if (fIncoming && !resending) {
    250278        // Set up the character set pop-up menu on the right of "To" box.
    251279        r.Set (windowRect.Width() - widestCharacterSet -
    252             StringWidth (B_TRANSLATE("Decoding:")) - 2 * SEPARATOR_MARGIN,
     280            StringWidth (kDecoding.String()) - 2 * SEPARATOR_MARGIN,
    253281                y - 2, windowRect.Width() - SEPARATOR_MARGIN,
    254282                y + menuFieldHeight);
    255         field = new BMenuField (r, "decoding", B_TRANSLATE("Decoding:"),
     283        field = new BMenuField (r, "decoding", kDecoding.String(),
    256284            fEncodingMenu, true /* fixedSize */,
    257285            B_FOLLOW_TOP | B_FOLLOW_RIGHT,
    258286            B_WILL_DRAW | B_NAVIGABLE | B_NAVIGABLE_JUMP);
    259         field->SetDivider(field->StringWidth(B_TRANSLATE("Decoding:")) + 5);
     287        field->SetDivider(field->StringWidth(kDecoding.String()) + 5);
    260288        AddChild(field);
    261289        r.Set(SEPARATOR_MARGIN, y,
    262290              field->Frame().left - SEPARATOR_MARGIN, y + menuFieldHeight);
    263         sprintf(string, B_TRANSLATE("From:"));
     291        sprintf(string, kFrom.String());
    264292    } else {
    265293        r.Set(x - 12, y, windowRect.Width() - SEPARATOR_MARGIN,
    266294            y + menuFieldHeight);
    THeaderView::THeaderView(BRect rect, BRect windowRect, bool incoming,  
    288316    if (!fIncoming || resending) {
    289317        r.right = r.left - 5;
    290318        r.left = r.right - ceilf(be_plain_font->StringWidth(
    291             B_TRANSLATE("To:")) + 25);
     319            kTo.String()) + 25);
    292320        r.top -= 1;
    293         fToMenu = new QPopupMenu(B_TRANSLATE("To:"));
     321        fToMenu = new QPopupMenu(kTo.String());
    294322        field = new BMenuField(r, "", "", fToMenu, true,
    295323            B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW);
    296324        field->SetDivider(0.0);
    THeaderView::THeaderView(BRect rect, BRect windowRect, bool incoming,  
    302330    if (!fIncoming || resending) {
    303331        // Put the character set box on the right of the From field.
    304332        r.Set(windowRect.Width() - widestCharacterSet -
    305             StringWidth(B_TRANSLATE("Encoding:")) - 2 * SEPARATOR_MARGIN,
     333            StringWidth(kEncoding.String()) - 2 * SEPARATOR_MARGIN,
    306334            y - 2, windowRect.Width() - SEPARATOR_MARGIN, y + menuFieldHeight);
    307335        BMenuField* encodingField = new BMenuField(r, "encoding",
    308             B_TRANSLATE("Encoding:"), fEncodingMenu, true /* fixedSize */,
     336            kEncoding.String(), fEncodingMenu, true /* fixedSize */,
    309337            B_FOLLOW_TOP | B_FOLLOW_RIGHT,
    310338            B_WILL_DRAW | B_NAVIGABLE | B_NAVIGABLE_JUMP);
    311339        encodingField->SetDivider(encodingField->StringWidth(
    312             B_TRANSLATE("Encoding:")) + 5);
     340            kEncoding.String()) + 5);
    313341        AddChild(encodingField);
    314342
    315343        field = encodingField;
    THeaderView::THeaderView(BRect rect, BRect windowRect, bool incoming,  
    359387
    360388        r.Set(SEPARATOR_MARGIN, y - 2,
    361389              field->Frame().left - SEPARATOR_MARGIN, y + menuFieldHeight);
    362         field = new BMenuField(r, "account", B_TRANSLATE("From:"),
     390        field = new BMenuField(r, "account", kFrom.String(),
    363391            fAccountMenu, true /* fixedSize */,
    364392            B_FOLLOW_TOP | B_FOLLOW_LEFT_RIGHT,
    365393            B_WILL_DRAW | B_NAVIGABLE | B_NAVIGABLE_JUMP);
    THeaderView::THeaderView(BRect rect, BRect windowRect, bool incoming,  
    375403              windowRect.Width() - SEPARATOR_MARGIN, y + menuFieldHeight);
    376404        if (account)
    377405            r.right -= SEPARATOR_MARGIN + ACCOUNT_FIELD_WIDTH;
    378         fAccountTo = new TTextControl(r, B_TRANSLATE("To:"), NULL, fIncoming,
     406        fAccountTo = new TTextControl(r, kTo.String(), NULL, fIncoming,
    379407            false, B_FOLLOW_LEFT_RIGHT);
    380408        fAccountTo->SetEnabled(false);
    381409        fAccountTo->SetDivider(x - 12 - SEPARATOR_MARGIN);
    THeaderView::THeaderView(BRect rect, BRect windowRect, bool incoming,  
    384412
    385413        if (account) {
    386414            r.left = r.right + 6;  r.right = windowRect.Width() - SEPARATOR_MARGIN;
    387             fAccount = new TTextControl(r, B_TRANSLATE("Account:"), NULL,
     415            fAccount = new TTextControl(r, kAccount.String(), NULL,
    388416                fIncoming, false, B_FOLLOW_RIGHT | B_FOLLOW_TOP);
    389417            fAccount->SetEnabled(false);
    390418            AddChild(fAccount);
    THeaderView::THeaderView(BRect rect, BRect windowRect, bool incoming,  
    397425        r.Set(SEPARATOR_MARGIN, y,
    398426            windowRect.Width() - SEPARATOR_MARGIN, y + menuFieldHeight);
    399427        y += controlHeight;
    400         fCc = new TTextControl(r, B_TRANSLATE("Cc:"),
     428        fCc = new TTextControl(r, kCc.String(),
    401429            NULL, fIncoming, false, B_FOLLOW_LEFT_RIGHT);
    402430        fCc->SetEnabled(false);
    403431        fCc->SetDivider(x - 12 - SEPARATOR_MARGIN);
    THeaderView::THeaderView(BRect rect, BRect windowRect, bool incoming,  
    409437    r.Set(SEPARATOR_MARGIN, y,
    410438        windowRect.Width() - SEPARATOR_MARGIN, y + menuFieldHeight);
    411439    y += controlHeight;
    412     fSubject = new TTextControl(r, B_TRANSLATE("Subject:"),
     440    fSubject = new TTextControl(r, kSubject.String(),
    413441        new BMessage(SUBJECT_FIELD),fIncoming, false, B_FOLLOW_LEFT_RIGHT);
    414442    AddChild(fSubject);
    415443    (msg = new BMessage(FIELD_CHANGED))->AddInt32("bitmask", FIELD_SUBJECT);
    THeaderView::THeaderView(BRect rect, BRect windowRect, bool incoming,  
    433461
    434462        r.right = r.left - 5;
    435463        r.left = r.right - ceilf(be_plain_font->StringWidth(
    436             B_TRANSLATE("Cc:")) + 25);
     464            kCc.String()) + 25);
    437465        r.top -= 1;
    438         fCcMenu = new QPopupMenu(B_TRANSLATE("Cc:"));
     466        fCcMenu = new QPopupMenu(kCc.String());
    439467        field = new BMenuField(r, "", "", fCcMenu, true,
    440468            B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW);
    441469
    THeaderView::THeaderView(BRect rect, BRect windowRect, bool incoming,  
    443471        field->SetEnabled(true);
    444472        AddChild(field);
    445473
    446         r.Set(BCC_FIELD_H + be_plain_font->StringWidth(B_TRANSLATE("Bcc:")), y,
     474        r.Set(BCC_FIELD_H + be_plain_font->StringWidth(kBcc.String()), y,
    447475              windowRect.Width() - SEPARATOR_MARGIN, y + menuFieldHeight);
    448476        y += controlHeight;
    449477        fBcc = new TTextControl(r, "", new BMessage(BCC_FIELD),
    THeaderView::THeaderView(BRect rect, BRect windowRect, bool incoming,  
    457485
    458486        r.right = r.left - 5;
    459487        r.left = r.right - ceilf(be_plain_font->StringWidth(
    460             B_TRANSLATE("Bcc:")) + 25);
     488            kBcc.String()) + 25);
    461489        r.top -= 1;
    462         fBccMenu = new QPopupMenu(B_TRANSLATE("Bcc:"));
     490        fBccMenu = new QPopupMenu(kBcc.String());
    463491        field = new BMenuField(r, "", "", fBccMenu, true,
    464492            B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW);
    465493        field->SetDivider(0.0);