File: pgtooltiphelp.h

package info (click to toggle)
asc 2.6.1.0-9
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 81,740 kB
  • sloc: cpp: 158,704; sh: 11,544; ansic: 6,736; makefile: 604; perl: 138
file content (145 lines) | stat: -rw-r--r-- 3,853 bytes parent folder | download | duplicates (4)
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
    ParaGUI - crossplatform widgetset
    Copyright (C) 2000,2001,2002  Alexander Pipelka
 
    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
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
    Alexander Pipelka
    pipelka@teleweb.at
 
    Last Update:      $Author: mbickel $
    Update Date:      $Date: 2009-08-23 13:09:34 $
    Source File:      $Source: /home/martin/asc/v2/svntest/games/asc/source/libs/paragui/include/pgtooltiphelp.h,v $
    CVS/RCS Revision: $Revision: 1.4 $
    Status:           $State: Exp $
*/

/** \file pgwidget.h
 Header file for the PG_Widget class.
*/

#ifndef PG_TOOLTIPHELP_H
#define PG_TOOLTIPHELP_H

#include <map>

#include "pgmessageobject.h"
#include "pgtimerobject.h"
#include "pgpoint.h"

class PG_Widget;
class PG_LineEdit;


/**
 @author Martin Bickel
 
 @short ToolTip Help for widgets
 
 Displays ToolTip help that opens when a mouse cursor hovers over a widget. 
 It behaves similar to a PG_Widget, but it is not derived from it
        
 The ToolTipHelp will delete itself when the parent widget is deleted. 
 It is also safe to delete the ToolTipHelp object manually prior to deleting the widget. 
 
 @ToDo Query the cursor size and position the help so it doesn't overlap with large cursors
*/
class DECLSPEC PG_ToolTipHelp: public sigc::trackable {
private:

class Ticker: public PG_TimerObject {
		volatile Uint32 ticker;
		Uint32 eventTimer(Uint32 interval) {
			++ticker;
			return interval;
		};
	public:
		Ticker( int interval ) : ticker(0) {
			SetTimer( interval );
		};
		Uint32 getTicker() {
			return ticker;
		};
	};

	static Ticker* ticker;

	void startTimer();

        static std::map<const PG_Widget*,PG_ToolTipHelp*> tooltips;
        
protected:
	PG_Widget* parentWidget;
	PG_TimerObject::ID id;
	Uint32 lastTick;

	enum { off, counting, shown } status;

	std::string my_text;
	std::string labelStyle;

	int my_delay;

	static PG_LineEdit* toolTipLabel;

	bool onParentEnter( );
	bool onParentLeave( );
	bool onParentDelete( const PG_MessageObject* object );
	bool onMouseMotion( const PG_MessageObject* object, const SDL_MouseMotionEvent *motion );
	bool onIdle();


public:
	/**
	Create a ToolTipHelp for the given widget
	     
	It automatically enables SigIdle calls for PG_Application

	       @param parent The widget for which the ToolTip Help shall be shown
	@param text The help text 
	       @param delay The delay in 1/10 s after which the help appears when the mouse has stopped moving 
	@param style The theme style for the Help. Default: Widget Type = ToolTipHelp . Object Name = LineEdit 
	*/
	PG_ToolTipHelp( PG_Widget* parent, const std::string& text, int delay = 10, const std::string &style="ToolTipHelp" );


	/**
	Changes the help text 
	*/
	void SetText( const std::string& text );

	/**
	Show the help to be shown
	       
	@param pos The screen coordinates of the upper left corner 
	*/
	void ShowHelp( const PG_Point& pos );

	/**
	Hides the ToolTip Help
	*/
	void HideHelp( );
        
        ~PG_ToolTipHelp();
        
        /**
        returns the Tooltip widget for the given widget, or NULL if none was created
        */
        static PG_ToolTipHelp* GetToolTip( const PG_Widget* widget );
};



#endif