Mercurial > hg > xemacs-beta
view src/toolbar-xlike.c @ 5127:a9c41067dd88 ben-lisp-object
more cleanups, terminology clarification, lots of doc work
-------------------- ChangeLog entries follow: --------------------
man/ChangeLog addition:
2010-03-05 Ben Wing <ben@xemacs.org>
* internals/internals.texi (Introduction to Allocation):
* internals/internals.texi (Integers and Characters):
* internals/internals.texi (Allocation from Frob Blocks):
* internals/internals.texi (lrecords):
* internals/internals.texi (Low-level allocation):
Rewrite section on allocation of Lisp objects to reflect the new
reality. Remove references to nonexistent XSETINT and XSETCHAR.
modules/ChangeLog addition:
2010-03-05 Ben Wing <ben@xemacs.org>
* postgresql/postgresql.c (allocate_pgconn):
* postgresql/postgresql.c (allocate_pgresult):
* postgresql/postgresql.h (struct Lisp_PGconn):
* postgresql/postgresql.h (struct Lisp_PGresult):
* ldap/eldap.c (allocate_ldap):
* ldap/eldap.h (struct Lisp_LDAP):
Same changes as in src/ dir. See large log there in ChangeLog,
but basically:
ALLOC_LISP_OBJECT -> ALLOC_NORMAL_LISP_OBJECT
LISP_OBJECT_HEADER -> NORMAL_LISP_OBJECT_HEADER
../hlo/src/ChangeLog addition:
2010-03-05 Ben Wing <ben@xemacs.org>
* alloc.c:
* alloc.c (old_alloc_sized_lcrecord):
* alloc.c (very_old_free_lcrecord):
* alloc.c (copy_lisp_object):
* alloc.c (zero_sized_lisp_object):
* alloc.c (zero_nonsized_lisp_object):
* alloc.c (lisp_object_storage_size):
* alloc.c (free_normal_lisp_object):
* alloc.c (FREE_FIXED_TYPE_WHEN_NOT_IN_GC):
* alloc.c (ALLOC_FROB_BLOCK_LISP_OBJECT):
* alloc.c (Fcons):
* alloc.c (noseeum_cons):
* alloc.c (make_float):
* alloc.c (make_bignum):
* alloc.c (make_bignum_bg):
* alloc.c (make_ratio):
* alloc.c (make_ratio_bg):
* alloc.c (make_ratio_rt):
* alloc.c (make_bigfloat):
* alloc.c (make_bigfloat_bf):
* alloc.c (size_vector):
* alloc.c (make_compiled_function):
* alloc.c (Fmake_symbol):
* alloc.c (allocate_extent):
* alloc.c (allocate_event):
* alloc.c (make_key_data):
* alloc.c (make_button_data):
* alloc.c (make_motion_data):
* alloc.c (make_process_data):
* alloc.c (make_timeout_data):
* alloc.c (make_magic_data):
* alloc.c (make_magic_eval_data):
* alloc.c (make_eval_data):
* alloc.c (make_misc_user_data):
* alloc.c (Fmake_marker):
* alloc.c (noseeum_make_marker):
* alloc.c (size_string_direct_data):
* alloc.c (make_uninit_string):
* alloc.c (make_string_nocopy):
* alloc.c (mark_lcrecord_list):
* alloc.c (alloc_managed_lcrecord):
* alloc.c (free_managed_lcrecord):
* alloc.c (sweep_lcrecords_1):
* alloc.c (malloced_storage_size):
* buffer.c (allocate_buffer):
* buffer.c (compute_buffer_usage):
* buffer.c (DEFVAR_BUFFER_LOCAL_1):
* buffer.c (nuke_all_buffer_slots):
* buffer.c (common_init_complex_vars_of_buffer):
* buffer.h (struct buffer_text):
* buffer.h (struct buffer):
* bytecode.c:
* bytecode.c (make_compiled_function_args):
* bytecode.c (size_compiled_function_args):
* bytecode.h (struct compiled_function_args):
* casetab.c (allocate_case_table):
* casetab.h (struct Lisp_Case_Table):
* charset.h (struct Lisp_Charset):
* chartab.c (fill_char_table):
* chartab.c (Fmake_char_table):
* chartab.c (make_char_table_entry):
* chartab.c (copy_char_table_entry):
* chartab.c (Fcopy_char_table):
* chartab.c (put_char_table):
* chartab.h (struct Lisp_Char_Table_Entry):
* chartab.h (struct Lisp_Char_Table):
* console-gtk-impl.h (struct gtk_device):
* console-gtk-impl.h (struct gtk_frame):
* console-impl.h (struct console):
* console-msw-impl.h (struct Lisp_Devmode):
* console-msw-impl.h (struct mswindows_device):
* console-msw-impl.h (struct msprinter_device):
* console-msw-impl.h (struct mswindows_frame):
* console-msw-impl.h (struct mswindows_dialog_id):
* console-stream-impl.h (struct stream_console):
* console-stream.c (stream_init_console):
* console-tty-impl.h (struct tty_console):
* console-tty-impl.h (struct tty_device):
* console-tty.c (allocate_tty_console_struct):
* console-x-impl.h (struct x_device):
* console-x-impl.h (struct x_frame):
* console.c (allocate_console):
* console.c (nuke_all_console_slots):
* console.c (DEFVAR_CONSOLE_LOCAL_1):
* console.c (common_init_complex_vars_of_console):
* data.c (make_weak_list):
* data.c (make_weak_box):
* data.c (make_ephemeron):
* database.c:
* database.c (struct Lisp_Database):
* database.c (allocate_database):
* database.c (finalize_database):
* device-gtk.c (allocate_gtk_device_struct):
* device-impl.h (struct device):
* device-msw.c:
* device-msw.c (mswindows_init_device):
* device-msw.c (msprinter_init_device):
* device-msw.c (finalize_devmode):
* device-msw.c (allocate_devmode):
* device-tty.c (allocate_tty_device_struct):
* device-x.c (allocate_x_device_struct):
* device.c:
* device.c (nuke_all_device_slots):
* device.c (allocate_device):
* dialog-msw.c (handle_question_dialog_box):
* elhash.c:
* elhash.c (struct Lisp_Hash_Table):
* elhash.c (finalize_hash_table):
* elhash.c (make_general_lisp_hash_table):
* elhash.c (Fcopy_hash_table):
* elhash.h (htentry):
* emacs.c (main_1):
* eval.c:
* eval.c (size_multiple_value):
* event-stream.c (finalize_command_builder):
* event-stream.c (allocate_command_builder):
* event-stream.c (free_command_builder):
* event-stream.c (event_stream_generate_wakeup):
* event-stream.c (event_stream_resignal_wakeup):
* event-stream.c (event_stream_disable_wakeup):
* event-stream.c (event_stream_wakeup_pending_p):
* events.h (struct Lisp_Timeout):
* events.h (struct command_builder):
* extents-impl.h:
* extents-impl.h (struct extent_auxiliary):
* extents-impl.h (struct extent_info):
* extents-impl.h (set_extent_no_chase_aux_field):
* extents-impl.h (set_extent_no_chase_normal_field):
* extents.c:
* extents.c (gap_array_marker):
* extents.c (gap_array):
* extents.c (extent_list_marker):
* extents.c (extent_list):
* extents.c (stack_of_extents):
* extents.c (gap_array_make_marker):
* extents.c (extent_list_make_marker):
* extents.c (allocate_extent_list):
* extents.c (SLOT):
* extents.c (mark_extent_auxiliary):
* extents.c (allocate_extent_auxiliary):
* extents.c (attach_extent_auxiliary):
* extents.c (size_gap_array):
* extents.c (finalize_extent_info):
* extents.c (allocate_extent_info):
* extents.c (uninit_buffer_extents):
* extents.c (allocate_soe):
* extents.c (copy_extent):
* extents.c (vars_of_extents):
* extents.h:
* faces.c (allocate_face):
* faces.h (struct Lisp_Face):
* faces.h (struct face_cachel):
* file-coding.c:
* file-coding.c (finalize_coding_system):
* file-coding.c (sizeof_coding_system):
* file-coding.c (Fcopy_coding_system):
* file-coding.h (struct Lisp_Coding_System):
* file-coding.h (MARKED_SLOT):
* fns.c (size_bit_vector):
* font-mgr.c:
* font-mgr.c (finalize_fc_pattern):
* font-mgr.c (print_fc_pattern):
* font-mgr.c (Ffc_pattern_p):
* font-mgr.c (Ffc_pattern_create):
* font-mgr.c (Ffc_name_parse):
* font-mgr.c (Ffc_name_unparse):
* font-mgr.c (Ffc_pattern_duplicate):
* font-mgr.c (Ffc_pattern_add):
* font-mgr.c (Ffc_pattern_del):
* font-mgr.c (Ffc_pattern_get):
* font-mgr.c (fc_config_create_using):
* font-mgr.c (fc_strlist_to_lisp_using):
* font-mgr.c (fontset_to_list):
* font-mgr.c (Ffc_config_p):
* font-mgr.c (Ffc_config_up_to_date):
* font-mgr.c (Ffc_config_build_fonts):
* font-mgr.c (Ffc_config_get_cache):
* font-mgr.c (Ffc_config_get_fonts):
* font-mgr.c (Ffc_config_set_current):
* font-mgr.c (Ffc_config_get_blanks):
* font-mgr.c (Ffc_config_get_rescan_interval):
* font-mgr.c (Ffc_config_set_rescan_interval):
* font-mgr.c (Ffc_config_app_font_add_file):
* font-mgr.c (Ffc_config_app_font_add_dir):
* font-mgr.c (Ffc_config_app_font_clear):
* font-mgr.c (size):
* font-mgr.c (Ffc_config_substitute):
* font-mgr.c (Ffc_font_render_prepare):
* font-mgr.c (Ffc_font_match):
* font-mgr.c (Ffc_font_sort):
* font-mgr.c (finalize_fc_config):
* font-mgr.c (print_fc_config):
* font-mgr.h:
* font-mgr.h (struct fc_pattern):
* font-mgr.h (XFC_PATTERN):
* font-mgr.h (struct fc_config):
* font-mgr.h (XFC_CONFIG):
* frame-gtk.c (allocate_gtk_frame_struct):
* frame-impl.h (struct frame):
* frame-msw.c (mswindows_init_frame_1):
* frame-x.c (allocate_x_frame_struct):
* frame.c (nuke_all_frame_slots):
* frame.c (allocate_frame_core):
* gc.c:
* gc.c (GC_CHECK_NOT_FREE):
* glyphs.c (finalize_image_instance):
* glyphs.c (allocate_image_instance):
* glyphs.c (Fcolorize_image_instance):
* glyphs.c (allocate_glyph):
* glyphs.c (unmap_subwindow_instance_cache_mapper):
* glyphs.c (register_ignored_expose):
* glyphs.h (struct Lisp_Image_Instance):
* glyphs.h (struct Lisp_Glyph):
* glyphs.h (struct glyph_cachel):
* glyphs.h (struct expose_ignore):
* gui.c (allocate_gui_item):
* gui.h (struct Lisp_Gui_Item):
* keymap.c (struct Lisp_Keymap):
* keymap.c (make_keymap):
* lisp.h:
* lisp.h (struct Lisp_String_Direct_Data):
* lisp.h (struct Lisp_String_Indirect_Data):
* lisp.h (struct Lisp_Vector):
* lisp.h (struct Lisp_Bit_Vector):
* lisp.h (DECLARE_INLINE_LISP_BIT_VECTOR):
* lisp.h (struct weak_box):
* lisp.h (struct ephemeron):
* lisp.h (struct weak_list):
* lrecord.h:
* lrecord.h (struct lrecord_implementation):
* lrecord.h (MC_ALLOC_CALL_FINALIZER):
* lrecord.h (struct lcrecord_list):
* lstream.c (finalize_lstream):
* lstream.c (sizeof_lstream):
* lstream.c (Lstream_new):
* lstream.c (Lstream_delete):
* lstream.h (struct lstream):
* marker.c:
* marker.c (finalize_marker):
* marker.c (compute_buffer_marker_usage):
* mule-charset.c:
* mule-charset.c (make_charset):
* mule-charset.c (compute_charset_usage):
* objects-impl.h (struct Lisp_Color_Instance):
* objects-impl.h (struct Lisp_Font_Instance):
* objects-tty-impl.h (struct tty_color_instance_data):
* objects-tty-impl.h (struct tty_font_instance_data):
* objects-tty.c (tty_initialize_color_instance):
* objects-tty.c (tty_initialize_font_instance):
* objects.c (finalize_color_instance):
* objects.c (Fmake_color_instance):
* objects.c (finalize_font_instance):
* objects.c (Fmake_font_instance):
* objects.c (reinit_vars_of_objects):
* opaque.c:
* opaque.c (sizeof_opaque):
* opaque.c (make_opaque_ptr):
* opaque.c (free_opaque_ptr):
* opaque.h:
* opaque.h (Lisp_Opaque):
* opaque.h (Lisp_Opaque_Ptr):
* print.c (printing_unreadable_lcrecord):
* print.c (external_object_printer):
* print.c (debug_p4):
* process.c (finalize_process):
* process.c (make_process_internal):
* procimpl.h (struct Lisp_Process):
* rangetab.c (Fmake_range_table):
* rangetab.c (Fcopy_range_table):
* rangetab.h (struct Lisp_Range_Table):
* scrollbar.c:
* scrollbar.c (create_scrollbar_instance):
* scrollbar.c (compute_scrollbar_instance_usage):
* scrollbar.h (struct scrollbar_instance):
* specifier.c (finalize_specifier):
* specifier.c (sizeof_specifier):
* specifier.c (set_specifier_caching):
* specifier.h (struct Lisp_Specifier):
* specifier.h (struct specifier_caching):
* symeval.h:
* symeval.h (SYMBOL_VALUE_MAGIC_P):
* symeval.h (DEFVAR_SYMVAL_FWD):
* symsinit.h:
* syntax.c (init_buffer_syntax_cache):
* syntax.h (struct syntax_cache):
* toolbar.c:
* toolbar.c (allocate_toolbar_button):
* toolbar.c (update_toolbar_button):
* toolbar.h (struct toolbar_button):
* tooltalk.c (struct Lisp_Tooltalk_Message):
* tooltalk.c (make_tooltalk_message):
* tooltalk.c (struct Lisp_Tooltalk_Pattern):
* tooltalk.c (make_tooltalk_pattern):
* ui-gtk.c:
* ui-gtk.c (allocate_ffi_data):
* ui-gtk.c (emacs_gtk_object_finalizer):
* ui-gtk.c (allocate_emacs_gtk_object_data):
* ui-gtk.c (allocate_emacs_gtk_boxed_data):
* ui-gtk.h:
* window-impl.h (struct window):
* window-impl.h (struct window_mirror):
* window.c (finalize_window):
* window.c (allocate_window):
* window.c (new_window_mirror):
* window.c (mark_window_as_deleted):
* window.c (make_dummy_parent):
* window.c (compute_window_mirror_usage):
* window.c (compute_window_usage):
Overall point of this change and previous ones in this repository:
(1) Introduce new, clearer terminology: everything other than int
or char is a "record" object, which comes in two types: "normal
objects" and "frob-block objects". Fix up all places that
referred to frob-block objects as "simple", "basic", etc.
(2) Provide an advertised interface for doing operations on Lisp
objects, including creating new types, that is clean and
consistent in its naming, uses the above-referenced terms and
avoids referencing "lrecords", "old lcrecords", etc., which should
hide under the surface.
(3) Make the size_in_bytes and finalizer methods take a
Lisp_Object rather than a void * for consistency with other methods.
(4) Separate finalizer method into finalizer and disksaver, so
that normal finalize methods don't have to worry about disksaving.
Other specifics:
(1) Renaming:
LISP_OBJECT_HEADER -> NORMAL_LISP_OBJECT_HEADER
ALLOC_LISP_OBJECT -> ALLOC_NORMAL_LISP_OBJECT
implementation->basic_p -> implementation->frob_block_p
ALLOCATE_FIXED_TYPE_AND_SET_IMPL -> ALLOC_FROB_BLOCK_LISP_OBJECT
*FCCONFIG*, wrap_fcconfig -> *FC_CONFIG*, wrap_fc_config
*FCPATTERN*, wrap_fcpattern -> *FC_PATTERN*, wrap_fc_pattern
(the last two changes make the naming of these macros consistent
with the naming of all other macros, since the objects are named
fc-config and fc-pattern with a hyphen)
(2) Lots of documentation fixes in lrecord.h.
(3) Eliminate macros for copying, freeing, zeroing objects, getting
their storage size. Instead, new functions:
zero_sized_lisp_object()
zero_nonsized_lisp_object()
lisp_object_storage_size()
free_normal_lisp_object()
(copy_lisp_object() already exists)
LISP_OBJECT_FROB_BLOCK_P() (actually a macro)
Eliminated:
free_lrecord()
zero_lrecord()
copy_lrecord()
copy_sized_lrecord()
old_copy_lcrecord()
old_copy_sized_lcrecord()
old_zero_lcrecord()
old_zero_sized_lcrecord()
LISP_OBJECT_STORAGE_SIZE()
COPY_SIZED_LISP_OBJECT()
COPY_SIZED_LCRECORD()
COPY_LISP_OBJECT()
ZERO_LISP_OBJECT()
FREE_LISP_OBJECT()
(4) Catch the remaining places where lrecord stuff was used directly
and use the advertised interface, e.g. alloc_sized_lrecord() ->
ALLOC_SIZED_LISP_OBJECT().
(5) Make certain statically-declared pseudo-objects
(buffer_local_flags, console_local_flags) have their lheader
initialized correctly, so things like copy_lisp_object() can work
on them. Make extent_auxiliary_defaults a proper heap object
Vextent_auxiliary_defaults, and make extent auxiliaries dumpable
so that this object can be dumped. allocate_extent_auxiliary()
now just creates the object, and attach_extent_auxiliary()
creates an extent auxiliary and attaches to an extent, like the
old allocate_extent_auxiliary().
(6) Create EXTENT_AUXILIARY_SLOTS macro, similar to the foo-slots.h
files but in a macro instead of a file. The purpose is to avoid
duplication when iterating over all the slots in an extent auxiliary.
Use it.
(7) In lstream.c, don't zero out object after allocation because
allocation routines take care of this.
(8) In marker.c, fix a mistake in computing marker overhead.
(9) In print.c, clean up printing_unreadable_lcrecord(),
external_object_printer() to avoid lots of ifdef NEW_GC's.
(10) Separate toolbar-button allocation into a separate
allocate_toolbar_button() function for use in the example code
in lrecord.h.
author | Ben Wing <ben@xemacs.org> |
---|---|
date | Fri, 05 Mar 2010 04:08:17 -0600 |
parents | cbe181529c34 |
children | d372b17f63ce |
line wrap: on
line source
/* toolbar implementation -- "Generic" (X or GTK) redisplay interface. Copyright (C) 1995 Board of Trustees, University of Illinois. Copyright (C) 1995 Sun Microsystems, Inc. Copyright (C) 1995, 1996, 2002, 2010 Ben Wing. Copyright (C) 1996 Chuck Thompson. This file is part of XEmacs. XEmacs 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, or (at your option) any later version. XEmacs 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 XEmacs; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* Synched up with: Not in FSF. */ #include <config.h> #include "lisp.h" #include "device-impl.h" #include "faces.h" #include "frame-impl.h" #include "glyphs.h" #include "toolbar.h" #include "window.h" /* This is used when we need to draw the toolbars ourselves -- on X or GTK. On MS Windows, we use the built-in toolbar controls. */ /* Only a very few things need to differ based on the toolkit used. ** ** Some of the routines used assert(FRAME_yyy_P(f)) checks, this is ** now abstracted into __INTERNAL_APPROPRIATENESS_CHECK(). When we ** add new window systems that use this code, we should either add a ** new case here, or just remove the checks completely. ** ** At least for X & GTK redraw_frame_toolbars() might end up getting ** called before we are completely initialized. To avoid this, we use ** the __INTERNAL_MAPPED_P(f) macro, that should return 0 if we should ** not draw the toolbars yet. When we add new window systems that use ** this code, we should add a new case here, if they need it. ** ** When clearing the toolbar, it is nice to flush the drawing queue. ** Use __INTERNAL_FLUSH to do this. It is passed a device. */ #if defined(HAVE_GTK) #include "console-gtk-impl.h" #define __INTERNAL_MAPPED_P(f) GTK_WIDGET_REALIZED (FRAME_GTK_TEXT_WIDGET (f)) #define __INTERNAL_FLUSH(d) gdk_flush() #define __INTERNAL_APPROPRIATENESS_CHECK(f) assert(FRAME_GTK_P (f)) #elif defined(HAVE_X_WINDOWS) #include "console-x-impl.h" #define __INTERNAL_MAPPED_P(f) XtIsRealized (FRAME_X_SHELL_WIDGET (f)) #define __INTERNAL_APPROPRIATENESS_CHECK(f) assert(FRAME_X_P (f)) #define __INTERNAL_FLUSH(d) XFlush (DEVICE_X_DISPLAY (d)) #else #define __INTERNAL_MAPPED_P(f) ABORT() #define __INTERNAL_APPROPRIATENESS_CHECK(f) ABORT() #define __INTERNAL_FLUSH(f) ABORT() #endif #include "toolbar-xlike.h" extern Lisp_Object Vtoolbar_shadow_thickness; static void __prepare_button_area (struct frame *f, struct toolbar_button *tb) { int sx = tb->x; int sy = tb->y; int swidth = tb->width; int sheight = tb->height; int border_width = tb->border_width; int x_adj, width_adj, y_adj, height_adj; struct device *d = XDEVICE (f->device); Lisp_Object window = FRAME_LAST_NONMINIBUF_WINDOW (f); struct window *w = XWINDOW (window); int shadow_thickness; int def_shadow_thickness = XINT (Fspecifier_instance(Vtoolbar_shadow_thickness, window, Qnil, Qnil)); face_index toolbar_findex; if (tb->vertical) { x_adj = border_width; width_adj = - 2 * border_width; y_adj = height_adj = 0; } else { x_adj = width_adj = 0; y_adj = border_width; height_adj = - 2 * border_width; } toolbar_findex = get_builtin_face_cache_index (w, Vtoolbar_face); /* Blank toolbar buttons that should be 3d will have EQ(tb->up_glyph, Qt) ** Blank toolbar buttons that should be flat will have NILP (tb->up_glyph) ** ** Real toolbar buttons will check tb->enabled && tb->down */ if (EQ (Qt, tb->up_glyph)) { shadow_thickness = def_shadow_thickness; } else if (NILP (tb->up_glyph)) { shadow_thickness = 0; } else { if (tb->enabled) { if (tb->down) shadow_thickness = -def_shadow_thickness; else shadow_thickness = def_shadow_thickness; } else { shadow_thickness = 0; } } /* Blank the entire area. */ redisplay_clear_region (window, toolbar_findex, sx + x_adj, sy + y_adj, swidth + width_adj, sheight + height_adj); /* Draw the outline. */ if (shadow_thickness) { MAYBE_DEVMETH (d, bevel_area, (w, toolbar_findex, sx + x_adj, sy + y_adj, swidth + width_adj, sheight + height_adj, abs(shadow_thickness), EDGE_ALL, (shadow_thickness < 0) ? EDGE_BEVEL_IN : EDGE_BEVEL_OUT)); } /* Handle the borders... */ redisplay_clear_region (window, toolbar_findex, sx, sy, (tb->vertical ? border_width : swidth), (tb->vertical ? sheight : border_width)); redisplay_clear_region (window, toolbar_findex, (tb->vertical ? sx + swidth : sx), (tb->vertical ? sy : sy + sheight), (tb->vertical ? border_width : swidth), (tb->vertical ? sheight : border_width)); } #define xlike_draw_blank_toolbar_button(f,tb) __prepare_button_area (f,tb) void xlike_output_toolbar_button (struct frame *f, Lisp_Object button) { int shadow_thickness = 2; int x_adj, y_adj, width_adj, height_adj; struct device *d = XDEVICE (f->device); Lisp_Object instance, window, glyph; struct toolbar_button *tb = XTOOLBAR_BUTTON (button); struct Lisp_Image_Instance *p; struct window *w; int vertical = tb->vertical; int border_width = tb->border_width; face_index button_findex; if (vertical) { x_adj = border_width; width_adj = - 2 * border_width; y_adj = 0; height_adj = 0; } else { x_adj = 0; width_adj = 0; y_adj = border_width; height_adj = - 2 * border_width; } window = FRAME_LAST_NONMINIBUF_WINDOW (f); w = XWINDOW (window); glyph = get_toolbar_button_glyph (w, tb); if (tb->enabled) { if (tb->down) { shadow_thickness = -2; } else { shadow_thickness = 2; } } else { shadow_thickness = 0; } /* #### It is currently possible for users to trash us by directly changing the toolbar glyphs. Avoid crashing in that case. */ if (GLYPHP (glyph)) { /* WARNING: this interface may change */ Lisp_Object face_list[2] = { XGLYPH_FACE (glyph), Vtoolbar_face }; button_findex = merge_face_list_to_cache_index (w, face_list, 2); instance = glyph_image_instance (glyph, window, ERROR_ME_DEBUG_WARN, 1); } else { button_findex = get_builtin_face_cache_index (w, Vtoolbar_face); instance = Qnil; } __prepare_button_area (f, tb); if (IMAGE_INSTANCEP (instance)) { int width = tb->width + width_adj - shadow_thickness * 2; int height = tb->height + height_adj - shadow_thickness * 2; int x_offset = x_adj + shadow_thickness; int y_offset = y_adj + shadow_thickness; p = XIMAGE_INSTANCE (instance); if (IMAGE_INSTANCE_PIXMAP_TYPE_P (p)) { struct display_box db; struct display_glyph_area dga; if (width > (int) IMAGE_INSTANCE_PIXMAP_WIDTH (p)) { x_offset += ((int) (width - IMAGE_INSTANCE_PIXMAP_WIDTH (p)) / 2); width = IMAGE_INSTANCE_PIXMAP_WIDTH (p); } if (height > (int) IMAGE_INSTANCE_PIXMAP_HEIGHT (p)) { y_offset += ((int) (height - IMAGE_INSTANCE_PIXMAP_HEIGHT (p)) / 2); height = IMAGE_INSTANCE_PIXMAP_HEIGHT (p); } /* Draw exactly in the area specified... */ db.xpos = tb->x + x_offset; db.ypos = tb->y + y_offset; db.width = width; db.height = height; /* Display the whole glyph */ dga.xoffset = 0; dga.yoffset = 0; dga.width = width; dga.height = height; redisplay_output_pixmap (w, instance, &db, &dga, button_findex, 0, 0, 0, 0); } else if (IMAGE_INSTANCE_TYPE (p) == IMAGE_TEXT) { /* #### We need to make the face used configurable. */ struct face_cachel *cachel = WINDOW_FACE_CACHEL (w, DEFAULT_INDEX); struct display_line dl; Lisp_Object string = IMAGE_INSTANCE_TEXT_STRING (p); unsigned char charsets[NUM_LEADING_BYTES]; Ichar_dynarr *buf; struct font_metric_info fm; /* This could be true if we were called via the Expose event handler. Mark the button as dirty and return immediately. */ if (f->window_face_cache_reset) { tb->dirty = 1; MARK_TOOLBAR_CHANGED; return; } buf = Dynarr_new (Ichar); convert_ibyte_string_into_ichar_dynarr (XSTRING_DATA (string), XSTRING_LENGTH (string), buf); find_charsets_in_ichar_string (charsets, Dynarr_begin (buf), Dynarr_length (buf)); ensure_face_cachel_complete (cachel, window, charsets); face_cachel_charset_font_metric_info (cachel, charsets, &fm); dl.ascent = fm.ascent; dl.descent = fm.descent; dl.ypos = tb->y + y_offset + fm.ascent; if (fm.ascent + fm.descent <= height) { dl.ypos += (height - fm.ascent - fm.descent) / 2; dl.clip = 0; } else { dl.clip = fm.ascent + fm.descent - height; } MAYBE_DEVMETH (d, output_string, (w, &dl, buf, tb->x + x_offset, 0, 0, width, button_findex, 0, 0, 0, 0)); Dynarr_free (buf); } /* We silently ignore the image if it isn't a pixmap or text. */ } tb->dirty = 0; } static int xlike_get_button_size (struct frame *f, Lisp_Object window, struct toolbar_button *tb, int vert, int pos) { int shadow_thickness = 2; int size; if (tb->blank) { if (!NILP (tb->down_glyph)) size = XINT (tb->down_glyph); else size = DEFAULT_TOOLBAR_BLANK_SIZE; } else { struct window *w = XWINDOW (window); Lisp_Object glyph = get_toolbar_button_glyph (w, tb); /* Unless, of course, the user has done something stupid like change the glyph out from under us. Use a blank placeholder in that case. */ if (NILP (glyph)) return XINT (f->toolbar_size[pos]); if (vert) size = glyph_height (glyph, window); else size = glyph_width (glyph, window); } if (!size) { /* If the glyph doesn't have a size we'll insert a blank placeholder instead. */ return XINT (f->toolbar_size[pos]); } size += shadow_thickness * 2; return (size); } #define XLIKE_OUTPUT_BUTTONS_LOOP(left) \ do { \ while (!NILP (button)) \ { \ struct toolbar_button *tb = XTOOLBAR_BUTTON (button); \ int size, height, width; \ \ if (left && tb->pushright) \ break; \ \ size = xlike_get_button_size (f, window, tb, vert, pos); \ \ if (vert) \ { \ width = bar_width; \ if (y + size > max_pixpos) \ height = max_pixpos - y; \ else \ height = size; \ } \ else \ { \ if (x + size > max_pixpos) \ width = max_pixpos - x; \ else \ width = size; \ height = bar_height; \ } \ \ if (tb->x != x \ || tb->y != y \ || tb->width != width \ || tb->height != height \ || tb->dirty \ || f->clear) /* This is clearly necessary. */ \ { \ if (width && height) \ { \ tb->x = x; \ tb->y = y; \ tb->width = width; \ tb->height = height; \ tb->border_width = border_width; \ tb->vertical = vert; \ \ if (tb->blank || NILP (tb->up_glyph)) \ { \ xlike_draw_blank_toolbar_button (f, tb); \ } \ else \ xlike_output_toolbar_button (f, button); \ } \ } \ \ if (vert) \ y += height; \ else \ x += width; \ \ if ((vert && y == max_pixpos) || (!vert && x == max_pixpos)) \ button = Qnil; \ else \ button = tb->next; \ } \ } while (0) #define SET_TOOLBAR_WAS_VISIBLE_FLAG(frame, pos, flag) \ do { \ switch (pos) \ { \ case TOP_TOOLBAR: \ (frame)->top_toolbar_was_visible = flag; \ break; \ case BOTTOM_TOOLBAR: \ (frame)->bottom_toolbar_was_visible = flag; \ break; \ case LEFT_TOOLBAR: \ (frame)->left_toolbar_was_visible = flag; \ break; \ case RIGHT_TOOLBAR: \ (frame)->right_toolbar_was_visible = flag; \ break; \ default: \ ABORT (); \ } \ } while (0) static void xlike_output_toolbar (struct frame *f, enum toolbar_pos pos) { int x, y, bar_width, bar_height, vert; int max_pixpos, right_size, right_start, blank_size; int border_width = FRAME_REAL_TOOLBAR_BORDER_WIDTH (f, pos); Lisp_Object button, window; face_index toolbar_findex; get_toolbar_coords (f, pos, &x, &y, &bar_width, &bar_height, &vert, 1); window = FRAME_LAST_NONMINIBUF_WINDOW (f); toolbar_findex = get_builtin_face_cache_index (XWINDOW (window), Vtoolbar_face); /* Do the border */ redisplay_clear_region (window, toolbar_findex, x, y, (vert ? bar_width : border_width), (vert ? border_width : bar_height)); redisplay_clear_region (window, toolbar_findex, (vert ? x : x + bar_width - border_width), (vert ? y + bar_height - border_width : y), (vert ? bar_width : border_width), (vert ? border_width : bar_height)); if (vert) { max_pixpos = y + bar_height - border_width; y += border_width; } else { max_pixpos = x + bar_width - border_width; x += border_width; } button = FRAME_TOOLBAR_BUTTONS (f, pos); right_size = 0; /* First loop over all of the buttons to determine how much room we need for left hand and right hand buttons. This loop will also make sure that all instances are instantiated so when we actually output them they will come up immediately. */ while (!NILP (button)) { struct toolbar_button *tb = XTOOLBAR_BUTTON (button); int size = xlike_get_button_size (f, window, tb, vert, pos); if (tb->pushright) right_size += size; button = tb->next; } button = FRAME_TOOLBAR_BUTTONS (f, pos); /* Loop over the left buttons, updating and outputting them. */ XLIKE_OUTPUT_BUTTONS_LOOP (1); /* Now determine where the right buttons start. */ right_start = max_pixpos - right_size; if (right_start < (vert ? y : x)) right_start = (vert ? y : x); /* Output the blank which goes from the end of the left buttons to the start of the right. */ blank_size = right_start - (vert ? y : x); if (blank_size) { int height, width; if (vert) { width = bar_width; height = blank_size; } else { width = blank_size; height = bar_height; } /* * Use a 3D pushright separator only if there isn't a toolbar * border. A flat separator meshes with the border and looks * better. */ if (1) { struct toolbar_button tb; tb.x = x; tb.y = y; tb.width = width; tb.height = height; tb.border_width = border_width; tb.vertical = vert; tb.enabled = 1; tb.up_glyph = border_width ? Qt : Qnil; __prepare_button_area (f, &tb); } if (vert) y += height; else x += width; } /* Loop over the right buttons, updating and outputting them. */ XLIKE_OUTPUT_BUTTONS_LOOP (0); if (!vert) { Lisp_Object frame = wrap_frame (f); redisplay_clear_region (frame, DEFAULT_INDEX, FRAME_PIXWIDTH (f) - 1, y, 1, bar_height); } SET_TOOLBAR_WAS_VISIBLE_FLAG (f, pos, 1); __INTERNAL_FLUSH (XDEVICE (f->device)); } static void xlike_clear_toolbar (struct frame *f, enum toolbar_pos pos, int thickness_change) { Lisp_Object frame; int x, y, width, height, vert; get_toolbar_coords (f, pos, &x, &y, &width, &height, &vert, 1); frame = wrap_frame (f); /* The thickness_change parameter is used by the toolbar resize routines to clear any excess toolbar if the size shrinks. */ if (thickness_change < 0) { if (pos == LEFT_TOOLBAR || pos == RIGHT_TOOLBAR) { x = x + width + thickness_change; width = -thickness_change; } else { y = y + height + thickness_change; height = -thickness_change; } } SET_TOOLBAR_WAS_VISIBLE_FLAG (f, pos, 0); redisplay_clear_region (frame, DEFAULT_INDEX, x, y, width, height); __INTERNAL_FLUSH (XDEVICE (f->device)); } void xlike_output_frame_toolbars (struct frame *f) { __INTERNAL_APPROPRIATENESS_CHECK(f); if (FRAME_REAL_TOP_TOOLBAR_VISIBLE (f)) xlike_output_toolbar (f, TOP_TOOLBAR); if (FRAME_REAL_BOTTOM_TOOLBAR_VISIBLE (f)) xlike_output_toolbar (f, BOTTOM_TOOLBAR); if (FRAME_REAL_LEFT_TOOLBAR_VISIBLE (f)) xlike_output_toolbar (f, LEFT_TOOLBAR); if (FRAME_REAL_RIGHT_TOOLBAR_VISIBLE (f)) xlike_output_toolbar (f, RIGHT_TOOLBAR); } void xlike_clear_frame_toolbars (struct frame *f) { __INTERNAL_APPROPRIATENESS_CHECK(f); if (f->top_toolbar_was_visible && !FRAME_REAL_TOP_TOOLBAR_VISIBLE (f)) xlike_clear_toolbar (f, TOP_TOOLBAR, 0); if (f->bottom_toolbar_was_visible && !FRAME_REAL_BOTTOM_TOOLBAR_VISIBLE (f)) xlike_clear_toolbar (f, BOTTOM_TOOLBAR, 0); if (f->left_toolbar_was_visible && !FRAME_REAL_LEFT_TOOLBAR_VISIBLE (f)) xlike_clear_toolbar (f, LEFT_TOOLBAR, 0); if (f->right_toolbar_was_visible && !FRAME_REAL_RIGHT_TOOLBAR_VISIBLE (f)) xlike_clear_toolbar (f, RIGHT_TOOLBAR, 0); } static void xlike_redraw_exposed_toolbar (struct frame *f, enum toolbar_pos pos, int x, int y, int width, int height) { int bar_x, bar_y, bar_width, bar_height, vert; Lisp_Object button = FRAME_TOOLBAR_BUTTONS (f, pos); get_toolbar_coords (f, pos, &bar_x, &bar_y, &bar_width, &bar_height, &vert, 1); if (((y + height) < bar_y) || (y > (bar_y + bar_height))) return; if (((x + width) < bar_x) || (x > (bar_x + bar_width))) return; while (!NILP (button)) { struct toolbar_button *tb = XTOOLBAR_BUTTON (button); if (vert) { if (((tb->y + tb->height) > y) && (tb->y < (y + height))) tb->dirty = 1; /* If this is true we have gone past the exposed region. */ if (tb->y > (y + height)) break; } else { if (((tb->x + tb->width) > x) && (tb->x < (x + width))) tb->dirty = 1; /* If this is true we have gone past the exposed region. */ if (tb->x > (x + width)) break; } button = tb->next; } /* Even if none of the buttons is in the area, the blank region at the very least must be because the first thing we did is verify that some portion of the toolbar is in the exposed region. */ xlike_output_toolbar (f, pos); } void xlike_redraw_exposed_toolbars (struct frame *f, int x, int y, int width, int height) { __INTERNAL_APPROPRIATENESS_CHECK(f); if (FRAME_REAL_TOP_TOOLBAR_VISIBLE (f)) xlike_redraw_exposed_toolbar (f, TOP_TOOLBAR, x, y, width, height); if (FRAME_REAL_BOTTOM_TOOLBAR_VISIBLE (f)) xlike_redraw_exposed_toolbar (f, BOTTOM_TOOLBAR, x, y, width, height); if (FRAME_REAL_LEFT_TOOLBAR_VISIBLE (f)) xlike_redraw_exposed_toolbar (f, LEFT_TOOLBAR, x, y, width, height); if (FRAME_REAL_RIGHT_TOOLBAR_VISIBLE (f)) xlike_redraw_exposed_toolbar (f, RIGHT_TOOLBAR, x, y, width, height); } void xlike_redraw_frame_toolbars (struct frame *f) { /* There are certain startup paths that lead to update_EmacsFrame in faces.c being called before a new frame is fully initialized. In particular before we have actually mapped it. That routine can call this one. So, we need to make sure that the frame is actually ready before we try and draw all over it. */ if (__INTERNAL_MAPPED_P(f)) xlike_redraw_exposed_toolbars (f, 0, 0, FRAME_PIXWIDTH (f), FRAME_PIXHEIGHT (f)); }