coolwidget.h

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

H
1,133
字号
    long firstcolumn;    long textlength;    long mark1, mark2;    long search_start;    int search_len;    Window last_child_focussed;	/* This is for main windows. It records				   the last child within this main window				   that has the focus. If the window				   manager switches focus to another				   window, then when focus is switch back,				   this will have kept the correct child to				   recieve focus. *//* settings */    unsigned long options;#define BUTTON_HIGHLIGHT		(1<<1)#define BUTTON_PRESSED			(1<<2)#define MENU_AUTO_PULL_UP		(1<<3)#define EDITOR_NO_FILE			(1<<3)#define EDITOR_NO_SCROLL		(1<<4)#define EDITOR_NO_TEXT			(1<<5)#define EDITOR_HORIZ_SCROLL		(1<<6)#define FILELIST_LAST_ENTRY		(1<<8)#define FILELIST_TAGGED_ENTRY		(1<<9)/* default is sort by name */#define FILELIST_SORT_UNSORTED		(1<<10)#define FILELIST_SORT_EXTENSIONS	(1<<11)#define FILELIST_SORT_SIZE		(1<<12)#define FILELIST_SORT_MDATE		(1<<13)#define FILELIST_SORT_CDATE		(1<<14)#define FILELIST_FILES_ONLY		(1<<15)#define FILELIST_DIRECTORIES_ONLY	(1<<16)#define FILELIST_ALL_FILES		(FILELIST_DIRECTORIES_ONLY|FILELIST_FILES_ONLY)/* these musn't be within the first 8 bits (see bitmapbutton.c) */ #define RADIO_INVERT_GROUP		(1<<8)#define RADIO_ONE_ALWAYS_ON		(1<<9)#define SWITCH_PICTURE_TYPE		(1<<10)#define TEXTBOX_FILE_LIST		(1<<1)#define TEXTBOX_MAN_PAGE		(1<<2)#define TEXTBOX_MARK_WHOLE_LINES	(1<<3)#define TEXTBOX_NO_CURSOR		(1<<4)#define TEXTBOX_NO_KEYS			(1<<5)#define TEXTBOX_NO_STRDUP		(1<<6)#define TEXTBOX_WRAP			(1<<7)#define TEXTINPUT_PASSWORD		(1<<3)#define TEXTINPUT_NUMBERS		(1<<4)#define TEXT_CENTRED			(1<<3)#define WINDOW_HAS_HEADING		(1<<1)#define WINDOW_SIZE_HINTS_SET		(1<<2)#define WINDOW_USER_POSITION		(1<<3)#define WINDOW_USER_SIZE		(1<<4)#define WINDOW_NO_BORDER		(1<<5)/* must be higher than all other options */#define WIDGET_HOTKEY_ACTIVATES		(1<<17)#define WIDGET_TAKES_FOCUS_RING		(1<<18)#define WIDGET_TAKES_SELECTION		(1<<19)#define WIDGET_FREE_USER_ON_DESTROY	(1<<20)    unsigned long position;#define WINDOW_ALWAYS_RAISED	(1<<0)	/* remains on top when even after CRaise'ing other windows */#define WINDOW_ALWAYS_LOWERED	(1<<1)	/* remins on bottom */#define WINDOW_UNMOVEABLE	(1<<2)	/* cannot be moved by clicking on the window's background */#define WINDOW_RESIZABLE	(1<<3)	/* can be resized (has cosmetic in the lower right corner) *//* these tell the widgets behaviour on resizing its parent window */#define POSITION_RIGHT		(1<<4)	/* moves to follow the right border */#define POSITION_WIDTH		(1<<5)	/* resizes to follow the right border */#define POSITION_BOTTOM		(1<<6)#define POSITION_HEIGHT		(1<<7)#define POSITION_CENTRE		(1<<8)	/* centres from left to right */#define POSITION_FILL		(1<<9)	/* fills to right border */#define WINDOW_MAXIMISED	(1<<10)/* links to other widgets as needed */    struct cool_widget *hori_scrollbar;    struct cool_widget *vert_scrollbar;    struct cool_widget *textbox;    struct cool_widget *textinput;    struct cool_widget *droppedmenu;    struct mouse_funcs *funcs;    char keypressed;			/* has a key been pressed since this widgets creation (used for text input) */    char resized;			/* has the widget just been resized? you can check this before rendering, and then reset to 0 */    unsigned short hotkey;		/* sometimes used */    unsigned long fg;			/* colors */    unsigned long bg;/* used for internal widgets for additional data */    void *hook;/* user structure. you can put addition data that you might need in here */    void *user;    void (*free_user) (void *);    XIC input_context;    void *rxvt;    Pixmap pixmap_mask;    char pad[228];/* for debugging */    u_32bit_t magic_end;};typedef struct cool_widget CWidget;/* you may want to use these */#define CTextOf(w) ((w)->text)#define CLabelOf(w) ((w)->label)#define CUserOf(w) ((w)->user)#define CHeightOf(w) ((w)->height)#define CWidthOf(w) ((w)->width)#define CXof(w) ((w)->x)#define CYof(w) ((w)->y)#define CWindowOf(w) ((w)->winid)#define CParentOf(w) ((w)->parentid)#define CIdentOf(w) ((w)->ident)#define CWindowOf(w) ((w)->winid)#define CHeightOf(w) ((w)->height)#define CWidthOf(w) ((w)->width)#define COptionsOf(w) ((w)->options)/* internal */typedef struct disabled_state {    u_32bit_t state[(MAX_NUMBER_OF_WIDGETS + 31) / 32];    u_32bit_t mask[(MAX_NUMBER_OF_WIDGETS + 31) / 32];} CState;/*   The only global variables for the widgets. This is the actual array   of pointers that holds the malloced widget structures */#ifdef COOL_WIDGET_Cint last_widget;		/* gives length of widget list */CWidget *widget[MAX_NUMBER_OF_WIDGETS];		/* first widget is at 1 */#elseextern int last_widget;extern CWidget *widget[MAX_NUMBER_OF_WIDGETS];#endif/* CIndex(i) used to return a pointer to the widget i */#define CIndex(i) widget[i]/* returns a pointer to the widget called ident or 0 if not found */CWidget *CIdent (const char *ident);/* returns a pointer to the widget of window win */CWidget *CWidgetOfWindow (Window win);/* Returns the widgets window or 0 if not found */Window CWindowOfWidget (const char *ident);/* Returns the first parent, grandparent, etc, of the window that is of the C_WIDGET_WINDOW type */CWidget *CDialogOfWindow (Window window);/* Returns top level window of the widget */CWidget *CMainOfWindow (Window window);/* Initialise. Opens connection to the X display, processing -display -font, and -geom args   sets up GC's, visual's and so on */void CInitialise (CInitData * config);/* returns non-zero if a child exitted */int CChildExitted (pid_t p, int *status);/* Call when app is done. This undraws all widgets, free's all data   and closes the connection to the X display */void CShutdown (void);/* Prints an error to stderr, or to a window if one can be created, then exits */void CError (const char *fmt,...);/* fd watch for internal select */int CAddWatch (int fd, void (*callback) (int, fd_set *, fd_set *, fd_set *, void *), int how, void *data);void CRemoveWatch (int fd, void (*callback) (int, fd_set *, fd_set *, fd_set *, void *), int how);#define WATCH_READING	(1<<0)#define WATCH_WRITING	(1<<1)#define WATCH_ERROR	(1<<2)/* Normal malloc with check for 0 return */void *CMalloc (size_t size);void *CDebugMalloc (size_t x, int line, const char *file);/* get UTF-8 sequence from user selected glyph */unsigned char *CGetUnichar (Window in, char *heading);/* Draw a panel onto which widgets will be drawn, this must not be a main window */Window CDrawDialog (const char *identifier, Window parent, int x, int y);/* Draw a panel with a heading and a seperator line. The position below the   seperator line is recorded in h, start drawing in the window from there. */Window CDrawHeadedDialog (const char *identifier, Window parent, int x, int y, const char *label);void CMapDialog (const char *ident);#define CDrawMainWindow(a,b) CDrawHeadedDialog (a, CRoot, 0, 0, b)void CSetBackgroundPixmap (const char *ident, const char *data[], int w, int h, char start_char);void CSetWindowResizable (const char *ident, int min_width, int min_height, int max_width, int max_height);/* returns the direct child of the root window */Window CGetWMWindow (Window win);void CRaiseWMWindow (char *ident);/* Draw a button */CWidget *CDrawButton (const char *identifier, Window parent, int x, int y,		      int width, int height, const char *label);/* Set tool hint for a widget */void CSetToolHint (const char *ident, char *text);/* Draw a button with a bitmap on it, (see dialog.c for example) */CWidget *CDrawBitmapButton (const char *identifier, Window parent, int x, int y,			    int width, int height, unsigned long fg, unsigned long bg, const unsigned char data[]);#define TICK_BUTTON_WIDTH 44#define PIXMAP_BUTTON_TICK TICK_BUTTON_WIDTH, TICK_BUTTON_WIDTH, tick_bits, '0'#define PIXMAP_BUTTON_SAVE TICK_BUTTON_WIDTH, TICK_BUTTON_WIDTH, save_pixmap, '0'#define PIXMAP_BUTTON_CROSS TICK_BUTTON_WIDTH, TICK_BUTTON_WIDTH, cross_bits, '0'#define PIXMAP_BUTTON_EXCLAMATION TICK_BUTTON_WIDTH, TICK_BUTTON_WIDTH, exclam_bits, '0'CWidget *CDrawPixmapButton (const char *identifier, Window parent,    int x, int y, int width, int height, const char *data[], char start_char);/* Draws a toggle switch, pass on as the default setting */CWidget *CDrawSwitch (const char *identifier, Window parent, int x, int y, int on, char *label, int group);/* Draw status line  - like a single line text widget but interprets colours */CWidget *CDrawStatus (const char *identifier, Window parent, int x, int y, int w, char *str);/* Draw a text input widget */CWidget *CDrawTextInput (const char *identifier, Window parent, int x, int y,		  int width, int height, int maxlen, const char *string);/* Adds a line of text to the history of a text input. */void CAddToTextInputHistory (const char *ident, const char *text);/* returns the most recent text inputted into a text widget of this name, do not free result */char *CLastInput (const char *ident);/* draws a fielded (like a ledger) text box */CWidget *CDrawFieldedTextbox (const char *identifier, Window parent, int x, int y,			      int width, int height, int line, int column,			      char **(*get_line) (void *, int, int *, int *),			      long options, void *data);struct file_entry {    unsigned long options;    char name[260];    struct stat stat;};char *get_file_list (const char *directory, unsigned long f, char *filter);struct file_entry *get_file_entry_list (const char *directory, unsigned long options, char *filter);CWidget *CDrawFilelist (const char *identifier, Window parent, int x, int y,			int width, int height, int line, int column,			struct file_entry *directentry,			long options);CWidget *CRedrawFilelist (const char *identifier, struct file_entry *directentry, int preserve);struct file_entry *CGetFilelistLine (CWidget *w, int line);/* Draws a scrollable textbox, with its scrollbar. text is newline seperate */CWidget *CDrawTextbox (const char *identifier, Window parent, int x, int y,		       int width, int height, int line, int column, const char *text, long options);#define TEXTBOX_BDR 8char *CGetTextBoxLine (CWidget * w, int line);CWidget *CDrawManPage (const char *identifier, Window parent, int x, int y,	  int width, int height, int line, int column, const char *text);/* Change the text of the textbox. If preserve is 1, then the position in the text is not altered */CWidget *CRedrawTextbox (const char *identifier, const char *text, int preserve);CWidget *CRedrawFieldedTextbox (const char *identifier, int preserve);CWidget *CClearTextbox (const char *identifier);/* Set the position of the text in the text-box, see coolwidget.c */int CSetTextboxPos (CWidget * wdt, int which, long p);/* Draws a thin horizontal raised ridge */CWidget *CDrawBar (Window parent, int x, int y, int w);/* Vertical scroll bar */CWidget *CDrawVerticalScrollbar (const char *identifier, Window parent, int x, int y,			       int length, int width, int pos, int prop);CWidget *CDrawHorizontalScrollbar (const char *identifier, Window parent, int x, int y,			       int length, int width, int pos, int prop);void CSetScrollbarCallback (const char *scrollbar, const char *wiget,			    void (*linktowiget) (CWidget *,				    CWidget *, XEvent *, CEvent *, int));/* eg: void link_scrollbar_to_textbox (CWidget * w, CWidget * textbox,    XEvent * xevent, CEvent * cwevent, int which_scrollbar_button_was_pressed_1_to_5); *//* Draws one or more lines of text (separate by newlines) in a sunken panel. Use like printf() */CWidget *CDrawText (const char *identifier, Window parent, int x, int y, const char *fmt,...);/* Will replace the text of an existing text widget. Unlike other widgets, multiple text widgets can have the same ident */CWidget *CRedrawText (const char *identifier, const char *fmt,...);void CTextSize (int *w, int *h, const char *str);/* Draws a file browser and returns a filename, file is the default file name */char *CGetFile (Window parent, int x, int y,		const char *dir, const char *file, const char *label);char *CGetDirectory (Window parent, int x, int y,		   const char *dir, const char *file, const char *label);char *CGetSaveFile (Window parent, int x, int y,		    const char *dir, const char *file, const char *label);char *CGetLoadFile (Window parent, int x, int y,		    const char *dir, const char *file, const char *label);/* Draws a directory browser and returns immediately */void CDrawBrowser (const char *ident, Window parent, int x, int y,		   const char *dir, const char *file, const char *label);/* Draws a simple spreadsheat widget (not supprted) */CWidget *CDrawSpreadSheet (const char *ident, Window parent, int x, int y, int w, int h, const char *spreadtext, const char *heading, int *columns);/* Draws a full blown text editor, scrollbar and status line */CWidget *CDrawEditor (const char *identifier, Window parent, int x, int y,	   int width, int height, const char *text, const char *filename,		const char *starting_directory, unsigned int options, unsigned long text_size);void CSetCursorColor (unsigned long c);/* Draws a menu button that may be pulled down if clicked on */CWidget *CDrawMenuButton (const char *ident, Window parent, Window focus_return,   int x, int y, int width, int height, int num_items, const char *label,...);/* this is a menu item: *//* ...label, const char *text, int hot_key, callfn call_back, unsigned long data,...); */void CSetMenuFocusReturn (const char *ident, Window w);void CSetLastMenu (CWidget * button);CWidget *CGetLastMenu (void);void CMenuSelectionDialog (CWidget * button);CWidget *get_pulled_menu (void);/* Draws menu buttons for the editor. focus_return is where focus goes to if you escape from a menu */void CDrawEditMenuButtons (const char *ident, Window parent, Window focus_return, int x, int y);void CAddMenuItem (const char *ident, const char *text, int hot_key, callfn call_back, unsigned long data);void CRemoveMenuItem (const char *ident, const char *text);void CReplaceMenuItem (const char *ident, const char *old_text, const char *new_text, int hot_key, callfn call_back, unsigned long data);void CRemoveMenuItemNumber (const char *ident, int i);void CInsertMenuItem (const char *ident, const char *after, const char *text, int hot_key, callfn call_back, unsigned long data);int CHasMenuItem (const char *ident, const char *text); /* returns -1 or menu item number *//* Draws a bitmap inside a sunken window */CWidget *CDrawBitmap (const char *identifier, Window parent, int x, int y,		      int width, int height, unsigned long fg, unsigned long bg, const unsigned char *data);/* Draws a black and white picture 1 byte per pixel contiguous data */CWidget *CDrawBWImage (const char *identifier, Window parent, int x, int y,		       int width, int height, unsigned char *data);XImage *CCreateImage (const char *data[], int width, int height, char start_char);Pixmap CCreatePixmap (const char *data[], int width, int height, char start_char);Pixmap CCreateClipMask (const char *data[], int width, int height, char start_char);/* A window with inward bevels */CWidget *CDrawSunkenPanel (const char *identifier, Window parent, int x, int y,			   int width, int height, const char *label);/* Draw a progress bar */CWidget *CDrawProgress (const char *identifier, Window parent, int x, int y,			int width, int height, int p);/* Draws a picture, containing nothing. Allows lines, rectangles etc to   be drawn into the picture */CWidget *CDrawPicture (const char *identifier, Window parent, int x, int y,		       int max_num_elements);/* Destroy a widget. This will destroy all descendent widgets recursively */int CDestroyWidget (const char *identifier);

⌨️ 快捷键说明

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