update font menu for color based on selection or cursor location
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2063 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -179,60 +179,53 @@ StyledEditWindow::InitWindow()
|
|||||||
|
|
||||||
//Add the "Font"-menu:
|
//Add the "Font"-menu:
|
||||||
BMessage *fontMessage;
|
BMessage *fontMessage;
|
||||||
menu= new BMenu("Font");
|
fFontMenu = new BMenu("Font");
|
||||||
fMenuBar->AddItem(menu);
|
fMenuBar->AddItem(fFontMenu);
|
||||||
|
|
||||||
//"Size"-subMenu
|
//"Size"-subMenu
|
||||||
subMenu=new BMenu("Size");
|
fFontSizeMenu=new BMenu("Size");
|
||||||
subMenu->SetRadioMode(true);
|
fFontSizeMenu->SetRadioMode(true);
|
||||||
menu->AddItem(subMenu);
|
fFontMenu->AddItem(fFontSizeMenu);
|
||||||
|
|
||||||
subMenu->AddItem(menuItem= new BMenuItem("9", fontMessage= new BMessage(FONT_SIZE)));
|
fFontSizeMenu->AddItem(menuItem= new BMenuItem("9", fontMessage= new BMessage(FONT_SIZE)));
|
||||||
fontMessage->AddFloat("size", 9.0);
|
fontMessage->AddFloat("size", 9.0);
|
||||||
|
|
||||||
subMenu->AddItem(menuItem= new BMenuItem("10", fontMessage= new BMessage(FONT_SIZE)));
|
fFontSizeMenu->AddItem(menuItem= new BMenuItem("10", fontMessage= new BMessage(FONT_SIZE)));
|
||||||
fontMessage->AddFloat("size",10.0);
|
fontMessage->AddFloat("size",10.0);
|
||||||
menuItem->SetMarked(true);
|
menuItem->SetMarked(true);
|
||||||
|
|
||||||
subMenu->AddItem(menuItem= new BMenuItem("12", fontMessage= new BMessage(FONT_SIZE)));
|
fFontSizeMenu->AddItem(menuItem= new BMenuItem("12", fontMessage= new BMessage(FONT_SIZE)));
|
||||||
fontMessage->AddFloat("size",12.0);
|
fontMessage->AddFloat("size",12.0);
|
||||||
subMenu->AddItem(menuItem= new BMenuItem("14", fontMessage= new BMessage(FONT_SIZE)));
|
fFontSizeMenu->AddItem(menuItem= new BMenuItem("14", fontMessage= new BMessage(FONT_SIZE)));
|
||||||
fontMessage->AddFloat("size",14.0);
|
fontMessage->AddFloat("size",14.0);
|
||||||
subMenu->AddItem(menuItem= new BMenuItem("18", fontMessage= new BMessage(FONT_SIZE)));
|
fFontSizeMenu->AddItem(menuItem= new BMenuItem("18", fontMessage= new BMessage(FONT_SIZE)));
|
||||||
fontMessage->AddFloat("size",18.0);
|
fontMessage->AddFloat("size",18.0);
|
||||||
|
|
||||||
subMenu->AddItem(menuItem= new BMenuItem("24", fontMessage= new BMessage(FONT_SIZE)));
|
fFontSizeMenu->AddItem(menuItem= new BMenuItem("24", fontMessage= new BMessage(FONT_SIZE)));
|
||||||
fontMessage->AddFloat("size",24.0);
|
fontMessage->AddFloat("size",24.0);
|
||||||
subMenu->AddItem(menuItem= new BMenuItem("36", fontMessage= new BMessage(FONT_SIZE)));
|
fFontSizeMenu->AddItem(menuItem= new BMenuItem("36", fontMessage= new BMessage(FONT_SIZE)));
|
||||||
fontMessage->AddFloat("size",36.0);
|
fontMessage->AddFloat("size",36.0);
|
||||||
subMenu->AddItem(menuItem= new BMenuItem("48", fontMessage= new BMessage(FONT_SIZE)));
|
fFontSizeMenu->AddItem(menuItem= new BMenuItem("48", fontMessage= new BMessage(FONT_SIZE)));
|
||||||
fontMessage->AddFloat("size",48.0);
|
fontMessage->AddFloat("size",48.0);
|
||||||
subMenu->AddItem(menuItem= new BMenuItem("72", fontMessage= new BMessage(FONT_SIZE)));
|
fFontSizeMenu->AddItem(menuItem= new BMenuItem("72", fontMessage= new BMessage(FONT_SIZE)));
|
||||||
fontMessage->AddFloat("size",72.0);
|
fontMessage->AddFloat("size",72.0);
|
||||||
|
|
||||||
//"Color"-subMenu
|
//"Color"-subMenu
|
||||||
subMenu= new BMenu("Color");
|
fFontColorMenu= new BMenu("Color");
|
||||||
subMenu->SetRadioMode(true);
|
fFontColorMenu->SetRadioMode(true);
|
||||||
menu->AddItem(subMenu);
|
fFontMenu->AddItem(fFontColorMenu);
|
||||||
|
|
||||||
ColorMenuItem *ColorItem;
|
ColorMenuItem *ColorItem;
|
||||||
|
|
||||||
subMenu->AddItem(menuItem= new BMenuItem("Black", fontMessage= new BMessage(FONT_COLOR)));
|
fFontColorMenu->AddItem(fBlackItem= new BMenuItem("Black", new BMessage(FONT_COLOR)));
|
||||||
fontMessage->AddPointer("colour",&BLACK);
|
fBlackItem->SetMarked(true);
|
||||||
menuItem->SetMarked(true);
|
fFontColorMenu->AddItem(fRedItem= new ColorMenuItem("Red", RED, new BMessage(FONT_COLOR)));
|
||||||
subMenu->AddItem(ColorItem= new ColorMenuItem("Red", RED, fontMessage= new BMessage(FONT_COLOR)));
|
fFontColorMenu->AddItem(fGreenItem= new ColorMenuItem("Green", GREEN, new BMessage(FONT_COLOR)));
|
||||||
fontMessage->AddPointer("colour", &RED);
|
fFontColorMenu->AddItem(fBlueItem= new ColorMenuItem("Blue", BLUE, new BMessage(FONT_COLOR)));
|
||||||
subMenu->AddItem(ColorItem= new ColorMenuItem("Green", GREEN, fontMessage= new BMessage(FONT_COLOR)));
|
fFontColorMenu->AddItem(fCyanItem= new ColorMenuItem("Cyan", CYAN, new BMessage(FONT_COLOR)));
|
||||||
fontMessage->AddPointer("colour", &GREEN);
|
fFontColorMenu->AddItem(fMagentaItem= new ColorMenuItem("Magenta", MAGENTA, new BMessage(FONT_COLOR)));
|
||||||
subMenu->AddItem(ColorItem= new ColorMenuItem("Blue", BLUE, fontMessage= new BMessage(FONT_COLOR)));
|
fFontColorMenu->AddItem(fYellowItem= new ColorMenuItem("Yellow", YELLOW, new BMessage(FONT_COLOR)));
|
||||||
fontMessage->AddPointer("colour", &BLUE);
|
fFontMenu->AddSeparatorItem();
|
||||||
subMenu->AddItem(ColorItem= new ColorMenuItem("Cyan", CYAN, fontMessage= new BMessage(FONT_COLOR)));
|
|
||||||
fontMessage->AddPointer("colour",&CYAN);
|
|
||||||
subMenu->AddItem(ColorItem= new ColorMenuItem("Magenta", MAGENTA, fontMessage= new BMessage(FONT_COLOR)));
|
|
||||||
fontMessage->AddPointer("colour", &MAGENTA);
|
|
||||||
subMenu->AddItem(ColorItem= new ColorMenuItem("Yellow", YELLOW, fontMessage= new BMessage(FONT_COLOR)));
|
|
||||||
fontMessage->AddPointer("colour", &YELLOW);
|
|
||||||
menu->AddSeparatorItem();
|
|
||||||
|
|
||||||
//Available fonts
|
//Available fonts
|
||||||
font_family plain_family;
|
font_family plain_family;
|
||||||
@@ -245,9 +238,10 @@ StyledEditWindow::InitWindow()
|
|||||||
if ( get_font_family ( i, &localfamily ) == B_OK ) {
|
if ( get_font_family ( i, &localfamily ) == B_OK ) {
|
||||||
subMenu=new BMenu(localfamily);
|
subMenu=new BMenu(localfamily);
|
||||||
subMenu->SetRadioMode(true);
|
subMenu->SetRadioMode(true);
|
||||||
menu->AddItem(menuItem = new BMenuItem(subMenu, new BMessage(FONT_FAMILY)));
|
fFontMenu->AddItem(menuItem = new BMenuItem(subMenu, new BMessage(FONT_FAMILY)));
|
||||||
if (!strcmp(plain_family,localfamily)) {
|
if (!strcmp(plain_family,localfamily)) {
|
||||||
menuItem->SetMarked(true);
|
menuItem->SetMarked(true);
|
||||||
|
fCurrentFontItem = menuItem;
|
||||||
}
|
}
|
||||||
int32 numStyles=count_font_styles(localfamily);
|
int32 numStyles=count_font_styles(localfamily);
|
||||||
for(int32 j = 0;j<numStyles;j++){
|
for(int32 j = 0;j<numStyles;j++){
|
||||||
@@ -460,12 +454,31 @@ StyledEditWindow::MessageReceived(BMessage *message)
|
|||||||
break;
|
break;
|
||||||
case FONT_COLOR:
|
case FONT_COLOR:
|
||||||
{
|
{
|
||||||
void *v;
|
void * ptr;
|
||||||
rgb_color *color;
|
if (message->FindPointer("source",&ptr) == B_OK) {
|
||||||
|
if (ptr == fBlackItem) {
|
||||||
|
SetFontColor(&BLACK);
|
||||||
|
} else if (ptr == fRedItem) {
|
||||||
|
SetFontColor(&RED);
|
||||||
|
} else if (ptr == fGreenItem) {
|
||||||
|
SetFontColor(&GREEN);
|
||||||
|
} else if (ptr == fBlueItem) {
|
||||||
|
SetFontColor(&BLUE);
|
||||||
|
} else if (ptr == fCyanItem) {
|
||||||
|
SetFontColor(&CYAN);
|
||||||
|
} else if (ptr == fMagentaItem) {
|
||||||
|
SetFontColor(&MAGENTA);
|
||||||
|
} else if (ptr == fYellowItem) {
|
||||||
|
SetFontColor(&YELLOW);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
message->FindPointer("colour",&v);
|
// void *v;
|
||||||
color= (rgb_color *) v;
|
// rgb_color *color;
|
||||||
SetFontColor(color);
|
//
|
||||||
|
// message->FindPointer("colour",&v);
|
||||||
|
// color= (rgb_color *) v;
|
||||||
|
// SetFontColor(color);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
/*********"Document"-menu*************/
|
/*********"Document"-menu*************/
|
||||||
@@ -605,8 +618,10 @@ StyledEditWindow::MessageReceived(BMessage *message)
|
|||||||
void
|
void
|
||||||
StyledEditWindow::MenusBeginning()
|
StyledEditWindow::MenusBeginning()
|
||||||
{
|
{
|
||||||
|
// set up the recent documents menu
|
||||||
BMessage documents;
|
BMessage documents;
|
||||||
be_roster->GetRecentDocuments(&documents,9,NULL,APP_SIGNATURE);
|
be_roster->GetRecentDocuments(&documents,9,NULL,APP_SIGNATURE);
|
||||||
|
|
||||||
// delete old items..
|
// delete old items..
|
||||||
// shatty: it would be preferable to keep the old
|
// shatty: it would be preferable to keep the old
|
||||||
// menu around instead of continuously thrashing
|
// menu around instead of continuously thrashing
|
||||||
@@ -626,6 +641,56 @@ StyledEditWindow::MenusBeginning()
|
|||||||
item->SetTarget(be_app);
|
item->SetTarget(be_app);
|
||||||
fRecentMenu->AddItem(item);
|
fRecentMenu->AddItem(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// update the font menu be/interface/GraphicsDefs.h
|
||||||
|
// unselect the old values
|
||||||
|
fCurrentFontItem->SetMarked(false);
|
||||||
|
BMenuItem * oldColorItem = fFontColorMenu->FindMarked();
|
||||||
|
if (oldColorItem != 0) {
|
||||||
|
oldColorItem->SetMarked(false);
|
||||||
|
}
|
||||||
|
BMenuItem * oldSizeItem = fFontSizeMenu->FindMarked();
|
||||||
|
if (oldSizeItem != 0) {
|
||||||
|
oldSizeItem->SetMarked(false);
|
||||||
|
}
|
||||||
|
// find the current font, color, size
|
||||||
|
BFont font;
|
||||||
|
uint32 sameProperties;
|
||||||
|
rgb_color color = BLACK;
|
||||||
|
bool sameColor;
|
||||||
|
fTextView->GetFontAndColor(&font,&sameProperties,&color,&sameColor);
|
||||||
|
|
||||||
|
if (sameColor && (color.alpha == 255)) {
|
||||||
|
if (color.red == 0) {
|
||||||
|
if (color.green == 0) {
|
||||||
|
if (color.blue == 0) {
|
||||||
|
fBlackItem->SetMarked(true);
|
||||||
|
} else if (color.blue == 255) {
|
||||||
|
fBlueItem->SetMarked(true);
|
||||||
|
}
|
||||||
|
} else if (color.green == 255) {
|
||||||
|
if (color.blue == 0) {
|
||||||
|
fGreenItem->SetMarked(true);
|
||||||
|
} else if (color.blue == 255) {
|
||||||
|
fCyanItem->SetMarked(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (color.red == 255) {
|
||||||
|
if (color.green == 0) {
|
||||||
|
if (color.blue == 0) {
|
||||||
|
fRedItem->SetMarked(true);
|
||||||
|
} else if (color.blue == 255) {
|
||||||
|
fMagentaItem->SetMarked(true);
|
||||||
|
}
|
||||||
|
} else if (color.green == 255) {
|
||||||
|
if (color.blue == 0) {
|
||||||
|
fYellowItem->SetMarked(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: select current font & size
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -1121,7 +1186,7 @@ StyledEditWindow::SetFontSize(float fontSize)
|
|||||||
}/***StyledEditWindow::SetFontSize()***/
|
}/***StyledEditWindow::SetFontSize()***/
|
||||||
|
|
||||||
void
|
void
|
||||||
StyledEditWindow::SetFontColor(rgb_color *color)
|
StyledEditWindow::SetFontColor(const rgb_color *color)
|
||||||
{
|
{
|
||||||
uint32 sameProperties;
|
uint32 sameProperties;
|
||||||
BFont font;
|
BFont font;
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ private:
|
|||||||
bool Replace(BString findthis, BString replacewith, bool casesens, bool wrap, bool backsearch);
|
bool Replace(BString findthis, BString replacewith, bool casesens, bool wrap, bool backsearch);
|
||||||
void ReplaceAll(BString find, BString replace, bool casesens);
|
void ReplaceAll(BString find, BString replace, bool casesens);
|
||||||
void SetFontSize(float fontSize);
|
void SetFontSize(float fontSize);
|
||||||
void SetFontColor(rgb_color *color);
|
void SetFontColor(const rgb_color *color);
|
||||||
void SetFontStyle(const char *fontFamily, const char *fontStyle);
|
void SetFontStyle(const char *fontFamily, const char *fontStyle);
|
||||||
void RevertToSaved();
|
void RevertToSaved();
|
||||||
|
|
||||||
@@ -46,16 +46,33 @@ private:
|
|||||||
BMessage *fPrintSettings;
|
BMessage *fPrintSettings;
|
||||||
BMessage *fSaveMessage;
|
BMessage *fSaveMessage;
|
||||||
BMenu *fRecentMenu;
|
BMenu *fRecentMenu;
|
||||||
|
|
||||||
|
BMenu *fFontMenu;
|
||||||
|
BMenu *fFontSizeMenu;
|
||||||
|
BMenu *fFontColorMenu;
|
||||||
|
BMenuItem *fCurrentFontItem;
|
||||||
|
|
||||||
BMenuItem *fSaveItem;
|
BMenuItem *fSaveItem;
|
||||||
BMenuItem *fRevertItem;
|
BMenuItem *fRevertItem;
|
||||||
|
|
||||||
BMenuItem *fUndoItem;
|
BMenuItem *fUndoItem;
|
||||||
BMenuItem *fCutItem;
|
BMenuItem *fCutItem;
|
||||||
BMenuItem *fCopyItem;
|
BMenuItem *fCopyItem;
|
||||||
BMenuItem *fClearItem;
|
BMenuItem *fClearItem;
|
||||||
|
|
||||||
|
BMenuItem *fBlackItem;
|
||||||
|
BMenuItem *fRedItem;
|
||||||
|
BMenuItem *fGreenItem;
|
||||||
|
BMenuItem *fBlueItem;
|
||||||
|
BMenuItem *fCyanItem;
|
||||||
|
BMenuItem *fMagentaItem;
|
||||||
|
BMenuItem *fYellowItem;
|
||||||
|
|
||||||
BMenuItem *fWrapItem;
|
BMenuItem *fWrapItem;
|
||||||
BMenuItem *fAlignLeft;
|
BMenuItem *fAlignLeft;
|
||||||
BMenuItem *fAlignCenter;
|
BMenuItem *fAlignCenter;
|
||||||
BMenuItem *fAlignRight;
|
BMenuItem *fAlignRight;
|
||||||
|
|
||||||
BString fStringToFind;
|
BString fStringToFind;
|
||||||
BString fReplaceString;
|
BString fReplaceString;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user