📄 abstractx11control.cpp
字号:
//AbstractX11Control.cpp/*Copyright 2000-2004 The VCF Project.Please see License.txt in the top level directorywhere you installed the VCF.*/#include "vcf/ApplicationKit/ApplicationKit.h"#include "vcf/ApplicationKit/ApplicationKitPrivate.h"#include "vcf/ApplicationKit/AbstractX11Control.h"#include "vcf/ApplicationKit/X11UIToolkit.h"using namespace VCF;std::map<xLib::Window,AbstractX11Control*> AbstractX11Control::xwndControlMap;AbstractX11Control::AbstractX11Control(): wndHandle_(0), control_(NULL), parent_(NULL), currentButtonState_(0), currentKeyState_(0), enabled_(true){}AbstractX11Control::~AbstractX11Control(){ if ( NULL != wndHandle_ ) { AbstractX11Control::unRegisterX11Control( this ); X11GraphicsToolkit* grafToolkit = (X11GraphicsToolkit*)GraphicsToolkit::getDefaultGraphicsToolkit(); XDestroyWindow( grafToolkit->getX11Display(), wndHandle_ ); }}void AbstractX11Control::registerX11Control( AbstractX11Control* x11Control ){ AbstractX11Control::xwndControlMap[x11Control->wndHandle_] = x11Control;}void AbstractX11Control::unRegisterX11Control( AbstractX11Control* x11Control ){ XwndControlMap::iterator found = AbstractX11Control::xwndControlMap.find( x11Control->wndHandle_ ); if ( found != AbstractX11Control::xwndControlMap.end() ) { AbstractX11Control::xwndControlMap.erase( found ); } X11UIToolkit* toolkit = reinterpret_cast<X11UIToolkit*>( UIToolkit::getDefaultUIToolkit() ); toolkit->removeControlFromPaintEventQueue( x11Control );}AbstractX11Control* AbstractX11Control::getX11ControlFromXWindow( xLib::Window wndHandle ){ AbstractX11Control* result = NULL; XwndControlMap::iterator found = AbstractX11Control::xwndControlMap.find( wndHandle ); if ( found != AbstractX11Control::xwndControlMap.end() ) { result = found->second; } return result;}/** * returns a text associated with the component. This usually gets used in the Control::getCaption() method. */String AbstractX11Control::getText(){ String result; return result;}/** * sets the text for the widget */void AbstractX11Control::setText( const String& text ){}/** * sets the bounds for the component. Bounds are specified in the coordinate system of the componenents parent. */void AbstractX11Control::setBounds( Rect* rect ){ X11GraphicsToolkit* grafToolkit = (X11GraphicsToolkit*)GraphicsToolkit::getDefaultGraphicsToolkit(); bounds_ = *rect; int l = (long)bounds_.left_; int t = (long)bounds_.top_; int w = (long)maxVal<double>(bounds_.getWidth(), 1.0 ); int h = (long)maxVal<double>(bounds_.getHeight(), 1.0 ); XMoveResizeWindow( grafToolkit->getX11Display(), wndHandle_, l, t, w, h );}/***advanced function for changing the size of multiple child windows*/bool AbstractX11Control::beginSetBounds( const ulong32& numberOfChildren ){ //X11GraphicsToolkit* grafToolkit = (X11GraphicsToolkit*)GraphicsToolkit::getDefaultGraphicsToolkit(); //XSync( grafToolkit->getX11Display(), False ); return true;}void AbstractX11Control::endSetBounds(){}/** * returns the bounds of the component in the coordinate system of the parent. */Rect* AbstractX11Control::getBounds(){ /* xLib::Window rootWnd = 0; int x = 0; int y = 0; unsigned int width = 0; unsigned int height = 0; unsigned int borderWidth = 0; unsigned int depth = 0; if ( NULL == wndHandle_ ) { throw InvalidPointerException( MAKE_ERROR_MSG_2("wndHandle_ is NULL!!!") ); } X11GraphicsToolkit* grafToolkit = (X11GraphicsToolkit*)GraphicsToolkit::getDefaultGraphicsToolkit(); XGetGeometry( grafToolkit->getX11Display(), wndHandle_, &rootWnd, &x, &y, &width, &height, &borderWidth, &depth ); bounds_.left_ = x; bounds_.top_ = y; bounds_.right_ = bounds_.left_ + (double)width; bounds_.bottom_ = bounds_.top_ + (double)height; */ return &bounds_;}/** * shows or hides the component. * This does NOT close the component (if invoked on a frame based component ). */void AbstractX11Control::setVisible( const bool& visible ){ if ( visible != visible_ ) { X11GraphicsToolkit* grafToolkit = (X11GraphicsToolkit*)GraphicsToolkit::getDefaultGraphicsToolkit(); if ( true == visible ) { XMapWindow( grafToolkit->getX11Display(), wndHandle_ ); } else { XUnmapWindow( grafToolkit->getX11Display(), wndHandle_ ); } } visible_ = visible;}/** * returns wether or not the component is currently visible. */bool AbstractX11Control::getVisible(){ return visible_;}/** * returns a bit-masked unsigned long that contains style constants. * These style constants are defined in the VCF, and must * be translated to the particular windowing system being used. */unsigned long AbstractX11Control::getStyleMask(){ return 0;}/** * sets the current style mask. * Should cause a repaint of the component, if neccessary. */void AbstractX11Control::setStyleMask( const unsigned long& styleMask ){}/** * returns the component that this Peer is attached to. */Control* AbstractX11Control::getControl(){ return control_;}/** * attahces the Peer to a particular component. This should only be done once. */void AbstractX11Control::setControl( Control* component ){ control_ = component;}void AbstractX11Control::setCursor( Cursor* cursor ){ if ( NULL != cursor ) { X11GraphicsToolkit* grafToolkit = reinterpret_cast<X11GraphicsToolkit*>(GraphicsToolkit::getDefaultGraphicsToolkit()); if ( Cursor::SCT_DEFAULT == cursor->getCursorID() ) { XUndefineCursor( grafToolkit->getX11Display(), wndHandle_ ); } else { XDefineCursor( grafToolkit->getX11Display(), wndHandle_, (xLib::Cursor)cursor->getPeer()->getCursorHandleID() ); } }}void AbstractX11Control::setParent( Control* parent ){ X11GraphicsToolkit* grafToolkit = (X11GraphicsToolkit*)GraphicsToolkit::getDefaultGraphicsToolkit(); if ( NULL == parent ) { parent_ = NULL; XReparentWindow( grafToolkit->getX11Display(), wndHandle_, NULL, (long)bounds_.left_, (long)bounds_.top_ ); } else { parent_ = dynamic_cast<AbstractX11Control*>( parent->getPeer() ); if ( NULL == parent_ ) { throw InvalidPointerException( MAKE_ERROR_MSG_2("Invalid peer type being used as a parent") ); } XReparentWindow( grafToolkit->getX11Display(), wndHandle_, parent_->wndHandle_, (long)bounds_.left_, (long)bounds_.top_ ); }}Control* AbstractX11Control::getParent(){ Control* result = NULL; if ( NULL != parent_ ) { result = parent_->getControl(); } return result;}bool AbstractX11Control::isFocused(){ X11GraphicsToolkit* grafToolkit = (X11GraphicsToolkit*)GraphicsToolkit::getDefaultGraphicsToolkit(); xLib::Window focusWnd = 0; int revert = 0; XGetInputFocus( grafToolkit->getX11Display(), &focusWnd, &revert ); return focusWnd == wndHandle_;}void AbstractX11Control::setFocus( const bool& focused ){ if ( focused ) { if ( !isFocused() ) { try { X11GraphicsToolkit* grafToolkit = (X11GraphicsToolkit*)GraphicsToolkit::getDefaultGraphicsToolkit(); //XSetInputFocus( grafToolkit->getX11Display(), wndHandle_, RevertToNone, CurrentTime ); } catch ( BasicException& ) { printf( "can't set focus\n" ); } } //printf( "XSetInputFocus( %p, %p, %d, %d )\n", // grafToolkit->getX11Display(), wndHandle_, RevertToNone, CurrentTime ); //this is not working at the momement } else { }}bool AbstractX11Control::isEnabled(){ return enabled_;}void AbstractX11Control::setEnabled( const bool& enabled ){ if ( enabled == enabled_ ) { return; } enabled_ = enabled; Container* container = control_->getContainer(); if ( NULL != container ) { Enumerator<Control*>* children = container->getChildren(); while ( children->hasMoreElements() ) { Control* child = children->nextElement(); child->setEnabled( enabled_ ); } } repaint();}void AbstractX11Control::setFont( Font* font ){}void AbstractX11Control::repaint( Rect* repaintRect ){ Rect * bounds = NULL; X11UIToolkit* toolkit = reinterpret_cast<X11UIToolkit*>( UIToolkit::getDefaultUIToolkit() ); if ( NULL == repaintRect ) { toolkit->repaintControl( this, bounds_ ); } else { toolkit->repaintControl( this, *repaintRect ); }}/***this keeps the mouse events being sent to this control, even is the*mouse leaves the physical bounds of the control*/void AbstractX11Control::keepMouseEvents(){ X11UIToolkit* toolkit = reinterpret_cast<X11UIToolkit*>( UIToolkit::getDefaultUIToolkit() ); toolkit->xGrabPointer( this );}/***releases mouse events - goes back to normal event handling*/void AbstractX11Control::releaseMouseEvents(){ X11UIToolkit* toolkit = reinterpret_cast<X11UIToolkit*>( UIToolkit::getDefaultUIToolkit() ); toolkit->xUnGrabPointer( this );}void AbstractX11Control::handleXEvent( xLib::Window wndHandle, XEvent* x11Event ){ AbstractX11Control* target = AbstractX11Control::getX11ControlFromXWindow( wndHandle ); if ( NULL != target ) { target->handleEvent( x11Event ); }}void AbstractX11Control::handleEvent( XEvent* x11Event ){ X11EventMsg eventMsg(x11Event, control_ ); Event* event = UIToolkit::getDefaultUIToolkit()->createEventFromNativeOSEventData( &eventMsg ); X11UIToolkit* toolkit = reinterpret_cast<X11UIToolkit*>( UIToolkit::getDefaultUIToolkit() ); bool eventHandled = false; switch ( x11Event->type ) { case KeyPress : { if ( true == enabled_ ) { currentKeyState_ = x11Event->xkey.state; if ( NULL != event ) { KeyboardEvent* srcEvent = (KeyboardEvent*)event; KeyboardEvent keyPressEvent( srcEvent->getSource(), Control::KEYBOARD_PRESSED, 1, srcEvent->getKeyMask(), srcEvent->getKeyValue(), srcEvent->getVirtualCode() ); //note - we may need to send then AFTER the KeyPress original event (a Control::KEYBOARD_DOWN //event) control_->handleEvent( &keyPressEvent ); } } else { //skip the event handling eventHandled = true; } } break; case KeyRelease : { currentKeyState_ = x11Event->xkey.state; if ( false == enabled_ ) { //skip the event handling eventHandled = true; } } break; case ButtonPress : { currentKeyState_ = x11Event->xbutton.state; currentButtonState_ = x11Event->xbutton.button; if ( false == enabled_ ) { //skip the event handling
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -