icon.c
上传用户:zlh9724
上传日期:2007-01-04
资源大小:1991k
文件大小:6k
源码类别:

浏览器

开发平台:

Unix_Linux

  1. /* howcome 11/10/94 */
  2. #include <stdio.h>
  3. #include <stdarg.h>
  4. #include <X11/Xlib.h>
  5. #include <X11/Xutil.h>
  6. #include <X11/Xos.h>
  7. #include <X11/keysym.h>
  8. #include "HTUtils.h" /* WWW general purpose macros */
  9. #include "tcp.h"
  10. #include "HTList.h"
  11. #include "HTAccess.h"
  12. #include "www.h"
  13. extern int debug;
  14. /*extern Doc *CurrentDoc;*/ 
  15. extern char * CacheDir;
  16. extern char * Editor;
  17. extern char * Icon;
  18. /* #define ICON_URL "http://info.cern.ch/hypertext/WWW/Icons/Experimental/w3o1.gif"*/
  19. #define ICON_URL "file://w3o1.gif"
  20. extern Display *display;
  21. extern int screen;
  22. extern int sbar_width;
  23. extern unsigned int win_width, win_height;
  24. extern int statusHeight;
  25. extern int ToolBarHeight;
  26. extern int depth;
  27. extern Pixmap icon_pixmap;
  28. Image *image = NULL;
  29. extern Window win;
  30. GC icon_gc;
  31. extern GC gc_fill, toolbar_gc;
  32. extern unsigned long windowColor;
  33. #define HARD_ICON_LENGTH 524
  34. #define HARD_ICON_64 "R0lGODlhMgAjAIQAAP///92amvYiF+AGEHkDCIf3opuRimZmr3pxdlli0jUqrhi/cwljBoiRwzUwkTQzacKleICR5Dkl04WFhQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAyACMAAAX+ICCOZGmeaKqubOu+ZiDPcK0GQp4PBGH/I5ygR9ANgT+cTyQ8ImHCJaApfbp6JKoVKNNVt6xZ0wlujXPfMotYRKt/bfL7pX0V7viCKa8v8bUGBwcICQqGJwULiooMe4uNQQCJjEIDBggNBpqFDoYKjo9+i4xMQ5MLDDoICJqaDZ6woqOQIqekUZMMQqutmgewhp0ktqjDo8VNuTkPDggQzwYNEQkSwIe1x7TEpEWnqQTMzs8NEgnmChLpnsah2MfFAATePswKB60N0gmZrq+f7u22wfMm4kE9QwgEJYjArxcCByOINRJIiiAAgw46eUpXrpemh+wqMno3kVRBZhqKDXHc5xHBP4DFckmaNRPeRZSwViZoCTHiu1AUbWLMaM2QIAMQDCjoCZNmTZIkhqa0du/ZUlnZfEIdYRDlVGDODmTE+kjbT1oncRZVEJapVqdNbXKVuhbTWFDt3pos0TXj16W/3Ibc2xRtVKl+/YJEYcvwU7kmuvadvIKBZct7LmNeMUGywQlz3oQAADs=     "
  35. /* Copyright (c) 1991 Bell Communications Research, Inc. (Bellcore) */
  36. #if defined __QNX__ || (defined(sco) && !defined(sco_os5))
  37. #define index strchr
  38. #else
  39. extern char *index();
  40. #endif
  41. static char basis_64[] =
  42.    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  43. /* janet: not used
  44. static char index_64[128] = {
  45.     -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
  46.     -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
  47.     -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,62, -1,-1,-1,63,
  48.     52,53,54,55, 56,57,58,59, 60,61,-1,-1, -1,-1,-1,-1,
  49.     -1, 0, 1, 2,  3, 4, 5, 6,  7, 8, 9,10, 11,12,13,14,
  50.     15,16,17,18, 19,20,21,22, 23,24,25,-1, -1,-1,-1,-1,
  51.     -1,26,27,28, 29,30,31,32, 33,34,35,36, 37,38,39,40,
  52.     41,42,43,44, 45,46,47,48, 49,50,51,-1, -1,-1,-1,-1
  53. };
  54. */
  55. /* #define char64(char c)  (((c) < 0 || (c) > 127) ? -1 : index_64[(c)]) */
  56. int char64(char c)
  57. {
  58.     char *s = (char *) index(basis_64, c);
  59.     if (s) return(s - basis_64);
  60.     return(-1); 
  61. }
  62. void SetIconWin(Window aWin)
  63. {
  64.     win = aWin;
  65. }
  66. void SetIconGC(GC aGC)
  67. {
  68.     icon_gc = aGC;
  69. }
  70. void LoadIcon ()
  71. {
  72.     int i,ii;
  73.     Block block;
  74.     unsigned int width, height;
  75.     GC drawGC;
  76.     Pixmap pixmap;
  77.     XImage *ximage;
  78.     char *data;
  79.     HTAnchor *a = NULL;
  80.     Doc *d = NULL;
  81.     if (Icon) {
  82. block.next = 0;
  83. /* fprintf(stderr,"LoadIcon sorry, cusomized icons temprarily disabled..n");*/
  84. a = libGetDocument(Icon, strlen(Icon), NULL, FALSE, TRUE, FALSE, FALSE, TRUE);
  85.     }
  86.     if (a && a->parent && a->parent->document) {
  87. d = (Doc *)a->parent->document;
  88.     }
  89.     if (d && d->content_buffer) {
  90. block.buffer = d->content_buffer;
  91. block.size = d->loaded_length;
  92. block.next = 0;
  93.     }
  94.     else {
  95. int c1, c2, c3, c4;
  96. char *b;
  97. char *buf;
  98. b = HARD_ICON_64;
  99. buf = (char *)malloc(HARD_ICON_LENGTH + 10);
  100. for (i=0, ii=0; i<176; i++) { /* janet 28/07/95: something's wrong here, */
  101.     c1 = char64(*b++); /*        probably 177 should be 176(?), because then it loops 177 times */
  102.     c2 = char64(*b++); /*        either that or *b is too short */
  103.     c3 = char64(*b++);
  104.     c4 = char64(*b++);
  105.     buf[ii++] = ((c1<<2) | ((c2&0x30)>>4));
  106.     buf[ii++] = (((c2&0XF) << 4) | ((c3&0x3C) >> 2));
  107.     buf[ii++] = (((c3&0x03) <<6) | c4);
  108. }
  109. block.buffer = buf;
  110. block.next = 0;
  111. block.size = 524; /* size of gif file */
  112.     }
  113.     
  114.     if (!block.buffer){
  115. image = NULL;
  116. return;
  117.     }
  118.     
  119.     image = (Image *)malloc(sizeof(Image));
  120.     image->url = NULL;
  121.     image->npixels = 0;
  122.     
  123.     data = (char *)LoadGifImage(image, &block, depth);
  124.     Free(block.buffer);
  125.     
  126.     width = image->width;
  127.     height = image->height;
  128.     
  129.     
  130.     if ((ximage = XCreateImage(display, DefaultVisual(display, screen),
  131.        depth, ZPixmap, 0, data,
  132.        width, height, (depth == 24 ? 32 : (depth == 16) ? 16 : 8), 0)) == 0)
  133. {
  134.     fprintf(stderr,"LoadIcon: Failed to create imagen");
  135.     Free(data);
  136.     Free(image);
  137.     image = NULL;
  138. }
  139.     /* howcome 22/2/95: do we need to set these?? */
  140.     ximage->byte_order = MSBFirst;
  141.     ximage->bitmap_bit_order = BitmapBitOrder(display);
  142.     if ((pixmap = XCreatePixmap(display, win, width, height, depth)) == 0)
  143. {
  144.     fprintf(stderr,"LoadIcon: Failed to create pixmapn");
  145.     Free(data);
  146.     Free(image);
  147.     image = NULL;
  148.     XDestroyImage(ximage);
  149. }
  150.     
  151.     drawGC = XCreateGC(display, pixmap, 0, 0);
  152.     XSetFunction(display, drawGC, GXcopy);
  153.     XPutImage(display, pixmap, drawGC, ximage, 0, 0, 0, 0, width, height);
  154.     XFreeGC(display, drawGC);
  155.     XDestroyImage(ximage);
  156.     
  157.     image->pixmap = pixmap;
  158.     image->width = width;
  159.     image->height = height;
  160.     image->next = NULL;
  161.     
  162.     icon_pixmap = pixmap;
  163. }
  164. void DisplayIcon ()
  165. {
  166.     XRectangle rect;
  167.     int x, y;
  168.     unsigned int w, h;
  169.     
  170.     if (!image)
  171.         LoadIcon();
  172.     rect.x = x = win_width - ICON_WIDTH;
  173.     rect.y = y = 0; 
  174.     rect.width = w = ICON_WIDTH;
  175.     rect.height = h = ICON_HEIGHT;
  176. /*    XSetClipRectangles(display, icon_gc, 0, 0, &rect, 1, Unsorted);*/
  177. /*    XSetClipRectangles(display, gc_fill, 0, 0, &rect, 1, Unsorted);*/
  178.     XSetForeground(display, toolbar_gc, windowColor);
  179.     XSetClipRectangles(display, toolbar_gc, 0, 0, &rect, 1, Unsorted);
  180.     XFillRectangle(display, win, toolbar_gc,
  181.                    x + 2, y + 2, ICON_WIDTH - 4, ICON_HEIGHT - 4);
  182.     if (image)
  183.     {
  184.         XCopyArea(display, image->pixmap, win, icon_gc,
  185.                   0, 0, image->width, image->height,
  186.                   x + (ICON_WIDTH - image->width) / 2,
  187.                   y + (ICON_HEIGHT - image->height) / 2); 
  188.     }
  189.     DrawOutSet(win, icon_gc, x, y, w, h);
  190. }