coolwidget.h

来自「具有IDE功能的编辑器」· C头文件 代码 · 共 1,133 行 · 第 1/3 页

H
1,133
字号
/* coolwidget.h - main header file   Copyright (C) 1996-2000 Paul Sheer   This program is free software; you can redistribute it and/or modify   it under the terms of the GNU General Public License as published by   the Free Software Foundation; either version 2 of the License, or   (at your option) any later version.   This program 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 General Public License for more details.   You should have received a copy of the GNU General Public License   along with this program; if not, write to the Free Software   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA   02111-1307, USA. */#ifndef COOL_WIDGET_H#define COOL_WIDGET_H#include <config.h>#include <stdio.h>#include <my_string.h>#include <stdlib.h>#include <stdarg.h>#include <ctype.h>#include <errno.h>#ifdef HAVE_SYS_ERRNO_H#include <sys/errno.h>#endif#if TIME_WITH_SYS_TIME# include <sys/time.h># include <time.h>#else# if HAVE_SYS_TIME_H#  include <sys/time.h># else#  include <time.h># endif#endif#include <sys/types.h>#ifdef HAVE_UNISTD_H#   include <unistd.h>#endif#ifdef HAVE_SYS_SELECT_H#  include <sys/select.h>#endif#if HAVE_DIRENT_H#include <dirent.h>#define NAMLEN(dirent) strlen((dirent)->d_name)#else#define dirent direct#define NAMLEN(dirent) (dirent)->d_namlen#if HAVE_SYS_NDIR_H#include <sys/ndir.h>#endif#if HAVE_SYS_DIR_H#include <sys/dir.h>#endif#if HAVE_NDIR_H#include <ndir.h>#endif#endif#include <sys/stat.h>#ifdef HAVE_UNISTD_H#include <unistd.h>#endif#include <X11/Intrinsic.h>#include "global.h"#include "vgagl.h"#include "lkeysym.h"#include "stringtools.h"#include "app_glob.c"#include "drawings.h"#include "3dkit.h"#include "xdnd.h"#include "mousemark.h"#include "font.h" #define ALRM_PER_SECOND 50typedef struct initialisation {    char *name, *display, *geometry, *font, *widget_font, *bg;    char *fg_red, *fg_green, *fg_blue;	/* string doubles */#define CINIT_OPTION_USE_GREY 1#define CINIT_OPTION_VERBOSE 2#define CINIT_OPTION_WAIT_FOR_DISPLAY 4    unsigned long options;    char *look;} CInitData;#define CEdit WEdit/* edit this *//* #define u_32bit_t unsigned long */#define u_32bit_t unsigned int#define word unsigned short#define byte unsigned char#define WIDGET_MAGIC_BEGIN 0x6e065f4d#define WIDGET_MAGIC_END 0x54f560e9#define TEXT_SET_COLUMN		1#define TEXT_SET_LINE		2#define TEXT_SET_POS		3#define TEXT_SET_CURSOR_LINE	4/* These are all the widget kinds (the kind member of the widget structure) */enum { \    C_NOT_A_WIDGET, C_BUTTON_WIDGET, C_WINDOW_WIDGET, C_BAR_WIDGET, C_SUNKEN_WIDGET, \    C_VERTSCROLL_WIDGET, C_HORISCROLL_WIDGET, C_HORSCROLL_WIDGET, C_TEXTINPUT_WIDGET, \    C_TEXTBOX_WIDGET, C_TEXT_WIDGET, C_BWIMAGE_WIDGET, C_SPREAD_WIDGET, \    C_PROGRESS_WIDGET, C_BITMAP_WIDGET, C_BITMAPBUTTON_WIDGET, C_SWITCH_WIDGET, \    C_8BITIMAGE_WIDGET, C_THREED_WIDGET, C_PICTURE_WIDGET, C_EDITOR_WIDGET, \    C_MENU_WIDGET, C_MENU_BUTTON_WIDGET, C_ALARM_WIDGET, C_FIELDED_TEXTBOX_WIDGET, \    C_TOOLHINT_WIDGET, C_ICON_WIDGET, C_STATUS_WIDGET, C_RXVT_WIDGET, C_UNICODE_WIDGET};/* the user can start creating his widgets from 100: */#define C_LAST_WIDGET 100/*   Here are some addition events that you may recieve or send using   CNextEvent instead of XNextEvent. (LASTEvent = 35) *//* this comes every 1/CGetCursorBlinkRate() of a second */#define AlarmEvent		(LASTEvent + 1)/* This you won't recieve ---  it is used for joining small expose regions together */#define InternalExpose		(LASTEvent + 2)/* Send this event to the editor to force the editor widget to execute a command */#define EditorCommand		(LASTEvent + 3)/* Comes every 1/ALRM_PER_SECOND of a second (see initapp.c for correct amount) */#define TickEvent		(LASTEvent + 4)/* a button repeat event happens when a mouse button is pressed and held down */#define ButtonRepeat		(LASTEvent + 5)/* When you recieve this it is because the window manager wants the app to   quit. You would recieve this when the user has pressed on the main window. */#define QuitApplication		(LASTEvent + 6)#define CLASTEvent		(LASTEvent + 7)/* Library is limited to this number of widgets at once */#define MAX_NUMBER_OF_WIDGETS	1024/* one of the (long int) "CoolBlue" colors (0-15) that make up the windows, buttons etc */#define color_widget(i)		color_pixels[i]/* one of a 3x3x3 (RxGxB) color palette. eg R=2, G=1, B=0 is color_palette(19). */#define color_palette(i)	color_pixels[(i) + 16]/* 0-64 grey levels (not supprted unless specified in config.h) */#define color_grey(i)		color_pixels[(i) + 43]int allocate_color (char *color);/* draw a line in the window d */#define CLine(d, x, y, w, h)		XDrawLine(CDisplay, d, CGC, x, y, w, h)/* rectangle */#define CRectangle(d, x, y, w, h)	XFillRectangle(CDisplay, d, CGC, x, y, w, h)/* rectangle */#define CBox(d, x, y, w, h)		XDrawRectangle(CDisplay, d, CGC, x, y, w, h)/* set the foreground color */#define CSetColor(c)			XSetForeground(CDisplay, CGC, c)/* set the background color */#define CSetBackgroundColor(c)		XSetBackground(CDisplay, CGC, c)/* width of text in pixels in the current font */int CImageTextWidth (const char *s, int l);/* width of a string in pixels in the current font Wide Character */int CImageTextWidthWC (XChar2b * s, wchar_t * swc, int l);/* width of a string in pixels in the current font */int CImageStringWidth (const char *s);/* draw image string */int CImageString (Window w, int x, int y, const char *s);/* draw image text */int CImageText (Window w, int x, int y, const char *s, int l);/* draw image string Wide Character - supply both wc and normal string formats */int CImageTextWC (Window w, int x, int y, XChar2b * s, wchar_t * swc, int l);unsigned char *wcrtomb_ucs4_to_utf8 (wchar_t c);#define SCREEN_ASPECT_RATIO 1.333/* some standard colors *//* the color of the "flat" of a window */#define COLOR_FLAT ((*look->get_button_flat_color) ())/* used for NeXTish drawings */#define COLOR_DARK  color_widget(5)#define COLOR_LIGHT color_widget(8)#define COLOR_WHITE color_widget(15)#define COLOR_BLACK color_widget(0)/* SelectInput for various types of widgets */#define INPUT_EXPOSE (KeyPressMask | KeyReleaseMask | ExposureMask | \			StructureNotifyMask | VisibilityChangeMask | \			LeaveWindowMask | EnterWindowMask | PointerMotionMask)#define INPUT_KEY (ExposureMask | ButtonPressMask | ButtonReleaseMask | \			KeyPressMask | KeyReleaseMask | ButtonMotionMask | \			StructureNotifyMask | PropertyChangeMask | \			LeaveWindowMask | EnterWindowMask | PointerMotionMask)#define INPUT_MOTION INPUT_KEY#define INPUT_BUTTON (INPUT_KEY | KeyReleaseMask)/* internal */#define WINDOW_MAPPED 1#define WINDOW_FOCUS_WHEN_MAPPED 2/* menu callback function */typedef void (*callfn) (unsigned long data);struct menu_item {    char *text;    char hot_key;    callfn call_back;    unsigned long data;		/* data for user. it is passed to callfn */};#define MENU_ITEM_BASIC(text,hot_key,callback,data) \    text, hot_key, callback, data/* not supported   #define MENU_ITEM_OPTION(text,hot_key,option) \   text, hotkey, (callfn) 1, (int *) option   #define MENU_ITEM_SECOND_LEVEL(text,hotkey,menuitems) \   text, hotkey, (callfn) 2, (struct menu_item *) menuitems */#define ClassOfVisual(v) ((v)->class)/* spacing between widgets in pixels */#define WIDGET_SPACING option_interwidget_spacing#define WIDGET_FOCUS_RING ((*look->get_focus_ring_size) ())#define WINDOW_EXTRA_SPACING ((*look->get_extra_window_spacing) ())/* spacing between the bevel and the text of the text widget */#define TEXT_RELIEF 3/* don't change this without adjusting white fill in inputwidget.c */#define TEXTINPUT_RELIEF 1#define BUTTON_RELIEF 2/* auto widget sizing (use instead of width or height to work out the width   of widgets that have text in them) */#define AUTO_WIDTH		-32000#define AUTO_HEIGHT		-32001#define AUTO_SIZE		AUTO_WIDTH, AUTO_HEIGHT#define TEXTINPUT_LAST_INPUT	((char *) 1)/* font offsets for drawing */#define FONT_OFFSET_X 0#define EDIT_FRAME_W 7#define EDIT_FRAME_H 7/* if this gets changed, the cursor rendering (upside down "L") in editdraw and   cooledit.c must be adjusted so that the cursor is erased properly */#define FONT_OFFSET_Y		FONT_BASE_LINE/*   A reduced event. This structure is returned by CNextEvent, and   contains most of the things you may need. Anything more is contained   in XEvent. */typedef struct {/* widget's identification string */    char *ident;    int i;/* data */    int x;    int y;    int xt;    int yt;    Window window;/* enumerated above */    int kind;    int type;/* if a key was pressed, this is the KeySym */    int key;    char xlat[8];	/* translation */    long insert;    Time time;    unsigned int button;/* 1 for a double click */    int double_click;    unsigned int state;/* if text was returned by the event */    char *text;/* if the event was already handled by a callback routine */    char handled;/* if the event coused an editor command */    int command;		/* editor commands */} CEvent;/* This is the structure of a widget. It is presently 232 bytes   long. With 100 widgets on at once, this is only 23k, so the   inefficiency in having only one structure is justified. */struct cool_widget {    char ident[33];		/*unique identifying string given by user *//* for debugging */    u_32bit_t magic_begin;/* essentials */    Window winid;		/* X integer window id of widget */    Window parentid;		/* parent window of window */    Window mainid;		/* main window of window */    int (*eh) (struct cool_widget *, XEvent *, CEvent *);	/* internal event handler */    int (*callback_before) (struct cool_widget *, XEvent *, CEvent *);	/* user event handler called before internal handler */    int (*callback) (struct cool_widget *, XEvent *, CEvent *);		/* user event handler */    void (*destroy) (struct cool_widget *);	/*only a few widgets need special distruction */    void (*resize) (int, int, int, int, int *, int *, int *, int *);	/* when the parent is resized,									   the new size and position are 									   returned by this function */    void (*render) (struct cool_widget *w);    char ** (*get_line) (void *data, int line_number, int *num_fields, int *tagged);	/* returns a text box line *//* void resize ( *          old_parent_w, old_parent_h,  *          new_parent_w, new_parent_h,  *          int *new_this_widget_x, int *new_this_widget_y,  *          int *new_this_widget_w, int *new_this_widget_h *      ); */    void (*scroll_bar_link) (struct cool_widget *, struct cool_widget *, XEvent *, CEvent *, int);    void (*scroll_bar_extra_render) (struct cool_widget *);/* * void scroll_bar_link (scrollbar, widget, xevent, cwevent, which_button_1_to_5); *//* basics */    int width, height;		/* of window --- just to save looking it up */    int x, y;			/* position in parent --- top left corner */    int kind;			/* one of C??????_WIDGET above */    char disabled;		/* displayed, but not functioning */    char takes_focus;		/* can this widget take input focus? */    char mapped;		/* has window yet been mapped */    char nothing;		/* pad *//* data */    char *label;		/* text that gets drawn into button */    char *graphic;		/* Possibly a bitmap to go onto the button */    int *tab;			/* columns for spreadsheat widget */    char *text;			/* text goes into textbox textinput and text widgets */    char *headings;		/* headings of spreadsheet columns */    GraphicsContext *gl_graphicscontext;	/*for svgalib image widgets */    XImage *ximage;		/* for X images picture widgets */    Pixmap pixmap;		/* for pixmaps */    CPicture *pic;		/* for lines, circles, rects and arcs. */    TD_Solid *solid;    char *toolhint;		/* hints for buttons */    struct editor_widget *editor;    struct menu_item *menu;/* Positions. What they are used for depends on the kind of widget. See coolwidget.c for an explanation */    long cursor;    long column;    long numlines;    long firstline;    long current;

⌨️ 快捷键说明

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