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

📄 gtkclist.c

📁 gtk是linux一款强大的夸平台的图形化开发工具
💻 C
📖 第 1 页 / 共 5 页
字号:
/* GTK - The GIMP Toolkit * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball, Josh MacDonald,  * Copyright (C) 1997-1998 Jay Painter <jpaint@serv.net><jpaint@gimp.org>   * * 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. *//* * Modified by the GTK+ Team and others 1997-1999.  See the AUTHORS * file for a list of people on the GTK+ Team.  See the ChangeLog * files for a list of changes.  These files are distributed with * GTK+ at ftp://ftp.gtk.org/pub/gtk/.  */#include <stdlib.h>#include <string.h>#include "config.h"#include "gtkmain.h"#include "gtkclist.h"#include "gtkbindings.h"#include "gtkdnd.h"#include <gdk/gdkx.h>#include <gdk/gdkkeysyms.h>/* length of button_actions array */#define MAX_BUTTON 5/* the number rows memchunk expands at a time */#define CLIST_OPTIMUM_SIZE 64/* the width of the column resize windows */#define DRAG_WIDTH  6/* minimum allowed width of a column */#define COLUMN_MIN_WIDTH 5/* this defigns the base grid spacing */#define CELL_SPACING 1/* added the horizontal space at the beginning and end of a row*/#define COLUMN_INSET 3/* used for auto-scrolling */#define SCROLL_TIME  100/* gives the top pixel of the given row in context of * the clist's voffset */#define ROW_TOP_YPIXEL(clist, row) (((clist)->row_height * (row)) + \				    (((row) + 1) * CELL_SPACING) + \				    (clist)->voffset)/* returns the row index from a y pixel location in the  * context of the clist's voffset */#define ROW_FROM_YPIXEL(clist, y)  (((y) - (clist)->voffset) / \				    ((clist)->row_height + CELL_SPACING))/* gives the left pixel of the given column in context of * the clist's hoffset */#define COLUMN_LEFT_XPIXEL(clist, colnum)  ((clist)->column[(colnum)].area.x + \					    (clist)->hoffset)/* returns the column index from a x pixel location in the  * context of the clist's hoffset */static inline gintCOLUMN_FROM_XPIXEL (GtkCList * clist,		    gint x){  gint i, cx;  for (i = 0; i < clist->columns; i++)    if (clist->column[i].visible)      {	cx = clist->column[i].area.x + clist->hoffset;	if (x >= (cx - (COLUMN_INSET + CELL_SPACING)) &&	    x <= (cx + clist->column[i].area.width + COLUMN_INSET))	  return i;      }  /* no match */  return -1;}/* returns the top pixel of the given row in the context of * the list height */#define ROW_TOP(clist, row)        (((clist)->row_height + CELL_SPACING) * (row))/* returns the left pixel of the given column in the context of * the list width */#define COLUMN_LEFT(clist, colnum) ((clist)->column[(colnum)].area.x)/* returns the total height of the list */#define LIST_HEIGHT(clist)         (((clist)->row_height * ((clist)->rows)) + \				    (CELL_SPACING * ((clist)->rows + 1)))/* returns the total width of the list */static inline gintLIST_WIDTH (GtkCList * clist) {  gint last_column;  for (last_column = clist->columns - 1;       last_column >= 0 && !clist->column[last_column].visible; last_column--);  if (last_column >= 0)    return (clist->column[last_column].area.x +	    clist->column[last_column].area.width +	    COLUMN_INSET + CELL_SPACING);  return 0;}#define GTK_CLIST_CLASS_FW(_widget_) GTK_CLIST_CLASS (((GtkObject*) (_widget_))->klass)/* redraw the list if it's not frozen */#define CLIST_UNFROZEN(clist)     (((GtkCList*) (clist))->freeze_count == 0)#define	CLIST_REFRESH(clist)	G_STMT_START { \  if (CLIST_UNFROZEN (clist)) \    GTK_CLIST_CLASS_FW (clist)->refresh ((GtkCList*) (clist)); \} G_STMT_END/* Signals */enum {  SELECT_ROW,  UNSELECT_ROW,  ROW_MOVE,  CLICK_COLUMN,  RESIZE_COLUMN,  TOGGLE_FOCUS_ROW,  SELECT_ALL,  UNSELECT_ALL,  UNDO_SELECTION,  START_SELECTION,  END_SELECTION,  TOGGLE_ADD_MODE,  EXTEND_SELECTION,  SCROLL_VERTICAL,  SCROLL_HORIZONTAL,  ABORT_COLUMN_RESIZE,  LAST_SIGNAL};enum {  SYNC_REMOVE,  SYNC_INSERT};enum {  ARG_0,  ARG_N_COLUMNS,  ARG_SHADOW_TYPE,  ARG_SELECTION_MODE,  ARG_ROW_HEIGHT,  ARG_TITLES_ACTIVE,  ARG_REORDERABLE,  ARG_USE_DRAG_ICONS,  ARG_SORT_TYPE};/* GtkCList Methods */static void gtk_clist_class_init (GtkCListClass *klass);static void gtk_clist_init       (GtkCList      *clist);/* GtkObject Methods */static void gtk_clist_destroy  (GtkObject *object);static void gtk_clist_finalize (GtkObject *object);static void gtk_clist_set_arg  (GtkObject *object,				GtkArg    *arg,				guint      arg_id);static void gtk_clist_get_arg  (GtkObject *object,				GtkArg    *arg,				guint      arg_id);/* GtkWidget Methods */static void gtk_clist_set_scroll_adjustments (GtkCList      *clist,					      GtkAdjustment *hadjustment,					      GtkAdjustment *vadjustment);static void gtk_clist_realize         (GtkWidget        *widget);static void gtk_clist_unrealize       (GtkWidget        *widget);static void gtk_clist_map             (GtkWidget        *widget);static void gtk_clist_unmap           (GtkWidget        *widget);static void gtk_clist_draw            (GtkWidget        *widget,			               GdkRectangle     *area);static gint gtk_clist_expose          (GtkWidget        *widget,			               GdkEventExpose   *event);static gint gtk_clist_key_press       (GtkWidget        *widget,				       GdkEventKey      *event);static gint gtk_clist_button_press    (GtkWidget        *widget,				       GdkEventButton   *event);static gint gtk_clist_button_release  (GtkWidget        *widget,				       GdkEventButton   *event);static gint gtk_clist_motion          (GtkWidget        *widget, 			               GdkEventMotion   *event);static void gtk_clist_size_request    (GtkWidget        *widget,				       GtkRequisition   *requisition);static void gtk_clist_size_allocate   (GtkWidget        *widget,				       GtkAllocation    *allocation);static void gtk_clist_draw_focus      (GtkWidget        *widget);static gint gtk_clist_focus_in        (GtkWidget        *widget,				       GdkEventFocus    *event);static gint gtk_clist_focus_out       (GtkWidget        *widget,				       GdkEventFocus    *event);static gint gtk_clist_focus           (GtkContainer     *container,				       GtkDirectionType  direction);static void gtk_clist_style_set       (GtkWidget        *widget,				       GtkStyle         *previous_style);static void gtk_clist_drag_begin      (GtkWidget        *widget,				       GdkDragContext   *context);static gint gtk_clist_drag_motion     (GtkWidget        *widget,				       GdkDragContext   *context,				       gint              x,				       gint              y,				       guint             time);static void gtk_clist_drag_leave      (GtkWidget        *widget,				       GdkDragContext   *context,				       guint             time);static void gtk_clist_drag_end        (GtkWidget        *widget,				       GdkDragContext   *context);static gboolean gtk_clist_drag_drop   (GtkWidget      *widget,				       GdkDragContext *context,				       gint            x,				       gint            y,				       guint           time);static void gtk_clist_drag_data_get   (GtkWidget        *widget,				       GdkDragContext   *context,				       GtkSelectionData *selection_data,				       guint             info,				       guint             time);static void gtk_clist_drag_data_received (GtkWidget        *widget,					  GdkDragContext   *context,					  gint              x,					  gint              y,					  GtkSelectionData *selection_data,					  guint             info,					  guint             time);/* GtkContainer Methods */static void gtk_clist_set_focus_child (GtkContainer  *container,				       GtkWidget     *child);static void gtk_clist_forall          (GtkContainer  *container,			               gboolean       include_internals,			               GtkCallback    callback,			               gpointer       callback_data);/* Selection */static void toggle_row                (GtkCList      *clist,			               gint           row,			               gint           column,			               GdkEvent      *event);static void real_select_row           (GtkCList      *clist,			               gint           row,			               gint           column,			               GdkEvent      *event);static void real_unselect_row         (GtkCList      *clist,			               gint           row,			               gint           column,			               GdkEvent      *event);static void update_extended_selection (GtkCList      *clist,				       gint           row);static GList *selection_find          (GtkCList      *clist,			               gint           row_number,			               GList         *row_list_element);static void real_select_all           (GtkCList      *clist);static void real_unselect_all         (GtkCList      *clist);static void move_vertical             (GtkCList      *clist,			               gint           row,			               gfloat         align);static void move_horizontal           (GtkCList      *clist,			               gint           diff);static void real_undo_selection       (GtkCList      *clist);static void fake_unselect_all         (GtkCList      *clist,			               gint           row);static void fake_toggle_row           (GtkCList      *clist,			               gint           row);static void resync_selection          (GtkCList      *clist,			               GdkEvent      *event);static void sync_selection            (GtkCList      *clist,	                               gint           row,                                       gint           mode);static void set_anchor                (GtkCList      *clist,			               gboolean       add_mode,			               gint           anchor,			               gint           undo_anchor);static void start_selection           (GtkCList      *clist);static void end_selection             (GtkCList      *clist);static void toggle_add_mode           (GtkCList      *clist);static void toggle_focus_row          (GtkCList      *clist);static void extend_selection          (GtkCList      *clist,			               GtkScrollType  scroll_type,			               gfloat         position,			               gboolean       auto_start_selection);static gint get_selection_info        (GtkCList       *clist,				       gint            x,				       gint            y,				       gint           *row,				       gint           *column);/* Scrolling */static void move_focus_row     (GtkCList      *clist,			        GtkScrollType  scroll_type,			        gfloat         position);static void scroll_horizontal  (GtkCList      *clist,			        GtkScrollType  scroll_type,			        gfloat         position);static void scroll_vertical    (GtkCList      *clist,			        GtkScrollType  scroll_type,			        gfloat         position);static void move_horizontal    (GtkCList      *clist,				gint           diff);static void move_vertical      (GtkCList      *clist,				gint           row,				gfloat         align);static gint horizontal_timeout (GtkCList      *clist);static gint vertical_timeout   (GtkCList      *clist);static void remove_grab        (GtkCList      *clist);/* Resize Columns */static void draw_xor_line             (GtkCList       *clist);static gint new_column_width          (GtkCList       *clist,			               gint            column,			               gint           *x);static void column_auto_resize        (GtkCList       *clist,				       GtkCListRow    *clist_row,				       gint            column,				       gint            old_width);static void real_resize_column        (GtkCList       *clist,				       gint            column,				       gint            width);static void abort_column_resize       (GtkCList       *clist);static void cell_size_request         (GtkCList       *clist,			               GtkCListRow    *clist_row,			               gint            column,				       GtkRequisition *requisition);/* Buttons */static void column_button_create      (GtkCList       *clist,				       gint            column);static void column_button_clicked     (GtkWidget      *widget,				       gpointer        data);/* Adjustments */static void adjust_adjustments        (GtkCList       *clist,				       gboolean        block_resize);static void check_exposures           (GtkCList       *clist);static void vadjustment_changed       (GtkAdjustment  *adjustment,				       gpointer        data);static void vadjustment_value_changed (GtkAdjustment  *adjustment,				       gpointer        data);static void hadjustment_changed       (GtkAdjustment  *adjustment,				       gpointer        data);static void hadjustment_value_changed (GtkAdjustment  *adjustment,				       gpointer        data);/* Drawing */static void get_cell_style   (GtkCList      *clist,			      GtkCListRow   *clist_row,			      gint           state,			      gint           column,			      GtkStyle     **style,			      GdkGC        **fg_gc,			      GdkGC        **bg_gc);static gint draw_cell_pixmap (GdkWindow     *window,			      GdkRectangle  *clip_rectangle,			      GdkGC         *fg_gc,			      GdkPixmap     *pixmap,			      GdkBitmap     *mask,			      gint           x,			      gint           y,			      gint           width,			      gint           height);static void draw_row         (GtkCList      *clist,			      GdkRectangle  *area,			      gint           row,			      GtkCListRow   *clist_row);static void draw_rows        (GtkCList      *clist,			      GdkRectangle  *area);static void clist_refresh    (GtkCList      *clist);static void draw_drag_highlight (GtkCList        *clist,				 GtkCListRow     *dest_row,				 gint             dest_row_number,				 GtkCListDragPos  drag_pos);     /* Size Allocation / Requisition */static void size_allocate_title_buttons (GtkCList *clist);static void size_allocate_columns       (GtkCList *clist,					 gboolean  block_resize);static gint list_requisition_width      (GtkCList *clist);/* Memory Allocation/Distruction Routines */static GtkCListColumn *columns_new (GtkCList      *clist);static void column_title_new       (GtkCList      *clist,			            gint           column,			            const gchar   *title);static void columns_delete         (GtkCList      *clist);static GtkCListRow *row_new        (GtkCList      *clist);static void row_delete             (GtkCList      *clist,			            GtkCListRow   *clist_row);static void set_cell_contents      (GtkCList      *clist,			            GtkCListRow   *clist_row,				    gint           column,				    GtkCellType    type,				    const gchar   *text,				    guint8         spacing,				    GdkPixmap     *pixmap,				    GdkBitmap     *mask);static gint real_insert_row        (GtkCList      *clist,				    gint           row,				    gchar         *text[]);static void real_remove_row        (GtkCList      *clist,				    gint           row);static void real_clear             (GtkCList      *clist);/* Sorting */static gint default_compare        (GtkCList      *clist,			            gconstpointer  row1,			            gconstpointer  row2);static void real_sort_list         (GtkCList      *clist);static GList *gtk_clist_merge      (GtkCList      *clist,				    GList         *a,				    GList         *b);static GList *gtk_clist_mergesort  (GtkCList      *clist,				    GList         *list,				    gint           num);

⌨️ 快捷键说明

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