diff options
author | csaba <csaba> | 2024-08-09 09:28:26 (GMT) |
---|---|---|
committer | csaba <csaba> | 2024-08-09 09:28:26 (GMT) |
commit | 4005b8a171b4c11f9c681bc4b29e03e9e4397151 (patch) | |
tree | 47ba4de27ffc2837d18f8cbbfcb0ce4413c0223a /win | |
parent | 54d140d9584a12bdee6df2bb413009375ac6c551 (diff) | |
parent | 81b42237844a5ea0b5ed45f4807a7cbffc0e9c57 (diff) | |
download | tk-4005b8a171b4c11f9c681bc4b29e03e9e4397151.zip tk-4005b8a171b4c11f9c681bc4b29e03e9e4397151.tar.gz tk-4005b8a171b4c11f9c681bc4b29e03e9e4397151.tar.bz2 |
Fix for ticket [f569b9410c]: Improve the look of the focus indicator on Windows.
Diffstat (limited to 'win')
-rw-r--r-- | win/tkWinButton.c | 20 | ||||
-rw-r--r-- | win/tkWinDraw.c | 11 | ||||
-rw-r--r-- | win/tkWinInt.h | 5 | ||||
-rw-r--r-- | win/ttkWinTheme.c | 30 |
4 files changed, 30 insertions, 36 deletions
diff --git a/win/tkWinButton.c b/win/tkWinButton.c index e0998b5..65cabdc 100644 --- a/win/tkWinButton.c +++ b/win/tkWinButton.c @@ -853,22 +853,16 @@ TkpDisplayButton( */ if (drawRing && butPtr->flags & GOT_FOCUS && butPtr->type != TYPE_LABEL) { - dc = TkWinGetDrawableDC(butPtr->display, pixmap, &state); if (butPtr->type == TYPE_BUTTON || !butPtr->indicatorOn) { - rect.top = butPtr->borderWidth + 1 + defaultWidth; - rect.left = rect.top; - rect.right = Tk_Width(tkwin) - rect.left; - rect.bottom = Tk_Height(tkwin) - rect.top; + int offset = butPtr->borderWidth + 1 + defaultWidth; + TkWinDrawDottedRect(butPtr->display, pixmap, gc->foreground, + offset, offset, + Tk_Width(tkwin) - 2*offset, Tk_Height(tkwin) - 2*offset); } else { - rect.top = y-1 + textYOffset; - rect.left = x-1 + textXOffset; - rect.right = x+butPtr->textWidth + 1 + textXOffset; - rect.bottom = y+butPtr->textHeight + 2 + textYOffset; + TkWinDrawDottedRect(butPtr->display, pixmap, gc->foreground, + x-1 + textXOffset, y-1 + textYOffset, + butPtr->textWidth + 2, butPtr->textHeight + 3); } - SetTextColor(dc, gc->foreground); - SetBkColor(dc, gc->background); - DrawFocusRect(dc, &rect); - TkWinReleaseDrawableDC(pixmap, dc, &state); } y += height/2; diff --git a/win/tkWinDraw.c b/win/tkWinDraw.c index 2b5382d..d1dd3c1 100644 --- a/win/tkWinDraw.c +++ b/win/tkWinDraw.c @@ -1507,7 +1507,9 @@ TkWinDrawDottedRect( Display *disp, /* Display containing the dotted rectangle. */ Drawable d, /* Where to draw the rectangle (typically a * pixmap for double buffering). */ - unsigned long pixel, /* color to use for drawing the rectangle. */ + long pixel, /* Color to use for drawing the rectangle. If + * pixel < 0 then the black color and the + * foreground mix mode R2_NOT are used. */ int x, int y, /* Coordinates of the top-left corner. */ int width, int height) /* Width & height, _including the border_. */ { @@ -1521,9 +1523,14 @@ TkWinDrawDottedRect( dc = TkWinGetDrawableDC(disp, d, &state); lb.lbStyle = BS_SOLID; - lb.lbColor = (COLORREF)pixel; + lb.lbColor = pixel < 0 ? : RGB(0, 0, 0) : (COLORREF)pixel; lb.lbHatch = 0; + if (pixel < 0) { + SetROP2(dc, R2_NOT); + SetBkMode(dc, TRANSPARENT); + } + pen = ExtCreatePen(PS_COSMETIC | PS_ALTERNATE, 1, &lb, 0, NULL); SelectObject(dc, pen); SelectObject(dc, GetStockObject(NULL_BRUSH)); diff --git a/win/tkWinInt.h b/win/tkWinInt.h index 3f363cd..93b98ca 100644 --- a/win/tkWinInt.h +++ b/win/tkWinInt.h @@ -230,9 +230,8 @@ MODULE_SCOPE int Winprint_Init(Tcl_Interp* interp); * The following is implemented in tkWinDraw.c and used in tkUtil.c */ -MODULE_SCOPE void TkWinDrawDottedRect (Display *disp, Drawable d, - unsigned long pixel, int x, int y, - int width, int height); +MODULE_SCOPE void TkWinDrawDottedRect(Display *disp, Drawable d, + long pixel, int x, int y, int width, int height); /* * Common routines used in Windows implementation diff --git a/win/ttkWinTheme.c b/win/ttkWinTheme.c index 72cd27a..11262cc 100644 --- a/win/ttkWinTheme.c +++ b/win/ttkWinTheme.c @@ -404,14 +404,16 @@ static void ButtonBorderElementDraw( DFC_BUTTON, /* classId */ DFCS_BUTTONPUSH | Ttk_StateTableLookup(pushbutton_statemap, state)); + TkWinReleaseDrawableDC(d, hdc, &dcState); + /* Draw focus ring: */ if (state & TTK_STATE_FOCUS) { short int borderWidth = 3; /* @@@ Use GetSystemMetrics?*/ - rc = BoxToRect(Ttk_PadBox(b, Ttk_UniformPadding(borderWidth))); - DrawFocusRect(hdc, &rc); + b = Ttk_PadBox(b, Ttk_UniformPadding(borderWidth)); + TkWinDrawDottedRect(Tk_Display(tkwin), d, -1, b.x, b.y, + b.width, b.height); } - TkWinReleaseDrawableDC(d, hdc, &dcState); } static const Ttk_ElementSpec ButtonBorderElementSpec = { @@ -424,7 +426,7 @@ static const Ttk_ElementSpec ButtonBorderElementSpec = { /*------------------------------------------------------------------------ * +++ Focus element. - * Draw dashed focus rectangle. + * Draw dotted focus rectangle. */ static void FocusElementSize( @@ -447,11 +449,8 @@ static void FocusElementDraw( Ttk_State state) { if (state & TTK_STATE_FOCUS) { - RECT rc = BoxToRect(b); - TkWinDCState dcState; - HDC hdc = TkWinGetDrawableDC(Tk_Display(tkwin), d, &dcState); - DrawFocusRect(hdc, &rc); - TkWinReleaseDrawableDC(d, hdc, &dcState); + TkWinDrawDottedRect(Tk_Display(tkwin), d, -1, b.x, b.y, + b.width, b.height); } } @@ -486,19 +485,14 @@ static void FillFocusElementDraw( Ttk_Box b, Ttk_State state) { - FillFocusElement *focus = (FillFocusElement *)elementRecord; - if (state & TTK_STATE_FOCUS) { - RECT rc = BoxToRect(b); - TkWinDCState dcState; + FillFocusElement *focus = (FillFocusElement *)elementRecord; XColor *fillColor = Tk_GetColorFromObj(tkwin, focus->fillColorObj); GC gc = Tk_GCForColor(fillColor, d); - HDC hdc; + XFillRectangle(Tk_Display(tkwin), d, gc, b.x, b.y, b.width, b.height); - XFillRectangle(Tk_Display(tkwin),d,gc, b.x,b.y,b.width,b.height); - hdc = TkWinGetDrawableDC(Tk_Display(tkwin), d, &dcState); - DrawFocusRect(hdc, &rc); - TkWinReleaseDrawableDC(d, hdc, &dcState); + TkWinDrawDottedRect(Tk_Display(tkwin), d, -1, b.x, b.y, + b.width, b.height); } } |