📄 xsmotifwindow.c
字号:
{
return ("_XsMotifSide");
}
// _expose
void _XsMotifSide::_expose (XEvent *event)
{
if (_topShadowGC == 0) // JACS
return;
// Clear out the window first
if (event != 0)
XClearWindow (XtDisplay (_base), XtWindow (_base));
Dimension w, h;
// Get the size of the side
XtVaGetValues (_base, XmNwidth, &w, XmNheight, &h, NULL);
// Draw the shadow
_drawShadows (0, 0, w, h, 1);
// Draw the extra lines
switch (_side)
{
case Top:
{
_drawLine (1, 1, w - 2, 1, _topShadowGC);
break;
}
case Bottom:
{
_drawLine (1, h - 2, w - 2, h - 2, _bottomShadowGC);
break;
}
case Left:
{
_drawLine (1, 1, 1, h - 2, _topShadowGC);
break;
}
case Right:
{
_drawLine (w - 2, 1, w - 2, h - 2, _bottomShadowGC);
break;
}
default:
assert (0);
}
}
// _input
void _XsMotifSide::_input (XEvent *event)
{
switch (event->type)
{
case ButtonPress:
{
if (event->xbutton.button == 2)
{
XsMoveOutline move (_win->base ( ));
// Start the move
if (move.go ( ) != False)
{
// Relocate the window
_win->setPosition (move.x ( ), move.y ( ));
}
}
else if (event->xbutton.button == 3)
_win->popupMenu ( );
break;
}
case ButtonRelease:
{
switch (event->xbutton.button)
{
case 1:
case 2:
{
_win->raise ( ); // Raise the window
break;
}
}
break;
}
case MotionNotify:
{
// Figure kind of resize we are doing
int dir;
if (_side == Top)
dir = XsResizeOutline::Up;
else if (_side == Bottom)
dir = XsResizeOutline::Down;
else if (_side == Left)
dir = XsResizeOutline::Left;
else if (_side == Right)
dir = XsResizeOutline::Right;
else
assert (0);
XsResizeOutline resize (_win->base ( ), dir);
resize.setMinSize (_win->minWidth ( ), _win->minHeight ( ));
// Start the resize
if (resize.go ( ) != False)
{
// Relocate the window
_win->setPosition (resize.x ( ), resize.y ( ));
_win->setSize (resize.width ( ), resize.height ( ));
}
break;
}
}
}
// _map
void _XsMotifSide::_map ( )
{
// Call the base-class
_XsMotifComponent::_map ( );
// Install the cursor
if (_side == Top)
XDefineCursor (XtDisplay (_base), XtWindow (_base), _cursors[TopCursor]);
else if (_side == Bottom)
XDefineCursor (XtDisplay (_base), XtWindow (_base), _cursors[BottomCursor]);
else if (_side == Left)
XDefineCursor (XtDisplay (_base), XtWindow (_base), _cursors[LeftCursor]);
else if (_side == Right)
XDefineCursor (XtDisplay (_base), XtWindow (_base), _cursors[RightCursor]);
else
assert (0);
}
// _configure
void _XsMotifSide::_configure (XEvent *event)
{
XConfigureEvent *ce = (XConfigureEvent*)event;
/*
Check if window has been resized. If so, generate an expose event
to redraw its contents.
*/
if ((_lastW != ce->width) || (_lastH != ce->height))
{
if ((_base != 0) && XtIsManaged (_base))
XClearArea (XtDisplay (_base), XtWindow (_base), 0, 0, 0, 0, True);
_lastW = ce->width;
_lastH = ce->height;
}
}
// _configureEventHandler
void _XsMotifSide::_configureEventHandler (Widget, XtPointer clientData, XEvent *event, Boolean*)
{
if (event->type == ConfigureNotify)
{
_XsMotifSide *obj = (_XsMotifSide*)clientData;
obj->_configure (event);
}
}
/*
----------------------------------------------------------------------------
_XsMotifButton
*/
// Constructor
_XsMotifButton::_XsMotifButton (const char *name, XsMotifWindow *win, Button button) :
_XsMotifComponent (name, win)
{
// Initialize
_pressed = False;
_button = button;
// Configure the component
XtVaSetValues (_base, XmNheight, _buttonSize, XmNwidth, _buttonSize,
XmNborderWidth, (Dimension)0, NULL);
}
// Destructor
_XsMotifButton::~_XsMotifButton ( )
{
// Empty
}
// redraw
void _XsMotifButton::redraw ( )
{
// Make sure component is viewable
if (!XtIsRealized (_base))
return;
// Check if window is viewable
XWindowAttributes attrs;
XGetWindowAttributes (XtDisplay (_base), XtWindow (_base), &attrs);
if (attrs.map_state == IsViewable)
_expose (0); // Just pretend we got an expose event
}
// className
const char *_XsMotifButton::className ( ) const
{
return ("_XsMotifButton");
}
// _expose
void _XsMotifButton::_expose (XEvent *event)
{
if (_topShadowGC == 0) // JACS
return;
Dimension w, h;
// Get the size of the button
XtVaGetValues (_base, XmNwidth, &w, XmNheight, &h, NULL);
// Draw the shadow
_drawShadows (0, 0, w, h, 1, _pressed);
// Draw the extra line
_drawLine (1, h - 2, w - 2, h - 2, (_pressed) ? _topShadowGC : _bottomShadowGC);
// Check if we need to draw the decal
if ((_button != Maximize) && (event == 0))
return;
// Compute the decal size
Dimension dw, dh;
Boolean reverse = False;
switch (_button)
{
case Menu:
{
dw = _buttonSize - 6;
dh = 4;
break;
}
case Minimize:
{
dw = dh = 4;
break;
}
case Maximize:
{
dw = _buttonSize - 6;
dh = dw - 1;
if (_win->maximized ( ))
reverse = True;
break;
}
default:
assert (0);
}
// Draw the decal
_drawShadows ((w / 2) - (dw / 2), (h / 2) - (dh / 2), dw, dh, 1, reverse);
}
// _input
void _XsMotifButton::_input (XEvent *event)
{
static Time lastTime = (Time)0;
switch (event->type)
{
case ButtonPress:
{
if (event->xbutton.button == 1)
{
_pressed = True;
if (_button == Menu)
{
// Get double-click time
int multiClick = XtGetMultiClickTime (XtDisplay (_base));
// Check for double-click
if ((event->xbutton.time - lastTime) <= multiClick)
{
_win->close ( );
return;
}
else
lastTime = event->xbutton.time;
// Redraw the button (pushed-in)
redraw ( );
// Popup the menu
_win->popupMenu (False);
// The menu will consume the ButtonRelease, so fake one
_pressed = False;
redraw ( );
}
else if ((_button == Minimize) || (_button == Maximize))
{
redraw ( );
}
}
else if (event->xbutton.button == 2)
{
XsMoveOutline move (_win->base ( ));
// Start the move
if (move.go ( ) != False)
{
// Relocate the window
_win->setPosition (move.x ( ), move.y ( ));
}
}
else if (event->xbutton.button == 3)
_win->popupMenu ( );
break;
}
case ButtonRelease:
{
if (event->xbutton.button == 1)
{
_pressed = False;
// Check if pointer is really in the window
XButtonEvent *b = &event->xbutton;
Dimension width, height;
Boolean inWindow = False;
XtVaGetValues (_base, XmNwidth, &width, XmNheight, &height, NULL);
if ((b->x >= 0) && (b->y >= 0) && (b->x < width) && (b->y < height))
inWindow = True;
if (_button == Minimize)
{
if (inWindow)
{
if (_win->minimized ( ))
_win->restore ( );
else
_win->minimize ( );
}
else
redraw ( );
}
else if (_button == Maximize)
{
if (inWindow)
{
if (_win->maximized ( ))
_win->restore ( );
else
_win->maximize ( );
}
else
redraw ( );
}
}
break;
}
}
}
// _map
void _XsMotifButton::_map ( )
{
// Call the base-class
_XsMotifComponent::_map ( );
// Raise ourself
XRaiseWindow (XtDisplay (_base), XtWindow (_base));
}
/*
----------------------------------------------------------------------------
_XsMotifTitle
*/
XtResource _XsMotifTitle::_resourceList[] = {
{
"title",
"Title",
XmRString,
sizeof (String),
XtOffset (_XsMotifTitle*, _titleString),
XmRImmediate,
NULL
},
{
"titleFont",
"TitleFont",
XmRFontStruct,
sizeof (XFontStruct*),
XtOffset (_XsMotifTitle*, _titleFont),
XmRString,
"-*-helvetica-bold-o-normal-*-14-*-*-*-*-*-iso8859-1"
}
};
// Constructor
_XsMotifTitle::_XsMotifTitle (const char *name, XsMotifWindow *win) :
_XsMotifComponent (name, win)
{
// Initialize
_pressed = False;
_titleString = 0;
_titleFont = 0;
_fontGC = 0;
_lastW = _lastH = -1;
// Get resources
_getResources (_resourceList, XtNumber (_resourceList));
// Copy title string to local memory
if (_titleString != 0)
{
char *tmp = new char[strlen (_titleString) + 1];
strcpy (tmp, _titleString);
_titleString = tmp;
}
// Configure the title
XtVaSetValues (_base, XmNheight, _buttonSize, XmNborderWidth,
(Dimension)0, NULL);
// Install event handler
XtAddEventHandler (_base, StructureNotifyMask, False, _configureEventHandler, (XtPointer)this);
}
// Destructor
_XsMotifTitle::~_XsMotifTitle ( )
{
if (_fontGC)
XtReleaseGC (_base, _fontGC);
delete [] _titleString;
}
// setTitle
void _XsMotifTitle::setTitle (const char *title)
{
assert (title != 0);
delete [] _titleString;
_titleString = new char[strlen (title) + 1];
strcpy (_titleString, title);
}
// className
const char *_XsMotifTitle::className ( ) const
{
return ("_XsMotifTitle");
}
// _componentDestroyed
void _XsMotifTitle::_componentDestroyed ( )
{
// Clean up the GCs
if (_fontGC)
XtReleaseGC (_base, _fontGC);
_fontGC = 0;
// Call base-class
_XsMotifComponent::_componentDestroyed ( );
}
// _redraw
void _XsMotifTitle::_redraw ( )
{
_expose (0); // Just pretend we got an expose event
}
// _expose
void _XsMotifTitle::_expose (XEvent *event)
{
if (_topShadowGC == 0) // JACS
return;
// Clear out the window first
if (event != 0)
XClearWindow (XtDisplay (_base), XtWindow (_base));
Dimension w, h;
// Get the size of the button
XtVaGetValues (_base, XmNwidth, &w, XmNheight, &h, NULL);
// Draw the shadow
_drawShadows (0, 0, w, h, 1, _pressed);
// Draw the extra line
_drawLine (1, h - 2, w - 2, h - 2, (_pressed) ? _topShadowGC : _bottomShadowGC);
// If this is an artificial event, no need continuing
if (event == 0)
return;
// Draw the text string
const int LeftOffset = 5;
const int TopOffset = 2;
// Figure out the title
const char *title = (_titleString != 0) ? _titleString : _win->name ( );
if ((title != 0) && (title[0] != '\0'))
{
int len = strlen (title);
XDrawString (XtDisplay (_base), XtWindow (_base), _fontGC,
LeftOffset, TopOffset + _titleFont->ascent, title, len);
}
}
// _input
void _XsMotifTitle::_input (XEvent *event)
{
switch (event->type)
{
case ButtonPress:
{
switch (event->xbutton.button)
{
case 1:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -