Tk Source Code

View Ticket
Login
Ticket UUID: 220534
Title: Implementation of XSetDashes for Windows
Type: Bug Version: final: 8.1.1
Submitter: welch Created on: 2000-10-31 23:45:52
Subsystem: 65. Generic Window Operations Assigned To: nobody
Priority: 2 Severity:
Status: Closed Last Modified: 2001-04-04 11:49:22
Resolution: Fixed Closed By: dgp
    Closed on: 2001-04-04 04:49:22
Description:
OriginalBugID: 2168 RFE
Version: 8.1.1
SubmitDate: '1999-06-03'
LastModified: '1999-12-13'
Severity: MED
Status: Released
Submitter: techsupp
ChangedBy: hobbs
OS: Windows NT
OSVersion: 4.0 SP3
Machine: X86
FixedDate: '1999-12-13'
FixedInVersion: 8.3b1


Name:

Jan Nijtmans


Comments:

This patch makes the XSetDashes function available for the mac

    as well, but there it only operates as a NOP.


DesiredBehavior:

This patch is extracted from the Dash-patch for 8.1.1,

    (to be released soon), but it is identical to version

    8.0.5 and 7.6p2. Slot 0 of the Xlib Stub-table is

    alread reserved for this function, the only thing

    missing is the implementation.


    This patch is created against 8.1.1, but it works

    unmodified for 8.0.x as well.


Patch:

*** generic/tkInt.decls.origWed May 26 07:11:33 1999

--- generic/tkInt.declsSat May 29 00:02:25 1999

***************

*** 1051,1060 ****


  # X functions for Windows


! # This slot is reserved for use by the dash patch:

! #  declare 0 win {

! #XSetDashes

! #  }

  declare 1 win {

      XModifierKeymap* XGetModifierMapping (Display* d)

  }

--- 1051,1061 ----


  # X functions for Windows


! declare 0 win {

!     void XSetDashes (Display* display, GC gc, int dash_offset,

!     _Xconst char* dash_list, int n)

! }

! 

  declare 1 win {

      XModifierKeymap* XGetModifierMapping (Display* d)

  }

***************

*** 1520,1529 ****


  # X functions for Mac


! # This slot is reserved for use by the dash patch:

! #  declare 0 win {

! #XSetDashes

! #  }


  declare 1 mac {

      XModifierKeymap* XGetModifierMapping (Display* d)

--- 1521,1530 ----


  # X functions for Mac


! declare 0 mac {

!     void XSetDashes (Display* display, GC gc, int dash_offset,

!     _Xconst char* dash_list, int n)

! }


  declare 1 mac {

      XModifierKeymap* XGetModifierMapping (Display* d)

*** win/tkWinDraw.c.origFri Apr 16 23:03:02 1999

--- win/tkWinDraw.cSat May 29 00:02:34 1999

***************

*** 125,130 ****

--- 125,131 ----

  static voidRenderObject _ANSI_ARGS_((HDC dc, GC gc,

      XPoint* points, int npoints, int mode, HPEN pen,

      WinDrawFunc func));

+ static HPENSetUpGraphicsPort _ANSI_ARGS_((GC gc));

  

  /*

   *----------------------------------------------------------------------

***************

*** 888,929 ****


      dc = TkWinGetDrawableDC(display, d, &state);


!     if (!tkpIsWin32s && (gc->line_width > 1)) {

! LOGBRUSH lb;

! DWORD style;

! 

! lb.lbStyle = BS_SOLID;

! lb.lbColor = gc->foreground;

! lb.lbHatch = 0;

! 

! style = PS_GEOMETRIC|PS_COSMETIC;

! switch (gc->cap_style) {

!     case CapNotLast:

!     case CapButt:

! style |= PS_ENDCAP_FLAT; 

! break;

!     case CapRound:

! style |= PS_ENDCAP_ROUND; 

! break;

!     default:

! style |= PS_ENDCAP_SQUARE; 

! break;

! }

! switch (gc->join_style) {

!     case JoinMiter: 

! style |= PS_JOIN_MITER; 

! break;

!     case JoinRound:

! style |= PS_JOIN_ROUND; 

! break;

!     default:

! style |= PS_JOIN_BEVEL; 

! break;

! }

! pen = ExtCreatePen(style, gc->line_width, &lb, 0, NULL);

!     } else {

! pen = CreatePen(PS_SOLID, gc->line_width, gc->foreground);

!     }

      RenderObject(dc, gc, points, npoints, mode, pen, Polyline);

      DeleteObject(pen);


--- 889,895 ----


      dc = TkWinGetDrawableDC(display, d, &state);


!     pen = SetUpGraphicsPort(gc);

      RenderObject(dc, gc, points, npoints, mode, pen, Polyline);

      DeleteObject(pen);


***************

*** 1009,1015 ****


      dc = TkWinGetDrawableDC(display, d, &state);


!     pen = CreatePen(PS_SOLID, gc->line_width, gc->foreground);

      oldPen = SelectObject(dc, pen);

      oldBrush = SelectObject(dc, GetStockObject(NULL_BRUSH));

      SetROP2(dc, tkpWinRopModes[gc->function]);

--- 975,981 ----


      dc = TkWinGetDrawableDC(display, d, &state);


!     pen = SetUpGraphicsPort(gc);

      oldPen = SelectObject(dc, pen);

      oldBrush = SelectObject(dc, GetStockObject(NULL_BRUSH));

      SetROP2(dc, tkpWinRopModes[gc->function]);

***************

*** 1171,1177 ****

       * difference in pixel definitions between X and Windows.

       */


!     pen = CreatePen(PS_SOLID, gc->line_width, gc->foreground);

      oldPen = SelectObject(dc, pen);

      if (!fill) {

  /*

--- 1137,1143 ----

       * difference in pixel definitions between X and Windows.

       */


!     pen = SetUpGraphicsPort(gc);

      oldPen = SelectObject(dc, pen);

      if (!fill) {

  /*

***************

*** 1193,1198 ****

--- 1159,1253 ----

      }

      DeleteObject(SelectObject(dc, oldPen));

      TkWinReleaseDrawableDC(d, dc, &state);

+ }

+ 

+ /*

+  *----------------------------------------------------------------------

+  *

+  * SetUpGraphicsPort --

+  *

+  *Set up the graphics port from the given GC.

+  *

+  * Results:

+  *None.

+  *

+  * Side effects:

+  *The current port is adjusted.

+  *

+  *----------------------------------------------------------------------

+  */

+ 

+ static HPEN

+ SetUpGraphicsPort(gc)

+     GC gc;

+ {

+     DWORD style;

+ 

+     if (gc->line_style == LineOnOffDash) {

+ unsigned char *p = (unsigned char *) &(gc->dashes);

+ /* pointer to the dash-list */

+ 

+ /*

+  * Below is a simple translation of serveral dash patterns

+  * to valid windows pen types. Far from complete,

+  * but I don't know how to do it better.

+  * Any ideas: <mailto:[email protected]>

+  */

+ 

+ if (p[1] && p[2]) {

+     if (!p[3] || p[4]) {

+ style = PS_DASHDOTDOT;/*-..*/

+     } else {

+ style = PS_DASHDOT;/*-.*/

+     }

+ } else {

+     if (p[0] > (4 * gc->line_width)) {

+ style = PS_DASH;/*-*/

+     } else {

+ style = PS_DOT;/*.*/

+     }

+ }

+     } else {

+ style = PS_SOLID;

+     }

+     if (tkpIsWin32s || (gc->line_width < 2)) {

+ if (gc->line_width > 1) {

+     style = PS_SOLID;

+ }

+ return CreatePen(style, gc->line_width, gc->foreground);

+     } else {

+ LOGBRUSH lb;

+ 

+ lb.lbStyle = BS_SOLID;

+ lb.lbColor = gc->foreground;

+ lb.lbHatch = 0;

+ 

+ style |= PS_GEOMETRIC;

+ switch (gc->cap_style) {

+     case CapNotLast:

+     case CapButt:

+ style |= PS_ENDCAP_FLAT; 

+ break;

+     case CapRound:

+ style |= PS_ENDCAP_ROUND; 

+ break;

+     default:

+ style |= PS_ENDCAP_SQUARE; 

+ break;

+ }

+ switch (gc->join_style) {

+     case JoinMiter: 

+ style |= PS_JOIN_MITER; 

+ break;

+     case JoinRound:

+ style |= PS_JOIN_ROUND; 

+ break;

+     default:

+ style |= PS_JOIN_BEVEL; 

+ break;

+ }

+ return ExtCreatePen(style, gc->line_width, &lb, 0, NULL);

+     }

  }

  

  /*

*** xlib/xgc.c.origFri Apr 16 23:03:05 1999

--- xlib/xgc.cSat May 29 00:02:34 1999

***************

*** 46,52 ****

  {

      GC gp;


!     gp = (XGCValues *)ckalloc(sizeof(XGCValues));

      if (!gp) {

  return None;

      }

--- 46,60 ----

  {

      GC gp;


! /*

!  * In order to have room for a dash list, MAX_DASH_LIST_SIZE extra chars are

!  * defined, which is invisible from the outside. The list is assumed to end

!  * with a 0-char, so this must be set explicitely during initialization.

!  */

! 

! #define MAX_DASH_LIST_SIZE 10

! 

!     gp = (XGCValues *)ckalloc(sizeof(XGCValues) + MAX_DASH_LIST_SIZE);

      if (!gp) {

  return None;

      }

***************

*** 73,78 ****

--- 81,87 ----

      gp->clip_y_origin = (mask & GCClipYOrigin)?values->clip_y_origin:0;

      gp->dash_offset = (mask & GCDashOffset)?values->dash_offset:0;

      gp->dashes = (mask & GCDashList)?values->dashes:4;

+     (&(gp->dashes))[1] = 0;


      if (mask & GCClipMask) {

  gp->clip_mask = (Pixmap)ckalloc(sizeof(TkpClipMask));

***************

*** 131,137 ****

      if (mask & GCClipYOrigin) { gc->clip_y_origin = values->clip_y_origin; }

      if (mask & GCClipMask) { XSetClipMask(d, gc, values->clip_mask); }

      if (mask & GCDashOffset) { gc->dash_offset = values->dash_offset; }

!     if (mask & GCDashList) { gc->dashes = values->dashes; }

  }

  

  /*

--- 140,146 ----

      if (mask & GCClipYOrigin) { gc->clip_y_origin = values->clip_y_origin; }

      if (mask & GCClipMask) { XSetClipMask(d, gc, values->clip_mask); }

      if (mask & GCDashOffset) { gc->dash_offset = values->dash_offset; }

!     if (mask & GCDashList) { gc->dashes = values->dashes; (&(gc->dashes))[1] = 0;}

  }

  

  /*

***************

*** 198,203 ****

--- 207,230 ----

  }


  void

+ XSetDashes(display, gc, dash_offset, dash_list, n)

+     Display* display;

+     GC gc;

+     int dash_offset;

+     _Xconst char* dash_list;

+     int n;

+ {

+     char *p = &(gc->dashes);

+ 

+     gc->dash_offset = dash_offset;

+     if (n > MAX_DASH_LIST_SIZE) n = MAX_DASH_LIST_SIZE;

+     while (n-- > 0) {

+ *p++ = *dash_list++;

+     }

+     *p = 0;

+ }

+ 

+ void

  XSetFunction(display, gc, function)

      Display *display;

      GC gc;


PatchFiles:

tkInt.decls tkWinDraw.c xgc.c




in 8.3b1. 
-- 12/13/1999 hobbs