From 30fd51473f390b92d40b3a3c83b25e2d4a042f08 Mon Sep 17 00:00:00 2001 From: haydentech Date: Wed, 14 May 2003 17:21:46 +0000 Subject: [PATCH] Minor header-related changes git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3246 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/os/interface/Menu.h | 6 +- headers/os/interface/MenuBar.h | 8 +- headers/os/interface/MenuItem.h | 6 +- headers/os/interface/Shape.h | 4 +- headers/os/support/Autolock.h | 4 +- headers/os/support/Debug.h | 2 +- headers/os/support/StopWatch.h | 2 +- headers/os/support/SupportDefs.h | 2 +- src/kits/app/MessageQueue.cpp | 8 +- src/kits/interface/ColorControl.cpp | 6 +- src/kits/interface/Control.cpp | 2 +- src/kits/interface/MenuItem.cpp | 962 ++++++++++----------- src/kits/interface/Picture.cpp | 1208 +++++++++++++-------------- src/kits/interface/ScrollBar.cpp | 6 +- src/kits/interface/Shape.cpp | 10 +- src/kits/interface/Slider.cpp | 2 +- src/kits/interface/StatusBar.cpp | 1162 +++++++++++++------------- 17 files changed, 1702 insertions(+), 1698 deletions(-) diff --git a/headers/os/interface/Menu.h b/headers/os/interface/Menu.h index 15993e3a89..a43abd55b6 100644 --- a/headers/os/interface/Menu.h +++ b/headers/os/interface/Menu.h @@ -171,9 +171,9 @@ virtual void DrawBackground(BRect update); /*----- Private or reserved -----------------------------------------*/ private: -friend BWindow; -friend BMenuBar; -friend BMenuItem; +friend class BWindow; +friend class BMenuBar; +friend class BMenuItem; friend status_t _init_interface_kit_(); friend status_t set_menu_info(menu_info *); friend status_t get_menu_info(menu_info *); diff --git a/headers/os/interface/MenuBar.h b/headers/os/interface/MenuBar.h index 739ce54786..619faa8b49 100644 --- a/headers/os/interface/MenuBar.h +++ b/headers/os/interface/MenuBar.h @@ -80,10 +80,10 @@ virtual void AllDetached(); virtual status_t Perform(perform_code d, void *arg); private: -friend BWindow; -friend BMenuItem; -friend BMenuField; -friend BMenu; +friend class BWindow; +friend class BMenuItem; +friend class BMenuField; +friend class BMenu; virtual void _ReservedMenuBar1(); virtual void _ReservedMenuBar2(); diff --git a/headers/os/interface/MenuItem.h b/headers/os/interface/MenuItem.h index 7ccb30c94c..8fc6436178 100644 --- a/headers/os/interface/MenuItem.h +++ b/headers/os/interface/MenuItem.h @@ -65,9 +65,9 @@ virtual void Highlight(bool on); /*----- Private or reserved -----------------------------------------*/ private: -friend BMenu; -friend BPopUpMenu; -friend BMenuBar; +friend class BMenu; +friend class BPopUpMenu; +friend class BMenuBar; virtual void _ReservedMenuItem1(); virtual void _ReservedMenuItem2(); diff --git a/headers/os/interface/Shape.h b/headers/os/interface/Shape.h index a7cb762b06..0b1495a646 100644 --- a/headers/os/interface/Shape.h +++ b/headers/os/interface/Shape.h @@ -74,9 +74,9 @@ virtual void _ReservedShape2(); virtual void _ReservedShape3(); virtual void _ReservedShape4(); - friend BShapeIterator; + friend class BShapeIterator; friend class TPicture; - friend BView; + friend class BView; friend class BFont; void GetData(int32 *opCount, int32 *ptCount, uint32 **opList, BPoint **ptList); void SetData(int32 opCount, int32 ptCount, uint32 *opList, BPoint *ptList); diff --git a/headers/os/support/Autolock.h b/headers/os/support/Autolock.h index 27dd098dfa..ba2423571d 100644 --- a/headers/os/support/Autolock.h +++ b/headers/os/support/Autolock.h @@ -1,5 +1,5 @@ // -// $Id: Autolock.h,v 1.1 2002/07/09 12:24:33 ejakowatz Exp $ +// $Id: Autolock.h,v 1.2 2003/05/14 17:21:46 haydentech Exp $ // // This is the BAutolock interface for OpenBeOS. It has been created to // be source and binary compatible with the BeOS version of BAutolock. @@ -11,7 +11,7 @@ #define _OPENBEOS_AUTOLOCK_H -#include "Locker.h" +#include #include diff --git a/headers/os/support/Debug.h b/headers/os/support/Debug.h index 788214882f..df956a9996 100644 --- a/headers/os/support/Debug.h +++ b/headers/os/support/Debug.h @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include /*------------------------------*/ diff --git a/headers/os/support/StopWatch.h b/headers/os/support/StopWatch.h index 1a58c4c18f..798e388312 100644 --- a/headers/os/support/StopWatch.h +++ b/headers/os/support/StopWatch.h @@ -2,7 +2,7 @@ #define _BLUE_STOP_WATCH_H #include -#include "support/SupportDefs.h" +#include #ifdef USE_OPENBEOS_NAMESPACE namespace OpenBeOS { diff --git a/headers/os/support/SupportDefs.h b/headers/os/support/SupportDefs.h index c00179184f..13d545578c 100644 --- a/headers/os/support/SupportDefs.h +++ b/headers/os/support/SupportDefs.h @@ -40,7 +40,7 @@ typedef unsigned short ushort; // System Includes ------------------------------------------------------------- #include #include -#include +#include // Project Includes ------------------------------------------------------------ diff --git a/src/kits/app/MessageQueue.cpp b/src/kits/app/MessageQueue.cpp index 6703e5b071..10c9341af5 100644 --- a/src/kits/app/MessageQueue.cpp +++ b/src/kits/app/MessageQueue.cpp @@ -1,14 +1,14 @@ // -// $Id: MessageQueue.cpp,v 1.2 2002/09/28 09:49:34 shatty Exp $ +// $Id: MessageQueue.cpp,v 1.3 2003/05/14 17:21:46 haydentech Exp $ // // This file contains the implementation of the BMessageQueue class // for the OpenBeOS project. // -#include "MessageQueue.h" -#include "Autolock.h" -#include "Message.h" +#include +#include +#include #ifdef USE_OPENBEOS_NAMESPACE namespace OpenBeOS { diff --git a/src/kits/interface/ColorControl.cpp b/src/kits/interface/ColorControl.cpp index f14abf1b1b..299eaa3049 100644 --- a/src/kits/interface/ColorControl.cpp +++ b/src/kits/interface/ColorControl.cpp @@ -28,9 +28,9 @@ #include // System Includes ------------------------------------------------------------- -#include "ColorControl.h" -#include "TextControl.h" -#include +#include +#include +#include // Project Includes ------------------------------------------------------------ diff --git a/src/kits/interface/Control.cpp b/src/kits/interface/Control.cpp index 3723162be4..3410d7d55a 100644 --- a/src/kits/interface/Control.cpp +++ b/src/kits/interface/Control.cpp @@ -26,7 +26,7 @@ // Standard Includes ----------------------------------------------------------- #include -#include +#include // System Includes ------------------------------------------------------------- #include diff --git a/src/kits/interface/MenuItem.cpp b/src/kits/interface/MenuItem.cpp index 45f6d4ab6a..b2ed09ae8e 100644 --- a/src/kits/interface/MenuItem.cpp +++ b/src/kits/interface/MenuItem.cpp @@ -1,481 +1,481 @@ -// Standard Includes ----------------------------------------------------------- -#include -#include - -// System Includes ------------------------------------------------------------- -#include -#include -#include -#include - -// Project Includes ------------------------------------------------------------ - -// Local Includes -------------------------------------------------------------- - -// Local Defines --------------------------------------------------------------- - -// Globals --------------------------------------------------------------------- - -//------------------------------------------------------------------------------ -BMenuItem::BMenuItem(const char *label, BMessage *message, char shortcut, - 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) -{ - fLabel = strdup(label); -} -//------------------------------------------------------------------------------ -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()); - - fSubmenu->fSuperitem = this; -} -//------------------------------------------------------------------------------ -BMenuItem::BMenuItem(BMessage *data) -{ -} -//------------------------------------------------------------------------------ -BArchivable *BMenuItem::Instantiate(BMessage *data) -{ - if (validate_instantiation(data, "BMenuItem")) - return new BMenuItem(data); - - return NULL; -} -//------------------------------------------------------------------------------ -status_t BMenuItem::Archive(BMessage *data, bool deep) const -{ - if (Label()) - data->AddString("_label", Label()); - - if (!IsEnabled()) - data->AddBool("_disable", true); - - if (IsMarked()) - data->AddBool("_marked", true); - - if (fUserTrigger) - data->AddInt32("_user_trig", fUserTrigger); - - if (fShortcutChar && fModifiers) - { - data->AddInt32("_shortcut", fShortcutChar); - data->AddInt32("_mods", fModifiers); - } - - if (Message()) - data->AddMessage("_msg", Message()); - - if (deep && Submenu()) - { - BMessage submenu; - Submenu()->Archive(&submenu); - data->AddMessage("_submenu", &submenu); - } - - return B_OK; -} -//------------------------------------------------------------------------------ -BMenuItem::~BMenuItem() -{ - if (fLabel) - free(fLabel); - - if (fSubmenu) - delete fSubmenu; -} -//------------------------------------------------------------------------------ -void BMenuItem::SetLabel(const char *string) -{ - if (fLabel) - free(fLabel); - - fLabel = strdup(string); - - Menu()->InvalidateLayout(); -} -//------------------------------------------------------------------------------ -void BMenuItem::SetEnabled(bool state) -{ - if (Menu()->IsEnabled() == false) - return; - - fEnabled = state; - - if (Submenu()) - Submenu()->SetEnabled(state); -} -//------------------------------------------------------------------------------ -void BMenuItem::SetMarked(bool state) -{ - fMark = state; - - if (state && Menu()) - Menu()->ItemMarked(this); -} -//------------------------------------------------------------------------------ -void BMenuItem::SetTrigger(char ch) -{ - fUserTrigger = ch; -} -//------------------------------------------------------------------------------ -void BMenuItem::SetShortcut(char ch, uint32 modifiers) -{ - fShortcutChar = ch; - fModifiers = modifiers; -} -//------------------------------------------------------------------------------ -const char *BMenuItem::Label() const -{ - return fLabel; -} -//------------------------------------------------------------------------------ -bool BMenuItem::IsEnabled() const -{ - return fEnabled; -} -//------------------------------------------------------------------------------ -bool BMenuItem::IsMarked() const -{ - return fMark; -} -//------------------------------------------------------------------------------ -char BMenuItem::Trigger() const -{ - if (fUserTrigger) - return fUserTrigger; - else - return fSysTrigger; -} -//------------------------------------------------------------------------------ -char BMenuItem::Shortcut(uint32 *modifiers) const -{ - if (modifiers) - *modifiers = fModifiers; - - return fShortcutChar; -} -//------------------------------------------------------------------------------ -BMenu *BMenuItem::Submenu() const -{ - return fSubmenu; -} -//------------------------------------------------------------------------------ -BMenu *BMenuItem::Menu() const -{ - return fSuper; -} -//------------------------------------------------------------------------------ -BRect BMenuItem::Frame() const -{ - return fBounds; -} -//------------------------------------------------------------------------------ -void BMenuItem::GetContentSize(float *width, float *height) -{ - BMenu *menu = Menu(); - - if (menu->fFontHeight == -1) - menu->CacheFontInfo(); - - *width = (float)ceil(menu->StringWidth(fLabel)); - *height = menu->fFontHeight; -} -//------------------------------------------------------------------------------ -void BMenuItem::TruncateLabel(float maxWidth, char *newLabel) -{ -} -//------------------------------------------------------------------------------ -void BMenuItem::DrawContent() -{ - fSuper->DrawString(fLabel); -} -//------------------------------------------------------------------------------ -void BMenuItem::Draw() -{ - if (IsEnabled() && fSelected) - { - fSuper->SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), - B_DARKEN_2_TINT)); - fSuper->SetLowColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), - B_DARKEN_2_TINT)); - fSuper->FillRect(Frame()); - } - - BPoint pt = ContentLocation(); - - fSuper->MovePenTo(pt.x, pt.y + Menu()->fAscent); - if (IsEnabled()) - fSuper->SetHighColor(ui_color(B_MENU_ITEM_TEXT_COLOR)); - else - fSuper->SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), - B_DISABLED_LABEL_TINT)); - DrawContent(); - - if (Menu()->Layout() == B_ITEMS_IN_COLUMN) - { - if (IsMarked()) - DrawMarkSymbol(); - - if (Submenu()) - DrawSubmenuSymbol(); - else if (fShortcutChar) - DrawShortcutSymbol(); - } -} -//------------------------------------------------------------------------------ -void BMenuItem::Highlight(bool flag) -{ - //Menu()->InvertRect(Frame()); - Menu()->Invalidate(Frame()); -} -//------------------------------------------------------------------------------ -bool BMenuItem::IsSelected() const -{ - return fSelected; -} -//------------------------------------------------------------------------------ -BPoint BMenuItem::ContentLocation () const -{ - if (!Menu()) - return BPoint(); - - return BPoint(fBounds.left + Menu()->fPad.left, - fBounds.top + Menu()->fPad.top); -} -//------------------------------------------------------------------------------ -void BMenuItem::_ReservedMenuItem1() {} -void BMenuItem::_ReservedMenuItem2() {} -void BMenuItem::_ReservedMenuItem3() {} -void BMenuItem::_ReservedMenuItem4() {} -//------------------------------------------------------------------------------ -BMenuItem::BMenuItem(const BMenuItem &) -{ -} -//------------------------------------------------------------------------------ -BMenuItem &BMenuItem::operator=(const BMenuItem &) -{ - return *this; -} -//------------------------------------------------------------------------------ -void BMenuItem::InitData() -{ -} -//------------------------------------------------------------------------------ -void BMenuItem::InitMenuData(BMenu *menu) -{ -} -//------------------------------------------------------------------------------ -void BMenuItem::Install(BWindow *window) -{ - if (Submenu()) - Submenu()->Install(window); - - char shortcut; - uint32 modifiers; - if (shortcut = Shortcut(&modifiers)) - window->AddShortcut(shortcut, modifiers, this); - - if (Target() == NULL) - SetTarget(window); -} -//------------------------------------------------------------------------------ -status_t BMenuItem::Invoke(BMessage *message) -{ - if (IsEnabled()) - { - BMessage msg; - - 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 - return B_OK; -} -//------------------------------------------------------------------------------ -void BMenuItem::Uninstall() -{ -} -//------------------------------------------------------------------------------ -void BMenuItem::SetSuper(BMenu *super) -{ - fSuper = super; -} -//------------------------------------------------------------------------------ -void BMenuItem::Select(bool on) -{ - fSelected = on; -} -//------------------------------------------------------------------------------ -void BMenuItem::DrawMarkSymbol() -{ - fSuper->SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), - B_DARKEN_1_TINT)); - fSuper->StrokeLine(BPoint(fBounds.left + 6.0f, fBounds.bottom - 3.0f), - BPoint(fBounds.left + 10.0f, fBounds.bottom - 12.0f)); - fSuper->StrokeLine(BPoint(fBounds.left + 7.0f, fBounds.bottom - 3.0f), - BPoint(fBounds.left + 11.0f, fBounds.bottom - 12.0f)); - - fSuper->SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), - B_DARKEN_4_TINT)); - - fSuper->StrokeLine(BPoint(fBounds.left + 6.0f, fBounds.bottom - 4.0f), - BPoint(fBounds.left + 10.0f, fBounds.bottom - 13.0f)); - fSuper->StrokeLine(BPoint(fBounds.left + 5.0f, fBounds.bottom - 4.0f), - BPoint(fBounds.left + 9.0f, fBounds.bottom - 13.0f)); - fSuper->StrokeLine(BPoint(fBounds.left + 5.0f, fBounds.bottom - 3.0f), - BPoint(fBounds.left + 3.0f, fBounds.bottom - 9.0f)); - fSuper->StrokeLine(BPoint(fBounds.left + 4.0f, fBounds.bottom - 4.0f), - BPoint(fBounds.left + 2.0f, fBounds.bottom - 9.0f)); -} -//------------------------------------------------------------------------------ -void BMenuItem::DrawShortcutSymbol() -{ - BString shortcut(""); - - if (fModifiers & B_CONTROL_KEY) - shortcut += "ctl+"; - - shortcut += fShortcutChar; - - fSuper->DrawString(shortcut.String(), ContentLocation() + - BPoint(fBounds.Width() - 14.0f - 22.0f, fBounds.Height() - 4.0f)); -} -//------------------------------------------------------------------------------ -void BMenuItem::DrawSubmenuSymbol() -{ - fSuper->SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), - B_LIGHTEN_MAX_TINT)); - fSuper->FillTriangle(BPoint(fBounds.right - 14.0f, fBounds.bottom - 4.0f), - BPoint(fBounds.right - 14.0f, fBounds.bottom - 12.0f), - BPoint(fBounds.right - 5.0f, fBounds.bottom - 8.0f)); - - fSuper->SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), - B_DARKEN_2_TINT)); - fSuper->StrokeLine(BPoint(fBounds.right - 14.0f, fBounds.bottom - 5), - BPoint(fBounds.right - 9.0f, fBounds.bottom - 7)); - fSuper->StrokeLine(BPoint(fBounds.right - 7.0f, fBounds.bottom - 8), - BPoint(fBounds.right - 7.0f, fBounds.bottom - 8)); - - fSuper->SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), - B_DARKEN_3_TINT)); - fSuper->StrokeTriangle(BPoint(fBounds.right - 14.0f, fBounds.bottom - 4.0f), - BPoint(fBounds.right - 14.0f, fBounds.bottom - 12.0f), - BPoint(fBounds.right - 5.0f, fBounds.bottom - 8.0f)); - - fSuper->SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), - B_LIGHTEN_1_TINT)); - fSuper->StrokeTriangle(BPoint(fBounds.right - 12.0f, fBounds.bottom - 7.0f), - BPoint(fBounds.right - 12.0f, fBounds.bottom - 9.0f), - BPoint(fBounds.right - 9.0f, fBounds.bottom - 8.0f)); - fSuper->FillTriangle(BPoint(fBounds.right - 12.0f, fBounds.bottom - 7.0f), - BPoint(fBounds.right - 12.0f, fBounds.bottom - 9.0f), - BPoint(fBounds.right - 9.0f, fBounds.bottom - 8.0f)); -} -//------------------------------------------------------------------------------ -void BMenuItem::DrawControlChar(const char *control) -{ -} -//------------------------------------------------------------------------------ -void BMenuItem::SetSysTrigger(char ch) -{ - fSysTrigger = ch; -} -//------------------------------------------------------------------------------ -BSeparatorItem::BSeparatorItem() - : BMenuItem(NULL, NULL, 0, 0) -{ -} -//------------------------------------------------------------------------------ -BSeparatorItem::BSeparatorItem(BMessage *data) - : BMenuItem(data) -{ -} -//------------------------------------------------------------------------------ -BSeparatorItem::~BSeparatorItem() -{ -} -//------------------------------------------------------------------------------ -status_t BSeparatorItem::Archive(BMessage *data, bool deep) const -{ - return BMenuItem::Archive(data, deep); -} -//------------------------------------------------------------------------------ -BArchivable *BSeparatorItem::Instantiate(BMessage *data) -{ - if (validate_instantiation(data, "BSeparatorItem")) - return new BSeparatorItem(data); - - return NULL; -} -//------------------------------------------------------------------------------ -void BSeparatorItem::SetEnabled(bool state) -{ - BSeparatorItem::SetEnabled(state); -} -//------------------------------------------------------------------------------ -void BSeparatorItem::GetContentSize(float *width, float *height) -{ - *width = 2.0f; - *height = 8.0f; -} -//------------------------------------------------------------------------------ -void BSeparatorItem::Draw() -{ - BRect bounds = Frame(); - - Menu()->SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), - B_DARKEN_2_TINT)); - Menu()->StrokeLine(BPoint(bounds.left + 1.0f, bounds.top + 4.0f), - BPoint(bounds.right - 1.0f, bounds.top + 4.0f)); - Menu()->SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), - B_LIGHTEN_2_TINT)); - Menu()->StrokeLine(BPoint(bounds.left + 1.0f, bounds.top + 5.0f), - BPoint(bounds.right - 1.0f, bounds.top + 5.0f)); - - Menu()->SetHighColor(0, 0, 0); -} -//------------------------------------------------------------------------------ -void BSeparatorItem::_ReservedSeparatorItem1() {} -void BSeparatorItem::_ReservedSeparatorItem2() {} -//------------------------------------------------------------------------------ -BSeparatorItem &BSeparatorItem::operator=(const BSeparatorItem &) -{ - return *this; -} -//------------------------------------------------------------------------------ +// Standard Includes ----------------------------------------------------------- +#include +#include + +// System Includes ------------------------------------------------------------- +#include +#include +#include +#include + +// Project Includes ------------------------------------------------------------ + +// Local Includes -------------------------------------------------------------- + +// Local Defines --------------------------------------------------------------- + +// Globals --------------------------------------------------------------------- + +//------------------------------------------------------------------------------ +BMenuItem::BMenuItem(const char *label, BMessage *message, char shortcut, + 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) +{ + fLabel = strdup(label); +} +//------------------------------------------------------------------------------ +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()); + + fSubmenu->fSuperitem = this; +} +//------------------------------------------------------------------------------ +BMenuItem::BMenuItem(BMessage *data) +{ +} +//------------------------------------------------------------------------------ +BArchivable *BMenuItem::Instantiate(BMessage *data) +{ + if (validate_instantiation(data, "BMenuItem")) + return new BMenuItem(data); + + return NULL; +} +//------------------------------------------------------------------------------ +status_t BMenuItem::Archive(BMessage *data, bool deep) const +{ + if (Label()) + data->AddString("_label", Label()); + + if (!IsEnabled()) + data->AddBool("_disable", true); + + if (IsMarked()) + data->AddBool("_marked", true); + + if (fUserTrigger) + data->AddInt32("_user_trig", fUserTrigger); + + if (fShortcutChar && fModifiers) + { + data->AddInt32("_shortcut", fShortcutChar); + data->AddInt32("_mods", fModifiers); + } + + if (Message()) + data->AddMessage("_msg", Message()); + + if (deep && Submenu()) + { + BMessage submenu; + Submenu()->Archive(&submenu); + data->AddMessage("_submenu", &submenu); + } + + return B_OK; +} +//------------------------------------------------------------------------------ +BMenuItem::~BMenuItem() +{ + if (fLabel) + free(fLabel); + + if (fSubmenu) + delete fSubmenu; +} +//------------------------------------------------------------------------------ +void BMenuItem::SetLabel(const char *string) +{ + if (fLabel) + free(fLabel); + + fLabel = strdup(string); + + Menu()->InvalidateLayout(); +} +//------------------------------------------------------------------------------ +void BMenuItem::SetEnabled(bool state) +{ + if (Menu()->IsEnabled() == false) + return; + + fEnabled = state; + + if (Submenu()) + Submenu()->SetEnabled(state); +} +//------------------------------------------------------------------------------ +void BMenuItem::SetMarked(bool state) +{ + fMark = state; + + if (state && Menu()) + Menu()->ItemMarked(this); +} +//------------------------------------------------------------------------------ +void BMenuItem::SetTrigger(char ch) +{ + fUserTrigger = ch; +} +//------------------------------------------------------------------------------ +void BMenuItem::SetShortcut(char ch, uint32 modifiers) +{ + fShortcutChar = ch; + fModifiers = modifiers; +} +//------------------------------------------------------------------------------ +const char *BMenuItem::Label() const +{ + return fLabel; +} +//------------------------------------------------------------------------------ +bool BMenuItem::IsEnabled() const +{ + return fEnabled; +} +//------------------------------------------------------------------------------ +bool BMenuItem::IsMarked() const +{ + return fMark; +} +//------------------------------------------------------------------------------ +char BMenuItem::Trigger() const +{ + if (fUserTrigger) + return fUserTrigger; + else + return fSysTrigger; +} +//------------------------------------------------------------------------------ +char BMenuItem::Shortcut(uint32 *modifiers) const +{ + if (modifiers) + *modifiers = fModifiers; + + return fShortcutChar; +} +//------------------------------------------------------------------------------ +BMenu *BMenuItem::Submenu() const +{ + return fSubmenu; +} +//------------------------------------------------------------------------------ +BMenu *BMenuItem::Menu() const +{ + return fSuper; +} +//------------------------------------------------------------------------------ +BRect BMenuItem::Frame() const +{ + return fBounds; +} +//------------------------------------------------------------------------------ +void BMenuItem::GetContentSize(float *width, float *height) +{ + BMenu *menu = Menu(); + + if (menu->fFontHeight == -1) + menu->CacheFontInfo(); + + *width = (float)ceil(menu->StringWidth(fLabel)); + *height = menu->fFontHeight; +} +//------------------------------------------------------------------------------ +void BMenuItem::TruncateLabel(float maxWidth, char *newLabel) +{ +} +//------------------------------------------------------------------------------ +void BMenuItem::DrawContent() +{ + fSuper->DrawString(fLabel); +} +//------------------------------------------------------------------------------ +void BMenuItem::Draw() +{ + if (IsEnabled() && fSelected) + { + fSuper->SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), + B_DARKEN_2_TINT)); + fSuper->SetLowColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), + B_DARKEN_2_TINT)); + fSuper->FillRect(Frame()); + } + + BPoint pt = ContentLocation(); + + fSuper->MovePenTo(pt.x, pt.y + Menu()->fAscent); + if (IsEnabled()) + fSuper->SetHighColor(ui_color(B_MENU_ITEM_TEXT_COLOR)); + else + fSuper->SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), + B_DISABLED_LABEL_TINT)); + DrawContent(); + + if (Menu()->Layout() == B_ITEMS_IN_COLUMN) + { + if (IsMarked()) + DrawMarkSymbol(); + + if (Submenu()) + DrawSubmenuSymbol(); + else if (fShortcutChar) + DrawShortcutSymbol(); + } +} +//------------------------------------------------------------------------------ +void BMenuItem::Highlight(bool flag) +{ + //Menu()->InvertRect(Frame()); + Menu()->Invalidate(Frame()); +} +//------------------------------------------------------------------------------ +bool BMenuItem::IsSelected() const +{ + return fSelected; +} +//------------------------------------------------------------------------------ +BPoint BMenuItem::ContentLocation () const +{ + if (!Menu()) + return BPoint(); + + return BPoint(fBounds.left + Menu()->fPad.left, + fBounds.top + Menu()->fPad.top); +} +//------------------------------------------------------------------------------ +void BMenuItem::_ReservedMenuItem1() {} +void BMenuItem::_ReservedMenuItem2() {} +void BMenuItem::_ReservedMenuItem3() {} +void BMenuItem::_ReservedMenuItem4() {} +//------------------------------------------------------------------------------ +BMenuItem::BMenuItem(const BMenuItem &) +{ +} +//------------------------------------------------------------------------------ +BMenuItem &BMenuItem::operator=(const BMenuItem &) +{ + return *this; +} +//------------------------------------------------------------------------------ +void BMenuItem::InitData() +{ +} +//------------------------------------------------------------------------------ +void BMenuItem::InitMenuData(BMenu *menu) +{ +} +//------------------------------------------------------------------------------ +void BMenuItem::Install(BWindow *window) +{ + if (Submenu()) + Submenu()->Install(window); + + char shortcut; + uint32 modifiers; + if (shortcut = Shortcut(&modifiers)) + window->AddShortcut(shortcut, modifiers, this); + + if (Target() == NULL) + SetTarget(window); +} +//------------------------------------------------------------------------------ +status_t BMenuItem::Invoke(BMessage *message) +{ + if (IsEnabled()) + { + BMessage msg; + + 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 + return B_OK; +} +//------------------------------------------------------------------------------ +void BMenuItem::Uninstall() +{ +} +//------------------------------------------------------------------------------ +void BMenuItem::SetSuper(BMenu *super) +{ + fSuper = super; +} +//------------------------------------------------------------------------------ +void BMenuItem::Select(bool on) +{ + fSelected = on; +} +//------------------------------------------------------------------------------ +void BMenuItem::DrawMarkSymbol() +{ + fSuper->SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), + B_DARKEN_1_TINT)); + fSuper->StrokeLine(BPoint(fBounds.left + 6.0f, fBounds.bottom - 3.0f), + BPoint(fBounds.left + 10.0f, fBounds.bottom - 12.0f)); + fSuper->StrokeLine(BPoint(fBounds.left + 7.0f, fBounds.bottom - 3.0f), + BPoint(fBounds.left + 11.0f, fBounds.bottom - 12.0f)); + + fSuper->SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), + B_DARKEN_4_TINT)); + + fSuper->StrokeLine(BPoint(fBounds.left + 6.0f, fBounds.bottom - 4.0f), + BPoint(fBounds.left + 10.0f, fBounds.bottom - 13.0f)); + fSuper->StrokeLine(BPoint(fBounds.left + 5.0f, fBounds.bottom - 4.0f), + BPoint(fBounds.left + 9.0f, fBounds.bottom - 13.0f)); + fSuper->StrokeLine(BPoint(fBounds.left + 5.0f, fBounds.bottom - 3.0f), + BPoint(fBounds.left + 3.0f, fBounds.bottom - 9.0f)); + fSuper->StrokeLine(BPoint(fBounds.left + 4.0f, fBounds.bottom - 4.0f), + BPoint(fBounds.left + 2.0f, fBounds.bottom - 9.0f)); +} +//------------------------------------------------------------------------------ +void BMenuItem::DrawShortcutSymbol() +{ + BString shortcut(""); + + if (fModifiers & B_CONTROL_KEY) + shortcut += "ctl+"; + + shortcut += fShortcutChar; + + fSuper->DrawString(shortcut.String(), ContentLocation() + + BPoint(fBounds.Width() - 14.0f - 22.0f, fBounds.Height() - 4.0f)); +} +//------------------------------------------------------------------------------ +void BMenuItem::DrawSubmenuSymbol() +{ + fSuper->SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), + B_LIGHTEN_MAX_TINT)); + fSuper->FillTriangle(BPoint(fBounds.right - 14.0f, fBounds.bottom - 4.0f), + BPoint(fBounds.right - 14.0f, fBounds.bottom - 12.0f), + BPoint(fBounds.right - 5.0f, fBounds.bottom - 8.0f)); + + fSuper->SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), + B_DARKEN_2_TINT)); + fSuper->StrokeLine(BPoint(fBounds.right - 14.0f, fBounds.bottom - 5), + BPoint(fBounds.right - 9.0f, fBounds.bottom - 7)); + fSuper->StrokeLine(BPoint(fBounds.right - 7.0f, fBounds.bottom - 8), + BPoint(fBounds.right - 7.0f, fBounds.bottom - 8)); + + fSuper->SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), + B_DARKEN_3_TINT)); + fSuper->StrokeTriangle(BPoint(fBounds.right - 14.0f, fBounds.bottom - 4.0f), + BPoint(fBounds.right - 14.0f, fBounds.bottom - 12.0f), + BPoint(fBounds.right - 5.0f, fBounds.bottom - 8.0f)); + + fSuper->SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), + B_LIGHTEN_1_TINT)); + fSuper->StrokeTriangle(BPoint(fBounds.right - 12.0f, fBounds.bottom - 7.0f), + BPoint(fBounds.right - 12.0f, fBounds.bottom - 9.0f), + BPoint(fBounds.right - 9.0f, fBounds.bottom - 8.0f)); + fSuper->FillTriangle(BPoint(fBounds.right - 12.0f, fBounds.bottom - 7.0f), + BPoint(fBounds.right - 12.0f, fBounds.bottom - 9.0f), + BPoint(fBounds.right - 9.0f, fBounds.bottom - 8.0f)); +} +//------------------------------------------------------------------------------ +void BMenuItem::DrawControlChar(const char *control) +{ +} +//------------------------------------------------------------------------------ +void BMenuItem::SetSysTrigger(char ch) +{ + fSysTrigger = ch; +} +//------------------------------------------------------------------------------ +BSeparatorItem::BSeparatorItem() + : BMenuItem(NULL, NULL, 0, 0) +{ +} +//------------------------------------------------------------------------------ +BSeparatorItem::BSeparatorItem(BMessage *data) + : BMenuItem(data) +{ +} +//------------------------------------------------------------------------------ +BSeparatorItem::~BSeparatorItem() +{ +} +//------------------------------------------------------------------------------ +status_t BSeparatorItem::Archive(BMessage *data, bool deep) const +{ + return BMenuItem::Archive(data, deep); +} +//------------------------------------------------------------------------------ +BArchivable *BSeparatorItem::Instantiate(BMessage *data) +{ + if (validate_instantiation(data, "BSeparatorItem")) + return new BSeparatorItem(data); + + return NULL; +} +//------------------------------------------------------------------------------ +void BSeparatorItem::SetEnabled(bool state) +{ + BSeparatorItem::SetEnabled(state); +} +//------------------------------------------------------------------------------ +void BSeparatorItem::GetContentSize(float *width, float *height) +{ + *width = 2.0f; + *height = 8.0f; +} +//------------------------------------------------------------------------------ +void BSeparatorItem::Draw() +{ + BRect bounds = Frame(); + + Menu()->SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), + B_DARKEN_2_TINT)); + Menu()->StrokeLine(BPoint(bounds.left + 1.0f, bounds.top + 4.0f), + BPoint(bounds.right - 1.0f, bounds.top + 4.0f)); + Menu()->SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), + B_LIGHTEN_2_TINT)); + Menu()->StrokeLine(BPoint(bounds.left + 1.0f, bounds.top + 5.0f), + BPoint(bounds.right - 1.0f, bounds.top + 5.0f)); + + Menu()->SetHighColor(0, 0, 0); +} +//------------------------------------------------------------------------------ +void BSeparatorItem::_ReservedSeparatorItem1() {} +void BSeparatorItem::_ReservedSeparatorItem2() {} +//------------------------------------------------------------------------------ +BSeparatorItem &BSeparatorItem::operator=(const BSeparatorItem &) +{ + return *this; +} +//------------------------------------------------------------------------------ diff --git a/src/kits/interface/Picture.cpp b/src/kits/interface/Picture.cpp index 0fb3fa93cb..fd34ea6d68 100644 --- a/src/kits/interface/Picture.cpp +++ b/src/kits/interface/Picture.cpp @@ -1,604 +1,604 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2001-2002, OpenBeOS -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// -// File Name: Picture.cpp -// Author: Marc Flerackers (mflerackers@androme.be) -// Description: BPicture records a series of drawing instructions that can -// be "replayed" later. -//------------------------------------------------------------------------------ - -// Standard Includes ----------------------------------------------------------- -#include -#include - -// System Includes ------------------------------------------------------------- -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// Project Includes ------------------------------------------------------------ - -// Local Includes -------------------------------------------------------------- - -// Local Defines --------------------------------------------------------------- - -// Globals --------------------------------------------------------------------- - -struct _BPictureExtent_ { - void *fNewData; - int32 fNewSize; - void *fOldData; - int32 fOldSize; - BList fPictures; // In R5 this is a BArray which is completely - // inline. -}; - -status_t do_playback(void * data, int32 size, BList& pictures, - void **callBackTable, int32 tableEntries, void *user); - -//------------------------------------------------------------------------------ -BPicture::BPicture() - : token(-1), - extent(NULL), - usurped(NULL) -{ - extent = new _BPictureExtent_; - extent->fNewData = NULL; - extent->fNewSize = 0; - extent->fOldData = NULL; - extent->fOldSize = 0; -} -//------------------------------------------------------------------------------ -BPicture::BPicture(const BPicture &picture) - : token(-1), - extent(NULL), - usurped(NULL) -{ - init_data(); - - if (picture.token != -1) - { - - BPrivate::BAppServerLink link; - PortLink::ReplyData replydata; - - link.portlink->SetOpCode(AS_CLONE_PICTURE); - link.portlink->Attach(picture.token); - link.portlink->FlushWithReply(&replydata); - token=*((int32*)replydata.buffer); - - } - if (picture.extent->fNewData != NULL) - { - extent->fNewSize = picture.extent->fNewSize; - extent->fNewData = malloc(extent->fNewSize); - memcpy(extent->fNewData, picture.extent->fNewData, extent->fNewSize); - - BPicture *pic; - - for (int32 i = 0; i < picture.extent->fPictures.CountItems(); i++) - { - pic = new BPicture(*(BPicture*)picture.extent->fPictures.ItemAt(i)); - extent->fPictures.AddItem(pic); - } - } - else if (picture.extent->fOldData != NULL) - { - extent->fOldSize = picture.extent->fOldSize; - extent->fOldData = malloc(extent->fOldSize); - memcpy(extent->fOldData, picture.extent->fOldData, extent->fOldSize); - - // In old data the sub pictures are inside the data - } -} -//------------------------------------------------------------------------------ -BPicture::BPicture(BMessage *archive) - : token(-1), - extent(NULL), - usurped(NULL) -{ - init_data(); - - int32 version, size; - int8 endian; - const void *data; - - if (archive->FindInt32("_ver", &version) != B_OK) - version = 0; - - if (archive->FindInt8("_endian", &endian) != B_OK) - endian = 0; - - if (archive->FindData("_data", B_RAW_TYPE, &data, (ssize_t*)&size) != B_OK) - return; - - // Load sub pictures - BMessage picMsg; - int32 i = 0; - - while (archive->FindMessage("piclib", i++, &picMsg) == B_OK) - { - BPicture *pic = new BPicture(&picMsg); - extent->fPictures.AddItem(pic); - } - - if (version == 0) - import_old_data(data, size); - else if (version == 1) - { - extent->fNewSize = size; - extent->fNewData = malloc(extent->fNewSize); - memcpy(extent->fNewData, data, extent->fNewSize); - -// swap_data(extent->fNewData, extent->fNewSize); - - if (extent->fNewSize != 0 && extent->fNewData != 0) - { - BPrivate::BAppServerLink link; - PortLink::ReplyData replydata; - BPicture *pic; - - link.portlink->SetOpCode(AS_CREATE_PICTURE); - link.portlink->Attach(extent->fPictures.CountItems()); - for (int32 i = 0; i < extent->fPictures.CountItems(); i++) - { - pic=(BPicture*)extent->fPictures.ItemAt(i); - if(pic) - link.portlink->Attach(pic->token); - } - link.portlink->Attach(extent->fNewSize); - link.portlink->Attach(extent->fNewData,extent->fNewSize); - link.portlink->FlushWithReply(&replydata); - token=*((int32*)replydata.buffer); - } - } - - // Do we just free the data now? - if (extent->fNewData) - { - free(extent->fNewData); - extent->fNewData = NULL; - extent->fNewSize = 0; - } - - if (extent->fOldData) - { - free(extent->fOldData); - extent->fOldData = NULL; - extent->fOldSize = 0; - } - - // What with the sub pictures? - for (i = 0; i < extent->fPictures.CountItems(); i++) - delete extent->fPictures.ItemAt(i); - extent->fPictures.MakeEmpty(); -} -//------------------------------------------------------------------------------ -BPicture::~BPicture() -{ - if (token != -1) - { - BPrivate::BAppServerLink link; - - link.portlink->SetOpCode(AS_DELETE_PICTURE); - link.portlink->Attach(token); - link.portlink->Flush(); - } - - if (extent->fNewData != NULL) - { - free(extent->fNewData); - extent->fNewData = NULL; - extent->fNewSize = 0; - } - - if (extent->fOldData != NULL) - { - free(extent->fOldData); - extent->fOldData = NULL; - extent->fOldSize = 0; - } - - for (int32 i = 0; i < extent->fPictures.CountItems(); i++) - delete extent->fPictures.ItemAt(i); - extent->fPictures.MakeEmpty(); - - free(extent); -} -//------------------------------------------------------------------------------ -BArchivable *BPicture::Instantiate(BMessage *archive) -{ - if (validate_instantiation(archive, "BPicture")) - return new BPicture(archive); - else - return NULL; -} -//------------------------------------------------------------------------------ -status_t BPicture::Archive(BMessage *archive, bool deep) const -{ - if (!const_cast(this)->assert_local_copy()) - return B_ERROR; - - status_t err = BArchivable::Archive(archive, deep); - - if (err != B_OK) - return err; - - err = archive->AddInt32("_ver", 1); - - if (err != B_OK) - return err; - - err = archive->AddInt8("_endian", B_HOST_IS_BENDIAN); - - if (err != B_OK) - return err; - - err = archive->AddData("_data", B_RAW_TYPE, extent->fNewData, - extent->fNewSize); - - for (int32 i = 0; i < extent->fPictures.CountItems(); i++) - { - BMessage picMsg; - - ((BPicture*)extent->fPictures.ItemAt(i))->Archive(&picMsg, deep); - - archive->AddMessage("piclib", &picMsg); - } - - return err; -} -//------------------------------------------------------------------------------ -status_t BPicture::Perform(perform_code d, void *arg) -{ - return BArchivable::Perform(d, arg); -} -//------------------------------------------------------------------------------ -status_t BPicture::Play(void **callBackTable, int32 tableEntries, void *user) -{ - if (!assert_local_copy()) - return B_ERROR; - - return do_playback(extent->fNewData, extent->fNewSize, extent->fPictures, - callBackTable, tableEntries, user); -} -//------------------------------------------------------------------------------ -status_t BPicture::Flatten(BDataIO *stream) -{ - if (!assert_local_copy()) - return B_ERROR; - - // TODO check the header - int32 bla1 = 2; - int32 bla2 = 0; - int32 count = 0; - - stream->Write(&bla1, 4); - stream->Write(&bla2, 4); - - count = extent->fPictures.CountItems(); - stream->Write(&count, 4); - - for (int32 i = 0; i < extent->fPictures.CountItems(); i++) - ((BPicture*)extent->fPictures.ItemAt(i))->Flatten(stream); - - stream->Write(&extent->fNewSize, 4); - stream->Write(extent->fNewData, extent->fNewSize); - - return B_OK; -} -//------------------------------------------------------------------------------ -status_t BPicture::Unflatten(BDataIO *stream) -{ - // TODO check the header - int32 bla1 = 2; - int32 bla2 = 0; - int32 count = 0; - - stream->Read(&bla1, 4); - stream->Read(&bla2, 4); - - stream->Read(&count, 4); - - for (int32 i = 0; i < count; i++) - { - BPicture *pic = new BPicture; - - pic->Unflatten(stream); - - extent->fPictures.AddItem(pic); - } - - stream->Read(&extent->fNewSize, 4); - extent->fNewData = malloc(extent->fNewSize); - stream->Read(extent->fNewData, extent->fNewSize); - -// swap_data(extent->fNewData, extent->fNewSize); - - BPrivate::BAppServerLink link; - PortLink::ReplyData replydata; - BPicture *pic; - - link.portlink->SetOpCode(AS_CREATE_PICTURE); - link.portlink->Attach(extent->fPictures.CountItems()); - for (int32 i = 0; i < extent->fPictures.CountItems(); i++) - { - pic=(BPicture*)extent->fPictures.ItemAt(i); - if(pic) - link.portlink->Attach(pic->token); - } - link.portlink->Attach(extent->fNewSize); - link.portlink->Attach(extent->fNewData, extent->fNewSize); - link.portlink->FlushWithReply(&replydata); - token=*((int32*)replydata.buffer); - - if (extent->fNewData) - { - free(extent->fNewData); - extent->fNewData = NULL; - extent->fNewSize = 0; - } - - return B_OK; -} -//------------------------------------------------------------------------------ -void BPicture::_ReservedPicture1() {} -void BPicture::_ReservedPicture2() {} -void BPicture::_ReservedPicture3() {} -//------------------------------------------------------------------------------ -BPicture &BPicture::operator=(const BPicture &) -{ - return *this; -} -//------------------------------------------------------------------------------ -void BPicture::init_data() -{ - token = -1; - usurped = NULL; - - extent = new _BPictureExtent_; - extent->fNewData = NULL; - extent->fNewSize = 0; - extent->fOldData = NULL; - extent->fOldSize = 0; -} -//------------------------------------------------------------------------------ -void BPicture::import_data(const void *data, int32 size, BPicture **subs, - int32 subCount) -{ - if (data == NULL || size == 0) - return; - - BPrivate::BAppServerLink link; - PortLink::ReplyData replydata; - - link.portlink->SetOpCode(AS_CREATE_PICTURE); - link.portlink->Attach(subCount); - - for (int32 i = 0; i < subCount; i++) - link.portlink->Attach(subs[i]->token); - - link.portlink->Attach(size); - link.portlink->Attach(data, size); - link.portlink->FlushWithReply(&replydata); - token=*((int32*)replydata.buffer); -} -//------------------------------------------------------------------------------ -void BPicture::import_old_data(const void *data, int32 size) -{ - // TODO: do we need to support old data, what is old data? - /*if (data == NULL) - return; - - if (size == 0) - return; - - convert_old_to_new(data, size, &extent->fNewData, &extent->fNewSize); - - BPrivate::BAppServerLink link; - PortLink::ReplyData replydata; - - link.portlink->SetOpCode(AS_CREATE_PICTURE); - link.portlink->Attach(0L); - link.portlink->Attach(extent->fNewSize); - link.portlink->Attach(extent->fNewData,extent->fNewSize); - link.portlink->FlushWithReply(&replydata); - token=*((int32*)replydata.buffer); - - // Do we free all data now? - free(extent->fNewData); - extent->fNewData = 0; - extent->fNewSize = 0; - free(extent->fOldData); - extent->fOldData = 0; - extent->fOldSize = 0;*/ -} -//------------------------------------------------------------------------------ -void BPicture::set_token(int32 _token) -{ - token = _token; -} -//------------------------------------------------------------------------------ -bool BPicture::assert_local_copy() -{ - if (extent->fNewData != NULL) - return true; - - if (token == -1) - return false; - -/* BPrivate::BAppServerLink link; - PortLink::ReplyData replydata; - int32 count; - - link.portlink->SetOpCode(AS_DOWNLOAD_PICTURE); - link.portlink->Attach(token); - link.portlink->FlushWithReply(&replydata); - count=*((int32*)replydata.buffer); - - // Read sub picture tokens - for (int32 i = 0; i < count; i++) - { - BPicture *pic = new BPicture; - - link.sread(4, &pic->token); - - extent->fPictures.AddItem(pic); - } - - link.sread(4, &extent->fNewSize); - extent->fNewData = malloc(extent->fNewSize); - link.sread(extent->fNewSize, &extent->fNewData);*/ - - return true; -} -//------------------------------------------------------------------------------ -bool BPicture::assert_old_local_copy() -{ - if (extent->fOldData != NULL) - return true; - - if (!assert_local_copy()) - return false; - -// convert_new_to_old(extent->fNewData, extent->fNewSize, extent->fOldData, -// extent->fOldSize); - - return true; -} -//------------------------------------------------------------------------------ -bool BPicture::assert_server_copy() -{ - if (token != -1) - return true; - - if (extent->fNewData == NULL) - return false; - -/* for (int32 i = 0; i < extent->fPictures.CountItems(); i++) - extent->fPictures.ItemAt(i)->assert_server_copy(); - - BPrivate::BAppServerLink link; - PortLink::ReplyData replydata; - - link.portlink->SetOpCode(AS_CREATE_PICTURE); - link.portlink->Attach(extent->fPictures.CountItems()); - for (int32 i = 0; i < extent->fPictures.CountItems(); i++) - link.portlink->Attach(extent->fPictures.ItemAt(i)->token); - link.portlink->Attach(extent->fNewSize); - link.portlink->Attach(extent->fNewData,extent->fNewSize); - link.portlink->FlushWithReply(&replydata); - token=*((int32*)replydata.buffer); - - return token != -1;*/ - return true; -} -//------------------------------------------------------------------------------ -BPicture::BPicture(const void *data, int32 size) -{ - init_data(); - import_old_data(data, size); -} -//------------------------------------------------------------------------------ -const void *BPicture::Data() const -{ - if (extent->fNewData == NULL) - { - const_cast(this)->assert_local_copy(); - //convert_new_to_old(void *, long, void **, long *); - } - - return extent->fNewData; -} -//------------------------------------------------------------------------------ -int32 BPicture::DataSize() const -{ - if (extent->fNewData == NULL) - { - const_cast(this)->assert_local_copy(); - //convert_new_to_old(void *, long, void **, long *); - } - - return extent->fNewSize; -} -//------------------------------------------------------------------------------ -void BPicture::usurp(BPicture *lameDuck) -{ - if (token != -1) - { - BPrivate::BAppServerLink link; - - link.portlink->SetOpCode(AS_DELETE_PICTURE); - link.portlink->Attach(token); - link.portlink->Flush(); - } - - if (extent->fNewData != NULL) - { - free(extent->fNewData); - extent->fNewData = NULL; - extent->fNewSize = 0; - } - - if (extent->fOldData != NULL) - { - free(extent->fOldData); - extent->fOldData = NULL; - extent->fOldSize = 0; - } - - for (int32 i = 0; i < extent->fPictures.CountItems(); i++) - delete extent->fPictures.ItemAt(i); - extent->fPictures.MakeEmpty(); - - free(extent); - - init_data(); - - // Do the usurping - usurped = lameDuck; -} -//------------------------------------------------------------------------------ -BPicture *BPicture::step_down() -{ - BPicture *lameDuck = usurped; - - usurped = NULL; - - return lameDuck; -} -//------------------------------------------------------------------------------ -status_t do_playback(void * data, int32 size, BList& pictures, - void **callBackTable, int32 tableEntries, void *user) -{ - TPicture pic(data, size, pictures); - - return pic.Play(callBackTable, tableEntries, user); -} -//------------------------------------------------------------------------------ - - +//------------------------------------------------------------------------------ +// Copyright (c) 2001-2002, OpenBeOS +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// +// File Name: Picture.cpp +// Author: Marc Flerackers (mflerackers@androme.be) +// Description: BPicture records a series of drawing instructions that can +// be "replayed" later. +//------------------------------------------------------------------------------ + +// Standard Includes ----------------------------------------------------------- +#include +#include + +// System Includes ------------------------------------------------------------- +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// Project Includes ------------------------------------------------------------ + +// Local Includes -------------------------------------------------------------- + +// Local Defines --------------------------------------------------------------- + +// Globals --------------------------------------------------------------------- + +struct _BPictureExtent_ { + void *fNewData; + int32 fNewSize; + void *fOldData; + int32 fOldSize; + BList fPictures; // In R5 this is a BArray which is completely + // inline. +}; + +status_t do_playback(void * data, int32 size, BList& pictures, + void **callBackTable, int32 tableEntries, void *user); + +//------------------------------------------------------------------------------ +BPicture::BPicture() + : token(-1), + extent(NULL), + usurped(NULL) +{ + extent = new _BPictureExtent_; + extent->fNewData = NULL; + extent->fNewSize = 0; + extent->fOldData = NULL; + extent->fOldSize = 0; +} +//------------------------------------------------------------------------------ +BPicture::BPicture(const BPicture &picture) + : token(-1), + extent(NULL), + usurped(NULL) +{ + init_data(); + + if (picture.token != -1) + { + + BPrivate::BAppServerLink link; + PortLink::ReplyData replydata; + + link.portlink->SetOpCode(AS_CLONE_PICTURE); + link.portlink->Attach(picture.token); + link.portlink->FlushWithReply(&replydata); + token=*((int32*)replydata.buffer); + + } + if (picture.extent->fNewData != NULL) + { + extent->fNewSize = picture.extent->fNewSize; + extent->fNewData = malloc(extent->fNewSize); + memcpy(extent->fNewData, picture.extent->fNewData, extent->fNewSize); + + BPicture *pic; + + for (int32 i = 0; i < picture.extent->fPictures.CountItems(); i++) + { + pic = new BPicture(*(BPicture*)picture.extent->fPictures.ItemAt(i)); + extent->fPictures.AddItem(pic); + } + } + else if (picture.extent->fOldData != NULL) + { + extent->fOldSize = picture.extent->fOldSize; + extent->fOldData = malloc(extent->fOldSize); + memcpy(extent->fOldData, picture.extent->fOldData, extent->fOldSize); + + // In old data the sub pictures are inside the data + } +} +//------------------------------------------------------------------------------ +BPicture::BPicture(BMessage *archive) + : token(-1), + extent(NULL), + usurped(NULL) +{ + init_data(); + + int32 version, size; + int8 endian; + const void *data; + + if (archive->FindInt32("_ver", &version) != B_OK) + version = 0; + + if (archive->FindInt8("_endian", &endian) != B_OK) + endian = 0; + + if (archive->FindData("_data", B_RAW_TYPE, &data, (ssize_t*)&size) != B_OK) + return; + + // Load sub pictures + BMessage picMsg; + int32 i = 0; + + while (archive->FindMessage("piclib", i++, &picMsg) == B_OK) + { + BPicture *pic = new BPicture(&picMsg); + extent->fPictures.AddItem(pic); + } + + if (version == 0) + import_old_data(data, size); + else if (version == 1) + { + extent->fNewSize = size; + extent->fNewData = malloc(extent->fNewSize); + memcpy(extent->fNewData, data, extent->fNewSize); + +// swap_data(extent->fNewData, extent->fNewSize); + + if (extent->fNewSize != 0 && extent->fNewData != 0) + { + BPrivate::BAppServerLink link; + PortLink::ReplyData replydata; + BPicture *pic; + + link.portlink->SetOpCode(AS_CREATE_PICTURE); + link.portlink->Attach(extent->fPictures.CountItems()); + for (int32 i = 0; i < extent->fPictures.CountItems(); i++) + { + pic=(BPicture*)extent->fPictures.ItemAt(i); + if(pic) + link.portlink->Attach(pic->token); + } + link.portlink->Attach(extent->fNewSize); + link.portlink->Attach(extent->fNewData,extent->fNewSize); + link.portlink->FlushWithReply(&replydata); + token=*((int32*)replydata.buffer); + } + } + + // Do we just free the data now? + if (extent->fNewData) + { + free(extent->fNewData); + extent->fNewData = NULL; + extent->fNewSize = 0; + } + + if (extent->fOldData) + { + free(extent->fOldData); + extent->fOldData = NULL; + extent->fOldSize = 0; + } + + // What with the sub pictures? + for (i = 0; i < extent->fPictures.CountItems(); i++) + delete extent->fPictures.ItemAt(i); + extent->fPictures.MakeEmpty(); +} +//------------------------------------------------------------------------------ +BPicture::~BPicture() +{ + if (token != -1) + { + BPrivate::BAppServerLink link; + + link.portlink->SetOpCode(AS_DELETE_PICTURE); + link.portlink->Attach(token); + link.portlink->Flush(); + } + + if (extent->fNewData != NULL) + { + free(extent->fNewData); + extent->fNewData = NULL; + extent->fNewSize = 0; + } + + if (extent->fOldData != NULL) + { + free(extent->fOldData); + extent->fOldData = NULL; + extent->fOldSize = 0; + } + + for (int32 i = 0; i < extent->fPictures.CountItems(); i++) + delete extent->fPictures.ItemAt(i); + extent->fPictures.MakeEmpty(); + + free(extent); +} +//------------------------------------------------------------------------------ +BArchivable *BPicture::Instantiate(BMessage *archive) +{ + if (validate_instantiation(archive, "BPicture")) + return new BPicture(archive); + else + return NULL; +} +//------------------------------------------------------------------------------ +status_t BPicture::Archive(BMessage *archive, bool deep) const +{ + if (!const_cast(this)->assert_local_copy()) + return B_ERROR; + + status_t err = BArchivable::Archive(archive, deep); + + if (err != B_OK) + return err; + + err = archive->AddInt32("_ver", 1); + + if (err != B_OK) + return err; + + err = archive->AddInt8("_endian", B_HOST_IS_BENDIAN); + + if (err != B_OK) + return err; + + err = archive->AddData("_data", B_RAW_TYPE, extent->fNewData, + extent->fNewSize); + + for (int32 i = 0; i < extent->fPictures.CountItems(); i++) + { + BMessage picMsg; + + ((BPicture*)extent->fPictures.ItemAt(i))->Archive(&picMsg, deep); + + archive->AddMessage("piclib", &picMsg); + } + + return err; +} +//------------------------------------------------------------------------------ +status_t BPicture::Perform(perform_code d, void *arg) +{ + return BArchivable::Perform(d, arg); +} +//------------------------------------------------------------------------------ +status_t BPicture::Play(void **callBackTable, int32 tableEntries, void *user) +{ + if (!assert_local_copy()) + return B_ERROR; + + return do_playback(extent->fNewData, extent->fNewSize, extent->fPictures, + callBackTable, tableEntries, user); +} +//------------------------------------------------------------------------------ +status_t BPicture::Flatten(BDataIO *stream) +{ + if (!assert_local_copy()) + return B_ERROR; + + // TODO check the header + int32 bla1 = 2; + int32 bla2 = 0; + int32 count = 0; + + stream->Write(&bla1, 4); + stream->Write(&bla2, 4); + + count = extent->fPictures.CountItems(); + stream->Write(&count, 4); + + for (int32 i = 0; i < extent->fPictures.CountItems(); i++) + ((BPicture*)extent->fPictures.ItemAt(i))->Flatten(stream); + + stream->Write(&extent->fNewSize, 4); + stream->Write(extent->fNewData, extent->fNewSize); + + return B_OK; +} +//------------------------------------------------------------------------------ +status_t BPicture::Unflatten(BDataIO *stream) +{ + // TODO check the header + int32 bla1 = 2; + int32 bla2 = 0; + int32 count = 0; + + stream->Read(&bla1, 4); + stream->Read(&bla2, 4); + + stream->Read(&count, 4); + + for (int32 i = 0; i < count; i++) + { + BPicture *pic = new BPicture; + + pic->Unflatten(stream); + + extent->fPictures.AddItem(pic); + } + + stream->Read(&extent->fNewSize, 4); + extent->fNewData = malloc(extent->fNewSize); + stream->Read(extent->fNewData, extent->fNewSize); + +// swap_data(extent->fNewData, extent->fNewSize); + + BPrivate::BAppServerLink link; + PortLink::ReplyData replydata; + BPicture *pic; + + link.portlink->SetOpCode(AS_CREATE_PICTURE); + link.portlink->Attach(extent->fPictures.CountItems()); + for (int32 i = 0; i < extent->fPictures.CountItems(); i++) + { + pic=(BPicture*)extent->fPictures.ItemAt(i); + if(pic) + link.portlink->Attach(pic->token); + } + link.portlink->Attach(extent->fNewSize); + link.portlink->Attach(extent->fNewData, extent->fNewSize); + link.portlink->FlushWithReply(&replydata); + token=*((int32*)replydata.buffer); + + if (extent->fNewData) + { + free(extent->fNewData); + extent->fNewData = NULL; + extent->fNewSize = 0; + } + + return B_OK; +} +//------------------------------------------------------------------------------ +void BPicture::_ReservedPicture1() {} +void BPicture::_ReservedPicture2() {} +void BPicture::_ReservedPicture3() {} +//------------------------------------------------------------------------------ +BPicture &BPicture::operator=(const BPicture &) +{ + return *this; +} +//------------------------------------------------------------------------------ +void BPicture::init_data() +{ + token = -1; + usurped = NULL; + + extent = new _BPictureExtent_; + extent->fNewData = NULL; + extent->fNewSize = 0; + extent->fOldData = NULL; + extent->fOldSize = 0; +} +//------------------------------------------------------------------------------ +void BPicture::import_data(const void *data, int32 size, BPicture **subs, + int32 subCount) +{ + if (data == NULL || size == 0) + return; + + BPrivate::BAppServerLink link; + PortLink::ReplyData replydata; + + link.portlink->SetOpCode(AS_CREATE_PICTURE); + link.portlink->Attach(subCount); + + for (int32 i = 0; i < subCount; i++) + link.portlink->Attach(subs[i]->token); + + link.portlink->Attach(size); + link.portlink->Attach(data, size); + link.portlink->FlushWithReply(&replydata); + token=*((int32*)replydata.buffer); +} +//------------------------------------------------------------------------------ +void BPicture::import_old_data(const void *data, int32 size) +{ + // TODO: do we need to support old data, what is old data? + /*if (data == NULL) + return; + + if (size == 0) + return; + + convert_old_to_new(data, size, &extent->fNewData, &extent->fNewSize); + + BPrivate::BAppServerLink link; + PortLink::ReplyData replydata; + + link.portlink->SetOpCode(AS_CREATE_PICTURE); + link.portlink->Attach(0L); + link.portlink->Attach(extent->fNewSize); + link.portlink->Attach(extent->fNewData,extent->fNewSize); + link.portlink->FlushWithReply(&replydata); + token=*((int32*)replydata.buffer); + + // Do we free all data now? + free(extent->fNewData); + extent->fNewData = 0; + extent->fNewSize = 0; + free(extent->fOldData); + extent->fOldData = 0; + extent->fOldSize = 0;*/ +} +//------------------------------------------------------------------------------ +void BPicture::set_token(int32 _token) +{ + token = _token; +} +//------------------------------------------------------------------------------ +bool BPicture::assert_local_copy() +{ + if (extent->fNewData != NULL) + return true; + + if (token == -1) + return false; + +/* BPrivate::BAppServerLink link; + PortLink::ReplyData replydata; + int32 count; + + link.portlink->SetOpCode(AS_DOWNLOAD_PICTURE); + link.portlink->Attach(token); + link.portlink->FlushWithReply(&replydata); + count=*((int32*)replydata.buffer); + + // Read sub picture tokens + for (int32 i = 0; i < count; i++) + { + BPicture *pic = new BPicture; + + link.sread(4, &pic->token); + + extent->fPictures.AddItem(pic); + } + + link.sread(4, &extent->fNewSize); + extent->fNewData = malloc(extent->fNewSize); + link.sread(extent->fNewSize, &extent->fNewData);*/ + + return true; +} +//------------------------------------------------------------------------------ +bool BPicture::assert_old_local_copy() +{ + if (extent->fOldData != NULL) + return true; + + if (!assert_local_copy()) + return false; + +// convert_new_to_old(extent->fNewData, extent->fNewSize, extent->fOldData, +// extent->fOldSize); + + return true; +} +//------------------------------------------------------------------------------ +bool BPicture::assert_server_copy() +{ + if (token != -1) + return true; + + if (extent->fNewData == NULL) + return false; + +/* for (int32 i = 0; i < extent->fPictures.CountItems(); i++) + extent->fPictures.ItemAt(i)->assert_server_copy(); + + BPrivate::BAppServerLink link; + PortLink::ReplyData replydata; + + link.portlink->SetOpCode(AS_CREATE_PICTURE); + link.portlink->Attach(extent->fPictures.CountItems()); + for (int32 i = 0; i < extent->fPictures.CountItems(); i++) + link.portlink->Attach(extent->fPictures.ItemAt(i)->token); + link.portlink->Attach(extent->fNewSize); + link.portlink->Attach(extent->fNewData,extent->fNewSize); + link.portlink->FlushWithReply(&replydata); + token=*((int32*)replydata.buffer); + + return token != -1;*/ + return true; +} +//------------------------------------------------------------------------------ +BPicture::BPicture(const void *data, int32 size) +{ + init_data(); + import_old_data(data, size); +} +//------------------------------------------------------------------------------ +const void *BPicture::Data() const +{ + if (extent->fNewData == NULL) + { + const_cast(this)->assert_local_copy(); + //convert_new_to_old(void *, long, void **, long *); + } + + return extent->fNewData; +} +//------------------------------------------------------------------------------ +int32 BPicture::DataSize() const +{ + if (extent->fNewData == NULL) + { + const_cast(this)->assert_local_copy(); + //convert_new_to_old(void *, long, void **, long *); + } + + return extent->fNewSize; +} +//------------------------------------------------------------------------------ +void BPicture::usurp(BPicture *lameDuck) +{ + if (token != -1) + { + BPrivate::BAppServerLink link; + + link.portlink->SetOpCode(AS_DELETE_PICTURE); + link.portlink->Attach(token); + link.portlink->Flush(); + } + + if (extent->fNewData != NULL) + { + free(extent->fNewData); + extent->fNewData = NULL; + extent->fNewSize = 0; + } + + if (extent->fOldData != NULL) + { + free(extent->fOldData); + extent->fOldData = NULL; + extent->fOldSize = 0; + } + + for (int32 i = 0; i < extent->fPictures.CountItems(); i++) + delete extent->fPictures.ItemAt(i); + extent->fPictures.MakeEmpty(); + + free(extent); + + init_data(); + + // Do the usurping + usurped = lameDuck; +} +//------------------------------------------------------------------------------ +BPicture *BPicture::step_down() +{ + BPicture *lameDuck = usurped; + + usurped = NULL; + + return lameDuck; +} +//------------------------------------------------------------------------------ +status_t do_playback(void * data, int32 size, BList& pictures, + void **callBackTable, int32 tableEntries, void *user) +{ + TPicture pic(data, size, pictures); + + return pic.Play(callBackTable, tableEntries, user); +} +//------------------------------------------------------------------------------ + + diff --git a/src/kits/interface/ScrollBar.cpp b/src/kits/interface/ScrollBar.cpp index e5177ca479..4bb3cdbf05 100644 --- a/src/kits/interface/ScrollBar.cpp +++ b/src/kits/interface/ScrollBar.cpp @@ -172,7 +172,7 @@ BArchivable *BScrollBar::Instantiate(BMessage *data) return NULL; } -status_t BScrollBar::Archive(BMessage *data, bool deep = true) const +status_t BScrollBar::Archive(BMessage *data, bool deep) const { return B_ERROR; } @@ -481,6 +481,10 @@ void BScrollBar::ResizeToPreferred() void BScrollBar::GetPreferredSize(float *width, float *height) { + if (fOrientation == B_VERTICAL) + *width = B_V_SCROLL_BAR_WIDTH; + else if (fOrientation == B_HORIZONTAL) + *height = B_H_SCROLL_BAR_HEIGHT; } void BScrollBar::MakeFocus(bool state) diff --git a/src/kits/interface/Shape.cpp b/src/kits/interface/Shape.cpp index e206605ad7..023444b382 100644 --- a/src/kits/interface/Shape.cpp +++ b/src/kits/interface/Shape.cpp @@ -24,11 +24,11 @@ // Description: BShape encapsulates a Postscript-style "path" //------------------------------------------------------------------------------ -#include "Shape.h" -#include "Point.h" -#include "Rect.h" -#include -#include +#include +#include +#include +#include +#include #define OP_LINETO 0x10000000 #define OP_BEZIERTO 0x20000000 diff --git a/src/kits/interface/Slider.cpp b/src/kits/interface/Slider.cpp index b39fbc9fd2..49a88d10c0 100644 --- a/src/kits/interface/Slider.cpp +++ b/src/kits/interface/Slider.cpp @@ -25,7 +25,7 @@ //------------------------------------------------------------------------------ // Standard Includes ----------------------------------------------------------- -#include +#include #include // System Includes ------------------------------------------------------------- diff --git a/src/kits/interface/StatusBar.cpp b/src/kits/interface/StatusBar.cpp index 0b8e6a10d7..45f06fcfc4 100644 --- a/src/kits/interface/StatusBar.cpp +++ b/src/kits/interface/StatusBar.cpp @@ -1,581 +1,581 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2001-2002, OpenBeOS -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -// -// File Name: StatusBar.cpp -// Author: Marc Flerackers (mflerackers@androme.be) -// Description: BStatusBar displays a "percentage-of-completion" gauge. -//------------------------------------------------------------------------------ - -// Standard Includes ----------------------------------------------------------- -#include -#include - -// System Includes ------------------------------------------------------------- -#include -#include -#include - -// Project Includes ------------------------------------------------------------ - -// Local Includes -------------------------------------------------------------- - -// Local Defines --------------------------------------------------------------- - -// Globals --------------------------------------------------------------------- - -//------------------------------------------------------------------------------ -BStatusBar::BStatusBar(BRect frame, const char *name, const char *label, - const char *trailingLabel) - : BView(frame, name, B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW), - fText(NULL), - fTrailingText(NULL), - fMax(100.0f), - fCurrent(0.0f), - fBarHeight(-1.0f), - fTrailingWidth(-1.0f), - fEraseText(-1.0f), - fEraseTrailingText(-1.0f), - fCustomBarHeight(false) - -{ - fLabel = strdup(label); - fTrailingLabel = strdup(trailingLabel); - - fBarColor.red = 50; - fBarColor.green = 150; - fBarColor.blue = 255; - fBarColor.alpha = 255; -} -//------------------------------------------------------------------------------ -BStatusBar::BStatusBar(BMessage *archive) - : BView(archive), - fTrailingWidth(-1.0f), - fEraseText(-1.0f), - fEraseTrailingText(-1.0f), - fCustomBarHeight(false) -{ - if (archive->FindFloat("_high", &fBarHeight) != B_OK) - fBarHeight = -1.0f; - - const void *ptr; - - if (archive->FindData("_bcolor", B_INT32_TYPE, &ptr, NULL ) != B_OK) - { - fBarColor.red = 50; - fBarColor.green = 150; - fBarColor.blue = 255; - fBarColor.alpha = 255; - } - else - memcpy(&fBarColor, ptr, sizeof(rgb_color)); - - if (archive->FindFloat("_val", &fCurrent) != B_OK) - fCurrent = 0.0f; - - if (archive->FindFloat("_max", &fMax) != B_OK) - fMax = 100.0f; - - const char *string; - - if (archive->FindString("_text", &string) != B_OK) - fText = NULL; - else - fText = strdup(string); - - if (archive->FindString("_ttext", &string) != B_OK) - fTrailingText = NULL; - else - fTrailingText = strdup(string); - - if (archive->FindString("_label", &string) != B_OK) - fLabel = NULL; - else - fLabel = strdup(string); - - if ( archive->FindString("_tlabel", &string) != B_OK) - fTrailingLabel = NULL; - else - fTrailingLabel = strdup(string); -} -//------------------------------------------------------------------------------ -BStatusBar::~BStatusBar() -{ - if (fLabel) - free(fLabel); - - if (fTrailingLabel) - free(fTrailingLabel); - - if (fText) - free(fText); - - if (fTrailingText) - free(fTrailingText); -} -//------------------------------------------------------------------------------ -BArchivable *BStatusBar::Instantiate(BMessage *archive) -{ - if (validate_instantiation(archive, "BStatusBar")) - return new BStatusBar(archive); - - return NULL; -} -//------------------------------------------------------------------------------ -status_t BStatusBar::Archive(BMessage *archive, bool deep) const -{ - status_t err = BView::Archive(archive, deep); - - if (err != B_OK) - return err; - - if (fBarHeight != 16.0f) - err = archive->AddFloat("_high", fBarHeight); - - if (err != B_OK) - return err; - - // TODO: Should we compare the color with (50, 150, 255) ? - err = archive->AddData("_bcolor", B_INT32_TYPE, &fBarColor, sizeof( int32 )); - - if (err != B_OK) - return err; - - if (fCurrent != 0.0f) - err = archive->AddFloat("_val", fCurrent); - - if (err != B_OK) - return err; - - if (fMax != 100.0f ) - err = archive->AddFloat("_max", fMax); - - if (err != B_OK) - return err; - - if (fText ) - err = archive->AddString("_text", fText); - - if (err != B_OK) - return err; - - if (fTrailingText) - err = archive->AddString("_ttext", fTrailingText); - - if (err != B_OK) - return err; - - if (fLabel) - err = archive->AddString("_label", fLabel); - - if (err != B_OK) - return err; - - if (fTrailingLabel) - err = archive->AddString ("_tlabel", fTrailingLabel); - - return err; -} -//------------------------------------------------------------------------------ -void BStatusBar::AttachedToWindow() -{ - float width, height; - GetPreferredSize(&width, &height); - ResizeTo(Frame().Width(), height); - - if (Parent()) - SetViewColor(Parent ()->ViewColor()); -} -//------------------------------------------------------------------------------ -void BStatusBar::MessageReceived(BMessage *message) -{ - switch(message->what) - { - case B_UPDATE_STATUS_BAR: - { - float delta; - const char *text = NULL, *trailing_text = NULL; - - message->FindFloat("delta", &delta); - message->FindString("text", &text); - message->FindString("trailing text", &trailing_text); - - Update(delta, text, trailing_text); - - break; - } - case B_RESET_STATUS_BAR: - { - const char *label = NULL, *trailing_label = NULL; - - message->FindString("label", &label); - message->FindString("trailing label", &trailing_label); - - Reset(label, trailing_label); - - break; - } - default: - BView::MessageReceived ( message ); - } -} -//------------------------------------------------------------------------------ -void BStatusBar::Draw(BRect updateRect) -{ - float width = Frame().Width(); - font_height fh; - GetFontHeight(&fh); - - SetHighColor(0, 0, 0); - MovePenTo(2.0f, (float)ceil(fh.ascent) + 1.0f); - - if (fLabel) - DrawString(fLabel); - if (fText) - DrawString(fText); - - if (fTrailingText) - { - if (fTrailingLabel) - { - MovePenTo(width - StringWidth(fTrailingText) - - StringWidth(fTrailingLabel) - 2.0f, - (float)ceil(fh.ascent) + 1.0f); - DrawString(fTrailingText); - DrawString(fTrailingLabel); - } - else - { - MovePenTo(width - StringWidth(fTrailingText) - 2.0f, - (float)ceil(fh.ascent) + 1.0f); - DrawString(fTrailingText); - } - - } - else if (fTrailingLabel) - { - MovePenTo(width - StringWidth(fTrailingLabel) - 2.0f, - (float)ceil(fh.ascent) + 1.0f); - DrawString(fTrailingLabel); - } - - BRect rect(0.0f, (float)ceil(fh.ascent) + 4.0f, width, - (float)ceil(fh.ascent) + 4.0f + fBarHeight); - - // First bevel - SetHighColor(tint_color(ui_color ( B_PANEL_BACKGROUND_COLOR ), B_DARKEN_1_TINT)); - StrokeLine(BPoint(rect.left, rect.bottom), BPoint(rect.left, rect.top)); - StrokeLine(BPoint(rect.right, rect.top)); - - SetHighColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_LIGHTEN_2_TINT)); - StrokeLine(BPoint(rect.left + 1.0f, rect.bottom), BPoint(rect.right, rect.bottom)); - StrokeLine(BPoint(rect.right, rect.top + 1.0f)); - - rect.InsetBy(1.0f, 1.0f); - - // Second bevel - SetHighColor(tint_color(ui_color ( B_PANEL_BACKGROUND_COLOR ), B_DARKEN_4_TINT)); - StrokeLine(BPoint(rect.left, rect.bottom), BPoint(rect.left, rect.top)); - StrokeLine(BPoint(rect.right, rect.top)); - - SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - StrokeLine(BPoint(rect.left + 1.0f, rect.bottom), BPoint(rect.right, rect.bottom)); - StrokeLine(BPoint(rect.right, rect.top + 1.0f)); - - rect.InsetBy(1.0f, 1.0f); - - // Filling - SetHighColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_LIGHTEN_MAX_TINT)); - FillRect(rect); - - if (fCurrent != 0.0f) - { - rect.right = rect.left + (float)ceil(fCurrent * (width - 4) / fMax), - - // Bevel - SetHighColor(tint_color(fBarColor, B_LIGHTEN_2_TINT)); - StrokeLine(BPoint(rect.left, rect.bottom), BPoint(rect.left, rect.top)); - StrokeLine(BPoint(rect.right, rect.top)); - - SetHighColor(tint_color(fBarColor, B_DARKEN_2_TINT)); - StrokeLine(BPoint(rect.left, rect.bottom), BPoint(rect.right, rect.bottom)); - StrokeLine(BPoint(rect.right, rect.top)); - - rect.InsetBy(1.0f, 1.0f); - - // Filling - SetHighColor(fBarColor); - FillRect(rect); - } -} -//------------------------------------------------------------------------------ -void BStatusBar::SetBarColor(rgb_color color) -{ - memcpy(&fBarColor, &color, sizeof(rgb_color)); - - Invalidate(); -} -//------------------------------------------------------------------------------ -void BStatusBar::SetBarHeight(float height) -{ - BRect frame = Frame(); - - fBarHeight = height; - fCustomBarHeight = true; - ResizeTo(frame.Width(), fBarHeight + 16); -} -//------------------------------------------------------------------------------ -void BStatusBar::SetText ( const char *string ) -{ - if (fText) - free(fText); - - fText = strdup(string); - - Invalidate(); -} -//------------------------------------------------------------------------------ -void BStatusBar::SetTrailingText(const char *string) -{ - if (fTrailingText) - free(fTrailingText); - - fTrailingText = strdup(string); - - Invalidate(); -} -//------------------------------------------------------------------------------ -void BStatusBar::SetMaxValue(float max) -{ - fMax = max; - - Invalidate(); -} -//------------------------------------------------------------------------------ -void BStatusBar::Update(float delta, const char *text, const char *trailingText) -{ - fCurrent += delta; - - if (fCurrent > fMax) - fCurrent = fMax; - - if (fText) - free(fText); - - fText = strdup(text); - - if (fTrailingText) - free(fTrailingText); - - fTrailingText = strdup(trailingText); - - Invalidate(); -} -//------------------------------------------------------------------------------ -void BStatusBar::Reset(const char *label, const char *trailingLabel) -{ - if (fLabel) - free(fLabel); - - fLabel = strdup(label); - - if (fTrailingLabel) - free(fTrailingLabel); - - fTrailingLabel = strdup(trailingLabel); - - fCurrent = 0.0f; - - Invalidate(); -} -float BStatusBar::CurrentValue() const -{ - return fCurrent; -} -//------------------------------------------------------------------------------ -float BStatusBar::MaxValue() const -{ - return fMax; -} -//------------------------------------------------------------------------------ -rgb_color BStatusBar::BarColor() const -{ - return fBarColor; -} -//------------------------------------------------------------------------------ -float BStatusBar::BarHeight() const -{ - if (!fCustomBarHeight && fBarHeight == -1.0f) - { - font_height fh; - GetFontHeight(&fh); - ((BStatusBar*)this)->fBarHeight = fh.ascent + fh.descent + 6.0f; - } - - return fBarHeight; -} -//------------------------------------------------------------------------------ -const char *BStatusBar::Text() const -{ - return fText; -} -//------------------------------------------------------------------------------ -const char *BStatusBar::TrailingText() const -{ - return fTrailingText; -} -//------------------------------------------------------------------------------ -const char *BStatusBar::Label() const -{ - return fLabel; -} -//------------------------------------------------------------------------------ -const char *BStatusBar::TrailingLabel() const -{ - return fTrailingLabel; -} -//------------------------------------------------------------------------------ -void BStatusBar::MouseDown(BPoint point) -{ - BView::MouseDown(point); -} -//------------------------------------------------------------------------------ -void BStatusBar::MouseUp(BPoint point) -{ - BView::MouseUp(point); -} -//------------------------------------------------------------------------------ -void BStatusBar::WindowActivated(bool state) -{ - BView::WindowActivated(state); -} -//------------------------------------------------------------------------------ -void BStatusBar::MouseMoved(BPoint point, uint32 transit, - const BMessage *message) -{ - BView::MouseMoved(point, transit, message); -} -//------------------------------------------------------------------------------ -void BStatusBar::DetachedFromWindow() -{ - BView::DetachedFromWindow(); -} -//------------------------------------------------------------------------------ -void BStatusBar::FrameMoved(BPoint new_position) -{ - BView::FrameMoved(new_position); -} -//------------------------------------------------------------------------------ -void BStatusBar::FrameResized(float new_width, float new_height) -{ - BView::FrameResized(new_width, new_height); -} -//------------------------------------------------------------------------------ -BHandler *BStatusBar::ResolveSpecifier(BMessage *message, int32 index, - BMessage *specifier, - int32 what, const char *property) -{ - return BView::ResolveSpecifier(message, index, specifier, what, property); -} -//------------------------------------------------------------------------------ -void BStatusBar::ResizeToPreferred() -{ - BView::ResizeToPreferred(); -} -//------------------------------------------------------------------------------ -void BStatusBar::GetPreferredSize(float *width, float *height) -{ - font_height fh; - GetFontHeight(&fh); - - *width = (fLabel ? (float)ceil(StringWidth(fLabel)) : 0.0f) + - (fTrailingLabel ? (float)ceil(StringWidth(fTrailingLabel)) : 0.0f) + - 7.0f; - *height = fh.ascent + fh.descent + 5.0f + BarHeight(); -} -//------------------------------------------------------------------------------ -void BStatusBar::MakeFocus(bool state) -{ - BView::MakeFocus(state); -} -//------------------------------------------------------------------------------ -void BStatusBar::AllAttached() -{ - BView::AllAttached(); -} -//------------------------------------------------------------------------------ -void BStatusBar::AllDetached() -{ - BView::AllDetached(); -} -//------------------------------------------------------------------------------ -status_t BStatusBar::GetSupportedSuites(BMessage *data) -{ - return BView::GetSupportedSuites(data); -} -//------------------------------------------------------------------------------ -status_t BStatusBar::Perform(perform_code d, void *arg) -{ - return B_ERROR; -} -//------------------------------------------------------------------------------ -void BStatusBar::_ReservedStatusBar1() {} -void BStatusBar::_ReservedStatusBar2() {} -void BStatusBar::_ReservedStatusBar3() {} -void BStatusBar::_ReservedStatusBar4() {} - -//------------------------------------------------------------------------------ -BStatusBar &BStatusBar::operator=(const BStatusBar &) -{ - return *this; -} -//------------------------------------------------------------------------------ -void BStatusBar::InitObject(const char *l, const char *aux_l) -{ - // TODO: -} -//------------------------------------------------------------------------------ -void BStatusBar::SetTextData(char **pp, const char *str) -{ - // TODO: -} -//------------------------------------------------------------------------------ -void BStatusBar::FillBar(BRect r) -{ - // TODO: -} -//------------------------------------------------------------------------------ -void BStatusBar::Resize() -{ - // TODO: -} -//------------------------------------------------------------------------------ -void BStatusBar::_Draw(BRect updateRect, bool bar_only) -{ - // TODO: -} -//------------------------------------------------------------------------------ - -/* - * $Log $ - * - * $Id $ - * - */ +//------------------------------------------------------------------------------ +// Copyright (c) 2001-2002, OpenBeOS +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. +// +// File Name: StatusBar.cpp +// Author: Marc Flerackers (mflerackers@androme.be) +// Description: BStatusBar displays a "percentage-of-completion" gauge. +//------------------------------------------------------------------------------ + +// Standard Includes ----------------------------------------------------------- +#include +#include + +// System Includes ------------------------------------------------------------- +#include +#include +#include + +// Project Includes ------------------------------------------------------------ + +// Local Includes -------------------------------------------------------------- + +// Local Defines --------------------------------------------------------------- + +// Globals --------------------------------------------------------------------- + +//------------------------------------------------------------------------------ +BStatusBar::BStatusBar(BRect frame, const char *name, const char *label, + const char *trailingLabel) + : BView(frame, name, B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW), + fText(NULL), + fTrailingText(NULL), + fMax(100.0f), + fCurrent(0.0f), + fBarHeight(-1.0f), + fTrailingWidth(-1.0f), + fEraseText(-1.0f), + fEraseTrailingText(-1.0f), + fCustomBarHeight(false) + +{ + fLabel = strdup(label); + fTrailingLabel = strdup(trailingLabel); + + fBarColor.red = 50; + fBarColor.green = 150; + fBarColor.blue = 255; + fBarColor.alpha = 255; +} +//------------------------------------------------------------------------------ +BStatusBar::BStatusBar(BMessage *archive) + : BView(archive), + fTrailingWidth(-1.0f), + fEraseText(-1.0f), + fEraseTrailingText(-1.0f), + fCustomBarHeight(false) +{ + if (archive->FindFloat("_high", &fBarHeight) != B_OK) + fBarHeight = -1.0f; + + const void *ptr; + + if (archive->FindData("_bcolor", B_INT32_TYPE, &ptr, NULL ) != B_OK) + { + fBarColor.red = 50; + fBarColor.green = 150; + fBarColor.blue = 255; + fBarColor.alpha = 255; + } + else + memcpy(&fBarColor, ptr, sizeof(rgb_color)); + + if (archive->FindFloat("_val", &fCurrent) != B_OK) + fCurrent = 0.0f; + + if (archive->FindFloat("_max", &fMax) != B_OK) + fMax = 100.0f; + + const char *string; + + if (archive->FindString("_text", &string) != B_OK) + fText = NULL; + else + fText = strdup(string); + + if (archive->FindString("_ttext", &string) != B_OK) + fTrailingText = NULL; + else + fTrailingText = strdup(string); + + if (archive->FindString("_label", &string) != B_OK) + fLabel = NULL; + else + fLabel = strdup(string); + + if ( archive->FindString("_tlabel", &string) != B_OK) + fTrailingLabel = NULL; + else + fTrailingLabel = strdup(string); +} +//------------------------------------------------------------------------------ +BStatusBar::~BStatusBar() +{ + if (fLabel) + free(fLabel); + + if (fTrailingLabel) + free(fTrailingLabel); + + if (fText) + free(fText); + + if (fTrailingText) + free(fTrailingText); +} +//------------------------------------------------------------------------------ +BArchivable *BStatusBar::Instantiate(BMessage *archive) +{ + if (validate_instantiation(archive, "BStatusBar")) + return new BStatusBar(archive); + + return NULL; +} +//------------------------------------------------------------------------------ +status_t BStatusBar::Archive(BMessage *archive, bool deep) const +{ + status_t err = BView::Archive(archive, deep); + + if (err != B_OK) + return err; + + if (fBarHeight != 16.0f) + err = archive->AddFloat("_high", fBarHeight); + + if (err != B_OK) + return err; + + // TODO: Should we compare the color with (50, 150, 255) ? + err = archive->AddData("_bcolor", B_INT32_TYPE, &fBarColor, sizeof( int32 )); + + if (err != B_OK) + return err; + + if (fCurrent != 0.0f) + err = archive->AddFloat("_val", fCurrent); + + if (err != B_OK) + return err; + + if (fMax != 100.0f ) + err = archive->AddFloat("_max", fMax); + + if (err != B_OK) + return err; + + if (fText ) + err = archive->AddString("_text", fText); + + if (err != B_OK) + return err; + + if (fTrailingText) + err = archive->AddString("_ttext", fTrailingText); + + if (err != B_OK) + return err; + + if (fLabel) + err = archive->AddString("_label", fLabel); + + if (err != B_OK) + return err; + + if (fTrailingLabel) + err = archive->AddString ("_tlabel", fTrailingLabel); + + return err; +} +//------------------------------------------------------------------------------ +void BStatusBar::AttachedToWindow() +{ + float width, height; + GetPreferredSize(&width, &height); + ResizeTo(Frame().Width(), height); + + if (Parent()) + SetViewColor(Parent ()->ViewColor()); +} +//------------------------------------------------------------------------------ +void BStatusBar::MessageReceived(BMessage *message) +{ + switch(message->what) + { + case B_UPDATE_STATUS_BAR: + { + float delta; + const char *text = NULL, *trailing_text = NULL; + + message->FindFloat("delta", &delta); + message->FindString("text", &text); + message->FindString("trailing text", &trailing_text); + + Update(delta, text, trailing_text); + + break; + } + case B_RESET_STATUS_BAR: + { + const char *label = NULL, *trailing_label = NULL; + + message->FindString("label", &label); + message->FindString("trailing label", &trailing_label); + + Reset(label, trailing_label); + + break; + } + default: + BView::MessageReceived ( message ); + } +} +//------------------------------------------------------------------------------ +void BStatusBar::Draw(BRect updateRect) +{ + float width = Frame().Width(); + font_height fh; + GetFontHeight(&fh); + + SetHighColor(0, 0, 0); + MovePenTo(2.0f, (float)ceil(fh.ascent) + 1.0f); + + if (fLabel) + DrawString(fLabel); + if (fText) + DrawString(fText); + + if (fTrailingText) + { + if (fTrailingLabel) + { + MovePenTo(width - StringWidth(fTrailingText) - + StringWidth(fTrailingLabel) - 2.0f, + (float)ceil(fh.ascent) + 1.0f); + DrawString(fTrailingText); + DrawString(fTrailingLabel); + } + else + { + MovePenTo(width - StringWidth(fTrailingText) - 2.0f, + (float)ceil(fh.ascent) + 1.0f); + DrawString(fTrailingText); + } + + } + else if (fTrailingLabel) + { + MovePenTo(width - StringWidth(fTrailingLabel) - 2.0f, + (float)ceil(fh.ascent) + 1.0f); + DrawString(fTrailingLabel); + } + + BRect rect(0.0f, (float)ceil(fh.ascent) + 4.0f, width, + (float)ceil(fh.ascent) + 4.0f + fBarHeight); + + // First bevel + SetHighColor(tint_color(ui_color ( B_PANEL_BACKGROUND_COLOR ), B_DARKEN_1_TINT)); + StrokeLine(BPoint(rect.left, rect.bottom), BPoint(rect.left, rect.top)); + StrokeLine(BPoint(rect.right, rect.top)); + + SetHighColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_LIGHTEN_2_TINT)); + StrokeLine(BPoint(rect.left + 1.0f, rect.bottom), BPoint(rect.right, rect.bottom)); + StrokeLine(BPoint(rect.right, rect.top + 1.0f)); + + rect.InsetBy(1.0f, 1.0f); + + // Second bevel + SetHighColor(tint_color(ui_color ( B_PANEL_BACKGROUND_COLOR ), B_DARKEN_4_TINT)); + StrokeLine(BPoint(rect.left, rect.bottom), BPoint(rect.left, rect.top)); + StrokeLine(BPoint(rect.right, rect.top)); + + SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + StrokeLine(BPoint(rect.left + 1.0f, rect.bottom), BPoint(rect.right, rect.bottom)); + StrokeLine(BPoint(rect.right, rect.top + 1.0f)); + + rect.InsetBy(1.0f, 1.0f); + + // Filling + SetHighColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_LIGHTEN_MAX_TINT)); + FillRect(rect); + + if (fCurrent != 0.0f) + { + rect.right = rect.left + (float)ceil(fCurrent * (width - 4) / fMax), + + // Bevel + SetHighColor(tint_color(fBarColor, B_LIGHTEN_2_TINT)); + StrokeLine(BPoint(rect.left, rect.bottom), BPoint(rect.left, rect.top)); + StrokeLine(BPoint(rect.right, rect.top)); + + SetHighColor(tint_color(fBarColor, B_DARKEN_2_TINT)); + StrokeLine(BPoint(rect.left, rect.bottom), BPoint(rect.right, rect.bottom)); + StrokeLine(BPoint(rect.right, rect.top)); + + rect.InsetBy(1.0f, 1.0f); + + // Filling + SetHighColor(fBarColor); + FillRect(rect); + } +} +//------------------------------------------------------------------------------ +void BStatusBar::SetBarColor(rgb_color color) +{ + memcpy(&fBarColor, &color, sizeof(rgb_color)); + + Invalidate(); +} +//------------------------------------------------------------------------------ +void BStatusBar::SetBarHeight(float height) +{ + BRect frame = Frame(); + + fBarHeight = height; + fCustomBarHeight = true; + ResizeTo(frame.Width(), fBarHeight + 16); +} +//------------------------------------------------------------------------------ +void BStatusBar::SetText ( const char *string ) +{ + if (fText) + free(fText); + + fText = strdup(string); + + Invalidate(); +} +//------------------------------------------------------------------------------ +void BStatusBar::SetTrailingText(const char *string) +{ + if (fTrailingText) + free(fTrailingText); + + fTrailingText = strdup(string); + + Invalidate(); +} +//------------------------------------------------------------------------------ +void BStatusBar::SetMaxValue(float max) +{ + fMax = max; + + Invalidate(); +} +//------------------------------------------------------------------------------ +void BStatusBar::Update(float delta, const char *text, const char *trailingText) +{ + fCurrent += delta; + + if (fCurrent > fMax) + fCurrent = fMax; + + if (fText) + free(fText); + + fText = strdup(text); + + if (fTrailingText) + free(fTrailingText); + + fTrailingText = strdup(trailingText); + + Invalidate(); +} +//------------------------------------------------------------------------------ +void BStatusBar::Reset(const char *label, const char *trailingLabel) +{ + if (fLabel) + free(fLabel); + + fLabel = strdup(label); + + if (fTrailingLabel) + free(fTrailingLabel); + + fTrailingLabel = strdup(trailingLabel); + + fCurrent = 0.0f; + + Invalidate(); +} +float BStatusBar::CurrentValue() const +{ + return fCurrent; +} +//------------------------------------------------------------------------------ +float BStatusBar::MaxValue() const +{ + return fMax; +} +//------------------------------------------------------------------------------ +rgb_color BStatusBar::BarColor() const +{ + return fBarColor; +} +//------------------------------------------------------------------------------ +float BStatusBar::BarHeight() const +{ + if (!fCustomBarHeight && fBarHeight == -1.0f) + { + font_height fh; + GetFontHeight(&fh); + ((BStatusBar*)this)->fBarHeight = fh.ascent + fh.descent + 6.0f; + } + + return fBarHeight; +} +//------------------------------------------------------------------------------ +const char *BStatusBar::Text() const +{ + return fText; +} +//------------------------------------------------------------------------------ +const char *BStatusBar::TrailingText() const +{ + return fTrailingText; +} +//------------------------------------------------------------------------------ +const char *BStatusBar::Label() const +{ + return fLabel; +} +//------------------------------------------------------------------------------ +const char *BStatusBar::TrailingLabel() const +{ + return fTrailingLabel; +} +//------------------------------------------------------------------------------ +void BStatusBar::MouseDown(BPoint point) +{ + BView::MouseDown(point); +} +//------------------------------------------------------------------------------ +void BStatusBar::MouseUp(BPoint point) +{ + BView::MouseUp(point); +} +//------------------------------------------------------------------------------ +void BStatusBar::WindowActivated(bool state) +{ + BView::WindowActivated(state); +} +//------------------------------------------------------------------------------ +void BStatusBar::MouseMoved(BPoint point, uint32 transit, + const BMessage *message) +{ + BView::MouseMoved(point, transit, message); +} +//------------------------------------------------------------------------------ +void BStatusBar::DetachedFromWindow() +{ + BView::DetachedFromWindow(); +} +//------------------------------------------------------------------------------ +void BStatusBar::FrameMoved(BPoint new_position) +{ + BView::FrameMoved(new_position); +} +//------------------------------------------------------------------------------ +void BStatusBar::FrameResized(float new_width, float new_height) +{ + BView::FrameResized(new_width, new_height); +} +//------------------------------------------------------------------------------ +BHandler *BStatusBar::ResolveSpecifier(BMessage *message, int32 index, + BMessage *specifier, + int32 what, const char *property) +{ + return BView::ResolveSpecifier(message, index, specifier, what, property); +} +//------------------------------------------------------------------------------ +void BStatusBar::ResizeToPreferred() +{ + BView::ResizeToPreferred(); +} +//------------------------------------------------------------------------------ +void BStatusBar::GetPreferredSize(float *width, float *height) +{ + font_height fh; + GetFontHeight(&fh); + + *width = (fLabel ? (float)ceil(StringWidth(fLabel)) : 0.0f) + + (fTrailingLabel ? (float)ceil(StringWidth(fTrailingLabel)) : 0.0f) + + 7.0f; + *height = fh.ascent + fh.descent + 5.0f + BarHeight(); +} +//------------------------------------------------------------------------------ +void BStatusBar::MakeFocus(bool state) +{ + BView::MakeFocus(state); +} +//------------------------------------------------------------------------------ +void BStatusBar::AllAttached() +{ + BView::AllAttached(); +} +//------------------------------------------------------------------------------ +void BStatusBar::AllDetached() +{ + BView::AllDetached(); +} +//------------------------------------------------------------------------------ +status_t BStatusBar::GetSupportedSuites(BMessage *data) +{ + return BView::GetSupportedSuites(data); +} +//------------------------------------------------------------------------------ +status_t BStatusBar::Perform(perform_code d, void *arg) +{ + return B_ERROR; +} +//------------------------------------------------------------------------------ +void BStatusBar::_ReservedStatusBar1() {} +void BStatusBar::_ReservedStatusBar2() {} +void BStatusBar::_ReservedStatusBar3() {} +void BStatusBar::_ReservedStatusBar4() {} + +//------------------------------------------------------------------------------ +BStatusBar &BStatusBar::operator=(const BStatusBar &) +{ + return *this; +} +//------------------------------------------------------------------------------ +void BStatusBar::InitObject(const char *l, const char *aux_l) +{ + // TODO: +} +//------------------------------------------------------------------------------ +void BStatusBar::SetTextData(char **pp, const char *str) +{ + // TODO: +} +//------------------------------------------------------------------------------ +void BStatusBar::FillBar(BRect r) +{ + // TODO: +} +//------------------------------------------------------------------------------ +void BStatusBar::Resize() +{ + // TODO: +} +//------------------------------------------------------------------------------ +void BStatusBar::_Draw(BRect updateRect, bool bar_only) +{ + // TODO: +} +//------------------------------------------------------------------------------ + +/* + * $Log $ + * + * $Id $ + * + */