#ifndef TOOLTIP_HH
#define TOOLTIP_HH  1

#ifdef HAVE_CONFIG_H
#include    "config.h"
#endif /* HAVE_CONFIG_H */

#include <string>
#include <vector>
#include <X11/Xlib.h>
#include <pthread.h>
#include <semaphore.h>
#include <sys/time.h>
#include <time.h>

using namespace std;

typedef enum direction_type { top_left = 0, top_right, bottom_left, bottom_right };
typedef void *(*pfunc_t)(void *);

const int no_delay = 0;

// Forward declaration
class BToolTip;

#ifdef DELAYED_TOOLTIPS
void *waiter_thread_helper_function(void *waiter_object);

class Waiter {
    public:
	Waiter();
	~Waiter();
	
	void waiter_loop(void);
	void wait(const int _secs, void (BToolTip::*_func)(), BToolTip *_param);
	void cancel(void);
    private:
	struct timeval wait_from;
	int wait_secs;
	bool fire, end;
	void (BToolTip::*func)();
	BToolTip *param;
	pthread_t wait_thread;
	sem_t run_waiter;
};
#endif /* DELAYED_TOOLTIPS */

class BToolTip {
    public:
	BToolTip();
	~BToolTip();

	// Member functions
	void createToolTipWindow(const int _x, const int _y, const unsigned int _w, const unsigned int _h);
	void setText(const string &tooltip_text);
	void setTimeout(const int seconds);
	void setPosition(const int _x, const int _y, const direction_type _direction = bottom_right);
	void redraw(const int _x, const int _y, const unsigned int _w, const unsigned int _h);
	void processEvent(const XEvent &event);
	void show(void);
	void showNow(void);
	void hide(void);

	bool isShown(void) const;
	int getTimeout(void) const;

    private:
	vector<string> current_tooltip_text;
	int x, y, real_x, real_y, timeout;
	unsigned int real_w, real_h;
	bool is_visible, is_created;
	direction_type direction;
	Pixmap tooltip_pixmap;
	Window tooltip_window;
#ifdef DELAYED_TOOLTIPS
	Waiter waiter;
#endif /* DELAYED_TOOLTIPS */
	pthread_mutex_t show_hide_syn;
};

#endif /* TOOLTIP_HH */


syntax highlighted by Code2HTML, v. 0.9.1