Mail: sizing/placing cleanup.
* 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.
This commit is contained in:
+50
-52
@@ -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();
|
||||
|
||||
@@ -325,15 +322,21 @@ 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;
|
||||
@@ -341,10 +344,8 @@ TMailApp::MessageReceived(BMessage *msg)
|
||||
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();
|
||||
@@ -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;
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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;
|
||||
@@ -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)
|
||||
{
|
||||
@@ -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++;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -104,6 +104,7 @@ class TMailApp : public BApplication {
|
||||
private:
|
||||
void _ClearPrintSettings();
|
||||
void _CheckForSpamFilterExistence();
|
||||
TMailWindow* _ActiveWindow();
|
||||
|
||||
status_t GetSettingsPath(BPath &path);
|
||||
status_t LoadOldSettings();
|
||||
|
||||
@@ -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 "> "
|
||||
|
||||
|
||||
+24
-33
@@ -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
|
||||
@@ -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),
|
||||
|
||||
@@ -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"));
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
@@ -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,
|
||||
@@ -91,7 +89,7 @@ private:
|
||||
BPopUpMenu* _BuildAutoMarkReadMenu(
|
||||
bool autoMarkRead);
|
||||
BPopUpMenu* _BuildButtonBarMenu(uint8 show);
|
||||
|
||||
|
||||
BPopUpMenu* _BuildBoolMenu(uint32 msg,
|
||||
const char* boolItem, bool isTrue);
|
||||
|
||||
|
||||
@@ -79,7 +79,6 @@ Settings::Settings()
|
||||
fMailCharacterSet(B_MS_WINDOWS_CONVERSION),
|
||||
fContentFont(be_fixed_font)
|
||||
{
|
||||
fContentFont.SetSize(12.0);
|
||||
fSignature = B_TRANSLATE("None");
|
||||
|
||||
LoadSettings();
|
||||
|
||||
+112
-150
@@ -32,6 +32,7 @@ countries. Other brand product names are registered trademarks or trademarks
|
||||
of their respective holders. All rights reserved.
|
||||
*/
|
||||
|
||||
|
||||
#include "Signature.h"
|
||||
|
||||
#include <stdio.h>
|
||||
@@ -39,9 +40,11 @@ of their respective holders. All rights reserved.
|
||||
#include <strings.h>
|
||||
|
||||
#include <Clipboard.h>
|
||||
#include <InterfaceKit.h>
|
||||
#include <Directory.h>
|
||||
#include <LayoutBuilder.h>
|
||||
#include <Locale.h>
|
||||
#include <StorageKit.h>
|
||||
#include <ScrollView.h>
|
||||
#include <StringView.h>
|
||||
|
||||
#include "MailApp.h"
|
||||
#include "MailPopUpMenu.h"
|
||||
@@ -53,24 +56,24 @@ of their respective holders. All rights reserved.
|
||||
#define B_TRANSLATION_CONTEXT "Mail"
|
||||
|
||||
|
||||
extern BRect signature_window;
|
||||
extern const char *kUndoStrings[];
|
||||
extern const char *kRedoStrings[];
|
||||
const float kSigHeight = 250;
|
||||
const float kSigWidth = 300;
|
||||
|
||||
extern const char* kUndoStrings[];
|
||||
extern const char* kRedoStrings[];
|
||||
|
||||
|
||||
TSignatureWindow::TSignatureWindow(BRect rect)
|
||||
:
|
||||
BWindow (rect, B_TRANSLATE("Signatures"), B_TITLED_WINDOW, 0),
|
||||
BWindow(rect, B_TRANSLATE("Signatures"), B_TITLED_WINDOW,
|
||||
B_AUTO_UPDATE_SIZE_LIMITS),
|
||||
fFile(NULL)
|
||||
{
|
||||
BMenu *menu;
|
||||
BMenuBar *menu_bar;
|
||||
BMenuItem *item;
|
||||
BMenuItem* item;
|
||||
|
||||
BRect r = Bounds();
|
||||
/*** Set up the menus ****/
|
||||
menu_bar = new BMenuBar(r, "MenuBar");
|
||||
menu = new BMenu(B_TRANSLATE("Signature"));
|
||||
// Set up the menu
|
||||
BMenuBar* menuBar = new BMenuBar("MenuBar");
|
||||
BMenu* menu = new BMenu(B_TRANSLATE("Signature"));
|
||||
menu->AddItem(fNew = new BMenuItem(B_TRANSLATE("New"),
|
||||
new BMessage(M_NEW), 'N'));
|
||||
fSignature = new TMenu(B_TRANSLATE("Open"), INDEX_SIGNATURE, M_SIGNATURE);
|
||||
@@ -80,7 +83,7 @@ TSignatureWindow::TSignatureWindow(BRect rect)
|
||||
new BMessage(M_SAVE), 'S'));
|
||||
menu->AddItem(fDelete = new BMenuItem(B_TRANSLATE("Delete"),
|
||||
new BMessage(M_DELETE), 'T'));
|
||||
menu_bar->AddItem(menu);
|
||||
menuBar->AddItem(menu);
|
||||
|
||||
menu = new BMenu(B_TRANSLATE("Edit"));
|
||||
menu->AddItem(fUndo = new BMenuItem(B_TRANSLATE("Undo"),
|
||||
@@ -100,22 +103,20 @@ TSignatureWindow::TSignatureWindow(BRect rect)
|
||||
menu->AddItem(item = new BMenuItem(B_TRANSLATE("Select all"),
|
||||
new BMessage(M_SELECT), 'A'));
|
||||
item->SetTarget(NULL, this);
|
||||
menu_bar->AddItem(menu);
|
||||
menuBar->AddItem(menu);
|
||||
|
||||
AddChild(menu_bar);
|
||||
/**** Done with the menu set up *****/
|
||||
fSigView = new TSignatureView();
|
||||
|
||||
/**** Add on the panel, giving it the width and at least one vertical pixel *****/
|
||||
fSigView = new TSignatureView(BRect(0, menu_bar->Frame().bottom+1,
|
||||
rect.Width(), menu_bar->Frame().bottom+2));
|
||||
AddChild(fSigView);
|
||||
BLayoutBuilder::Group<>(this, B_VERTICAL, 0)
|
||||
.Add(menuBar)
|
||||
.Add(fSigView);
|
||||
|
||||
/* resize the window to the correct height */
|
||||
fSigView->SetResizingMode(B_FOLLOW_NONE);
|
||||
ResizeTo(rect.Width()-2, fSigView->Frame().bottom-2);
|
||||
fSigView->SetResizingMode(B_FOLLOW_ALL);
|
||||
|
||||
SetSizeLimits(kSigWidth, RIGHT_BOUNDARY, r.top + 100, RIGHT_BOUNDARY);
|
||||
if (!rect.IsValid()) {
|
||||
float fontFactor = be_plain_font->Size() / 12.0f;
|
||||
ResizeTo(kSigWidth * fontFactor, kSigHeight * fontFactor);
|
||||
// TODO: this should work, too, but doesn't
|
||||
//ResizeToPreferred();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -127,37 +128,37 @@ TSignatureWindow::~TSignatureWindow()
|
||||
void
|
||||
TSignatureWindow::MenusBeginning()
|
||||
{
|
||||
int32 finish = 0;
|
||||
int32 start = 0;
|
||||
BTextView *text_view;
|
||||
|
||||
fDelete->SetEnabled(fFile);
|
||||
fSave->SetEnabled(IsDirty());
|
||||
fUndo->SetEnabled(false); // ***TODO***
|
||||
|
||||
text_view = (BTextView *)fSigView->fName->ChildAt(0);
|
||||
if (text_view->IsFocus())
|
||||
text_view->GetSelection(&start, &finish);
|
||||
BTextView* textView = fSigView->fName->TextView();
|
||||
int32 finish = 0;
|
||||
int32 start = 0;
|
||||
if (textView->IsFocus())
|
||||
textView->GetSelection(&start, &finish);
|
||||
else
|
||||
fSigView->fTextView->GetSelection(&start, &finish);
|
||||
|
||||
fCut->SetEnabled(start != finish);
|
||||
fCopy->SetEnabled(start != finish);
|
||||
|
||||
fNew->SetEnabled(text_view->TextLength() | fSigView->fTextView->TextLength());
|
||||
fNew->SetEnabled(textView->TextLength()
|
||||
| fSigView->fTextView->TextLength());
|
||||
be_clipboard->Lock();
|
||||
fPaste->SetEnabled(be_clipboard->Data()->HasData("text/plain", B_MIME_TYPE));
|
||||
fPaste->SetEnabled(be_clipboard->Data()->HasData("text/plain",
|
||||
B_MIME_TYPE));
|
||||
be_clipboard->Unlock();
|
||||
|
||||
// Undo stuff
|
||||
bool isRedo = false;
|
||||
undo_state undoState = B_UNDO_UNAVAILABLE;
|
||||
bool isRedo = false;
|
||||
undo_state undoState = B_UNDO_UNAVAILABLE;
|
||||
|
||||
BTextView *focusTextView = dynamic_cast<BTextView *>(CurrentFocus());
|
||||
if (focusTextView != NULL)
|
||||
undoState = focusTextView->UndoState(&isRedo);
|
||||
|
||||
fUndo->SetLabel((isRedo) ? kRedoStrings[undoState] : kUndoStrings[undoState]);
|
||||
fUndo->SetLabel(isRedo ? kRedoStrings[undoState] : kUndoStrings[undoState]);
|
||||
fUndo->SetEnabled(undoState != B_UNDO_UNAVAILABLE);
|
||||
}
|
||||
|
||||
@@ -165,24 +166,19 @@ TSignatureWindow::MenusBeginning()
|
||||
void
|
||||
TSignatureWindow::MessageReceived(BMessage* msg)
|
||||
{
|
||||
char *sig;
|
||||
char name[B_FILE_NAME_LENGTH];
|
||||
BFont *font;
|
||||
BTextView *text_view;
|
||||
entry_ref ref;
|
||||
off_t size;
|
||||
|
||||
switch(msg->what) {
|
||||
switch (msg->what) {
|
||||
case CHANGE_FONT:
|
||||
{
|
||||
BFont* font;
|
||||
msg->FindPointer("font", (void **)&font);
|
||||
fSigView->fTextView->SetFontAndColor(font);
|
||||
fSigView->fTextView->Invalidate(fSigView->fTextView->Bounds());
|
||||
break;
|
||||
}
|
||||
|
||||
case M_NEW:
|
||||
if (Clear()) {
|
||||
fSigView->fName->SetText("");
|
||||
// fSigView->fTextView->SetText(NULL, (int32)0);
|
||||
fSigView->fTextView->SetText("");
|
||||
fSigView->fName->MakeFocus(true);
|
||||
}
|
||||
@@ -201,7 +197,7 @@ TSignatureWindow::MessageReceived(BMessage* msg)
|
||||
NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
|
||||
alert->SetShortcut(0, B_ESCAPE);
|
||||
int32 choice = alert->Go();
|
||||
|
||||
|
||||
if (choice == 0)
|
||||
break;
|
||||
|
||||
@@ -217,22 +213,29 @@ TSignatureWindow::MessageReceived(BMessage* msg)
|
||||
}
|
||||
case M_SIGNATURE:
|
||||
if (Clear()) {
|
||||
entry_ref ref;
|
||||
msg->FindRef("ref", &ref);
|
||||
fEntry.SetTo(&ref);
|
||||
fFile = new BFile(&ref, O_RDWR);
|
||||
if (fFile->InitCheck() == B_NO_ERROR) {
|
||||
fFile->ReadAttr(INDEX_SIGNATURE, B_STRING_TYPE, 0, name, sizeof(name));
|
||||
if (fFile->InitCheck() == B_OK) {
|
||||
char name[B_FILE_NAME_LENGTH];
|
||||
fFile->ReadAttr(INDEX_SIGNATURE, B_STRING_TYPE, 0, name,
|
||||
sizeof(name));
|
||||
fSigView->fName->SetText(name);
|
||||
|
||||
off_t size;
|
||||
fFile->GetSize(&size);
|
||||
sig = (char *)malloc(size);
|
||||
char* sig = (char*)malloc(size);
|
||||
if (sig == NULL)
|
||||
break;
|
||||
|
||||
size = fFile->Read(sig, size);
|
||||
fSigView->fTextView->SetText(sig, size);
|
||||
fSigView->fName->MakeFocus(true);
|
||||
text_view = (BTextView *)fSigView->fName->ChildAt(0);
|
||||
text_view->Select(0, text_view->TextLength());
|
||||
BTextView* textView = fSigView->fName->TextView();
|
||||
textView->Select(0, textView->TextLength());
|
||||
fSigView->fTextView->fDirty = false;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
fFile = NULL;
|
||||
beep();
|
||||
BAlert* alert = new BAlert("",
|
||||
@@ -275,12 +278,10 @@ TSignatureWindow::FrameResized(float width, float height)
|
||||
void
|
||||
TSignatureWindow::Show()
|
||||
{
|
||||
BTextView *text_view;
|
||||
|
||||
Lock();
|
||||
text_view = (BTextView *)fSigView->fName->TextView();
|
||||
BTextView* textView = (BTextView *)fSigView->fName->TextView();
|
||||
fSigView->fName->MakeFocus(true);
|
||||
text_view->Select(0, text_view->TextLength());
|
||||
textView->Select(0, textView->TextLength());
|
||||
Unlock();
|
||||
|
||||
BWindow::Show();
|
||||
@@ -290,8 +291,6 @@ TSignatureWindow::Show()
|
||||
bool
|
||||
TSignatureWindow::Clear()
|
||||
{
|
||||
int32 result;
|
||||
|
||||
if (IsDirty()) {
|
||||
beep();
|
||||
BAlert *alert = new BAlert("",
|
||||
@@ -303,7 +302,7 @@ TSignatureWindow::Clear()
|
||||
alert->SetShortcut(0, B_ESCAPE);
|
||||
alert->SetShortcut(1, 'd');
|
||||
alert->SetShortcut(2, 's');
|
||||
result = alert->Go();
|
||||
int32 result = alert->Go();
|
||||
if (result == 0)
|
||||
return false;
|
||||
if (result == 2)
|
||||
@@ -320,17 +319,16 @@ TSignatureWindow::Clear()
|
||||
bool
|
||||
TSignatureWindow::IsDirty()
|
||||
{
|
||||
char name[B_FILE_NAME_LENGTH];
|
||||
|
||||
if (fFile) {
|
||||
if (fFile != NULL) {
|
||||
char name[B_FILE_NAME_LENGTH];
|
||||
fFile->ReadAttr(INDEX_SIGNATURE, B_STRING_TYPE, 0, name, sizeof(name));
|
||||
if ((strcmp(name, fSigView->fName->Text())) || (fSigView->fTextView->fDirty))
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
if ((strlen(fSigView->fName->Text())) ||
|
||||
(fSigView->fTextView->TextLength()))
|
||||
if (strcmp(name, fSigView->fName->Text()) != 0
|
||||
|| fSigView->fTextView->fDirty) {
|
||||
return true;
|
||||
}
|
||||
} else if (fSigView->fName->Text()[0] != '\0'
|
||||
|| fSigView->fTextView->TextLength() != 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -400,83 +398,57 @@ err_exit:
|
||||
}
|
||||
|
||||
|
||||
//====================================================================
|
||||
// #pragma mark -
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
TSignatureView::TSignatureView(BRect rect)
|
||||
: BBox(rect, "SigView", B_FOLLOW_ALL, B_WILL_DRAW)
|
||||
TSignatureView::TSignatureView()
|
||||
:
|
||||
BGridView("SigView")
|
||||
{
|
||||
GridLayout()->SetInsets(B_USE_DEFAULT_SPACING);
|
||||
|
||||
BStringView* nameLabel = new BStringView("NameLabel",
|
||||
B_TRANSLATE("Title:"));
|
||||
nameLabel->SetAlignment(B_ALIGN_RIGHT);
|
||||
GridLayout()->AddView(nameLabel, 0, 0);
|
||||
|
||||
fName = new TNameControl("", new BMessage(NAME_FIELD));
|
||||
GridLayout()->AddItem(fName->CreateTextViewLayoutItem(), 1, 0);
|
||||
|
||||
BStringView* signatureLabel = new BStringView("SigLabel",
|
||||
B_TRANSLATE("Signature:"));
|
||||
signatureLabel->SetAlignment(B_ALIGN_RIGHT);
|
||||
GridLayout()->AddView(signatureLabel, 0, 1);
|
||||
|
||||
fTextView = new TSigTextView();
|
||||
|
||||
font_height fontHeight;
|
||||
fTextView->GetFontHeight(&fontHeight);
|
||||
float lineHeight = ceilf(fontHeight.ascent) + ceilf(fontHeight.descent);
|
||||
|
||||
BScrollView* scroller = new BScrollView("SigScroller", fTextView, 0,
|
||||
false, true);
|
||||
scroller->SetExplicitPreferredSize(
|
||||
BSize(fTextView->StringWidth("W") * 30, lineHeight * 6));
|
||||
|
||||
GridLayout()->AddView(scroller, 1, 1, 1, 2);
|
||||
|
||||
GridLayout()->AddItem(BSpaceLayoutItem::CreateGlue(), 0, 2);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TSignatureView::AttachedToWindow()
|
||||
{
|
||||
BRect rect = Bounds();
|
||||
float name_text_length = StringWidth(B_TRANSLATE("Title:"));
|
||||
float sig_text_length = StringWidth(B_TRANSLATE("Signature:"));
|
||||
float divide_length;
|
||||
|
||||
if (name_text_length > sig_text_length)
|
||||
divide_length = name_text_length;
|
||||
else
|
||||
divide_length = sig_text_length;
|
||||
|
||||
rect.InsetBy(8,0);
|
||||
rect.top+= 8;
|
||||
|
||||
fName = new TNameControl(rect, B_TRANSLATE("Title:"),
|
||||
new BMessage(NAME_FIELD));
|
||||
AddChild(fName);
|
||||
|
||||
fName->SetDivider(divide_length + 10);
|
||||
fName->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT);
|
||||
|
||||
rect.OffsetBy(0,fName->Bounds().Height()+5);
|
||||
rect.bottom = rect.top + kSigHeight;
|
||||
rect.left = fName->TextView()->Frame().left;
|
||||
|
||||
BRect text = rect;
|
||||
text.OffsetTo(10,0);
|
||||
fTextView = new TSigTextView(rect, text);
|
||||
BScrollView *scroller = new BScrollView("SigScroller", fTextView, B_FOLLOW_ALL, 0, false, true);
|
||||
AddChild(scroller);
|
||||
scroller->ResizeBy(-1 * scroller->ScrollBar(B_VERTICAL)->Frame().Width() - 9, 0);
|
||||
scroller->MoveBy(7,0);
|
||||
|
||||
/* back up a bit to make room for the label */
|
||||
|
||||
rect = scroller->Frame();
|
||||
BStringView *stringView = new BStringView(rect, "SigLabel",
|
||||
B_TRANSLATE("Signature:"));
|
||||
AddChild(stringView);
|
||||
|
||||
float tWidth, tHeight;
|
||||
stringView->GetPreferredSize(&tWidth, &tHeight);
|
||||
|
||||
/* the 5 is for the spacer in the TextView */
|
||||
|
||||
rect.OffsetBy(-1 *(tWidth) - 5, 0);
|
||||
rect.right = rect.left + tWidth;
|
||||
rect.bottom = rect.top + tHeight;
|
||||
|
||||
stringView->MoveTo(rect.LeftTop());
|
||||
stringView->ResizeTo(rect.Width(), rect.Height());
|
||||
|
||||
/* Resize the View to the correct height */
|
||||
scroller->SetResizingMode(B_FOLLOW_NONE);
|
||||
ResizeTo(Frame().Width(), scroller->Frame().bottom + 8);
|
||||
scroller->SetResizingMode(B_FOLLOW_ALL);
|
||||
}
|
||||
|
||||
|
||||
//====================================================================
|
||||
// #pragma mark -
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
TNameControl::TNameControl(BRect rect, const char *label, BMessage *msg)
|
||||
:BTextControl(rect, "", label, "", msg, B_FOLLOW_LEFT_RIGHT)
|
||||
TNameControl::TNameControl(const char* label, BMessage* invocationMessage)
|
||||
:
|
||||
BTextControl("", label, "", invocationMessage)
|
||||
{
|
||||
strcpy(fLabel, label);
|
||||
}
|
||||
@@ -487,13 +459,12 @@ TNameControl::AttachedToWindow()
|
||||
{
|
||||
BTextControl::AttachedToWindow();
|
||||
|
||||
SetDivider(StringWidth(fLabel) + 6);
|
||||
TextView()->SetMaxBytes(B_FILE_NAME_LENGTH - 1);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TNameControl::MessageReceived(BMessage *msg)
|
||||
TNameControl::MessageReceived(BMessage* msg)
|
||||
{
|
||||
switch (msg->what) {
|
||||
case M_SELECT:
|
||||
@@ -506,27 +477,18 @@ TNameControl::MessageReceived(BMessage *msg)
|
||||
}
|
||||
|
||||
|
||||
//====================================================================
|
||||
// #pragma mark -
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
TSigTextView::TSigTextView(BRect frame, BRect text)
|
||||
:BTextView(frame, "SignatureView", text, B_FOLLOW_ALL, B_NAVIGABLE | B_WILL_DRAW)
|
||||
TSigTextView::TSigTextView()
|
||||
:
|
||||
BTextView("SignatureView", B_NAVIGABLE | B_WILL_DRAW)
|
||||
{
|
||||
fDirty = false;
|
||||
SetDoesUndo(true);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TSigTextView::FrameResized(float /*width*/, float /*height*/)
|
||||
{
|
||||
BRect r(Bounds());
|
||||
r.InsetBy(3, 3);
|
||||
SetTextRect(r);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TSigTextView::DeleteText(int32 offset, int32 len)
|
||||
{
|
||||
|
||||
+20
-30
@@ -31,22 +31,16 @@ 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.
|
||||
*/
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
//
|
||||
// Signature.h
|
||||
//
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
#ifndef _SIGNATURE_H
|
||||
#define _SIGNATURE_H
|
||||
|
||||
|
||||
#include <Alert.h>
|
||||
#include <Beep.h>
|
||||
#include <Box.h>
|
||||
#include <FindDirectory.h>
|
||||
#include <Font.h>
|
||||
#include <fs_index.h>
|
||||
#include <GridView.h>
|
||||
#include <Menu.h>
|
||||
#include <MenuBar.h>
|
||||
#include <MenuItem.h>
|
||||
@@ -56,9 +50,6 @@ All rights reserved.
|
||||
#include <TextControl.h>
|
||||
#include <Window.h>
|
||||
|
||||
const float kSigHeight = 200;
|
||||
const float kSigWidth = 457;
|
||||
|
||||
|
||||
#define INDEX_SIGNATURE "_signature"
|
||||
|
||||
@@ -98,48 +89,47 @@ private:
|
||||
TSignatureView *fSigView;
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
class TSignatureView : public BBox {
|
||||
class TSignatureView : public BGridView {
|
||||
public:
|
||||
TSignatureView(BRect);
|
||||
virtual void AttachedToWindow();
|
||||
TSignatureView();
|
||||
virtual void AttachedToWindow();
|
||||
|
||||
TNameControl *fName;
|
||||
TSigTextView *fTextView;
|
||||
TNameControl* fName;
|
||||
TSigTextView* fTextView;
|
||||
|
||||
private:
|
||||
float fOffset;
|
||||
float fOffset;
|
||||
};
|
||||
|
||||
//====================================================================
|
||||
|
||||
class TNameControl : public BTextControl {
|
||||
public:
|
||||
TNameControl(BRect, const char*, BMessage*);
|
||||
virtual void AttachedToWindow();
|
||||
virtual void MessageReceived(BMessage*);
|
||||
TNameControl(const char* label,
|
||||
BMessage* invocationMessage);
|
||||
|
||||
virtual void AttachedToWindow();
|
||||
virtual void MessageReceived(BMessage* message);
|
||||
|
||||
private:
|
||||
char fLabel[100];
|
||||
};
|
||||
|
||||
//====================================================================
|
||||
|
||||
class TSigTextView : public BTextView {
|
||||
public:
|
||||
TSigTextView(BRect, BRect);
|
||||
void FrameResized(float width, float height);
|
||||
TSigTextView();
|
||||
|
||||
virtual void DeleteText(int32, int32);
|
||||
virtual void KeyDown(const char*, int32);
|
||||
virtual void InsertText(const char*, int32, int32, const text_run_array*);
|
||||
virtual void MessageReceived(BMessage*);
|
||||
virtual void DeleteText(int32 offset, int32 length);
|
||||
virtual void KeyDown(const char*, int32);
|
||||
virtual void InsertText(const char*, int32, int32,
|
||||
const text_run_array*);
|
||||
virtual void MessageReceived(BMessage* message);
|
||||
|
||||
bool fDirty;
|
||||
|
||||
private:
|
||||
TSignatureView *fParent;
|
||||
TSignatureView* fParent;
|
||||
};
|
||||
|
||||
#endif // #ifndef _SIGNATURE_H
|
||||
|
||||
Reference in New Issue
Block a user