Moved IconButton from LaunchBox (actually the updated version from WebPositive)
into libshared.a as BPrivate::BIconButton. Removed some outdated functionality as well (now only uses BControlLook for drawing, cleaned up custom drawing). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40587 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,42 +1,55 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2006, Haiku.
|
* Copyright 2006-2011, Haiku.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Stephan Aßmus <superstippi@gmx.de>
|
* Stephan Aßmus <superstippi@gmx.de>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** gui class that loads an image from disk and shows it
|
|
||||||
as clickable button */
|
|
||||||
|
|
||||||
// TODO: inherit from BControl?
|
|
||||||
|
|
||||||
// NOTE: this file is a duplicate of the version in Icon-O-Matic/generic
|
|
||||||
// it should be placed into a common folder for generic useful stuff
|
|
||||||
|
|
||||||
#ifndef ICON_BUTTON_H
|
#ifndef ICON_BUTTON_H
|
||||||
#define ICON_BUTTON_H
|
#define ICON_BUTTON_H
|
||||||
|
|
||||||
|
|
||||||
|
//! GUI class that loads an image from disk and shows it as clickable button.
|
||||||
|
|
||||||
|
// TODO: inherit from BControl
|
||||||
|
|
||||||
|
|
||||||
#include <Invoker.h>
|
#include <Invoker.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
#include <View.h>
|
#include <View.h>
|
||||||
|
|
||||||
|
|
||||||
class BBitmap;
|
class BBitmap;
|
||||||
class BMimeType;
|
class BMimeType;
|
||||||
|
|
||||||
class IconButton : public BView, public BInvoker {
|
|
||||||
|
namespace BPrivate {
|
||||||
|
|
||||||
|
|
||||||
|
class BIconButton : public BView, public BInvoker {
|
||||||
public:
|
public:
|
||||||
IconButton(const char* name,
|
BIconButton(const char* name,
|
||||||
uint32 id,
|
uint32 id,
|
||||||
const char* label = NULL,
|
const char* label = NULL,
|
||||||
BMessage* message = NULL,
|
BMessage* message = NULL,
|
||||||
BHandler* target = NULL);
|
BHandler* target = NULL);
|
||||||
virtual ~IconButton();
|
virtual ~BIconButton();
|
||||||
|
|
||||||
// BView interface
|
// BView interface
|
||||||
virtual void MessageReceived(BMessage* message);
|
virtual void MessageReceived(BMessage* message);
|
||||||
virtual void AttachedToWindow();
|
virtual void AttachedToWindow();
|
||||||
|
|
||||||
virtual void Draw(BRect updateRect);
|
virtual void Draw(BRect updateRect);
|
||||||
|
virtual bool ShouldDrawBorder() const;
|
||||||
|
virtual void DrawBorder(BRect& frame,
|
||||||
|
const BRect& updateRect,
|
||||||
|
const rgb_color& backgroundColor,
|
||||||
|
uint32 controlLookFlags);
|
||||||
|
virtual void DrawBackground(BRect& frame,
|
||||||
|
const BRect& updateRect,
|
||||||
|
const rgb_color& backgroundColor,
|
||||||
|
uint32 controlLookFlags);
|
||||||
|
|
||||||
virtual void MouseDown(BPoint where);
|
virtual void MouseDown(BPoint where);
|
||||||
virtual void MouseUp(BPoint where);
|
virtual void MouseUp(BPoint where);
|
||||||
virtual void MouseMoved(BPoint where, uint32 transit,
|
virtual void MouseMoved(BPoint where, uint32 transit,
|
||||||
@@ -50,7 +63,7 @@ public:
|
|||||||
// BInvoker interface
|
// BInvoker interface
|
||||||
virtual status_t Invoke(BMessage* message = NULL);
|
virtual status_t Invoke(BMessage* message = NULL);
|
||||||
|
|
||||||
// IconButton
|
// BIconButton
|
||||||
bool IsValid() const;
|
bool IsValid() const;
|
||||||
|
|
||||||
virtual int32 Value() const;
|
virtual int32 Value() const;
|
||||||
@@ -64,6 +77,7 @@ public:
|
|||||||
uint32 ID() const
|
uint32 ID() const
|
||||||
{ return fID; }
|
{ return fID; }
|
||||||
|
|
||||||
|
status_t SetIcon(int32 resourceID);
|
||||||
status_t SetIcon(const char* pathToBitmap);
|
status_t SetIcon(const char* pathToBitmap);
|
||||||
status_t SetIcon(const BBitmap* bitmap);
|
status_t SetIcon(const BBitmap* bitmap);
|
||||||
status_t SetIcon(const BMimeType* fileType,
|
status_t SetIcon(const BMimeType* fileType,
|
||||||
@@ -73,23 +87,11 @@ public:
|
|||||||
color_space format,
|
color_space format,
|
||||||
bool convertToBW = false);
|
bool convertToBW = false);
|
||||||
void ClearIcon();
|
void ClearIcon();
|
||||||
|
void TrimIcon(bool keepAspect = true);
|
||||||
|
|
||||||
BBitmap* Bitmap() const;
|
BBitmap* Bitmap() const;
|
||||||
// caller has to delete the returned bitmap
|
// caller has to delete the returned bitmap
|
||||||
|
const BString& Label() const;
|
||||||
virtual bool DrawBorder() const;
|
|
||||||
virtual void DrawNormalBorder(BRect r,
|
|
||||||
rgb_color background,
|
|
||||||
rgb_color shadow,
|
|
||||||
rgb_color darkShadow,
|
|
||||||
rgb_color lightShadow,
|
|
||||||
rgb_color light);
|
|
||||||
virtual void DrawPressedBorder(BRect r,
|
|
||||||
rgb_color background,
|
|
||||||
rgb_color shadow,
|
|
||||||
rgb_color darkShadow,
|
|
||||||
rgb_color lightShadow,
|
|
||||||
rgb_color light);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
enum {
|
enum {
|
||||||
@@ -105,19 +107,14 @@ protected:
|
|||||||
void _ClearFlags(uint32 flags);
|
void _ClearFlags(uint32 flags);
|
||||||
bool _HasFlags(uint32 flags) const;
|
bool _HasFlags(uint32 flags) const;
|
||||||
|
|
||||||
void _DrawFrame(BRect frame,
|
private:
|
||||||
rgb_color col1,
|
|
||||||
rgb_color col2,
|
|
||||||
rgb_color col3,
|
|
||||||
rgb_color col4);
|
|
||||||
|
|
||||||
// private:
|
|
||||||
BBitmap* _ConvertToRGB32(const BBitmap* bitmap) const;
|
BBitmap* _ConvertToRGB32(const BBitmap* bitmap) const;
|
||||||
status_t _MakeBitmaps(const BBitmap* bitmap);
|
status_t _MakeBitmaps(const BBitmap* bitmap);
|
||||||
void _DeleteBitmaps();
|
void _DeleteBitmaps();
|
||||||
void _SendMessage() const;
|
void _SendMessage() const;
|
||||||
void _Update();
|
void _Update();
|
||||||
|
|
||||||
|
private:
|
||||||
uint32 fButtonState;
|
uint32 fButtonState;
|
||||||
int32 fID;
|
int32 fID;
|
||||||
BBitmap* fNormalBitmap;
|
BBitmap* fNormalBitmap;
|
||||||
@@ -129,4 +126,11 @@ protected:
|
|||||||
BHandler* fTargetCache;
|
BHandler* fTargetCache;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} // namespac BPrivate
|
||||||
|
|
||||||
|
|
||||||
|
using BPrivate::BIconButton;
|
||||||
|
|
||||||
|
|
||||||
#endif // ICON_BUTTON_H
|
#endif // ICON_BUTTON_H
|
||||||
@@ -4,7 +4,6 @@ UsePrivateHeaders shared ;
|
|||||||
|
|
||||||
Application LaunchBox :
|
Application LaunchBox :
|
||||||
App.cpp
|
App.cpp
|
||||||
IconButton.cpp
|
|
||||||
LaunchButton.cpp
|
LaunchButton.cpp
|
||||||
main.cpp
|
main.cpp
|
||||||
MainWindow.cpp
|
MainWindow.cpp
|
||||||
@@ -20,7 +19,6 @@ DoCatalogs LaunchBox :
|
|||||||
x-vnd.Haiku-LaunchBox
|
x-vnd.Haiku-LaunchBox
|
||||||
:
|
:
|
||||||
App.cpp
|
App.cpp
|
||||||
IconButton.cpp
|
|
||||||
LaunchButton.cpp
|
LaunchButton.cpp
|
||||||
MainWindow.cpp
|
MainWindow.cpp
|
||||||
NamePanel.cpp
|
NamePanel.cpp
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ LaunchButton::sIgnoreDoubleClick = true;
|
|||||||
LaunchButton::LaunchButton(const char* name, uint32 id, const char* label,
|
LaunchButton::LaunchButton(const char* name, uint32 id, const char* label,
|
||||||
BMessage* message, BHandler* target)
|
BMessage* message, BHandler* target)
|
||||||
:
|
:
|
||||||
IconButton(name, id, label, message, target),
|
BIconButton(name, id, label, message, target),
|
||||||
fRef(NULL),
|
fRef(NULL),
|
||||||
fAppSig(NULL),
|
fAppSig(NULL),
|
||||||
fDescription(""),
|
fDescription(""),
|
||||||
@@ -65,7 +65,7 @@ LaunchButton::~LaunchButton()
|
|||||||
void
|
void
|
||||||
LaunchButton::AttachedToWindow()
|
LaunchButton::AttachedToWindow()
|
||||||
{
|
{
|
||||||
IconButton::AttachedToWindow();
|
BIconButton::AttachedToWindow();
|
||||||
_UpdateToolTip();
|
_UpdateToolTip();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,7 +85,7 @@ LaunchButton::Draw(BRect updateRect)
|
|||||||
ConstrainClippingRegion(®ion);
|
ConstrainClippingRegion(®ion);
|
||||||
}
|
}
|
||||||
if (IsValid()) {
|
if (IsValid()) {
|
||||||
IconButton::Draw(updateRect);
|
BIconButton::Draw(updateRect);
|
||||||
} else {
|
} else {
|
||||||
rgb_color background = LowColor();
|
rgb_color background = LowColor();
|
||||||
rgb_color lightShadow = tint_color(background,
|
rgb_color lightShadow = tint_color(background,
|
||||||
@@ -149,7 +149,7 @@ LaunchButton::MessageReceived(BMessage* message)
|
|||||||
case B_PASTE:
|
case B_PASTE:
|
||||||
case B_MODIFIERS_CHANGED:
|
case B_MODIFIERS_CHANGED:
|
||||||
default:
|
default:
|
||||||
IconButton::MessageReceived(message);
|
BIconButton::MessageReceived(message);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -177,7 +177,7 @@ LaunchButton::MouseDown(BPoint where)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (callInherited)
|
if (callInherited)
|
||||||
IconButton::MouseDown(where);
|
BIconButton::MouseDown(where);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -188,7 +188,7 @@ LaunchButton::MouseUp(BPoint where)
|
|||||||
fAnticipatingDrop = false;
|
fAnticipatingDrop = false;
|
||||||
Invalidate();
|
Invalidate();
|
||||||
}
|
}
|
||||||
IconButton::MouseUp(where);
|
BIconButton::MouseUp(where);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -238,11 +238,12 @@ LaunchButton::MouseMoved(BPoint where, uint32 transit,
|
|||||||
BMessage message(B_SIMPLE_DATA);
|
BMessage message(B_SIMPLE_DATA);
|
||||||
message.AddPointer("button", this);
|
message.AddPointer("button", this);
|
||||||
message.AddRef("refs", fRef);
|
message.AddRef("refs", fRef);
|
||||||
|
// DragMessage takes ownership of the bitmap.
|
||||||
DragMessage(&message, bitmap, B_OP_ALPHA, fDragStart);
|
DragMessage(&message, bitmap, B_OP_ALPHA, fDragStart);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
IconButton::MouseMoved(where, transit, dragMessage);
|
BIconButton::MouseMoved(where, transit, dragMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -262,11 +263,11 @@ LaunchButton::PreferredSize()
|
|||||||
float hPadding = max_c(6.0, ceilf(minHeight / 3.0));
|
float hPadding = max_c(6.0, ceilf(minHeight / 3.0));
|
||||||
float vPadding = max_c(6.0, ceilf(minWidth / 3.0));
|
float vPadding = max_c(6.0, ceilf(minWidth / 3.0));
|
||||||
|
|
||||||
if (fLabel.CountChars() > 0) {
|
if (Label().CountChars() > 0) {
|
||||||
font_height fh;
|
font_height fh;
|
||||||
GetFontHeight(&fh);
|
GetFontHeight(&fh);
|
||||||
minHeight += ceilf(fh.ascent + fh.descent) + vPadding;
|
minHeight += ceilf(fh.ascent + fh.descent) + vPadding;
|
||||||
minWidth += StringWidth(fLabel.String()) + vPadding;
|
minWidth += StringWidth(Label().String()) + vPadding;
|
||||||
}
|
}
|
||||||
|
|
||||||
return BSize(minWidth + hPadding, minHeight + vPadding);
|
return BSize(minWidth + hPadding, minHeight + vPadding);
|
||||||
@@ -427,3 +428,21 @@ LaunchButton::_NotifySettingsChanged()
|
|||||||
{
|
{
|
||||||
be_app->PostMessage(MSG_SETTINGS_CHANGED);
|
be_app->PostMessage(MSG_SETTINGS_CHANGED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
LaunchButton::_DrawFrame(BRect r, rgb_color col1, rgb_color col2,
|
||||||
|
rgb_color col3, rgb_color col4)
|
||||||
|
{
|
||||||
|
BeginLineArray(8);
|
||||||
|
AddLine(BPoint(r.left, r.bottom), BPoint(r.left, r.top), col1);
|
||||||
|
AddLine(BPoint(r.left + 1.0, r.top), BPoint(r.right, r.top), col1);
|
||||||
|
AddLine(BPoint(r.right, r.top + 1.0), BPoint(r.right, r.bottom), col2);
|
||||||
|
AddLine(BPoint(r.right - 1.0, r.bottom), BPoint(r.left + 1.0, r.bottom), col2);
|
||||||
|
r.InsetBy(1.0, 1.0);
|
||||||
|
AddLine(BPoint(r.left, r.bottom), BPoint(r.left, r.top), col3);
|
||||||
|
AddLine(BPoint(r.left + 1.0, r.top), BPoint(r.right, r.top), col3);
|
||||||
|
AddLine(BPoint(r.right, r.top + 1.0), BPoint(r.right, r.bottom), col4);
|
||||||
|
AddLine(BPoint(r.right - 1.0, r.bottom), BPoint(r.left + 1.0, r.bottom), col4);
|
||||||
|
EndLineArray();
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2006-2009, Stephan Aßmus <[email protected]>
|
* Copyright 2006-2011, Stephan Aßmus <[email protected]>
|
||||||
* All rights reserved. Distributed under the terms of the MIT License.
|
* All rights reserved. Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
#ifndef LAUNCH_BUTTON_H
|
#ifndef LAUNCH_BUTTON_H
|
||||||
#define LAUNCH_BUTTON_H
|
#define LAUNCH_BUTTON_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <IconButton.h>
|
||||||
#include <List.h>
|
#include <List.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
|
|
||||||
#include "IconButton.h"
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
MSG_ADD_SLOT = 'adsl',
|
MSG_ADD_SLOT = 'adsl',
|
||||||
@@ -17,7 +18,8 @@ enum {
|
|||||||
MSG_LAUNCH = 'lnch',
|
MSG_LAUNCH = 'lnch',
|
||||||
};
|
};
|
||||||
|
|
||||||
class LaunchButton : public IconButton {
|
|
||||||
|
class LaunchButton : public BIconButton {
|
||||||
public:
|
public:
|
||||||
LaunchButton(const char* name, uint32 id,
|
LaunchButton(const char* name, uint32 id,
|
||||||
const char* label = NULL,
|
const char* label = NULL,
|
||||||
@@ -25,7 +27,7 @@ public:
|
|||||||
BHandler* target = NULL);
|
BHandler* target = NULL);
|
||||||
virtual ~LaunchButton();
|
virtual ~LaunchButton();
|
||||||
|
|
||||||
// IconButton interface
|
// BIconButton interface
|
||||||
virtual void AttachedToWindow();
|
virtual void AttachedToWindow();
|
||||||
virtual void Draw(BRect updateRect);
|
virtual void Draw(BRect updateRect);
|
||||||
virtual void MessageReceived(BMessage* message);
|
virtual void MessageReceived(BMessage* message);
|
||||||
@@ -64,6 +66,11 @@ private:
|
|||||||
|
|
||||||
void _NotifySettingsChanged();
|
void _NotifySettingsChanged();
|
||||||
|
|
||||||
|
void _DrawFrame(BRect frame,
|
||||||
|
rgb_color left, rgb_color top,
|
||||||
|
rgb_color right, rgb_color bottom);
|
||||||
|
|
||||||
|
private:
|
||||||
entry_ref* fRef;
|
entry_ref* fRef;
|
||||||
char* fAppSig;
|
char* fAppSig;
|
||||||
BString fDescription;
|
BString fDescription;
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -3,7 +3,7 @@ SubDir HAIKU_TOP src kits shared ;
|
|||||||
SetSubDirSupportedPlatformsBeOSCompatible ;
|
SetSubDirSupportedPlatformsBeOSCompatible ;
|
||||||
AddSubDirSupportedPlatforms libbe_test ;
|
AddSubDirSupportedPlatforms libbe_test ;
|
||||||
|
|
||||||
UseLibraryHeaders agg ;
|
UseLibraryHeaders agg icon ;
|
||||||
UsePrivateHeaders shared libbe ;
|
UsePrivateHeaders shared libbe ;
|
||||||
UseHeaders [ FDirName $(HAIKU_COMMON_DEBUG_OBJECT_DIR) servers input ] ;
|
UseHeaders [ FDirName $(HAIKU_COMMON_DEBUG_OBJECT_DIR) servers input ] ;
|
||||||
UseHeaders [ FDirName $(HAIKU_TOP) src kits ] ;
|
UseHeaders [ FDirName $(HAIKU_TOP) src kits ] ;
|
||||||
@@ -19,6 +19,7 @@ StaticLibrary libshared.a :
|
|||||||
CommandPipe.cpp
|
CommandPipe.cpp
|
||||||
DragTrackingFilter.cpp
|
DragTrackingFilter.cpp
|
||||||
HashString.cpp
|
HashString.cpp
|
||||||
|
IconButton.cpp
|
||||||
Keymap.cpp
|
Keymap.cpp
|
||||||
NaturalCompare.cpp
|
NaturalCompare.cpp
|
||||||
QueryFile.cpp
|
QueryFile.cpp
|
||||||
|
|||||||
Reference in New Issue
Block a user