Changeset 1721

Show
Ignore:
Timestamp:
02/17/98 01:45:22 (11 years ago)
Author:
himi
Message:

Meadow--Multilingual Enhancement to GNU Emacs with ADvantages Over Windows

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/GNU/src/xmenu.c

    r1719 r1721  
    4242#include "keyboard.h" 
    4343#include "blockinput.h" 
     44#include "puresize.h" 
    4445#include "buffer.h" 
    4546 
     
    9091Lisp_Object Qdebug_on_next_call; 
    9192 
     93Lisp_Object Qmenu_alias; 
     94 
     95extern Lisp_Object Qmenu_enable; 
    9296extern Lisp_Object Qmenu_bar; 
    9397extern Lisp_Object Qmouse_click, Qevent_kind; 
    9498 
    95 extern Lisp_Object QCtoggle, QCradio
     99extern Lisp_Object Vdefine_key_rebound_commands
    96100 
    97101extern Lisp_Object Voverriding_local_map; 
     
    114118static void keymap_panes (); 
    115119static void single_keymap_panes (); 
    116 static void single_menu_item (); 
    117120static void list_of_panes (); 
    118121static void list_of_items (); 
     
    337340} 
    338341  
     342/* Figure out the current keyboard equivalent of a menu item ITEM1. 
     343   The item string for menu display should be ITEM_STRING. 
     344   Store the equivalent keyboard key sequence's 
     345   textual description into *DESCRIP_PTR. 
     346   Also cache them in the item itself. 
     347   Return the real definition to execute.  */ 
     348 
     349static Lisp_Object 
     350menu_item_equiv_key (item_string, item1, descrip_ptr) 
     351     Lisp_Object item_string; 
     352     Lisp_Object item1; 
     353     Lisp_Object *descrip_ptr; 
     354{ 
     355  /* This is the real definition--the function to run.  */ 
     356  Lisp_Object def; 
     357  /* This is the sublist that records cached equiv key data 
     358     so we can save time.  */ 
     359  Lisp_Object cachelist; 
     360  /* These are the saved equivalent keyboard key sequence 
     361     and its key-description.  */ 
     362  Lisp_Object savedkey, descrip; 
     363  Lisp_Object def1; 
     364  int changed = 0; 
     365  struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; 
     366 
     367  /* If a help string follows the item string, skip it.  */ 
     368  if (CONSP (XCONS (item1)->cdr) 
     369      && STRINGP (XCONS (XCONS (item1)->cdr)->car)) 
     370    item1 = XCONS (item1)->cdr; 
     371 
     372  def = Fcdr (item1); 
     373 
     374  /* Get out the saved equivalent-keyboard-key info.  */ 
     375  cachelist = savedkey = descrip = Qnil; 
     376  if (CONSP (def) && CONSP (XCONS (def)->car) 
     377      && (NILP (XCONS (XCONS (def)->car)->car) 
     378          || VECTORP (XCONS (XCONS (def)->car)->car))) 
     379    { 
     380      cachelist = XCONS (def)->car; 
     381      def = XCONS (def)->cdr; 
     382      savedkey = XCONS (cachelist)->car; 
     383      descrip = XCONS (cachelist)->cdr; 
     384    } 
     385 
     386  GCPRO4 (def, def1, savedkey, descrip); 
     387 
     388  /* Is it still valid?  */ 
     389  def1 = Qnil; 
     390  if (!NILP (savedkey)) 
     391    def1 = Fkey_binding (savedkey, Qnil); 
     392  /* If not, update it.  */ 
     393  if (! EQ (def1, def) 
     394      /* If the command is an alias for another 
     395         (such as easymenu.el and lmenu.el set it up), 
     396         check if the original command matches the cached command.  */ 
     397      && !(SYMBOLP (def) && SYMBOLP (XSYMBOL (def)->function) 
     398           && EQ (def1, XSYMBOL (def)->function)) 
     399      /* If something had no key binding before, don't recheck it 
     400         because that is too slow--except if we have a list of rebound 
     401         commands in Vdefine_key_rebound_commands, do recheck any command 
     402         that appears in that list.  */ 
     403      && (NILP (cachelist) || !NILP (savedkey) 
     404          || (! EQ (Qt, Vdefine_key_rebound_commands) 
     405              && !NILP (Fmemq (def, Vdefine_key_rebound_commands))))) 
     406    { 
     407      changed = 1; 
     408      descrip = Qnil; 
     409      /* If the command is an alias for another 
     410         (such as easymenu.el and lmenu.el set it up), 
     411         see if the original command name has equivalent keys.  */ 
     412      if (SYMBOLP (def) && SYMBOLP (XSYMBOL (def)->function) 
     413          && ! NILP (Fget (def, Qmenu_alias))) 
     414        savedkey = Fwhere_is_internal (XSYMBOL (def)->function, 
     415                                       Qnil, Qt, Qnil); 
     416      else 
     417        /* Otherwise look up the specified command itself. 
     418           We don't try both, because that makes easymenu menus slow.  */ 
     419        savedkey = Fwhere_is_internal (def, Qnil, Qt, Qnil); 
     420 
     421      if (!NILP (savedkey)) 
     422        { 
     423          descrip = Fkey_description (savedkey); 
     424          descrip = concat2 (make_string ("  (", 3), descrip); 
     425          descrip = concat2 (descrip, make_string (")", 1)); 
     426        } 
     427    } 
     428 
     429  /* Cache the data we just got in a sublist of the menu binding.  */ 
     430  if (NILP (cachelist)) 
     431    { 
     432      CHECK_IMPURE (item1); 
     433      XCONS (item1)->cdr = Fcons (Fcons (savedkey, descrip), def); 
     434    } 
     435  else if (changed) 
     436    { 
     437      XCONS (cachelist)->car = savedkey; 
     438      XCONS (cachelist)->cdr = descrip; 
     439    } 
     440 
     441  UNGCPRO; 
     442  *descrip_ptr = descrip; 
     443  return def; 
     444} 
     445 
     446/* This is used as the handler when calling internal_condition_case_1.  */ 
     447 
     448static Lisp_Object 
     449menu_item_enabled_p_1 (arg) 
     450     Lisp_Object arg; 
     451{ 
     452  /* If we got a quit from within the menu computation, 
     453     quit all the way out of it.  This takes care of C-] in the debugger.  */ 
     454  if (CONSP (arg) && EQ (XCONS (arg)->car, Qquit)) 
     455    Fsignal (Qquit, Qnil); 
     456 
     457  return Qnil; 
     458} 
     459 
     460/* Return non-nil if the command DEF is enabled when used as a menu item. 
     461   This is based on looking for a menu-enable property. 
     462   If NOTREAL is set, don't bother really computing this.  */ 
     463 
     464static Lisp_Object 
     465menu_item_enabled_p (def, notreal) 
     466     Lisp_Object def; 
     467     int notreal; 
     468{ 
     469  Lisp_Object enabled, tem; 
     470 
     471  enabled = Qt; 
     472  if (notreal) 
     473    return enabled; 
     474  if (SYMBOLP (def)) 
     475    { 
     476      /* No property, or nil, means enable. 
     477         Otherwise, enable if value is not nil.  */ 
     478      tem = Fget (def, Qmenu_enable); 
     479      if (!NILP (tem)) 
     480        /* (condition-case nil (eval tem) 
     481           (error nil))  */ 
     482        enabled = internal_condition_case_1 (Feval, tem, Qerror, 
     483                                             menu_item_enabled_p_1); 
     484    } 
     485  return enabled; 
     486} 
     487  
    339488/* Look through KEYMAPS, a vector of keymaps that is NMAPS long, 
    340489   and generate menu panes for them in menu_items. 
     
    365514   The other arguments are passed along 
    366515   or point to local variables of the previous function. 
    367    If NOTREAL is nonzero, only check for equivalent key bindings, don't 
    368    evaluate expressions in menu items and don't make any menu
     516   If NOTREAL is nonzero, 
     517   don't bother really computing whether an item is enabled
    369518 
    370519   If we encounter submenus deeper than MAXDEPTH levels, ignore them.  */ 
     
    378527     int maxdepth; 
    379528{ 
    380   Lisp_Object pending_maps = Qnil; 
    381   Lisp_Object tail, item; 
    382   struct gcpro gcpro1, gcpro2; 
    383   int notbuttons = 0; 
     529  Lisp_Object pending_maps; 
     530  Lisp_Object tail, item, item1, item_string, table; 
     531  struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; 
    384532 
    385533  if (maxdepth <= 0) 
    386534    return; 
    387535 
     536  pending_maps = Qnil; 
     537 
    388538  push_menu_pane (pane_name, prefix); 
    389539 
    390 #ifndef HAVE_BOXES 
    391   /* Remember index for first item in this pane so we can go back and 
    392      add a prefix when (if) we see the first button.  After that, notbuttons 
    393      is set to 0, to mark that we have seen a button and all non button 
    394      items need a prefix.  */ 
    395   notbuttons = menu_items_used; 
    396 #endif 
    397  
    398540  for (tail = keymap; CONSP (tail); tail = XCONS (tail)->cdr) 
    399541    { 
    400       GCPRO2 (keymap, pending_maps); 
    401       /* Look at each key binding, and if it is a menu item add it 
    402          to this menu.  */ 
     542      /* Look at each key binding, and if it has a menu string, 
     543         make a menu item from it.  */ 
    403544      item = XCONS (tail)->car; 
    404545      if (CONSP (item)) 
    405         single_menu_item (XCONS (item)->car, XCONS (item)->cdr, 
    406                           &pending_maps, notreal, maxdepth, &notbuttons); 
     546        { 
     547          item1 = XCONS (item)->cdr; 
     548          if (CONSP (item1)) 
     549            { 
     550              item_string = XCONS (item1)->car; 
     551              if (STRINGP (item_string)) 
     552                { 
     553                  /* This is the real definition--the function to run.  */ 
     554                  Lisp_Object def; 
     555                  /* These are the saved equivalent keyboard key sequence 
     556                     and its key-description.  */ 
     557                  Lisp_Object descrip; 
     558                  Lisp_Object tem, enabled; 
     559 
     560                  /* GCPRO because ...enabled_p will call eval 
     561                     and ..._equiv_key may autoload something. 
     562                     Protecting KEYMAP preserves everything we use; 
     563                     aside from that, must protect whatever might be 
     564                     a string.  Since there's no GCPRO5, we refetch 
     565                     item_string instead of protecting it.  */ 
     566                  descrip = def = Qnil; 
     567                  GCPRO4 (keymap, pending_maps, def, descrip); 
     568 
     569                  def = menu_item_equiv_key (item_string, item1, &descrip); 
     570                  enabled = menu_item_enabled_p (def, notreal); 
     571 
     572                  UNGCPRO; 
     573 
     574                  item_string = XCONS (item1)->car; 
     575 
     576                  tem = Fkeymapp (def); 
     577                  if (XSTRING (item_string)->data[0] == '@' && !NILP (tem)) 
     578                    pending_maps = Fcons (Fcons (def, Fcons (item_string, XCONS (item)->car)), 
     579                                          pending_maps); 
     580                  else 
     581                    { 
     582                      Lisp_Object submap; 
     583                      GCPRO4 (keymap, pending_maps, descrip, item_string); 
     584                      submap = get_keymap_1 (def, 0, 1); 
     585                      UNGCPRO; 
     586#ifndef USE_X_TOOLKIT 
     587                      /* Indicate visually that this is a submenu.  */ 
     588                      if (!NILP (submap)) 
     589                        item_string = concat2 (item_string, 
     590                                               build_string (" >")); 
     591#endif 
     592                      /* If definition is nil, pass nil as the key.  */ 
     593                      push_menu_item (item_string, enabled, 
     594                                      XCONS (item)->car, def, 
     595                                      descrip); 
     596#ifdef USE_X_TOOLKIT 
     597                      /* Display a submenu using the toolkit.  */ 
     598                      if (! NILP (submap)) 
     599                        { 
     600                          push_submenu_start (); 
     601                          single_keymap_panes (submap, Qnil, 
     602                                               XCONS (item)->car, notreal, 
     603                                               maxdepth - 1); 
     604                          push_submenu_end (); 
     605                        } 
     606#endif 
     607                    } 
     608                } 
     609            } 
     610        } 
    407611      else if (VECTORP (item)) 
    408612        { 
     
    414618              Lisp_Object character; 
    415619              XSETFASTINT (character, c); 
    416               single_menu_item (character, XVECTOR (item)->contents[c], 
    417                                 &pending_maps, notreal, maxdepth, &notbuttons); 
     620              item1 = XVECTOR (item)->contents[c]; 
     621              if (CONSP (item1)) 
     622                { 
     623                  item_string = XCONS (item1)->car; 
     624                  if (STRINGP (item_string)) 
     625                    { 
     626                      Lisp_Object def; 
     627 
     628                      /* These are the saved equivalent keyboard key sequence 
     629                         and its key-description.  */ 
     630                      Lisp_Object descrip; 
     631                      Lisp_Object tem, enabled; 
     632 
     633                      /* GCPRO because ...enabled_p will call eval 
     634                         and ..._equiv_key may autoload something. 
     635                         Protecting KEYMAP preserves everything we use; 
     636                         aside from that, must protect whatever might be 
     637                         a string.  Since there's no GCPRO5, we refetch 
     638                         item_string instead of protecting it.  */ 
     639                      GCPRO4 (keymap, pending_maps, def, descrip); 
     640                      descrip = def = Qnil; 
     641 
     642                      def = menu_item_equiv_key (item_string, item1, &descrip); 
     643                      enabled = menu_item_enabled_p (def, notreal); 
     644 
     645                      UNGCPRO; 
     646 
     647                      item_string = XCONS (item1)->car; 
     648 
     649                      tem = Fkeymapp (def); 
     650                      if (XSTRING (item_string)->data[0] == '@' && !NILP (tem)) 
     651                        pending_maps = Fcons (Fcons (def, Fcons (item_string, character)), 
     652                                              pending_maps); 
     653                      else 
     654                        { 
     655                          Lisp_Object submap; 
     656                          GCPRO4 (keymap, pending_maps, descrip, item_string); 
     657                          submap = get_keymap_1 (def, 0, 1); 
     658                          UNGCPRO; 
     659#ifndef USE_X_TOOLKIT 
     660                          if (!NILP (submap)) 
     661                            item_string = concat2 (item_string, 
     662                                                   build_string (" >")); 
     663#endif 
     664                          /* If definition is nil, pass nil as the key.  */ 
     665                          push_menu_item (item_string, enabled, character, 
     666                                          def, descrip); 
     667#ifdef USE_X_TOOLKIT 
     668                          if (! NILP (submap)) 
     669                            { 
     670                              push_submenu_start (); 
     671                              single_keymap_panes (submap, Qnil, 
     672                                                   character, notreal, 
     673                                                   maxdepth - 1); 
     674                              push_submenu_end (); 
     675                            } 
     676#endif 
     677                        } 
     678                    } 
     679                } 
    418680            } 
    419681        } 
    420       UNGCPRO; 
    421682    } 
    422683 
     
    434695      pending_maps = Fcdr (pending_maps); 
    435696    } 
    436 } 
    437   
    438 /* This is a subroutine of single_keymap_panes that handles one 
    439    keymap entry. 
    440    KEY is a key in a keymap and ITEM is its binding.  
    441    PENDING_MAPS_PTR points to a list of keymaps waiting to be made into 
    442    separate panes. 
    443    If NOTREAL is nonzero, only check for equivalent key bindings, don't 
    444    evaluate expressions in menu items and don't make any menu. 
    445    If we encounter submenus deeper than MAXDEPTH levels, ignore them. 
    446    NOTBUTTONS_PTR is only used when simulating toggle boxes and radio 
    447    buttons.  It points to variable notbuttons in single_keymap_panes, 
    448    which keeps track of if we have seen a button in this menu or not.  */ 
    449  
    450 static void 
    451 single_menu_item (key, item, pending_maps_ptr, notreal, maxdepth, 
    452                   notbuttons_ptr) 
    453      Lisp_Object key, item; 
    454      Lisp_Object *pending_maps_ptr; 
    455      int maxdepth, notreal; 
    456      int *notbuttons_ptr; 
    457 { 
    458   Lisp_Object def, map, item_string, enabled; 
    459   struct gcpro gcpro1, gcpro2; 
    460   int res; 
    461    
    462   /* Parse the menu item and leave the result in item_properties.  */ 
    463   GCPRO2 (key, item); 
    464   res = parse_menu_item (item, notreal, 0); 
    465   UNGCPRO; 
    466   if (!res) 
    467     return;                     /* Not a menu item.  */ 
    468  
    469   map = XVECTOR (item_properties)->contents[ITEM_PROPERTY_MAP]; 
    470    
    471   if (notreal) 
    472     { 
    473       /* We don't want to make a menu, just traverse the keymaps to 
    474          precompute equivalent key bindings.  */ 
    475       if (!NILP (map)) 
    476         single_keymap_panes (map, Qnil, key, 1, maxdepth - 1); 
    477       return; 
    478     } 
    479  
    480   enabled = XVECTOR (item_properties)->contents[ITEM_PROPERTY_ENABLE]; 
    481   item_string = XVECTOR (item_properties)->contents[ITEM_PROPERTY_NAME];  
    482  
    483   if (!NILP (map) && XSTRING (item_string)->data[0] == '@') 
    484     { 
    485       if (!NILP (enabled)) 
    486         /* An enabled separate pane. Remember this to handle it later.  */ 
    487         *pending_maps_ptr = Fcons (Fcons (map, Fcons (item_string, key)), 
    488                                    *pending_maps_ptr); 
    489       return; 
    490     } 
    491  
    492 #ifndef HAVE_BOXES 
    493   /* Simulate radio buttons and toggle boxes by putting a prefix in 
    494      front of them.  */ 
    495   { 
    496     Lisp_Object prefix = Qnil; 
    497     Lisp_Object type = XVECTOR (item_properties)->contents[ITEM_PROPERTY_TYPE]; 
    498     if (!NILP (type)) 
    499       { 
    500         Lisp_Object selected 
    501           = XVECTOR (item_properties)->contents[ITEM_PROPERTY_SELECTED]; 
    502  
    503         if (*notbuttons_ptr) 
    504           /* The first button. Line up previous items in this menu.  */ 
    505           { 
    506             int index = *notbuttons_ptr; /* Index for first item this menu.  */ 
    507             int submenu = 0; 
    508             Lisp_Object tem; 
    509             while (index < menu_items_used) 
    510               { 
    511                 tem 
    512                   = XVECTOR (menu_items)->contents[index + MENU_ITEMS_ITEM_NAME]; 
    513                 if (NILP (tem)) 
    514                   { 
    515                     index++; 
    516                     submenu++;          /* Skip sub menu.  */ 
    517                   } 
    518                 else if (EQ (tem, Qlambda)) 
    519                   { 
    520                     index++; 
    521                     submenu--;          /* End sub menu.  */ 
    522                   } 
    523                 else if (EQ (tem, Qt)) 
    524                   index += 3;           /* Skip new pane marker. */ 
    525                 else if (EQ (tem, Qquote)) 
    526                   index++;              /* Skip a left, right divider. */ 
    527                 else 
    528                   { 
    529                     if (!submenu && XSTRING (tem)->data[0] != '\0' 
    530                         && XSTRING (tem)->data[0] != '-') 
    531                       XVECTOR (menu_items)->contents[index + MENU_ITEMS_ITEM_NAME] 
    532                         = concat2 (build_string ("    "), tem); 
    533                     index += MENU_ITEMS_ITEM_LENGTH; 
    534                   } 
    535               } 
    536             *notbuttons_ptr = 0; 
    537           } 
    538  
    539         /* Calculate prefix, if any, for this item.  */ 
    540         if (EQ (type, QCtoggle)) 
    541           prefix = build_string (NILP (selected) ? "[ ] " : "[X] "); 
    542         else if (EQ (type, QCradio)) 
    543           prefix = build_string (NILP (selected) ? "( ) " : "(*) "); 
    544       } 
    545     /* Not a button. If we have earlier buttons, then we need a prefix.  */ 
    546     else if (!*notbuttons_ptr && XSTRING (item_string)->data[0] != '\0' 
    547              && XSTRING (item_string)->data[0] != '-') 
    548       prefix = build_string ("    "); 
    549  
    550     if (!NILP (prefix)) 
    551       item_string = concat2 (prefix, item_string); 
    552   } 
    553 #endif /* not HAVE_BOXES */ 
    554   
    555 #ifndef USE_X_TOOLKIT 
    556   if (!NILP(map)) 
    557     /* Indicate visually that this is a submenu.  */ 
    558     item_string = concat2 (item_string, build_string (" >")); 
    559 #endif 
    560  
    561   push_menu_item (item_string, enabled, key, 
    562                   XVECTOR (item_properties)->contents[ITEM_PROPERTY_DEF], 
    563                   XVECTOR (item_properties)->contents[ITEM_PROPERTY_KEYEQ]); 
    564  
    565 #ifdef USE_X_TOOLKIT 
    566   /* Display a submenu using the toolkit.  */ 
    567   if (! (NILP (map) || NILP (enabled))) 
    568     { 
    569       push_submenu_start (); 
    570       single_keymap_panes (map, Qnil, key, 0, maxdepth - 1); 
    571       push_submenu_end (); 
    572     } 
    573 #endif 
    574697} 
    575698  
     
    687810          FRAME_PTR new_f = selected_frame; 
    688811          Lisp_Object bar_window; 
    689           enum scroll_bar_part part; 
     812          int part; 
    690813          unsigned long time; 
    691814 
     
    10261149               && dpyinfo->display == event.xbutton.display) 
    10271150        { 
    1028           KeySym keysym = XLookupKeysym (&event.xkey, 0); 
    1029           if (!IsModifierKey (keysym)) 
    1030             { 
    1031               popup_activated_flag = 0; 
    1032               break; 
    1033             } 
     1151          popup_activated_flag = 0; 
     1152          break; 
    10341153        } 
    10351154      /* Button presses outside the menu also pop it down.  */ 
     
    10961215   execute Lisp code.  */ 
    10971216    
    1098 void 
    10991217x_activate_menubar (f) 
    11001218     FRAME_PTR f; 
     
    15671685      specbind (Qdebug_on_next_call, Qnil); 
    15681686 
    1569       record_unwind_protect (Fset_match_data, Fmatch_data (Qnil, Qnil)); 
     1687      record_unwind_protect (Fstore_match_data, Fmatch_data (Qnil, Qnil)); 
    15701688      if (NILP (Voverriding_local_map_menu_flag)) 
    15711689        { 
     
    24422560                  continue; 
    24432561                } 
    2444               width = STRING_BYTES (XSTRING (item))
     2562              width = XSTRING (item)->size
    24452563              if (width > maxwidth) 
    24462564                maxwidth = width; 
     
    24652583          if (!NILP (descrip)) 
    24662584            { 
    2467               int gap = maxwidth - STRING_BYTES (XSTRING (item_name))
     2585              int gap = maxwidth - XSTRING (item_name)->size
    24682586#ifdef C_ALLOCA 
    24692587              Lisp_Object spacer; 
     
    24772595              item_data 
    24782596                = (unsigned char *) alloca (maxwidth 
    2479                                             + STRING_BYTES (XSTRING (descrip)) + 1); 
     2597                                            + XSTRING (descrip)->size + 1); 
    24802598              bcopy (XSTRING (item_name)->data, item_data, 
    2481                      STRING_BYTES (XSTRING (item_name))); 
     2599                     XSTRING (item_name)->size); 
    24822600              for (j = XSTRING (item_name)->size; j < maxwidth; j++) 
    24832601                item_data[j] = ' '; 
    24842602              bcopy (XSTRING (descrip)->data, item_data + j, 
    2485                      STRING_BYTES (XSTRING (descrip))); 
    2486               item_data[j + STRING_BYTES (XSTRING (descrip))] = 0; 
     2603                     XSTRING (descrip)->size); 
     2604              item_data[j + XSTRING (descrip)->size] = 0; 
    24872605#endif 
    24882606            } 
     
    26082726#endif /* HAVE_MENUS */ 
    26092727  
    2610 void 
    26112728syms_of_xmenu () 
    26122729{ 
    26132730  staticpro (&menu_items); 
    26142731  menu_items = Qnil; 
     2732 
     2733  Qmenu_alias = intern ("menu-alias"); 
     2734  staticpro (&Qmenu_alias); 
    26152735 
    26162736  Qdebug_on_next_call = intern ("debug-on-next-call"); 
  • branches/GNU/src/xrdb.c

    r1719 r1721  
    2323#ifdef emacs 
    2424#include <config.h> 
    25 #endif 
    26  
    27 #ifdef HAVE_UNISTD_H 
    28 #include <unistd.h> 
    2925#endif 
    3026 
     
    8985#define realloc xrealloc 
    9086#define free xfree 
    91 extern long *xmalloc (), *xrealloc (); 
    9287#endif 
    9388 
  • branches/GNU/src/xselect.c

    r1719 r1721  
    11/* X Selection processing for Emacs. 
    2    Copyright (C) 1993, 1994, 1995, 1996, 1997 Free Software Foundation. 
     2   Copyright (C) 1993, 1994, 1995, 1996 Free Software Foundation. 
    33 
    44This file is part of GNU Emacs. 
     
    2828#include "frame.h"      /* Need this to get the X window of selected_frame */ 
    2929#include "blockinput.h" 
    30 #include "buffer.h" 
    3130#include "charset.h" 
    3231#include "coding.h" 
    33 #include "process.h" 
    3432 
    3533#define CUT_BUFFER_SUPPORT 
     
    5048/* Coding system for communicating with other X clients via cutbuffer, 
    5149   selection, and clipboard.  */ 
    52 static Lisp_Object Vselection_coding_system; 
    53  
    54 /* Coding system for the next communicating with other X clients.  */ 
    55 static Lisp_Object Vnext_selection_coding_system; 
     50static Lisp_Object Vclipboard_coding_system; 
    5651 
    5752/* If this is a smaller number than the max-request-size of the display, 
     
    735730      x_selection_current_request = 0; 
    736731 
    737       /* Use xfree, not XFree, because lisp_data_to_selection_data 
     732      /* Use free, not XFree, because lisp_data_to_selection_data 
    738733         calls xmalloc itself.  */ 
    739734      if (!nofree) 
    740         xfree (data); 
     735        free (data); 
    741736    } 
    742737  unbind_to (count, Qnil); 
     
    941936          else 
    942937            property_change_wait_list = rest->next; 
    943           xfree (rest); 
     938          free (rest); 
    944939          return; 
    945940        } 
     
    10301025          else 
    10311026            property_change_wait_list = rest->next; 
    1032           xfree (rest); 
     1027          free (rest); 
    10331028          return; 
    10341029        } 
     
    11741169/* Subroutines of x_get_window_property_as_lisp_data */ 
    11751170 
    1176 /* Use xfree, not XFree, to free the data obtained with this function.  */ 
     1171/* Use free, not XFree, to free the data obtained with this function.  */ 
    11771172 
    11781173static void 
     
    12571252} 
    12581253  
    1259 /* Use xfree, not XFree, to free the data obtained with this function.  */ 
     1254/* Use free, not XFree, to free the data obtained with this function.  */ 
    12601255 
    12611256static void 
     
    13191314            XSelectInput (display, window, STANDARD_EVENT_SET); 
    13201315          unexpect_property_change (wait_object); 
    1321           /* Use xfree, not XFree, because x_get_window_property 
     1316          /* Use free, not XFree, because x_get_window_property 
    13221317             calls xmalloc itself.  */ 
    1323           if (tmp_data) xfree (tmp_data); 
     1318          if (tmp_data) free (tmp_data); 
    13241319          break; 
    13251320        } 
     
    13461341      bcopy (tmp_data, (*data_ret) + offset, tmp_size_bytes); 
    13471342      offset += tmp_size_bytes; 
    1348       /* Use xfree, not XFree, because x_get_window_property 
     1343      /* Use free, not XFree, because x_get_window_property 
    13491344         calls xmalloc itself.  */ 
    1350       xfree (tmp_data); 
     1345      free (tmp_data); 
    13511346    } 
    13521347} 
     
    14031398      unsigned int min_size_bytes = * ((unsigned int *) data); 
    14041399      BLOCK_INPUT; 
    1405       /* Use xfree, not XFree, because x_get_window_property 
     1400      /* Use free, not XFree, because x_get_window_property 
    14061401         calls xmalloc itself.  */ 
    1407       xfree ((char *) data); 
     1402      free ((char *) data); 
    14081403      UNBLOCK_INPUT; 
    14091404      receive_incremental_selection (display, window, property, target_type, 
     
    14231418                                     actual_type, actual_format); 
    14241419   
    1425   /* Use xfree, not XFree, because x_get_window_property 
     1420  /* Use free, not XFree, because x_get_window_property 
    14261421     calls xmalloc itself.  */ 
    1427   xfree ((char *) data); 
     1422  free ((char *) data); 
    14281423  return val; 
    14291424} 
     
    14741469      int require_encoding = 0; 
    14751470 
    1476       if ( 
    1477 #if 1 
    1478           1 
    1479 #else 
    1480           ! NILP (buffer_defaults.enable_multibyte_characters) 
    1481 #endif 
    1482           ) 
     1471      /* If TYPE is `TEXT' or `COMPOUND_TEXT', we should decode DATA 
     1472         to Emacs internal format because DATA may be encoded in 
     1473         compound text format.  In addtion, if TYPE is `STRING' and 
     1474         DATA contains any 8-bit Latin-1 code, we should also decode 
     1475         it.  */ 
     1476      if (type == dpyinfo->Xatom_TEXT || type == dpyinfo->Xatom_COMPOUND_TEXT) 
     1477        require_encoding = 1; 
     1478      else if (type == XA_STRING) 
    14831479        { 
    1484           /* If TYPE is `TEXT' or `COMPOUND_TEXT', we should decode 
    1485              DATA to Emacs internal format because DATA may be encoded 
    1486              in compound text format.  In addtion, if TYPE is `STRING' 
    1487              and DATA contains any 8-bit Latin-1 code, we should also 
    1488              decode it.  */ 
    1489           if (type == dpyinfo->Xatom_TEXT 
    1490               || type == dpyinfo->Xatom_COMPOUND_TEXT) 
    1491             require_encoding = 1; 
    1492           else if (type == XA_STRING) 
     1480          int i; 
     1481          for (i = 0; i < size; i++) 
    14931482            { 
    1494               int i; 
    1495               for (i = 0; i < size; i++) 
     1483              if (data[i] >= 0x80) 
    14961484                { 
    1497                   if (data[i] >= 0x80) 
    1498                     { 
    1499                       require_encoding = 1; 
    1500                       break; 
    1501                     } 
     1485                  require_encoding = 1; 
     1486                  break; 
    15021487                } 
    15031488            } 
    15041489        } 
    15051490      if (!require_encoding) 
    1506         { 
    1507           str = make_unibyte_string ((char *) data, size); 
    1508           Vlast_coding_system_used = Qraw_text; 
    1509         } 
     1491        str = make_string ((char *) data, size); 
    15101492      else 
    15111493        { 
    1512           int bufsize
     1494          int bufsize, dummy
    15131495          unsigned char *buf; 
    15141496          struct coding_system coding; 
    15151497 
    1516           if (NILP (Vnext_selection_coding_system)) 
    1517             Vnext_selection_coding_system = Vselection_coding_system; 
    15181498          setup_coding_system 
    1519             (Fcheck_coding_system(Vnext_selection_coding_system), &coding); 
    1520           Vnext_selection_coding_system = Qnil; 
    1521           coding.mode |= CODING_MODE_LAST_BLOCK; 
     1499            (Fcheck_coding_system(Vclipboard_coding_system), &coding); 
     1500          coding.last_block = 1; 
    15221501          bufsize = decoding_buffer_size (&coding, size); 
    15231502          buf = (unsigned char *) xmalloc (bufsize); 
    1524           decode_coding (&coding, data, buf, size, bufsize); 
    1525           size = (coding.fake_multibyte 
    1526                   ? multibyte_chars_in_text (buf, coding.produced) 
    1527                   : coding.produced_char); 
    1528           str = make_string_from_bytes ((char *) buf, size, coding.produced); 
    1529           xfree (buf); 
    1530           Vlast_coding_system_used = coding.symbol; 
     1503          size = decode_coding (&coding, data, buf, size, bufsize, &dummy); 
     1504          str = make_string ((char *) buf, size); 
     1505          free (buf); 
    15311506        } 
    15321507      return str; 
     
    15891564 
    15901565 
    1591 /* Use xfree, not XFree, to free the data obtained with this function.  */ 
     1566/* Use free, not XFree, to free the data obtained with this function.  */ 
    15921567 
    15931568static void 
     
    16311606 
    16321607      *format_ret = 8; 
    1633       *size_ret = STRING_BYTES (XSTRING (obj))
     1608      *size_ret = XSTRING (obj)->size
    16341609      *data_ret = XSTRING (obj)->data; 
    16351610      bzero (charsets, (MAX_CHARSET + 1) * sizeof (int)); 
    1636       num = ((*size_ret <= 1    /* Check the possibility of short cut.  */ 
    1637               || !STRING_MULTIBYTE (obj) 
    1638               || *size_ret == XSTRING (obj)->size) 
     1611      num = ((*size_ret <= 1)   /* Check the possibility of short cut.  */ 
    16391612             ? 0 
    1640              : find_charset_in_str (*data_ret, *size_ret, charsets, Qnil, 1)); 
     1613             : find_charset_in_str (*data_ret, *size_ret, charsets, Qnil)); 
    16411614 
    16421615      if (!num || (num == 1 && charsets[CHARSET_ASCII])) 
     
    16451618          *nofree_ret = 1; 
    16461619          if (NILP (type)) type = QSTRING; 
    1647           Vlast_coding_system_used = Qraw_text; 
    16481620        } 
    16491621      else 
     
    16531625             expects if OBJ contains only ASCII and Latin-1 
    16541626             characters.  */ 
    1655           int bufsize
     1627          int bufsize, dummy
    16561628          unsigned char *buf; 
    16571629          struct coding_system coding; 
    16581630 
    1659           if (NILP (Vnext_selection_coding_system)) 
    1660             Vnext_selection_coding_system = Vselection_coding_system; 
    16611631          setup_coding_system 
    1662             (Fcheck_coding_system (Vnext_selection_coding_system), &coding); 
    1663           Vnext_selection_coding_system = Qnil; 
    1664           coding.mode |= CODING_MODE_LAST_BLOCK; 
     1632            (Fcheck_coding_system (Vclipboard_coding_system), &coding); 
     1633          coding.last_block = 1; 
    16651634          bufsize = encoding_buffer_size (&coding, *size_ret); 
    16661635          buf = (unsigned char *) xmalloc (bufsize); 
    1667           encode_coding (&coding, *data_ret, buf, *size_ret, bufsize); 
    1668           *size_ret = coding.produced
     1636          *size_ret = encode_coding (&coding, *data_ret, buf, 
     1637                                    *size_ret, bufsize, &dummy)
    16691638          *data_ret = buf; 
    1670           if (charsets[charset_latin_iso8859_1
     1639          if (charsets[get_charset_id(charset_latin_iso8859_1)
    16711640              && (num == 1 || (num == 2 && charsets[CHARSET_ASCII]))) 
    16721641            { 
     
    16791648              if (NILP (type)) type = QCOMPOUND_TEXT; 
    16801649            } 
    1681           Vlast_coding_system_used = coding.symbol; 
    16821650        } 
    16831651    } 
     
    19421910  Time timestamp; 
    19431911  Atom selection_atom; 
    1944   struct selection_input_event event; 
     1912  XSelectionClearEvent event; 
    19451913  Display *display; 
    19461914  struct x_display_info *dpyinfo; 
     
    19721940  SELECTION_EVENT_SELECTION (&event) = selection_atom; 
    19731941  SELECTION_EVENT_TIME (&event) = timestamp; 
    1974   x_handle_selection_clear ((struct input_event *) &event); 
     1942  x_handle_selection_clear (&event); 
    19751943 
    19761944  return Qt; 
     
    21172085  x_get_window_property (display, window, buffer_atom, &data, &bytes, 
    21182086                         &type, &format, &size, 0); 
    2119   if (!data || !format) 
    2120     return Qnil; 
     2087  if (!data) return Qnil; 
    21212088   
    21222089  if (format != 8 || type != XA_STRING) 
     
    21272094 
    21282095  ret = (bytes ? make_string ((char *) data, bytes) : Qnil); 
    2129   /* Use xfree, not XFree, because x_get_window_property 
     2096  /* Use free, not XFree, because x_get_window_property 
    21302097     calls xmalloc itself.  */ 
    2131   xfree (data); 
     2098  free (data); 
    21322099  return ret; 
    21332100} 
     
    21612128                                  display, buffer); 
    21622129  data = (unsigned char *) XSTRING (string)->data; 
    2163   bytes = STRING_BYTES (XSTRING (string))
     2130  bytes = XSTRING (string)->size
    21642131  bytes_remaining = bytes; 
    21652132 
     
    21962163DEFUN ("x-rotate-cut-buffers-internal", Fx_rotate_cut_buffers_internal, 
    21972164  Sx_rotate_cut_buffers_internal, 1, 1, 0, 
    2198   "Rotate the values of the cut buffers by the given number of step.\n\ 
    2199 Positive means shift the values forward, negative means backward.") 
     2165  "Rotate the values of the cut buffers by the given number of steps;\n\ 
     2166positive means move values forward, negative means backward.") 
    22002167  (n) 
    22012168     Lisp_Object n; 
     
    22982265  Vx_sent_selection_hooks = Qnil; 
    22992266 
    2300   DEFVAR_LISP ("selection-coding-system", &Vselection_coding_system, 
     2267  DEFVAR_LISP ("clipboard-coding-system", &Vclipboard_coding_system, 
    23012268    "Coding sy