⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fl_x.cxx

📁 PIXIL is a small footprint operating environment, complete with PDA PIM applications, a browser and
💻 CXX
📖 第 1 页 / 共 4 页
字号:
//// "$Id: Fl_x.cxx,v 1.1.1.1 2003/08/07 21:18:40 jasonk Exp $"//// X specific code for the Fast Light Tool Kit (FLTK).//// Copyright 1998-1999 by Bill Spitzak and others.//// This library is free software; you can redistribute it and/or// modify it under the terms of the GNU Library General Public// License as published by the Free Software Foundation; either// version 2 of the License, or (at your option) any later version.//// This library is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU// Library General Public License for more details.//// You should have received a copy of the GNU Library General Public// License along with this library; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307// USA.//// Please report all bugs and problems to "fltk-bugs@easysw.com".//#ifdef WIN32#include "Fl_win32.cxx"//for Nano-x,by tanghao#else#include <config.h>#include <FL/Fl.H>#ifdef NANO_X#include <nxdraw.h>#include <FL/x.H>#include <FL/Fl_Window.H>#include <ctype.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include <sys/time.h>#include <iostream.h>#define CONSOLIDATE_MOTION 1/**** Define this if your keyboard lacks a backspace key... ****//* #define BACKSPACE_HACK 1 */////////////////////////////////////////////////////////////////// interface to poll/select call:#if HAVE_POLL#include <poll.h>static pollfd *pollfds = 0;#else#if HAVE_SYS_SELECT_H#  include <sys/select.h>#endif /* HAVE_SYS_SELECT_H */// The following #define is only needed for HP-UX 9.x and earlier://#define select(a,b,c,d,e) select((a),(int *)(b),(int *)(c),(int *)(d),(e))static fd_set fdsets[3];static int maxfd;#define POLLIN 1#define POLLOUT 4#define POLLERR 8#endif /* HAVE_POLL *//* JHC 09/19/00 - Added this array to simplify grabbing keystrokes *//* Because we care about so many different modifiers, its almost easier *//* to have an array instead of a million if statements *//* I think I have everything mapped, but check me for accuracy */static struct{  unsigned short key;  unsigned short value;}keymap_array[] ={  {  MWKEY_ENTER, FL_Enter}  , {  MWKEY_BACKSPACE, FL_BackSpace}  , {  MWKEY_TAB, FL_Tab}  , {  MWKEY_SCROLLOCK, FL_Scroll_Lock}  , {	MWKEY_ESCAPE, FL_Escape}	, {  MWKEY_HOME, FL_Home}  , {  MWKEY_LEFT, FL_Left}  , {  MWKEY_UP, FL_Up}  , {  MWKEY_RIGHT, FL_Right}  , {  MWKEY_DOWN, FL_Down}  , {  MWKEY_PAGEUP, FL_Page_Up}  , {  MWKEY_PAGEDOWN, FL_Page_Down}  , {  MWKEY_END, FL_End}  ,    //  { 99 , FL_Insert},  {  MWKEY_BACKSPACE, FL_BackSpace}  , {  MWKEY_KP_ENTER, FL_KP_Enter}  , {  MWKEY_KP7, FL_KP + '7'}  , {  MWKEY_KP4, FL_KP + '4'}  , {  MWKEY_KP8, FL_KP + '8'}  , {  MWKEY_KP6, FL_KP + '6'}  , {  MWKEY_KP2, FL_KP + '2'}  , {  MWKEY_KP9, FL_KP + '9'}  , {  MWKEY_KP3, FL_KP + '3'}  , {  MWKEY_KP1, FL_KP + '1'}  , {  MWKEY_KP5, FL_KP + '5'}  , {  MWKEY_KP0, FL_KP + '0'}  , {  MWKEY_KP_PERIOD, FL_KP + '.'}  , {  MWKEY_KP_MULTIPLY, FL_KP + '*'}  , {  MWKEY_KP_PLUS, FL_KP + '+'}  , {  MWKEY_KP_MINUS, FL_KP + '-'}  , {  MWKEY_KP_DIVIDE, FL_KP + '/'}  , {  MWKEY_F1, FL_F + 1}  , {  MWKEY_F2, FL_F + 2}  , {  MWKEY_F3, FL_F + 3}  , {  MWKEY_F4, FL_F + 4}  , {  MWKEY_F5, FL_F + 5}  , {  MWKEY_F6, FL_F + 6}  , {  MWKEY_F7, FL_F + 7}  , {  MWKEY_F8, FL_F + 8}  , {  MWKEY_F9, FL_F + 9}  , {  MWKEY_F10, FL_F + 10}  , {  MWKEY_F11, FL_F + 11}  , {  MWKEY_F12, FL_F + 12}  , {  MWKEY_RSHIFT, FL_Shift_R}  , {  MWKEY_LSHIFT, FL_Shift_L}  , {  MWKEY_LCTRL, FL_Control_L}  , {  MWKEY_RCTRL, FL_Control_R}  , {  MWKEY_CAPSLOCK, FL_Caps_Lock}  , {  MWKEY_LMETA, FL_Alt_L}  , {  MWKEY_RMETA, FL_Alt_R}  , {  MWKEY_DELETE, FL_Delete}  , {  0, 0}};static int nfds = 0;static int fd_array_size = 0;static struct FD{  int fd;  short events;  void (*cb) (int, void *);  void *arg;} *fd = 0;voidFl::add_fd (int n, int events, void (*cb) (int, void *), void *v){  if (events != POLLIN) return;  remove_fd (n, events);  GrRegisterInput(n);  int i = nfds++;  if (i >= fd_array_size) {    fd_array_size = 2 * fd_array_size + 1;    fd = (FD *) realloc (fd, fd_array_size * sizeof (FD));#ifdef JEFFM_FUGLY#if HAVE_POLL    pollfds = (pollfd *) realloc (pollfds, fd_array_size * sizeof (pollfd));#endif#endif  }  fd[i].fd = n;  fd[i].events = events;  fd[i].cb = cb;  fd[i].arg = v;#ifdef JEFFM_FUGLY#if HAVE_POLL  fds[i].fd = n;  fds[i].events = events;#else  if (events & POLLIN)    FD_SET (n, &fdsets[0]);  if (events & POLLOUT)    FD_SET (n, &fdsets[1]);  if (events & POLLERR)    FD_SET (n, &fdsets[2]);  if (n > maxfd)    maxfd = n;#endif#endif /* fuggly */}voidFl::add_fd (int fd, void (*cb) (int, void *), void *v){  Fl::add_fd (fd, POLLIN, cb, v);}voidFl::remove_fd (int n, int events){  int i, j;  for (i = j = 0; i < nfds; i++) {    if (fd[i].fd == n) {      int e = fd[i].events & ~events;      if (!e)	continue;		// if no events left, delete this fd      fd[i].events = e;#ifdef JEFFM_FUGLY#if HAVE_POLL      fds[j].events = e;#endif#endif    }    // move it down in the array if necessary:    if (j < i) {      fd[j] = fd[i];#if HAVE_POLL      fds[j] = fds[i];#endif    }    j++;  }  nfds = j;#ifdef JEFFM_FUGLY #if !HAVE_POLL  if (events & POLLIN)    FD_CLR (n, &fdsets[0]);  if (events & POLLOUT)    FD_CLR (n, &fdsets[1]);  if (events & POLLERR)    FD_CLR (n, &fdsets[2]);  if (n == maxfd)    maxfd--;#endif#endif  GrUnregisterInput(n); }voidFl::remove_fd (int n){  remove_fd (n, -1);}intfl_ready (){  GR_EVENT ev;  if (GrPeekEvent (&ev))    return 1;#if HAVE_POLL  return::poll (fds, nfds, 0);#else  timeval t;  t.tv_sec = 0;  t.tv_usec = 0;  fd_set fdt[3];  fdt[0] = fdsets[0];  fdt[1] = fdsets[1];  fdt[2] = fdsets[2];  return::select (maxfd + 1, &fdt[0], &fdt[1], &fdt[2], &t);#endif}#if CONSOLIDATE_MOTIONstatic Fl_Window *send_motion;extern Fl_Window *fl_xmousewin;#endifint update = 0;double fl_wait (int timeout_flag, double time){  int msec = 0;  double mtime = 100.0 * time;  if (timeout_flag)    if (mtime < 1)      msec = 1;    else      msec = int (mtime);  GR_EVENT ev;  GrGetNextEventTimeout (&ev, msec);  fl_handle (ev);#if CONSOLIDATE_MOTION  if (send_motion && send_motion == fl_xmousewin) {    send_motion = 0;    Fl::handle (FL_MOVE, fl_xmousewin);  }#endif  return time;}//////////////////////////////////////////////////////////////////for nanoX ,by tanghaoint fl_display = 0;int fl_screen;XVisualInfo *fl_visual;Colormap fl_colormap;voidfl_open_display (){  if (fl_display)    return;  int d = 0;  if ((d = GrOpen ()) < 0) {    char buffer[256];    /* run server and window manager */    //sprintf(buffer, "%s/nano-X -p &; %s/nanowm &", NANOXFOLDER, NANOXFOLDER);    sprintf (buffer, "%s/nano-X -p &", NANOXFOLDER);    system (buffer);    if ((d = GrOpen ()) < 0) {      printf ("cannot open Nano-X graphics,Please run 'nano-X -p' first.\n");      exit (1);    }  }  //      for nanox,by tanghao  fl_display = d;  // for nanox,by tanghao  fl_screen = 0;  //end nanox}voidfl_close_display (){  Fl::remove_fd (fl_display);  GrClose ();}intFl::h (){  fl_open_display ();  GR_SCREEN_INFO si;		/* information about screen */  GrGetScreenInfo (&si);  return si.rows;//  return DisplayHeight(fl_display,fl_screen);}intFl::w (){  fl_open_display ();  GR_SCREEN_INFO si;		/* information about screen */  GrGetScreenInfo (&si);  return si.cols;  //  return DisplayWidth(fl_display,fl_screen);}voidFl::get_mouse (int &x, int &y){  fl_open_display ();  // for nanox,by tanghao  //  Window root = RootWindow(fl_display, fl_screen);  //  Window c; int mx,my,cx,cy; unsigned int mask;  //  XQueryPointer(fl_display,root,&root,&c,&mx,&my,&cx,&cy,&mask);  //  x = mx;  //  y = my;  fprintf (stderr, "Nano-X don't support get_mouse(x,y)in file(Fl_X.cxx)\n");  GR_WINDOW_INFO info;  GrGetWindowInfo (fl_window, &info);	//(GR_WINDOW_ID wid, GR_WINDOW_INFO *infoptr);  x = info.x + info.width / 2;  y = info.y + info.height / 2;  //end nanox}////////////////////////////////////////////////////////////////// for nanox,by tanghao//const XEvent* fl_xevent; // the current x event//constGR_EVENT *fl_xevent;		// the current nanox eventulong fl_event_time;		// the last timestamp from an x event//end nanoxchar fl_key_vector[32];		// used by Fl::get_key()// Record event mouse position and state from an XEvent:static int px, py;static ulong ptime;static voidset_event_xy (){#if CONSOLIDATE_MOTION  send_motion = 0;#endif  //for nanox,by tanghao  //  Fl::e_x_root = fl_xevent->xbutton.x_root;  //  Fl::e_x = fl_xevent->xbutton.x;  //  Fl::e_y_root = fl_xevent->xbutton.y_root;  //  Fl::e_y = fl_xevent->xbutton.y;  //  Fl::e_state = fl_xevent->xbutton.state << 16;  //  fl_event_time = fl_xevent->xbutton.time;  Fl::e_x_root = fl_xevent->button.rootx;  Fl::e_x = fl_xevent->button.x;  Fl::e_y_root = fl_xevent->button.rooty;  Fl::e_y = fl_xevent->button.y;  ulong state = Fl::e_state & 0xff0000;	// keep shift key states  //    if(fl_xevent->button.modifiers&GR_MODIFIER_SHIFT)state |= FL_SHIFT;  //    if(fl_xevent->button.modifiers&GR_MODIFIER_CTRL)state |= FL_CTRL;  //    if(fl_xevent->button.modifiers&GR_MODIFIER_META)state |= FL_ALT;  if (fl_xevent->button.buttons & GR_BUTTON_L)    state |= FL_BUTTON3;  if (fl_xevent->button.buttons & GR_BUTTON_M)    state |= FL_BUTTON2;  if (fl_xevent->button.buttons & GR_BUTTON_R)    state |= FL_BUTTON1;  Fl::e_state = state;  //  fl_event_time = fl_xevent->xbutton.time; maybe not support in nanox  fl_event_time = 0;  //end nanox#ifdef __sgi  // get the meta key off PC keyboards:  if (fl_key_vector[18] & 0x18)    Fl::e_state |= FL_META;#endif  // turn off is_click if enough time or mouse movement has passed:  if (abs (Fl::e_x_root - px) + abs (Fl::e_y_root - py) > 3      || fl_event_time >= ptime + 1000)    Fl::e_is_click = 0;}// if this is same event as last && is_click, increment click count:static inline voidcheckdouble (){  if (Fl::e_is_click == Fl::e_keysym)    Fl::e_clicks++;  else {    Fl::e_clicks = 0;    Fl::e_is_click = Fl::e_keysym;  }  px = Fl::e_x_root;  py = Fl::e_y_root;  ptime = fl_event_time;}static Fl_Window *resize_bug_fix;//////////////////////////////////////////////////////////////////int fix_exposure = 0;intfl_handle (const GR_EVENT & xevent){  int i;  GR_WINDOW_INFO info;  fl_xevent = (GR_EVENT *) & xevent;  Window xid = xevent.general.wid;	//fl_window;  int button = 0;  int event = 0;  Fl_Window *window = fl_find (xid);  /* #$*#&$ - Some events are not tied to a window */  if (xevent.type == GR_EVENT_TYPE_FDINPUT) {    int fdnum = xevent.fdinput.fd;       for(i = 0; i < nfds; i++) {      if (fd[i].fd == fdnum) { 	if (fd[i].cb) fd[i].cb(fdnum, fd[i].arg);	break;      }    }    return Fl::handle (event, window);  }  if (window)    switch (xevent.type) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -