📄 fl.cxx
字号:
// MRS: Originally we checked the button state, but a user reported that it
// broke click-to-focus in FLWM?!?
// if (!(Fl::event_state() & 0x7f00000 /*FL_BUTTONS*/)) {
if (!Fl::pushed()) {
// set belowmouse based on Fl::modal() and fl_xmousewin:
w = fl_xmousewin;
if (w) {
if (Fl::modal()) w = Fl::modal();
if (!w->contains(Fl::belowmouse())) {
w->handle(FL_ENTER);
if (!w->contains(Fl::belowmouse())) Fl::belowmouse(w);
} else {
// send a FL_MOVE event so the enter/leave state is up to date
Fl::e_x = Fl::e_x_root-fl_xmousewin->x();
Fl::e_y = Fl::e_y_root-fl_xmousewin->y();
w->handle(FL_MOVE);
}
} else {
Fl::belowmouse(0);
Fl_Tooltip::enter(0);
}
}
}
#ifndef WIN32
extern Fl_Widget *fl_selection_requestor; // from Fl_x.cxx
#endif
// This function is called by ~Fl_Widget() and by Fl_Widget::deactivate
// and by Fl_Widget::hide(). It indicates that the widget does not want
// to receive any more events, and also removes all global variables that
// point at the widget.
// I changed this from the 1.0.1 behavior, the older version could send
// FL_LEAVE or FL_UNFOCUS events to the widget. This appears to not be
// desirable behavior and caused flwm to crash.
void fl_throw_focus(Fl_Widget *o) {
if (o->contains(Fl::pushed())) Fl::pushed_ = 0;
#ifndef WIN32
if (o->contains(fl_selection_requestor)) fl_selection_requestor = 0;
#endif
if (o->contains(Fl::belowmouse())) Fl::belowmouse_ = 0;
if (o->contains(Fl::focus())) Fl::focus_ = 0;
if (o == fl_xfocus) fl_xfocus = 0;
if (o == Fl_Tooltip::current()) Fl_Tooltip::current(0);
if (o == fl_xmousewin) fl_xmousewin = 0;
Fl_Tooltip::exit(o);
fl_fix_focus();
}
////////////////////////////////////////////////////////////////
// Call to->handle but first replace the mouse x/y with the correct
// values to account for nested X windows. 'window' is the outermost
// window the event was posted to by X:
static int send(int event, Fl_Widget* to, Fl_Window* window) {
int dx = window->x();
int dy = window->y();
for (const Fl_Widget* w = to; w; w = w->parent())
if (w->type()>=FL_WINDOW) {dx -= w->x(); dy -= w->y();}
int save_x = Fl::e_x; Fl::e_x += dx;
int save_y = Fl::e_y; Fl::e_y += dy;
int ret = to->handle(event);
Fl::e_y = save_y;
Fl::e_x = save_x;
return ret;
}
int Fl::handle(int e, Fl_Window* window)
{
e_number = e;
if (fl_local_grab) return fl_local_grab(e);
Fl_Widget* wi = window;
switch (e) {
case FL_CLOSE:
if (grab() || modal() && window != modal()) return 0;
wi->do_callback();
return 1;
case FL_SHOW:
wi->show(); // this calls Fl_Widget::show(), not Fl_Window::show()
return 1;
case FL_HIDE:
wi->hide(); // this calls Fl_Widget::hide(), not Fl_Window::hide()
return 1;
case FL_PUSH:
if (grab()) wi = grab();
else if (modal() && wi != modal()) return 0;
pushed_ = wi;
Fl_Tooltip::current(wi);
if (send(e, wi, window)) return 1;
// raise windows that are clicked on:
window->show();
return 1;
case FL_DND_ENTER:
case FL_DND_DRAG:
dnd_flag = 1;
break;
case FL_DND_LEAVE:
dnd_flag = 1;
belowmouse(0);
dnd_flag = 0;
return 1;
case FL_DND_RELEASE:
wi = belowmouse();
break;
case FL_MOVE:
case FL_DRAG:
fl_xmousewin = window; // this should already be set, but just in case.
if (pushed()) {
wi = pushed();
if (grab()) wi = grab();
e_number = e = FL_DRAG;
break;
}
if (modal() && wi != modal()) wi = 0;
if (grab()) wi = grab();
{Fl_Widget* pbm = belowmouse();
int ret = (wi && send(e, wi, window));
if (pbm != belowmouse()) Fl_Tooltip::enter(belowmouse());
return ret;}
case FL_RELEASE: {
// printf("FL_RELEASE: window=%p, pushed() = %p, grab() = %p, modal() = %p\n",
// window, pushed(), grab(), modal());
if (grab()) {
wi = grab();
pushed_ = 0; // must be zero before callback is done!
} else if (pushed()) {
wi = pushed();
pushed_ = 0; // must be zero before callback is done!
} else if (modal() && wi != modal()) return 0;
int r = send(e, wi, window);
fl_fix_focus();
return r;}
case FL_UNFOCUS:
window = 0;
case FL_FOCUS:
fl_xfocus = window;
fl_fix_focus();
return 1;
case FL_KEYBOARD:
Fl_Tooltip::enter((Fl_Widget*)0);
fl_xfocus = window; // this should not happen! But maybe it does:
// Try it as keystroke, sending it to focus and all parents:
for (wi = grab() ? grab() : focus(); wi; wi = wi->parent())
if (send(FL_KEYBOARD, wi, window)) return 1;
// recursive call to try shortcut:
if (handle(FL_SHORTCUT, window)) return 1;
// and then try a shortcut with the case of the text swapped, by
// changing the text and falling through to FL_SHORTCUT case:
{char* c = (char*)event_text(); // cast away const
if (!isalpha(*c)) return 0;
*c = isupper(*c) ? tolower(*c) : toupper(*c);}
e_number = e = FL_SHORTCUT;
case FL_SHORTCUT:
if (grab()) {wi = grab(); break;} // send it to grab window
// Try it as shortcut, sending to mouse widget and all parents:
wi = belowmouse(); if (!wi) {wi = modal(); if (!wi) wi = window;}
for (; wi; wi = wi->parent()) if (send(FL_SHORTCUT, wi, window)) return 1;
// try using add_handle() functions:
if (send_handlers(FL_SHORTCUT)) return 1;
// make Escape key close windows:
if (event_key()==FL_Escape) {
wi = modal(); if (!wi) wi = window;
wi->do_callback();
return 1;
}
return 0;
case FL_ENTER:
fl_xmousewin = window;
fl_fix_focus();
Fl_Tooltip::enter(belowmouse());
return 1;
case FL_LEAVE:
if (!pushed_) {
belowmouse(0);
Fl_Tooltip::enter(0);
}
if (window == fl_xmousewin) {fl_xmousewin = 0; fl_fix_focus();}
return 1;
case FL_MOUSEWHEEL:
fl_xfocus = window; // this should not happen! But maybe it does:
// Try it as keystroke, sending it to focus and all parents:
for (wi = grab() ? grab() : focus(); wi; wi = wi->parent())
if (send(FL_MOUSEWHEEL, wi, window)) return 1;
default:
break;
}
if (wi && send(e, wi, window)) {
dnd_flag = 0;
return 1;
}
dnd_flag = 0;
return send_handlers(e);
}
////////////////////////////////////////////////////////////////
// hide() destroys the X window, it does not do unmap!
#if !defined(WIN32) && USE_XFT
extern void fl_destroy_xft_draw(Window);
#endif
void Fl_Window::hide() {
clear_visible();
if (!shown()) return;
// remove from the list of windows:
Fl_X* ip = i;
Fl_X** pp = &Fl_X::first;
for (; *pp != ip; pp = &(*pp)->next) if (!*pp) return;
*pp = ip->next;
#ifdef __APPLE__
// remove all childwindow links
for ( Fl_X *pc = Fl_X::first; pc; pc = pc->next )
{
if ( pc->xidNext == ip ) pc->xidNext = ip->xidNext;
if ( pc->xidChildren == ip ) pc->xidChildren = ip->xidNext;
}
#endif // __APPLE__
i = 0;
// recursively remove any subwindows:
for (Fl_X *wi = Fl_X::first; wi;) {
Fl_Window* W = wi->w;
if (W->window() == this) {
W->hide();
W->set_visible();
wi = Fl_X::first;
} else wi = wi->next;
}
if (this == Fl::modal_) { // we are closing the modal window, find next one:
Fl_Window* W;
for (W = Fl::first_window(); W; W = Fl::next_window(W))
if (W->modal()) break;
Fl::modal_ = W;
}
// Make sure no events are sent to this window:
fl_throw_focus(this);
handle(FL_HIDE);
#ifdef WIN32
if (ip->private_dc) ReleaseDC(ip->xid,ip->private_dc);
if (ip->xid == fl_window && fl_gc) {
ReleaseDC(fl_window, fl_gc);
fl_window = (HWND)-1;
fl_gc = 0;
}
#elif defined(__APPLE__)
if ( ip->xid == fl_window )
fl_window = 0;
#else
if (ip->region) XDestroyRegion(ip->region);
#endif
#ifdef __APPLE__
if ( !parent() ) // don't destroy shared windows!
{
//+ RemoveTrackingHandler( dndTrackingHandler, ip->xid );
//+ RemoveReceiveHandler( dndReceiveHandler, ip->xid );
XDestroyWindow(fl_display, ip->xid);
}
#else
# if USE_XFT
fl_destroy_xft_draw(ip->xid);
# endif
XDestroyWindow(fl_display, ip->xid);
#endif
#ifdef WIN32
// Try to stop the annoying "raise another program" behavior
if (non_modal() && Fl::first_window() && Fl::first_window()->shown())
Fl::first_window()->show();
#endif
delete ip;
}
Fl_Window::~Fl_Window() {
hide();
}
// FL_SHOW and FL_HIDE are called whenever the visibility of this widget
// or any parent changes. We must correctly map/unmap the system's window.
// For top-level windows it is assummed the window has already been
// mapped or unmapped!!! This is because this should only happen when
// Fl_Window::show() or Fl_Window::hide() is called, or in response to
// iconize/deiconize events from the system.
int Fl_Window::handle(int ev)
{
if (parent()) {
switch (ev) {
case FL_SHOW:
if (!shown()) show();
else XMapWindow(fl_display, fl_xid(this)); // extra map calls are harmless
break;
case FL_HIDE:
if (shown()) {
// Find what really turned invisible, if is was a parent window
// we do nothing. We need to avoid unnecessary unmap calls
// because they cause the display to blink when the parent is
// remapped. However if this or any intermediate non-window
// widget has really had hide() called directly on it, we must
// unmap because when the parent window is remapped we don't
// want to reappear.
if (visible()) {
Fl_Widget* p = parent(); for (;p->visible();p = p->parent()) {}
if (p->type() >= FL_WINDOW) break; // don't do the unmap
}
XUnmapWindow(fl_display, fl_xid(this));
}
break;
}
// } else if (ev == FL_FOCUS || ev == FL_UNFOCUS) {
// Fl_Tooltip::exit(Fl_Tooltip::current());
}
return Fl_Group::handle(ev);
}
////////////////////////////////////////////////////////////////
// Back compatability cut & paste functions for fltk 1.1 only:
void Fl::selection_owner(Fl_Widget *owner) {selection_owner_ = owner;}
void Fl::selection(Fl_Widget &owner, const char* text, int len) {
selection_owner_ = &owner;
Fl::copy(text, len, 0);
}
void Fl::paste(Fl_Widget &receiver) {
Fl::paste(receiver, 0);
}
////////////////////////////////////////////////////////////////
#include <FL/fl_draw.H>
void Fl_Widget::redraw() {
damage(FL_DAMAGE_ALL);
}
void Fl_Widget::redraw_label() {
if (window()) {
if (box() == FL_NO_BOX) {
// Widgets with the FL_NO_BOX boxtype need a parent to
// redraw, since it is responsible for redrawing the
// background...
int X = x() > 0 ? x() - 1 : 0;
int Y = y() > 0 ? y() - 1 : 0;
window()->damage(FL_DAMAGE_ALL, X, Y, w() + 2, h() + 2);
}
if (align() && !(align() & FL_ALIGN_INSIDE) && window()->shown()) {
// If the label is not inside the widget, compute the location of
// the label and redraw the window within that bounding box...
int W = 0, H = 0;
label_.measure(W, H);
W += 5; // Add a little to the size of the label to cover overflow
H += 5;
if (align() & FL_ALIGN_BOTTOM) {
window()->damage(FL_DAMAGE_EXPOSE, x(), y() + h(), w(), H);
} else if (align() & FL_ALIGN_TOP) {
window()->damage(FL_DAMAGE_EXPOSE, x(), y() - H, w(), H);
} else if (align() & FL_ALIGN_LEFT) {
window()->damage(FL_DAMAGE_EXPOSE, x() - W, y(), W, h());
} else if (align() & FL_ALIGN_RIGHT) {
window()->damage(FL_DAMAGE_EXPOSE, x() + w(), y(), W, h());
} else {
window()->damage(FL_DAMAGE_ALL);
}
} else {
// The label is inside the widget, so just redraw the widget itself...
damage(FL_DAMAGE_ALL);
}
}
}
void Fl_Widget::damage(uchar fl) {
if (type() < FL_WINDOW) {
// damage only the rectangle covered by a child widget:
damage(fl, x(), y(), w(), h());
} else {
// damage entire window by deleting the region:
Fl_X* i = Fl_X::i((Fl_Window*)this);
if (!i) return; // window not mapped, so ignore it
if (i->region) {XDestroyRegion(i->region); i->region = 0;}
damage_ |= fl;
Fl::damage(FL_DAMAGE_CHILD);
}
}
void Fl_Widget::damage(uchar fl, int X, int Y, int W, int H) {
Fl_Widget* wi = this;
// mark all parent widgets between this and window with FL_DAMAGE_CHILD:
while (wi->type() < FL_WINDOW) {
wi->damage_ |= fl;
wi = wi->parent();
if (!wi) return;
fl = FL_DAMAGE_CHILD;
}
Fl_X* i = Fl_X::i((Fl_Window*)wi);
if (!i) return; // window not mapped, so ignore it
if (X<=0 && Y<=0 && W>=wi->w() && H>=wi->h()) {
// if damage covers entire window delete region:
wi->damage(fl);
return;
}
// clip the damage to the window and quit if none:
if (X < 0) {W += X; X = 0;}
if (Y < 0) {H += Y; Y = 0;}
if (W > wi->w()-X) W = wi->w()-X;
if (H > wi->h()-Y) H = wi->h()-Y;
if (W <= 0 || H <= 0) return;
if (wi->damage()) {
// if we already have damage we must merge with existing region:
if (i->region) {
#ifdef WIN32
Fl_Region R = XRectangleRegion(X, Y, W, H);
CombineRgn(i->region, i->region, R, RGN_OR);
XDestroyRegion(R);
#elif defined(__APPLE__)
Fl_Region R = NewRgn();
SetRectRgn(R, X, Y, X+W, Y+H);
UnionRgn(R, i->region, i->region);
DisposeRgn(R);
#else
XRectangle R;
R.x = X; R.y = Y; R.width = W; R.height = H;
XUnionRectWithRegion(&R, i->region, i->region);
#endif
}
wi->damage_ |= fl;
} else {
// create a new region:
if (i->region) XDestroyRegion(i->region);
i->region = XRectangleRegion(X,Y,W,H);
wi->damage_ = fl;
}
Fl::damage(FL_DAMAGE_CHILD);
}
void Fl_Window::flush() {
make_current();
//if (damage() == FL_DAMAGE_EXPOSE && can_boxcheat(box())) fl_boxcheat = this;
fl_clip_region(i->region); i->region = 0;
draw();
}
//
// End of "$Id: Fl.cxx,v 1.1.1.1 2003/06/03 22:25:41 agno Exp $".
//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -