StyledEdit didn't clear the marks on the Font Styles in the font menu.

It resulted in several bogus checkmarks. (ticket #2984)

Also, The last font was always checked by default. The error was that 
instead than Marking the "left align" item, it was checking that font because 
of the wrong variable used.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30590 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Philippe Saint-Pierre 2009-05-02 20:24:53 +00:00
parent 1fd6d62418
commit 12483e3cbf
2 changed files with 50 additions and 34 deletions

View File

@ -5,6 +5,7 @@
* Authors: * Authors:
* Mattias Sundblad * Mattias Sundblad
* Andrew Bachmann * Andrew Bachmann
* Philippe Saint-Pierre
*/ */
#include "Constants.h" #include "Constants.h"
@ -225,12 +226,10 @@ StyledEditWindow::InitWindow(uint32 encoding)
fFontColorMenu->AddItem(fYellowItem = new ColorMenuItem("Yellow", YELLOW, new BMessage(FONT_COLOR))); fFontColorMenu->AddItem(fYellowItem = new ColorMenuItem("Yellow", YELLOW, new BMessage(FONT_COLOR)));
fFontMenu->AddSeparatorItem(); fFontMenu->AddSeparatorItem();
// Available fonts, mark "be_plain_font" item // Available fonts
font_family plainFamily;
font_style plainStyle;
be_plain_font->GetFamilyAndStyle(&plainFamily, &plainStyle);
fCurrentFontItem = 0; fCurrentFontItem = 0;
fCurrentStyleItem = 0;
BMenu* subMenu; BMenu* subMenu;
int32 numFamilies = count_font_families(); int32 numFamilies = count_font_families();
@ -239,12 +238,8 @@ StyledEditWindow::InitWindow(uint32 encoding)
if (get_font_family(i, &family) == B_OK) { if (get_font_family(i, &family) == B_OK) {
subMenu = new BMenu(family); subMenu = new BMenu(family);
subMenu->SetRadioMode(true); subMenu->SetRadioMode(true);
fFontMenu->AddItem(menuItem = new BMenuItem(subMenu, new BMessage(FONT_FAMILY))); fFontMenu->AddItem(menuItem = new BMenuItem(subMenu,
new BMessage(FONT_FAMILY)));
if (!strcmp(plainFamily, family)) {
menuItem->SetMarked(true);
fCurrentFontItem = menuItem;
}
int32 numStyles = count_font_styles(family); int32 numStyles = count_font_styles(family);
for (int32 j = 0; j < numStyles; j++) { for (int32 j = 0; j < numStyles; j++) {
@ -253,9 +248,6 @@ StyledEditWindow::InitWindow(uint32 encoding)
if (get_font_style(family, j, &style, &flags) == B_OK) { if (get_font_style(family, j, &style, &flags) == B_OK) {
subMenu->AddItem(menuItem = new BMenuItem(style, subMenu->AddItem(menuItem = new BMenuItem(style,
new BMessage(FONT_STYLE))); new BMessage(FONT_STYLE)));
if (!strcmp(plainStyle, style))
menuItem->SetMarked(true);
} }
} }
} }
@ -270,7 +262,7 @@ StyledEditWindow::InitWindow(uint32 encoding)
subMenu->SetRadioMode(true); subMenu->SetRadioMode(true);
subMenu->AddItem(fAlignLeft = new BMenuItem("Left", new BMessage(ALIGN_LEFT))); subMenu->AddItem(fAlignLeft = new BMenuItem("Left", new BMessage(ALIGN_LEFT)));
menuItem->SetMarked(true); fAlignLeft->SetMarked(true);
subMenu->AddItem(fAlignCenter = new BMenuItem("Center", new BMessage(ALIGN_CENTER))); subMenu->AddItem(fAlignCenter = new BMenuItem("Center", new BMessage(ALIGN_CENTER)));
subMenu->AddItem(fAlignRight = new BMenuItem("Right", new BMessage(ALIGN_RIGHT))); subMenu->AddItem(fAlignRight = new BMenuItem("Right", new BMessage(ALIGN_RIGHT)));
@ -444,8 +436,8 @@ StyledEditWindow::MessageReceived(BMessage *message)
const char* fontStyle = NULL; const char* fontStyle = NULL;
void* ptr; void* ptr;
if (message->FindPointer("source", &ptr) == B_OK) { if (message->FindPointer("source", &ptr) == B_OK) {
fCurrentFontItem = static_cast<BMenuItem*>(ptr); BMenuItem* item = static_cast<BMenuItem*>(ptr);
fontFamily = fCurrentFontItem->Label(); fontFamily = item->Label();
} }
SetFontStyle(fontFamily, fontStyle); SetFontStyle(fontFamily, fontStyle);
break; break;
@ -460,9 +452,9 @@ StyledEditWindow::MessageReceived(BMessage *message)
fontStyle = item->Label(); fontStyle = item->Label();
BMenu* menu = item->Menu(); BMenu* menu = item->Menu();
if (menu != NULL) { if (menu != NULL) {
fCurrentFontItem = menu->Superitem(); BMenuItem* super_item = menu->Superitem();
if (fCurrentFontItem != NULL) if (super_item != NULL)
fontFamily = fCurrentFontItem->Label(); fontFamily = super_item->Label();
} }
} }
SetFontStyle(fontFamily, fontStyle); SetFontStyle(fontFamily, fontStyle);
@ -629,8 +621,20 @@ StyledEditWindow::MenusBeginning()
// update the font menu // update the font menu
// unselect the old values // unselect the old values
if (fCurrentFontItem != NULL) if (fCurrentFontItem != NULL) {
fCurrentFontItem->SetMarked(false); fCurrentFontItem->SetMarked(false);
BMenu* menu = fCurrentFontItem->Submenu();
if (menu != NULL) {
BMenuItem* item = menu->FindMarked();
if (item != NULL) {
item->SetMarked(false);
}
}
}
if (fCurrentStyleItem != NULL) {
fCurrentStyleItem->SetMarked(false);
}
BMenuItem* oldColorItem = fFontColorMenu->FindMarked(); BMenuItem* oldColorItem = fFontColorMenu->FindMarked();
if (oldColorItem != NULL) if (oldColorItem != NULL)
@ -689,18 +693,20 @@ StyledEditWindow::MenusBeginning()
} }
} }
if (sameProperties & B_FONT_FAMILY_AND_STYLE) { font_family family;
font_family family; font_style style;
font_style style; font.GetFamilyAndStyle(&family, &style);
font.GetFamilyAndStyle(&family, &style);
fCurrentFontItem = fFontMenu->FindItem(family); fCurrentFontItem = fFontMenu->FindItem(family);
if (fCurrentFontItem != NULL) {
fCurrentFontItem->SetMarked(true); if (fCurrentFontItem != NULL) {
BMenu* menu = fCurrentFontItem->Submenu(); fCurrentFontItem->SetMarked(true);
if (menu != NULL) { BMenu* menu = fCurrentFontItem->Submenu();
BMenuItem* item = menu->FindItem(style); if (menu != NULL) {
if (item != NULL) BMenuItem* item = menu->FindItem(style);
item->SetMarked(true); fCurrentStyleItem = item;
if (fCurrentStyleItem != NULL) {
item->SetMarked(true);
} }
} }
} }
@ -1278,8 +1284,15 @@ StyledEditWindow::SetFontStyle(const char *fontFamily, const char *fontStyle)
// clear that family's bit on the menu, if necessary // clear that family's bit on the menu, if necessary
if (strcmp(oldFamily, fontFamily)) { if (strcmp(oldFamily, fontFamily)) {
BMenuItem* oldItem = fFontMenu->FindItem(oldFamily); BMenuItem* oldItem = fFontMenu->FindItem(oldFamily);
if (oldItem != NULL) if (oldItem != NULL) {
oldItem->SetMarked(false); oldItem->SetMarked(false);
BMenu* menu = oldItem->Submenu();
if (menu != NULL) {
oldItem = menu->FindItem(oldStyle);
if (oldItem != NULL)
oldItem->SetMarked(false);
}
}
} }
font.SetFamilyAndStyle(fontFamily, fontStyle); font.SetFamilyAndStyle(fontFamily, fontStyle);
@ -1287,8 +1300,10 @@ StyledEditWindow::SetFontStyle(const char *fontFamily, const char *fontStyle)
BMenuItem* superItem; BMenuItem* superItem;
superItem = fFontMenu->FindItem(fontFamily); superItem = fFontMenu->FindItem(fontFamily);
if (superItem != NULL) if (superItem != NULL) {
superItem->SetMarked(true); superItem->SetMarked(true);
fCurrentFontItem = superItem;
}
_UpdateCleanUndoRedoSaveRevert(); _UpdateCleanUndoRedoSaveRevert();
} }

View File

@ -70,6 +70,7 @@ class StyledEditWindow : public BWindow {
BMenu *fFontSizeMenu; BMenu *fFontSizeMenu;
BMenu *fFontColorMenu; BMenu *fFontColorMenu;
BMenuItem *fCurrentFontItem; BMenuItem *fCurrentFontItem;
BMenuItem *fCurrentStyleItem;
BMenuItem *fSaveItem; BMenuItem *fSaveItem;
BMenuItem *fRevertItem; BMenuItem *fRevertItem;