diff --git a/src/apps/bemail/Enclosures.cpp b/src/apps/bemail/Enclosures.cpp index ab80668dd8..e69d885b87 100644 --- a/src/apps/bemail/Enclosures.cpp +++ b/src/apps/bemail/Enclosures.cpp @@ -120,19 +120,17 @@ GetTrackerIcon(BMimeType &type, BBitmap *icon, icon_size iconSize) TEnclosuresView::TEnclosuresView(BRect rect, BRect wind_rect) - : BView(rect, "m_enclosures", B_FOLLOW_TOP | B_FOLLOW_LEFT_RIGHT, B_WILL_DRAW), + : BView(rect, "m_enclosures", B_FOLLOW_TOP | B_FOLLOW_LEFT_RIGHT, B_WILL_DRAW), fFocus(false) { - rgb_color c; - c.red = c.green = c.blue = VIEW_COLOR; - SetViewColor(c); + SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); BFont font = *be_plain_font; font.SetSize(FONT_SIZE); font_height fHeight; font.GetHeight(&fHeight); fOffset = 12; - + BRect r; r.left = ENCLOSE_TEXT_H + font.StringWidth( MDR_DIALECT_CHOICE ("Enclosures: ","添付ファイル")) + 5; @@ -166,16 +164,13 @@ TEnclosuresView::~TEnclosuresView() void TEnclosuresView::Draw(BRect where) { - float offset; - BFont font = *be_plain_font; - BView::Draw(where); + + BFont font = *be_plain_font; font.SetSize(FONT_SIZE); SetFont(&font); SetHighColor(0, 0, 0); - SetLowColor(VIEW_COLOR, VIEW_COLOR, VIEW_COLOR); - - offset = 12; + SetLowColor(ViewColor()); font_height fHeight; font.GetHeight(&fHeight); diff --git a/src/apps/bemail/Mail.h b/src/apps/bemail/Mail.h index dfe843b977..a22c55e8d4 100644 --- a/src/apps/bemail/Mail.h +++ b/src/apps/bemail/Mail.h @@ -60,7 +60,6 @@ All rights reserved. #define WIND_HEIGHT 400 #define RIGHT_BOUNDARY 8191 #define SEPARATOR_MARGIN 7 -#define VIEW_COLOR 216 #define FONT_SIZE 11.0 #define QUOTE "> " diff --git a/src/apps/bemail/Status.cpp b/src/apps/bemail/Status.cpp index 3c6d2c8af5..4f40e67cb2 100644 --- a/src/apps/bemail/Status.cpp +++ b/src/apps/bemail/Status.cpp @@ -32,105 +32,109 @@ names are registered trademarks or trademarks of their respective holders. All rights reserved. */ -//-------------------------------------------------------------------- -// -// Status.cpp -// -//-------------------------------------------------------------------- + +#include "Mail.h" +#include "Status.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include -#include -#include "Mail.h" -#include "Status.h" +#define STATUS_TEXT "Status:" +#define STATUS_FIELD_H 10 +#define STATUS_FIELD_V 8 +#define STATUS_FIELD_WIDTH (STATUS_WIDTH - STATUS_FIELD_H) +#define STATUS_FIELD_HEIGHT 16 + +#define BUTTON_WIDTH 70 +#define BUTTON_HEIGHT 20 + +#define S_OK_BUTTON_X1 (STATUS_WIDTH - BUTTON_WIDTH - 6) +#define S_OK_BUTTON_Y1 (STATUS_HEIGHT - (BUTTON_HEIGHT + 10)) +#define S_OK_BUTTON_X2 (S_OK_BUTTON_X1 + BUTTON_WIDTH) +#define S_OK_BUTTON_Y2 (S_OK_BUTTON_Y1 + BUTTON_HEIGHT) +#define S_OK_BUTTON_TEXT "OK" + +#define S_CANCEL_BUTTON_X1 (S_OK_BUTTON_X1 - (BUTTON_WIDTH + 10)) +#define S_CANCEL_BUTTON_Y1 S_OK_BUTTON_Y1 +#define S_CANCEL_BUTTON_X2 (S_CANCEL_BUTTON_X1 + BUTTON_WIDTH) +#define S_CANCEL_BUTTON_Y2 S_OK_BUTTON_Y2 +#define S_CANCEL_BUTTON_TEXT "Cancel" + +enum status_messages { + STATUS = 128, + OK, + CANCEL +}; -//==================================================================== - -TStatusWindow::TStatusWindow(BRect rect, BWindow *window, const char *status) - : BWindow(rect, "", B_MODAL_WINDOW, B_NOT_RESIZABLE) +TStatusWindow::TStatusWindow(BRect rect, BMessenger target, const char* status) + : BWindow(rect, "", B_MODAL_WINDOW, B_NOT_RESIZABLE), + fTarget(target) { - BRect r(0, 0, STATUS_WIDTH, STATUS_HEIGHT); + BView* view = new BView(Bounds(), "", B_FOLLOW_ALL, B_WILL_DRAW); + view->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + AddChild(view); - r.InsetBy(-1, -1); - fView = new TStatusView(r, window, status); - Lock(); - AddChild(fView); - Unlock(); - Show(); -} - - -//==================================================================== -// #pragma mark - - - -TStatusView::TStatusView(BRect rect, BWindow *window, const char *status) - : BBox(rect, "", B_FOLLOW_ALL, B_WILL_DRAW) -{ - fWindow = window; - fString = status; - - SetViewColor(VIEW_COLOR, VIEW_COLOR, VIEW_COLOR); - - BFont font = *be_plain_font; - font.SetSize(FONT_SIZE); - SetFont(&font); -} - - -void -TStatusView::AttachedToWindow() -{ BRect r(STATUS_FIELD_H, STATUS_FIELD_V, STATUS_FIELD_WIDTH, STATUS_FIELD_V + STATUS_FIELD_HEIGHT); - fStatus = new BTextControl(r, "", STATUS_TEXT, fString, new BMessage(STATUS)); - AddChild(fStatus); + fStatus = new BTextControl(r, "", STATUS_TEXT, status, new BMessage(STATUS)); + view->AddChild(fStatus); - BFont font = *be_plain_font; - font.SetSize(FONT_SIZE); - fStatus->SetFont(&font); - fStatus->SetDivider(StringWidth(STATUS_TEXT) + 6); + fStatus->SetDivider(fStatus->StringWidth(STATUS_TEXT) + 6); fStatus->BTextControl::MakeFocus(true); r.Set(S_OK_BUTTON_X1, S_OK_BUTTON_Y1, S_OK_BUTTON_X2, S_OK_BUTTON_Y2); BButton *button = new BButton(r, "", S_OK_BUTTON_TEXT, new BMessage(OK)); - AddChild(button); - button->SetTarget(this); + view->AddChild(button); button->MakeDefault(true); r.Set(S_CANCEL_BUTTON_X1, S_CANCEL_BUTTON_Y1, S_CANCEL_BUTTON_X2, S_CANCEL_BUTTON_Y2); button = new BButton(r, "", S_CANCEL_BUTTON_TEXT, new BMessage(CANCEL)); - AddChild(button); - button->SetTarget(this); + view->AddChild(button); + + Show(); +} + + +TStatusWindow::~TStatusWindow() +{ } void -TStatusView::MessageReceived(BMessage *msg) +TStatusWindow::MessageReceived(BMessage* msg) { - char name[B_FILE_NAME_LENGTH]; - char new_name[B_FILE_NAME_LENGTH]; - int32 index = 0; - uint32 loop; - status_t result; - BDirectory dir; - BEntry entry; - BFile file; - BNodeInfo *node; - BPath path; - - switch (msg->what) - { + switch (msg->what) { case STATUS: break; case OK: - if (!Exists(fStatus->Text())) { + { + if (!_Exists(fStatus->Text())) { + int32 index = 0; + uint32 loop; + status_t result; + BDirectory dir; + BEntry entry; + BFile file; + BNodeInfo* node; + BPath path; + find_directory(B_USER_SETTINGS_DIRECTORY, &path, true); dir.SetTo(path.Path()); if (dir.FindEntry("bemail", &entry) == B_NO_ERROR) @@ -144,6 +148,9 @@ TStatusView::MessageReceived(BMessage *msg) else dir.CreateDirectory("status", &dir); if (dir.InitCheck() == B_NO_ERROR) { + char name[B_FILE_NAME_LENGTH]; + char newName[B_FILE_NAME_LENGTH]; + sprintf(name, "%s", fStatus->Text()); if (strlen(name) > B_FILE_NAME_LENGTH - 10) name[B_FILE_NAME_LENGTH - 10] = 0; @@ -151,40 +158,41 @@ TStatusView::MessageReceived(BMessage *msg) if (name[loop] == '/') name[loop] = '\\'; } - strcpy(new_name, name); + strcpy(newName, name); while (1) { - if ((result = dir.CreateFile(new_name, &file, true)) == B_NO_ERROR) + if ((result = dir.CreateFile(newName, &file, true)) == B_NO_ERROR) break; if (result != EEXIST) goto err_exit; - sprintf(new_name, "%s_%ld", name, index++); + sprintf(newName, "%s_%ld", name, index++); } - dir.FindEntry(new_name, &entry); + dir.FindEntry(newName, &entry); node = new BNodeInfo(&file); node->SetType("text/plain"); delete node; file.Write(fStatus->Text(), strlen(fStatus->Text()) + 1); file.SetSize(file.Position()); file.WriteAttr(INDEX_STATUS, B_STRING_TYPE, 0, fStatus->Text(), - strlen(fStatus->Text()) + 1); + strlen(fStatus->Text()) + 1); } } -err_exit: + err_exit: { - BMessage closeCstmMsg(M_CLOSE_CUSTOM); - closeCstmMsg.AddString("status", fStatus->Text()); - fWindow->PostMessage(&closeCstmMsg); + BMessage close(M_CLOSE_CUSTOM); + close.AddString("status", fStatus->Text()); + fTarget.SendMessage(&close); // will fall through } + } case CANCEL: - Window()->Quit(); + Quit(); break; } } bool -TStatusView::Exists(const char *status) +TStatusWindow::_Exists(const char* status) { BVolume volume; BVolumeRoster().GetBootVolume(&volume); diff --git a/src/apps/bemail/Status.h b/src/apps/bemail/Status.h index a7676cd073..0cd378cb86 100644 --- a/src/apps/bemail/Status.h +++ b/src/apps/bemail/Status.h @@ -31,89 +31,33 @@ of Be Incorporated in the United States and other countries. Other brand product names are registered trademarks or trademarks of their respective holders. All rights reserved. */ - -//-------------------------------------------------------------------- -// -// Status.h -// -//-------------------------------------------------------------------- - #ifndef _STATUS_H #define _STATUS_H -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include + +#include #include + +#define INDEX_STATUS "_status" + #define STATUS_WIDTH 220 #define STATUS_HEIGHT 80 -#define STATUS_TEXT "Status:" -#define STATUS_FIELD_H 10 -#define STATUS_FIELD_V 8 -#define STATUS_FIELD_WIDTH (STATUS_WIDTH - STATUS_FIELD_H) -#define STATUS_FIELD_HEIGHT 16 -#define BUTTON_WIDTH 70 -#define BUTTON_HEIGHT 20 - -#define S_OK_BUTTON_X1 (STATUS_WIDTH - BUTTON_WIDTH - 6) -#define S_OK_BUTTON_Y1 (STATUS_HEIGHT - (BUTTON_HEIGHT + 10)) -#define S_OK_BUTTON_X2 (S_OK_BUTTON_X1 + BUTTON_WIDTH) -#define S_OK_BUTTON_Y2 (S_OK_BUTTON_Y1 + BUTTON_HEIGHT) -#define S_OK_BUTTON_TEXT "OK" - -#define S_CANCEL_BUTTON_X1 (S_OK_BUTTON_X1 - (BUTTON_WIDTH + 10)) -#define S_CANCEL_BUTTON_Y1 S_OK_BUTTON_Y1 -#define S_CANCEL_BUTTON_X2 (S_CANCEL_BUTTON_X1 + BUTTON_WIDTH) -#define S_CANCEL_BUTTON_Y2 S_OK_BUTTON_Y2 -#define S_CANCEL_BUTTON_TEXT "Cancel" - -#define INDEX_STATUS "_status" - -enum status_messages { - STATUS = 128, - OK, - CANCEL -}; - -class TStatusView; - -//==================================================================== - -class TStatusWindow : public BWindow -{ +class TStatusWindow : public BWindow { public: - TStatusWindow(BRect, BWindow *, const char *status); + TStatusWindow(BRect frame, BMessenger target, const char* status); + virtual ~TStatusWindow(); + + protected: + virtual void MessageReceived(BMessage* message); private: - TStatusView *fView; -}; + bool _Exists(const char* status); -//-------------------------------------------------------------------- - -class TStatusView : public BBox -{ - public: - TStatusView(BRect, BWindow *, const char *); - - virtual void AttachedToWindow(); - virtual void MessageReceived(BMessage *); - bool Exists(const char *); - - private: - const char *fString; - BTextControl *fStatus; - BWindow *fWindow; + BMessenger fTarget; + BTextControl* fStatus; }; #endif // #ifndef _STATUS_H