*** empty log message ***
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3540 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+250
-88
@@ -7,6 +7,7 @@
|
|||||||
#include <String.h>
|
#include <String.h>
|
||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
|
#include <Bitmap.h>
|
||||||
|
|
||||||
// Project Includes ------------------------------------------------------------
|
// Project Includes ------------------------------------------------------------
|
||||||
|
|
||||||
@@ -19,58 +20,100 @@
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
BMenuItem::BMenuItem(const char *label, BMessage *message, char shortcut,
|
BMenuItem::BMenuItem(const char *label, BMessage *message, char shortcut,
|
||||||
uint32 modifiers)
|
uint32 modifiers)
|
||||||
: BInvoker(message, NULL),
|
|
||||||
fSubmenu(NULL),
|
|
||||||
fWindow(NULL),
|
|
||||||
fSuper(NULL),
|
|
||||||
fModifiers(modifiers),
|
|
||||||
fCachedWidth(0.0f),
|
|
||||||
fTriggerIndex(0),
|
|
||||||
fUserTrigger(0),
|
|
||||||
fSysTrigger(0),
|
|
||||||
fShortcutChar(shortcut),
|
|
||||||
fMark(false),
|
|
||||||
fEnabled(true),
|
|
||||||
fSelected(false)
|
|
||||||
{
|
{
|
||||||
|
InitData();
|
||||||
fLabel = strdup(label);
|
fLabel = strdup(label);
|
||||||
|
SetMessage(message);
|
||||||
|
|
||||||
|
fShortcutChar = shortcut;
|
||||||
|
|
||||||
|
if (shortcut != 0)
|
||||||
|
fModifiers = modifiers | B_COMMAND_KEY;
|
||||||
|
else
|
||||||
|
fModifiers = 0;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
BMenuItem::BMenuItem(BMenu *menu, BMessage *message)
|
BMenuItem::BMenuItem(BMenu *menu, BMessage *message)
|
||||||
: BInvoker(message, NULL),
|
|
||||||
fSubmenu(menu),
|
|
||||||
fWindow(NULL),
|
|
||||||
fSuper(NULL),
|
|
||||||
fModifiers(0),
|
|
||||||
fCachedWidth(0.0f),
|
|
||||||
fTriggerIndex(0),
|
|
||||||
fUserTrigger(0),
|
|
||||||
fSysTrigger(0),
|
|
||||||
fShortcutChar(0),
|
|
||||||
fMark(false),
|
|
||||||
fEnabled(true),
|
|
||||||
fSelected(false)
|
|
||||||
{
|
{
|
||||||
fLabel = strdup(menu->Name());
|
InitData();
|
||||||
|
SetMessage(message);
|
||||||
fSubmenu->fSuperitem = this;
|
InitMenuData(menu);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
BMenuItem::BMenuItem(BMessage *data)
|
BMenuItem::BMenuItem(BMessage *data)
|
||||||
{
|
{
|
||||||
|
InitData();
|
||||||
|
|
||||||
|
if (data->HasString("_label"))
|
||||||
|
{
|
||||||
|
const char *string;
|
||||||
|
|
||||||
|
data->FindString("_label", &string);
|
||||||
|
SetLabel(string);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool disable;
|
||||||
|
if (data->FindBool("_disable", &disable) == B_OK)
|
||||||
|
SetEnabled(!disable);
|
||||||
|
|
||||||
|
bool marked;
|
||||||
|
if (data->FindBool("_marked", &marked) == B_OK)
|
||||||
|
SetMarked(marked);
|
||||||
|
|
||||||
|
if (data->HasInt32("_user_trig"))
|
||||||
|
{
|
||||||
|
int32 user_trig;
|
||||||
|
|
||||||
|
data->FindInt32("_user_trig", &user_trig);
|
||||||
|
|
||||||
|
SetTrigger(user_trig);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data->HasInt32("_shortcut"))
|
||||||
|
{
|
||||||
|
int32 shortcut, mods;
|
||||||
|
|
||||||
|
data->FindInt32("_shortcut", &shortcut);
|
||||||
|
data->FindInt32("_mods", &mods);
|
||||||
|
|
||||||
|
SetShortcut(shortcut, mods);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data->HasMessage("_msg"))
|
||||||
|
{
|
||||||
|
BMessage *msg = new BMessage;
|
||||||
|
|
||||||
|
data->FindMessage("_msg", msg);
|
||||||
|
SetMessage(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
BMessage subMessage;
|
||||||
|
|
||||||
|
if (data->FindMessage("_submenu", &subMessage) == B_OK)
|
||||||
|
{
|
||||||
|
BArchivable *object = instantiate_object(&subMessage);
|
||||||
|
|
||||||
|
if (object)
|
||||||
|
{
|
||||||
|
BMenu *menu = dynamic_cast<BMenu*>(object);
|
||||||
|
|
||||||
|
if (menu)
|
||||||
|
InitMenuData(menu);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
BArchivable *BMenuItem::Instantiate(BMessage *data)
|
BArchivable *BMenuItem::Instantiate(BMessage *data)
|
||||||
{
|
{
|
||||||
if (validate_instantiation(data, "BMenuItem"))
|
if (validate_instantiation(data, "BMenuItem"))
|
||||||
return new BMenuItem(data);
|
return new BMenuItem(data);
|
||||||
|
else
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
status_t BMenuItem::Archive(BMessage *data, bool deep) const
|
status_t BMenuItem::Archive(BMessage *data, bool deep) const
|
||||||
{
|
{
|
||||||
if (Label())
|
if (fLabel)
|
||||||
data->AddString("_label", Label());
|
data->AddString("_label", Label());
|
||||||
|
|
||||||
if (!IsEnabled())
|
if (!IsEnabled())
|
||||||
@@ -82,7 +125,7 @@ status_t BMenuItem::Archive(BMessage *data, bool deep) const
|
|||||||
if (fUserTrigger)
|
if (fUserTrigger)
|
||||||
data->AddInt32("_user_trig", fUserTrigger);
|
data->AddInt32("_user_trig", fUserTrigger);
|
||||||
|
|
||||||
if (fShortcutChar && fModifiers)
|
if (fShortcutChar)
|
||||||
{
|
{
|
||||||
data->AddInt32("_shortcut", fShortcutChar);
|
data->AddInt32("_shortcut", fShortcutChar);
|
||||||
data->AddInt32("_mods", fModifiers);
|
data->AddInt32("_mods", fModifiers);
|
||||||
@@ -91,10 +134,11 @@ status_t BMenuItem::Archive(BMessage *data, bool deep) const
|
|||||||
if (Message())
|
if (Message())
|
||||||
data->AddMessage("_msg", Message());
|
data->AddMessage("_msg", Message());
|
||||||
|
|
||||||
if (deep && Submenu())
|
if (deep && fSubmenu)
|
||||||
{
|
{
|
||||||
BMessage submenu;
|
BMessage submenu;
|
||||||
Submenu()->Archive(&submenu);
|
|
||||||
|
if (fSubmenu->Archive(&submenu, true) == B_OK)
|
||||||
data->AddMessage("_submenu", &submenu);
|
data->AddMessage("_submenu", &submenu);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,20 +159,36 @@ void BMenuItem::SetLabel(const char *string)
|
|||||||
if (fLabel)
|
if (fLabel)
|
||||||
free(fLabel);
|
free(fLabel);
|
||||||
|
|
||||||
|
if (string)
|
||||||
fLabel = strdup(string);
|
fLabel = strdup(string);
|
||||||
|
else
|
||||||
|
string = NULL;
|
||||||
|
|
||||||
Menu()->InvalidateLayout();
|
if (fSuper)
|
||||||
|
{
|
||||||
|
fSuper->InvalidateLayout();
|
||||||
|
|
||||||
|
if (fSuper->LockLooper())
|
||||||
|
{
|
||||||
|
fSuper->Invalidate();
|
||||||
|
fSuper->UnlockLooper();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BMenuItem::SetEnabled(bool state)
|
void BMenuItem::SetEnabled(bool state)
|
||||||
{
|
{
|
||||||
if (Menu()->IsEnabled() == false)
|
if (fSubmenu)
|
||||||
return;
|
fSubmenu->SetEnabled(state);
|
||||||
|
|
||||||
fEnabled = state;
|
fEnabled = state;
|
||||||
|
BMenu *menu = Menu();
|
||||||
|
|
||||||
if (Submenu())
|
if (menu && menu->LockLooper())
|
||||||
Submenu()->SetEnabled(state);
|
{
|
||||||
|
menu->Invalidate(fBounds);
|
||||||
|
menu->UnlockLooper();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BMenuItem::SetMarked(bool state)
|
void BMenuItem::SetMarked(bool state)
|
||||||
@@ -142,12 +202,41 @@ void BMenuItem::SetMarked(bool state)
|
|||||||
void BMenuItem::SetTrigger(char ch)
|
void BMenuItem::SetTrigger(char ch)
|
||||||
{
|
{
|
||||||
fUserTrigger = ch;
|
fUserTrigger = ch;
|
||||||
|
|
||||||
|
if (strchr(fLabel, ch) != 0)
|
||||||
|
fSysTrigger = ch;
|
||||||
|
else
|
||||||
|
fSysTrigger = -1;
|
||||||
|
|
||||||
|
if (fSuper)
|
||||||
|
fSuper->InvalidateLayout();
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BMenuItem::SetShortcut(char ch, uint32 modifiers)
|
void BMenuItem::SetShortcut(char ch, uint32 modifiers)
|
||||||
{
|
{
|
||||||
|
if (fShortcutChar != 0 && (fModifiers & B_COMMAND_KEY) && fWindow)
|
||||||
|
fWindow->RemoveShortcut(fShortcutChar, fModifiers);
|
||||||
|
|
||||||
fShortcutChar = ch;
|
fShortcutChar = ch;
|
||||||
fModifiers = modifiers;
|
|
||||||
|
if (ch != 0)
|
||||||
|
fModifiers = modifiers | B_COMMAND_KEY;
|
||||||
|
else
|
||||||
|
fModifiers = 0;
|
||||||
|
|
||||||
|
if (fShortcutChar != 0 && (fModifiers & B_COMMAND_KEY) && fWindow)
|
||||||
|
fWindow->AddShortcut(fShortcutChar, fModifiers, this);
|
||||||
|
|
||||||
|
if (fSuper)
|
||||||
|
{
|
||||||
|
fSuper->InvalidateLayout();
|
||||||
|
|
||||||
|
if (fSuper->LockLooper())
|
||||||
|
{
|
||||||
|
fSuper->Invalidate();
|
||||||
|
fSuper->UnlockLooper();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
const char *BMenuItem::Label() const
|
const char *BMenuItem::Label() const
|
||||||
@@ -157,7 +246,13 @@ const char *BMenuItem::Label() const
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
bool BMenuItem::IsEnabled() const
|
bool BMenuItem::IsEnabled() const
|
||||||
{
|
{
|
||||||
return fEnabled;
|
if (fSubmenu)
|
||||||
|
return fSubmenu->IsEnabled();
|
||||||
|
|
||||||
|
if (!fEnabled)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return fSuper ? fSuper->IsEnabled() : true;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
bool BMenuItem::IsMarked() const
|
bool BMenuItem::IsMarked() const
|
||||||
@@ -167,10 +262,7 @@ bool BMenuItem::IsMarked() const
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
char BMenuItem::Trigger() const
|
char BMenuItem::Trigger() const
|
||||||
{
|
{
|
||||||
if (fUserTrigger)
|
|
||||||
return fUserTrigger;
|
return fUserTrigger;
|
||||||
else
|
|
||||||
return fSysTrigger;
|
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
char BMenuItem::Shortcut(uint32 *modifiers) const
|
char BMenuItem::Shortcut(uint32 *modifiers) const
|
||||||
@@ -198,13 +290,12 @@ BRect BMenuItem::Frame() const
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BMenuItem::GetContentSize(float *width, float *height)
|
void BMenuItem::GetContentSize(float *width, float *height)
|
||||||
{
|
{
|
||||||
BMenu *menu = Menu();
|
fSuper->CacheFontInfo();
|
||||||
|
|
||||||
if (menu->fFontHeight == -1)
|
fCachedWidth = fSuper->StringWidth(fLabel);
|
||||||
menu->CacheFontInfo();
|
|
||||||
|
|
||||||
*width = (float)ceil(menu->StringWidth(fLabel));
|
*width = (float)ceil(fCachedWidth);
|
||||||
*height = menu->fFontHeight;
|
*height = fSuper->fFontHeight;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BMenuItem::TruncateLabel(float maxWidth, char *newLabel)
|
void BMenuItem::TruncateLabel(float maxWidth, char *newLabel)
|
||||||
@@ -213,12 +304,17 @@ void BMenuItem::TruncateLabel(float maxWidth, char *newLabel)
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BMenuItem::DrawContent()
|
void BMenuItem::DrawContent()
|
||||||
{
|
{
|
||||||
|
fSuper->MovePenBy(0, fSuper->fAscent);
|
||||||
fSuper->DrawString(fLabel);
|
fSuper->DrawString(fLabel);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BMenuItem::Draw()
|
void BMenuItem::Draw()
|
||||||
{
|
{
|
||||||
if (IsEnabled() && fSelected)
|
bool enabled = IsEnabled();
|
||||||
|
|
||||||
|
fSuper->CacheFontInfo();
|
||||||
|
|
||||||
|
if (IsSelected() && (enabled || Submenu())/* && fSuper->fRedrawAfterSticky*/)
|
||||||
{
|
{
|
||||||
fSuper->SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR),
|
fSuper->SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR),
|
||||||
B_DARKEN_2_TINT));
|
B_DARKEN_2_TINT));
|
||||||
@@ -227,32 +323,34 @@ void BMenuItem::Draw()
|
|||||||
fSuper->FillRect(Frame());
|
fSuper->FillRect(Frame());
|
||||||
}
|
}
|
||||||
|
|
||||||
BPoint pt = ContentLocation();
|
|
||||||
|
|
||||||
fSuper->MovePenTo(pt.x, pt.y + Menu()->fAscent);
|
|
||||||
if (IsEnabled())
|
if (IsEnabled())
|
||||||
fSuper->SetHighColor(ui_color(B_MENU_ITEM_TEXT_COLOR));
|
fSuper->SetHighColor(ui_color(B_MENU_ITEM_TEXT_COLOR));
|
||||||
|
else if (IsSelected())
|
||||||
|
fSuper->SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR),
|
||||||
|
B_LIGHTEN_1_TINT));
|
||||||
else
|
else
|
||||||
fSuper->SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR),
|
fSuper->SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR),
|
||||||
B_DISABLED_LABEL_TINT));
|
B_DISABLED_LABEL_TINT));
|
||||||
|
|
||||||
|
fSuper->MovePenTo(ContentLocation());
|
||||||
DrawContent();
|
DrawContent();
|
||||||
|
|
||||||
if (Menu()->Layout() == B_ITEMS_IN_COLUMN)
|
if (fSuper->Layout() == B_ITEMS_IN_COLUMN)
|
||||||
{
|
{
|
||||||
if (IsMarked())
|
if (IsMarked())
|
||||||
DrawMarkSymbol();
|
DrawMarkSymbol();
|
||||||
|
|
||||||
|
if (fShortcutChar)
|
||||||
|
DrawShortcutSymbol();
|
||||||
|
|
||||||
if (Submenu())
|
if (Submenu())
|
||||||
DrawSubmenuSymbol();
|
DrawSubmenuSymbol();
|
||||||
else if (fShortcutChar)
|
|
||||||
DrawShortcutSymbol();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BMenuItem::Highlight(bool flag)
|
void BMenuItem::Highlight(bool flag)
|
||||||
{
|
{
|
||||||
//Menu()->InvertRect(Frame());
|
Menu()->Draw(Frame());
|
||||||
Menu()->Invalidate(Frame());
|
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
bool BMenuItem::IsSelected() const
|
bool BMenuItem::IsSelected() const
|
||||||
@@ -260,11 +358,8 @@ bool BMenuItem::IsSelected() const
|
|||||||
return fSelected;
|
return fSelected;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
BPoint BMenuItem::ContentLocation () const
|
BPoint BMenuItem::ContentLocation() const
|
||||||
{
|
{
|
||||||
if (!Menu())
|
|
||||||
return BPoint();
|
|
||||||
|
|
||||||
return BPoint(fBounds.left + Menu()->fPad.left,
|
return BPoint(fBounds.left + Menu()->fPad.left,
|
||||||
fBounds.top + Menu()->fPad.top);
|
fBounds.top + Menu()->fPad.top);
|
||||||
}
|
}
|
||||||
@@ -285,61 +380,129 @@ BMenuItem &BMenuItem::operator=(const BMenuItem &)
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BMenuItem::InitData()
|
void BMenuItem::InitData()
|
||||||
{
|
{
|
||||||
|
fLabel = NULL;
|
||||||
|
fSubmenu = 0;
|
||||||
|
fWindow = NULL;
|
||||||
|
fSuper = NULL;
|
||||||
|
fModifiers = 0;
|
||||||
|
fCachedWidth = 0;
|
||||||
|
fTriggerIndex = -1;
|
||||||
|
fUserTrigger = 0;
|
||||||
|
fSysTrigger = 0;
|
||||||
|
fShortcutChar = 0;
|
||||||
|
fMark = false;
|
||||||
|
fEnabled = true;
|
||||||
|
fSelected = false;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BMenuItem::InitMenuData(BMenu *menu)
|
void BMenuItem::InitMenuData(BMenu *menu)
|
||||||
{
|
{
|
||||||
|
fSubmenu = menu;
|
||||||
|
fSubmenu->fSuperitem = this;
|
||||||
|
|
||||||
|
BMenuItem *item;
|
||||||
|
|
||||||
|
if (menu->IsRadioMode() && menu->IsLabelFromMarked() &&
|
||||||
|
(item = menu->FindMarked()) != NULL)
|
||||||
|
SetLabel(item->Label());
|
||||||
|
else
|
||||||
|
SetLabel(menu->Name());
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BMenuItem::Install(BWindow *window)
|
void BMenuItem::Install(BWindow *window)
|
||||||
{
|
{
|
||||||
if (Submenu())
|
if (fSubmenu)
|
||||||
Submenu()->Install(window);
|
fSubmenu->Install(window);
|
||||||
|
|
||||||
char shortcut;
|
fWindow = window;
|
||||||
uint32 modifiers;
|
|
||||||
if (shortcut = Shortcut(&modifiers))
|
|
||||||
window->AddShortcut(shortcut, modifiers, this);
|
|
||||||
|
|
||||||
if (Target() == NULL)
|
if (fShortcutChar != 0 && (fModifiers & B_COMMAND_KEY) && fWindow)
|
||||||
|
window->AddShortcut(fShortcutChar, fModifiers, this);
|
||||||
|
|
||||||
|
if (!Messenger().IsValid())
|
||||||
SetTarget(window);
|
SetTarget(window);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
status_t BMenuItem::Invoke(BMessage *message)
|
status_t BMenuItem::Invoke(BMessage *message)
|
||||||
{
|
{
|
||||||
if (IsEnabled())
|
if (!IsEnabled())
|
||||||
|
return B_ERROR;
|
||||||
|
|
||||||
|
if (fSuper->IsRadioMode())
|
||||||
|
SetMarked(true);
|
||||||
|
|
||||||
|
bool notify = false;
|
||||||
|
uint32 kind = InvokeKind(¬ify);
|
||||||
|
|
||||||
|
BMessage clone(kind);
|
||||||
|
status_t err = B_BAD_VALUE;
|
||||||
|
|
||||||
|
if (!message && !notify)
|
||||||
|
message = Message();
|
||||||
|
|
||||||
|
if (!message)
|
||||||
{
|
{
|
||||||
BMessage msg;
|
if (!fSuper->IsWatched())
|
||||||
|
return err;
|
||||||
if (message)
|
|
||||||
msg = *message;
|
|
||||||
else if (Message())
|
|
||||||
msg = *Message();
|
|
||||||
else
|
|
||||||
return B_OK;
|
|
||||||
|
|
||||||
msg.AddInt64("when", system_time()); // TODO
|
|
||||||
msg.AddPointer("source", this);
|
|
||||||
msg.AddInt32("index", Menu()->IndexOf(this));
|
|
||||||
|
|
||||||
return BInvoker::Invoke(&msg);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return B_OK;
|
clone = *message;
|
||||||
|
|
||||||
|
clone.AddInt32("index", Menu()->IndexOf(this));
|
||||||
|
clone.AddInt64("when", (int64)system_time());
|
||||||
|
clone.AddPointer("source", this);
|
||||||
|
clone.AddMessenger("be:sender", BMessenger(fSuper));
|
||||||
|
|
||||||
|
if (message)
|
||||||
|
err = BInvoker::Invoke(&clone);
|
||||||
|
|
||||||
|
// TODO: assynchronous messaging
|
||||||
|
// SendNotices(kind, &clone);
|
||||||
|
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BMenuItem::Uninstall()
|
void BMenuItem::Uninstall()
|
||||||
{
|
{
|
||||||
|
if (fSubmenu)
|
||||||
|
fSubmenu->Uninstall();
|
||||||
|
|
||||||
|
if (Target() == fWindow)
|
||||||
|
SetTarget(BMessenger());
|
||||||
|
|
||||||
|
if (0x6c != 0 && fModifiers & B_COMMAND_KEY && fWindow)
|
||||||
|
fWindow->RemoveShortcut(fShortcutChar, fModifiers);
|
||||||
|
|
||||||
|
fWindow = NULL;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BMenuItem::SetSuper(BMenu *super)
|
void BMenuItem::SetSuper(BMenu *super)
|
||||||
{
|
{
|
||||||
|
if (fSuper != NULL && super != NULL)
|
||||||
|
{
|
||||||
|
debugger("Error - can't add menu or menu item to more than 1 container (either menu or menubar).");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
fSuper = super;
|
fSuper = super;
|
||||||
|
|
||||||
|
if (fSubmenu)
|
||||||
|
fSubmenu->fSuper = super;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BMenuItem::Select(bool on)
|
void BMenuItem::Select(bool on)
|
||||||
{
|
{
|
||||||
|
if (Submenu())
|
||||||
|
{
|
||||||
fSelected = on;
|
fSelected = on;
|
||||||
|
Highlight(on);
|
||||||
|
}
|
||||||
|
else if (IsEnabled())
|
||||||
|
{
|
||||||
|
fSelected = on;
|
||||||
|
Highlight(on);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BMenuItem::DrawMarkSymbol()
|
void BMenuItem::DrawMarkSymbol()
|
||||||
@@ -374,7 +537,7 @@ void BMenuItem::DrawShortcutSymbol()
|
|||||||
shortcut += fShortcutChar;
|
shortcut += fShortcutChar;
|
||||||
|
|
||||||
fSuper->DrawString(shortcut.String(), ContentLocation() +
|
fSuper->DrawString(shortcut.String(), ContentLocation() +
|
||||||
BPoint(fBounds.Width() - 14.0f - 22.0f, fBounds.Height() - 4.0f));
|
BPoint(fBounds.Width() - 14.0f - 32.0f, fBounds.Height() - 4.0f));
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BMenuItem::DrawSubmenuSymbol()
|
void BMenuItem::DrawSubmenuSymbol()
|
||||||
@@ -440,13 +603,12 @@ BArchivable *BSeparatorItem::Instantiate(BMessage *data)
|
|||||||
{
|
{
|
||||||
if (validate_instantiation(data, "BSeparatorItem"))
|
if (validate_instantiation(data, "BSeparatorItem"))
|
||||||
return new BSeparatorItem(data);
|
return new BSeparatorItem(data);
|
||||||
|
else
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BSeparatorItem::SetEnabled(bool state)
|
void BSeparatorItem::SetEnabled(bool state)
|
||||||
{
|
{
|
||||||
BMenuItem::SetEnabled(state);
|
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BSeparatorItem::GetContentSize(float *width, float *height)
|
void BSeparatorItem::GetContentSize(float *width, float *height)
|
||||||
|
|||||||
@@ -24,12 +24,21 @@
|
|||||||
// Description: BShape encapsulates a Postscript-style "path"
|
// Description: BShape encapsulates a Postscript-style "path"
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Standard Includes -----------------------------------------------------------
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
// System Includes -------------------------------------------------------------
|
||||||
#include <Shape.h>
|
#include <Shape.h>
|
||||||
#include <Point.h>
|
#include <Point.h>
|
||||||
#include <Rect.h>
|
#include <Rect.h>
|
||||||
#include <Errors.h>
|
#include <Errors.h>
|
||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
|
|
||||||
|
// Project Includes ------------------------------------------------------------
|
||||||
|
|
||||||
|
// Local Includes --------------------------------------------------------------
|
||||||
|
|
||||||
|
// Local Defines ---------------------------------------------------------------
|
||||||
#define OP_LINETO 0x10000000
|
#define OP_LINETO 0x10000000
|
||||||
#define OP_BEZIERTO 0x20000000
|
#define OP_BEZIERTO 0x20000000
|
||||||
#define OP_CLOSE 0x40000000
|
#define OP_CLOSE 0x40000000
|
||||||
@@ -46,6 +55,8 @@ struct shape_data {
|
|||||||
int32 ptBlockSize;
|
int32 ptBlockSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Globals ---------------------------------------------------------------------
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
BShapeIterator::BShapeIterator()
|
BShapeIterator::BShapeIterator()
|
||||||
{
|
{
|
||||||
@@ -191,12 +202,13 @@ BShape::~BShape()
|
|||||||
free(data->opList);
|
free(data->opList);
|
||||||
free(data->ptList);
|
free(data->ptList);
|
||||||
|
|
||||||
delete fPrivateData;
|
delete (shape_data*)fPrivateData;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
status_t BShape::Archive(BMessage *archive, bool deep) const
|
status_t BShape::Archive(BMessage *archive, bool deep) const
|
||||||
{
|
{
|
||||||
status_t err = BArchivable::Archive(archive, deep);
|
status_t err = BArchivable::Archive(archive, deep);
|
||||||
|
int32 i;
|
||||||
|
|
||||||
if (err != B_OK)
|
if (err != B_OK)
|
||||||
return err;
|
return err;
|
||||||
@@ -211,7 +223,7 @@ status_t BShape::Archive(BMessage *archive, bool deep) const
|
|||||||
archive->AddData("pts", B_POINT_TYPE, data->ptList, sizeof(BPoint), true,
|
archive->AddData("pts", B_POINT_TYPE, data->ptList, sizeof(BPoint), true,
|
||||||
data->ptCount);
|
data->ptCount);
|
||||||
|
|
||||||
for (int32 i = 1; i < data->ptCount; i++)
|
for (i = 1; i < data->ptCount; i++)
|
||||||
archive->AddPoint("pts", data->ptList[i]);
|
archive->AddPoint("pts", data->ptList[i]);
|
||||||
|
|
||||||
// Avoids allocation for each op
|
// Avoids allocation for each op
|
||||||
|
|||||||
Reference in New Issue
Block a user