diff --git a/src/apps/terminal/MYOB/AppearPrefView.cpp b/src/apps/terminal/MYOB/AppearPrefView.cpp index 15ba8930f8..52104ed291 100644 --- a/src/apps/terminal/MYOB/AppearPrefView.cpp +++ b/src/apps/terminal/MYOB/AppearPrefView.cpp @@ -33,23 +33,19 @@ #include #include #include -#include -#include #include #include "AppearPrefView.h" +#include "MenuUtil.h" #include "PrefHandler.h" #include "TermWindow.h" #include "TermConst.h" -#include "MenuUtil.h" -#include "TTextControl.h" -#define MAX_FONT_SIZE 32 -#define MIN_FONT_SIZE 6 +BPopUpMenu *MakeFontMenu(ulong msg, const char *defaultFontName); +BPopUpMenu *MakeSizeMenu(ulong msg, uint8 defaultSize); -AppearancePrefView::AppearancePrefView (BRect frame, const char *name, - TermWindow *window) +AppearancePrefView::AppearancePrefView (BRect frame, const char *name, TermWindow *window) :PrefView (frame, name) { const char *color_tbl[]= @@ -64,139 +60,181 @@ AppearancePrefView::AppearancePrefView (BRect frame, const char *name, }; fTermWindow = window; - - mHalfFont = new BMenuField(BRect(0,0,220,20), "halffont", "Half Size Font", MakeFontMenu(MSG_HALF_FONT_CHANGED, gTermPref->getString(PREF_HALF_FONT_FAMILY)), B_WILL_DRAW); - AddChild(mHalfFont); - mHalfFont->SetDivider (120); - mHalfSize = new TTextControl(BRect(220, 0, 300, 20), "halfsize", "Size", "", new BMessage(MSG_HALF_SIZE_CHANGED)); - AddChild(mHalfSize); - mHalfSize->SetText(gTermPref->getString(PREF_HALF_FONT_SIZE)); - mHalfSize->SetDivider (50); - - mFullFont = new BMenuField(BRect(0,30,220,50), "fullfont", "Full Size Font", MakeFontMenu(MSG_FULL_FONT_CHANGED, gTermPref->getString(PREF_FULL_FONT_FAMILY)), B_WILL_DRAW); - AddChild(mFullFont); - mFullFont->SetDivider (120); + float fontDividerSize = StringWidth("Half Size Font") + 15.0; + float sizeDividerSize = StringWidth("Size") + 15.0; + + BRect r(5,5,225,25); + + BMenu *menu = MakeFontMenu(MSG_HALF_FONT_CHANGED, gTermPref->getString(PREF_HALF_FONT_FAMILY)); + fHalfFont = new BMenuField(r, "halffont", "Half Width Font", menu, B_WILL_DRAW); + AddChild(fHalfFont); + fHalfFont->SetDivider(fontDividerSize); + + r.OffsetBy(r.Width() + 10, 0); + menu = MakeSizeMenu(MSG_HALF_SIZE_CHANGED, 12); + fHalfFontSize = new BMenuField(r, "halfsize", "Size", menu, B_WILL_DRAW); + fHalfFontSize->SetDivider(sizeDividerSize); + AddChild(fHalfFontSize); + + r.OffsetBy(-r.Width() - 10,r.Height() + 5); + menu = MakeFontMenu(MSG_FULL_FONT_CHANGED, gTermPref->getString(PREF_FULL_FONT_FAMILY)); + fFullFont = new BMenuField(r, "fullfont", "Full Width Font", menu, B_WILL_DRAW); + AddChild(fFullFont); + fFullFont->SetDivider(fontDividerSize); - mFullSize = new TTextControl(BRect(220, 30, 300, 50), "fullsize", "Size", "", new BMessage(MSG_FULL_SIZE_CHANGED)); - AddChild(mFullSize); - mFullSize->SetText(gTermPref->getString(PREF_FULL_FONT_SIZE)); - mFullSize->SetDivider (50); - - mColorField = new BMenuField(BRect(0,60,200,80), NULL, NULL, MakeMenu (MSG_COLOR_FIELD_CHANGED, color_tbl, color_tbl[0]), B_WILL_DRAW); - AddChild(mColorField); - - mColorCtl = SetupBColorControl(BPoint(20, 85), B_CELLS_32x8, 6, MSG_COLOR_CHANGED); - mColorCtl->SetValue(gTermPref->getRGB(PREF_TEXT_FORE_COLOR)); + r.OffsetBy(r.Width() + 10, 0); + menu = MakeSizeMenu(MSG_FULL_SIZE_CHANGED, 12); + fFullFontSize = new BMenuField(r, "fullsize", "Size", menu, B_WILL_DRAW); + fFullFontSize->SetDivider(sizeDividerSize); + AddChild(fFullFontSize); + + r.OffsetBy(-r.Width() - 10,r.Height() + 25); + fColorField = new BMenuField(r, NULL, NULL, MakeMenu (MSG_COLOR_FIELD_CHANGED, color_tbl, color_tbl[0]), B_WILL_DRAW); + AddChild(fColorField); + fColorCtl = SetupBColorControl(BPoint(r.left, r.bottom + 10), B_CELLS_32x8, 6, + MSG_COLOR_CHANGED); + fColorCtl->SetValue(gTermPref->getRGB(PREF_TEXT_FORE_COLOR)); } void AppearancePrefView::Revert (void) { - - mHalfSize->SetText (gTermPref->getString (PREF_HALF_FONT_SIZE)); - mFullSize->SetText (gTermPref->getString (PREF_FULL_FONT_SIZE)); - mColorField->Menu()->ItemAt(0)->SetMarked (true); - mColorCtl->SetValue (gTermPref->getRGB(PREF_TEXT_FORE_COLOR)); + fColorField->Menu()->ItemAt(0)->SetMarked (true); + fColorCtl->SetValue (gTermPref->getRGB(PREF_TEXT_FORE_COLOR)); - mHalfFont->Menu()->FindItem (gTermPref->getString(PREF_HALF_FONT_FAMILY))->SetMarked(true); - mFullFont->Menu()->FindItem (gTermPref->getString(PREF_FULL_FONT_FAMILY))->SetMarked(true); - - return; - -} - -//////////////////////////////////////////////////////////////////////////// -// SaveIfModified (void) -// -//////////////////////////////////////////////////////////////////////////// -void -AppearancePrefView::SaveIfModified (void) -{ - BMessenger messenger (fTermWindow); - - if (mHalfSize->IsModified()) { - gTermPref->setString (PREF_HALF_FONT_SIZE, mHalfSize->Text()); - messenger.SendMessage (MSG_HALF_SIZE_CHANGED); - mHalfSize->ModifiedText (false); - } - if (mFullSize->IsModified()) { - gTermPref->setString (PREF_FULL_FONT_SIZE, mFullSize->Text()); - messenger.SendMessage (MSG_FULL_SIZE_CHANGED); - mFullSize->ModifiedText (false); - } - return; + fHalfFont->Menu()->FindItem (gTermPref->getString(PREF_HALF_FONT_FAMILY))->SetMarked(true); + fFullFont->Menu()->FindItem (gTermPref->getString(PREF_FULL_FONT_FAMILY))->SetMarked(true); + fHalfFontSize->Menu()->FindItem (gTermPref->getString(PREF_HALF_FONT_FAMILY))->SetMarked(true); + fFullFontSize->Menu()->FindItem (gTermPref->getString(PREF_FULL_FONT_FAMILY))->SetMarked(true); } void AppearancePrefView::AttachedToWindow (void) { - mHalfSize->SetTarget (this); - mFullSize->SetTarget (this); - mHalfFont->Menu()->SetTargetForItems(this); - mFullFont->Menu()->SetTargetForItems(this); - - mColorCtl->SetTarget (this); - mColorField->Menu()->SetTargetForItems(this); + fHalfFontSize->Menu()->SetTargetForItems(this); + fFullFontSize->Menu()->SetTargetForItems(this); + + fHalfFont->Menu()->SetTargetForItems(this); + fFullFont->Menu()->SetTargetForItems(this); + fColorCtl->SetTarget (this); + fColorField->Menu()->SetTargetForItems(this); } void AppearancePrefView::MessageReceived (BMessage *msg) { bool modified = false; - int size; - switch (msg->what) { - case MSG_HALF_FONT_CHANGED: - gTermPref->setString (PREF_HALF_FONT_FAMILY, mHalfFont->Menu()->FindMarked()->Label()); - modified = true; - break; - - case MSG_HALF_SIZE_CHANGED: - size = atoi (mHalfSize->Text()); - if (size > MAX_FONT_SIZE || size < MIN_FONT_SIZE) { - mHalfSize->SetText (gTermPref->getString (PREF_HALF_FONT_SIZE)); - beep (); - } else { - gTermPref->setString (PREF_HALF_FONT_SIZE, mHalfSize->Text()); - modified = true; - } - break; - - case MSG_FULL_FONT_CHANGED: - gTermPref->setString (PREF_FULL_FONT_FAMILY, mFullFont->Menu()->FindMarked()->Label()); - modified = true; - break; - - case MSG_FULL_SIZE_CHANGED: - size = atoi (mHalfSize->Text()); - if (size > MAX_FONT_SIZE || size < MIN_FONT_SIZE) { - mFullSize->SetText (gTermPref->getString (PREF_FULL_FONT_SIZE)); - beep (); - } else { - gTermPref->setString (PREF_FULL_FONT_SIZE, mFullSize->Text()); - } - modified = true; - break; - - case MSG_COLOR_CHANGED: - gTermPref->setRGB(mColorField->Menu()->FindMarked()->Label(), mColorCtl->ValueAsColor()); - modified = true; - break; - - case MSG_COLOR_FIELD_CHANGED: - mColorCtl->SetValue(gTermPref->getRGB (mColorField->Menu()->FindMarked()->Label())); - break; - - default: - PrefView::MessageReceived(msg); - return; // Oh ! - } - - if(modified){ - fTermWindow->PostMessage (msg); - (this->Window())->PostMessage(MSG_PREF_MODIFIED); - } + switch (msg->what) + { + case MSG_HALF_FONT_CHANGED: + { + gTermPref->setString (PREF_HALF_FONT_FAMILY, fHalfFont->Menu()->FindMarked()->Label()); + modified = true; + break; + } + case MSG_HALF_SIZE_CHANGED: + { + gTermPref->setString (PREF_HALF_FONT_SIZE, fHalfFontSize->Menu()->FindMarked()->Label()); + modified = true; + break; + } + case MSG_FULL_FONT_CHANGED: + { + gTermPref->setString (PREF_FULL_FONT_FAMILY, fFullFont->Menu()->FindMarked()->Label()); + modified = true; + break; + } + case MSG_FULL_SIZE_CHANGED: + { + gTermPref->setString (PREF_FULL_FONT_SIZE, fFullFontSize->Menu()->FindMarked()->Label()); + modified = true; + break; + } + case MSG_COLOR_CHANGED: + { + gTermPref->setRGB(fColorField->Menu()->FindMarked()->Label(), fColorCtl->ValueAsColor()); + modified = true; + break; + } + case MSG_COLOR_FIELD_CHANGED: + { + fColorCtl->SetValue(gTermPref->getRGB (fColorField->Menu()->FindMarked()->Label())); + break; + } + default: + { + PrefView::MessageReceived(msg); + return; // Oh ! + } + } + + if(modified) + { + fTermWindow->PostMessage(msg); + Window()->PostMessage(MSG_PREF_MODIFIED); + } +} + +BPopUpMenu * +MakeFontMenu(ulong msg, const char *defaultFontName) +{ + BPopUpMenu *menu = new BPopUpMenu(""); + int32 numFamilies = count_font_families(); + + for ( int32 i = 0; i < numFamilies; i++ ) + { + font_family family; + uint32 flags; + + if ( get_font_family(i, &family, &flags) == B_OK ) + { + menu->AddItem(new BMenuItem(family, new BMessage(msg))); + if(!strcmp(defaultFontName, family)) + { + BMenuItem *item=menu->ItemAt(i); + item->SetMarked(true); + } + } + } + + return menu; +} + +BPopUpMenu * +MakeSizeMenu(ulong msg, uint8 defaultSize) +{ + BPopUpMenu *menu = new BPopUpMenu("size"); + + BMenuItem *item; + + for(uint8 i=9; i<13; i++) + { + BString string; + string << i; + + item = new BMenuItem(string.String(), new BMessage(msg)); + menu->AddItem(item); + + if(i == defaultSize) + item->SetMarked(true); + + } + + item = new BMenuItem("14", new BMessage(msg)); + menu->AddItem(item); + + if(defaultSize == 14) + item->SetMarked(true); + + item = new BMenuItem("16", new BMessage(msg)); + menu->AddItem(item); + + if(defaultSize == 16) + item->SetMarked(true); + + return menu; } diff --git a/src/apps/terminal/MYOB/AppearPrefView.h b/src/apps/terminal/MYOB/AppearPrefView.h index 3a70e9944f..e29ee61d57 100644 --- a/src/apps/terminal/MYOB/AppearPrefView.h +++ b/src/apps/terminal/MYOB/AppearPrefView.h @@ -38,30 +38,24 @@ class TTextControl; class AppearancePrefView : public PrefView { - public: - AppearancePrefView(BRect r, - const char *name, - TermWindow *window); +public: + AppearancePrefView(BRect r, const char *name, + TermWindow *window); - virtual void Revert (void); - virtual void SaveIfModified (void); - virtual void MessageReceived (BMessage *); - virtual void AttachedToWindow (void); + virtual void Revert (void); + virtual void MessageReceived (BMessage *); + virtual void AttachedToWindow (void); - private: - TTextControl *mHalfSize; - TTextControl *mFullSize; - BMenuField *mHalfFont; - BMenuField *mFullFont; - - BMenuField *mColorField; - BColorControl *mColorCtl; - - int mSubMenu_button; - int mPaste_button; - - TermWindow *fTermWindow; - +private: + BMenuField *fHalfFont, + *fHalfFontSize, + *fFullFont, + *fFullFontSize; + + BMenuField *fColorField; + BColorControl *fColorCtl; + + TermWindow *fTermWindow; }; #endif //AppearancePrefView_H_INCLUDED diff --git a/src/apps/terminal/MYOB/MenuUtil.cpp b/src/apps/terminal/MYOB/MenuUtil.cpp index 6ddcdd7a0e..962ceea8b7 100644 --- a/src/apps/terminal/MYOB/MenuUtil.cpp +++ b/src/apps/terminal/MYOB/MenuUtil.cpp @@ -44,132 +44,83 @@ extern PrefHandler *gTermPref; #define LOCALE_FILE_DIR PREF_FOLDER"menu/" -////////////////////////////////////////////////////////////////////////////// -// -// -////////////////////////////////////////////////////////////////////////////// -BPopUpMenu * -MakeFontMenu(ulong msg, const char *defaultFontName) -{ - BPopUpMenu *menu = new BPopUpMenu("font"); - int32 numFamilies = count_font_families(); - - for ( int32 i = 0; i < numFamilies; i++ ) { - font_family family; - uint32 flags; - - if ( get_font_family(i, &family, &flags) == B_OK ) { - menu->AddItem(new BMenuItem(family, new BMessage(msg))); - if(!strcmp(defaultFontName, family)){ - (menu->ItemAt(i))->SetMarked(true); - } - } - } - - return menu; -} -////////////////////////////////////////////////////////////////////////////// -// -// -////////////////////////////////////////////////////////////////////////////// BPopUpMenu * MakeMenu(ulong msg, const char **items, const char *defaultItemName) { - BPopUpMenu *menu = new BPopUpMenu(""); - - int32 i = 0; - while(*items) { - menu->AddItem(new BMenuItem(*items, new BMessage(msg))); - if(!strcmp(*items, defaultItemName)){ - (menu->ItemAt(i))->SetMarked(true); - } - items++; - i++; - } - - return menu; + BPopUpMenu *menu = new BPopUpMenu(""); + + int32 i = 0; + while(*items) + { + menu->AddItem(new BMenuItem(*items, new BMessage(msg))); + if(!strcmp(*items, defaultItemName)) + { + (menu->ItemAt(i))->SetMarked(true); + } + items++; + i++; + } + return menu; } -//////////////////////////////////////////////////////////////////////////// -// -// -//////////////////////////////////////////////////////////////////////////// int longname2op(const char *longname) { -int op = M_UTF8; -const etable *s = encoding_table; - - for (int i = 0; s->name; s++, i++){ - if(!strcmp(s->name, longname)) { - op = s->op; - break; - } - } - - return op; + int op = M_UTF8; + const etable *s = encoding_table; + + for (int i = 0; s->name; s++, i++) + { + if(!strcmp(s->name, longname)) + { + op = s->op; + break; + } + } + return op; } -//////////////////////////////////////////////////////////////////////////// -// -// -//////////////////////////////////////////////////////////////////////////// -const char* +const char * op2longname(int op) { - return encoding_table[op].name; + return encoding_table[op].name; } -////////////////////////////////////////////////////////////////////////////// -// -// -////////////////////////////////////////////////////////////////////////////// void MakeEncodingMenu(BMenu *eMenu, int coding, bool flag) { - const etable *e = encoding_table; - int i = 0; - while(e->name){ - BMessage *msg = new BMessage(MENU_ENCODING); - msg->AddInt32("op", (int32)e->op); - if (flag) { - eMenu->AddItem(new BMenuItem(e->name, msg, e->shortcut)); - } - else { - eMenu->AddItem(new BMenuItem(e->name, msg)); - } - - if ( i == coding) { - (eMenu->ItemAt(i))->SetMarked(true); - } - e++; - i++; - } + const etable *e = encoding_table; + int i = 0; + while(e->name) + { + BMessage *msg = new BMessage(MENU_ENCODING); + msg->AddInt32("op", (int32)e->op); + if (flag) + eMenu->AddItem(new BMenuItem(e->name, msg, e->shortcut)); + else + eMenu->AddItem(new BMenuItem(e->name, msg)); + + if ( i == coding) + { + (eMenu->ItemAt(i))->SetMarked(true); + } + e++; + i++; + } } -////////////////////////////////////////////////////////////////////////////// -// -// -////////////////////////////////////////////////////////////////////////////// void -LoadLocaleFile (PrefHandler *pref) +LoadLocaleFile(PrefHandler *pref) { - - const char *locale; - char buf[B_PATH_NAME_LENGTH]; - status_t sts; - - /* - * Open menu localize file. - */ - locale = gTermPref->getString (PREF_GUI_LANGUAGE); - sprintf (buf, "%s%s", LOCALE_FILE_DIR, locale); - - sts = pref->OpenText (buf); - - if (sts == B_ERROR) - pref->OpenText (LOCALE_FILE_DEFAULT); - - return; - + const char *locale; + char buf[B_PATH_NAME_LENGTH]; + status_t sts; + + locale = gTermPref->getString (PREF_GUI_LANGUAGE); + sprintf (buf, "%s%s", LOCALE_FILE_DIR, locale); + + sts = pref->OpenText (buf); + + if (sts == B_ERROR) + pref->OpenText (LOCALE_FILE_DEFAULT); } diff --git a/src/apps/terminal/MYOB/MenuUtil.h b/src/apps/terminal/MYOB/MenuUtil.h index 11c1072225..7cf5161261 100644 --- a/src/apps/terminal/MYOB/MenuUtil.h +++ b/src/apps/terminal/MYOB/MenuUtil.h @@ -41,15 +41,13 @@ class BPopUpMenu; class BMenu; class PrefHandler; - - BPopUpMenu * MakeFontMenu(ulong msg, const char *defaultFontName); - BPopUpMenu * MakeMenu(ulong msg, const char **items, - const char *defaultItemName); + BPopUpMenu * MakeMenu(ulong msg, const char **items, + const char *defaultItemName); - int longname2op(const char *longname); - const char* op2longname(int op); - void MakeEncodingMenu(BMenu *eMenu, int coding, bool flag); - void LoadLocaleFile (PrefHandler *); + int longname2op(const char *longname); + const char * op2longname(int op); + void MakeEncodingMenu(BMenu *eMenu, int coding, bool flag); + void LoadLocaleFile (PrefHandler *); #ifdef __cplusplus } diff --git a/src/apps/terminal/MYOB/PrefDlg.cpp b/src/apps/terminal/MYOB/PrefDlg.cpp index 97b463c0b9..0d26eb166a 100644 --- a/src/apps/terminal/MYOB/PrefDlg.cpp +++ b/src/apps/terminal/MYOB/PrefDlg.cpp @@ -29,7 +29,6 @@ */ #include #include -#include #include #include #include @@ -44,306 +43,209 @@ #include "MenuUtil.h" #include "AppearPrefView.h" -//#include "ShellPrefView.h" #include "PrefView.h" #include "spawn.h" -// Gloval Preference Handler +// Global Preference Handler extern PrefHandler *gTermPref; - -////////////////////////////////////////////////////////////////////////////// -// PrefDlg -// Constructer -////////////////////////////////////////////////////////////////////////////// PrefDlg::PrefDlg(TermWindow *inWindow) - : BWindow(CenteredRect(BRect(0, 0, 350, 250)), "Preference", - B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, - B_NOT_RESIZABLE|B_NOT_ZOOMABLE) + : BWindow(CenteredRect(BRect(0, 0, 350, 215)), "Preference", + B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, + B_NOT_RESIZABLE|B_NOT_ZOOMABLE) { - - fTermWindow = inWindow; - fPrefTemp = new PrefHandler(gTermPref); - fDirty = false; - fSavePanel = NULL; - - SetupContent(); - Show(); - - AddShortcut ((ulong)'Q', (ulong)B_COMMAND_KEY, new BMessage(B_QUIT_REQUESTED)); - AddShortcut ((ulong)'W', (ulong)B_COMMAND_KEY, new BMessage(B_QUIT_REQUESTED)); + fTermWindow = inWindow; + fPrefTemp = new PrefHandler(gTermPref); + fDirty = false; + fSavePanel = NULL; + + BRect r; + + BView *top = new BView(Bounds(), "topview", B_FOLLOW_NONE, B_WILL_DRAW); + top->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + AddChild(top); + + r=top->Bounds(); + r.bottom *= .75; + AppearancePrefView *prefView= new AppearancePrefView(r, "Appearance", + fTermWindow); + top->AddChild(prefView); + + fSaveAsFileButton = new BButton(BRect(0,0,1,1), "savebutton", + "Save to File", + new BMessage(MSG_SAVEAS_PRESSED), + B_FOLLOW_TOP, B_WILL_DRAW); + fSaveAsFileButton->ResizeToPreferred(); + fSaveAsFileButton->MoveTo(5, top->Bounds().Height() - 5 - + fSaveAsFileButton->Bounds().Height()); + top->AddChild(fSaveAsFileButton); + + + fSaveButton = new BButton(BRect(0,0,1,1), "okbutton", "OK", + new BMessage(MSG_SAVE_PRESSED), B_FOLLOW_TOP, + B_WILL_DRAW); + fSaveButton->ResizeToPreferred(); + fSaveButton->MoveTo(top->Bounds().Width() - 5 - fSaveButton->Bounds().Width(), + top->Bounds().Height() - 5 - fSaveButton->Bounds().Height()); + fSaveButton->MakeDefault(true); + top->AddChild(fSaveButton); + + fRevertButton = new BButton(BRect(0,0,1,1), "revertbutton", + "Cancel", new BMessage(MSG_REVERT_PRESSED), + B_FOLLOW_TOP, B_WILL_DRAW); + fRevertButton->ResizeToPreferred(); + fRevertButton->MoveTo(fSaveButton->Frame().left - 10 - + fRevertButton->Bounds().Width(), + top->Bounds().Height() - 5 - + fRevertButton->Bounds().Height()); + top->AddChild(fRevertButton); + + AddShortcut ((ulong)'Q', (ulong)B_COMMAND_KEY, new BMessage(B_QUIT_REQUESTED)); + AddShortcut ((ulong)'W', (ulong)B_COMMAND_KEY, new BMessage(B_QUIT_REQUESTED)); + + Show(); } -////////////////////////////////////////////////////////////////////////////// -// PrefDlg -////////////////////////////////////////////////////////////////////////////// PrefDlg::~PrefDlg (void) { } -////////////////////////////////////////////////////////////////////////////// -// SetupContent() -// Set up content of window. -////////////////////////////////////////////////////////////////////////////// -void -PrefDlg::SetupContent() -{ - BRect r; - - Lock(); - - BView *top = new BView(Bounds(), "topview", B_FOLLOW_NONE, B_WILL_DRAW); - top->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - AddChild (top); - - // - // Tab View - // - r = top->Bounds(); - r.bottom -= 40; - r.InsetBy (0, 5); - - fTabView = new BTabView(r, "tab_view", B_WIDTH_FROM_WIDEST); - fTabView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - - r = fTabView->Bounds(); - r.InsetBy(10,10); - r.bottom -= fTabView->TabHeight(); - - fTabView->AddTab(new AppearancePrefView (r, "Appearance", fTermWindow)); - // fTabView->AddTab(new ShellPrefView (r, "Shell", fTermWindow)); - - // - // OK, Apply and Cancel button. - // - - fSaveAsFileButton = new BButton(BRect(50,215,150,20), "savebutton", "Save to File", new BMessage(MSG_SAVEAS_PRESSED), B_FOLLOW_TOP, B_WILL_DRAW); - top->AddChild(fSaveAsFileButton); - fRevertButton = new BButton(BRect(180,215,250,20), "revertbutton", "Cancel", new BMessage(MSG_REVERT_PRESSED), B_FOLLOW_TOP, B_WILL_DRAW); - top->AddChild(fRevertButton); - fSaveButton = new BButton(BRect(260,215,330,20), "okbutton", "OK", new BMessage(MSG_SAVE_PRESSED), B_FOLLOW_TOP, B_WILL_DRAW); - top->AddChild(fSaveButton); - - - top->AddChild (fTabView); - - Unlock(); -} - -////////////////////////////////////////////////////////////////////////////// -// if OK button pressed -// -////////////////////////////////////////////////////////////////////////////// void PrefDlg::Quit() { - fTermWindow->PostMessage(MSG_PREF_CLOSED); - delete fPrefTemp; - delete fSavePanel; - BWindow::Quit(); + fTermWindow->PostMessage(MSG_PREF_CLOSED); + delete fPrefTemp; + delete fSavePanel; + BWindow::Quit(); } -////////////////////////////////////////////////////////////////////////////// -// QuitRequested -// if close box checked and perf is changed.. -////////////////////////////////////////////////////////////////////////////// + bool -PrefDlg::QuitRequested () +PrefDlg::QuitRequested() { - if(!fDirty) return true; - - BAlert *alert = new BAlert("", - "Save changes to this preference panel?", - "Cancel", "Don't Save", - "Save", - B_WIDTH_AS_USUAL, - B_OFFSET_SPACING, - B_WARNING_ALERT); - alert->SetShortcut(0, B_ESCAPE); - alert->SetShortcut(1, 'd'); - alert->SetShortcut(2, 's'); - int32 button_index = alert->Go(); - - switch (button_index) { - - case 0: // Cancel - return false; - break; - - case 2: // Save - this->doSave(); - break; - - case 1: // Don't Save - default: - break; - } - - return true; + if(!fDirty) + return true; + + BAlert *alert = new BAlert("", "Save changes to this preference panel?", + "Cancel", "Don't Save", "Save", + B_WIDTH_AS_USUAL, B_OFFSET_SPACING, + B_WARNING_ALERT); + alert->SetShortcut(0, B_ESCAPE); + alert->SetShortcut(1, 'd'); + alert->SetShortcut(2, 's'); + int32 button_index = alert->Go(); + + if(button_index==0) + return false; + else + if(button_index==2) + doSave(); + + return true; } -////////////////////////////////////////////////////////////////////////////// -// if SaveAs button pressed -// -////////////////////////////////////////////////////////////////////////////// + void PrefDlg::doSaveAs (void) { - for (int32 i = 0; i < fTabView->CountTabs(); i++) { - // PrefView *aView = (PrefView *)fTabView->ViewForTab(i); - // aView->SaveIfModified (); - } - - if(!fSavePanel){ - fSavePanel = new BFilePanel(B_SAVE_PANEL, new BMessenger(this)); - } - - fSavePanel->Show(); + if(!fSavePanel) + fSavePanel = new BFilePanel(B_SAVE_PANEL, new BMessenger(this)); + + fSavePanel->Show(); } -////////////////////////////////////////////////////////////////////////////// -// -// -////////////////////////////////////////////////////////////////////////////// + void PrefDlg::SaveRequested(BMessage *msg) { - entry_ref dirref; - const char *filename; - - msg->FindRef("directory", &dirref); - msg->FindString("name", &filename); - BDirectory dir(&dirref); - BPath path(&dir, filename); - - gTermPref->SaveAsText (path.Path(), PREFFILE_MIMETYPE, TERM_SIGNATURE); + entry_ref dirref; + const char *filename; + + msg->FindRef("directory", &dirref); + msg->FindString("name", &filename); + + BDirectory dir(&dirref); + BPath path(&dir, filename); + + gTermPref->SaveAsText (path.Path(), PREFFILE_MIMETYPE, TERM_SIGNATURE); } -////////////////////////////////////////////////////////////////////////////// -// if OK button pressed -// -////////////////////////////////////////////////////////////////////////////// + void PrefDlg::doSave (void) { - for (int32 i = 0; i < fTabView->CountTabs(); i++) { - // PrefView *aView = (PrefView *)fTabView->ViewForTab(i); - // aView->SaveIfModified (); - } - - delete fPrefTemp; - fPrefTemp = new PrefHandler (gTermPref); - - gTermPref->SaveAsText (TERM_PREF, PREFFILE_MIMETYPE); - - fDirty = false; + delete fPrefTemp; + fPrefTemp = new PrefHandler (gTermPref); + + gTermPref->SaveAsText (TERM_PREF, PREFFILE_MIMETYPE); + + fDirty = false; } -////////////////////////////////////////////////////////////////////////////// -// if cancel button pressed -// -////////////////////////////////////////////////////////////////////////////// + void PrefDlg::doRevert (void) { - BMessenger messenger (fTermWindow); - - delete gTermPref; - gTermPref = new PrefHandler (fPrefTemp); - - messenger.SendMessage (MSG_HALF_FONT_CHANGED); - messenger.SendMessage (MSG_COLOR_CHANGED); - messenger.SendMessage (MSG_ROWS_CHANGED); - messenger.SendMessage (MSG_INPUT_METHOD_CHANGED); - - this->DisableUpdates(); - this->Lock(); - for (int32 i = 0; i < fTabView->CountTabs(); i++) { - // PrefView *aView = (PrefView *)fTabView->ViewForTab(i); - // aView->Revert (); - } - this->Unlock(); - this->EnableUpdates(); - - fDirty = false; + BMessenger messenger (fTermWindow); + + delete gTermPref; + gTermPref = new PrefHandler (fPrefTemp); + + messenger.SendMessage (MSG_HALF_FONT_CHANGED); + messenger.SendMessage (MSG_COLOR_CHANGED); + messenger.SendMessage (MSG_ROWS_CHANGED); + messenger.SendMessage (MSG_INPUT_METHOD_CHANGED); + + fDirty = false; } -////////////////////////////////////////////////////////////////////////////// -// -// -////////////////////////////////////////////////////////////////////////////// + void PrefDlg::MessageReceived(BMessage *msg) { - switch (msg->what) { - case MSG_SAVE_PRESSED: - doSave(); - PostMessage(B_QUIT_REQUESTED); - break; - - case MSG_SAVEAS_PRESSED: - doSaveAs(); - break; - - case MSG_REVERT_PRESSED: - doRevert(); - PostMessage(B_QUIT_REQUESTED); - break; - - case MSG_PREF_MODIFIED: - fDirty = true; - break; - - case B_SAVE_REQUESTED: - this->SaveRequested(msg); - break; - - default: - BWindow::MessageReceived(msg); - break; - } + switch (msg->what) + { + case MSG_SAVE_PRESSED: + { + doSave(); + PostMessage(B_QUIT_REQUESTED); + break; + } + case MSG_SAVEAS_PRESSED: + { + doSaveAs(); + break; + } + case MSG_REVERT_PRESSED: + { + doRevert(); + PostMessage(B_QUIT_REQUESTED); + break; + } + case MSG_PREF_MODIFIED: + { + fDirty = true; + break; + } + case B_SAVE_REQUESTED: + { + SaveRequested(msg); + break; + } + default: + { + BWindow::MessageReceived(msg); + break; + } + } } -////////////////////////////////////////////////////////////////////////////// -// SetupBox -// make Box -////////////////////////////////////////////////////////////////////////////// -BBox * -PrefDlg::SetupBox(BRect r, const char *label, BView *parent) -{ - BBox *b; - b = new BBox(r); - b->SetLabel(label); - parent->AddChild(b); - return b; -} -////////////////////////////////////////////////////////////////////////////// -// SetupButton -// make Button -////////////////////////////////////////////////////////////////////////////// -//BButton * -//PrefDlg::SetupButton(BRect r, const char *label, ulong msg, BView *parent, bool defaultButton) -//{ -// BButton *b; -// -// b = new BButton(r, "", label, new BMessage(msg)); -// parent->AddChild(b); -// -// if (defaultButton) -// (parent->Window())->SetDefaultButton(b); -// -// return b; -//} -////////////////////////////////////////////////////////////////////////////// -// Ajust Input Rect to locate center of Screen. -// ( static member function. ) -////////////////////////////////////////////////////////////////////////////// BRect PrefDlg::CenteredRect(BRect r) { - BRect screenRect = BScreen().Frame(); - - screenRect.InsetBy(10,10); - - float x = screenRect.left + (screenRect.Width() - r.Width()) / 2; - float y = screenRect.top + (screenRect.Height() - r.Height()) / 3; - - r.OffsetTo(x, y); - - return r; + BRect screenRect = BScreen().Frame(); + + screenRect.InsetBy(10,10); + + float x = screenRect.left + (screenRect.Width() - r.Width()) / 2; + float y = screenRect.top + (screenRect.Height() - r.Height()) / 3; + + r.OffsetTo(x, y); + + return r; } diff --git a/src/apps/terminal/MYOB/PrefDlg.h b/src/apps/terminal/MYOB/PrefDlg.h index a6106f8187..45c86de7db 100644 --- a/src/apps/terminal/MYOB/PrefDlg.h +++ b/src/apps/terminal/MYOB/PrefDlg.h @@ -55,38 +55,29 @@ class BFilePanel; class PrefDlg : public BWindow { public: - PrefDlg(TermWindow *inWindow); - ~PrefDlg (); - - void Quit(); - + PrefDlg(TermWindow *inWindow); + ~PrefDlg(); + void Quit(); private: - void doSave (void); - void doSaveAs (void); - void doRevert (void); - void SaveRequested(BMessage *msg); - - bool QuitRequested (); - void MessageReceived (BMessage *msg); - - void SetupContent(); - - BBox* SetupBox(BRect r, const char *label, BView *parent); - BButton* SetupButton(BRect r, const char *label, ulong msg, - BView *parent, bool defaultButton=false); - - static BRect CenteredRect(BRect r); - -private: - TermWindow *fTermWindow; - BTabView *fTabView; - PrefHandler *fPrefTemp; - BFilePanel *fSavePanel; - BButton *fSaveAsFileButton; - BButton *fRevertButton; - BButton *fSaveButton; - - bool fDirty; + void doSave (void); + void doSaveAs (void); + void doRevert (void); + void SaveRequested(BMessage *msg); + + bool QuitRequested(); + void MessageReceived (BMessage *msg); + + static BRect CenteredRect(BRect r); + + TermWindow *fTermWindow; + PrefHandler *fPrefTemp; + BFilePanel *fSavePanel; + + BButton *fSaveAsFileButton, + *fRevertButton, + *fSaveButton; + + bool fDirty; }; #endif //PREFDLG_H_INCLUDED