1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
/*
Crystal Space Windowing System: floating hints class
Copyright (C) 2000 by Andrew Zabolotny <bit@eltech.ru>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __CSHINTS_H__
#define __CSHINTS_H__
#define CSWS_INTERNAL
#include "csws.h"
#include "cscomp.h"
#include "csutil/csvector.h"
/**
* This component will display "floating hints", which will vanish
* as soon as you move the mouse or press a key. A object of this class
* is automatically created by csComponent class when it detects that
* the mouse is unmoved for some time over some non-focused component
* that has an associated hint.
*/
class csHint : public csComponent
{
/// Old mouse owner (before the hint has popped up). Usually NULL.
csComponent *oldmo;
public:
/// Create a floating hint with an text string
csHint (csComponent *iParent, const char *iText, iFont *Font = NULL,
int iFontSize = -1);
/// Cleanup before destruction
virtual ~csHint ();
/// Draw the hint object
virtual void Draw ();
/// Handle all events before any others get a chance to eat it
virtual bool PreHandleEvent (iEvent &Event);
/// Set the text of the hint (also resizes the window)
virtual void SetText (const char *iText);
};
/// Default timeout for hints (in 1/1000 seconds)
#define CSHINT_DEFAULT_TIMEOUT 3000
/**
* The "hint manager" keeps track of all hints and associated components,
* and creates the appropiate csHint when it detects mouse is not moved
* for too long time.
*/
class csHintManager : public csVector
{
// This structure holds the data about one hint
struct HintStore
{
// The component associated with the hint
csComponent *comp;
// The text string starts right after the end of this structure
char text [1];
};
/// The application
csApp *app;
/// Last time when the mouse has been moved
csTicks time;
/// The timeout
csTicks timeout;
/// Font for hints
iFont *font;
/// Font size
int fontsize;
/// True if we haven't checked yet the component under the mouse
bool check;
public:
/// Initialize the hint manager object
csHintManager (csApp *iApp);
/// Destroy the hint manager
virtual ~csHintManager ();
/// Override FreeItem to correctly free hint store objects
virtual bool FreeItem (csSome Item);
/// Compare two hints (by csComponent's)
virtual int Compare (csSome Item1, csSome Item2, int Mode) const;
/// Compare a hint with a csComponent
virtual int CompareKey (csSome Item, csConstSome Key, int Mode) const;
/// Add a new hint
void Add (const char *iText, csComponent *iComp);
/// Remove the hint (if any) associated with this component
void Remove (csComponent *iComp);
/// Examine a mouse event
void HandleEvent (iEvent &Event);
/// Set hints timeout
void SetTimeout (csTicks iTimeout)
{ timeout = iTimeout; }
/// Set the font and font size for hints
void SetFont (iFont *iNewFont, int iSize);
private:
// Check if this child has an associated hint
static bool do_checkhint (csComponent *comp, void *data);
};
#endif // __CSHINTS_H__
|