Restyled Menu preflet, it's still very ugly but at least I can

understand where's things.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16611 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini
2006-03-06 17:15:16 +00:00
parent 9f6376a0c7
commit b820da1a25
13 changed files with 750 additions and 740 deletions
-20
View File
@@ -1,20 +0,0 @@
#include "MenuApp.h"
ColorPicker::ColorPicker()
:BColorControl(BPoint(10,10), B_CELLS_32x8,
9, "COLOR", new BMessage(MENU_COLOR), true)
{
menu_info info;
get_menu_info(&info);
SetValue(info.background_color);
}
ColorPicker::~ColorPicker()
{}
void
ColorPicker::MessageReceived(BMessage *msg){
switch(msg->what) {
}
}
+16 -11
View File
@@ -1,9 +1,14 @@
#include <Application.h>
#include <Button.h>
#include <ColorControl.h>
#include <Menu.h>
#include "MenuApp.h" #include "ColorWindow.h"
#include "msg.h"
ColorWindow::ColorWindow() ColorWindow::ColorWindow()
: BWindow(BRect(150,150,350,200), "Menu Color Scheme", B_TITLED_WINDOW, B_NOT_ZOOMABLE | B_NOT_RESIZABLE) : BWindow(BRect(150,150,350,200), "Menu Color Scheme", B_TITLED_WINDOW, B_NOT_ZOOMABLE | B_NOT_RESIZABLE)
{ {
// Set and collect the variables for revert // Set and collect the variables for revert
get_menu_info(&info); get_menu_info(&info);
get_menu_info(&revert_info); get_menu_info(&revert_info);
@@ -11,7 +16,9 @@
BView *colView = new BView(BRect(0,0,1000,100), "menuView", BView *colView = new BView(BRect(0,0,1000,100), "menuView",
B_FOLLOW_ALL_SIDES, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE); B_FOLLOW_ALL_SIDES, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE);
colorPicker = new ColorPicker(); colorPicker = new BColorControl(BPoint(10,10), B_CELLS_32x8,
9, "COLOR", new BMessage(MENU_COLOR), true);
colorPicker->SetValue(info.background_color);
colView->SetViewColor(219,219,219,255); colView->SetViewColor(219,219,219,255);
colView->AddChild(colorPicker); colView->AddChild(colorPicker);
AddChild(colView); AddChild(colView);
@@ -26,14 +33,12 @@
colView->AddChild(DefaultButton); colView->AddChild(DefaultButton);
colView->AddChild(RevertButton); colView->AddChild(RevertButton);
} }
ColorWindow::~ColorWindow()
{}
void void
ColorWindow::MessageReceived(BMessage *msg) ColorWindow::MessageReceived(BMessage *msg)
{ {
switch(msg->what) { switch(msg->what) {
case MENU_REVERT: case MENU_REVERT:
@@ -65,4 +70,4 @@
BMessage(msg); BMessage(msg);
break; break;
} }
} }
+21
View File
@@ -0,0 +1,21 @@
#ifndef __COLORWINDOW_H
#define __COLORWINDOW_H
#include <Menu.h>
#include <Window.h>
class BColorControl;
class BButton;
class ColorWindow : public BWindow {
public:
ColorWindow();
virtual void MessageReceived(BMessage *msg);
BColorControl *colorPicker;
BButton *DefaultButton;
BButton *RevertButton;
menu_info revert_info;
menu_info info;
};
#endif
+26 -29
View File
@@ -1,21 +1,22 @@
#include "FontMenu.h"
#include "msg.h"
#include "MenuApp.h" #include <stdlib.h>
#include <stdlib.h>
FontMenu::FontMenu() #include <Message.h>
#include <MenuItem.h>
FontMenu::FontMenu()
: BMenu("Font", B_ITEMS_IN_COLUMN) : BMenu("Font", B_ITEMS_IN_COLUMN)
{ {
get_menu_info(&info); get_menu_info(&info);
SetRadioMode(true); SetRadioMode(true);
GetFonts(); GetFonts();
} }
FontMenu::~FontMenu() void
{ /*nothing to clean up*/} FontMenu::GetFonts()
{
void
FontMenu::GetFonts()
{
int32 numFamilies = count_font_families(); int32 numFamilies = count_font_families();
for ( int32 i = 0; i < numFamilies; i++ ) { for ( int32 i = 0; i < numFamilies; i++ ) {
font_family *family = (font_family*)malloc(sizeof(font_family)); font_family *family = (font_family*)malloc(sizeof(font_family));
@@ -45,11 +46,11 @@
AddItem(fontFamily); AddItem(fontFamily);
} }
} }
} }
void void
FontMenu::Update() FontMenu::Update()
{ {
// it may be better to pull all menu prefs // it may be better to pull all menu prefs
// related stuff out of the FontMenu class // related stuff out of the FontMenu class
// so it can be easily reused in other apps // so it can be easily reused in other apps
@@ -62,7 +63,6 @@
SetFont(&font); SetFont(&font);
SetViewColor(info.background_color); SetViewColor(info.background_color);
InvalidateLayout(); InvalidateLayout();
// font style menus // font style menus
for (int i = 0; i < CountItems(); i++) { for (int i = 0; i < CountItems(); i++) {
ItemAt(i)->Submenu()->SetFont(&font); ItemAt(i)->Submenu()->SetFont(&font);
@@ -70,17 +70,16 @@
ClearAllMarkedItems(); ClearAllMarkedItems();
PlaceCheckMarkOnFont(info.f_family, info.f_style); PlaceCheckMarkOnFont(info.f_family, info.f_style);
} }
status_t status_t
FontMenu::PlaceCheckMarkOnFont(font_family family, font_style style) FontMenu::PlaceCheckMarkOnFont(font_family family, font_style style)
{ {
BMenuItem *fontFamilyItem; BMenuItem *fontFamilyItem;
BMenuItem *fontStyleItem; BMenuItem *fontStyleItem;
BMenu *styleMenu; BMenu *styleMenu;
fontFamilyItem = FindItem(family); fontFamilyItem = FindItem(family);
if ((fontFamilyItem != NULL) && (family != NULL)) if ((fontFamilyItem != NULL) && (family != NULL))
{ {
fontFamilyItem->SetMarked(true); fontFamilyItem->SetMarked(true);
@@ -89,7 +88,6 @@
if ((styleMenu != NULL) && (style != NULL)) if ((styleMenu != NULL) && (style != NULL))
{ {
fontStyleItem = styleMenu->FindItem(style); fontStyleItem = styleMenu->FindItem(style);
if (fontStyleItem != NULL) if (fontStyleItem != NULL)
{ {
fontStyleItem->SetMarked(true); fontStyleItem->SetMarked(true);
@@ -102,13 +100,13 @@
else else
return B_ERROR; return B_ERROR;
return B_OK; return B_OK;
} }
void
FontMenu::ClearAllMarkedItems() void
{ FontMenu::ClearAllMarkedItems()
{
// we need to clear all menuitems and submenuitems // we need to clear all menuitems and submenuitems
for (int i = 0; i < CountItems(); i++) { for (int i = 0; i < CountItems(); i++) {
ItemAt(i)->SetMarked(false); ItemAt(i)->SetMarked(false);
@@ -118,5 +116,4 @@
submenu->ItemAt(j)->SetMarked(false); submenu->ItemAt(j)->SetMarked(false);
} }
} }
}
}
+37
View File
@@ -0,0 +1,37 @@
#ifndef __FONTMENU_H
#define __FONTMENU_H
#include <Menu.h>
class FontSizeMenu : public BMenu {
public:
FontSizeMenu();
virtual void Update();
private:
menu_info info;
BMenuItem *fontSizeNine;
BMenuItem *fontSizeTen;
BMenuItem *fontSizeEleven;
BMenuItem *fontSizeTwelve;
BMenuItem *fontSizeFourteen;
BMenuItem *fontSizeEighteen;
};
class FontMenu : public BMenu {
public:
FontMenu();
virtual void GetFonts();
virtual void Update();
virtual status_t PlaceCheckMarkOnFont(font_family family, font_style style);
virtual void ClearAllMarkedItems();
private:
menu_info info;
BMenuItem *fontFamily;
BMenu *fontStyleMenu;
BMenuItem *fontStyleItem;
};
#endif
+12 -10
View File
@@ -1,9 +1,13 @@
#include "FontMenu.h"
#include "msg.h"
#include "MenuApp.h" #include <Message.h>
#include <MenuItem.h>
#include <Window.h>
FontSizeMenu::FontSizeMenu() FontSizeMenu::FontSizeMenu()
:BMenu("Font Size", B_ITEMS_IN_COLUMN) :BMenu("Font Size", B_ITEMS_IN_COLUMN)
{ {
get_menu_info(&info); get_menu_info(&info);
BMessage *msg = new BMessage(MENU_FONT_SIZE); BMessage *msg = new BMessage(MENU_FONT_SIZE);
@@ -44,14 +48,12 @@
SetTargetForItems(Window()); SetTargetForItems(Window());
SetRadioMode(true); SetRadioMode(true);
} }
FontSizeMenu::~FontSizeMenu()
{ }
void void
FontSizeMenu::Update() FontSizeMenu::Update()
{ {
get_menu_info(&info); get_menu_info(&info);
BFont font; BFont font;
@@ -66,4 +68,4 @@
InvalidateLayout(); InvalidateLayout();
Invalidate(); Invalidate();
SetEnabled(true); SetEnabled(true);
} }
-1
View File
@@ -2,7 +2,6 @@ SubDir HAIKU_TOP src preferences menu ;
Preference Menu : Preference Menu :
BitmapMenuItem.cpp BitmapMenuItem.cpp
ColorPicker.cpp
ColorWindow.cpp ColorWindow.cpp
FontMenu.cpp FontMenu.cpp
FontSizeMenu.cpp FontSizeMenu.cpp
+24 -27
View File
@@ -1,40 +1,28 @@
#include "MenuApp.h"
#include "MenuWindow.h"
#include "msg.h"
#include "MenuApp.h" MenuApp::MenuApp()
MenuApp::MenuApp()
: BApplication("application/x-vnd.Be-GGUI") : BApplication("application/x-vnd.Be-GGUI")
{ {
get_menu_info(&info); get_menu_info(&info);
menuWindow = new MenuWindow(); menuWindow = new MenuWindow();
Update(); Update();
menuWindow->Show(); menuWindow->Show();
} }
MenuApp::~MenuApp()
{/*nothing to clean up*/}
bool void
MenuApp::QuitRequested() MenuApp::Update()
{ {
return true;
}
void
MenuApp::Update()
{
menuWindow->Update(); menuWindow->Update();
} }
int main()
{
new MenuApp();
be_app -> Run();
delete be_app;
}
void void
MenuApp::MessageReceived(BMessage *msg){ MenuApp::MessageReceived(BMessage *msg)
{
switch(msg->what) { switch(msg->what) {
//others //others
@@ -49,7 +37,16 @@
break; break;
default: default:
BMessage(msg); BApplication::MessageReceived(msg);
break; break;
} }
} }
int main()
{
new MenuApp();
be_app->Run();
delete be_app;
}
+10 -123
View File
@@ -1,134 +1,21 @@
#include <Application.h> #ifndef __MENU_APP_H
#include <Button.h> #define __MENU_APP_H
#include <ColorControl.h>
#include <Window.h>
#include <Box.h>
#include <Alert.h>
#include <Menu.h>
#include <MenuBar.h>
#include <MenuItem.h>
#include "BitmapMenuItem.h" #include <Application.h>
#include <Menu.h>
#ifndef MENU_H class MenuWindow;
#define MENU_H class MenuApp : public BApplication {
public:
#include "msg.h"
class FontSizeMenu : public BMenu {
public:
FontSizeMenu();
virtual ~FontSizeMenu();
virtual void Update();
menu_info info;
BMenuItem *fontSizeNine;
BMenuItem *fontSizeTen;
BMenuItem *fontSizeEleven;
BMenuItem *fontSizeTwelve;
BMenuItem *fontSizeFourteen;
BMenuItem *fontSizeEighteen;
};
class FontMenu : public BMenu {
public:
FontMenu();
virtual ~FontMenu();
virtual void GetFonts();
virtual void Update();
virtual status_t PlaceCheckMarkOnFont(font_family family, font_style style);
virtual void ClearAllMarkedItems();
menu_info info;
BMenuItem *fontFamily;
BMenu *fontStyleMenu;
BMenuItem *fontStyleItem;
};
class MenuBar : public BMenuBar {
public:
MenuBar();
void set_menu();
void build_menu();
virtual void Update();
virtual void FrameResized(float width, float height);
BRect menu_rect;
BRect rect;
menu_info info;
//seperator submenu
BMenu *separatorStyleMenu;
BMenuItem *separatorStyleZero;
BMenuItem *separatorStyleOne;
BMenuItem *separatorStyleTwo;
//others
FontMenu *fontMenu;
FontSizeMenu *fontSizeMenu;
BMenuItem *clickToOpenItem;
BMenuItem *alwaysShowTriggersItem;
BMenuItem *colorSchemeItem;
BMenuItem *separatorStyleItem;
BMenuItem *ctlAsShortcutItem;
BMenuItem *altAsShortcutItem;
};
class ColorPicker : public BColorControl {
public:
ColorPicker();
virtual ~ColorPicker();
virtual void MessageReceived(BMessage *msg);
};
class ColorWindow : public BWindow {
public:
ColorWindow();
virtual ~ColorWindow();
virtual void MessageReceived(BMessage *msg);
ColorPicker *colorPicker;
BButton *DefaultButton;
BButton *RevertButton;
menu_info revert_info;
menu_info info;
};
class MenuWindow : public BWindow {
public:
MenuWindow();
virtual ~MenuWindow();
virtual void MessageReceived(BMessage *msg);
virtual bool QuitRequested();
virtual void Update();
void Defaults();
bool revert;
ColorWindow *colorWindow;
BMenuItem *toggleItem;
menu_info info;
menu_info revert_info;
BRect rect;
BMenu *menu;
MenuBar *menuBar;
BBox *menuView;
BButton *revertButton;
BButton *defaultButton;
};
class MenuApp : public BApplication {
public:
MenuApp(); MenuApp();
virtual ~MenuApp();
virtual void Update(); virtual void Update();
virtual void MessageReceived(BMessage *msg); virtual void MessageReceived(BMessage *msg);
virtual bool QuitRequested();
//main private:
MenuWindow *menuWindow; MenuWindow *menuWindow;
BRect rect; BRect rect;
menu_info info; menu_info info;
BMenu *menu; BMenu *menu;
}; };
#endif #endif
+31 -28
View File
@@ -1,24 +1,28 @@
#include "MenuApp.h" #include "BitmapMenuItem.h"
#include "FontMenu.h"
#include "MenuBar.h"
#include "msg.h"
#include <Application.h> #include <Application.h>
#include <Resources.h> #include <Resources.h>
#include <TranslationUtils.h> #include <TranslationUtils.h>
#include <Window.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
MenuBar::MenuBar() MenuBar::MenuBar()
:BMenuBar(BRect(40,10,10,10), "menu", B_FOLLOW_TOP|B_FRAME_EVENTS, B_ITEMS_IN_COLUMN, true) :BMenuBar(BRect(40,10,10,10), "menu", B_FOLLOW_TOP|B_FRAME_EVENTS, B_ITEMS_IN_COLUMN, true)
{ {
get_menu_info(&info); get_menu_info(&info);
build_menu(); build_menu();
set_menu(); set_menu();
} }
void void
MenuBar::build_menu() MenuBar::build_menu()
{ {
// font and font size menus // font and font size menus
fontMenu = new FontMenu(); fontMenu = new FontMenu();
fontSizeMenu = new FontSizeMenu(); fontSizeMenu = new FontSizeMenu();
@@ -72,11 +76,11 @@
AddItem(ctlAsShortcutItem); AddItem(ctlAsShortcutItem);
AddItem(altAsShortcutItem); AddItem(altAsShortcutItem);
SetTargetForItems(Window()); SetTargetForItems(Window());
} }
void void
MenuBar::set_menu() MenuBar::set_menu()
{ {
key_map *keys; key_map *keys;
char *chars; char *chars;
bool altAsShortcut; bool altAsShortcut;
@@ -85,7 +89,6 @@
get_menu_info(&info); get_menu_info(&info);
alwaysShowTriggersItem->SetMarked(info.triggers_always_shown); alwaysShowTriggersItem->SetMarked(info.triggers_always_shown);
clickToOpenItem->SetMarked(info.click_to_open); clickToOpenItem->SetMarked(info.click_to_open);
alwaysShowTriggersItem->SetEnabled(info.click_to_open); alwaysShowTriggersItem->SetEnabled(info.click_to_open);
@@ -97,18 +100,17 @@
free(chars); free(chars);
free(keys); free(keys);
} }
void
MenuBar::Update() void
{ MenuBar::Update()
{
// get up-to-date menu info // get up-to-date menu info
get_menu_info(&info); get_menu_info(&info);
// update submenus // update submenus
fontMenu->Update(); fontMenu->Update();
fontSizeMenu->Update(); fontSizeMenu->Update();
// this needs to be updated in case the Defaults // this needs to be updated in case the Defaults
// were requested. // were requested.
if (info.separator == 0) if (info.separator == 0)
@@ -117,7 +119,6 @@
separatorStyleOne->SetMarked(true); separatorStyleOne->SetMarked(true);
else if (info.separator == 2) else if (info.separator == 2)
separatorStyleTwo->SetMarked(true); separatorStyleTwo->SetMarked(true);
set_menu(); set_menu();
BFont font; BFont font;
@@ -130,9 +131,11 @@
// force the menu to redraw // force the menu to redraw
InvalidateLayout(); InvalidateLayout();
} }
void MenuBar::FrameResized(float width, float height)
{ void
MenuBar::FrameResized(float width, float height)
{
Window()->PostMessage(UPDATE_WINDOW); Window()->PostMessage(UPDATE_WINDOW);
} }
+39
View File
@@ -0,0 +1,39 @@
#ifndef __BARMENU_H
#define __BARMENU_H
#include <MenuBar.h>
class BMenuItem;
class FontMenu;
class FontSizeMenu;
class MenuBar : public BMenuBar {
public:
MenuBar();
void set_menu();
void build_menu();
virtual void Update();
virtual void FrameResized(float width, float height);
BRect menu_rect;
BRect rect;
menu_info info;
//seperator submenu
BMenu *separatorStyleMenu;
BMenuItem *separatorStyleZero;
BMenuItem *separatorStyleOne;
BMenuItem *separatorStyleTwo;
//others
FontMenu *fontMenu;
FontSizeMenu *fontSizeMenu;
BMenuItem *clickToOpenItem;
BMenuItem *alwaysShowTriggersItem;
BMenuItem *colorSchemeItem;
BMenuItem *separatorStyleItem;
BMenuItem *ctlAsShortcutItem;
BMenuItem *altAsShortcutItem;
};
#endif
+37 -28
View File
@@ -1,18 +1,27 @@
#include "MenuApp.h" #include "ColorWindow.h"
#include <stdio.h> #include "MenuApp.h"
#include <string.h> #include "MenuBar.h"
#include <Roster.h> #include "MenuWindow.h"
#include "msg.h"
MenuWindow::MenuWindow() #include <stdio.h>
#include <string.h>
#include <Alert.h>
#include <Box.h>
#include <Button.h>
#include <MenuItem.h>
#include <Roster.h>
MenuWindow::MenuWindow()
: BWindow(rect, "Menu", B_TITLED_WINDOW, B_NOT_ZOOMABLE | B_NOT_RESIZABLE) : BWindow(rect, "Menu", B_TITLED_WINDOW, B_NOT_ZOOMABLE | B_NOT_RESIZABLE)
{ {
get_menu_info(&revert_info); get_menu_info(&revert_info);
get_menu_info(&info); get_menu_info(&info);
revert = false; revert = false;
MoveTo((rect.left += 100),(rect.top += 100)); MoveTo((rect.left += 100),(rect.top += 100));
menuView = new BBox(Bounds(), "menuView", B_FOLLOW_ALL_SIDES, menuView = new BBox(Bounds(), "menuView", B_FOLLOW_ALL_SIDES,
B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, B_PLAIN_BORDER); B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, B_PLAIN_BORDER);
AddChild(menuView); AddChild(menuView);
@@ -32,14 +41,12 @@
Update(); Update();
} }
MenuWindow::~MenuWindow()
{/*nothing to delete;*/}
void void
MenuWindow::MessageReceived(BMessage *msg) MenuWindow::MessageReceived(BMessage *msg)
{ {
switch(msg->what) { switch(msg->what) {
case MENU_REVERT: case MENU_REVERT:
@@ -119,7 +126,6 @@
set_modifier_key(B_RIGHT_COMMAND_KEY, 0x60); set_modifier_key(B_RIGHT_COMMAND_KEY, 0x60);
set_modifier_key(B_LEFT_CONTROL_KEY, 0x5d); set_modifier_key(B_LEFT_CONTROL_KEY, 0x5d);
set_modifier_key(B_RIGHT_OPTION_KEY, 0x5f); set_modifier_key(B_RIGHT_OPTION_KEY, 0x5f);
be_roster->Broadcast(new BMessage(B_MODIFIERS_CHANGED)); be_roster->Broadcast(new BMessage(B_MODIFIERS_CHANGED));
Update(); Update();
break; break;
@@ -152,18 +158,20 @@
BMessage(msg); BMessage(msg);
break; break;
} }
} }
bool
MenuWindow::QuitRequested() bool
{ MenuWindow::QuitRequested()
{
be_app->PostMessage(B_QUIT_REQUESTED); be_app->PostMessage(B_QUIT_REQUESTED);
return true; return BWindow::QuitRequested();
} }
void
MenuWindow::Update() void
{ MenuWindow::Update()
{
revertButton->SetEnabled(revert); revertButton->SetEnabled(revert);
// alert the rest of the application to update // alert the rest of the application to update
@@ -171,11 +179,12 @@
// resize the window according to the size of menuBar // resize the window according to the size of menuBar
ResizeTo((menuBar->Frame().right + 35), (menuBar->Frame().bottom + 45)); ResizeTo((menuBar->Frame().right + 35), (menuBar->Frame().bottom + 45));
} }
void
MenuWindow::Defaults() void
{ MenuWindow::Defaults()
{
// to set the default color. this should be changed // to set the default color. this should be changed
// to the system color for system wide compatability. // to the system color for system wide compatability.
rgb_color color; rgb_color color;
@@ -197,4 +206,4 @@
info.triggers_always_shown = false; info.triggers_always_shown = false;
set_menu_info(&info); set_menu_info(&info);
Update(); Update();
} }
+34
View File
@@ -0,0 +1,34 @@
#ifndef __MENU_WINDOW_H
#define __MENU_WINDOW_H
#include <Window.h>
class ColorWindow;
class BMenuItem;
class BMenu;
class BBox;
class BButton;
class MenuBar;
class MenuWindow : public BWindow {
public:
MenuWindow();
virtual void MessageReceived(BMessage *msg);
virtual bool QuitRequested();
virtual void Update();
void Defaults();
private:
bool revert;
ColorWindow *colorWindow;
BMenuItem *toggleItem;
menu_info info;
menu_info revert_info;
BRect rect;
BMenu *menu;
MenuBar *menuBar;
BBox *menuView;
BButton *revertButton;
BButton *defaultButton;
};
#endif