* Copyright (c) 1999-2000, Eric Moon.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __TIPMANAGERIMPL_H__
#define __TIPMANAGERIMPL_H__
#include <set>
#include <list>
#include <utility>
#include <Debug.h>
#include <SupportDefs.h>
#include <Font.h>
#include <Point.h>
#include <Rect.h>
#include <GraphicsDefs.h>
#include <String.h>
#include <View.h>
class BWindow;
class BMessageRunner;
#include "cortex_defs.h"
__BEGIN_CORTEX_NAMESPACE
class tip_entry {
public:
tip_entry(
BRect _rect,
const char* _text,
TipManager::offset_mode_t _offsetMode,
BPoint _offset,
uint32 _flags) :
rect(_rect),
text(_text),
offsetMode(_offsetMode),
offset(_offset),
flags(_flags) {}
tip_entry(
BRect _rect) :
rect(_rect) {}
tip_entry() {}
void dump(int indent) {
BString s;
s.SetTo('\t', indent);
PRINT((
"%stip_entry '%s'\n",
s.String(),
text.String()));
}
BRect rect;
BString text;
TipManager::offset_mode_t offsetMode;
BPoint offset;
uint32 flags;
};
class tip_entry_ptr_less_fn { public:
bool operator()(
const tip_entry* a,
const tip_entry* b) const {
if(a->rect.IsValid())
if(b->rect.IsValid()) {
if(a->rect.left == b->rect.left)
return a->rect.top > b->rect.top;
return a->rect.left > b->rect.left;
}
else
return true;
else
return false;
}
};
typedef std::set<tip_entry*, tip_entry_ptr_less_fn > tip_entry_set;
class _ViewEntry {
public:
virtual ~_ViewEntry();
_ViewEntry() {}
_ViewEntry(
BView* target,
_ViewEntry* parent) :
m_target(target),
m_parent(parent) {}
status_t add(
BView* view,
const tip_entry& entry);
status_t remove(
BView* view,
const BRect& rect);
std::pair<BView*, const tip_entry*> match(
BPoint point,
BPoint screenPoint);
BRect Frame();
BView* target() const { return m_target; }
_ViewEntry* parent() const { return m_parent; }
size_t countTips() const;
void dump(int indent);
private:
const tip_entry* fullFrameTip() const;
BView* m_target;
_ViewEntry* m_parent;
std::list<_ViewEntry*> m_childViews;
tip_entry_set m_tips;
};
class _WindowEntry {
public:
virtual ~_WindowEntry();
_WindowEntry() {}
_WindowEntry(
BWindow* target) :
m_target(target) {}
status_t add(
BView* view,
const tip_entry& entry);
status_t remove(
BView* view,
const BRect& rect);
std::pair<BView*, const tip_entry*> match(
BPoint screenPoint);
BWindow* target() const { return m_target; }
size_t countViews() const { return m_views.size(); }
void dump(int indent);
private:
BWindow* m_target;
std::list<_ViewEntry*> m_views;
};
class _TipManagerView :
public BView {
typedef BView _inherited;
public:
enum message_t {
M_TIME_PASSED
};
public:
virtual ~_TipManagerView();
_TipManagerView(
TipWindow* tipWindow,
TipManager* manager,
bigtime_t updatePeriod,
bigtime_t idlePeriod);
public:
status_t armTip(
const BRect& screenRect,
const char* text,
TipManager::offset_mode_t offsetMode,
BPoint offset,
uint32 flags);
status_t hideTip(
const BRect& screenRect);
status_t setTip(
const BRect& rect,
const char* text,
BView* view,
TipManager::offset_mode_t offsetMode,
BPoint offset,
uint32 flags);
status_t removeTip(
const BRect& rect,
BView* view);
status_t removeAll(
BWindow* window);
public:
void AttachedToWindow();
void KeyDown(
const char* bytes,
int32 count);
void MouseDown(
BPoint point);
void MouseMoved(
BPoint point,
uint32 orientation,
const BMessage* dragMessage);
public:
void MessageReceived(
BMessage* message);
private:
TipWindow* m_tipWindow;
TipManager* m_manager;
std::list<_WindowEntry*> m_windows;
BMessageRunner* m_messageRunner;
enum tip_window_state_t {
TIP_WINDOW_HIDDEN,
TIP_WINDOW_VISIBLE,
TIP_WINDOW_ARMED
};
tip_window_state_t m_tipWindowState;
bigtime_t m_updatePeriod;
bigtime_t m_idlePeriod;
BPoint m_lastMousePoint;
bigtime_t m_lastEventTime;
bool m_triggered;
BRect m_visibleTipRect;
tip_entry* m_armedTip;
private:
inline void _timePassed();
inline void _showTip(
const tip_entry* entry);
inline void _hideTip();
};
__END_CORTEX_NAMESPACE
#endif