Allow setting a listener target and a modification message.
git-svn-id: http://svn.haiku-os.org/webpositive/webkit/trunk@457 94f232f2-1747-11df-bad5-a5bfde151594
This commit is contained in:
parent
1547f92b8e
commit
b0240c4936
@ -15,6 +15,7 @@
|
||||
#include <Box.h>
|
||||
#include <Catalog.h>
|
||||
#include <Locale.h>
|
||||
#include <Looper.h>
|
||||
#include <MenuField.h>
|
||||
#include <MenuItem.h>
|
||||
#include <PopUpMenu.h>
|
||||
@ -43,7 +44,9 @@ static const int32 kMsgSetSize = 'size';
|
||||
FontSelectionView::FontSelectionView(const char* name, const char* label,
|
||||
bool separateStyles, const BFont* currentFont)
|
||||
:
|
||||
BHandler(name)
|
||||
BHandler(name),
|
||||
fMessage(NULL),
|
||||
fTarget(NULL)
|
||||
{
|
||||
if (currentFont == NULL)
|
||||
fCurrentFont = _DefaultFont();
|
||||
@ -96,6 +99,8 @@ FontSelectionView::~FontSelectionView()
|
||||
delete fStylesMenuField;
|
||||
if (!fFontsMenuField->Window())
|
||||
delete fFontsMenuField;
|
||||
|
||||
delete fMessage;
|
||||
}
|
||||
|
||||
|
||||
@ -120,6 +125,7 @@ FontSelectionView::MessageReceived(BMessage* message)
|
||||
|
||||
fCurrentFont.SetSize(size);
|
||||
_UpdateFontPreview();
|
||||
_Invoke();
|
||||
break;
|
||||
}
|
||||
|
||||
@ -153,6 +159,8 @@ FontSelectionView::MessageReceived(BMessage* message)
|
||||
if (fStylesMenuField != NULL)
|
||||
_AddStylesToMenu(fCurrentFont, fStylesMenuField->Menu());
|
||||
}
|
||||
|
||||
_Invoke();
|
||||
break;
|
||||
}
|
||||
|
||||
@ -173,6 +181,7 @@ FontSelectionView::MessageReceived(BMessage* message)
|
||||
|
||||
fCurrentFont.SetFamilyAndStyle(family, style);
|
||||
_UpdateFontPreview();
|
||||
_Invoke();
|
||||
break;
|
||||
}
|
||||
|
||||
@ -182,6 +191,21 @@ FontSelectionView::MessageReceived(BMessage* message)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
FontSelectionView::SetMessage(BMessage* message)
|
||||
{
|
||||
delete fMessage;
|
||||
fMessage = message;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
FontSelectionView::SetTarget(BHandler* target)
|
||||
{
|
||||
fTarget = target;
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
@ -379,6 +403,16 @@ FontSelectionView::PreviewBox() const
|
||||
// #pragma mark - private
|
||||
|
||||
|
||||
void
|
||||
FontSelectionView::_Invoke()
|
||||
{
|
||||
if (fTarget != NULL && fTarget->Looper() != NULL && fMessage != NULL) {
|
||||
BMessage message(*fMessage);
|
||||
fTarget->Looper()->PostMessage(&message, fTarget);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BFont
|
||||
FontSelectionView::_DefaultFont() const
|
||||
{
|
||||
|
@ -35,6 +35,9 @@ public:
|
||||
void AttachedToLooper();
|
||||
virtual void MessageReceived(BMessage* message);
|
||||
|
||||
void SetMessage(BMessage* message);
|
||||
void SetTarget(BHandler* target);
|
||||
|
||||
void SetFont(const BFont& font, float size);
|
||||
void SetFont(const BFont& font);
|
||||
void SetSize(float size);
|
||||
@ -59,6 +62,8 @@ public:
|
||||
BView* PreviewBox() const;
|
||||
|
||||
private:
|
||||
void _Invoke();
|
||||
|
||||
BFont _DefaultFont() const;
|
||||
void _SelectCurrentFont(bool select);
|
||||
void _SelectCurrentSize(bool select);
|
||||
@ -78,6 +83,9 @@ protected:
|
||||
|
||||
BFont fSavedFont;
|
||||
BFont fCurrentFont;
|
||||
|
||||
BMessage* fMessage;
|
||||
BHandler* fTarget;
|
||||
};
|
||||
|
||||
#endif // FONT_SELECTION_VIEW_H
|
||||
|
Loading…
Reference in New Issue
Block a user