fluxbox/src/FbTk/FbWindow.hh

158 lines
5.7 KiB
C++
Raw Normal View History

2002-12-03 16:25:27 +00:00
// FbWindow.hh for FbTk - fluxbox toolkit
2003-04-14 12:04:32 +00:00
// Copyright (c) 2002 - 2003 Henrik Kinnunen (fluxgen at users.sourceforge.net)
2002-12-03 16:25:27 +00:00
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
// $Id: FbWindow.hh,v 1.15 2003/05/12 04:20:25 fluxgen Exp $
2002-12-03 16:25:27 +00:00
#ifndef FBTK_FBWINDOW_HH
#define FBTK_FBWINDOW_HH
2003-04-29 08:51:59 +00:00
#include "FbDrawable.hh"
2002-12-03 16:25:27 +00:00
#include <X11/Xlib.h>
namespace FbTk {
class Color;
2003-04-29 08:51:59 +00:00
/// Wrapper for X window
2003-05-10 13:24:59 +00:00
/**
* Example:
* FbWindow window(0, 10, 10, 100, 100, ExposeMask | ButtonPressMask); \n
* this will create a window on screen 0, position 10 10, size 100 100 \n
* and with eventmask Expose and ButtonPress. \n
* You need to register it to some eventhandler so you can catch events: \n
* EventManager::instance()->add(your_eventhandler, window); \n
* @see EventHandler
* @see EventManager
*/
2003-04-29 08:51:59 +00:00
class FbWindow: public FbDrawable {
2002-12-03 16:25:27 +00:00
public:
FbWindow();
2003-05-10 13:24:59 +00:00
2002-12-03 16:25:27 +00:00
FbWindow(const FbWindow &win_copy);
2003-05-10 13:24:59 +00:00
2002-12-03 16:25:27 +00:00
FbWindow(int screen_num,
2003-04-14 12:04:32 +00:00
int x, int y, unsigned int width, unsigned int height, long eventmask,
2002-12-03 16:25:27 +00:00
bool overrride_redirect = false,
int depth = CopyFromParent,
int class_type = InputOutput);
2003-05-10 13:24:59 +00:00
2002-12-03 16:25:27 +00:00
FbWindow(const FbWindow &parent,
2003-04-16 16:02:14 +00:00
int x, int y,
unsigned int width, unsigned int height,
long eventmask,
2002-12-03 16:25:27 +00:00
bool overrride_redirect = false,
int depth = CopyFromParent,
int class_type = InputOutput);
virtual ~FbWindow();
void setBackgroundColor(const FbTk::Color &bg_color);
void setBackgroundPixmap(Pixmap bg_pixmap);
void setBorderColor(const FbTk::Color &border_color);
2003-04-16 16:02:14 +00:00
void setBorderWidth(unsigned int size);
2003-05-10 13:24:59 +00:00
/// set window name (title)
2002-12-03 16:25:27 +00:00
void setName(const char *name);
void setEventMask(long mask);
/// clear window with background pixmap or color
2003-04-29 08:51:59 +00:00
virtual void clear();
2002-12-03 16:25:27 +00:00
/// assign a new X window to this
virtual FbWindow &operator = (Window win);
virtual void hide();
virtual void show();
virtual void showSubwindows();
2002-12-16 11:17:26 +00:00
2002-12-03 16:25:27 +00:00
virtual void move(int x, int y);
2003-04-14 12:04:32 +00:00
virtual void resize(unsigned int width, unsigned int height);
virtual void moveResize(int x, int y, unsigned int width, unsigned int height);
virtual void lower();
virtual void raise();
2002-12-03 16:25:27 +00:00
2003-05-10 13:24:59 +00:00
/// @return parent FbWindow
2002-12-16 11:17:26 +00:00
const FbWindow *parent() const { return m_parent; }
2003-05-10 13:24:59 +00:00
/// @return real X window
2003-04-29 08:51:59 +00:00
inline Window window() const { return m_window; }
2003-05-10 13:24:59 +00:00
/// @return drawable (the X window)
2003-04-29 08:51:59 +00:00
inline Drawable drawable() const { return window(); }
2002-12-03 16:25:27 +00:00
int x() const { return m_x; }
int y() const { return m_y; }
2003-04-14 12:04:32 +00:00
unsigned int width() const { return m_width; }
unsigned int height() const { return m_height; }
unsigned int borderWidth() const { return m_border_width; }
2003-05-10 13:24:59 +00:00
int depth() const { return m_depth; }
2002-12-16 11:17:26 +00:00
int screenNumber() const;
2002-12-03 16:25:27 +00:00
/// compare X window
bool operator == (Window win) const { return m_window == win; }
2002-12-13 20:29:31 +00:00
bool operator != (Window win) const { return m_window != win; }
2002-12-04 00:02:52 +00:00
/// compare two windows
bool operator == (const FbWindow &win) const { return m_window == win.m_window; }
2002-12-13 20:29:31 +00:00
bool operator != (const FbWindow &win) const { return m_window != win.m_window; }
2002-12-16 11:17:26 +00:00
2003-04-14 12:04:32 +00:00
protected:
2003-05-10 13:24:59 +00:00
/// creates a window with x window client (m_window = client)
2003-04-14 12:04:32 +00:00
explicit FbWindow(Window client);
/// updates x,y, width, height and screen num from X window
void updateGeometry();
2002-12-03 16:25:27 +00:00
private:
/// sets new X window and destroys old
2003-05-10 23:11:33 +00:00
void setNew(Window win);
/// creates a new X window
2003-04-14 12:04:32 +00:00
void create(Window parent, int x, int y, unsigned int width, unsigned int height,
long eventmask,
2002-12-03 16:25:27 +00:00
bool override_redirect,
int depth,
int class_type);
2003-05-10 13:24:59 +00:00
static Display *s_display; ///< display connection
const FbWindow *m_parent; ///< parent FbWindow
int m_screen_num; ///< screen num on which this window exist
2003-01-05 22:58:11 +00:00
Window m_window; ///< the X window
int m_x, m_y; ///< position of window
2003-04-14 12:04:32 +00:00
unsigned int m_width, m_height; ///< size of window
2003-05-10 13:24:59 +00:00
unsigned int m_border_width; ///< border size
int m_depth; ///< bit depth
2003-04-14 12:04:32 +00:00
bool m_destroy; ///< wheter the x window was created before
2002-12-03 16:25:27 +00:00
};
bool operator == (Window win, const FbWindow &fbwin);
2003-05-10 13:24:59 +00:00
/// helper class for some STL routines
2003-04-14 12:04:32 +00:00
class ChangeProperty {
public:
ChangeProperty(Display *disp, Atom prop, int mode,
unsigned char *state, int num):m_disp(disp),
m_prop(prop), m_state(state), m_num(num), m_mode(mode){
}
void operator () (FbTk::FbWindow *win) {
XChangeProperty(m_disp, win->window(), m_prop, m_prop, 32, m_mode,
m_state, m_num);
}
private:
Display *m_disp;
Atom m_prop;
unsigned char *m_state;
int m_num;
int m_mode;
};
2002-12-03 16:25:27 +00:00
}; // end namespace FbTk
#endif // FBTK_FBWINDOW_HH