wwindow.cpp
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C++ 代码 · 共 1,324 行 · 第 1/3 页
CPP
1,324 行
}
WEXPORT WWindow::~WWindow() {
/***************************/
destroyWindow();
if( _handle ) {
GUIDestroyWnd( _handle );
_handle = NULL;
}
}
WWindow* WEXPORT WWindow::hasFocus() {
/************************************/
gui_window *hwnd = GUIGetFront();
if( hwnd ) {
return( (WWindow *)GUIGetExtra( hwnd ) );
}
return( NULL );
}
bool WEXPORT WWindow::setFocus() {
/********************************/
if( handle() ) {
GUIBringToFront( handle() );
return( TRUE );
} else {
return( FALSE );
}
}
void WEXPORT WWindow::addChild( WObject* child ) {
/************************************************/
_children.add( child );
}
void WEXPORT WWindow::removeChild( WObject* child ) {
/***************************************************/
_children.removeSame( child );
}
WWindow* WWindow::switchChild( WWindow* currChild, bool forward ) {
/*****************************************************************/
int icount = _children.count();
int index = _children.indexOfSame( currChild );
int startIndex = index;
if( index < 0 ) {
return( NULL );
}
for( ;; ) {
if( forward ) {
index = (index + 1) % icount;
} else {
index = (index + icount - 1) % icount;
}
if( index == startIndex ) return( currChild );
WWindow* w = (WWindow *)_children[ index ];
if( w->isVisible() ) {
if( w->setFocus() ) {
return( w );
}
}
}
}
WWindow* WWindow::nextChild( WWindow* w ) {
/*****************************************/
int icount = _children.count();
for( int i=0; i<icount; i++ ) {
WWindow* nw = (WWindow*)_children[i];
if( w == nw ) {
if( i+1 < icount ) {
return( (WWindow*)_children[ i+1 ] );
}
return( (WWindow*)_children[0] );
}
}
return( NULL );
}
typedef struct key_map {
WKeyCode alt_key;
char ascii;
} key_map;
static key_map KeyMapping[] = {
WKeyAltA, 'A',
WKeyAltB, 'B',
WKeyAltC, 'C',
WKeyAltD, 'D',
WKeyAltE, 'E',
WKeyAltF, 'F',
WKeyAltG, 'G',
WKeyAltH, 'H',
WKeyAltI, 'I',
WKeyAltJ, 'J',
WKeyAltK, 'K',
WKeyAltL, 'L',
WKeyAltM, 'M',
WKeyAltN, 'N',
WKeyAltO, 'O',
WKeyAltP, 'P',
WKeyAltQ, 'Q',
WKeyAltR, 'R',
WKeyAltS, 'S',
WKeyAltT, 'T',
WKeyAltU, 'U',
WKeyAltV, 'V',
WKeyAltW, 'W',
WKeyAltX, 'X',
WKeyAltY, 'Y',
WKeyAltZ, 'Z',
WKeyAlt0, '0',
WKeyAlt1, '1',
WKeyAlt2, '2',
WKeyAlt3, '3',
WKeyAlt4, '4',
WKeyAlt5, '5',
WKeyAlt6, '6',
WKeyAlt7, '7',
WKeyAlt8, '8',
WKeyAlt9, '9',
};
static WKeyCode MapAccelKey( int key ) {
/**************************************/
for( int i = 0; i < sizeof( KeyMapping ); ++i ) {
if( KeyMapping[i].ascii == key ) {
return( KeyMapping[i].alt_key );
}
}
return( WKeyNone );
}
AccelKey *WWindow::findAccelKey( WKeyCode key ) {
/***********************************************/
int icount = _accelKeys.count();
for( int i = 0; i < icount; ++i ) {
AccelKey *ak = (AccelKey *)_accelKeys[i];
if( ak->_key == key ) {
return( ak );
}
}
return( NULL );
}
void WEXPORT WWindow::addAccelKey( WKeyCode key, WObject* client, bcbk cb ) {
/***************************************************************************/
_accelKeys.add( new AccelKey( key, client, cb ) );
}
void WEXPORT WWindow::addAccelKey( int key, WObject* client, bcbk cb ) {
/**********************************************************************/
WKeyCode kc;
if( isalpha( key ) ) {
key = toupper( key );
}
kc = MapAccelKey( key );
if( kc ) {
_accelKeys.add( new AccelKey( kc, client, cb ) );
}
}
void WEXPORT WWindow::removeAccelKey( WKeyCode key ) {
/****************************************************/
AccelKey *ak = findAccelKey( key );
if( ak != NULL ) {
_accelKeys.removeSame( ak );
}
}
void WEXPORT WWindow::close() {
/*****************************/
if( reallyClose() ) {
GUIDestroyWnd( handle() );
setHandle( NULL );
}
}
void WEXPORT WWindow::getText( char* textBuf, unsigned textLen ) {
/****************************************************************/
GUIGetWindowText( _handle, textBuf, textLen );
}
void WEXPORT WWindow::getText( WString& str ) {
/*********************************************/
unsigned len = getTextLength();
char* t = new char[ len+1 ];
getText( t, len+1 );
str = t;
delete [] t;
}
void WEXPORT WWindow::setText( const char *text ) {
/*************************************************/
GUISetWindowText( _handle, (char *)text );
}
WMenu* WEXPORT WWindow::setMenu( WMenu* menu ) {
/**********************************************/
WMenu* oldMenu = clearMenu();
_menu = menu;
_menu->attachMenu( this, 0 );
return( oldMenu );
}
WMenu* WEXPORT WWindow::clearMenu() {
/***********************************/
WMenu* oldMenu = _menu;
if( _menu != NULL ) {
_menu->detachMenu();
_menu = NULL;
}
return( oldMenu );
}
WToolBar* WEXPORT WWindow::setToolBar( WToolBar *toolbar ) {
/**********************************************************/
WToolBar* previous = clearToolBar();
_toolBar = toolbar;
_toolBar->attach( this );
return( previous );
}
WToolBar* WEXPORT WWindow::clearToolBar() {
/*****************************************/
WToolBar* curr = _toolBar;
if( _toolBar != NULL ) {
_toolBar->detach();
_toolBar = NULL;
}
return( curr );
}
void WEXPORT WWindow::setPopup( WPopupMenu* popup ) {
/***************************************************/
_popup = popup;
}
void WEXPORT WWindow::clearPopup() {
/**********************************/
_popup = NULL;
}
void WEXPORT WWindow::insertPopup( WPopupMenu *pop, int index ) {
/***************************************************************/
if( menu() == NULL ) return;
menu()->insertPopup( pop, index );
pop->attachMenu( this, 0 );
}
void WEXPORT WWindow::removePopup( WPopupMenu *pop ) {
/****************************************************/
if( menu() == NULL ) return;
menu()->removePopup( pop );
pop->detachMenu();
}
void WEXPORT WWindow::shrink( int wBorder, int hBorder ) {
/********************************************************/
if( _children.count() > 0 ) {
WRect wr;
getRectangle( wr, FALSE );
int icount = _children.count();
for( int i = 0; i < icount; i++ ) {
WRect cr;
((WWindow*)_children[i])->getRectangle( cr, FALSE );
if( i == 0 ) {
wr.w( cr.x() + cr.w() );
wr.h( cr.y() + cr.h() );
} else {
if( cr.x() + cr.w() > wr.w() ) {
wr.w( cr.x() + cr.w() );
}
if( cr.y() + cr.h() > wr.h() ) {
wr.h( cr.y() + cr.h() );
}
}
}
wr.w( wr.w() + wBorder + 2*frameWidth() );
wr.h( wr.h() + hBorder + WSystemMetrics::captionSize() + 2*frameHeight() );
move( wr );
}
}
void WEXPORT WWindow::shrink() {
/******************************/
WPoint avg;
WPoint max;
textMetrics( avg, max );
shrink( avg.y(), avg.x() );
}
bool WEXPORT WWindow::updateAutosize() {
/**************************************/
WRect rect;
WRect prect;
bool move;
int w_adjust = 0;
int h_adjust = 0;
move = FALSE;
getRectangle( rect );
if( parent() ) {
parent()->getClientRect( prect );
}
if( _autosize.x() >= 0 ) {
if( rect.x() < 0 ) {
// don't let the x co-ordinate change sign in case
// the window is moved outside the client area
_autosize.x( 0 );
if( isMaximized() ) {
w_adjust = rect.x();
}
move = TRUE;
} else {
_autosize.x( rect.x() );
}
}
if( _autosize.y() >= 0 ) {
if( rect.y() < 0 ) {
// don't let the y co-ordinate change sign in case
// the window is moved outside the client area
_autosize.y( 0 );
if( isMaximized() ) {
h_adjust = rect.y();
}
move = TRUE;
} else {
_autosize.y( rect.y() );
}
}
if( _autosize.w() >= 0 ) {
_autosize.w( rect.w() + w_adjust );
}
if( _autosize.h() >= 0 ) {
_autosize.h( rect.h() + h_adjust );
}
return( move );
}
void WEXPORT WWindow::moved( int, int ) {
/***************************************/
if( updateAutosize() ) {
// Don't let the window be moved to a location that
// causes the x and/or y co-ordinates to change from
// a positive value to a negative value
autosize();
}
}
void WEXPORT WWindow::resized( int, int ) {
/*****************************************/
updateAutosize();
}
void WEXPORT WWindow::size( WOrdinal w, WOrdinal h ) {
/****************************************************/
_autosize.w( w );
_autosize.h( h );
autosize();
}
void WEXPORT WWindow::move( WOrdinal x, WOrdinal y ) {
/****************************************************/
_autosize.x( x );
_autosize.y( y );
autosize();
}
void WEXPORT WWindow::move( const WRect& r ) {
/********************************************/
_autosize = r;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?