From: Dana Jansens Date: Fri, 21 Mar 2003 18:42:39 +0000 (+0000) Subject: rm the old code including the .pys and the c++ shit X-Git-Url: https://git.dogcows.com/gitweb?a=commitdiff_plain;h=a52a6d96d701c993896f276e4198003317632aaf;p=chaz%2Fopenbox rm the old code including the .pys and the c++ shit --- diff --git a/otk/.cvsignore b/otk/.cvsignore deleted file mode 100644 index a563c2af..00000000 --- a/otk/.cvsignore +++ /dev/null @@ -1,45 +0,0 @@ -Makefile -Makefile.in -.deps -otk_test -otk_wrap.cc -.libs -application.lo -appwidget.lo -button.lo -color.lo -configuration.lo -display.lo -eventdispatcher.lo -eventhandler.lo -focuslabel.lo -focuswidget.lo -font.lo -gccache.lo -image.lo -imagecontrol.lo -label.lo -libotk.la -otk_wrap.lo -property.lo -rect.lo -screeninfo.lo -style.lo -texture.lo -timer.lo -timerqueuemanager.lo -truerendercontrol.lo -pseudorendercontrol.lo -util.lo -widget.lo -ustring.lo -surface.lo -rendertexture.lo -rendertest -renderstyle.lo -messagedialog.lo -rendercontrol.lo -rendercolor.lo -otk.py -otk.pc -otk.lo diff --git a/otk/Makefile.am b/otk/Makefile.am deleted file mode 100644 index 58fe305d..00000000 --- a/otk/Makefile.am +++ /dev/null @@ -1,51 +0,0 @@ -buttonsdir = $(pkgdatadir)/buttons -includeotkdir = $(includedir)/otk -pkgconfigdir = $(libdir)/pkgconfig - -CPPFLAGS=$(XFT_CFLAGS) @CPPFLAGS@ -DBUTTONSDIR=\"$(buttonsdir)\" - -lib_LTLIBRARIES=libotk.la - -libotk_la_SOURCES=rendercontrol.cc truerendercontrol.cc surface.cc util.cc \ - renderstyle.cc rendercolor.cc pseudorendercontrol.cc \ - display.cc font.cc property.cc timer.cc \ - eventdispatcher.cc eventhandler.cc ustring.cc \ - widget.cc application.cc label.cc appwidget.cc button.cc \ - otk.cc messagedialog.cc - -#focuswidget.cc focuslabel.cc - -includeotk_HEADERS=application.hh appwidget.hh assassin.hh button.hh \ - display.hh eventdispatcher.hh eventhandler.hh font.hh \ - label.hh otk.hh point.hh property.hh pseudorendercontrol.hh\ - rect.hh rendercolor.hh rendercontrol.hh renderstyle.hh \ - rendertexture.hh size.hh strut.hh surface.hh \ - timer.hh truerendercontrol.hh ustring.hh util.hh widget.hh \ - messagedialog.hh ../config.h - -EXTRA_DIST = otk.pc.in - -DISTCLEANFILES = otk.pc -MAINTAINERCLEANFILES= Makefile.in - -pkgconfig_DATA = otk.pc - -otk.pc: otk.pc.in - @regex_cmd@ -e "s,\@prefix\@,$(prefix)," \ - -e "s,\@version\@,$(VERSION)," \ - @srcdir@/$^ > $@ - -distclean-local: - $(RM) *\~ *.orig *.rej .\#* - -uninstall-am: - -rmdir -p $(includeotkdir) - -rmdir -p $(pkgconfigdir) - -otk_test: libotk.la otk_test.cc - $(CXX) $(CPPFLAGS) $(CXXFLAGS) -DHAVE_CONFIG_H -I. -I. -I.. -I../src $(XFT_CFLAGS) -Wall -W -pedantic -DNDEBUG -g -O2 -o otk_test otk_test.cc $(XFT_LIBS) -L. -lotk @LIBS@ - -rendertest: libotk.la rendertest.cc - $(CXX) $(CPPFLAGS) $(CXXFLAGS) -DHAVE_CONFIG_H -I. -I. -I.. -I../src $(XFT_CFLAGS) -Wall -W -pedantic -DNDEBUG -g -O2 -o $@ rendertest.cc $(XFT_LIBS) -L. -lotk @LIBS@ - -# local dependencies diff --git a/otk/TODO b/otk/TODO deleted file mode 100644 index 1a380c13..00000000 --- a/otk/TODO +++ /dev/null @@ -1,38 +0,0 @@ -* Implement borders and border overlapping in widget - the widget has a outer geometry(that of the border) and a inner one - (the current geometry) - if the overlap flag is true, the inner widgets' borders are overlapped - as much as possible while the widgets are still entirely visible. - -* make OtkButton do pixmaps - -* OtkMenu - this can wait, probably - -* OtkWidget - see about focus() - focus() on widgets means 'highlight', not take Focus. solve this mess - -* OtkTextWidget - widget that holds text that can be justified and whatnot - the button should prolly be modified to subclass this - -* OtkApplication - do all derty work init display/screen/style/image control etc - event loop - do docking - close app, clean up crap - watch for style properties on the root window, update crap - on the fly. - -* widget factory for openbox - singleton that fetches widgets to openbox so that openbox - doesn't need to do useless work in creating/initializing/etc - -* cleanup image code - less deps on screen and display - what's this thing about 8bpp being busticatered - -* cleanups - name classes OtkBummy instead of OB... or B... - make Style hold pointers to colors and textures diff --git a/otk/application.cc b/otk/application.cc deleted file mode 100644 index 1f65046b..00000000 --- a/otk/application.cc +++ /dev/null @@ -1,65 +0,0 @@ -// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- - -#include "config.h" - -#include "application.hh" -#include "eventhandler.hh" -#include "timer.hh" -#include "property.hh" -#include "rendercolor.hh" -#include "renderstyle.hh" -#include "display.hh" - -#include -#include - -namespace otk { - -extern void initialize(); -extern void destroy(); - -Application::Application(int argc, char **argv) - : EventDispatcher(), - _dockable(false), - _appwidget_count(0) -{ - (void)argc; - (void)argv; - - otk::initialize(); - - _screen = DefaultScreen(**display); - - loadStyle(); -} - -Application::~Application() -{ - otk::destroy(); -} - -void Application::loadStyle(void) -{ - // XXX: find the style name as a property - std::string style = "/usr/local/share/openbox/styles/artwiz"; - //_style->load(style); - otk::RenderStyle::setStyle(_screen, style); -} - -void Application::run(void) -{ - if (_appwidget_count <= 0) { - std::cerr << "ERROR: No main widgets exist. You must create and show() " << - "an AppWidget for the Application before calling " << - "Application::run().\n"; - ::exit(1); - } - - while (_appwidget_count > 0) { - dispatchEvents(); - if (_appwidget_count > 0) - Timer::dispatchTimers(); // fire pending events - } -} - -} diff --git a/otk/application.hh b/otk/application.hh deleted file mode 100644 index 6da36d28..00000000 --- a/otk/application.hh +++ /dev/null @@ -1,39 +0,0 @@ -// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- -#ifndef __application_hh -#define __application_hh - -#include "eventdispatcher.hh" - -namespace otk { - -class AppWidget; - -class Application : public EventDispatcher { - -public: - - Application(int argc, char **argv); - virtual ~Application(); - - inline int screen() const { return _screen; } - - virtual void run(void); - // more bummy cool functionality - - void setDockable(bool dockable) { _dockable = dockable; } - inline bool isDockable(void) const { return _dockable; } - -private: - void loadStyle(void); - - int _screen; - bool _dockable; - - int _appwidget_count; - - friend class AppWidget; -}; - -} - -#endif diff --git a/otk/appwidget.cc b/otk/appwidget.cc deleted file mode 100644 index 5dcad7ae..00000000 --- a/otk/appwidget.cc +++ /dev/null @@ -1,56 +0,0 @@ -// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- - -#include "config.h" - -#include "appwidget.hh" -#include "application.hh" -#include "property.hh" -#include "renderstyle.hh" -#include "display.hh" - -extern "C" { -#include -} - -namespace otk { - -AppWidget::AppWidget(Application *app, Direction direction, int bevel) - : Widget(app->screen(), app, direction, bevel), - _application(app) -{ - assert(app); - - // set WM Protocols on the window - Atom protocols[2]; - protocols[0] = Property::atoms.wm_protocols; - protocols[1] = Property::atoms.wm_delete_window; - XSetWMProtocols(**display, window(), protocols, 2); -} - -AppWidget::~AppWidget() -{ -} - -void AppWidget::show() -{ - if (!visible()) - _application->_appwidget_count++; - Widget::show(true); -} - -void AppWidget::hide() -{ - if (visible()) - _application->_appwidget_count--; - Widget::hide(); -} - -void AppWidget::clientMessageHandler(const XClientMessageEvent &e) -{ - EventHandler::clientMessageHandler(e); - if (e.message_type == Property::atoms.wm_protocols && - static_cast(e.data.l[0]) == Property::atoms.wm_delete_window) - hide(); -} - -} diff --git a/otk/appwidget.hh b/otk/appwidget.hh deleted file mode 100644 index 5595e88e..00000000 --- a/otk/appwidget.hh +++ /dev/null @@ -1,29 +0,0 @@ -// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- -#ifndef __appwidget_hh -#define __appwidget_hh - -#include "widget.hh" - -namespace otk { - -class Application; - -class AppWidget : public Widget { - -public: - AppWidget(Application *app, Direction direction = Horizontal, int bevel = 0); - virtual ~AppWidget(); - - virtual void show(); - virtual void hide(); - - virtual void clientMessageHandler(const XClientMessageEvent &e); - -private: - - Application *_application; -}; - -} - -#endif // __appwidget_hh diff --git a/otk/assassin.hh b/otk/assassin.hh deleted file mode 100644 index 5caf17f0..00000000 --- a/otk/assassin.hh +++ /dev/null @@ -1,16 +0,0 @@ -// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- -#ifndef __assassin_hh -#define __assassin_hh - -namespace otk { - -struct PointerAssassin { - template - inline void operator()(const T ptr) const { - delete ptr; - } -}; - -} - -#endif // __assassin_hh diff --git a/otk/button.cc b/otk/button.cc deleted file mode 100644 index 313d8acf..00000000 --- a/otk/button.cc +++ /dev/null @@ -1,77 +0,0 @@ -// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- - -#include "config.h" - -#include "button.hh" - -namespace otk { - -Button::Button(Widget *parent) - : Label(parent), - _pressed(false) -{ - setHorizontalJustify(RenderStyle::CenterJustify); - setVerticalJustify(RenderStyle::CenterJustify); - styleChanged(*RenderStyle::style(screen())); -} - -Button::~Button() -{ -} - -void Button::press(unsigned int mouse_button) -{ - if (_pressed) return; - - _pressed = true; - _mouse_button = mouse_button; - - styleChanged(*RenderStyle::style(screen())); - refresh(); -} - -void Button::release(unsigned int mouse_button) -{ - if (!_pressed || _mouse_button != mouse_button) return; // wrong button - - _pressed = false; - - styleChanged(*RenderStyle::style(screen())); - refresh(); -} - -void Button::buttonPressHandler(const XButtonEvent &e) -{ - Widget::buttonPressHandler(e); - press(e.button); -} - -void Button::buttonReleaseHandler(const XButtonEvent &e) -{ - Widget::buttonReleaseHandler(e); - bool p = _pressed; - release(e.button); - if (p && !_pressed && e.x > 0 && e.y > 0 && - e.x < area().width() && e.y < area().height()) - clickHandler(_mouse_button); -} - -void Button::styleChanged(const RenderStyle &style) -{ - if (isHighlighted()) { - if (_pressed) - _texture = style.buttonPressFocusBackground(); - else - _texture = style.buttonUnpressFocusBackground(); - _forecolor = style.buttonFocusColor(); - } else { - if (_pressed) - _texture = style.buttonPressUnfocusBackground(); - else - _texture = style.buttonUnpressUnfocusBackground(); - _forecolor = style.buttonUnfocusColor(); - } - refresh(); -} - -} diff --git a/otk/button.hh b/otk/button.hh deleted file mode 100644 index a3805aa0..00000000 --- a/otk/button.hh +++ /dev/null @@ -1,34 +0,0 @@ -// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- -#ifndef __button_hh -#define __button_hh - -#include "label.hh" - -namespace otk { - -class Button : public Label { - -public: - Button(Widget *parent); - virtual ~Button(); - - virtual inline bool isPressed() const { return _pressed; } - - virtual void press(unsigned int mouse_button); - virtual void release(unsigned int mouse_button); - - virtual void buttonPressHandler(const XButtonEvent &e); - virtual void buttonReleaseHandler(const XButtonEvent &e); - - virtual void clickHandler(unsigned int button) {(void)button;} - - virtual void styleChanged(const RenderStyle &style); - -private: - bool _pressed; - unsigned int _mouse_button; -}; - -} - -#endif diff --git a/otk/display.cc b/otk/display.cc deleted file mode 100644 index d4580a0e..00000000 --- a/otk/display.cc +++ /dev/null @@ -1,306 +0,0 @@ -// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- - -#include "config.h" - -#include "display.hh" -#include "util.hh" - -extern "C" { -#include - -#ifdef XKB -#include -#endif // XKB - -#ifdef SHAPE -#include -#endif // SHAPE - -#ifdef XINERAMA -#include -#endif // XINERAMA - -#ifdef HAVE_SIGNAL_H -# include -#endif // HAVE_SIGNAL_H - -#ifdef HAVE_FCNTL_H -# include -#endif // HAVE_FCNTL_H - -#ifdef HAVE_UNISTD_H -# include -# include -#endif // HAVE_UNISTD_H - -#include "../src/gettext.h" -#define _(str) gettext(str) -} - -#include - -namespace otk { - - -Display *display = (Display*) 0; - -static int xerrorHandler(::Display *d, XErrorEvent *e) -{ - if (!display->ignoreErrors()) { -#ifdef DEBUG - char errtxt[128]; - - //if (e->error_code != BadWindow) - { - XGetErrorText(d, e->error_code, errtxt, 127); - printf("X Error: %s\n", errtxt); - if (e->error_code != BadWindow) - abort(); - } -#else - (void)d; - (void)e; -#endif - } - return false; -} - - -Display::Display(::Display *d) - : _display(d), - _xkb(false), - _xkb_event_basep(0), - _shape(false), - _shape_event_basep(0), - _xinerama(false), - _xinerama_event_basep(0), - _mask_list(), - _num_lock_mask(0), - _scroll_lock_mask(0), - _grab_count(0) -{ - int junk; - (void)junk; - - assert(_display); - - display = this; - - if (fcntl(ConnectionNumber(_display), F_SETFD, 1) == -1) { - printf(_("Couldn't mark display connection as close-on-exec.\n\n")); - ::exit(1); - } - if (!XSupportsLocale()) - printf(_("X server does not support locale.\n")); - if (!XSetLocaleModifiers("")) - printf(_("Cannot set locale modifiers for the X server.\n")); - - // set our error handler for X errors - XSetErrorHandler(xerrorHandler); - - // set the DISPLAY environment variable for any lauched children, to the - // display we're using, so they open in the right place. - putenv(std::string("DISPLAY=") + DisplayString(_display)); - - // find the availability of X extensions we like to use -#ifdef XKB - _xkb = XkbQueryExtension(_display, &junk, &_xkb_event_basep, &junk, NULL, - NULL); -#endif - -#ifdef SHAPE - _shape = XShapeQueryExtension(_display, &_shape_event_basep, &junk); -#endif - -#ifdef XINERAMA - _xinerama = XineramaQueryExtension(_display, &_xinerama_event_basep, &junk); -#endif // XINERAMA - - // get lock masks that are defined by the display (not constant) - _modmap = XGetModifierMapping(_display); - assert(_modmap); - if (_modmap && _modmap->max_keypermod > 0) { - const int mask_table[] = { - ShiftMask, LockMask, ControlMask, Mod1Mask, - Mod2Mask, Mod3Mask, Mod4Mask, Mod5Mask - }; - const size_t size = (sizeof(mask_table) / sizeof(mask_table[0])) * - _modmap->max_keypermod; - // get the values of the keyboard lock modifiers - // Note: Caps lock is not retrieved the same way as Scroll and Num lock - // since it doesn't need to be. - const KeyCode num_lock = XKeysymToKeycode(_display, XK_Num_Lock); - const KeyCode scroll_lock = XKeysymToKeycode(_display, XK_Scroll_Lock); - - for (size_t cnt = 0; cnt < size; ++cnt) { - if (! _modmap->modifiermap[cnt]) continue; - - if (num_lock == _modmap->modifiermap[cnt]) - _num_lock_mask = mask_table[cnt / _modmap->max_keypermod]; - if (scroll_lock == _modmap->modifiermap[cnt]) - _scroll_lock_mask = mask_table[cnt / _modmap->max_keypermod]; - } - } - - _mask_list[0] = 0; - _mask_list[1] = LockMask; - _mask_list[2] = _num_lock_mask; - _mask_list[3] = LockMask | _num_lock_mask; - _mask_list[4] = _scroll_lock_mask; - _mask_list[5] = _scroll_lock_mask | LockMask; - _mask_list[6] = _scroll_lock_mask | _num_lock_mask; - _mask_list[7] = _scroll_lock_mask | LockMask | _num_lock_mask; - - /* - If the default depth is at least 8 we will use that, - otherwise we try to find the largest TrueColor visual. - Preference is given to 24 bit over larger depths if 24 bit is an option. - */ - - int screen = DefaultScreen(_display); - _depth = DefaultDepth(_display, screen); - _visual = DefaultVisual(_display, screen); - _colormap = DefaultColormap(_display, screen); - - if (_depth < 8) { - // search for a TrueColor Visual... if we can't find one... - // we will use the default visual for the screen - XVisualInfo vinfo_template, *vinfo_return; - int vinfo_nitems; - int best = -1; - - vinfo_template.screen = screen; - vinfo_template.c_class = TrueColor; - - vinfo_return = XGetVisualInfo(_display, - VisualScreenMask | VisualClassMask, - &vinfo_template, &vinfo_nitems); - if (vinfo_return) { - int max_depth = 1; - for (int i = 0; i < vinfo_nitems; ++i) { - if (vinfo_return[i].depth > max_depth) { - if (max_depth == 24 && vinfo_return[i].depth > 24) - break; // prefer 24 bit over 32 - max_depth = vinfo_return[i].depth; - best = i; - } - } - if (max_depth < _depth) best = -1; - } - - if (best != -1) { - _depth = vinfo_return[best].depth; - _visual = vinfo_return[best].visual; - _colormap = XCreateColormap(_display, RootWindow(_display, screen), - _visual, AllocNone); - } - - XFree(vinfo_return); - } -} - - -Display::~Display() -{ - while (_grab_count > 0) - ungrab(); - - XFreeModifiermap(_modmap); - - XCloseDisplay(_display); -} - - -void Display::setIgnoreErrors(bool t) -{ - // sync up so that anything already sent is/isn't ignored! - XSync(_display, false); - _ignore_errors = t; -} - -void Display::grab() -{ - if (_grab_count == 0) { - XGrabServer(_display); - XSync(_display, false); // make sure it kicks in - } - _grab_count++; -} - - -void Display::ungrab() -{ - if (_grab_count == 0) return; - _grab_count--; - if (_grab_count == 0) { - XUngrabServer(_display); - XFlush(_display); // ungrab as soon as possible - } -} - - - - - - - -/* - * Grabs a button, but also grabs the button in every possible combination - * with the keyboard lock keys, so that they do not cancel out the event. - - * if allow_scroll_lock is true then only the top half of the lock mask - * table is used and scroll lock is ignored. This value defaults to false. - */ -void Display::grabButton(unsigned int button, unsigned int modifiers, - Window grab_window, bool owner_events, - unsigned int event_mask, int pointer_mode, - int keyboard_mode, Window confine_to, - Cursor cursor, bool allow_scroll_lock) const -{ - unsigned int length = (allow_scroll_lock) ? 8 / 2: - 8; - for (size_t cnt = 0; cnt < length; ++cnt) - XGrabButton(_display, button, modifiers | _mask_list[cnt], - grab_window, owner_events, event_mask, pointer_mode, - keyboard_mode, confine_to, cursor); -} - - -/* - * Releases the grab on a button, and ungrabs all possible combinations of the - * keyboard lock keys. - */ -void Display::ungrabButton(unsigned int button, unsigned int modifiers, - Window grab_window) const -{ - for (size_t cnt = 0; cnt < 8; ++cnt) - XUngrabButton(_display, button, modifiers | _mask_list[cnt], - grab_window); -} - -void Display::grabKey(unsigned int keycode, unsigned int modifiers, - Window grab_window, bool owner_events, - int pointer_mode, int keyboard_mode, - bool allow_scroll_lock) const -{ - unsigned int length = (allow_scroll_lock) ? 8 / 2: - 8; - for (size_t cnt = 0; cnt < length; ++cnt) - XGrabKey(_display, keycode, modifiers | _mask_list[cnt], - grab_window, owner_events, pointer_mode, keyboard_mode); -} - -void Display::ungrabKey(unsigned int keycode, unsigned int modifiers, - Window grab_window) const -{ - for (size_t cnt = 0; cnt < 8; ++cnt) - XUngrabKey(_display, keycode, modifiers | _mask_list[cnt], - grab_window); -} - -void Display::ungrabAllKeys(Window grab_window) const -{ - XUngrabKey(_display, AnyKey, AnyModifier, grab_window); -} - -} diff --git a/otk/display.hh b/otk/display.hh deleted file mode 100644 index 25c1b45a..00000000 --- a/otk/display.hh +++ /dev/null @@ -1,126 +0,0 @@ -// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- -#ifndef __display_hh -#define __display_hh - -extern "C" { -#include -} - -namespace otk { - -class RenderControl; - -class Display; - -//! The display instance for the library -extern Display *display; - -//! Manages a single X11 display. -class Display -{ -private: - //! The X display - ::Display *_display; - - //! Does the display have the XKB extension? - bool _xkb; - //! Base for events for the XKB extension - int _xkb_event_basep; - - //! Does the display have the Shape extension? - bool _shape; - //! Base for events for the Shape extension - int _shape_event_basep; - - //! Does the display have the Xinerama extension? - bool _xinerama; - //! Base for events for the Xinerama extension - int _xinerama_event_basep; - - //! A list of all possible combinations of keyboard lock masks - unsigned int _mask_list[8]; - - //! The value of the mask for the NumLock modifier - unsigned int _num_lock_mask; - - //! The value of the mask for the ScrollLock modifier - unsigned int _scroll_lock_mask; - - //! The key codes for the modifier keys - XModifierKeymap *_modmap; - - //! The number of requested grabs on the display - int _grab_count; - - //! When true, X errors will be ignored. Use with care. - bool _ignore_errors; - - //! The optimal visual for the display - Visual *_visual; - - //! Our colormap built for the optimal visual - Colormap _colormap; - - //! The depth of our optimal visual - int _depth; - -public: - //! Wraps an open Display connection - /*! - @param d An open Display connection. - */ - Display(::Display *d); - //! Destroys the class, closes the X display - ~Display(); - - //! Returns if the display has the xkb extension available - inline bool xkb() const { return _xkb; } - //! Returns the xkb extension's event base - inline int xkbEventBase() const { return _xkb_event_basep; } - - //! Returns if the display has the shape extension available - inline bool shape() const { return _shape; } - //! Returns the shape extension's event base - inline int shapeEventBase() const { return _shape_event_basep; } - //! Returns if the display has the xinerama extension available - inline bool xinerama() const { return _xinerama; } - - inline unsigned int numLockMask() const { return _num_lock_mask; } - inline unsigned int scrollLockMask() const { return _scroll_lock_mask; } - const XModifierKeymap *modifierMap() const { return _modmap; } - - inline ::Display* operator*() const { return _display; } - - //! When true, X errors will be ignored. - inline bool ignoreErrors() const { return _ignore_errors; } - //! Set whether X errors should be ignored. Use with care. - void setIgnoreErrors(bool t); - - //! Grabs the display - void grab(); - - //! Ungrabs the display - void ungrab(); - - - - /* TEMPORARY */ - void grabButton(unsigned int button, unsigned int modifiers, - Window grab_window, bool owner_events, - unsigned int event_mask, int pointer_mode, - int keyboard_mode, Window confine_to, Cursor cursor, - bool allow_scroll_lock) const; - void ungrabButton(unsigned int button, unsigned int modifiers, - Window grab_window) const; - void grabKey(unsigned int keycode, unsigned int modifiers, - Window grab_window, bool owner_events, - int pointer_mode, int keyboard_mode, - bool allow_scroll_lock) const; - void ungrabKey(unsigned int keycode, unsigned int modifiers, - Window grab_window) const; - void ungrabAllKeys(Window grab_window) const; -}; - -} - -#endif // __display_hh diff --git a/otk/eventdispatcher.cc b/otk/eventdispatcher.cc deleted file mode 100644 index 1b90dbc0..00000000 --- a/otk/eventdispatcher.cc +++ /dev/null @@ -1,217 +0,0 @@ -// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- - -#include "config.h" - -#include "eventdispatcher.hh" -#include "display.hh" - -#include -#include - -namespace otk { - -EventDispatcher::EventDispatcher() - : _fallback(0), _master(0) -{ -} - -EventDispatcher::~EventDispatcher() -{ -} - -void EventDispatcher::clearAllHandlers(void) -{ - _map.clear(); -} - -void EventDispatcher::registerHandler(Window id, EventHandler *handler) -{ - _map.insert(std::pair(id, handler)); -} - -void EventDispatcher::clearHandler(Window id) -{ - _map.erase(id); -} - -void EventDispatcher::dispatchEvents(bool remote) -{ - XEvent e; - - while (true) { - /* - There are slightly different event retrieval semantics here for local (or - high bandwidth) versus remote (or low bandwidth) connections to the - display/Xserver. - */ - if (remote) { - if (!XPending(**display)) - return; - } else { - /* - This XSync allows for far more compression of events, which makes - things like Motion events perform far far better. Since it also means - network traffic for every event instead of every X events (where X is - the number retrieved at a time), it probably should not be used for - setups where Openbox is running on a remote/low bandwidth - display/Xserver. - */ - XSync(**display, false); - if (!XEventsQueued(**display, QueuedAlready)) - return; - } - XNextEvent(**display, &e); - -#if 0//defined(DEBUG) - printf("Event %d window %lx\n", e.type, e.xany.window); -#endif - - if (e.type == FocusIn || e.type == FocusOut) { - // focus events are a beast all their own.. yuk, hate, etc. - dispatchFocus(e); - } else { - Window win; - - // pick a window - switch (e.type) { - case UnmapNotify: - win = e.xunmap.window; - break; - case DestroyNotify: - win = e.xdestroywindow.window; - break; - case ConfigureRequest: - win = e.xconfigurerequest.window; - break; - default: - win = e.xany.window; - } - - // grab the lasttime and hack up the modifiers - switch (e.type) { - case ButtonPress: - case ButtonRelease: - _lasttime = e.xbutton.time; - e.xbutton.state &= ~(LockMask | display->numLockMask() | - display->scrollLockMask()); - break; - case KeyPress: - e.xkey.state &= ~(LockMask | display->numLockMask() | - display->scrollLockMask()); - break; - case MotionNotify: - _lasttime = e.xmotion.time; - e.xmotion.state &= ~(LockMask | display->numLockMask() | - display->scrollLockMask()); - break; - case PropertyNotify: - _lasttime = e.xproperty.time; - break; - case EnterNotify: - case LeaveNotify: - _lasttime = e.xcrossing.time; - if (e.xcrossing.mode != NotifyNormal) - continue; // skip me! - break; - } - - dispatch(win, e); - } - } -} - -void EventDispatcher::dispatchFocus(const XEvent &e) -{ -// printf("focus %s detail %d -> 0x%lx\n", -// (e.xfocus.type == FocusIn ? "IN" : "OUT"), -// e.xfocus.detail, e.xfocus.window); - // ignore focus changes from grabs - if (e.xfocus.mode == NotifyGrab) //|| e.xfocus.mode == NotifyUngrab || - // From Metacity, from WindowMaker, ignore all funky pointer root events - // its commented out cuz I don't think we need this at all. If problems - // arise we can look into it - //e.xfocus.detail > NotifyNonlinearVirtual) - return; - - if (e.type == FocusIn) { - //printf("Got FocusIn!\n"); - - // send a FocusIn to whatever was just focused - dispatch(e.xfocus.window, e); - //printf("Sent FocusIn 0x%lx\n", e.xfocus.window); - - } else if (e.type == FocusOut) { - //printf("Got FocusOut!\n"); - - // FocusOut events just make us look for FocusIn events. They are ignored - // otherwise. - XEvent fi; - if (XCheckTypedEvent(**display, FocusIn, &fi)) { - //printf("Found FocusIn\n"); - dispatchFocus(fi); - // dont unfocus the window we just focused! - if (fi.xfocus.window == e.xfocus.window) - return; - } - - dispatch(e.xfocus.window, e); - //printf("Sent FocusOut 0x%lx\n", e.xfocus.window); - } -} - -void EventDispatcher::dispatch(Window win, const XEvent &e) -{ - EventHandler *handler = 0; - EventMap::iterator it; - - // master gets everything first - if (_master) - _master->handle(e); - - // find handler for the chosen window - it = _map.find(win); - - if (it != _map.end()) { - // if we found a handler - handler = it->second; - } else if (e.type == ConfigureRequest) { - // unhandled configure requests must be used to configure the window - // directly - XWindowChanges xwc; - - xwc.x = e.xconfigurerequest.x; - xwc.y = e.xconfigurerequest.y; - xwc.width = e.xconfigurerequest.width; - xwc.height = e.xconfigurerequest.height; - xwc.border_width = e.xconfigurerequest.border_width; - xwc.sibling = e.xconfigurerequest.above; - xwc.stack_mode = e.xconfigurerequest.detail; - -#ifdef DEBUG - printf("Proxying configure event for 0x%lx\n", e.xconfigurerequest.window); -#endif - - // we are not to be held responsible if someone sends us an invalid - // request! - display->setIgnoreErrors(true); - XConfigureWindow(**display, e.xconfigurerequest.window, - e.xconfigurerequest.value_mask, &xwc); - display->setIgnoreErrors(false); - } else { - // grab a falback if it exists - handler = _fallback; - } - - if (handler) - handler->handle(e); -} - -EventHandler *EventDispatcher::findHandler(Window win) -{ - EventMap::iterator it = _map.find(win); - if (it != _map.end()) - return it->second; - return 0; -} - -} diff --git a/otk/eventdispatcher.hh b/otk/eventdispatcher.hh deleted file mode 100644 index 35c3722e..00000000 --- a/otk/eventdispatcher.hh +++ /dev/null @@ -1,62 +0,0 @@ -// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- -#ifndef __eventdispatcher -#define __eventdispatcher - -#include "eventhandler.hh" -#include -#include - -namespace otk { - -typedef std::map EventMap; - -class EventDispatcher { -public: - - EventDispatcher(); - virtual ~EventDispatcher(); - - virtual void clearAllHandlers(void); - virtual void registerHandler(Window id, EventHandler *handler); - virtual void clearHandler(Window id); - //! Dispatch events from the X server to the appropriate EventHandlers - /*! - @param remote Is the Xserver on a remote (low bandwidth) connection or on a - local (high bandwidth) connection. This allows you to specify - 'false' in which case slightly different semantics are used - for event retrieval.
- The default is 'true' since this should generally be used, - only the Openbox window manager should need to specify - 'false' here. - */ - virtual void dispatchEvents(bool remote = true); - - inline void setFallbackHandler(EventHandler *fallback) - { _fallback = fallback; } - EventHandler *getFallbackHandler(void) const { return _fallback; } - - //! Sets an event handler that gets all events for all handlers after - //! any specific handlers have received them - inline void setMasterHandler(EventHandler *master) - { _master = master; } - EventHandler *getMasterHandler(void) const { return _master; } - - EventHandler *findHandler(Window win); - - inline Time lastTime() const { return _lasttime; } - -private: - EventMap _map; - EventHandler *_fallback; - EventHandler *_master; - - //! The time at which the last XEvent with a time was received - Time _lasttime; - - void dispatch(Window win, const XEvent &e); - void dispatchFocus(const XEvent &e); -}; - -} - -#endif diff --git a/otk/eventhandler.cc b/otk/eventhandler.cc deleted file mode 100644 index 6539d587..00000000 --- a/otk/eventhandler.cc +++ /dev/null @@ -1,106 +0,0 @@ -// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- - -#include "config.h" - -#include "display.hh" -#include "eventhandler.hh" - -namespace otk { - -EventHandler::EventHandler() -{ -} - - -EventHandler::~EventHandler() -{ -} - - -void EventHandler::handle(const XEvent &e) -{ - switch(e.type){ - case KeyPress: - return keyPressHandler(e.xkey); - case KeyRelease: - return keyReleaseHandler(e.xkey); - case ButtonPress: - return buttonPressHandler(e.xbutton); - case ButtonRelease: - return buttonReleaseHandler(e.xbutton); - case MotionNotify: - return motionHandler(e.xmotion); - case EnterNotify: - return enterHandler(e.xcrossing); - case LeaveNotify: - return leaveHandler(e.xcrossing); - case FocusIn: - return focusHandler(e.xfocus); - case FocusOut: - return unfocusHandler(e.xfocus); - case Expose: - return exposeHandler(e.xexpose); - case GraphicsExpose: - return graphicsExposeHandler(e.xgraphicsexpose); - case NoExpose: - return noExposeEventHandler(e.xnoexpose); - case CirculateRequest: - return circulateRequestHandler(e.xcirculaterequest); - case ConfigureRequest: - return configureRequestHandler(e.xconfigurerequest); - case MapRequest: - return mapRequestHandler(e.xmaprequest); - case ResizeRequest: - return resizeRequestHandler(e.xresizerequest); - case CirculateNotify: - return circulateHandler(e.xcirculate); - case ConfigureNotify: - return configureHandler(e.xconfigure); - case CreateNotify: - return createHandler(e.xcreatewindow); - case DestroyNotify: - return destroyHandler(e.xdestroywindow); - case GravityNotify: - return gravityHandler(e.xgravity); - case MapNotify: - return mapHandler(e.xmap); - case MappingNotify: - return mappingHandler(e.xmapping); - case ReparentNotify: - return reparentHandler(e.xreparent); - case UnmapNotify: - return unmapHandler(e.xunmap); - case VisibilityNotify: - return visibilityHandler(e.xvisibility); - case ColormapNotify: - return colorMapHandler(e.xcolormap); - case ClientMessage: - return clientMessageHandler(e.xclient); - case PropertyNotify: - return propertyHandler(e.xproperty); - case SelectionClear: - return selectionClearHandler(e.xselectionclear); - case SelectionNotify: - return selectionHandler(e.xselection); - case SelectionRequest: - return selectionRequestHandler(e.xselectionrequest); - default: -#ifdef SHAPE - if (e.type == display->shapeEventBase()) - return shapeHandler((*(XShapeEvent*)&e)); -#endif // SHAPE -#ifdef XKB - if (e.type == display->xkbEventBase()) - return xkbHandler((*(XkbEvent*)&e)); -#endif // XKB - ; - } -} - - -void EventHandler::clientMessageHandler(const XClientMessageEvent &) -{ - -} - -} diff --git a/otk/eventhandler.hh b/otk/eventhandler.hh deleted file mode 100644 index f2457568..00000000 --- a/otk/eventhandler.hh +++ /dev/null @@ -1,152 +0,0 @@ -// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- -#ifndef __eventhandler__hh -#define __eventhandler__hh - -extern "C" { -#include - -#ifdef SHAPE -#include -#endif // SHAPE - -#ifdef XKB -#include -#endif // XKB - -} - -namespace otk { - -class EventHandler { -public: - //! Dispatches events to one of the other handlers based on their type. - virtual void handle(const XEvent &e); - - //! Called whenever any key is pressed. - virtual void keyPressHandler(const XKeyEvent &) {} - - //! Called whenever any key is released. - virtual void keyReleaseHandler(const XKeyEvent &) {} - - //! Called whenever a button of the pointer is pressed. - virtual void buttonPressHandler(const XButtonEvent &) {} - - //! Called whenever a button of the pointer is released. - virtual void buttonReleaseHandler(const XButtonEvent &) {} - - //! Called whenever the pointer moved - virtual void motionHandler(const XMotionEvent &) {} - - //! Called whenever the pointer enters a window. - virtual void enterHandler(const XCrossingEvent &) {} - - //! Called whenever the pointer leaves a window. - virtual void leaveHandler(const XCrossingEvent &) {} - - //! Called when a window gains focus. - virtual void focusHandler(const XFocusChangeEvent &) {} - - //! Called when a window looses focus. - virtual void unfocusHandler(const XFocusChangeEvent &) {} - - //! Called when a window becomes visible to the user. - virtual void exposeHandler(const XExposeEvent &) {} - - //! Called to handle GraphicsExpose events. - virtual void graphicsExposeHandler(const XGraphicsExposeEvent &) {} - - //! Called to handle NoExpose events. - virtual void noExposeEventHandler(const XNoExposeEvent &) {} - - //! Called when the window requests a change in its z-order. - virtual void circulateRequestHandler(const XCirculateRequestEvent &) - {} - - //! Called when a different client initiates a configure window request. - virtual void configureRequestHandler(const XConfigureRequestEvent &) - {} - - //! Called when a different client tries to map a window. - virtual void mapRequestHandler(const XMapRequestEvent &) {} - - //! Called when another client attemps to change the size of a window. - virtual void resizeRequestHandler(const XResizeRequestEvent &) {} - - //! Called when the z-order of the window has changed. - virtual void circulateHandler(const XCirculateEvent &) {} - - //! Called when the window as been reconfigured. - virtual void configureHandler(const XConfigureEvent &) {} - - //! Called when a window is created. - virtual void createHandler(const XCreateWindowEvent &) {} - - //! Called when a window is destroyed. - virtual void destroyHandler(const XDestroyWindowEvent &) {} - - //! Called when a window is moved because of a change in the size of its - //! parent. - virtual void gravityHandler(const XGravityEvent &) {} - - //! Called when a window is mapped. - virtual void mapHandler(const XMapEvent &) {} - - //! Called when the server generats a MappingNotify event - virtual void mappingHandler(const XMappingEvent &) {} - - //! Called when a window is reparented - virtual void reparentHandler(const XReparentEvent &) {} - - //! Called when a window is unmapped - virtual void unmapHandler(const XUnmapEvent &) {} - - //! Called when a the visibilty of a window changes - virtual void visibilityHandler(const XVisibilityEvent &) {} - - //! Called when the colormap changes, or is installed or unistalled - virtual void colorMapHandler(const XColormapEvent &) {} - - //! Called when a property of a window changes - virtual void propertyHandler(const XPropertyEvent &) {} - - //! Called when the client loses ownership of a selection - virtual void selectionClearHandler(const XSelectionClearEvent &) {} - - //! Called when a ConvertSelection protocol request is sent - virtual void selectionHandler(const XSelectionEvent &) {} - - //! Called when a SelectionEvent occurs - virtual void selectionRequestHandler(const XSelectionRequestEvent &) {} - - //! Called when a client calls XSendEvent - /*! - Some types of client messages are filtered out and sent to more specific - event handler functions. - */ - virtual void clientMessageHandler(const XClientMessageEvent &); - -#if defined(SHAPE) || defined(DOXYGEN_IGNORE) - //! Called when a shape extension event fires - virtual void shapeHandler(const XShapeEvent &) {} -#endif // SHAPE - -#if defined(XKB) || defined(DOXYGEN_IGNORE) - //! Called when an xkb extension event fires - virtual void xkbHandler(const XkbEvent &) {} -#endif // XKB - - virtual ~EventHandler(); - -protected: - /*! Constructor for the EventHandler class. - This is protected so that EventHandlers can't be instantiated on their - own. - */ - EventHandler(); - -private: -}; - -} - -#endif diff --git a/otk/font.cc b/otk/font.cc deleted file mode 100644 index ee9c37d7..00000000 --- a/otk/font.cc +++ /dev/null @@ -1,102 +0,0 @@ -// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- - -#include "config.h" - -#include "font.hh" -#include "surface.hh" -#include "util.hh" -#include "display.hh" -#include "screeninfo.hh" - -extern "C" { -#include "../src/gettext.h" -#define _(str) gettext(str) -} - -#include -#include -#include -#include - -namespace otk { - -bool Font::_xft_init = false; - -Font::Font(int screen_num, const std::string &fontstring, - bool shadow, unsigned char offset, unsigned char tint) - : _screen_num(screen_num), - _fontstring(fontstring), - _shadow(shadow), - _offset(offset), - _tint(tint), - _xftfont(0) -{ - assert(screen_num >= 0); - assert(tint <= CHAR_MAX); - - if (!_xft_init) { - if (!XftInit(0)) { - printf(_("Couldn't initialize Xft.\n\n")); - ::exit(3); - } -#ifdef DEBUG - int version = XftGetVersion(); - printf("Using Xft %d.%d.%d (Built against %d.%d.%d).\n", - version / 10000 % 100, version / 100 % 100, version % 100, - XFT_MAJOR, XFT_MINOR, XFT_REVISION); -#endif - _xft_init = true; - } - - if ((_xftfont = XftFontOpenName(**display, _screen_num, - _fontstring.c_str()))) - return; - - printf(_("Unable to load font: %s\n"), _fontstring.c_str()); - printf(_("Trying fallback font: %s\n"), "fixed"); - - if ((_xftfont = XftFontOpenName(**display, _screen_num, - "fixed"))) - return; - - printf(_("Unable to load font: %s\n"), "fixed"); - printf(_("Aborting!.\n")); - - ::exit(3); // can't continue without a font -} - - -Font::~Font(void) -{ - if (_xftfont) - XftFontClose(**display, _xftfont); -} - - -int Font::measureString(const ustring &string) const -{ - XGlyphInfo info; - - if (string.utf8()) - XftTextExtentsUtf8(**display, _xftfont, - (FcChar8*)string.c_str(), string.bytes(), &info); - else - XftTextExtents8(**display, _xftfont, - (FcChar8*)string.c_str(), string.bytes(), &info); - - return (signed) info.xOff + (_shadow ? _offset : 0); -} - - -int Font::height(void) const -{ - return (signed) _xftfont->height + (_shadow ? _offset : 0); -} - - -int Font::maxCharWidth(void) const -{ - return (signed) _xftfont->max_advance_width; -} - -} diff --git a/otk/font.hh b/otk/font.hh deleted file mode 100644 index 53e48c4e..00000000 --- a/otk/font.hh +++ /dev/null @@ -1,60 +0,0 @@ -// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- -#ifndef __font_hh -#define __font_hh - -#include "ustring.hh" -#include "truerendercontrol.hh" - -extern "C" { -#include -#define _XFT_NO_COMPAT_ // no Xft 1 API -#include -} - -#include - -namespace otk { - -class Color; -class Surface; - -class Font { - /* - * static members - */ -private: - static bool _xft_init; - - int _screen_num; - - std::string _fontstring; - - bool _shadow; - unsigned char _offset; - unsigned char _tint; - - XftFont *_xftfont; - - bool createXftFont(void); - -public: - // loads an Xft font - Font(int screen_num, const std::string &fontstring, bool shadow, - unsigned char offset, unsigned char tint); - virtual ~Font(); - - inline const std::string &fontstring() const { return _fontstring; } - - int height() const; - int maxCharWidth() const; - - int measureString(const ustring &string) const; - - // The RenderControl classes use the internal data to render the fonts, but - // noone else needs it, so its private. - friend class RenderControl; -}; - -} - -#endif // __font_hh diff --git a/otk/label.cc b/otk/label.cc deleted file mode 100644 index 8ec03dd9..00000000 --- a/otk/label.cc +++ /dev/null @@ -1,176 +0,0 @@ -// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- - -#include "config.h" - -#include "label.hh" -#include "display.hh" -#include "rendercontrol.hh" - -#include - -namespace otk { - -Label::Label(int screen, EventDispatcher *ed, int bevel) - : Widget(screen, ed, Widget::Horizontal, bevel, true), - _text(""), - _font(0), - _justify_horz(RenderStyle::LeftTopJustify), - _justify_vert(RenderStyle::LeftTopJustify), - _highlight(false) -{ - styleChanged(*RenderStyle::style(screen)); -} - -Label::Label(Widget *parent) - : Widget(parent), - _text(""), - _font(0), - _justify_horz(RenderStyle::LeftTopJustify), - _justify_vert(RenderStyle::LeftTopJustify), - _highlight(false) -{ - styleChanged(*RenderStyle::style(screen())); -} - -Label::~Label() -{ -} - -void Label::setHorizontalJustify(RenderStyle::Justify j) -{ - _justify_horz = j; - refresh(); -} - -void Label::setVerticalJustify(RenderStyle::Justify j) -{ - _justify_vert = j; - refresh(); -} - -void Label::setHighlighted(bool h) -{ - _highlight = h; - styleChanged(*RenderStyle::style(screen())); - refresh(); -} - -void Label::setText(const ustring &text) -{ - bool utf = text.utf8(); - std::string s = text.c_str(); // use a normal string, for its functionality - - _parsedtext.clear(); - _text = text; - - // parse it into multiple lines - std::string::size_type p = 0; - while (p != std::string::npos) { - std::string::size_type p2 = s.find('\n', p); - std::string s(s.substr(p, (p2==std::string::npos?p2:p2-p))); - - // turn tabs into spaces (multiples of 8) - std::string::size_type t; - while ((t = s.find('\t')) != std::string::npos) - s.replace(t, 1, std::string(8 - t % 8, ' ')); - - _parsedtext.push_back(s); - _parsedtext.back().setUtf8(utf); - p = (p2==std::string::npos?p2:p2+1); - } - calcDefaultSizes(); -} - -void Label::setFont(const Font *f) -{ - _font = f; - calcDefaultSizes(); -} - -void Label::calcDefaultSizes() -{ - int longest = 0; - // find the longest line - std::vector::iterator it, end = _parsedtext.end(); - for (it = _parsedtext.begin(); it != end; ++it) { - int length = _font->measureString(*it); - if (length < 0) continue; // lines too long get skipped - if (length > longest) longest = length; - } - setMinSize(Size(longest + borderWidth() * 2 + bevel() * 4, - _parsedtext.size() * _font->height() + borderWidth() * 2 + - bevel() * 2)); -} - -void Label::styleChanged(const RenderStyle &style) -{ - if (_highlight) { - _texture = style.labelFocusBackground(); - _forecolor = style.textFocusColor(); - } else { - _texture = style.labelUnfocusBackground(); - _forecolor = style.textUnfocusColor(); - } - if (_font != style.labelFont()) { - _font = style.labelFont(); - calcDefaultSizes(); - } -} - -void Label::renderForeground(Surface &surface) -{ - const RenderControl *control = display->renderControl(screen()); - int sidemargin = bevel() * 2; - int y = bevel(); - int w = area().width() - borderWidth() * 2 - sidemargin * 2; - int h = area().height() - borderWidth() * 2 - bevel() * 2; - - switch (_justify_vert) { - case RenderStyle::RightBottomJustify: - y += h - (_parsedtext.size() * _font->height()); - if (y < bevel()) y = bevel(); - break; - case RenderStyle::CenterJustify: - y += (h - (_parsedtext.size() * _font->height())) / 2; - if (y < bevel()) y = bevel(); - break; - case RenderStyle::LeftTopJustify: - break; - } - - if (w <= 0) return; // can't fit anything - - std::vector::iterator it, end = _parsedtext.end(); - for (it = _parsedtext.begin(); it != end; ++it, y += _font->height()) { - ustring t = *it; // the actual text to draw - int x = sidemargin; // x coord for the text - - // find a string that will fit inside the area for text - ustring::size_type text_len = t.size(); - int length; - - do { - t.resize(text_len); - length = _font->measureString(t); - } while (length > w && text_len-- > 0); - if (length < 0) continue; // lines too long get skipped - - if (text_len <= 0) continue; // won't fit anything - - // justify the text - switch (_justify_horz) { - case RenderStyle::RightBottomJustify: - x += w - length; - break; - case RenderStyle::CenterJustify: - x += (w - length) / 2; - break; - case RenderStyle::LeftTopJustify: - break; - } - - control->drawString(surface, *_font, x, y, *_forecolor, t); - } -} - -} diff --git a/otk/label.hh b/otk/label.hh deleted file mode 100644 index cd9ef5a1..00000000 --- a/otk/label.hh +++ /dev/null @@ -1,66 +0,0 @@ -// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- -#ifndef __label_hh -#define __label_hh - -#include "widget.hh" -#include "ustring.hh" -#include "renderstyle.hh" -#include "font.hh" - -#include - -namespace otk { - -class Label : public Widget { - -public: - Label(int screen, EventDispatcher *ed, int bevel = 3); - Label(Widget *parent); - virtual ~Label(); - - inline const ustring& text(void) const { return _text; } - void setText(const ustring &text); - - virtual inline bool isHighlighted() const { return _highlight; } - virtual void setHighlighted(bool h); - - RenderStyle::Justify horizontalJustify() const { return _justify_horz; } - virtual void setHorizontalJustify(RenderStyle::Justify j); - RenderStyle::Justify verticalJustify() const { return _justify_vert; } - virtual void setVerticalJustify(RenderStyle::Justify j); - - const Font *font() const { return _font; } - virtual void setFont(const Font *f); - - virtual void styleChanged(const RenderStyle &style); - - virtual void renderForeground(Surface &surface); - -protected: - virtual void calcDefaultSizes(); - - //! The color the label will use for rendering its text - RenderColor *_forecolor; - -private: - //! Text to be displayed in the label - ustring _text; - //! Text to be displayed, parsed into its separate lines - std::vector _parsedtext; - //! The actual text being shown, may be a subset of _text - ustring _drawtext; - //! The font the text will be rendered with - const Font *_font; - //! The horizontal justification used for drawing text - RenderStyle::Justify _justify_horz; - //! The vertical justification used for drawing text - RenderStyle::Justify _justify_vert; - //! The drawing offset for the text - int _drawx; - //! If the widget is highlighted or not - bool _highlight; -}; - -} - -#endif diff --git a/otk/messagedialog.cc b/otk/messagedialog.cc deleted file mode 100644 index ac468cb3..00000000 --- a/otk/messagedialog.cc +++ /dev/null @@ -1,187 +0,0 @@ -// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- - -#include "config.h" - -#include "messagedialog.hh" -#include "assassin.hh" -#include "button.hh" -#include "label.hh" -#include "display.hh" -#include "property.hh" -#include "eventdispatcher.hh" -#include "timer.hh" - -#include - -namespace otk { - -class DialogButtonWidget : public Button { - MessageDialog *_dia; -public: - DialogButtonWidget(Widget *parent, MessageDialog *dia, - const DialogButton &b) - : Button(parent), - _dia(dia) - { - assert(dia); - setBevel(1); - setMaxSize(Size(0,0)); - setText(b.label()); - setHighlighted(b.isDefault()); - show(); - } - - virtual void buttonPressHandler(const XButtonEvent &e) { - // limit to the left button - if (e.button == Button1) - Button::buttonPressHandler(e); - } - virtual void clickHandler(unsigned int) { - _dia->setResult(DialogButton(text(), isHighlighted())); - _dia->hide(); - } -}; - -MessageDialog::MessageDialog(int screen, EventDispatcher *ed, ustring title, - ustring caption) - : Widget(screen, ed, Widget::Vertical), - _result("", false) -{ - init(title, caption); -} - -MessageDialog::MessageDialog(EventDispatcher *ed, ustring title, - ustring caption) - : Widget(DefaultScreen(**display), ed, Widget::Vertical), - _result("", false) -{ - init(title, caption); -} - -MessageDialog::MessageDialog(Widget *parent, ustring title, ustring caption) - : Widget(parent, Widget::Vertical), - _result("", false) -{ - init(title, caption); -} - -void MessageDialog::init(const ustring &title, const ustring &caption) -{ - _label = new Label(this); - _label->show(); - _label->setHighlighted(true); - _button_holder = new Widget(this, Widget::Horizontal); - _button_holder->show(); - _return = XKeysymToKeycode(**display, XStringToKeysym("Return")); - _escape = XKeysymToKeycode(**display, XStringToKeysym("Escape")); - - setEventMask(eventMask() | KeyPressMask); - _label->setText(caption); - if (title.utf8()) - otk::Property::set(window(), otk::Property::atoms.net_wm_name, - otk::Property::utf8, title); - otk::Property::set(window(), otk::Property::atoms.wm_name, - otk::Property::ascii, otk::ustring(title.c_str(), false)); - - // set WM Protocols on the window - Atom protocols[2]; - protocols[0] = Property::atoms.wm_protocols; - protocols[1] = Property::atoms.wm_delete_window; - XSetWMProtocols(**display, window(), protocols, 2); -} - -MessageDialog::~MessageDialog() -{ - if (visible()) hide(); - delete _button_holder; - delete _label; -} - -const DialogButton& MessageDialog::run() -{ - if (!visible()) - show(); - - while (visible()) { - dispatcher()->dispatchEvents(); - if (visible()) - Timer::dispatchTimers(); // fire pending events - } - return _result; -} - -void MessageDialog::addButton(const DialogButton &b) -{ - _button_widgets.push_back(new DialogButtonWidget(_button_holder, - this, b)); -} - -void MessageDialog::focus() -{ - if (visible()) - XSetInputFocus(**display, window(), None, CurrentTime); -} - -void MessageDialog::show() -{ - Rect r; - - if (parent()) - r = parent()->area(); - else - r = Rect(Point(0, 0), display->screenInfo(screen())->size()); - - XSizeHints size; - size.flags = PMinSize | PPosition | PWinGravity; - size.min_width = minSize().width(); - size.min_height = minSize().height(); - size.win_gravity = CenterGravity; - - Size dest = minSize(); - if (dest.width() < 200 || dest.height() < 100) { - if (dest.width() < 200 && dest.height() < 100) dest = Size(200, 100); - else if (dest.width() < 200) dest = Size(200, dest.height()); - else dest = Size(dest.width(), 100); - resize(dest); - } - - // center it above its parent - move(Point(r.x() + (r.width() - dest.width()) / 2, - r.y() + (r.height() - dest.height()) / 2)); - - XSetWMNormalHints(**display, window(), &size); - - Widget::show(); -} - -void MessageDialog::hide() -{ - Widget::hide(); - std::for_each(_button_widgets.begin(), _button_widgets.end(), - PointerAssassin()); -} - -void MessageDialog::keyPressHandler(const XKeyEvent &e) -{ - if (e.keycode == _return) { - std::vector