~ubuntu-branches/ubuntu/precise/ncbi-tools6/precise

« back to all changes in this revision

Viewing changes to vibrant/ncbidraw.c

  • Committer: Bazaar Package Importer
  • Author(s): Aaron M. Ucko
  • Date: 2005-03-27 12:00:15 UTC
  • mfrom: (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050327120015-embhesp32nj73p9r
Tags: 6.1.20041020-3
* Fix FTBFS under GCC 4.0 caused by inconsistent use of "static" on
  functions.  (Closes: #295110.)
* Add a watch file, now that we can.  (Upstream's layout needs version=3.)

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
*
30
30
* Version Creation Date:   1/1/91
31
31
*
32
 
* $Revision: 6.29 $
 
32
* $Revision: 6.37 $
33
33
*
34
34
* File Description: 
35
35
*       Vibrant drawing functions.
37
37
* Modifications:  
38
38
* --------------------------------------------------------------------------
39
39
* $Log: ncbidraw.c,v $
 
40
* Revision 6.37  2004/04/14 19:15:50  sinyakov
 
41
* WIN_MSWIN: support X-Windows-like -bg color command line option
 
42
*
 
43
* Revision 6.36  2003/11/17 17:03:30  kans
 
44
* changed C++ style comments to C comments
 
45
*
 
46
* Revision 6.35  2003/03/19 21:13:22  kans
 
47
* protect UNIX version of ScrollRect
 
48
*
 
49
* Revision 6.34  2002/06/13 16:15:12  kans
 
50
* fix includes for OS_UNIX_DARWIN with WIN_MAC (EN) - still bug in vibutils.c file dialog
 
51
*
 
52
* Revision 6.33  2002/03/28 13:35:48  kans
 
53
* only include MoreCarbonAccessors.h if not OS_UNIX_DARWIN
 
54
*
 
55
* Revision 6.32  2002/03/06 20:15:14  northup
 
56
* under X11 cache colors from XAllocColor using a hash table. (EN)
 
57
*
 
58
* Revision 6.31  2002/02/04 19:04:51  kans
 
59
* pass fsp.size to LoadFontData for systemFont on Mac - now label width calculated correctly
 
60
*
 
61
* Revision 6.30  2002/02/04 18:49:15  kans
 
62
* fsp.size = GetDefFontSize () for systemFont on Mac - Mac OS X uses Lucida Grande 13
 
63
*
40
64
* Revision 6.29  2001/08/29 21:14:10  juran
41
65
* Move Carbon forward-compatibility to MoreCarbonAccessors.h.
42
66
* Call InvalRgn instead of InvalWindowRegion.
313
337
Nlm_Boolean  Nlm_nowPrinting = FALSE;
314
338
 
315
339
#ifdef WIN_MAC
316
 
# include "MoreCarbonAccessors.h"
 
340
#include "MoreCarbonAccessors.h"
317
341
#endif
318
342
 
319
343
#ifdef WIN_MAC
871
895
#endif
872
896
 
873
897
 
 
898
#ifdef WIN_MSWIN
 
899
extern BOOLEAN Nlm_hasBackColor;
 
900
extern COLORREF Nlm_crBackColor;
 
901
extern HBRUSH Nlm_hbrWindowBackground;
 
902
#endif
 
903
 
 
904
 
874
905
extern void Nlm_ResetDrawingTools (void)
875
906
{
876
907
#ifdef WIN_MAC
890
921
    SetROP2 (Nlm_currentHDC, R2_COPYPEN);
891
922
    SelectObject(Nlm_currentHDC, GetStockObject(SYSTEM_FONT));
892
923
    winTextColor = GetSysColor (COLOR_WINDOWTEXT);
893
 
    winBkColor = GetSysColor (COLOR_WINDOW);
 
924
    winBkColor = Nlm_hasBackColor ?
 
925
                   Nlm_crBackColor :
 
926
                   GetSysColor (COLOR_WINDOW);
894
927
    SetTextColor (Nlm_currentHDC, winTextColor);
895
928
    SetBkColor (Nlm_currentHDC, winBkColor);
896
929
    SetBkMode (Nlm_currentHDC, TRANSPARENT);
1299
1332
}
1300
1333
 
1301
1334
 
 
1335
#ifdef WIN_X
 
1336
#define COLOR_HASH(lrgb) (lrgb % 251)  /* 251 is the largest prime less than 256 */
 
1337
#define RGB_2_LRGB(red, green, blue) ((red) | (green << 8) | (blue << 16))
 
1338
#define LRGB_RED(lrgb)   ((lrgb) & 0xFF)
 
1339
#define LRGB_GREEN(lrgb) ((lrgb >> 8) & 0xFF)
 
1340
#define LRGB_BLUE(lrgb)  (((lrgb >> 16) & 0xFF)
 
1341
 
 
1342
/* note: without a lock, the same color may appear multiple times in the hash table (not the end of the world) */
 
1343
typedef struct nlm_colorHashBucket {
 
1344
  Nlm_Uint4  lrgb;
 
1345
  XColor xcolor;
 
1346
  struct nlm_colorHashBucket PNTR next;
 
1347
} Nlm_ColorHashBucket, PNTR Nlm_ColorHashBucketPtr;
 
1348
#endif
 
1349
 
1302
1350
extern void Nlm_SelectColor (Nlm_Uint1 red, Nlm_Uint1 green, Nlm_Uint1 blue)
1303
1351
{
1304
1352
#ifdef WIN_MAC
1335
1383
#endif
1336
1384
#ifdef WIN_X
1337
1385
  XColor xcolor;
 
1386
  Nlm_Uint1  hash;
 
1387
  Nlm_Uint4  lrgb;
 
1388
  Nlm_ColorHashBucketPtr CHBP, tail;
 
1389
  static Nlm_ColorHashBucketPtr ColorHashBuckets [256] = {NULL};
 
1390
 
 
1391
  lrgb = RGB_2_LRGB (red, green, blue);
 
1392
  hash = COLOR_HASH (lrgb);
 
1393
  tail = NULL;
 
1394
  if (ColorHashBuckets [hash] != NULL) {
 
1395
    for (CHBP = ColorHashBuckets [hash]; CHBP != NULL; CHBP = CHBP->next) {
 
1396
      if (CHBP->lrgb == lrgb) {
 
1397
        xcolor = CHBP->xcolor;
 
1398
        Nlm_ChooseColor (xcolor.pixel);
 
1399
        return;
 
1400
      }
 
1401
      tail = CHBP;
 
1402
    }
 
1403
  }
 
1404
 
1338
1405
  Nlm_XAllocColor(&xcolor, Nlm_VibrantDefaultColormap(), red, green, blue);
1339
 
  Nlm_ChooseColor( xcolor.pixel );
 
1406
  Nlm_ChooseColor(xcolor.pixel );
 
1407
 
 
1408
  if (tail != NULL) {
 
1409
    tail->next = MemNew (sizeof (Nlm_ColorHashBucket));
 
1410
    tail = tail->next;
 
1411
  } else {
 
1412
    tail = ColorHashBuckets [hash] = MemNew (sizeof (Nlm_ColorHashBucket));
 
1413
  }
 
1414
  if (tail != NULL) {
 
1415
    tail->lrgb = lrgb;
 
1416
    tail->xcolor = xcolor;
 
1417
  }  
 
1418
  
1340
1419
#endif
1341
1420
#ifdef WIN_GIF
1342
1421
  Nlm_curGIFColor = (int)Nlm_GetColorRGB ( red, green, blue );
1343
1422
#endif
1344
1423
}
1345
1424
 
 
1425
#ifdef WIN_X
 
1426
#undef COLOR_HASH
 
1427
#undef RGB_2_LRGB
 
1428
#undef LRGB_RED
 
1429
#undef LRGB_GREEN
 
1430
#undef LRGB_BLUE
 
1431
#endif
 
1432
 
1346
1433
 
1347
1434
extern Nlm_Uint4 Nlm_GetColorRGB (Nlm_Uint1 red, Nlm_Uint1 green,
1348
1435
                                  Nlm_Uint1 blue)
4226
4313
  unsigned int  srcX;
4227
4314
  unsigned int  srcY;
4228
4315
 
 
4316
  if (r != NULL) {
 
4317
    if (ABS (dy) >= ABS (r->bottom - r->top) || ABS (dx) >= ABS (r->right - r->left)) {
 
4318
      Nlm_InvalRect (r);
 
4319
      return;
 
4320
    }
 
4321
  }
4229
4322
  if (r != NULL && Nlm_currentXDisplay != NULL &&
4230
4323
      Nlm_currentXGC != NULL && Nlm_currentXWindow != 0) {
4231
4324
    height = ABS (r->bottom - r->top) - ABS (dy);
6233
6326
  pixelMap->bounds.left = 0;
6234
6327
  pixelMap->bounds.top = 0;
6235
6328
  pixelMap->cmpSize = 8;
6236
 
// 2001-03-22:  Joshua Juran
6237
 
// Evidently these two members don't exist in Carbon.  So don't set them.
 
6329
  /* 2001-03-22:  Joshua Juran */
 
6330
  /* Evidently these two members don't exist in Carbon.  So don't set them. */
6238
6331
#if !TARGET_API_MAC_CARBON
6239
6332
  pixelMap->planeBytes = 0;
6240
6333
  pixelMap->pmReserved = 0;
6337
6430
 
6338
6431
  Nlm_updateRgn = (Nlm_RegioN) (NewRgn ());
6339
6432
  SetRectRgn ((Nlm_RgnTool) Nlm_updateRgn, -32768, -32768, 32767, 32767);
6340
 
  //HLock ((Handle) Nlm_updateRgn);
 
6433
  /* HLock ((Handle) Nlm_updateRgn); */
6341
6434
  GetRegionBounds(Nlm_updateRgn, &bounds);
6342
6435
  Local__RectToolToRecT (&bounds, &Nlm_updateRect);
6343
 
  //HUnlock ((Handle) Nlm_updateRgn);
 
6436
  /* HUnlock ((Handle) Nlm_updateRgn); */
6344
6437
 
6345
6438
  Nlm_fontList = NULL;
6346
6439
  Nlm_fontInUse = NULL;
6352
6445
  Nlm_PtoCstr ( tmpFontName );
6353
6446
  Nlm_StringNCpy_0 (fsp.name, tmpFontName, FONT_NAME_SIZE - 1);
6354
6447
  fsp.name[FONT_NAME_SIZE - 1] = 0;
6355
 
  fsp.size = 12;
6356
 
  Nlm_LoadFontData (Nlm_systemFont, NULL, -1, &fsp, 0, 12, 0, NULL);
 
6448
  fsp.size = GetDefFontSize ();
 
6449
  Nlm_LoadFontData (Nlm_systemFont, NULL, -1, &fsp, 0, fsp.size, 0, NULL);
6357
6450
  Nlm_programFont = (Nlm_FonT) Nlm_HandNew (sizeof (Nlm_FontRec));
6358
6451
  /* esl: LoadFontData changed to work with new FontData format */
6359
6452
  Nlm_StrCpy (fsp.name, "Monaco");