Index: .fossil-settings/crlf-glob ================================================================== --- .fossil-settings/crlf-glob +++ .fossil-settings/crlf-glob @@ -1,5 +1,2 @@ -win/buildall.vc.bat -win/makefile.vc -win/mkd.bat -win/rmd.bat -win/rules.vc +win/*.bat +win/*.vc Index: .fossil-settings/crnl-glob ================================================================== --- .fossil-settings/crnl-glob +++ .fossil-settings/crnl-glob @@ -1,5 +1,2 @@ -win/buildall.vc.bat -win/makefile.vc -win/mkd.bat -win/rmd.bat -win/rules.vc +win/*.bat +win/*.vc Index: .fossil-settings/ignore-glob ================================================================== --- .fossil-settings/ignore-glob +++ .fossil-settings/ignore-glob @@ -17,8 +17,11 @@ */tkConfig.sh */wish* */tktest* */versions.vc doc/man.macros -win/Debug_VC* -win/Release_VC* +win/Debug* +win/Release* +win/nmhlp-out.txt +win/nmakehlp.out unix/tk.pc +html/* Index: README ================================================================== --- README +++ README @@ -1,7 +1,7 @@ README: Tk - This is the Tk 8.6.7 source distribution. + This is the Tk 8.6.8 source distribution. http://sourceforge.net/projects/tcl/files/Tcl/ You can get any source release of Tk from the URL above. 1. Introduction --------------- Index: changes ================================================================== --- changes +++ changes @@ -1313,11 +1313,11 @@ 2/19/94 (bug fix) Modified tkBind.c to save and restore the interpreter's result across the execution of binding scripts. Otherwise if an event triggers in the middle of some other script (e.g. a destroy event during window creation, because there was an error in the creation command), -the intepreter's result gets lost. +the interpreter's result gets lost. 2/19/94 (bug fix) Fixed bug in dealing with results of sent command that could cause them to get lost in some situations. 2/21/94 (bug fix) Don't let user close a dialog window created by @@ -7368,11 +7368,11 @@ 2017-03-06 (bug)[6b3644] Fix -alpha for 16-bit color PNG (LemonMan) 2017-03-11 (bug)[775273] artifacts on Ubuntu 16.10+ (nemethi) -2n017-03-26 (TIP 464) Win multimedia keys support (fassel,vogel) +2017-03-26 (TIP 464) Win multimedia keys support (fassel,vogel) 2017-03-29 (bug)[28a3c3] test BTree memleaks plugged (anonymous) 2017-04-06 (bug)[db8c54] Stop freed mem access in warp pointer callback (porter) @@ -7413,5 +7413,85 @@ 2017-08-08 (bug)[28d0b8] Follow ICCCM advice on X selection protocol (donchenko) 2017-08-08 (bug)[4966ca] Scidb race in notebook tab selection (cramer) --- Released 8.6.7, August 9, 2017 --- http://core.tcl.tk/tk/ for details + +2017-08-24 (bug)[f1a3ca] Memory leak in [text] B-tree (edhume3) + +2017-08-24 (bug)[ee40fd] Report [console] init errors (the) + +2017-08-24 (bug)[3295446] Improve history visibility in [console] (goth) + +2017-08-24 (bug) canvas closed polylines fully honor -joinstyle (vogel) + +2017-08-24 (bug)[cc42cc] out of mem crash in tests imgPhoto-18.* (vogel) + +2017-09-16 (bug)[3406785] fix coords rounding when drawing canvas items (vogel) + +2017-09-24 (bug)[8277e1] linux fontchooser sync with available fonts (vogel) + +2017-09-24 (bug)[5239fd] Segfault copying a photo image to itself (bachmann) + +2017-09-24 (bug)[514ff6] canvas rotated text overlap detection (vogel) + +2017-09-24 (bug)[1e0db2] canvas rchars artifacts (bruchie,vogel) + +2017-10-07 (bug)[d9fdfa] display of Long non-wrapped lines in text (cramer) + +2017-10-07 (bug)[dd9667] text anchor not set (vogel) + +2017-10-11 (bugs) memleaks and other changes for macOS 10.13 support (culler) + +2017-10-11 (bug)[111de2] macOS colorspace improvement (walzer,culler) + +2017-10-13 (bug) macOS scrolling issues (culler) + +2017-10-15 (bug) clipping regions in scrolling and drawing on macOS (culler) + +2017-10-15 (bug) macOS redraw artifacts (culler) + +2017-10-22 (bug)[bb6b40] ::tk::AmpMenuArgs and 'entryconf' (vogel) + +2017-10-22 (bug)[55b95f] Crash [scale] with a bignum value (vogel) + +2017-10-28 (bug)[ce62c8] text-37.1 fails (vogel) + +2017-11-03 (bug)[0ef1c5] OS X - tests menu-22.[345] hang (vogel) + +2017-11-04 (bug)[c8c52b] repair OBOE in menu.test on macOS (vogel) + +2017-11-11 (feature) Implement [wm_iconphoto] on macOS (walzer) + +2017-11-11 (bug) display of embedded toplevels (culler) + +2017-11-19 (bug)[73ba07] Correct property type for MULTIPLE conversion (dpb) + +2017-11-20 (bug) Memory leak in tkImgPhoto.c. (werner) + +2017-11-21 (bug) Defeat zombie toplevels (culler) + +2017-11-25 (bug) macOS resposive menu bar for command line apps (culler) + +2017-11-25 (bug)[1c659e] support png from mac screenshots (vogel) + +2017-11-25 (bug)[de4af1] macOS file selector "all types" setting (culler) + +2017-11-26 (bug) [wm withdraw] on Window and Dock menus (walzer) + +2017-11-27 (feature) Drop support for macOS 10.5 (culler) + +2017-11-30 (bug)[164c1b] Fixes [raise] on macOS (culler) + +2017-11-30 (bug)[13d63d] macOS support of menu -postcommand (culler) + +2017-12-05 (bug) enable custom icon display on macOS (walzer) + +2017-12-05 (bug)[1088805,0feb63] macOS bind failures (culler) + +2017-12-05 (bug)[3382424] Suppress noisy messages on macOS (culler) + +2017-12-08 (new)[TIP 477] nmake build system reform (nadkarni) + +2017-12-18 (bug)[b77626] Make [tk busy -cursor] silent no-op on macOS (vogel) + +--- Released 8.6.8, December 22, 2017 --- http://core.tcl.tk/tk/ for details Index: doc/bind.n ================================================================== --- doc/bind.n +++ doc/bind.n @@ -17,13 +17,14 @@ .BE .SH "INTRODUCTION" .PP The \fBbind\fR command associates Tcl scripts with X events. If all three arguments are specified, \fBbind\fR will -arrange for \fIscript\fR (a Tcl script) to be evaluated whenever -the event(s) given by \fIsequence\fR occur in the window(s) -identified by \fItag\fR. +arrange for \fIscript\fR (a Tcl script called the +.QW "binding script") +to be evaluated whenever the event(s) given by \fIsequence\fR +occur in the window(s) identified by \fItag\fR. If \fIscript\fR is prefixed with a .QW + , then it is appended to any existing binding for \fIsequence\fR; otherwise \fIscript\fR replaces any existing binding. @@ -385,11 +386,12 @@ \fItype\fR field may be omitted; it will default to \fBKeyPress\fR. For example, \fB\fR is equivalent to \fB\fR. .SH "BINDING SCRIPTS AND SUBSTITUTIONS" .PP -The \fIscript\fR argument to \fBbind\fR is a Tcl script, +The \fIscript\fR argument to \fBbind\fR is a Tcl script, called the +.QW "binding script", which will be executed whenever the given event sequence occurs. \fICommand\fR will be executed in the same interpreter that the \fBbind\fR command was executed in, and it will run at global level (only global variables will be accessible). If \fIscript\fR contains @@ -604,16 +606,24 @@ a particular window or to associate additional binding tags with the window. .PP The \fBcontinue\fR and \fBbreak\fR commands may be used inside a binding script to control the processing of matching scripts. -If \fBcontinue\fR is invoked, then the current binding script -is terminated but Tk will continue processing binding scripts -associated with other \fItag\fR's. +If \fBcontinue\fR is invoked within a binding script, then this +binding script, including all other +.QW + +appended scripts, is terminated but Tk will continue processing +binding scripts associated with other \fItag\fR's. If the \fBbreak\fR command is invoked within a binding script, then that script terminates and no other scripts will be invoked for the event. +.PP +Within a script called from the binding script, \fBreturn\fR +\fB-code ok\fR may be used to continue processing (including +.QW + +appended scripts), or \fBreturn\fR \fB-code break\fR may be used to +stop processing all other binding scripts. .PP If more than one binding matches a particular event and they have the same \fItag\fR, then the most specific binding is chosen and its script is evaluated. The following tests are applied, in order, to determine which of Index: doc/busy.n ================================================================== --- doc/busy.n +++ doc/busy.n @@ -26,11 +26,11 @@ .TH busy n "" Tk "Tk Built-In Commands" .so man.macros .BS '\" Note: do not modify the .SH NAME line immediately below! .SH NAME -busy \- confine pointer and keyboard events to a window sub-tree +busy \- confine pointer events to a window sub-tree .SH SYNOPSIS \fBtk busy\fR \fIwindow \fR?\fIoptions\fR? .sp \fBtk busy hold\fR \fIwindow \fR?\fIoptions\fR? .sp @@ -42,13 +42,14 @@ .sp \fBtk busy status \fIwindow\fR .BE .SH DESCRIPTION .PP -The \fBtk busy\fR command provides a simple means to block keyboard, button, -and pointer events from Tk widgets, while overriding the widget's cursor with -a configurable busy cursor. +The \fBtk busy\fR command provides a simple means to block pointer events from +Tk widgets, while overriding the widget's cursor with a configurable busy +cursor. Note this command does not prevent keyboard events from being sent to +the widgets made busy. .SH INTRODUCTION .PP There are many times in applications where you want to temporarily restrict what actions the user can take. For example, an application could have a .QW Run @@ -66,12 +67,12 @@ etc.\0are ignored by the widget. You can set a special cursor (like a watch) that overrides the widget's normal cursor, providing feedback that the application (widget) is temporarily busy. .PP When a widget is made busy, the widget and all of its descendants will ignore -events. It's easy to make an entire panel of widgets busy. You can simply make -the toplevel widget (such as +pointer events. It's easy to make an entire panel of widgets busy. You can +simply make the toplevel widget (such as .QW . ) busy. This is easier and far much more efficient than recursively traversing the widget hierarchy, disabling each widget and re-configuring its cursor. .PP Often, the \fBtk busy\fR command can be used instead of Tk's \fBgrab\fR @@ -238,24 +239,31 @@ widgets they cover. Please note this if you are tracking Enter/Leave events in widgets. .SS "KEYBOARD EVENTS" .PP When a widget is made busy, the widget is prevented from gaining the keyboard -focus by the busy window. But if the widget already had focus, it still may -received keyboard events. To prevent this, you must move focus to another -window. +focus by a user clicking on it by the busy window. But if the widget already had +focus, it still may receive keyboard events. The widget can also still receive +focus through keyboard traversal. To prevent this, you must move +focus to another window and make sure the focus can not go back to the widgets +made busy (e.g. but restricting focus to a cancel button). .PP .CS +pack [frame .frame] +pack [text .frame.text] \fBtk busy\fR hold .frame -label .dummy -focus .dummy +pack [button .cancel -text "Cancel" -command exit] +focus .cancel +bind .cancel {break} +bind .cancel {break} update .CE .PP The above example moves the focus from .frame immediately after invoking the \fBhold\fR so that no keyboard events will be sent to \fB.frame\fR or any of -its descendants. +its descendants. It also makes sure it's not possible to leave button +\fB.cancel\fR using the keyboard. .SH PORTABILITY .PP Note that the \fBtk busy\fR command does not currently have any effect on OSX when Tk is built using Aqua support. .SH "SEE ALSO" Index: doc/canvas.n ================================================================== --- doc/canvas.n +++ doc/canvas.n @@ -655,10 +655,24 @@ Note: the insertion cursor is only displayed in an item if that item currently has the keyboard focus (see the \fBfocus\fR widget command, above), but the cursor position may be set even when the item does not have the focus. This command returns an empty string. +.TP +\fIpathName \fBimage \fIimagename\fR ?\fIsubsample\fR? ?\fIzoom\fR? +. +Draw the canvas into the Tk photo image named \fIimagename\fR. If a \fB-scrollregion\fR +has been defined then this will be the boundaries of the canvas region drawn and the +final size of the photo image. Otherwise the widget width and height with an origin +of 0,0 will be the size of the canvas region drawn and the final size of the photo +image. Optionally an integer \fIsubsample\fR factor may be given and the photo image +will be reduced in size. In addition to the \fIsubsample\fR an integer \fIzoom\fR +factor can also be given and the photo image will be enlarged. The image background +will be filled with the canvas background colour. The canvas widget does not need to +be mapped for this widget command to work, but at least one of it's ancestors must be +mapped. +This command returns an empty string. .TP \fIpathName \fBimove \fItagOrId index x y\fR .VS 8.6 This command causes the \fIindex\fR'th coordinate of each of the items indicated by \fItagOrId\fR to be relocated to the location (\fIx\fR,\fIy\fR). Index: doc/grid.n ================================================================== --- doc/grid.n +++ doc/grid.n @@ -158,11 +158,12 @@ \fB\-row \fIn\fR . Insert the slave so that it occupies the \fIn\fRth row in the grid. Row numbers start with 0. If this option is not supplied, then the slave is arranged on the same row as the previous slave specified on this -call to \fBgrid\fR, or the first unoccupied row if this is the first slave. +call to \fBgrid\fR, or the next row after the highest occupied row +if this is the first slave. .TP \fB\-rowspan \fIn\fR . Insert the slave so that it occupies \fIn\fR rows in the grid. The default is one row. If the next \fBgrid\fR command contains Index: doc/radiobutton.n ================================================================== --- doc/radiobutton.n +++ doc/radiobutton.n @@ -39,20 +39,10 @@ .OP \-indicatoron indicatorOn IndicatorOn Specifies whether or not the indicator should be drawn. Must be a proper boolean value. If false, the \fB\-relief\fR option is ignored and the widget's relief is always sunken if the widget is selected and raised otherwise. -.OP \-selectcolor selectColor Background -Specifies a background color to use when the button is selected. -If \fB\-indicatoron\fR is true then the color applies to the indicator. -Under Windows, this color is used as the background for the indicator -regardless of the select state. -If \fB\-indicatoron\fR is false, this color is used as the background -for the entire widget, in place of \fB\-background\fR or \fB\-activeBackground\fR, -whenever the widget is selected. -If specified as an empty string then no special color is used for -displaying when the widget is selected. .OP \-offrelief offRelief OffRelief Specifies the relief for the checkbutton when the indicator is not drawn and the checkbutton is off. The default value is .QW raised . By setting this option to @@ -69,10 +59,20 @@ mouse cursor is over the widget. This option can be used to make toolbar buttons, by configuring \fB\-relief flat \-overrelief raised\fR. If the value of this option is the empty string, then no alternative relief is used when the mouse cursor is over the radiobutton. The empty string is the default value. +.OP \-selectcolor selectColor Background +Specifies a background color to use when the button is selected. +If \fB\-indicatoron\fR is true then the color applies to the indicator. +Under Windows, this color is used as the background for the indicator +regardless of the select state. +If \fB\-indicatoron\fR is false, this color is used as the background +for the entire widget, in place of \fB\-background\fR or \fB\-activeBackground\fR, +whenever the widget is selected. +If specified as an empty string then no special color is used for +displaying when the widget is selected. .OP \-selectimage selectImage SelectImage Specifies an image to display (in place of the \fB\-image\fR option) when the radiobutton is selected. This option is ignored unless the \fB\-image\fR option has been specified. Index: doc/raise.n ================================================================== --- doc/raise.n +++ doc/raise.n @@ -29,10 +29,13 @@ this could end up either raising or lowering \fIwindow\fR. .PP All \fBtoplevel\fR windows may be restacked with respect to each other, whatever their relative path names, but the window manager is not obligated to strictly honor requests to restack. +.PP +On macOS raising an iconified \fBtoplevel\fR window causes it to be +deiconified. .SH EXAMPLE .PP Make a button appear to be in a sibling frame that was created after it. This is is often necessary when building GUIs in the style where you create your activity widgets first before laying them out on the Index: doc/scale.n ================================================================== --- doc/scale.n +++ doc/scale.n @@ -89,14 +89,14 @@ value of the variable changes, the scale will update to reflect this value. Whenever the scale is manipulated interactively, the variable will be modified to reflect the scale's new value. .OP \-width width Width -Specifies the desired narrow dimension of the trough in screen units +Specifies the desired narrow dimension of the scale in screen units (i.e. any of the forms acceptable to \fBTk_GetPixels\fR). -For vertical scales this is the trough's width; for horizontal scales -this is the trough's height. +For vertical scales this is the scale's width; for horizontal scales +this is the scale's height. .BE .SH DESCRIPTION .PP The \fBscale\fR command creates a new window (given by the \fIpathName\fR argument) and makes it into a scale widget. Index: doc/selection.n ================================================================== --- doc/selection.n +++ doc/selection.n @@ -138,10 +138,30 @@ that it has lost the selection. If \fIcommand\fR is specified, it is a Tcl script to execute when some other window claims ownership of the selection away from \fIwindow\fR. \fISelection\fR defaults to PRIMARY. .RE +.SH WIDGET FACILITIES +.PP +The \fBtext\fR, \fBentry\fR, \fBttk::entry\fR, \fBlistbox\fR, \fBspinbox\fR and \fBttk::spinbox\fR widgets have the option \fB\-exportselection\fR. If a widget has this option set to boolean \fBtrue\fR, then (in an unsafe interpreter) a selection made in the widget is automatically written to the \fBPRIMARY\fR selection. +.PP +A GUI event, for example \fB<>\fR, can copy the \fBPRIMARY\fR selection to certain widgets. This copy is implemented by a widget binding to the event. The binding script makes appropriate calls to the \fBselection\fR command. +.PP +.SH PORTABILITY ISSUES +.PP +On X11, the \fBPRIMARY\fR selection is a system-wide feature of the X server, allowing communication between different processes that are X11 clients. +.PP +On Windows, the \fBPRIMARY\fR selection is not provided by the system, but only by Tk, and so it is shared only between windows of a master interpreter and its unsafe slave interpreters. It is not shared between interpreters in different processes or different threads. Each master interpreter has a separate \fBPRIMARY\fR selection that is shared only with its unsafe slaves. +.PP +.SH SECURITY +.PP +A safe interpreter cannot read from the \fBPRIMARY\fR selection because its \fBselection\fR command is hidden. For this reason the \fBPRIMARY\fR selection cannot be written to the Tk widgets of a safe interpreter. +.PP +A Tk widget can have its option \fB\-exportselection\fR set to boolean \fBtrue\fR, but in a safe interpreter this option has no effect: writing from the widget to the \fBPRIMARY\fR selection is disabled. +.PP +These are security features. A safe interpreter may run untrusted code, and it is a security risk if this untrusted code can read or write the \fBPRIMARY\fR selection used by other interpreters. +.PP .SH EXAMPLES .PP On X11 platforms, one of the standard selections available is the \fBSECONDARY\fR selection. Hardly anything uses it, but here is how to read it using Tk: Index: doc/text.n ================================================================== --- doc/text.n +++ doc/text.n @@ -535,11 +535,11 @@ character of that display line. .TP \fB\-rmargincolor \fIcolor\fR . \fIColor\fR specifies the background color to use in regions that do not -contain characters because they are indented by \fB\-rmargin1\fR. It may +contain characters because they are indented by \fB\-rmargin\fR. It may have any of the forms accepted by \fBTk_GetColor\fR. If \fIcolor\fR has not been specified, or if it is specified as an empty string, then the color used is specified by the \fB-background\fR tag option (or, if this is also unspecified, by the \fB-background\fR widget option). .TP Index: doc/ttk_button.n ================================================================== --- doc/ttk_button.n +++ doc/ttk_button.n @@ -37,17 +37,10 @@ .RS .PP Depending on the theme, the default button may be displayed with an extra highlight ring, or with a different border color. .RE -.OP \-width width Width -If greater than zero, specifies how much space, in character widths, -to allocate for the text label. -If less than zero, specifies a minimum width. -If zero or unspecified, the natural width of the text label is used. -Note that some themes may specify a non-zero \fB\-width\fR -in the style. .\" Not documented -- may go away .\" .OP \-padding padding Padding .\" .OP \-foreground foreground Foreground .\" .OP \-font font Font .\" .OP \-anchor anchor Anchor @@ -62,19 +55,12 @@ Invokes the command associated with the button. .SH "STANDARD STYLES" .PP \fBTtk::button\fR widgets support the \fBToolbutton\fR style in all standard themes, which is useful for creating widgets for toolbars. -.SH "COMPATIBILITY OPTIONS" -.OP \-state state State -May be set to \fBnormal\fR or \fBdisabled\fR to control the -\fBdisabled\fR state bit. This is a -.QW write-only -option: setting it changes the widget state, but the \fBstate\fR -widget command does not affect the state option. .SH "SEE ALSO" ttk::widget(n), button(n) .SH "KEYWORDS" widget, button, default, command '\" Local Variables: '\" mode: nroff '\" End: Index: doc/ttk_label.n ================================================================== --- doc/ttk_label.n +++ doc/ttk_label.n @@ -17,11 +17,11 @@ A \fBttk::label\fR widget displays a textual label and/or image. The label may be linked to a Tcl variable to automatically change the displayed text. .SO ttk_widget \-class \-compound \-cursor -\-image \-padding \-style \-takefocus +\-image \-padding \-state \-style \-takefocus \-text \-textvariable \-underline \-width .SE .SH "WIDGET-SPECIFIC OPTIONS" .OP \-anchor anchor Anchor Index: doc/ttk_panedwindow.n ================================================================== --- doc/ttk_panedwindow.n +++ doc/ttk_panedwindow.n @@ -104,10 +104,18 @@ .\" Full story: "total size" is either the -height (resp -width), .\" or the actual window height (resp actual window width), .\" depending on which changed most recently. Returns the new position of sash number \fIindex\fR. .\" Full story: new position may be different than the requested position. +.PP +The panedwindow widget also supports the following generic \fBttk::widget\fR +widget subcommands (see \fIttk::widget(n)\fR for details): +.DS +.ta 5.5c 11c +\fBcget\fR \fBconfigure\fR +\fBinstate\fR \fBstate\fR +.DE .SH "VIRTUAL EVENTS" .PP The panedwindow widget generates an \fB<>\fR virtual event on LeaveNotify/NotifyInferior events, because Tk does not execute binding scripts for events when the pointer crosses from a parent to a child. The Index: doc/ttk_progressbar.n ================================================================== --- doc/ttk_progressbar.n +++ doc/ttk_progressbar.n @@ -22,21 +22,28 @@ .SO ttk_widget \-class \-cursor \-takefocus \-style .SE .SH "WIDGET-SPECIFIC OPTIONS" -.OP \-orient orient Orient -One of \fBhorizontal\fR or \fBvertical\fR. -Specifies the orientation of the progress bar. .OP \-length length Length Specifies the length of the long axis of the progress bar (width if horizontal, height if vertical). -.OP \-mode mode Mode -One of \fBdeterminate\fR or \fBindeterminate\fR. .OP \-maximum maximum Maximum A floating point number specifying the maximum \fB\-value\fR. Defaults to 100. +.OP \-mode mode Mode +One of \fBdeterminate\fR or \fBindeterminate\fR. +.OP \-orient orient Orient +One of \fBhorizontal\fR or \fBvertical\fR. +Specifies the orientation of the progress bar. +.OP \-phase phase Phase +Read-only option. +The widget periodically increments the value of this option +whenever the \fB\-value\fR is greater than 0 and, +in \fIdeterminate\fR mode, less than \fB\-maximum\fR. +This option may be used by the current theme +to provide additional animation effects. .OP \-value value Value The current value of the progress bar. In \fIdeterminate\fR mode, this represents the amount of work completed. In \fIindeterminate\fR mode, it is interpreted modulo \fB\-maximum\fR; that is, the progress bar completes one @@ -45,17 +52,10 @@ .OP \-variable variable Variable The name of a global Tcl variable which is linked to the \fB\-value\fR. If specified, the \fB\-value\fR of the progress bar is automatically set to the value of the variable whenever the latter is modified. -.OP \-phase phase Phase -Read-only option. -The widget periodically increments the value of this option -whenever the \fB\-value\fR is greater than 0 and, -in \fIdeterminate\fR mode, less than \fB\-maximum\fR. -This option may be used by the current theme -to provide additional animation effects. .SH "WIDGET COMMAND" .PP .TP \fIpathName \fBcget \fIoption\fR Returns the current value of the specified \fIoption\fR; see \fIttk::widget(n)\fR. Index: doc/ttk_separator.n ================================================================== --- doc/ttk_separator.n +++ doc/ttk_separator.n @@ -15,11 +15,11 @@ .SH DESCRIPTION .PP A \fBttk::separator\fR widget displays a horizontal or vertical separator bar. .SO ttk_widget -\-class \-cursor \-state +\-class \-cursor \-style \-takefocus .SE .SH "WIDGET-SPECIFIC OPTIONS" .OP \-orient orient Orient One of \fBhorizontal\fR or \fBvertical\fR. @@ -27,12 +27,13 @@ .SH "WIDGET COMMAND" .PP Separator widgets support the standard \fBcget\fR, \fBconfigure\fR, \fBidentify\fR, \fBinstate\fR, and \fBstate\fR methods. No other widget methods are used. +.PP .SH "SEE ALSO" ttk::widget(n) .SH "KEYWORDS" widget, separator '\" Local Variables: '\" mode: nroff '\" End: Index: doc/ttk_sizegrip.n ================================================================== --- doc/ttk_sizegrip.n +++ doc/ttk_sizegrip.n @@ -16,11 +16,11 @@ .PP A \fBttk::sizegrip\fR widget (also known as a \fIgrow box\fR) allows the user to resize the containing toplevel window by pressing and dragging the grip. .SO ttk_widget -\-class \-cursor \-state +\-class \-cursor \-style \-takefocus .SE .SH "WIDGET COMMAND" .PP Sizegrip widgets support the standard Index: doc/ttk_spinbox.n ================================================================== --- doc/ttk_spinbox.n +++ doc/ttk_spinbox.n @@ -19,44 +19,44 @@ to select among a set of values. The widget implements all the features of the \fBttk::entry\fR widget including support of the \fB\-textvariable\fR option to link the value displayed by the widget to a Tcl variable. .SO ttk_widget -\-class \-cursor \-style +\-class \-cursor \-state \-style \-takefocus \-xscrollcommand .SE .SO ttk_entry \-validate \-validatecommand .SE .SH "WIDGET-SPECIFIC OPTIONS" +.OP \-command command Command +Specifies a Tcl command to be invoked whenever a spinbutton is invoked. +.OP \-format format Format +Specifies an alternate format to use when setting the string value +when using the \fB\-from\fR and \fB\-to\fR range. +This must be a format specifier of the form \fB%.f\fR, +as it will format a floating-point number. .OP \-from from From A floating\-point value specifying the lowest value for the spinbox. This is used in conjunction with \fB\-to\fR and \fB\-increment\fR to set a numerical range. -.OP \-to to To -A floating\-point value specifying the highest permissible value for the -widget. See also \fB\-from\fR and \fB\-increment\fR. -range. .OP \-increment increment Increment A floating\-point value specifying the change in value to be applied each time one of the widget spin buttons is pressed. The up button applies a positive increment, the down button applies a negative increment. +.OP \-to to To +A floating\-point value specifying the highest permissible value for the +widget. See also \fB\-from\fR and \fB\-increment\fR. +range. .OP \-values values Values This must be a Tcl list of values. If this option is set then this will override any range set using the \fB\-from\fR, \fB\-to\fR and \fB\-increment\fR options. The widget will instead use the values specified beginning with the first value. .OP \-wrap wrap Wrap Must be a proper boolean value. If on, the spinbox will wrap around the values of data in the widget. -.OP \-format format Format -Specifies an alternate format to use when setting the string value -when using the \fB\-from\fR and \fB\-to\fR range. -This must be a format specifier of the form \fB%.f\fR, -as it will format a floating-point number. -.OP \-command command Command -Specifies a Tcl command to be invoked whenever a spinbutton is invoked. .SH "INDICES" .PP See the \fBttk::entry\fR manual for information about indexing characters. .SH "VALIDATION" .PP @@ -65,12 +65,10 @@ .SH "WIDGET COMMAND" .PP The following subcommands are possible for spinbox widgets in addition to the commands described for the \fBttk::entry\fR widget: .TP -\fIpathName \fBcurrent \fIindex\fR -.TP \fIpathName \fBget\fR Returns the spinbox's current value. .TP \fIpathName \fBset \fIvalue\fR Set the spinbox string to \fIvalue\fR. If a \fB\-format\fR option has Index: doc/ttk_widget.n ================================================================== --- doc/ttk_widget.n +++ doc/ttk_widget.n @@ -123,10 +123,13 @@ If greater than zero, specifies how much space, in character widths, to allocate for the text label. If less than zero, specifies a minimum width. If zero or unspecified, the natural width of the text label is used. .SH "COMPATIBILITY OPTIONS" +This option is only available for themed widgets that have +.QW corresponding +traditional Tk widgets. .OP \-state state State May be set to \fBnormal\fR or \fBdisabled\fR to control the \fBdisabled\fR state bit. This is a write-only option: setting it changes the widget state, Index: doc/wm.n ================================================================== --- doc/wm.n +++ doc/wm.n @@ -486,11 +486,17 @@ On X, the images are arranged into the _NET_WM_ICON X property, which most modern window managers support. A \fBwm iconbitmap\fR may exist simultaneously. It is recommended to use not more than 2 icons, placing the larger icon first. .PP -On Macintosh, this currently does nothing. +On Macintosh, the first image called is loaded into an OSX-native icon +format, and becomes the application icon in dialogs, the Dock, and +other contexts. At the +script level the command will accept only the first image passed in the +parameters as support for multiple sizes/resolutions on macOS is outside Tk's +scope. Developers should use the largest icon they can support +(preferably 512 pixels) to ensure smooth rendering on the Mac. .RE .TP \fBwm iconposition \fIwindow\fR ?\fIx y\fR? . If \fIx\fR and \fIy\fR are specified, they are passed to the window Index: generic/tk.h ================================================================== --- generic/tk.h +++ generic/tk.h @@ -73,14 +73,14 @@ */ #define TK_MAJOR_VERSION 8 #define TK_MINOR_VERSION 6 #define TK_RELEASE_LEVEL TCL_FINAL_RELEASE -#define TK_RELEASE_SERIAL 7 +#define TK_RELEASE_SERIAL 8 #define TK_VERSION "8.6" -#define TK_PATCH_LEVEL "8.6.7" +#define TK_PATCH_LEVEL "8.6.8" /* * A special definition used to allow this header file to be included from * windows or mac resource files so that they can obtain version information. * RC_INVOKED is defined by default by the windows RC tool and manually set Index: generic/tkBind.c ================================================================== --- generic/tkBind.c +++ generic/tkBind.c @@ -1736,13 +1736,14 @@ goto nextSequence; } } if (psPtr->flags & PAT_NEARBY) { XEvent *firstPtr = &bindPtr->eventRing[bindPtr->curEvent]; - int timeDiff; + long timeDiff; - timeDiff = (Time) firstPtr->xkey.time - eventPtr->xkey.time; + timeDiff = ((long)firstPtr->xkey.time - + (long)eventPtr->xkey.time); if ((firstPtr->xkey.x_root < (eventPtr->xkey.x_root - NEARBY_PIXELS)) || (firstPtr->xkey.x_root > (eventPtr->xkey.x_root + NEARBY_PIXELS)) || (firstPtr->xkey.y_root @@ -3331,13 +3332,13 @@ case EVENT_TIME: if (Tcl_GetIntFromObj(interp, valuePtr, &number) != TCL_OK) { return TCL_ERROR; } if (flags & KEY_BUTTON_MOTION_CROSSING) { - event.general.xkey.time = (Time) number; + event.general.xkey.time = number; } else if (flags & PROP) { - event.general.xproperty.time = (Time) number; + event.general.xproperty.time = number; } else { goto badopt; } break; case EVENT_WIDTH: @@ -3464,11 +3465,11 @@ */ if ((warp != 0) && Tk_IsMapped(tkwin)) { TkDisplay *dispPtr = TkGetDisplay(event.general.xmotion.display); -Tk_Window warpWindow = Tk_IdToWindow(dispPtr->display, + Tk_Window warpWindow = Tk_IdToWindow(dispPtr->display, event.general.xmotion.window); if (!(dispPtr->flags & TK_DISPLAY_IN_WARP)) { Tcl_DoWhenIdle(DoWarp, dispPtr); dispPtr->flags |= TK_DISPLAY_IN_WARP; Index: generic/tkBusy.c ================================================================== --- generic/tkBusy.c +++ generic/tkBusy.c @@ -15,20 +15,18 @@ #include "tkInt.h" #include "tkBusy.h" #include "default.h" /* - * Things about the busy system that may be configured. Note that currently on - * OSX/Aqua, that's nothing at all. + * Things about the busy system that may be configured. Note that on some + * platforms this may or may not have an effect. */ static const Tk_OptionSpec busyOptionSpecs[] = { -#ifndef MAC_OSX_TK {TK_OPTION_CURSOR, "-cursor", "cursor", "Cursor", DEF_BUSY_CURSOR, -1, Tk_Offset(Busy, cursor), TK_OPTION_NULL_OK, 0, 0}, -#endif {TK_OPTION_END, NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0} }; /* * Forward declarations of functions defined in this file. Index: generic/tkButton.c ================================================================== --- generic/tkButton.c +++ generic/tkButton.c @@ -1607,10 +1607,23 @@ int flags) /* Information about what happened. */ { register TkButton *butPtr = clientData; const char *value; Tcl_Obj *valuePtr; + + /* + * See ticket [5d991b82]. + */ + + if (butPtr->selVarNamePtr == NULL) { + if (!(flags & TCL_INTERP_DESTROYED)) { + Tcl_UntraceVar2(interp, name1, name2, + TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS, + ButtonVarProc, clientData); + } + return NULL; + } /* * If the variable is being unset, then just re-establish the trace unless * the whole interpreter is going away. */ @@ -1690,21 +1703,34 @@ /* ARGSUSED */ static char * ButtonTextVarProc( ClientData clientData, /* Information about button. */ Tcl_Interp *interp, /* Interpreter containing variable. */ - const char *name1, /* Not used. */ - const char *name2, /* Not used. */ + const char *name1, /* Name of variable. */ + const char *name2, /* Second part of variable name. */ int flags) /* Information about what happened. */ { TkButton *butPtr = clientData; Tcl_Obj *valuePtr; if (butPtr->flags & BUTTON_DELETED) { return NULL; } + /* + * See ticket [5d991b82]. + */ + + if (butPtr->textVarNamePtr == NULL) { + if (!(flags & TCL_INTERP_DESTROYED)) { + Tcl_UntraceVar2(interp, name1, name2, + TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS, + ButtonTextVarProc, clientData); + } + return NULL; + } + /* * If the variable is unset, then immediately recreate it unless the whole * interpreter is going away. */ Index: generic/tkCanvas.c ================================================================== --- generic/tkCanvas.c +++ generic/tkCanvas.c @@ -266,10 +266,11 @@ static void CanvasWorldChanged(ClientData instanceData); static int ConfigureCanvas(Tcl_Interp *interp, TkCanvas *canvasPtr, int argc, Tcl_Obj *const *argv, int flags); static void DestroyCanvas(char *memPtr); +static int DrawCanvas(Tcl_Interp *interp, ClientData clientData, Tk_PhotoHandle photohandle, int subsample, int zoom); static void DisplayCanvas(ClientData clientData); static void DoItem(Tcl_Obj *accumObj, Tk_Item *itemPtr, Tk_Uid tag); static void EventuallyRedrawItem(TkCanvas *canvasPtr, Tk_Item *itemPtr); @@ -803,10 +804,11 @@ static const char *const optionStrings[] = { "addtag", "bbox", "bind", "canvasx", "canvasy", "cget", "configure", "coords", "create", "dchars", "delete", "dtag", "find", "focus", "gettags", "icursor", + "image", "imove", "index", "insert", "itemcget", "itemconfigure", "lower", "move", "moveto", "postscript", "raise", "rchars", "scale", "scan", "select", "type", "xview", "yview", @@ -815,10 +817,11 @@ enum options { CANV_ADDTAG, CANV_BBOX, CANV_BIND, CANV_CANVASX, CANV_CANVASY, CANV_CGET, CANV_CONFIGURE, CANV_COORDS, CANV_CREATE, CANV_DCHARS, CANV_DELETE, CANV_DTAG, CANV_FIND, CANV_FOCUS, CANV_GETTAGS, CANV_ICURSOR, + CANV_IMAGE, CANV_IMOVE, CANV_INDEX, CANV_INSERT, CANV_ITEMCGET, CANV_ITEMCONFIGURE, CANV_LOWER, CANV_MOVE, CANV_MOVETO, CANV_POSTSCRIPT, CANV_RAISE, CANV_RCHARS, CANV_SCALE, CANV_SCAN, CANV_SELECT, CANV_TYPE, CANV_XVIEW, CANV_YVIEW @@ -1184,12 +1187,12 @@ tmpObj = Tcl_NewListObj(2, objv+4); FOR_EVERY_CANVAS_ITEM_MATCHING(objv[2], &searchPtr, goto doneImove) { int index; - int x1,x2,y1,y2; - int dontRedraw1,dontRedraw2; + int x1, x2, y1, y2; + int dontRedraw1, dontRedraw2; /* * The TK_MOVABLE_POINTS flag should only be set for types that * support the same semantics of index, dChars and insert methods * as lines and canvases. @@ -1215,15 +1218,15 @@ x1 = itemPtr->x1; y1 = itemPtr->y1; x2 = itemPtr->x2; y2 = itemPtr->y2; itemPtr->redraw_flags &= ~TK_ITEM_DONT_REDRAW; ItemDelChars(canvasPtr, itemPtr, index, index); - dontRedraw1=itemPtr->redraw_flags & TK_ITEM_DONT_REDRAW; + dontRedraw1 = itemPtr->redraw_flags & TK_ITEM_DONT_REDRAW; itemPtr->redraw_flags &= ~TK_ITEM_DONT_REDRAW; ItemInsert(canvasPtr, itemPtr, index, tmpObj); - dontRedraw2=itemPtr->redraw_flags & TK_ITEM_DONT_REDRAW; + dontRedraw2 = itemPtr->redraw_flags & TK_ITEM_DONT_REDRAW; if (!(dontRedraw1 && dontRedraw2)) { Tk_CanvasEventuallyRedraw((Tk_Canvas) canvasPtr, x1, y1, x2, y2); EventuallyRedrawItem(canvasPtr, itemPtr); @@ -1332,11 +1335,11 @@ Tcl_SetObjResult(interp, Tcl_NewIntObj(itemPtr->id)); break; } case CANV_DCHARS: { int first, last; - int x1,x2,y1,y2; + int x1, x2, y1, y2; if ((objc != 4) && (objc != 5)) { Tcl_WrongNumArgs(interp, 2, objv, "tagOrId first ?last?"); result = TCL_ERROR; goto done; @@ -1360,11 +1363,11 @@ } /* * Redraw both item's old and new areas: it's possible that a * delete could result in a new area larger than the old area. - * Except if the insertProc sets the TK_ITEM_DONT_REDRAW flag, + * Except if the dCharsProc sets the TK_ITEM_DONT_REDRAW flag, * nothing more needs to be done. */ x1 = itemPtr->x1; y1 = itemPtr->y1; x2 = itemPtr->x2; y2 = itemPtr->y2; @@ -1570,11 +1573,11 @@ Tcl_SetObjResult(interp, Tcl_NewIntObj(index)); break; } case CANV_INSERT: { int beforeThis; - int x1,x2,y1,y2; + int x1, x2, y1, y2; if (objc != 5) { Tcl_WrongNumArgs(interp, 2, objv, "tagOrId beforeThis string"); result = TCL_ERROR; goto done; @@ -1798,11 +1801,12 @@ RELINK_ITEMS(objv[2], prevPtr); break; } case CANV_RCHARS: { int first, last; - int x1,x2,y1,y2; + int x1, x2, y1, y2; + int dontRedraw1, dontRedraw2; if (objc != 6) { Tcl_WrongNumArgs(interp, 2, objv, "tagOrId first last string"); result = TCL_ERROR; goto done; @@ -1829,16 +1833,20 @@ * TK_ITEM_DONT_REDRAW flag, nothing more needs to be done. */ x1 = itemPtr->x1; y1 = itemPtr->y1; x2 = itemPtr->x2; y2 = itemPtr->y2; - itemPtr->redraw_flags &= ~TK_ITEM_DONT_REDRAW; + itemPtr->redraw_flags &= ~TK_ITEM_DONT_REDRAW; ItemDelChars(canvasPtr, itemPtr, first, last); + dontRedraw1 = itemPtr->redraw_flags & TK_ITEM_DONT_REDRAW; + + itemPtr->redraw_flags &= ~TK_ITEM_DONT_REDRAW; ItemInsert(canvasPtr, itemPtr, first, objv[5]); + dontRedraw2 = itemPtr->redraw_flags & TK_ITEM_DONT_REDRAW; - if (!(itemPtr->redraw_flags & TK_ITEM_DONT_REDRAW)) { + if (!(dontRedraw1 && dontRedraw2)) { Tk_CanvasEventuallyRedraw((Tk_Canvas) canvasPtr, x1, y1, x2, y2); EventuallyRedrawItem(canvasPtr, itemPtr); } itemPtr->redraw_flags &= ~TK_ITEM_DONT_REDRAW; @@ -2124,10 +2132,50 @@ break; } CanvasSetOrigin(canvasPtr, canvasPtr->xOrigin, newY); break; } + case CANV_IMAGE: { + Tk_PhotoHandle photohandle; + int subsample = 1, zoom = 1; + + if (objc < 3 || objc > 5) { + Tcl_WrongNumArgs(interp, 2, objv, "imagename ?subsample? ?zoom?"); + result = TCL_ERROR; + goto done; + } + + if ((photohandle = Tk_FindPhoto(interp, Tcl_GetString(objv[2]) )) == 0) { + result = TCL_ERROR; + goto done; + } + + /* + * If we are given a subsample or a zoom then grab them. + */ + + if (objc >= 4 && Tcl_GetIntFromObj(interp, objv[3], &subsample) != TCL_OK) { + result = TCL_ERROR; + goto done; + } + if (objc >= 5 && Tcl_GetIntFromObj(interp, objv[4], &zoom) != TCL_OK) { + result = TCL_ERROR; + goto done; + } + + /* + * Set the image size to zero, which allows the DrawCanvas() function + * to expand the image automatically when it copies the pixmap into it. + */ + + if (Tk_PhotoSetSize(interp, photohandle, 0, 0) != TCL_OK) { + result = TCL_ERROR; + goto done; + } + + result = DrawCanvas(interp, clientData, photohandle, subsample, zoom); + } } done: #ifndef USE_OLD_TAG_SEARCH TagSearchDestroy(searchPtr); @@ -2409,10 +2457,504 @@ canvasPtr->xOrigin, canvasPtr->yOrigin, canvasPtr->xOrigin + Tk_Width(canvasPtr->tkwin), canvasPtr->yOrigin + Tk_Height(canvasPtr->tkwin)); } +/* + *---------------------------------------------------------------------- + * + * DecomposeMaskToShiftAndBits -- + * + * Given a 32 bit pixel mask, we find the position of the lowest bit and the + * width of the mask bits. + * + * Results: + * None. + * + * Side effects: +* None. + * + *---------------------------------------------------------------------- + */ +static void +DecomposeMaskToShiftAndBits( + unsigned long mask, /* The pixel mask to examine */ + int *shift, /* Where to put the shift count (position of lowest bit) */ + int *bits) /* Where to put the bit count (width of the pixel mask) */ +{ + int i; + + *shift = 0; + *bits = 0; + + /* + * Find the lowest '1' bit in the mask. + */ + + for (i = 0; i < 32; ++i) { + if (mask & 1 << i) + break; + } + if (i < 32) { + *shift = i; + + /* + * Now find the next '0' bit and the width of the mask. + */ + + for ( ; i < 32; ++i) { + if ((mask & 1 << i) == 0) + break; + else + ++*bits; + } + + /* + * Limit to the top 8 bits if the mask was wider than 8. + */ + + if (*bits > 8) { + *shift += *bits - 8; + *bits = 8; + } + } +} + +/* + *---------------------------------------------------------------------- + * + * DrawCanvas -- + * + * This function draws the contents of a canvas into the given Photo image. + * This function is called from the widget "image" subcommand. + * The canvas does not need to be mapped (one of it's ancestors must be) + * in order for this function to work. + * + * Results: + * None. + * + * Side effects: + * Canvas contents from within the -scrollregion or widget size are rendered + * into the Photo. Any errors are left in the result. + * + *---------------------------------------------------------------------- + */ + +#define OVERDRAW_PIXELS 32 /* How much larger we make the pixmap + * that the canvas objects are drawn into */ + +/* From stackoverflow.com/questions/2100331/c-macro-definition-to-determine-big-endian-or-little-endian-machine */ +#define IS_BIG_ENDIAN (*(unsigned short *)"\0\xff" < 0x100) + +#define BYTE_SWAP16(n) ((((unsigned short)n)>>8) | (((unsigned short)n)<<8)) +#define BYTE_SWAP32(n) (((n>>24)&0x000000FF) | ((n<<8)&0x00FF0000) | ((n>>8)&0x0000FF00) | ((n<<24)&0xFF000000)) + +static int +DrawCanvas( + Tcl_Interp *interp, /* As passed to the widget command, and we will leave errors here */ + ClientData clientData, + Tk_PhotoHandle photohandle, /* The photo we are rendering into */ + int subsample, /* If either subsample or zoom are not 1 then we call Tk_PhotoPutZoomedBlock() */ + int zoom) +{ + TkCanvas * canvasPtr = clientData; + Tk_Window tkwin; + Display *displayPtr; + Tk_PhotoImageBlock blockPtr = {0}; + Window wid; + Tk_Item * itemPtr; + Pixmap pixmap = 0; + XImage *ximagePtr = NULL; + Visual *visualPtr; + GC xgc = 0; + XGCValues xgcValues; + int canvasX1, canvasY1, canvasX2, canvasY2, cWidth, cHeight, + pixmapX1, pixmapY1, pixmapX2, pixmapY2, pmWidth, pmHeight, + bitsPerPixel, bytesPerPixel, x, y, result = TCL_OK, + rshift, gshift, bshift, rbits, gbits, bbits; + +#ifdef DEBUG_DRAWCANVAS + char buffer[128]; +#endif + + if ((tkwin = canvasPtr->tkwin) == NULL) { + Tcl_AppendResult(interp, "canvas tkwin is NULL!", NULL); + result = TCL_ERROR; + goto done; + } + + /* + * If this canvas is unmapped, then we won't have a window id, so we will + * try the ancestors of the canvas until we find a window that has a + * valid window id. The Tk_GetPixmap() call requires a valid window id. + */ + + do { + + if ((displayPtr = Tk_Display(tkwin)) == NULL) { + Tcl_AppendResult(interp, "canvas (or parent) display is NULL!", NULL); + result = TCL_ERROR; + goto done; + } + + if ((wid = Tk_WindowId(tkwin)) != 0) { + continue; + } + + if ((tkwin = Tk_Parent(tkwin)) == NULL) { + Tcl_AppendResult(interp, "canvas has no parent with a valid window id! Is the toplevel window mapped?", NULL); + result = TCL_ERROR; + goto done; + } + + } while (wid == 0); + + bitsPerPixel = Tk_Depth(tkwin); + visualPtr = Tk_Visual(tkwin); + + if (subsample == 0) { + Tcl_AppendResult(interp, "subsample cannot be zero", NULL); + result = TCL_ERROR; + goto done; + } + + /* + * Scan through the item list, registering the bounding box for all items + * that didn't do that for the final coordinates yet. This can be + * determined by the FORCE_REDRAW flag. + */ + + for (itemPtr = canvasPtr -> firstItemPtr; itemPtr != NULL; + itemPtr = itemPtr -> nextPtr) { + if (itemPtr -> redraw_flags & FORCE_REDRAW) { + itemPtr -> redraw_flags &= ~FORCE_REDRAW; + EventuallyRedrawItem(canvasPtr, itemPtr); + itemPtr -> redraw_flags &= ~FORCE_REDRAW; + } + } + + /* + * The DisplayCanvas() function works out the region that needs redrawing, + * but we don't do this. We grab the whole scrollregion or canvas window + * area. If we have a defined -scrollregion we use that as the drawing + * region, otherwise use the canvas window height and width with an origin + * of 0,0. + */ + if (canvasPtr->scrollX1 != 0 || canvasPtr->scrollY1 != 0 || + canvasPtr->scrollX2 != 0 || canvasPtr->scrollY2 != 0) { + + canvasX1 = canvasPtr->scrollX1; + canvasY1 = canvasPtr->scrollY1; + canvasX2 = canvasPtr->scrollX2; + canvasY2 = canvasPtr->scrollY2; + cWidth = canvasX2 - canvasX1 + 1; + cHeight = canvasY2 - canvasY1 + 1; + + } else { + + cWidth = Tk_Width(tkwin); + cHeight = Tk_Height(tkwin); + canvasX1 = 0; + canvasY1 = 0; + canvasX2 = canvasX1 + cWidth - 1; + canvasY2 = canvasY1 + cHeight - 1; + } + + /* + * Allocate a pixmap to draw into. We add OVERDRAW_PIXELS in the same way + * that DisplayCanvas() does to avoid problems on some systems when objects + * are being drawn too close to the edge. + */ + + pixmapX1 = canvasX1 - OVERDRAW_PIXELS; + pixmapY1 = canvasY1 - OVERDRAW_PIXELS; + pixmapX2 = canvasX2 + OVERDRAW_PIXELS; + pixmapY2 = canvasY2 + OVERDRAW_PIXELS; + pmWidth = pixmapX2 - pixmapX1 + 1; + pmHeight = pixmapY2 - pixmapY1 + 1; + if ((pixmap = Tk_GetPixmap(displayPtr, Tk_WindowId(tkwin), pmWidth, pmHeight, + bitsPerPixel)) == 0) { + Tcl_AppendResult(interp, "failed to create drawing Pixmap", NULL); + result = TCL_ERROR; + goto done; + } + + /* + * Before we can draw the canvas objects into the pixmap it's background + * should be filled with canvas background colour. + */ + + xgcValues.function = GXcopy; + xgcValues.foreground = Tk_3DBorderColor(canvasPtr->bgBorder)->pixel; + xgc = XCreateGC(displayPtr, pixmap, GCFunction|GCForeground, &xgcValues); + XFillRectangle(displayPtr,pixmap,xgc,0,0,pmWidth,pmHeight); + + /* + * Draw all the cavas items into the pixmap + */ + + canvasPtr->drawableXOrigin = pixmapX1; + canvasPtr->drawableYOrigin = pixmapY1; + for (itemPtr = canvasPtr->firstItemPtr; itemPtr != NULL; + itemPtr = itemPtr->nextPtr) { + if ((itemPtr->x1 >= pixmapX2) || (itemPtr->y1 >= pixmapY2) || + (itemPtr->x2 < pixmapX1) || (itemPtr->y2 < pixmapY1)) { + if (!AlwaysRedraw(itemPtr)) { + continue; + } + } + if (itemPtr->state == TK_STATE_HIDDEN || + (itemPtr->state == TK_STATE_NULL && canvasPtr->canvas_state + == TK_STATE_HIDDEN)) { + continue; + } + ItemDisplay(canvasPtr, itemPtr, pixmap, pixmapX1, pixmapY1, pmWidth, + pmHeight); + } + + /* + * Copy the Pixmap into an ZPixmap format XImage so we can copy it across + * to the photo image. This seems to be the only way to get Pixmap image + * data out of an image. Note we have to account for the OVERDRAW_PIXELS + * border width. + */ + + if ((ximagePtr = XGetImage(displayPtr, pixmap, -pixmapX1, -pixmapY1, cWidth, + cHeight, AllPlanes, ZPixmap)) == NULL) { + Tcl_AppendResult(interp, "failed to copy Pixmap to XImage", NULL); + result = TCL_ERROR; + goto done; + } + +#ifdef DEBUG_DRAWCANVAS + Tcl_AppendResult(interp, "ximagePtr {", NULL); + sprintf(buffer,"%d",ximagePtr->width); Tcl_AppendResult(interp, " width ", buffer, NULL); + sprintf(buffer,"%d",ximagePtr->height); Tcl_AppendResult(interp, " height ", buffer, NULL); + sprintf(buffer,"%d",ximagePtr->xoffset); Tcl_AppendResult(interp, " xoffset ", buffer, NULL); + sprintf(buffer,"%d",ximagePtr->format); Tcl_AppendResult(interp, " format ", buffer, NULL); + Tcl_AppendResult(interp, " ximagePtr->data", NULL); + if (ximagePtr->data != NULL) { + int ix, iy; + + Tcl_AppendResult(interp, " {", NULL); + for (iy = 0; iy < ximagePtr->height; ++ iy) { + Tcl_AppendResult(interp, " {", NULL); + for (ix = 0; ix < ximagePtr->bytes_per_line; ++ ix) { + if (ix > 0) { + if (ix % 4 == 0) + Tcl_AppendResult(interp, "-", NULL); + else + Tcl_AppendResult(interp, " ", NULL); + } + sprintf(buffer,"%2.2x",ximagePtr->data[ximagePtr->bytes_per_line * iy + ix]&0xFF); + Tcl_AppendResult(interp, buffer, NULL); + } + Tcl_AppendResult(interp, " }", NULL); + } + Tcl_AppendResult(interp, " }", NULL); + } else + sprintf(buffer," NULL"); + sprintf(buffer,"%d",ximagePtr->byte_order); Tcl_AppendResult(interp, " byte_order ", buffer, NULL); + sprintf(buffer,"%d",ximagePtr->bitmap_unit); Tcl_AppendResult(interp, " bitmap_unit ", buffer, NULL); + sprintf(buffer,"%d",ximagePtr->bitmap_bit_order); Tcl_AppendResult(interp, " bitmap_bit_order ", buffer, NULL); + sprintf(buffer,"%d",ximagePtr->bitmap_pad); Tcl_AppendResult(interp, " bitmap_pad ", buffer, NULL); + sprintf(buffer,"%d",ximagePtr->depth); Tcl_AppendResult(interp, " depth ", buffer, NULL); + sprintf(buffer,"%d",ximagePtr->bytes_per_line); Tcl_AppendResult(interp, " bytes_per_line ", buffer, NULL); + sprintf(buffer,"%d",ximagePtr->bits_per_pixel); Tcl_AppendResult(interp, " bits_per_pixel ", buffer, NULL); + sprintf(buffer,"0x%8.8lx",ximagePtr->red_mask); Tcl_AppendResult(interp, " red_mask ", buffer, NULL); + sprintf(buffer,"0x%8.8lx",ximagePtr->green_mask); Tcl_AppendResult(interp, " green_mask ", buffer, NULL); + sprintf(buffer,"0x%8.8lx",ximagePtr->blue_mask); Tcl_AppendResult(interp, " blue_mask ", buffer, NULL); + Tcl_AppendResult(interp, " }", NULL); + + Tcl_AppendResult(interp, "\nvisualPtr {", NULL); + sprintf(buffer,"0x%8.8lx",visualPtr->red_mask); Tcl_AppendResult(interp, " red_mask ", buffer, NULL); + sprintf(buffer,"0x%8.8lx",visualPtr->green_mask); Tcl_AppendResult(interp, " green_mask ", buffer, NULL); + sprintf(buffer,"0x%8.8lx",visualPtr->blue_mask); Tcl_AppendResult(interp, " blue_mask ", buffer, NULL); + Tcl_AppendResult(interp, " }", NULL); + +#endif + + /* + * Fill in the PhotoImageBlock structure abd allocate a block of memory + * for the converted image data. Note we allocate an alpha channel even + * though we don't use one, because this layout helps Tk_PhotoPutBlock() + * use memcpy() instead of the slow pixel or line copy. + */ + + blockPtr.width = cWidth; + blockPtr.height = cHeight; + blockPtr.pixelSize = 4; + blockPtr.pitch = blockPtr.pixelSize * blockPtr.width; + blockPtr.offset[0] = 0; + blockPtr.offset[1] = 1; + blockPtr.offset[2] = 2; + blockPtr.offset[3] = 3; + blockPtr.pixelPtr = ckalloc(blockPtr.pixelSize * blockPtr.height * blockPtr.width); + + /* + * Now convert the image data pixel by pixel from XImage to 32bit RGBA + * format suitable for Tk_PhotoPutBlock(). + */ + + DecomposeMaskToShiftAndBits(visualPtr->red_mask,&rshift,&rbits); + DecomposeMaskToShiftAndBits(visualPtr->green_mask,&gshift,&gbits); + DecomposeMaskToShiftAndBits(visualPtr->blue_mask,&bshift,&bbits); + +#ifdef DEBUG_DRAWCANVAS + sprintf(buffer,"%d",rshift); Tcl_AppendResult(interp, "\nbits { rshift ", buffer, NULL); + sprintf(buffer,"%d",gshift); Tcl_AppendResult(interp, " gshift ", buffer, NULL); + sprintf(buffer,"%d",bshift); Tcl_AppendResult(interp, " bshift ", buffer, NULL); + sprintf(buffer,"%d",rbits); Tcl_AppendResult(interp, " rbits ", buffer, NULL); + sprintf(buffer,"%d",gbits); Tcl_AppendResult(interp, " gbits ", buffer, NULL); + sprintf(buffer,"%d",bbits); Tcl_AppendResult(interp, " bbits ", buffer, " }", NULL); + Tcl_AppendResult(interp, "\nConverted_image {", NULL); +#endif + + /* Ok, had to use ximagePtr->bits_per_pixel here and in the switch (...) + * below to get this to work on Windows. X11 correctly sets the bitmap + *_pad and bitmap_unit fields to 32, but on Windows they are 0 and 8 + * respectively! + */ + + bytesPerPixel = ximagePtr->bits_per_pixel/8; + for (y = 0; y < blockPtr.height; ++y) { + +#ifdef DEBUG_DRAWCANVAS + Tcl_AppendResult(interp, " {", NULL); +#endif + + for(x = 0; x < blockPtr.width; ++x) { + unsigned long pixel; + + switch (ximagePtr->bits_per_pixel) { + + /* + * Get an 8 bit pixel from the XImage. + */ + + case 8 : + pixel = *((unsigned char *)(ximagePtr->data + bytesPerPixel * x + + ximagePtr->bytes_per_line * y)); + break; + + /* + * Get a 16 bit pixel from the XImage, and correct the + * byte order as necessary. + */ + + case 16 : + pixel = *((unsigned short *)(ximagePtr->data + bytesPerPixel * x + + ximagePtr->bytes_per_line * y)); + if ((IS_BIG_ENDIAN && ximagePtr->byte_order == LSBFirst) + || (!IS_BIG_ENDIAN && ximagePtr->byte_order == MSBFirst)) + pixel = BYTE_SWAP16(pixel); + break; + + /* + * Grab a 32 bit pixel from the XImage, and correct the + * byte order as necessary. + */ + + case 32 : + pixel = *((unsigned long *)(ximagePtr->data + bytesPerPixel * x + + ximagePtr->bytes_per_line * y)); + if ((IS_BIG_ENDIAN && ximagePtr->byte_order == LSBFirst) + || (!IS_BIG_ENDIAN && ximagePtr->byte_order == MSBFirst)) + pixel = BYTE_SWAP32(pixel); + break; + } + + /* + * We have a pixel with the correct byte order, so pull out the + * colours and place them in the photo block. Perhaps we could + * just not bother with the alpha byte because we are using + * TK_PHOTO_COMPOSITE_SET later? + * ***Windows: We have to swap the red and blue values. The + * XImage storage is B - G - R - A which becomes a 32bit ARGB + * quad. However the visual mask is a 32bit ABGR quad. And + * Tk_PhotoPutBlock() wants R-G-B-A which is a 32bit ABGR quad. + * If the visual mask was correct there would be no need to + * swap anything here. + */ + +#ifdef _WIN32 +#define R_OFFSET 2 +#define B_OFFSET 0 +#else +#define R_OFFSET 0 +#define B_OFFSET 2 +#endif + blockPtr.pixelPtr[blockPtr.pitch * y + blockPtr.pixelSize * x + R_OFFSET] = + (unsigned char)((pixel & visualPtr->red_mask) >> rshift); + blockPtr.pixelPtr[blockPtr.pitch * y + blockPtr.pixelSize * x +1] = + (unsigned char)((pixel & visualPtr->green_mask) >> gshift); + blockPtr.pixelPtr[blockPtr.pitch * y + blockPtr.pixelSize * x + B_OFFSET] = + (unsigned char)((pixel & visualPtr->blue_mask) >> bshift); + blockPtr.pixelPtr[blockPtr.pitch * y + blockPtr.pixelSize * x +3] = 0xFF; + +#ifdef DEBUG_DRAWCANVAS + { + int ix; + if (x > 0) + Tcl_AppendResult(interp, "-", NULL); + for (ix = 0; ix < 4; ++ix) { + if (ix > 0) + Tcl_AppendResult(interp, " ", NULL); + sprintf(buffer,"%2.2x",blockPtr.pixelPtr[blockPtr.pitch * y + + blockPtr.pixelSize * x + ix]&0xFF); + Tcl_AppendResult(interp, buffer, NULL); + } + } +#endif + + } + +#ifdef DEBUG_DRAWCANVAS + Tcl_AppendResult(interp, " }", NULL); +#endif + + } + +#ifdef DEBUG_DRAWCANVAS + Tcl_AppendResult(interp, " }", NULL); +#endif + + /* + * Now put the copied pixmap into the photo. + * If either zoom or subsample are not 1, we use the zoom function. + */ + + if (subsample != 1 || zoom != 1) { + if ((result = Tk_PhotoPutZoomedBlock(interp, photohandle, &blockPtr, + 0, 0, cWidth * zoom / subsample, cHeight * zoom / subsample, + zoom, zoom, subsample, subsample, TK_PHOTO_COMPOSITE_SET)) + != TCL_OK) { + goto done; + } + } else { + if ((result = Tk_PhotoPutBlock(interp, photohandle, &blockPtr, 0, 0, + cWidth, cHeight, TK_PHOTO_COMPOSITE_SET)) != TCL_OK) { + goto done; + } + } + + /* + * Clean up anything we have allocated and exit. + */ + +done: + if (blockPtr.pixelPtr) + ckfree(blockPtr.pixelPtr); + if (pixmap) + Tk_FreePixmap(Tk_Display(tkwin), pixmap); + if (ximagePtr) + XDestroyImage(ximagePtr); + if (xgc) + XFreeGC(displayPtr,xgc); + return result; +} + /* *---------------------------------------------------------------------- * * DisplayCanvas -- * Index: generic/tkEntry.c ================================================================== --- generic/tkEntry.c +++ generic/tkEntry.c @@ -885,11 +885,12 @@ } else { entryPtr->selectFirst = index; entryPtr->selectLast = index2; } if (!(entryPtr->flags & GOT_SELECTION) - && (entryPtr->exportSelection)) { + && (entryPtr->exportSelection) + && (!Tcl_IsSafe(entryPtr->interp))) { Tk_OwnSelection(entryPtr->tkwin, XA_PRIMARY, EntryLostSelection, entryPtr); entryPtr->flags |= GOT_SELECTION; } EventuallyRedraw(entryPtr); @@ -1120,11 +1121,11 @@ /* * Store old values that we need to effect certain behavior if they change * value. */ - oldExport = entryPtr->exportSelection; + oldExport = (entryPtr->exportSelection) && (!Tcl_IsSafe(entryPtr->interp)); if (entryPtr->type == TK_SPINBOX) { oldValues = sbPtr->valueStr; oldFormat = sbPtr->reqFormat; oldFrom = sbPtr->fromValue; oldTo = sbPtr->toValue; @@ -1274,10 +1275,11 @@ /* * Claim the selection if we've suddenly started exporting it. */ if (entryPtr->exportSelection && (!oldExport) + && (!Tcl_IsSafe(entryPtr->interp)) && (entryPtr->selectFirst != -1) && !(entryPtr->flags & GOT_SELECTION)) { Tk_OwnSelection(entryPtr->tkwin, XA_PRIMARY, EntryLostSelection, entryPtr); entryPtr->flags |= GOT_SELECTION; @@ -2743,11 +2745,12 @@ /* * Grab the selection if we don't own it already. */ - if (!(entryPtr->flags & GOT_SELECTION) && (entryPtr->exportSelection)) { + if (!(entryPtr->flags & GOT_SELECTION) && (entryPtr->exportSelection) + && (!Tcl_IsSafe(entryPtr->interp))) { Tk_OwnSelection(entryPtr->tkwin, XA_PRIMARY, EntryLostSelection, entryPtr); entryPtr->flags |= GOT_SELECTION; } @@ -2810,11 +2813,12 @@ Entry *entryPtr = clientData; int byteCount; const char *string; const char *selStart, *selEnd; - if ((entryPtr->selectFirst < 0) || !(entryPtr->exportSelection)) { + if ((entryPtr->selectFirst < 0) || (!entryPtr->exportSelection) + || Tcl_IsSafe(entryPtr->interp)) { return -1; } string = entryPtr->displayString; selStart = Tcl_UtfAtIndex(string, entryPtr->selectFirst); selEnd = Tcl_UtfAtIndex(selStart, @@ -2863,11 +2867,12 @@ * selection since it is always visible. * This is controlled by ::tk::AlwaysShowSelection. */ if (TkpAlwaysShowSelection(entryPtr->tkwin) - && (entryPtr->selectFirst >= 0) && entryPtr->exportSelection) { + && (entryPtr->selectFirst >= 0) && entryPtr->exportSelection + && (!Tcl_IsSafe(entryPtr->interp))) { entryPtr->selectFirst = -1; entryPtr->selectLast = -1; EventuallyRedraw(entryPtr); } } @@ -3128,12 +3133,12 @@ /* ARGSUSED */ static char * EntryTextVarProc( ClientData clientData, /* Information about button. */ Tcl_Interp *interp, /* Interpreter containing variable. */ - const char *name1, /* Not used. */ - const char *name2, /* Not used. */ + const char *name1, /* Name of variable. */ + const char *name2, /* Second part of variable name. */ int flags) /* Information about what happened. */ { Entry *entryPtr = clientData; const char *value; @@ -3141,10 +3146,23 @@ /* * Just abort early if we entered here while being deleted. */ return NULL; } + + /* + * See ticket [5d991b82]. + */ + + if (entryPtr->textVarName == NULL) { + if (!(flags & TCL_INTERP_DESTROYED)) { + Tcl_UntraceVar2(interp, name1, name2, + TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS, + EntryTextVarProc, clientData); + } + return NULL; + } /* * If the variable is unset, then immediately recreate it unless the whole * interpreter is going away. */ @@ -4032,11 +4050,12 @@ } else { entryPtr->selectFirst = index; entryPtr->selectLast = index2; } if (!(entryPtr->flags & GOT_SELECTION) - && entryPtr->exportSelection) { + && entryPtr->exportSelection + && (!Tcl_IsSafe(entryPtr->interp))) { Tk_OwnSelection(entryPtr->tkwin, XA_PRIMARY, EntryLostSelection, entryPtr); entryPtr->flags |= GOT_SELECTION; } EventuallyRedraw(entryPtr); Index: generic/tkFont.c ================================================================== --- generic/tkFont.c +++ generic/tkFont.c @@ -3149,26 +3149,24 @@ cx[0] = cx[3] = chunkPtr->x; cy[0] = cy[1] = chunkPtr->y - fontPtr->fm.ascent; cx[1] = cx[2] = chunkPtr->x + chunkPtr->displayWidth; cy[2] = cy[3] = chunkPtr->y + fontPtr->fm.descent; - if ( !PointInQuadrilateral(cx, cy, rx[0], ry[0]) || - !PointInQuadrilateral(cx, cy, rx[1], ry[1]) || - !PointInQuadrilateral(cx, cy, rx[2], ry[2]) || - !PointInQuadrilateral(cx, cy, rx[3], ry[3])) { - goto notReverseInside; - } - } - return 0; + if ( PointInQuadrilateral(cx, cy, rx[0], ry[0]) && + PointInQuadrilateral(cx, cy, rx[1], ry[1]) && + PointInQuadrilateral(cx, cy, rx[2], ry[2]) && + PointInQuadrilateral(cx, cy, rx[3], ry[3])) { + return 0; + } + } /* * If we're overlapping now, we must be partially in and out of at least * one chunk. If that is the case, there must be one line segment of the * rectangle that is touching or crossing a line segment of a chunk. */ - notReverseInside: chunkPtr = layoutPtr->chunks; for (i=0 ; inumChunks ; i++,chunkPtr++) { int j; Index: generic/tkGrid.c ================================================================== --- generic/tkGrid.c +++ generic/tkGrid.c @@ -2866,21 +2866,22 @@ gridPtr->masterPtr->flags |= REQUESTED_RELAYOUT; Tcl_DoWhenIdle(ArrangeGrid, gridPtr->masterPtr); } } } else if (eventPtr->type == DestroyNotify) { - register Gridder *gridPtr2, *nextPtr; + register Gridder *slavePtr, *nextPtr; if (gridPtr->masterPtr != NULL) { Unlink(gridPtr); } - for (gridPtr2 = gridPtr->slavePtr; gridPtr2 != NULL; - gridPtr2 = nextPtr) { - Tk_UnmapWindow(gridPtr2->tkwin); - gridPtr2->masterPtr = NULL; - nextPtr = gridPtr2->nextPtr; - gridPtr2->nextPtr = NULL; + for (slavePtr = gridPtr->slavePtr; slavePtr != NULL; + slavePtr = nextPtr) { + Tk_ManageGeometry(slavePtr->tkwin, NULL, NULL); + Tk_UnmapWindow(slavePtr->tkwin); + slavePtr->masterPtr = NULL; + nextPtr = slavePtr->nextPtr; + slavePtr->nextPtr = NULL; } Tcl_DeleteHashEntry(Tcl_FindHashEntry(&dispPtr->gridHashTable, (char *) gridPtr->tkwin)); if (gridPtr->flags & REQUESTED_RELAYOUT) { Tcl_CancelIdleCall(ArrangeGrid, gridPtr); @@ -2892,15 +2893,15 @@ && !(gridPtr->flags & REQUESTED_RELAYOUT)) { gridPtr->flags |= REQUESTED_RELAYOUT; Tcl_DoWhenIdle(ArrangeGrid, gridPtr); } } else if (eventPtr->type == UnmapNotify) { - register Gridder *gridPtr2; + register Gridder *slavePtr; - for (gridPtr2 = gridPtr->slavePtr; gridPtr2 != NULL; - gridPtr2 = gridPtr2->nextPtr) { - Tk_UnmapWindow(gridPtr2->tkwin); + for (slavePtr = gridPtr->slavePtr; slavePtr != NULL; + slavePtr = slavePtr->nextPtr) { + Tk_UnmapWindow(slavePtr->tkwin); } } } /* @@ -3081,11 +3082,12 @@ defaultRow = tmp; } } /* - * If no -row is given, use the first unoccupied row of the master. + * If no -row is given, use the next row after the highest occupied row + * of the master. */ if (defaultRow < 0) { if (masterPtr != NULL && masterPtr->masterDataPtr != NULL) { SetGridSize(masterPtr); Index: generic/tkImgPNG.c ================================================================== --- generic/tkImgPNG.c +++ generic/tkImgPNG.c @@ -33,11 +33,11 @@ /* * Chunk type flags. */ -#define PNG_CF_ANCILLARY 0x10000000L /* Non-critical chunk (can ignore). */ +#define PNG_CF_ANCILLARY 0x20000000L /* Non-critical chunk (can ignore). */ #define PNG_CF_PRIVATE 0x00100000L /* Application-specific chunk. */ #define PNG_CF_RESERVED 0x00001000L /* Not used. */ #define PNG_CF_COPYSAFE 0x00000010L /* Opaque data safe for copying. */ /* @@ -982,11 +982,11 @@ * No nice ASCII conversion; shouldn't happen either, but * we'll be doubly careful. */ Tcl_SetObjResult(interp, Tcl_NewStringObj( - "encountered an unsupported criticial chunk type", + "encountered an unsupported critical chunk type", -1)); } else { char typeString[5]; typeString[0] = (char) ((chunkType >> 24) & 255); @@ -993,11 +993,11 @@ typeString[1] = (char) ((chunkType >> 16) & 255); typeString[2] = (char) ((chunkType >> 8) & 255); typeString[3] = (char) (chunkType & 255); typeString[4] = '\0'; Tcl_SetObjResult(interp, Tcl_ObjPrintf( - "encountered an unsupported criticial chunk type" + "encountered an unsupported critical chunk type" " \"%s\"", typeString)); } Tcl_SetErrorCode(interp, "TK", "IMAGE", "PNG", "UNSUPPORTED_CRITICAL", NULL); return TCL_ERROR; Index: generic/tkImgPhInstance.c ================================================================== --- generic/tkImgPhInstance.c +++ generic/tkImgPhInstance.c @@ -416,10 +416,17 @@ #define GetBValue(rgb) (UCHAR(((rgb) & blue_mask) >> blue_shift)) #define RGB(r, g, b) ((unsigned)( \ (UCHAR(r) << red_shift) | \ (UCHAR(g) << green_shift) | \ (UCHAR(b) << blue_shift) )) +#ifdef MAC_OSX_TK +#define RGBA(r, g, b, a) ((unsigned)( \ + (UCHAR(r) << red_shift) | \ + (UCHAR(g) << green_shift) | \ + (UCHAR(b) << blue_shift) | \ + (UCHAR(a) << alpha_shift) )) +#endif #define RGB15(r, g, b) ((unsigned)( \ (((r) * red_mask / 255) & red_mask) | \ (((g) * green_mask / 255) & green_mask) | \ (((b) * blue_mask / 255) & blue_mask) )) #endif /* !_WIN32 */ @@ -483,10 +490,17 @@ green_shift++; } while ((0x0001 & (blue_mask >> blue_shift)) == 0) { blue_shift++; } +#ifdef MAC_OSX_TK + unsigned long alpha_mask = visual->alpha_mask; + unsigned long alpha_shift = 0; + while ((0x0001 & (alpha_mask >> alpha_shift)) == 0) { + alpha_shift++; + } +#endif #endif /* !_WIN32 */ /* * Only UNIX requires the special case for <24bpp. It varies with 3 extra * shifts and uses RGB15. The 24+bpp version could also then be further @@ -583,11 +597,15 @@ unalpha = 255 - alpha; /* Calculate once. */ r = ALPHA_BLEND(ra, r, alpha, unalpha); g = ALPHA_BLEND(ga, g, alpha, unalpha); b = ALPHA_BLEND(ba, b, alpha, unalpha); } +#ifndef MAC_OSX_TK XPutPixel(bgImg, x, y, RGB(r, g, b)); +#else + XPutPixel(bgImg, x, y, RGBA(r, g, b, alpha)); +#endif } } } #undef ALPHA_BLEND } Index: generic/tkImgPhoto.c ================================================================== --- generic/tkImgPhoto.c +++ generic/tkImgPhoto.c @@ -574,10 +574,13 @@ } Tk_PhotoGetImage(srcHandle, &block); if ((options.fromX2 > block.width) || (options.fromY2 > block.height) || (options.fromX2 > block.width) || (options.fromY2 > block.height)) { + if (options.background) { + Tk_FreeColor(options.background); + } Tcl_SetObjResult(interp, Tcl_NewStringObj( "coordinates for -from option extend outside source image", -1)); Tcl_SetErrorCode(interp, "TK", "IMAGE", "PHOTO", "BAD_FROM", NULL); return TCL_ERROR; @@ -622,38 +625,50 @@ / -options.subsampleY; } options.toY2 = options.toY + height * options.zoomY; } - /* - * Set the destination image size if the -shrink option was specified. - */ - - if (options.options & OPT_SHRINK) { - if (ImgPhotoSetSize(masterPtr, options.toX2, - options.toY2) != TCL_OK) { - Tcl_SetObjResult(interp, Tcl_NewStringObj( - TK_PHOTO_ALLOC_FAILURE_MESSAGE, -1)); - Tcl_SetErrorCode(interp, "TK", "MALLOC", NULL); - return TCL_ERROR; - } - } - /* * Copy the image data over using Tk_PhotoPutZoomedBlock. */ block.pixelPtr += options.fromX * block.pixelSize + options.fromY * block.pitch; block.width = options.fromX2 - options.fromX; block.height = options.fromY2 - options.fromY; - return Tk_PhotoPutZoomedBlock(interp, (Tk_PhotoHandle) masterPtr, + result = Tk_PhotoPutZoomedBlock(interp, (Tk_PhotoHandle) masterPtr, &block, options.toX, options.toY, options.toX2 - options.toX, options.toY2 - options.toY, options.zoomX, options.zoomY, options.subsampleX, options.subsampleY, options.compositingRule); + /* + * Set the destination image size if the -shrink option was specified. + * This has to be done _after_ copying the data. Otherwise, if source + * and destination are the same image, block.pixelPtr would point to + * an invalid memory block (bug [5239fd749b]). + */ + + if (options.options & OPT_SHRINK) { + if (ImgPhotoSetSize(masterPtr, options.toX2, + options.toY2) != TCL_OK) { + if (options.background) { + Tk_FreeColor(options.background); + } + Tcl_SetObjResult(interp, Tcl_NewStringObj( + TK_PHOTO_ALLOC_FAILURE_MESSAGE, -1)); + Tcl_SetErrorCode(interp, "TK", "MALLOC", NULL); + return TCL_ERROR; + } + } + Tk_ImageChanged(masterPtr->tkMaster, 0, 0, 0, 0, + masterPtr->width, masterPtr->height); + if (options.background) { + Tk_FreeColor(options.background); + } + return result; + case PHOTO_DATA: { char *data; /* * photo data command - first parse and check any options given. Index: generic/tkListbox.c ================================================================== --- generic/tkListbox.c +++ generic/tkListbox.c @@ -1563,11 +1563,11 @@ Tk_SavedOptions savedOptions; Tcl_Obj *oldListObj = NULL; Tcl_Obj *errorResult = NULL; int oldExport, error; - oldExport = listPtr->exportSelection; + oldExport = (listPtr->exportSelection) && (!Tcl_IsSafe(listPtr->interp)); if (listPtr->listVarName != NULL) { Tcl_UntraceVar2(interp, listPtr->listVarName, NULL, TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS, ListboxListVarProc, listPtr); } @@ -1605,14 +1605,15 @@ } listPtr->inset = listPtr->highlightWidth + listPtr->borderWidth; /* * Claim the selection if we've suddenly started exporting it and - * there is a selection to export. + * there is a selection to export and this interp is unsafe. */ - if (listPtr->exportSelection && !oldExport + if (listPtr->exportSelection && (!oldExport) + && (!Tcl_IsSafe(listPtr->interp)) && (listPtr->numSelected != 0)) { Tk_OwnSelection(listPtr->tkwin, XA_PRIMARY, ListboxLostSelection, listPtr); } @@ -3077,11 +3078,12 @@ if (firstRedisplay >= 0) { EventuallyRedrawRange(listPtr, first, last); } if ((oldCount == 0) && (listPtr->numSelected > 0) - && listPtr->exportSelection) { + && (listPtr->exportSelection) + && (!Tcl_IsSafe(listPtr->interp))) { Tk_OwnSelection(listPtr->tkwin, XA_PRIMARY, ListboxLostSelection, listPtr); } return TCL_OK; } @@ -3123,11 +3125,11 @@ int length, count, needNewline, stringLen, i; Tcl_Obj *curElement; const char *stringRep; Tcl_HashEntry *entry; - if (!listPtr->exportSelection) { + if ((!listPtr->exportSelection) || Tcl_IsSafe(listPtr->interp)) { return -1; } /* * Use a dynamic string to accumulate the contents of the selection. @@ -3194,11 +3196,12 @@ ListboxLostSelection( ClientData clientData) /* Information about listbox widget. */ { register Listbox *listPtr = clientData; - if ((listPtr->exportSelection) && (listPtr->nElements > 0)) { + if ((listPtr->exportSelection) && (!Tcl_IsSafe(listPtr->interp)) + && (listPtr->nElements > 0)) { ListboxSelect(listPtr, 0, listPtr->nElements-1, 0); GenerateListboxSelectEvent(listPtr); } } @@ -3426,18 +3429,31 @@ static char * ListboxListVarProc( ClientData clientData, /* Information about button. */ Tcl_Interp *interp, /* Interpreter containing variable. */ - const char *name1, /* Not used. */ - const char *name2, /* Not used. */ + const char *name1, /* Name of variable. */ + const char *name2, /* Second part of variable name. */ int flags) /* Information about what happened. */ { Listbox *listPtr = clientData; Tcl_Obj *oldListObj, *varListObj; int oldLength, i; Tcl_HashEntry *entry; + + /* + * See ticket [5d991b82]. + */ + + if (listPtr->listVarName == NULL) { + if (!(flags & TCL_INTERP_DESTROYED)) { + Tcl_UntraceVar2(interp, name1, name2, + TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS, + ListboxListVarProc, clientData); + } + return NULL; + } /* * Bwah hahahaha! Puny mortal, you can't unset a -listvar'd variable! */ Index: generic/tkMenu.c ================================================================== --- generic/tkMenu.c +++ generic/tkMenu.c @@ -2493,10 +2493,26 @@ return NULL; } menuPtr = mePtr->menuPtr; + + if (menuPtr->menuFlags & MENU_DELETION_PENDING) { + return NULL; + } + + /* + * See ticket [5d991b82]. + */ + + if (mePtr->namePtr == NULL) { + Tcl_UntraceVar2(interp, name1, name2, + TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS, + MenuVarProc, clientData); + return NULL; + } + name = Tcl_GetString(mePtr->namePtr); /* * If the variable is being unset, then re-establish the trace. */ Index: generic/tkMenubutton.c ================================================================== --- generic/tkMenubutton.c +++ generic/tkMenubutton.c @@ -878,10 +878,23 @@ int flags) /* Information about what happened. */ { register TkMenuButton *mbPtr = clientData; const char *value; unsigned len; + + /* + * See ticket [5d991b82]. + */ + + if (mbPtr->textVarName == NULL) { + if (!(flags & TCL_INTERP_DESTROYED)) { + Tcl_UntraceVar2(interp, name1, name2, + TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS, + MenuButtonTextVarProc, clientData); + } + return NULL; + } /* * If the variable is unset, then immediately recreate it unless the whole * interpreter is going away. */ Index: generic/tkMessage.c ================================================================== --- generic/tkMessage.c +++ generic/tkMessage.c @@ -835,10 +835,23 @@ const char *name2, /* Second part of variable name. */ int flags) /* Information about what happened. */ { register Message *msgPtr = clientData; const char *value; + + /* + * See ticket [5d991b82]. + */ + + if (msgPtr->textVarName == NULL) { + if (!(flags & TCL_INTERP_DESTROYED)) { + Tcl_UntraceVar2(interp, name1, name2, + TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS, + MessageTextVarProc, clientData); + } + return NULL; + } /* * If the variable is unset, then immediately recreate it unless the whole * interpreter is going away. */ Index: generic/tkObj.c ================================================================== --- generic/tkObj.c +++ generic/tkObj.c @@ -151,12 +151,23 @@ { ThreadSpecificData *tsdPtr = Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); if (tsdPtr->doubleTypePtr == NULL) { - tsdPtr->doubleTypePtr = Tcl_GetObjType("double"); - tsdPtr->intTypePtr = Tcl_GetObjType("int"); + /* Smart initialization of doubleTypePtr/intTypePtr without + * hash-table lookup or creating complete Tcl_Obj's */ + Tcl_Obj obj; + obj.length = 3; + obj.bytes = (char *)"0.0"; + obj.typePtr = NULL; + Tcl_GetDoubleFromObj(NULL, &obj, &obj.internalRep.doubleValue); + tsdPtr->doubleTypePtr = obj.typePtr; + obj.bytes += 2; + obj.length = 1; + obj.typePtr = NULL; + Tcl_GetLongFromObj(NULL, &obj, &obj.internalRep.longValue); + tsdPtr->intTypePtr = obj.typePtr; } return tsdPtr; } /* @@ -1110,11 +1121,11 @@ * * Results: * None * * Side effects: - * All instances of Tcl_ObjType structues used in Tk are registered with + * All instances of Tcl_ObjType structures used in Tk are registered with * Tcl. * *---------------------------------------------------------------------- */ Index: generic/tkPack.c ================================================================== --- generic/tkPack.c +++ generic/tkPack.c @@ -1360,11 +1360,11 @@ /* * If we have emptied this master from slaves it means we are no longer * handling it and should mark it as free. */ - if (masterPtr->slavePtr == NULL && masterPtr->flags & ALLOCED_MASTER) { + if ((masterPtr->slavePtr == NULL) && (masterPtr->flags & ALLOCED_MASTER)) { TkFreeGeometryMaster(masterPtr->tkwin, "pack"); masterPtr->flags &= ~ALLOCED_MASTER; } } Index: generic/tkRectOval.c ================================================================== --- generic/tkRectOval.c +++ generic/tkRectOval.c @@ -757,15 +757,107 @@ Tk_CanvasDrawableCoords(canvas, rectOvalPtr->bbox[0],rectOvalPtr->bbox[1], &x1, &y1); Tk_CanvasDrawableCoords(canvas, rectOvalPtr->bbox[2],rectOvalPtr->bbox[3], &x2, &y2); - if (x2 <= x1) { - x2 = x1+1; + if (x2 == x1) { + + /* + * The width of the bounding box corresponds to less than one pixel + * on screen. Adjustment is needed to avoid drawing attempts with zero + * width items (which would draw nothing). The bounding box spans + * either 1 or 2 pixels. Select which pixel will be drawn. + */ + + short ix1 = (short) (rectOvalPtr->bbox[0]); + short ix2 = (short) (rectOvalPtr->bbox[2]); + + if (ix1 == ix2) { + + /* + * x1 and x2 are "within the same pixel". Use this pixel. + * Note: the degenerated case (bbox[0]==bbox[2]) of a completely + * flat box results in arbitrary selection of the pixel at the + * right (with positive coordinate) or left (with negative + * coordinate) of the box. There is no "best choice" here. + */ + + if (ix1 > 0) { + x2 += 1; + } else { + x1 -= 1; + } + } else { + + /* + * (x1,x2) span two pixels. Select the one with the larger + * covered "area". + */ + + if (ix1 > 0) { + if ((rectOvalPtr->bbox[2] - ix2) > (ix2 - rectOvalPtr->bbox[0])) { + x2 += 1; + } else { + x1 -= 1; + } + } else { + if ((rectOvalPtr->bbox[2] - ix1) > (ix1 - rectOvalPtr->bbox[0])) { + x2 += 1; + } else { + x1 -= 1; + } + } + } } - if (y2 <= y1) { - y2 = y1+1; + if (y2 == y1) { + + /* + * The height of the bounding box corresponds to less than one pixel + * on screen. Adjustment is needed to avoid drawing attempts with zero + * height items (which would draw nothing). The bounding box spans + * either 1 or 2 pixels. Select which pixel will be drawn. + */ + + short iy1 = (short) (rectOvalPtr->bbox[1]); + short iy2 = (short) (rectOvalPtr->bbox[3]); + + if (iy1 == iy2) { + + /* + * y1 and y2 are "within the same pixel". Use this pixel. + * Note: the degenerated case (bbox[1]==bbox[3]) of a completely + * flat box results in arbitrary selection of the pixel below + * (with positive coordinate) or above (with negative coordinate) + * the box. There is no "best choice" here. + */ + + if (iy1 > 0) { + y2 += 1; + } else { + y1 -= 1; + } + } else { + + /* + * (y1,y2) span two pixels. Select the one with the larger + * covered "area". + */ + + if (iy1 > 0) { + if ((rectOvalPtr->bbox[3] - iy2) > (iy2 - rectOvalPtr->bbox[1])) { + y2 += 1; + } else { + y1 -= 1; + } + } else { + if ((rectOvalPtr->bbox[3] - iy1) > (iy1 - rectOvalPtr->bbox[1])) { + y2 += 1; + } else { + y1 -= 1; + } + } + } } /* * Display filled part first (if wanted), then outline. If we're * stippling, then modify the stipple offset in the GC. Be sure to reset Index: generic/tkScale.c ================================================================== --- generic/tkScale.c +++ generic/tkScale.c @@ -19,10 +19,14 @@ #include "default.h" #include "tkInt.h" #include "tkScale.h" +#if defined(_WIN32) +#define snprintf _snprintf +#endif + /* * The following table defines the legal values for the -orient option. It is * used together with the "enum orient" declaration in tkScale.h. */ @@ -675,13 +679,13 @@ valuePtr, &varValue) != TCL_OK)) { ScaleSetVariable(scalePtr); } else { char varString[TCL_DOUBLE_SPACE], scaleString[TCL_DOUBLE_SPACE]; - sprintf(varString, scalePtr->format, varValue); - sprintf(scaleString, scalePtr->format, scalePtr->value); - if (strcmp(varString, scaleString)) { + Tcl_PrintDouble(NULL, varValue, varString); + Tcl_PrintDouble(NULL, scalePtr->value, scaleString); + if (strcmp(varString, scaleString)) { ScaleSetVariable(scalePtr); } } Tcl_TraceVar2(interp, Tcl_GetString(scalePtr->varNamePtr), NULL, TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS, @@ -934,14 +938,20 @@ * Vertical scale: compute the amount of space needed to display the * scales value by formatting strings for the two end points; use * whichever length is longer. */ - sprintf(valueString, scalePtr->format, scalePtr->fromValue); + if (snprintf(valueString, TCL_DOUBLE_SPACE, scalePtr->format, + scalePtr->fromValue) < 0) { + valueString[TCL_DOUBLE_SPACE - 1] = '\0'; + } valuePixels = Tk_TextWidth(scalePtr->tkfont, valueString, -1); - sprintf(valueString, scalePtr->format, scalePtr->toValue); + if (snprintf(valueString, TCL_DOUBLE_SPACE, scalePtr->format, + scalePtr->toValue) < 0) { + valueString[TCL_DOUBLE_SPACE - 1] = '\0'; + } tmp = Tk_TextWidth(scalePtr->tkfont, valueString, -1); if (valuePixels < tmp) { valuePixels = tmp; } @@ -1179,10 +1189,23 @@ register TkScale *scalePtr = clientData; const char *resultStr; double value; Tcl_Obj *valuePtr; int result; + + /* + * See ticket [5d991b82]. + */ + + if (scalePtr->varNamePtr == NULL) { + if (!(flags & TCL_INTERP_DESTROYED)) { + Tcl_UntraceVar2(interp, name1, name2, + TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS, + ScaleVarProc, clientData); + } + return NULL; + } /* * If the variable is unset, then immediately recreate it unless the whole * interpreter is going away. */ @@ -1312,11 +1335,14 @@ register TkScale *scalePtr) /* Info about widget. */ { if (scalePtr->varNamePtr != NULL) { char string[TCL_DOUBLE_SPACE]; - sprintf(string, scalePtr->format, scalePtr->value); + if (snprintf(string, TCL_DOUBLE_SPACE, scalePtr->format, + scalePtr->value) < 0) { + string[TCL_DOUBLE_SPACE - 1] = '\0'; + } scalePtr->flags |= SETTING_VAR; Tcl_ObjSetVar2(scalePtr->interp, scalePtr->varNamePtr, NULL, Tcl_NewStringObj(string, -1), TCL_GLOBAL_ONLY); scalePtr->flags &= ~SETTING_VAR; } Index: generic/tkText.c ================================================================== --- generic/tkText.c +++ generic/tkText.c @@ -2076,11 +2076,11 @@ * already have values for some fields. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[]) /* Argument objects. */ { Tk_SavedOptions savedOptions; - int oldExport = textPtr->exportSelection; + int oldExport = (textPtr->exportSelection) && (!Tcl_IsSafe(textPtr->interp)); int mask = 0; if (Tk_SetOptions(interp, (char *) textPtr, textPtr->optionTable, objc, objv, textPtr->tkwin, &savedOptions, &mask) != TCL_OK) { return TCL_ERROR; @@ -2305,11 +2305,11 @@ /* * Claim the selection if we've suddenly started exporting it and there * are tagged characters. */ - if (textPtr->exportSelection && (!oldExport)) { + if (textPtr->exportSelection && (!oldExport) && (!Tcl_IsSafe(textPtr->interp))) { TkTextSearch search; TkTextIndex first, last; TkTextMakeByteIndex(textPtr->sharedTextPtr->tree, textPtr, 0, 0, &first); @@ -2724,14 +2724,18 @@ if (sharedTextPtr->refCount > PIXEL_CLIENTS) { ckfree(lineAndByteIndex); } /* - * Invalidate any selection retrievals in progress. + * Invalidate any selection retrievals in progress, and send an event + * that the selection changed if that is the case. */ for (tPtr = sharedTextPtr->peers; tPtr != NULL ; tPtr = tPtr->next) { + if (TkBTreeCharTagged(indexPtr, tPtr->selTagPtr)) { + TkTextSelectionEvent(tPtr); + } tPtr->abortSelections = 1; } /* * For convenience, return the length of the string. @@ -3067,10 +3071,13 @@ TkTextIndex index1, index2; TkText *tPtr; int *lineAndByteIndex; int resetViewCount; int pixels[2*PIXEL_CLIENTS]; + Tcl_HashSearch search; + Tcl_HashEntry *hPtr; + int i; if (sharedTextPtr == NULL) { sharedTextPtr = textPtr->sharedTextPtr; } @@ -3131,46 +3138,40 @@ } ckfree(arrayPtr); } } - if (line1 < line2) { - /* - * We are deleting more than one line. For speed, we remove all tags - * from the range first. If we don't do this, the code below can (when - * there are many tags) grow non-linearly in execution time. - */ - - Tcl_HashSearch search; - Tcl_HashEntry *hPtr; - int i; - - for (i=0, hPtr=Tcl_FirstHashEntry(&sharedTextPtr->tagTable, &search); - hPtr != NULL; i++, hPtr = Tcl_NextHashEntry(&search)) { - TkTextTag *tagPtr = Tcl_GetHashValue(hPtr); - - TkBTreeTag(&index1, &index2, tagPtr, 0); - } - - /* - * Special case for the sel tag which is not in the hash table. We - * need to do this once for each peer text widget. - */ - - for (tPtr = sharedTextPtr->peers; tPtr != NULL ; - tPtr = tPtr->next) { - if (TkBTreeTag(&index1, &index2, tPtr->selTagPtr, 0)) { - /* - * Send an event that the selection changed. This is - * equivalent to: - * event generate $textWidget <> - */ - - TkTextSelectionEvent(textPtr); - tPtr->abortSelections = 1; - } - } + /* + * For speed, we remove all tags from the range first. If we don't + * do this, the code below can (when there are many tags) grow + * non-linearly in execution time. + */ + + for (i=0, hPtr=Tcl_FirstHashEntry(&sharedTextPtr->tagTable, &search); + hPtr != NULL; i++, hPtr = Tcl_NextHashEntry(&search)) { + TkTextTag *tagPtr = Tcl_GetHashValue(hPtr); + + TkBTreeTag(&index1, &index2, tagPtr, 0); + } + + /* + * Special case for the sel tag which is not in the hash table. We + * need to do this once for each peer text widget. + */ + + for (tPtr = sharedTextPtr->peers; tPtr != NULL ; + tPtr = tPtr->next) { + if (TkBTreeTag(&index1, &index2, tPtr->selTagPtr, 0)) { + /* + * Send an event that the selection changed. This is + * equivalent to: + * event generate $textWidget <> + */ + + TkTextSelectionEvent(textPtr); + tPtr->abortSelections = 1; + } } /* * Tell the display what's about to happen so it can discard obsolete * display information, then do the deletion. Also, if the deletion @@ -3376,11 +3377,11 @@ TkTextIndex eof; int count, chunkSize, offsetInSeg; TkTextSearch search; TkTextSegment *segPtr; - if (!textPtr->exportSelection) { + if ((!textPtr->exportSelection) || Tcl_IsSafe(textPtr->interp)) { return -1; } /* * Find the beginning of the next range of selected text. Note: if the @@ -3506,11 +3507,11 @@ register TkText *textPtr = clientData; if (TkpAlwaysShowSelection(textPtr->tkwin)) { TkTextIndex start, end; - if (!textPtr->exportSelection) { + if ((!textPtr->exportSelection) || Tcl_IsSafe(textPtr->interp)) { return; } /* * On Windows and Mac systems, we want to remember the selection for @@ -3753,14 +3754,14 @@ "-hidden", "--", "-all", "-backwards", "-count", "-elide", "-exact", "-forwards", "-nocase", "-nolinestop", "-overlap", "-regexp", "-strictlimits", NULL }; enum SearchSwitches { - SEARCH_HIDDEN, - SEARCH_END, SEARCH_ALL, SEARCH_BACK, SEARCH_COUNT, SEARCH_ELIDE, - SEARCH_EXACT, SEARCH_FWD, SEARCH_NOCASE, - SEARCH_NOLINESTOP, SEARCH_OVERLAP, SEARCH_REGEXP, SEARCH_STRICTLIMITS + TK_TEXT_SEARCH_HIDDEN, + TK_TEXT_SEARCH_END, TK_TEXT_SEARCH_ALL, TK_TEXT_SEARCH_BACK, TK_TEXT_SEARCH_COUNT, TK_TEXT_SEARCH_ELIDE, + TK_TEXT_SEARCH_EXACT, TK_TEXT_SEARCH_FWD, TK_TEXT_SEARCH_NOCASE, + TK_TEXT_SEARCH_NOLINESTOP, TK_TEXT_SEARCH_OVERLAP, TK_TEXT_SEARCH_REGEXP, TK_TEXT_SEARCH_STRICTLIMITS }; /* * Set up the search specification, including the last 4 fields which are * text widget specific. @@ -3806,20 +3807,20 @@ sizeof(char *), "switch", 0, &index); return TCL_ERROR; } switch ((enum SearchSwitches) index) { - case SEARCH_END: + case TK_TEXT_SEARCH_END: i++; goto endOfSwitchProcessing; - case SEARCH_ALL: + case TK_TEXT_SEARCH_ALL: searchSpec.all = 1; break; - case SEARCH_BACK: + case TK_TEXT_SEARCH_BACK: searchSpec.backwards = 1; break; - case SEARCH_COUNT: + case TK_TEXT_SEARCH_COUNT: if (i >= objc-1) { Tcl_SetObjResult(interp, Tcl_NewStringObj( "no value given for \"-count\" option", -1)); Tcl_SetErrorCode(interp, "TK", "TEXT", "VALUE", NULL); return TCL_ERROR; @@ -3831,33 +3832,33 @@ * function, which is fair. */ searchSpec.varPtr = objv[i]; break; - case SEARCH_ELIDE: - case SEARCH_HIDDEN: + case TK_TEXT_SEARCH_ELIDE: + case TK_TEXT_SEARCH_HIDDEN: searchSpec.searchElide = 1; break; - case SEARCH_EXACT: + case TK_TEXT_SEARCH_EXACT: searchSpec.exact = 1; break; - case SEARCH_FWD: + case TK_TEXT_SEARCH_FWD: searchSpec.backwards = 0; break; - case SEARCH_NOCASE: + case TK_TEXT_SEARCH_NOCASE: searchSpec.noCase = 1; break; - case SEARCH_NOLINESTOP: + case TK_TEXT_SEARCH_NOLINESTOP: searchSpec.noLineStop = 1; break; - case SEARCH_OVERLAP: + case TK_TEXT_SEARCH_OVERLAP: searchSpec.overlap = 1; break; - case SEARCH_STRICTLIMITS: + case TK_TEXT_SEARCH_STRICTLIMITS: searchSpec.strictLimits = 1; break; - case SEARCH_REGEXP: + case TK_TEXT_SEARCH_REGEXP: searchSpec.exact = 0; break; default: Tcl_Panic("unexpected switch fallthrough"); } Index: generic/tkTextDisp.c ================================================================== --- generic/tkTextDisp.c +++ generic/tkTextDisp.c @@ -4118,12 +4118,12 @@ */ TkWindow *winPtr = (TkWindow *)(textPtr->tkwin); MacDrawable *macWin = winPtr->privatePtr; if (macWin && (macWin->flags & TK_DO_NOT_DRAW)){ dInfoPtr->flags &= ~REDRAW_PENDING; - return; - } + return; + } #endif if ((textPtr->tkwin == NULL) || (textPtr->flags & DESTROYED)) { /* * The widget has been deleted. Don't do anything. @@ -4272,11 +4272,10 @@ if (dlPtr->nextPtr == dlPtr2) { break; } dlPtr = dlPtr->nextPtr; } - /* * Scan through the lines following the copied ones to see if we are * going to overwrite them with the copy operation. If so, mark them * for redisplay. */ @@ -4296,13 +4295,11 @@ damageRgn = TkCreateRegion(); if (TkScrollWindow(textPtr->tkwin, dInfoPtr->scrollGC, dInfoPtr->x, oldY, dInfoPtr->maxX-dInfoPtr->x, height, 0, y-oldY, damageRgn)) { -#ifndef MAC_OSX_TK TextInvalidateRegion(textPtr, damageRgn); -#endif } numCopies++; TkDestroyRegion(damageRgn); } @@ -4440,15 +4437,42 @@ #endif /* TK_NO_DOUBLE_BUFFERING */ return; } dlPtr->oldY = dlPtr->y; dlPtr->flags &= ~(NEW_LAYOUT | OLD_Y_INVALID); +#ifdef MAC_OSX_TK + } else if (dlPtr->chunkPtr != NULL) { + /* + * On macOS we need to redisplay all embedded windows which + * were moved by the call to TkScrollWindows above. This is + * not necessary on Unix or Windows because XScrollWindow will + * have included the bounding rectangles of all of these + * windows in the damage region. The macosx implementation of + * TkScrollWindow does not do this. It simply generates a + * damage region which is the scroll source rectangle minus + * the scroll destination rectangle. This is because there is + * no efficient process available for iterating through the + * subwindows which meet the scrolled area. (On Unix this is + * handled by GraphicsExpose events generated by XCopyArea and + * on Windows by ScrollWindowEx. On macOS the low level + * scrolling is accomplished by calling [view scrollRect:by:]. + * This method does not provide any damage information and, in + * any case, could not be aware of Tk windows which were not + * based on NSView objects. + * + * On the other hand, this loop is already iterating through + * all embedded windows which could possibly have been moved + * by the scrolling. So it is as efficient to redisplay them + * here as it would have been if they had been redisplayed by + * the call to TextInvalidateRegion above. + */ +#else } else if (dlPtr->chunkPtr != NULL && ((dlPtr->y < 0) || (dlPtr->y + dlPtr->height > dInfoPtr->maxY))) { - register TkTextDispChunk *chunkPtr; - /* + * On platforms other than the Mac: + * * It's the first or last DLine which are also overlapping the * top or bottom of the window, but we decided above it wasn't * necessary to display them (we were able to update them by * scrolling). This is fine, except that if the lines contain * any embedded windows, we must still call the display proc @@ -4458,10 +4482,12 @@ * doesn't! * * So, we loop through all the chunks, calling the display * proc of embedded windows only. */ +#endif + register TkTextDispChunk *chunkPtr; for (chunkPtr = dlPtr->chunkPtr; (chunkPtr != NULL); chunkPtr = chunkPtr->nextPtr) { int x; if (chunkPtr->displayProc != TkTextEmbWinDisplayProc) { @@ -4480,17 +4506,22 @@ * right). */ x = -chunkPtr->width; } + if (tkTextDebug) { + char string[TK_POS_CHARS]; + + TkTextPrintIndex(textPtr, &dlPtr->index, string); + LOG("tk_textEmbWinDisplay", string); + } TkTextEmbWinDisplayProc(textPtr, chunkPtr, x, dlPtr->spaceAbove, dlPtr->height-dlPtr->spaceAbove-dlPtr->spaceBelow, dlPtr->baseline - dlPtr->spaceAbove, NULL, (Drawable) None, dlPtr->y + dlPtr->spaceAbove); } - } } #ifndef TK_NO_DOUBLE_BUFFERING Tk_FreePixmap(Tk_Display(textPtr->tkwin), pixmap); #endif /* TK_NO_DOUBLE_BUFFERING */ Index: generic/tkTextTag.c ================================================================== --- generic/tkTextTag.c +++ generic/tkTextTag.c @@ -241,10 +241,11 @@ */ TkTextSelectionEvent(textPtr); if (addTag && textPtr->exportSelection + && (!Tcl_IsSafe(textPtr->interp)) && !(textPtr->flags & GOT_SELECTION)) { Tk_OwnSelection(textPtr->tkwin, XA_PRIMARY, TkTextLostSelection, textPtr); textPtr->flags |= GOT_SELECTION; } Index: generic/ttk/ttkButton.c ================================================================== --- generic/ttk/ttkButton.c +++ generic/ttk/ttkButton.c @@ -487,24 +487,29 @@ static int CheckbuttonConfigure(Tcl_Interp *interp, void *recordPtr, int mask) { Checkbutton *checkPtr = recordPtr; - Ttk_TraceHandle *vt = Ttk_TraceVariable( - interp, checkPtr->checkbutton.variableObj, - CheckbuttonVariableChanged, checkPtr); - - if (!vt) { - return TCL_ERROR; + Tcl_Obj *varName = checkPtr->checkbutton.variableObj; + Ttk_TraceHandle *vt = NULL; + + if (varName != NULL && *Tcl_GetString(varName) != '\0') { + vt = Ttk_TraceVariable(interp, varName, + CheckbuttonVariableChanged, checkPtr); + if (!vt) { + return TCL_ERROR; + } } if (BaseConfigure(interp, recordPtr, mask) != TCL_OK){ Ttk_UntraceVariable(vt); return TCL_ERROR; } - Ttk_UntraceVariable(checkPtr->checkbutton.variableTrace); + if (checkPtr->checkbutton.variableTrace) { + Ttk_UntraceVariable(checkPtr->checkbutton.variableTrace); + } checkPtr->checkbutton.variableTrace = vt; return TCL_OK; } @@ -546,14 +551,17 @@ if (corePtr->state & TTK_STATE_SELECTED) newValue = checkPtr->checkbutton.offValueObj; else newValue = checkPtr->checkbutton.onValueObj; - if (Tcl_ObjSetVar2(interp, - checkPtr->checkbutton.variableObj, NULL, newValue, - TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG) - == NULL) + if (checkPtr->checkbutton.variableObj == NULL || + *Tcl_GetString(checkPtr->checkbutton.variableObj) == '\0') + CheckbuttonVariableChanged(checkPtr, Tcl_GetString(newValue)); + else if (Tcl_ObjSetVar2(interp, + checkPtr->checkbutton.variableObj, NULL, newValue, + TCL_GLOBAL_ONLY|TCL_LEAVE_ERR_MSG) + == NULL) return TCL_ERROR; if (WidgetDestroyed(corePtr)) return TCL_ERROR; Index: generic/ttk/ttkEntry.c ================================================================== --- generic/ttk/ttkEntry.c +++ generic/ttk/ttkEntry.c @@ -335,11 +335,12 @@ Entry *entryPtr = (Entry *) clientData; size_t byteCount; const char *string; const char *selStart, *selEnd; - if (entryPtr->entry.selectFirst < 0 || !entryPtr->entry.exportSelection) { + if (entryPtr->entry.selectFirst < 0 || (!entryPtr->entry.exportSelection) + || Tcl_IsSafe(entryPtr->core.interp)) { return -1; } string = entryPtr->entry.displayString; selStart = Tcl_UtfAtIndex(string, entryPtr->entry.selectFirst); @@ -370,15 +371,16 @@ TtkRedisplayWidget(&entryPtr->core); } /* EntryOwnSelection -- * Assert ownership of the PRIMARY selection, - * if -exportselection set and selection is present. + * if -exportselection set and selection is present and interp is unsafe. */ static void EntryOwnSelection(Entry *entryPtr) { if (entryPtr->entry.exportSelection + && (!Tcl_IsSafe(entryPtr->core.interp)) && !(entryPtr->core.flags & GOT_SELECTION)) { Tk_OwnSelection(entryPtr->core.tkwin, XA_PRIMARY, EntryLostSelection, (ClientData) entryPtr); entryPtr->core.flags |= GOT_SELECTION; } @@ -997,11 +999,12 @@ entryPtr->entry.textVariableTrace = vt; } /* Claim the selection, in case we've suddenly started exporting it. */ - if (entryPtr->entry.exportSelection && entryPtr->entry.selectFirst != -1) { + if (entryPtr->entry.exportSelection && (entryPtr->entry.selectFirst != -1) + && (!Tcl_IsSafe(entryPtr->core.interp))) { EntryOwnSelection(entryPtr); } /* Handle -state compatibility option: */ Index: generic/ttk/ttkProgress.c ================================================================== --- generic/ttk/ttkProgress.c +++ generic/ttk/ttkProgress.c @@ -419,25 +419,27 @@ (void)Tcl_GetDoubleFromObj(NULL, pb->progress.maximumObj, &maximum); value = fmod(value, maximum); } newValueObj = Tcl_NewDoubleObj(value); + Tcl_IncrRefCount(newValueObj); TtkRedisplayWidget(&pb->core); /* Update value by setting the linked -variable, if there is one: */ if (pb->progress.variableTrace) { - return Tcl_ObjSetVar2( - interp, pb->progress.variableObj, 0, newValueObj, - TCL_GLOBAL_ONLY | TCL_LEAVE_ERR_MSG) - ? TCL_OK : TCL_ERROR; + int result = Tcl_ObjSetVar2( + interp, pb->progress.variableObj, 0, newValueObj, + TCL_GLOBAL_ONLY | TCL_LEAVE_ERR_MSG) + ? TCL_OK : TCL_ERROR; + Tcl_DecrRefCount(newValueObj); + return result; } /* Otherwise, change the -value directly: */ - Tcl_IncrRefCount(newValueObj); Tcl_DecrRefCount(pb->progress.valueObj); pb->progress.valueObj = newValueObj; CheckAnimation(pb); return TCL_OK; Index: generic/ttk/ttkScale.c ================================================================== --- generic/ttk/ttkScale.c +++ generic/ttk/ttkScale.c @@ -13,10 +13,14 @@ #define DEF_SCALE_LENGTH "100" #define MAX(a,b) ((a) > (b) ? (a) : (b)) #define MIN(a,b) ((a) < (b) ? (a) : (b)) +/* Bit fields for OptionSpec mask field: + */ +#define STATE_CHANGED (0x100) /* -state option changed */ + /* * Scale widget record */ typedef struct { @@ -33,10 +37,15 @@ Tcl_Obj *variableObj; /* internal state */ Ttk_TraceHandle *variableTrace; + /* + * Compatibility/legacy options: + */ + Tcl_Obj *stateObj; + } ScalePart; typedef struct { WidgetCore core; @@ -63,10 +72,14 @@ {TK_OPTION_DOUBLE, "-value", "value", "Value", "0", Tk_Offset(Scale,scale.valueObj), -1, 0, 0, 0}, {TK_OPTION_PIXELS, "-length", "length", "Length", DEF_SCALE_LENGTH, Tk_Offset(Scale,scale.lengthObj), -1, 0, 0, GEOMETRY_CHANGED}, + + {TK_OPTION_STRING, "-state", "state", "State", + "normal", Tk_Offset(Scale,scale.stateObj), -1, + 0,0,STATE_CHANGED}, WIDGET_TAKEFOCUS_TRUE, WIDGET_INHERIT_OPTIONS(ttkCoreOptionSpecs) }; @@ -136,10 +149,14 @@ if (scale->scale.variableTrace) { Ttk_UntraceVariable(scale->scale.variableTrace); } scale->scale.variableTrace = vt; + + if (mask & STATE_CHANGED) { + TtkCheckStateOption(&scale->core, scale->scale.stateObj); + } return TCL_OK; } /* ScalePostConfigure -- Index: generic/ttk/ttkTrace.c ================================================================== --- generic/ttk/ttkTrace.c +++ generic/ttk/ttkTrace.c @@ -24,21 +24,32 @@ */ static char * VarTraceProc( ClientData clientData, /* Widget record pointer */ Tcl_Interp *interp, /* Interpreter containing variable. */ - const char *name1, /* (unused) */ - const char *name2, /* (unused) */ + const char *name1, /* Name of variable. */ + const char *name2, /* Second part of variable name. */ int flags) /* Information about what happened. */ { Ttk_TraceHandle *tracePtr = clientData; const char *name, *value; Tcl_Obj *valuePtr; if (flags & TCL_INTERP_DESTROYED) { return NULL; } + + /* + * See ticket [5d991b82]. + */ + + if (tracePtr->varnameObj == NULL) { + Tcl_UntraceVar2(interp, name1, name2, + TCL_GLOBAL_ONLY|TCL_TRACE_WRITES|TCL_TRACE_UNSETS, + VarTraceProc, clientData); + return NULL; + } name = Tcl_GetString(tracePtr->varnameObj); /* * If the variable is being unset, then re-establish the trace: ADDED library/demos/images/earthmenu.png Index: library/demos/images/earthmenu.png ================================================================== --- /dev/null +++ library/demos/images/earthmenu.png cannot compute difference between binary files Index: library/demos/menu.tcl ================================================================== --- library/demos/menu.tcl +++ library/demos/menu.tcl @@ -112,14 +112,16 @@ set m $w.menu.icon $w.menu add cascade -label "Icons" -menu $m -underline 0 menu $m -tearoff 0 # Main widget program sets variable tk_demoDirectory -$m add command -bitmap @[file join $tk_demoDirectory images pattern.xbm] \ +image create photo lilearth -file [file join $tk_demoDirectory \ +images earthmenu.png] +$m add command -image lilearth \ -hidemargin 1 -command [list \ tk_dialog $w.pattern {Bitmap Menu Entry} \ - "The menu entry you invoked displays a bitmap rather than\ + "The menu entry you invoked displays a photoimage rather than\ a text string. Other than this, it is just like any other\ menu entry." {} 0 OK ] foreach i {info questhead error} { $m add command -bitmap $i -hidemargin 1 -command [list \ puts "You invoked the $i bitmap" ] Index: library/demos/twind.tcl ================================================================== --- library/demos/twind.tcl +++ library/demos/twind.tcl @@ -81,16 +81,16 @@ $t window create end \ -create {button %W.peer -text "Make A Peer" -command "textMakePeer %W" \ -cursor top_left_arrow} -padx 3 $t insert end " widget. Notice how peer widgets can have different " $t insert end "font settings, and by default contain all the images " -$t insert end "of the 'parent', but many of the embedded windows, " -$t insert end "such as buttons will not be there. The easiest way " -$t insert end "to ensure they are in all peers is to use '-create' " -$t insert end "embedded window creation scripts " -$t insert end "(the plot above and the 'Make A Peer' button are " -$t insert end "designed to show up in all peers). A good use of " +$t insert end "of the 'parent', but that the embedded windows, " +$t insert end "such as buttons may not appear in the peer. To ensure " +$t insert end "that embedded windows appear in all peers you can set the " +$t insert end "'-create' option to a script or a string containing %W. " +$t insert end "(The plot above and the 'Make A Peer' button are " +$t insert end "designed to show up in all peers.) A good use of " $t insert end "peers is for " $t window create end \ -create {button %W.split -text "Split Windows" -command "textSplitWindow %W" \ -cursor top_left_arrow} -padx 3 $t insert end " \n\n" @@ -110,10 +110,11 @@ $t insert end "\"Short\", it changes to a longer string so that " $t insert end "you can see how the text widget automatically " $t insert end "changes the layout. Click on the button again " $t insert end "to restore the short string.\n" +$t insert end "\nNOTE: these buttons will not appear in peers!\n" "peer_warning" button $t.default -text Default -command "embDefBg $t" \ -cursor top_left_arrow $t window create end -window $t.default -padx 3 global embToggle set embToggle Short @@ -161,11 +162,10 @@ $t insert end "\n\nFinally, images fit comfortably in text widgets too:" $t image create end -image \ [image create photo -file [file join $tk_demoDirectory images ouster.png]] - proc textWindBigB w { $w configure -borderwidth 15 } @@ -300,10 +300,11 @@ set w [toplevel .peer$n] wm title $w "Text Peer #$n" frame $w.f -highlightthickness 1 -borderwidth 1 -relief sunken set t [$parent peer create $w.f.text -yscrollcommand "$w.scroll set" \ -borderwidth 0 -highlightthickness 0] + $t tag configure peer_warning -font boldFont pack $t -expand yes -fill both ttk::scrollbar $w.scroll -command "$t yview" pack $w.scroll -side right -fill y pack $w.f -expand yes -fill both } @@ -315,11 +316,12 @@ } else { set parent [winfo parent $textW] set w [winfo parent $parent] set t [$textW peer create $w.peer \ -yscrollcommand "$w.scroll set"] + $t tag configure peer_warning -font boldFont $w.pane add $t } } else { return } } Index: library/fontchooser.tcl ================================================================== --- library/fontchooser.tcl +++ library/fontchooser.tcl @@ -63,10 +63,13 @@ if {![winfo exists $S(W)]} { Create wm transient $S(W) [winfo toplevel $S(-parent)] tk::PlaceWindow $S(W) widget $S(-parent) } + set S(fonts) [lsort -dictionary [font families]] + set S(fonts,lcase) {} + foreach font $S(fonts) { lappend S(fonts,lcase) [string tolower $font]} wm deiconify $S(W) } proc ::tk::fontchooser::Hide {} { variable S Index: library/text.tcl ================================================================== --- library/text.tcl +++ library/text.tcl @@ -766,10 +766,13 @@ } else { $w tag add sel insert $new } $w mark set $anchorname insert } else { + if {[catch {$w index $anchorname}]} { + $w mark set $anchorname insert + } if {[$w compare $new < $anchorname]} { set first $new set last $anchorname } else { set first $anchorname @@ -1053,17 +1056,17 @@ proc ::tk_textCut w { if {![catch {set data [$w get sel.first sel.last]}]} { # make <> an atomic operation on the Undo stack, # i.e. separate it from other delete operations on either side set oldSeparator [$w cget -autoseparators] - if {$oldSeparator} { + if {([$w cget -state] eq "normal") && $oldSeparator} { $w edit separator } clipboard clear -displayof $w clipboard append -displayof $w $data $w delete sel.first sel.last - if {$oldSeparator} { + if {([$w cget -state] eq "normal") && $oldSeparator} { $w edit separator } } } Index: library/tk.tcl ================================================================== --- library/tk.tcl +++ library/tk.tcl @@ -9,11 +9,11 @@ # # See the file "license.terms" for information on usage and redistribution of # this file, and for a DISCLAIMER OF ALL WARRANTIES. # Verify that we have Tk binary and script components from the same release -package require -exact Tk 8.6.7 +package require -exact Tk 8.6.8 # Create a ::tk namespace namespace eval ::tk { # Set up the msgcat commands namespace eval msgcat { @@ -598,22 +598,23 @@ } # ::tk::AmpMenuArgs -- # Processes arguments for a menu entry, turning -label option into # -label and -underline options, returned by ::tk::UnderlineAmpersand. +# The cmd argument is supposed to be either "add" or "entryconfigure" # -proc ::tk::AmpMenuArgs {widget add type args} { +proc ::tk::AmpMenuArgs {widget cmd type args} { set options {} foreach {opt val} $args { if {$opt eq "-label"} { lassign [UnderlineAmpersand $val] newlabel under lappend options -label $newlabel -underline $under } else { lappend options $opt $val } } - $widget add $type {*}$options + $widget $cmd $type {*}$options } # ::tk::FindAltKeyTarget -- # Search recursively through the hierarchy of visible widgets to find # button or label which has $char as underlined character. Index: library/ttk/altTheme.tcl ================================================================== --- library/ttk/altTheme.tcl +++ library/ttk/altTheme.tcl @@ -93,12 +93,16 @@ # Treeview: ttk::style configure Heading -font TkHeadingFont -relief raised ttk::style configure Treeview -background $colors(-window) ttk::style map Treeview \ - -background [list selected $colors(-selectbg)] \ - -foreground [list selected $colors(-selectfg)] ; + -background [list disabled $colors(-frame)\ + {!disabled !selected} $colors(-window) \ + selected $colors(-selectbg)] \ + -foreground [list disabled $colors(-disabledfg) \ + {!disabled !selected} black \ + selected $colors(-selectfg)] ttk::style configure TScale \ -groovewidth 4 -troughrelief sunken \ -sliderwidth raised -borderwidth 2 ttk::style configure TProgressbar \ Index: library/ttk/aquaTheme.tcl ================================================================== --- library/ttk/aquaTheme.tcl +++ library/ttk/aquaTheme.tcl @@ -39,12 +39,17 @@ # Treeview: ttk::style configure Heading -font TkHeadingFont ttk::style configure Treeview -rowheight 18 -background White ttk::style map Treeview \ - -background {{selected background} systemHighlightSecondary - selected systemHighlight} + -background [list disabled systemDialogBackgroundInactive \ + {!disabled !selected} systemWindowBody \ + {selected background} systemHighlightSecondary \ + selected systemHighlight] \ + -foreground [list disabled systemModelessDialogInactiveText \ + {!disabled !selected} black \ + selected systemModelessDialogActiveText] # Enable animation for ttk::progressbar widget: ttk::style configure TProgressbar -period 100 -maxphase 255 # For Aqua, labelframe labels should appear outside the border, Index: library/ttk/clamTheme.tcl ================================================================== --- library/ttk/clamTheme.tcl +++ library/ttk/clamTheme.tcl @@ -129,12 +129,16 @@ # Treeview: ttk::style configure Heading \ -font TkHeadingFont -relief raised -padding {3} ttk::style configure Treeview -background $colors(-window) ttk::style map Treeview \ - -background [list selected $colors(-selectbg)] \ - -foreground [list selected $colors(-selectfg)] ; + -background [list disabled $colors(-frame)\ + {!disabled !selected} $colors(-window) \ + selected $colors(-selectbg)] \ + -foreground [list disabled $colors(-disabledfg) \ + {!disabled !selected} black \ + selected $colors(-selectfg)] ttk::style configure TLabelframe \ -labeloutside true -labelmargins {0 0 0 4} \ -borderwidth 2 -relief raised Index: library/ttk/classicTheme.tcl ================================================================== --- library/ttk/classicTheme.tcl +++ library/ttk/classicTheme.tcl @@ -96,12 +96,16 @@ # Treeview: ttk::style configure Heading -font TkHeadingFont -relief raised ttk::style configure Treeview -background $colors(-window) ttk::style map Treeview \ - -background [list selected $colors(-selectbg)] \ - -foreground [list selected $colors(-selectfg)] ; + -background [list disabled $colors(-frame)\ + {!disabled !selected} $colors(-window) \ + selected $colors(-selectbg)] \ + -foreground [list disabled $colors(-disabledfg) \ + {!disabled !selected} black \ + selected $colors(-selectfg)] # # Toolbar buttons: # ttk::style configure Toolbutton -padding 2 -relief flat -shiftrelief 2 Index: library/ttk/defaults.tcl ================================================================== --- library/ttk/defaults.tcl +++ library/ttk/defaults.tcl @@ -108,12 +108,16 @@ ttk::style configure Heading -font TkHeadingFont -relief raised ttk::style configure Treeview \ -background $colors(-window) \ -foreground $colors(-text) ; ttk::style map Treeview \ - -background [list selected $colors(-selectbg)] \ - -foreground [list selected $colors(-selectfg)] ; + -background [list disabled $colors(-frame)\ + {!disabled !selected} $colors(-window) \ + selected $colors(-selectbg)] \ + -foreground [list disabled $colors(-disabledfg) \ + {!disabled !selected} black \ + selected $colors(-selectfg)] # Combobox popdown frame ttk::style layout ComboboxPopdownFrame { ComboboxPopdownFrame.border -sticky nswe } Index: library/ttk/vistaTheme.tcl ================================================================== --- library/ttk/vistaTheme.tcl +++ library/ttk/vistaTheme.tcl @@ -44,12 +44,16 @@ # Treeview: ttk::style configure Heading -font TkHeadingFont ttk::style configure Treeview -background SystemWindow ttk::style map Treeview \ - -background [list selected SystemHighlight] \ - -foreground [list selected SystemHighlightText] ; + -background [list disabled SystemButtonFace \ + {!disabled !selected} SystemWindow \ + selected SystemHighlight] \ + -foreground [list disabled SystemGrayText \ + {!disabled !selected} SystemWindowText \ + selected SystemHighlightText] # Label and Toolbutton ttk::style configure TLabelframe.Label -foreground "#0046d5" ttk::style configure Toolbutton -padding {4 4} Index: library/ttk/winTheme.tcl ================================================================== --- library/ttk/winTheme.tcl +++ library/ttk/winTheme.tcl @@ -69,12 +69,16 @@ # Treeview: ttk::style configure Heading -font TkHeadingFont -relief raised ttk::style configure Treeview -background SystemWindow ttk::style map Treeview \ - -background [list selected SystemHighlight] \ - -foreground [list selected SystemHighlightText] ; + -background [list disabled SystemButtonFace \ + {!disabled !selected} SystemWindow \ + selected SystemHighlight] \ + -foreground [list disabled SystemGrayText \ + {!disabled !selected} SystemWindowText \ + selected SystemHighlightText] ttk::style configure TProgressbar \ -background SystemHighlight -borderwidth 0 ; } } Index: library/ttk/xpTheme.tcl ================================================================== --- library/ttk/xpTheme.tcl +++ library/ttk/xpTheme.tcl @@ -59,7 +59,17 @@ -selectforeground [list !focus SystemWindowText] \ ; ttk::style configure Toolbutton -padding {4 4} + # Treeview: + ttk::style configure Heading -font TkHeadingFont -relief raised + ttk::style configure Treeview -background SystemWindow + ttk::style map Treeview \ + -background [list disabled SystemButtonFace \ + {!disabled !selected} SystemWindow \ + selected SystemHighlight] \ + -foreground [list disabled SystemGrayText \ + {!disabled !selected} SystemWindowText \ + selected SystemHighlightText]; } } Index: macosx/README ================================================================== --- macosx/README +++ macosx/README @@ -1,42 +1,42 @@ -Tcl/Tk Mac OS X README +Tcl/Tk macOS README ---------------------- -This is the README file for the Mac OS X/Darwin version of Tcl/Tk. +This is the README file for the macOS/Darwin version of Tcl/Tk. 1. Where to go for support -------------------------- - The tcl-mac mailing list on sourceforge is the best place to ask questions -specific to Tcl & Tk on Mac OS X: +specific to Tcl & Tk on macOS: http://lists.sourceforge.net/lists/listinfo/tcl-mac (this page also has a link to searchable archives of the list, please check them before asking on the list, many questions have already been answered). - For general Tcl/Tk questions, the newsgroup comp.lang.tcl is your best bet: http://groups.google.com/group/comp.lang.tcl/ -- The Tcl'ers Wiki also has many pages dealing with Tcl & Tk on Mac OS X, see +- The Tcl'ers Wiki also has many pages dealing with Tcl & Tk on macOS, see http://wiki.tcl.tk/_/ref?N=3753 http://wiki.tcl.tk/_/ref?N=8361 -- Please report bugs with Tk on Mac OS X to the tracker: +- Please report bugs with Tk on macOS to the tracker: http://core.tcl.tk/tk/reportlist -2. Using Tcl/Tk on Mac OS X +2. Using Tcl/Tk on macOS --------------------------- -- There are two versions of Tk available on Mac OS X: TkAqua using the native +- There are two versions of Tk available on macOS: TkAqua using the native aqua widgets and look&feel, and TkX11 using the traditional unix X11 wigets. TkX11 requires an X11 server to be installed, such as Apple's X11 (which is -available as an optional or default install on recent Mac OS X). +available as an optional or default install on recent macOS). TkAqua and TkX11 can be distinguished at runtime via [tk windowingsystem]. -- At a minimum, Mac OS X 10.3 is required to run Tcl and TkX11. -TkAqua requires Mac OS X 10.5 or later (starting with the Cocoa-based Tk 8.5.7). +- At a minimum, macOS 10.3 is required to run Tcl and TkX11. +TkAqua requires macOS 10.6 or later. -- Unless weak-linking is used, Tcl/Tk built on Mac OS X 10.x will not run on +- Unless weak-linking is used, Tcl/Tk built on macOS 10.x will not run on 10.y with y < x; on the other hand Tcl/Tk built on 10.y will always run on 10.x with y <= x (but without any of the fixes and optimizations that would be available in a binary built on 10.x). Weak-linking is available on OS X 10.2 or later, it additionally allows Tcl/Tk built on 10.x to run on any 10.y with x > y >= z (for a chosen z >= 2). @@ -60,12 +60,11 @@ the Resources/Scripts directory of the framework. - [load]able binary extensions can linked as either ordinary shared libraries (.dylib) or as MachO bundles (since 8.4.10/8.5a3); bundles have the advantage that they are [load]ed more efficiently from a tcl VFS (no temporary copy to the -native filesystem required), and prior to Mac OS X 10.5, only bundles can be -[unload]ed. +native filesystem required). - The 'deploy' target of macosx/GNUmakefile installs the html manpages into the standard documentation location in the Tcl/Tk frameworks: Tcl.framework/Resources/Documentation/Reference/Tcl Tk.framework/Resources/Documentation/Reference/Tk @@ -161,11 +160,11 @@ present, this procedure is invoked instead by the standard Help menu item. Support for the Window menu and [tk::mac::ShowHelp] was added with the Cocoa-based Tk 8.5.7. - The TkAqua-specific command [tk::unsupported::MacWindowStyle style] is used to -get and set Mac OS X-specific toplevel window class and attributes. Note that +get and set macOS-specific toplevel window class and attributes. Note that the window class and many attributes have to be set before the window is first mapped for the change to have any effect. The command has the following syntax: tk::unsupported::MacWindowStyle style window ?class? ?attributes? The 2 argument form returns a list of the current class and attributes for the @@ -177,80 +176,46 @@ Window attribute names: standardDocument, standardFloating, resizable, fullZoom, horizontalZoom, verticalZoom, closeBox, collapseBox, toolbarButton, sideTitlebar, noTitleBar, unifiedTitleAndToolbar, metal, hud, noShadow, doesNotCycle, noActivates, hideOnSuspend, inWindowMenu, ignoreClicks, doesNotHide, - canJoinAllSpaces, moveToActiveSpace, nonActivating, black, dark, light, - gray, red, green, blue, cyan, yellow, magenta, orange, purple, - brown, clear, opacity + canJoinAllSpaces, moveToActiveSpace, nonActivating Note that not all attributes are valid for all window classes. Support for the 3 argument form was added with the Cocoa-based Tk 8.5.7, at the same time support for some legacy Carbon-specific classes and attributes was removed (they are still accepted by the command but no longer have any effect). -The color window attributes (black, dark, red, etc.) and the "opacity" allow one to set the background and opacity of a textured ("metal") window. This allows a Tk window to implement a window without the dividing line between the titlebar and the rest of the window, or the "unified toolbar" effect, which is increasingly standard in Mac applications. An example: - -toplevel .f -tk::unsupported::MacWindowStyle style .f document {metal light opaque closeBox collapseBox resizable standardDocument } - -pack [label .f.f -bg #ababab -text "This is a textured window\nwith opacity and a gray background\nsimilar to other Mac applications"] -fill both -expand yes - -The color attributes correspond to system-defined NSColor constants (e.g., red is [NSColor redColor]. The "light" and "dark" attributes correspond to lightGrayColor and darkGrayColor, respectively (because of the way the attributes are parsed, using "lightgray" and "darkgray" would cause a conflict with the core "gray" attribute). - -Below are the corresponding hex and/or Tk-defined colors that can be used from Tk widgets to match the NSColor-based attributes: - -black #000000 -dark #545454 -light #ababab -white #ffffff -gray #7f7f7f -red #ff0000 -green #00ff00 -blue #0000ff -cyan #00ffff -yellow #ffff00 -magenta #ff00ff -orange #ff8000 -purple #800080 -brown #996633 -clear systemTransparent - -- The Cocoa-based TkAqua can be distinguished from the older Carbon-based -version via the [winfo server .] command, example output on Mac OS X 10.5.7: - Cocoa-based: CG409.3 Apple AppKit GC 949.46 Mac OS X 1057 - Carbon-based: QD10R30 Apple 1057 - -- If you want to use Remote Debugging with Xcode, you need to set the +If you want to use Remote Debugging with Xcode, you need to set the environment variable XCNOSTDIN to 1 in the Executable editor for Wish. That will cause us to force closing stdin & stdout. Otherwise, given how Xcode launches Wish remotely, they will be left open and then Wish & gdb will fight for stdin. -3. Building Tcl/Tk on Mac OS X +3. Building Tcl/Tk on macOS ------------------------------ -- At least Mac OS X 10.3 is required to build Tcl and TkX11, and Mac OS X 10.5 -is required to build TkAqua. -Apple's Xcode Developer Tools need to be installed (only the most recent version -matching your OS release is supported), the Xcode installer is available on Mac -OS X install media or may be present in /Applications/Installers on Macs that -came with OS X preinstalled. The most recent version can always be downloaded -from the ADC website http://connect.apple.com (free ADC membership required). - -- Tcl/Tk are most easily built as Mac OS X frameworks via GNUmakefile in +- At least macOS 10.3 is required to build Tcl and TkX11, and macOS 10.6 +is required to build TkAqua. The XCode application provides everything +needed to build Tk, but it is not necessary to install the full XCode. +It suffices to install the Command Line Tools package, which can be done +by running the command: +xcode-selecct --install + +- Tcl/Tk are most easily built as macOS frameworks via GNUmakefile in tcl/macosx and tk/macosx (see below for details), but can also be built with the standard unix configure and make buildsystem in tcl/unix resp. tk/unix as on any other unix platform (indeed, the GNUmakefiles are just wrappers around the unix buildsystem). -The Mac OS X specific configure flags are --enable-aqua, --enable-framework and +The macOS specific configure flags are --enable-aqua, --enable-framework and --disable-corefoundation (which disables CF and notably reverts to the standard select based notifier). Note that --enable-aqua is incompatible with --disable-corefoundation (for both Tcl and Tk configure). -- It is also possible to build with the Xcode IDE via the projects in -tk/macosx, take care to use the project matching your DevTools and OS version: +- It was once possible to build with the Xcode IDE via the projects in +tk/macosx, but this has not been tested recently. Take care to use the +project matching your DevTools and OS version: Tk.xcode: for Xcode 3.1 on 10.5 Tk.xcodeproj: for Xcode 3.2 on 10.6 These have the following targets: Tk: calls through to tk/macosx/GNUMakefile, requires a corresponding build of the Tcl @@ -290,11 +255,11 @@ ${USER}.pbxuser file (located inside the Tk.xcodeproj bundle directory) with a text editor. - To build universal binaries outside of the Xcode IDE, set CFLAGS as follows: export CFLAGS="-arch i386 -arch x86_64 -arch ppc" -This requires Mac OS X 10.4 and Xcode 2.4 (or Xcode 2.2 if -arch x86_64 is +This requires macOS 10.4 and Xcode 2.4 (or Xcode 2.2 if -arch x86_64 is omitted, but _not_ Xcode 2.1) and will work on any architecture (on PowerPC Tiger you need to add "-isysroot /Developer/SDKs/MacOSX10.4u.sdk"). Note that configure requires CFLAGS to contain a least one architecture that can be run on the build machine (i.e. ppc on G3/G4, ppc or ppc64 on G5, ppc or i386 on Core and ppc, i386 or x86_64 on Core2/Xeon). @@ -301,13 +266,13 @@ Universal builds of Tcl TEA extensions are also possible with CFLAGS set as above, they will be [load]able by universal as well as thin binaries of Tcl. - To enable weak-linking, set the MACOSX_DEPLOYMENT_TARGET environment variable to the minimal OS version the binaries should be able to run on, e.g: - export MACOSX_DEPLOYMENT_TARGET=10.4 + export MACOSX_DEPLOYMENT_TARGET=10.6 This requires at least gcc 3.1; with gcc 4 or later, set/add to CFLAGS instead: - export CFLAGS="-mmacosx-version-min=10.4" + export CFLAGS="-mmacosx-version-min=10.6" Support for weak-linking was added with 8.4.14/8.5a5. Detailed Instructions for building with macosx/GNUmakefile ---------------------------------------------------------- @@ -387,65 +352,212 @@ TCL_FRAMEWORK_DIR=$HOME/Library/Frameworks TCLSH_DIR=$HOME/usr/bin sudo make -C tk${ver}/macosx install \ TCL_FRAMEWORK_DIR=$HOME/Library/Frameworks TCLSH_DIR=$HOME/usr/bin The Makefile variables TCL_FRAMEWORK_DIR and TCLSH_DIR were added with Tk 8.4.3. -4. About the event loop in Tk for Mac OSX ------------------------------------------ +4. Details regarding the macOS port of Tk. +------------------------------------------- + +4.1 About the event loop +~~~~~~~~~~~~~~~~~~~~~~~~ -The main program in a typical OSX application looks like this (see *) +The main program in a typical OSX application looks like this (see +https://developer.apple.com/library/mac/documentation/Cocoa/\ +Reference/ApplicationKit/Classes/NSApplication_Class) void NSApplicationMain(int argc, char *argv[]) { [NSApplication sharedApplication]; [NSBundle loadNibNamed:@"myMain" owner:NSApp]; [NSApp run]; } +Here NSApp is a standard global variable, initialized by the OS, which +points to an object in a subclass of NSApplication (called +TKApplication in the case of the macOS port of Tk). -The run method implements the event loop for the application. There -are three key steps in the run method. First it calls -[NSApp finishLaunching], which creates the bouncing application icon -and does other mysterious things. Second it creates an +The [NSApp run] method implements the event loop for a typical Mac +application. There are three key steps in the run method. First it +calls [NSApp finishLaunching], which creates the bouncing application +icon and does other mysterious things. Second it creates an NSAutoreleasePool. Third, it starts an event loop which drains the NSAutoreleasePool every time the queue is empty, and replaces the drained pool with a new one. This third step is essential to preventing memory leaks, since the internal methods of Appkit objects all assume that an autorelease pool is in scope and will be drained when the event processing cycle ends. -Mac OSX Tk does not call the [NSApp run] method at all. Instead it -uses the event loop built in to Tk. So we must take care to replicate -the important features of the method ourselves. Here is how this -works in outline. - -We add a private NSAUtoreleasePool* property to our subclass of -NSApplication. (The subclass is called TKApplication but can be -referenced with the global variable NSApp). The TkpInit -function calls [NSApp _setup] which initializes this property by -creating an NSAutoreleasePool. A bit later on, TkpInit calls -[NSAPP _setupEventLoop] which in turn calls the -[NSApp finishLaunching] method. - -Each time that Tcl processes an event in its queue, it calls a -platform specific function which, in the case of Mac OSX, is named -TkMacOSXEventsCheckProc. In the unix implementations of Tk, including -the Mac OSX version, this function collects events from an "event -source", and transfers them to the Tcl event queue. In Mac OSX the -event source is the NSApplication event queue. Each NSEvent is -converted to a Tcl event which is added to the Tcl event queue. The -NSEvent is also passed to [NSApp sendevent], which sends the event on -to the application's NSWindows, which send it to their NSViews, etc. +The macOS Tk application does not call the [NSApp run] method at +all. Instead it uses the event loop built in to Tk. So the +application must take care to replicate the important features of the +method ourselves. The way that autorelease pools are handled is +discussed in 4.2 below. Here we discuss the event handling itself. + +The Tcl event loop simply consists of repeated calls to TclDoOneEvent. +Each call to TclDoOneEvent begins by collecting all pending events from +an "event source", converting them to Tcl events and adding them +to the Tcl event queue. For macOS, the event source is the NSApp +object, which maintains an event queue even though its run method +will never be called to process them. The NSApp provides methods for +inspecting the queue and removing events from it as well as the +[NSApp sendevent] which sends an event to all of the application's +NSWindows which can then send it to subwindows, etc. + +The event collection process consists of first calling a platform +specific SetupProc and then a platform specific CheckProc. In +the macOS port, these are named TkMacOSXEventsSetupProc and +TkMacOSXEventsCheckProc. + +It is important to understand that the Apple window manager does not +have the concept of an expose event. Their replacement for an expose +event is to have the window manager call the [NSView drawRect] method +in any situation where an expose event for that NSView would be +generated in X11. The [NSView drawRect] method is a no-op which is +expected to be overridden by any application. In the case of Tcl, the +replacement [NSView drawRect] method creates a Tcl expose event +for each dirty rectangle of the NSView, and then adds the expose +event to the Tcl queue. + + +4.2 Autorelease pools +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +In order to carry out the job of managing autorelease pools, which +would normally be handled by the [NSApp run] method, a private +NSAUtoreleasePool* property is added to the TkApplication subclass of +NSApplication. The TkpInit function calls [NSApp _setup] which +initializes this property by creating an NSAutoreleasePool prior to +calling [NSApp finishLaunching]. This mimics the behavior of the +[NSApp run] method, which calls [NSApp finishLaunching] just before +starting the event loop. + Since the CheckProc function gets called for every Tk event, it is an appropriate place to drain the main NSAutoreleasePool and replace it -with a new pool. This is done by calling the method -[NSApp _resetAutoreleasePool], where _resetAutoreleasePool is a method -which we define for the subclass TKApplication. - -One minor caveat is that there are several steps of the Tk -initialization which precede the call to TkpInit. Notably, the font -package is initialized first. Since there is no NSAUtoreleasePool in -scope prior to calling TkpInit, the functions called in these -preliminary stages need to create and drain their own +with a new pool. This is done by calling the method [NSApp +_resetAutoreleasePool], where _resetAutoreleasePool is a method which +we define for the subclass. Unfortunately, by itself this is not +sufficient for safe memory managememt because, as was made painfully +evident with the release of OS X 10.13, it is possible for calls to +TclDoOneEvent, and hence to CheckProc, to be nested. Draining the +autorelease pool in a nested call leads to crashes as objects in use +by the outer call can get freed by the inner call and then reused later. +One particular situation where this happens is when a modal dialogue +gets posted by a Tk Application. To address this, the NSApp object +also implements a semaphore to prevent draining the autorelease pool +in nested calls to CheckProc. + +One additional minor caveat for developers is that there are several +steps of the Tk initialization which precede the call to TkpInit. +Notably, the font package is initialized first. Since there is no +NSAUtoreleasePool in scope prior to calling TkpInit, the functions +called in these preliminary stages need to create and drain their own NSAutoreleasePools whenever they call methods of Appkit objects (e.g. NSFont). -* https://developer.apple.com/library/mac/documentation/Cocoa/\ -Reference/ApplicationKit/Classes/NSApplication_Class +4.3 Clipping regions and "ghost windows" +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Another unusual aspect of the macOS port is its use of clipping +regions. It was part of Daniel Steffen's original design that the +TkWindowPrivate struct maintains three HIShapeRef regions, named +visRgn, aboveVisRgn and drawRgn. These regions are used as clipping +masks whenever drawing into an NSView. The visRgn is the bounding box +of the window with a rectangle removed for each subwindow and for each +sibling window at a higher stacking level. The drawRgn is the +intersection of the visRgn with the clipping rectangle of the +window. (Normally, the clipping rectangle is the same as the bounding +rectangle, but drawing can be clipped to a smaller rectangle by +calling TkpClipDrawableToRect.) The aboveVisRgn is the intersection of +the window's bounding rectangle with the bounding rectangle of the +parent window. Much of the code in tkMacOSXSubindows.c is devoted to +rebuilding these clipping regions whenever something changes in the +layout of the windows. This turns out to be a tricky thing to do and +it is extremely prone to errors which can be difficult to trace. + +It is not entirely clear what the original reason for using these +clipping regions was. But one benefit is that if they are correctly +maintained then it allows windows to be drawn in any order. You do +not have to draw them in the order of the window hierarchy. Each +window can draw its entire rectangle through its own mask and never +have to worry about drawing in the wrong place. It is likely that +the need for using clipping regions arose because, as Apple explicitly +states in the documentation for [NSView subviews], + + "The order of the subviews may be considered as being + back-to-front, but this does not imply invalidation and drawing + behavior." + +In the early versions of the macOS port, buttons were implemented as +subviews of class TkButton. This probably exacerbated the likelihood +that Tk windows would need to be drawn in arbitrary order. + +The most obvious side effect caused by not maintaining the clipping +regions is the appearance of so-called "ghost windows". A common +situation where these may arise is when a window containing buttons +is being scrolled. A user may see two images of the same button on +the screen, one in the pre-scroll location and one in the post-scroll +location. + +To see how these 'ghost windows' can arise, think about what happens if +the clipping regions are not maintained correctly. A window might +have a rectangle missing from its clipping region because that +rectangle is the bounding rectangle for a subwindow, say a button. +The parent should not draw in the missing rectangle since doing so +would trash the button. The button is responsible for drawing +there. Now imagine that the button gets moved, say by a scroll, but +the missing rectangle in the parent's clipping region does not get +moved correctly, or it gets moved later on, after the parent has +redrawn itself. The parent would still not be allowed to draw in the +old rectangle, so the user would continue to see the image of the +button in its old location, as well as another image in the new +location. This is a prototypical example of a "ghost window". +Anytime you see a "ghost window", you should suspect problems with the +updates to the clipping region visRgn. It is natural to look for +timing issues, race conditions, or other "event loop problems". But +in fact, the whole design of the code is to make those timing issues +irrelevant. As long as the clipping regions are correctly maintained +the timing does not matter. And if they are not correctly maintained +then you will see "ghost windows". + +It is worth including a detailed description of one specific place +where the failure to correctly maintain clipping regions caused "ghost +window" artifacts that plagued the macOS port for years. These +occurred when scrolling a Text widget which contained embedded +subwindows. It involved some specific differences between the +low-level behavior of Apple's window manager versus those of the other +platforms, and the fix ultimately required changes in the generic Tk +implementation (documented in the comments in the DisplayText +function). + +The Text widget attempts to improve perfomance when scrolling by +minimizing the number of text lines which need to be redisplayed. It +does this by calling the platform-specific TkScrollWindow function +which uses a low-level routine to map one rectangle of the window to +another. The TkScrollWindow function returns a damage region which is +then used by the Text widget's DisplayText function to determine which +text lines need to be redrawn. On the unix and win platforms, this +damage region includes bounding rectangles for all embedded windows +inside the Text widget. The way that this works is system dependent. +On unix, the low level scrolling is done by XCopyRegion, which +generates a GraphicsExpose event for each embedded window. These +GraphicsExposed events are processsed within TkScrollWindow, using a +special handler which adds the bounding rectangle of each subwindow to +the damage region. On the win platform the damage region is built by +the low level function ScrollWindowEx, and it also includes bounding +rectangles for all embedded windows. This is possible because on X11 +and Windows every Tk widget is also known to the window manager as a +window. The situation is different on macOS. The underlying object +for a top level window on macOS is the NSView. However, Apple +explicitly warns in its documentation that performance degradation +occurs when an NSView has more than about 100 subviews. A Text widget +with thousands of lines of text could easily contain more than 100 +embedded windows. In fact, while the original Cocoa port of Tk did +use the NSButton object, which is derived from NSView, as the basis +for its Tk Buttons, that was changed in order to improve performance. +Moreover, the low level routine used for scrolling on macOS, namely +[NSView scrollrect:by], does not provide any damage information. So +TkScrollWindow needs to work differently on macOS. Since it would be +inefficient to iterate through all embedded windows in a Text widget, +looking for those which meet the scrolling area, the damage region +constructed by TkScrollWindow contains only the difference between the +source and destination rectangles for the scrolling. The embedded +windows are redrawn within the DisplayText function by some +conditional code which is only used for macOS. + Index: macosx/Tk-Common.xcconfig ================================================================== --- macosx/Tk-Common.xcconfig +++ macosx/Tk-Common.xcconfig @@ -40,7 +40,7 @@ TCL_FRAMEWORK_DIR = $(SYMROOT)/../tcl/$(CONFIGURATION) TCL_LIBRARY = $(LIBDIR)/tcl$(VERSION) TCL_PACKAGE_PATH = "$(LIBDIR)" TCL_DEFS = HAVE_TCL_CONFIG_H TK_LIBRARY = $(LIBDIR)/tk$(VERSION) -TK_DEFS = HAVE_TK_CONFIG_H TCL_NO_DEPRECATED +TK_DEFS = HAVE_TK_CONFIG_H VERSION = 8.6 Index: macosx/Tk.xcode/project.pbxproj ================================================================== --- macosx/Tk.xcode/project.pbxproj +++ macosx/Tk.xcode/project.pbxproj @@ -1981,11 +1981,10 @@ F96D446C08F272B9004A47F5 /* tclXtNotify.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclXtNotify.c; sourceTree = ""; }; F96D446D08F272B9004A47F5 /* tclXtTest.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclXtTest.c; sourceTree = ""; }; F96D447008F272BA004A47F5 /* aclocal.m4 */ = {isa = PBXFileReference; explicitFileType = text.script.sh; fileEncoding = 4; path = aclocal.m4; sourceTree = ""; }; F96D447108F272BA004A47F5 /* buildall.vc.bat */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = buildall.vc.bat; sourceTree = ""; }; F96D447208F272BA004A47F5 /* cat.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = cat.c; sourceTree = ""; }; - F96D447308F272BA004A47F5 /* coffbase.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = coffbase.txt; sourceTree = ""; }; F96D447408F272BA004A47F5 /* configure */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = configure; sourceTree = ""; }; F96D447508F272BA004A47F5 /* configure.in */ = {isa = PBXFileReference; explicitFileType = text.script.sh; fileEncoding = 4; path = configure.in; sourceTree = ""; }; F96D447708F272BA004A47F5 /* Makefile.in */ = {isa = PBXFileReference; explicitFileType = sourcecode.make; fileEncoding = 4; path = Makefile.in; sourceTree = ""; }; F96D447808F272BA004A47F5 /* makefile.vc */ = {isa = PBXFileReference; explicitFileType = sourcecode.make; fileEncoding = 4; path = makefile.vc; sourceTree = ""; }; F96D447908F272BA004A47F5 /* nmakehlp.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = nmakehlp.c; sourceTree = ""; }; @@ -3814,11 +3813,10 @@ isa = PBXGroup; children = ( F96D447008F272BA004A47F5 /* aclocal.m4 */, F96D447108F272BA004A47F5 /* buildall.vc.bat */, F96D447208F272BA004A47F5 /* cat.c */, - F96D447308F272BA004A47F5 /* coffbase.txt */, F96D447408F272BA004A47F5 /* configure */, F96D447508F272BA004A47F5 /* configure.in */, F96D447708F272BA004A47F5 /* Makefile.in */, F96D447808F272BA004A47F5 /* makefile.vc */, F96D447908F272BA004A47F5 /* nmakehlp.c */, Index: macosx/Tk.xcodeproj/project.pbxproj ================================================================== --- macosx/Tk.xcodeproj/project.pbxproj +++ macosx/Tk.xcodeproj/project.pbxproj @@ -1981,11 +1981,10 @@ F96D446C08F272B9004A47F5 /* tclXtNotify.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclXtNotify.c; sourceTree = ""; }; F96D446D08F272B9004A47F5 /* tclXtTest.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = tclXtTest.c; sourceTree = ""; }; F96D447008F272BA004A47F5 /* aclocal.m4 */ = {isa = PBXFileReference; explicitFileType = text.script.sh; fileEncoding = 4; path = aclocal.m4; sourceTree = ""; }; F96D447108F272BA004A47F5 /* buildall.vc.bat */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = buildall.vc.bat; sourceTree = ""; }; F96D447208F272BA004A47F5 /* cat.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = cat.c; sourceTree = ""; }; - F96D447308F272BA004A47F5 /* coffbase.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = coffbase.txt; sourceTree = ""; }; F96D447408F272BA004A47F5 /* configure */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = configure; sourceTree = ""; }; F96D447508F272BA004A47F5 /* configure.in */ = {isa = PBXFileReference; explicitFileType = text.script.sh; fileEncoding = 4; path = configure.in; sourceTree = ""; }; F96D447708F272BA004A47F5 /* Makefile.in */ = {isa = PBXFileReference; explicitFileType = sourcecode.make; fileEncoding = 4; path = Makefile.in; sourceTree = ""; }; F96D447808F272BA004A47F5 /* makefile.vc */ = {isa = PBXFileReference; explicitFileType = sourcecode.make; fileEncoding = 4; path = makefile.vc; sourceTree = ""; }; F96D447908F272BA004A47F5 /* nmakehlp.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = nmakehlp.c; sourceTree = ""; }; @@ -3814,11 +3813,10 @@ isa = PBXGroup; children = ( F96D447008F272BA004A47F5 /* aclocal.m4 */, F96D447108F272BA004A47F5 /* buildall.vc.bat */, F96D447208F272BA004A47F5 /* cat.c */, - F96D447308F272BA004A47F5 /* coffbase.txt */, F96D447408F272BA004A47F5 /* configure */, F96D447508F272BA004A47F5 /* configure.in */, F96D447708F272BA004A47F5 /* Makefile.in */, F96D447808F272BA004A47F5 /* makefile.vc */, F96D447908F272BA004A47F5 /* nmakehlp.c */, Index: macosx/Wish-Info.plist.in ================================================================== --- macosx/Wish-Info.plist.in +++ macosx/Wish-Info.plist.in @@ -67,11 +67,11 @@ CFBundleSignature WiSH CFBundleVersion @TK_VERSION@@TK_PATCH_LEVEL@ LSMinimumSystemVersion - 10.5.0 + 10.6.0 LSRequiresCarbon NSAppleScriptEnabled OSAScriptingDefinition Index: macosx/tkMacOSXBitmap.c ================================================================== --- macosx/tkMacOSXBitmap.c +++ macosx/tkMacOSXBitmap.c @@ -10,11 +10,11 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. */ #include "tkMacOSXPrivate.h" - +#include "tkMacOSXConstants.h" /* * This structure holds information about native bitmaps. */ typedef struct { @@ -296,11 +296,11 @@ } } else { string = [NSString stringWithUTF8String:name]; image = [NSImage imageNamed:string]; if (!image) { - NSURL *url = [NSURL URLWithString:string]; + NSURL *url = [NSURL fileURLWithPath:string]; if (url) { image = [[[NSImage alloc] initWithContentsOfURL:url] autorelease]; } } Index: macosx/tkMacOSXButton.c ================================================================== --- macosx/tkMacOSXButton.c +++ macosx/tkMacOSXButton.c @@ -362,11 +362,12 @@ } else if (haveImage) { /* Image only */ width = butPtr->width > 0 ? butPtr->width : width + butPtr->indicatorSpace; height = butPtr->height > 0 ? butPtr->height : height; } else { /* Text only */ - width = txtWidth + butPtr->indicatorSpace; + /*Add four pixels of padding to width for text-only buttons to improve appearance.*/ + width = txtWidth + butPtr->indicatorSpace + 4; height = txtHeight; if (butPtr->width > 0) { width = butPtr->width * charWidth; } if (butPtr->height > 0) { Index: macosx/tkMacOSXColor.c ================================================================== --- macosx/tkMacOSXColor.c +++ macosx/tkMacOSXColor.c @@ -264,17 +264,13 @@ case TRANSPARENT_PIXEL: rgba[3] = 0.0; break; } - // this attempts to find something roughly fitting for any display -// *c = CGColorCreateGenericRGB(rgba[0], rgba[1], rgba[2], rgba[3]); - - // may be off for non-main display but in most cases better than prev static CGColorSpaceRef deviceRGBSpace = NULL; if (!deviceRGBSpace) { - deviceRGBSpace = CGDisplayCopyColorSpace(CGMainDisplayID()); + deviceRGBSpace = CGColorSpaceCreateDeviceRGB(); } *c = CGColorCreate(deviceRGBSpace, rgba ); } return err; } ADDED macosx/tkMacOSXConstants.h Index: macosx/tkMacOSXConstants.h ================================================================== --- /dev/null +++ macosx/tkMacOSXConstants.h @@ -0,0 +1,95 @@ +/* + * tkMacOSXConstants.h -- + * + * Macros which map the names of NS constants used in the Tk code to + * the new name that Apple came up with for subsequent versions of the + * operating system. (Each new OS release seems to come with a new + * naming convention for the same old constants.) + * + * Copyright (c) 2017 Marc Culler + * + * See the file "license.terms" for information on usage and redistribution + * of this file, and for a DISCLAIMER OF ALL WARRANTIES. + */ + +#ifndef _TKMACCONSTANTS +#define _TKMACCONSTANTS + +/* + * Let's raise a glass for the project manager who improves our lives by + * generating deprecation warnings about pointless changes of the names + * of constants. + */ + +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 101000 +#define NSOKButton NSModalResponseOK +#endif + +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 101200 +#define NSAppKitDefined NSEventTypeAppKitDefined +#define NSApplicationActivatedEventType NSEventSubtypeApplicationActivated +#define NSApplicationDeactivatedEventType NSEventSubtypeApplicationDeactivated +#define NSWindowExposedEventType NSEventSubtypeWindowExposed +#define NSScreenChangedEventType NSEventSubtypeScreenChanged +#define NSWindowMovedEventType NSEventSubtypeWindowMoved +#define NSKeyUp NSEventTypeKeyUp +#define NSKeyDown NSEventTypeKeyDown +#define NSFlagsChanged NSEventTypeFlagsChanged +#define NSLeftMouseDown NSEventTypeLeftMouseDown +#define NSLeftMouseUp NSEventTypeLeftMouseUp +#define NSRightMouseDown NSEventTypeRightMouseDown +#define NSRightMouseUp NSEventTypeRightMouseUp +#define NSLeftMouseDragged NSEventTypeLeftMouseDragged +#define NSRightMouseDragged NSEventTypeRightMouseDragged +#define NSMouseMoved NSEventTypeMouseMoved +#define NSMouseEntered NSEventTypeMouseEntered +#define NSMouseExited NSEventTypeMouseExited +#define NSScrollWheel NSEventTypeScrollWheel +#define NSOtherMouseDown NSEventTypeOtherMouseDown +#define NSOtherMouseUp NSEventTypeOtherMouseUp +#define NSOtherMouseDragged NSEventTypeOtherMouseDragged +#define NSTabletPoint NSEventTypeTabletPoint +#define NSTabletProximity NSEventTypeTabletProximity +#define NSDeviceIndependentModifierFlagsMask NSEventModifierFlagDeviceIndependentFlagsMask +#define NSCommandKeyMask NSEventModifierFlagCommand +#define NSShiftKeyMask NSEventModifierFlagShift +#define NSAlphaShiftKeyMask NSEventModifierFlagCapsLock +#define NSAlternateKeyMask NSEventModifierFlagOption +#define NSControlKeyMask NSEventModifierFlagControl +#define NSNumericPadKeyMask NSEventModifierFlagNumericPad +#define NSFunctionKeyMask NSEventModifierFlagFunction +#define NSCursorUpdate NSEventTypeCursorUpdate +#define NSTexturedBackgroundWindowMask NSWindowStyleMaskTexturedBackground +#define NSCompositeCopy NSCompositingOperationCopy +#define NSWarningAlertStyle NSAlertStyleWarning +#define NSInformationalAlertStyle NSAlertStyleInformational +#define NSCriticalAlertStyle NSAlertStyleCritical +#define NSCenterTextAlignment NSTextAlignmentCenter +#define NSDeviceIndependentModifierFlagsMask NSEventModifierFlagDeviceIndependentFlagsMask +#define NSCommandKeyMask NSEventModifierFlagCommand +#define NSShiftKeyMask NSEventModifierFlagShift +#define NSAlphaShiftKeyMask NSEventModifierFlagCapsLock +#define NSAlternateKeyMask NSEventModifierFlagOption +#define NSControlKeyMask NSEventModifierFlagControl +#define NSNumericPadKeyMask NSEventModifierFlagNumericPad +#define NSFunctionKeyMask NSEventModifierFlagFunction +#define NSKeyUp NSEventTypeKeyUp +#define NSKeyDown NSEventTypeKeyDown +#define NSFlagsChanged NSEventTypeFlagsChanged +#define NSAlphaShiftKeyMask NSEventModifierFlagCapsLock +#define NSShiftKeyMask NSEventModifierFlagShift +#define NSAnyEventMask NSEventMaskAny +#define NSTexturedBackgroundWindowMask NSWindowStyleMaskTexturedBackground +#define NSUtilityWindowMask NSWindowStyleMaskUtilityWindow +#define NSNonactivatingPanelMask NSWindowStyleMaskNonactivatingPanel +#define NSDocModalWindowMask NSWindowStyleMaskDocModalWindow +#define NSHUDWindowMask NSWindowStyleMaskHUDWindow +#define NSTitledWindowMask NSWindowStyleMaskTitled +#define NSClosableWindowMask NSWindowStyleMaskClosable +#define NSResizableWindowMask NSWindowStyleMaskResizable +#define NSUnifiedTitleAndToolbarWindowMask NSWindowStyleMaskUnifiedTitleAndToolbar +#define NSMiniaturizableWindowMask NSWindowStyleMaskMiniaturizable +#define NSBorderlessWindowMask NSWindowStyleMaskBorderless +#endif + +#endif Index: macosx/tkMacOSXDefault.h ================================================================== --- macosx/tkMacOSXDefault.h +++ macosx/tkMacOSXDefault.h @@ -323,15 +323,10 @@ #define DEF_MENU_POST_COMMAND "" #define DEF_MENU_RELIEF "flat" #define DEF_MENU_SELECT_COLOR "systemMenuActive" #define DEF_MENU_SELECT_MONO BLACK #define DEF_MENU_TAKE_FOCUS "0" - -/* - * FIXME: Turn the default back to 1 when we make tearoff menus work again. - */ - #define DEF_MENU_TEAROFF "0" #define DEF_MENU_TEAROFF_CMD ((char *) NULL) #define DEF_MENU_TITLE "" #define DEF_MENU_TYPE "normal" Index: macosx/tkMacOSXDialog.c ================================================================== --- macosx/tkMacOSXDialog.c +++ macosx/tkMacOSXDialog.c @@ -12,10 +12,11 @@ * this file, and for a DISCLAIMER OF ALL WARRANTIES. */ #include "tkMacOSXPrivate.h" #include "tkFileFilter.h" +#include "tkMacOSXConstants.h" #if MAC_OS_X_VERSION_MIN_REQUIRED < 1090 #define modalOK NSOKButton #define modalCancel NSCancelButton #else @@ -28,15 +29,20 @@ /*Vars for filtering in "open file" and "save file" dialogs.*/ typedef struct { bool doFileTypes; // show the accessory view which displays the filter menu bool preselectFilter; // a filter was selected by the typevariable bool userHasSelectedFilter; // The user has changed the filter in the accessory view + NSMutableArray *fileTypeNames; // array of names, e.g. "Text document" NSMutableArray *fileTypeExtensions; // array of allowed extensions per name, e.g. "txt", "doc" NSMutableArray *fileTypeLabels; // displayed string, e.g. "Text document (.txt, .doc)" - NSMutableArray *allAllowedExtensions; // set of all allowed extensions - NSInteger fileTypeIndex; // index of currently selected filter + NSMutableArray *fileTypeAllowsAll; // boolean if the all pattern (*.*) is included + + NSMutableArray *allowedExtensions; // set of all allowed extensions + bool allowedExtensionsAllowAll; // set of all allowed extensions includes *.* + + NSUInteger fileTypeIndex; // index of currently selected filter } filepanelFilterInfo; filepanelFilterInfo filterInfo; NSOpenPanel *openpanel; @@ -161,11 +167,10 @@ /* * Construct a file URL from directory and filename. Either may * be nil. If both are nil, returns nil. */ -#if MAC_OS_X_VERSION_MIN_REQUIRED > 1050 static NSURL *getFileURL(NSString *directory, NSString *filename) { NSURL *url = nil; if (directory) { url = [NSURL fileURLWithPath:directory isDirectory:YES]; } @@ -172,12 +177,10 @@ if (filename) { url = [NSURL URLWithString:filename relativeToURL:url]; } return url; } -#endif - #pragma mark TKApplication(TKDialog) @interface NSColorPanel(TKDialog) - (void) _setUseModalAppearance: (BOOL) flag; @@ -188,11 +191,11 @@ - (void) tkFilePanelDidEnd: (NSSavePanel *) panel returnCode: (NSInteger) returnCode contextInfo: (void *) contextInfo { FilePanelCallbackInfo *callbackInfo = contextInfo; - if (returnCode == NSFileHandlingPanelOKButton) { + if (returnCode == modalOK) { Tcl_Obj *resultObj; if (callbackInfo->multiple) { resultObj = Tcl_NewListObj(0, NULL); for (NSURL *url in [(NSOpenPanel*)panel URLs]) { @@ -216,11 +219,11 @@ ckfree(tmpv); } } else { Tcl_SetObjResult(callbackInfo->interp, resultObj); } - } else if (returnCode == NSFileHandlingPanelCancelButton) { + } else if (returnCode == modalCancel) { Tcl_ResetResult(callbackInfo->interp); } if (panel == [NSApp modalWindow]) { [NSApp stopModalWithCode:returnCode]; } @@ -266,23 +269,42 @@ ckfree(callbackInfo); } } - (void)selectFormat:(id)sender { - NSPopUpButton *button = (NSPopUpButton *)sender; - filterInfo.fileTypeIndex = [button indexOfSelectedItem]; - NSMutableArray *allowedtypes = filterInfo.fileTypeExtensions[filterInfo.fileTypeIndex]; - [openpanel setAllowedFileTypes:allowedtypes]; + NSPopUpButton *button = (NSPopUpButton *)sender; + filterInfo.fileTypeIndex = [button indexOfSelectedItem]; + + if ([[filterInfo.fileTypeAllowsAll objectAtIndex:filterInfo.fileTypeIndex] boolValue]) { + [openpanel setAllowsOtherFileTypes:YES]; + /* setAllowsOtherFileTypes might have no effect; it's inherited from the + * NSSavePanel, where it has the effect that it does not append an extension + * Setting the allowed file types to nil allows selecting any file */ + [openpanel setAllowedFileTypes:nil]; + } else { + NSMutableArray *allowedtypes = [filterInfo.fileTypeExtensions objectAtIndex:filterInfo.fileTypeIndex]; + [openpanel setAllowedFileTypes:allowedtypes]; + [openpanel setAllowsOtherFileTypes:NO]; + } + filterInfo.userHasSelectedFilter = true; - } - (void)saveFormat:(id)sender { - NSPopUpButton *button = (NSPopUpButton *)sender; - filterInfo.fileTypeIndex = [button indexOfSelectedItem]; - NSMutableArray *allowedtypes = filterInfo.fileTypeExtensions[filterInfo.fileTypeIndex]; - [savepanel setAllowedFileTypes:allowedtypes]; + NSPopUpButton *button = (NSPopUpButton *)sender; + filterInfo.fileTypeIndex = [button indexOfSelectedItem]; + + if ([[filterInfo.fileTypeAllowsAll objectAtIndex:filterInfo.fileTypeIndex] boolValue]) { + [savepanel setAllowsOtherFileTypes:YES]; + [savepanel setAllowedFileTypes:nil]; + } else { + NSMutableArray *allowedtypes = [filterInfo.fileTypeExtensions objectAtIndex:filterInfo.fileTypeIndex]; + [savepanel setAllowedFileTypes:allowedtypes]; + [savepanel setAllowsOtherFileTypes:NO]; + } + + filterInfo.userHasSelectedFilter = true; } @end #pragma mark - @@ -373,11 +395,11 @@ [colorPanel setColor:initialColor]; } returnCode = [NSApp runModalForWindow:colorPanel]; if (returnCode == modalOK) { color = [[colorPanel color] colorUsingColorSpace: - [NSColorSpace genericRGBColorSpace]]; + [NSColorSpace deviceRGBColorSpace]]; numberOfComponents = [color numberOfComponents]; } if (color && numberOfComponents >= 3 && numberOfComponents <= 4) { CGFloat components[4]; char colorstr[8]; @@ -417,43 +439,54 @@ filterInfo.fileTypeIndex = 0; filterInfo.fileTypeExtensions = [NSMutableArray array]; filterInfo.fileTypeNames = [NSMutableArray array]; filterInfo.fileTypeLabels = [NSMutableArray array]; - filterInfo.allAllowedExtensions = [NSMutableArray array]; + filterInfo.fileTypeAllowsAll = [NSMutableArray array]; + + filterInfo.allowedExtensions = [NSMutableArray array]; + filterInfo.allowedExtensionsAllowAll = NO; if (filterInfo.doFileTypes) { for (FileFilter *filterPtr = fl.filters; filterPtr; filterPtr = filterPtr->next) { NSString * name = [[NSString alloc] initWithUTF8String: filterPtr -> name]; [filterInfo.fileTypeNames addObject:name]; [name release]; NSMutableArray * clauseextensions = [NSMutableArray array]; NSMutableArray * displayextensions = [NSMutableArray array]; + bool allowsAll = NO; for (FileFilterClause *clausePtr = filterPtr->clauses; clausePtr; clausePtr = clausePtr->next) { + for (GlobPattern *globPtr = clausePtr->patterns; globPtr; globPtr = globPtr->next) { const char *str = globPtr->pattern; while (*str && (*str == '*' || *str == '.')) { str++; } if (*str) { NSString *extension = [[NSString alloc] initWithUTF8String:str]; - if (![filterInfo.allAllowedExtensions containsObject:extension]) { - [filterInfo.allAllowedExtensions addObject:extension]; + if (![filterInfo.allowedExtensions containsObject:extension]) { + [filterInfo.allowedExtensions addObject:extension]; } [clauseextensions addObject:extension]; [displayextensions addObject:[@"." stringByAppendingString:extension]]; [extension release]; + } else { + // it is the all pattern (*, .* or *.*) + allowsAll = YES; + filterInfo.allowedExtensionsAllowAll = YES; + [displayextensions addObject:@"*"]; } } } [filterInfo.fileTypeExtensions addObject:clauseextensions]; + [filterInfo.fileTypeAllowsAll addObject:[NSNumber numberWithBool:allowsAll]]; NSMutableString * label = [[NSMutableString alloc] initWithString:name]; [label appendString:@" ("]; [label appendString:[displayextensions componentsJoinedByString:@", "]]; [label appendString:@")"]; @@ -485,10 +518,21 @@ } TkFreeFileFilters(&fl); return TCL_OK; } + +bool filterCompatible(NSString *extension, int filterIndex) { + NSMutableArray *allowedExtensions = [filterInfo.fileTypeExtensions objectAtIndex: filterIndex]; + + /* If this contains the all pattern, accept any extension */ + if ([[filterInfo.fileTypeAllowsAll objectAtIndex:filterIndex] boolValue]) { + return true; + } + + return [allowedExtensions containsObject: extension]; +} /* *---------------------------------------------------------------------- * @@ -616,19 +660,19 @@ if (parseFileFilters(interp, fileTypesPtr, typeVariablePtr) != TCL_OK) { goto end; } if (filterInfo.doFileTypes) { - NSView *accessoryView = [[NSView alloc] initWithFrame:NSMakeRect(0.0, 0.0, 200, 32.0)]; + NSView *accessoryView = [[NSView alloc] initWithFrame:NSMakeRect(0.0, 0.0, 300, 32.0)]; NSTextField *label = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 60, 22)]; [label setEditable:NO]; - [label setStringValue:@"Enable:"]; + [label setStringValue:@"Filter:"]; [label setBordered:NO]; [label setBezeled:NO]; [label setDrawsBackground:NO]; - NSPopUpButton *popupButton = [[NSPopUpButton alloc] initWithFrame:NSMakeRect(50.0, 2, 140, 22.0) pullsDown:NO]; + NSPopUpButton *popupButton = [[NSPopUpButton alloc] initWithFrame:NSMakeRect(50.0, 2, 240, 22.0) pullsDown:NO]; [popupButton addItemsWithTitles:filterInfo.fileTypeLabels]; [popupButton setAction:@selector(selectFormat:)]; [accessoryView addSubview:label]; [accessoryView addSubview:popupButton]; @@ -638,17 +682,21 @@ * open the accessory view */ [popupButton selectItemAtIndex:filterInfo.fileTypeIndex]; /* on OSX > 10.11, the optons are not visible by default. Ergo allow all file types [openpanel setAllowedFileTypes:filterInfo.fileTypeExtensions[filterInfo.fileTypeIndex]]; */ - [openpanel setAllowedFileTypes:filterInfo.allAllowedExtensions]; + [openpanel setAllowedFileTypes:filterInfo.allowedExtensions]; + } else { + [openpanel setAllowedFileTypes:filterInfo.allowedExtensions]; + } + + if (filterInfo.allowedExtensionsAllowAll) { + [openpanel setAllowsOtherFileTypes:YES]; } else { - [openpanel setAllowedFileTypes:filterInfo.allAllowedExtensions]; + [openpanel setAllowsOtherFileTypes:NO]; } - [openpanel setAllowsOtherFileTypes:NO]; - [openpanel setAccessoryView:accessoryView]; } else { /* No filters are given. Allow picking all files */ [openpanel setAllowsOtherFileTypes:YES]; } @@ -664,21 +712,11 @@ callbackInfo->cmdObj = cmdObj; callbackInfo->interp = interp; callbackInfo->multiple = multiple; parent = TkMacOSXDrawableWindow(((TkWindow *) tkwin)->window); if (haveParentOption && parent && ![parent attachedSheet]) { - parentIsKey = [parent isKeyWindow]; -#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060 - [openpanel beginSheetForDirectory:directory - file:filename - types:openFileTypes - modalForWindow:parent - modalDelegate:NSApp - didEndSelector: - @selector(tkFilePanelDidEnd:returnCode:contextInfo:) - contextInfo:callbackInfo]; -#else + parentIsKey = [parent isKeyWindow]; if (directory || filename ) { NSURL * fileURL = getFileURL(directory, filename); [openpanel setDirectoryURL:fileURL]; } @@ -685,41 +723,73 @@ [openpanel beginSheetModalForWindow:parent completionHandler:^(NSInteger returnCode) { [NSApp tkFilePanelDidEnd:openpanel returnCode:returnCode contextInfo:callbackInfo ]; } ]; -#endif modalReturnCode = cmdObj ? modalOther : [NSApp runModalForWindow:openpanel]; } else { -#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060 - modalReturnCode = [openpanel runModalForDirectory:directory - file:filename]; -#else if (directory || filename ) { NSURL * fileURL = getFileURL(directory, filename); [openpanel setDirectoryURL:fileURL]; } modalReturnCode = [openpanel runModal]; -#endif [NSApp tkFilePanelDidEnd:openpanel returnCode:modalReturnCode contextInfo:callbackInfo]; } result = (modalReturnCode != modalError) ? TCL_OK : TCL_ERROR; if (parentIsKey) { [parent makeKeyWindow]; } if ((typeVariablePtr && (modalReturnCode == NSOKButton)) && - filterInfo.doFileTypes && filterInfo.userHasSelectedFilter) { + filterInfo.doFileTypes) { /* * The -typevariable must be set to the selected file type, if the dialog was not cancelled */ - #if 0 - NSLog(@"result: %i modal: %li", result, (long)modalReturnCode); - #endif - NSString * selectedFilter = filterInfo.fileTypeNames[filterInfo.fileTypeIndex]; + NSInteger selectedFilterIndex = filterInfo.fileTypeIndex; + NSString *selectedFilter = NULL; + if (filterInfo.userHasSelectedFilter) { + selectedFilterIndex = filterInfo.fileTypeIndex; + selectedFilter = [filterInfo.fileTypeNames objectAtIndex:selectedFilterIndex]; + } else { + /* Difficult case: the user has not touched the filter settings, but we must + * return something in the typevariable. First check if the preselected type is compatible + * with the selected file, otherwise choose the first compatible type from the list, + * finally fall back to the empty string */ + NSURL *selectedFile; + if (multiple) { + // Use the first file in the case of multiple selection + // Anyway it is not overly useful here + selectedFile = [[openpanel URLs] objectAtIndex:0]; + } else { + selectedFile = [openpanel URL]; + } + + NSString *extension = [selectedFile pathExtension]; + if (filterInfo.preselectFilter && + filterCompatible(extension, filterInfo.fileTypeIndex)) { + selectedFilterIndex = filterInfo.fileTypeIndex; // The preselection from the typevariable + selectedFilter = [filterInfo.fileTypeNames objectAtIndex:selectedFilterIndex]; + } else { + // scan the list + int i; + for (i = 0; i < [filterInfo.fileTypeNames count]; i++) { + if (filterCompatible(extension, i)) { + selectedFilterIndex = i; + break; + } + } + if (i == selectedFilterIndex) { + selectedFilter = [filterInfo.fileTypeNames objectAtIndex:selectedFilterIndex]; + } else { + selectedFilter = @""; + } + + } + } + Tcl_ObjSetVar2(interp, typeVariablePtr, NULL, Tcl_NewStringObj([selectedFilter UTF8String], -1), TCL_GLOBAL_ONLY); } @@ -864,30 +934,30 @@ if (parseFileFilters(interp, fileTypesPtr, typeVariablePtr) != TCL_OK) { goto end; } if (filterInfo.doFileTypes) { - NSView *accessoryView = [[NSView alloc] initWithFrame:NSMakeRect(0.0, 0.0, 200, 32.0)]; + NSView *accessoryView = [[NSView alloc] initWithFrame:NSMakeRect(0.0, 0.0, 300, 32.0)]; NSTextField *label = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 60, 22)]; [label setEditable:NO]; [label setStringValue:NSLocalizedString(@"Format:", nil)]; [label setBordered:NO]; [label setBezeled:NO]; [label setDrawsBackground:NO]; - NSPopUpButton *popupButton = [[NSPopUpButton alloc] initWithFrame:NSMakeRect(50.0, 2, 140, 22.0) pullsDown:NO]; + NSPopUpButton *popupButton = [[NSPopUpButton alloc] initWithFrame:NSMakeRect(50.0, 2, 340, 22.0) pullsDown:NO]; [popupButton addItemsWithTitles:filterInfo.fileTypeLabels]; [popupButton selectItemAtIndex:filterInfo.fileTypeIndex]; [popupButton setAction:@selector(saveFormat:)]; [accessoryView addSubview:label]; [accessoryView addSubview:popupButton]; [savepanel setAccessoryView:accessoryView]; - [savepanel setAllowedFileTypes:filterInfo.fileTypeExtensions[filterInfo.fileTypeIndex]]; - [savepanel setAllowsOtherFileTypes:NO]; + [savepanel setAllowedFileTypes:[filterInfo.fileTypeExtensions objectAtIndex:filterInfo.fileTypeIndex]]; + [savepanel setAllowsOtherFileTypes:filterInfo.allowedExtensionsAllowAll]; } else if (defaultType) { /* If no filetypes are given, defaultextension is an alternative way * to specify the attached extension. Just propose this extension, * but don't display an accessory view */ NSMutableArray *AllowedFileTypes = [NSMutableArray array]; @@ -911,20 +981,11 @@ callbackInfo->multiple = 0; parent = TkMacOSXDrawableWindow(((TkWindow *) tkwin)->window); if (haveParentOption && parent && ![parent attachedSheet]) { parentIsKey = [parent isKeyWindow]; -#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060 - [savepanel beginSheetForDirectory:directory - file:filename - modalForWindow:parent - modalDelegate:NSApp - didEndSelector: - @selector(tkFilePanelDidEnd:returnCode:contextInfo:) - contextInfo:callbackInfo]; -#else - if (directory) { + if (directory) { [savepanel setDirectoryURL:[NSURL fileURLWithPath:directory isDirectory:YES]]; } /*check for file name, otherwise set to empty string; crashes with uncaught exception if set to nil*/ if (filename) { [savepanel setNameFieldStringValue:filename]; @@ -934,16 +995,12 @@ [savepanel beginSheetModalForWindow:parent completionHandler:^(NSInteger returnCode) { [NSApp tkFilePanelDidEnd:savepanel returnCode:returnCode contextInfo:callbackInfo ]; } ]; -#endif modalReturnCode = cmdObj ? modalOther : [NSApp runModalForWindow:savepanel]; } else { -#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060 - modalReturnCode = [savepanel runModalForDirectory:directory file:filename]; -#else if (directory) { [savepanel setDirectoryURL:[NSURL fileURLWithPath:directory isDirectory:YES]]; } /*check for file name, otherwise set to empty string; crashes with uncaught exception if set to nil*/ if (filename) { @@ -950,14 +1007,10 @@ [savepanel setNameFieldStringValue:filename]; } else { [savepanel setNameFieldStringValue:@""]; } modalReturnCode = [savepanel runModal]; - #if 0 - NSLog(@"modal: %li", modalReturnCode); - #endif -#endif [NSApp tkFilePanelDidEnd:savepanel returnCode:modalReturnCode contextInfo:callbackInfo]; } result = (modalReturnCode != modalError) ? TCL_OK : TCL_ERROR; if (parentIsKey) { @@ -966,14 +1019,11 @@ if ((typeVariablePtr && (modalReturnCode == NSOKButton)) && filterInfo.doFileTypes) { /* * The -typevariable must be set to the selected file type, if the dialog was not cancelled */ - #if 0 - NSLog(@"result: %i modal: %li", result, (long)modalReturnCode); - #endif - NSString * selectedFilter = filterInfo.fileTypeNames[filterInfo.fileTypeIndex]; + NSString * selectedFilter = [filterInfo.fileTypeNames objectAtIndex:filterInfo.fileTypeIndex]; Tcl_ObjSetVar2(interp, typeVariablePtr, NULL, Tcl_NewStringObj([selectedFilter UTF8String], -1), TCL_GLOBAL_ONLY); } @@ -1088,34 +1138,21 @@ if (!directory) { directory = @"/"; } parent = TkMacOSXDrawableWindow(((TkWindow *) tkwin)->window); if (haveParentOption && parent && ![parent attachedSheet]) { - parentIsKey = [parent isKeyWindow]; -#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060 - [panel beginSheetForDirectory:directory - file:nil - modalForWindow:parent - modalDelegate:NSApp - didEndSelector: @selector(tkFilePanelDidEnd:returnCode:contextInfo:) - contextInfo:callbackInfo]; -#else + parentIsKey = [parent isKeyWindow]; [panel setDirectoryURL:[NSURL fileURLWithPath:directory isDirectory:YES]]; [panel beginSheetModalForWindow:parent completionHandler:^(NSInteger returnCode) { [NSApp tkFilePanelDidEnd:panel returnCode:returnCode contextInfo:callbackInfo ]; } ]; -#endif modalReturnCode = cmdObj ? modalOther : [NSApp runModalForWindow:panel]; } else { -#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060 - modalReturnCode = [panel runModalForDirectory:directory file:nil]; -#else [panel setDirectoryURL:[NSURL fileURLWithPath:directory isDirectory:YES]]; modalReturnCode = [panel runModal]; -#endif [NSApp tkFilePanelDidEnd:panel returnCode:modalReturnCode contextInfo:callbackInfo]; } result = (modalReturnCode != modalError) ? TCL_OK : TCL_ERROR; if (parentIsKey) { Index: macosx/tkMacOSXDraw.c ================================================================== --- macosx/tkMacOSXDraw.c +++ macosx/tkMacOSXDraw.c @@ -14,11 +14,10 @@ * of this file, and for a DISCLAIMER OF ALL WARRANTIES. */ #include "tkMacOSXPrivate.h" #include "tkMacOSXDebug.h" -#include "xbytes.h" #include "tkButton.h" /* #ifdef TK_MAC_DEBUG #define TK_MAC_DEBUG_DRAWING @@ -43,16 +42,10 @@ /* * Prototypes for functions used only in this file. */ static void ClipToGC(Drawable d, GC gc, HIShapeRef *clipRgnPtr); -static CGImageRef CreateCGImageWithXImage(XImage *ximage); -static CGContextRef GetCGContextForDrawable(Drawable d); -static void DrawCGImage(Drawable d, GC gc, CGContextRef context, CGImageRef image, - unsigned long imageForeground, unsigned long imageBackground, - CGRect imageBounds, CGRect srcBounds, CGRect dstBounds); - /* *---------------------------------------------------------------------- * * TkMacOSXInitCGDrawing -- @@ -106,17 +99,18 @@ } /* *---------------------------------------------------------------------- * - * BitmapRepFromDrawableRect + * TkMacOSXBitmapRepFromDrawableRect * * Extract bitmap data from a MacOSX drawable as an NSBitmapImageRep. * * Results: - * Returns an autoreleased NSBitmapRep representing the image of the given - * rectangle of the given drawable. + * Returns an NSBitmapRep representing the image of the given + * rectangle of the given drawable. This object is retained. + * The caller is responsible for releasing it. * * NOTE: The x,y coordinates should be relative to a coordinate system with * origin at the top left, as used by XImage and CGImage, not bottom * left as used by NSView. * @@ -124,11 +118,11 @@ * None * *---------------------------------------------------------------------- */ NSBitmapImageRep* -BitmapRepFromDrawableRect( +TkMacOSXBitmapRepFromDrawableRect( Drawable drawable, int x, int y, unsigned int width, unsigned int height) @@ -138,34 +132,34 @@ CGImageRef cg_image=NULL, sub_cg_image=NULL; NSBitmapImageRep *bitmap_rep=NULL; NSView *view=NULL; if ( mac_drawable->flags & TK_IS_PIXMAP ) { /* - This means that the MacDrawable is functioning as a Tk Pixmap, so its view - field is NULL. + * This means that the MacDrawable is functioning as a + * Tk Pixmap, so its view field is NULL. */ - cg_context = GetCGContextForDrawable(drawable); + cg_context = TkMacOSXGetCGContextForDrawable(drawable); CGRect image_rect = CGRectMake(x, y, width, height); cg_image = CGBitmapContextCreateImage( (CGContextRef) cg_context); sub_cg_image = CGImageCreateWithImageInRect(cg_image, image_rect); if ( sub_cg_image ) { - /*This can be dealloc'ed prematurely if set for autorelease, causing crashes.*/ bitmap_rep = [NSBitmapImageRep alloc]; [bitmap_rep initWithCGImage:sub_cg_image]; } if ( cg_image ) { CGImageRelease(cg_image); } } else if ( (view = TkMacOSXDrawableView(mac_drawable)) ) { - /* convert top-left coordinates to NSView coordinates */ + /* + * Convert Tk top-left to NSView bottom-left coordinates. + */ int view_height = [view bounds].size.height; NSRect view_rect = NSMakeRect(x + mac_drawable->xOff, - view_height - height - y - mac_drawable->yOff, - width,height); + view_height - height - y - mac_drawable->yOff, + width, height); if ( [view lockFocusIfCanDraw] ) { - /*This can be dealloc'ed prematurely if set for autorelease, causing crashes.*/ bitmap_rep = [NSBitmapImageRep alloc]; bitmap_rep = [bitmap_rep initWithFocusedViewRect:view_rect]; [view unlockFocus]; } else { TkMacOSXDbgMsg("Could not lock focus on view."); @@ -228,20 +222,20 @@ if ( dc.context ) { if (srcDraw->flags & TK_IS_PIXMAP) { img = TkMacOSXCreateCGImageWithDrawable(src); }else if (TkMacOSXDrawableWindow(src)) { - bitmap_rep = BitmapRepFromDrawableRect(src, src_x, src_y, width, height); + bitmap_rep = TkMacOSXBitmapRepFromDrawableRect(src, src_x, src_y, width, height); if ( bitmap_rep ) { img = [bitmap_rep CGImage]; } } else { TkMacOSXDbgMsg("Invalid source drawable - neither window nor pixmap."); } if (img) { - DrawCGImage(dst, gc, dc.context, img, gc->foreground, gc->background, + TkMacOSXDrawCGImage(dst, gc, dc.context, img, gc->foreground, gc->background, CGRectMake(0, 0, srcDraw->size.width, srcDraw->size.height), CGRectMake(src_x, src_y, width, height), CGRectMake(dest_x, dest_y, width, height)); CFRelease(img); @@ -337,11 +331,11 @@ CGImageRelease(img); CGImageRelease(mask); CGImageRelease(submask); CGImageRelease(subimage); } else { - DrawCGImage(dst, gc, dc.context, img, gc->foreground, imageBackground, + TkMacOSXDrawCGImage(dst, gc, dc.context, img, gc->foreground, imageBackground, CGRectMake(0, 0, srcDraw->size.width, srcDraw->size.height), CGRectMake(src_x, src_y, width, height), CGRectMake(dest_x, dest_y, width, height)); CGImageRelease(img); } @@ -354,162 +348,10 @@ TkMacOSXRestoreDrawingContext(&dc); } else { /* source drawable is a window, not a Pixmap */ XCopyArea(display, src, dst, gc, src_x, src_y, width, height, dest_x, dest_y); } } - -/* - *---------------------------------------------------------------------- - * - * TkPutImage -- - * - * Copies a subimage from an in-memory image to a rectangle of - * of the specified drawable. - * - * Results: - * None. - * - * Side effects: - * Draws the image on the specified drawable. - * - *---------------------------------------------------------------------- - */ - -int -TkPutImage( - unsigned long *colors, /* Unused on Macintosh. */ - int ncolors, /* Unused on Macintosh. */ - Display* display, /* Display. */ - Drawable d, /* Drawable to place image on. */ - GC gc, /* GC to use. */ - XImage* image, /* Image to place. */ - int src_x, /* Source X & Y. */ - int src_y, - int dest_x, /* Destination X & Y. */ - int dest_y, - unsigned int width, /* Same width & height for both */ - unsigned int height) /* distination and source. */ -{ - TkMacOSXDrawingContext dc; - - display->request++; - if (!TkMacOSXSetupDrawingContext(d, gc, 1, &dc)) { - return BadDrawable; - } - if (dc.context) { - CGImageRef img = CreateCGImageWithXImage(image); - - if (img) { - /* If the XImage has big pixels, rescale the source dimensions.*/ - int pp = image->pixelpower; - DrawCGImage(d, gc, dc.context, img, gc->foreground, gc->background, - CGRectMake(0, 0, image->width<height<bytes_per_line * image->height; - const CGFloat *decode = NULL; - CGBitmapInfo bitmapInfo; - CGDataProviderRef provider = NULL; - char *data = NULL; - CGDataProviderReleaseDataCallback releaseData = ReleaseData; - - if (image->bits_per_pixel == 1) { - /* - * BW image - */ - - /* Reverses the sense of the bits */ - static const CGFloat decodeWB[2] = {1, 0}; - decode = decodeWB; - - bitsPerComponent = 1; - bitsPerPixel = 1; - if (image->bitmap_bit_order != MSBFirst) { - char *srcPtr = image->data + image->xoffset; - char *endPtr = srcPtr + len; - char *destPtr = (data = ckalloc(len)); - - while (srcPtr < endPtr) { - *destPtr++ = xBitReverseTable[(unsigned char)(*(srcPtr++))]; - } - } else { - data = memcpy(ckalloc(len), image->data + image->xoffset, len); - } - if (data) { - provider = CGDataProviderCreateWithData(data, data, len, releaseData); - } - if (provider) { - img = CGImageMaskCreate(image->width, image->height, bitsPerComponent, - bitsPerPixel, image->bytes_per_line, provider, decode, 0); - } - } else if (image->format == ZPixmap && image->bits_per_pixel == 32) { - /* - * Color image - */ - - CGColorSpaceRef colorspace = CGColorSpaceCreateWithName(kCGColorSpaceSRGB); - - bitsPerComponent = 8; - bitsPerPixel = 32; - bitmapInfo = (image->byte_order == MSBFirst ? - kCGBitmapByteOrder32Big : kCGBitmapByteOrder32Little) | - kCGImageAlphaNoneSkipFirst; - data = memcpy(ckalloc(len), image->data + image->xoffset, len); - if (data) { - provider = CGDataProviderCreateWithData(data, data, len, releaseData); - } - if (provider) { - img = CGImageCreate(image->width, image->height, bitsPerComponent, - bitsPerPixel, image->bytes_per_line, colorspace, bitmapInfo, - provider, decode, 0, kCGRenderingIntentDefault); - CFRelease(provider); - } - if (colorspace) { - CFRelease(colorspace); - } - } else { - TkMacOSXDbgMsg("Unsupported image type"); - } - return img; -} /* *---------------------------------------------------------------------- * * TkMacOSXCreateCGImageWithDrawable -- @@ -528,11 +370,11 @@ CGImageRef TkMacOSXCreateCGImageWithDrawable( Drawable drawable) { CGImageRef img = NULL; - CGContextRef context = GetCGContextForDrawable(drawable); + CGContextRef context = TkMacOSXGetCGContextForDrawable(drawable); if (context) { img = CGBitmapContextCreateImage(context); } return img; @@ -596,12 +438,14 @@ Tk_Image image, int width, int height) { Pixmap pixmap = Tk_GetPixmap(display, None, width, height, 0); + MacDrawable *macDraw = (MacDrawable *) pixmap; NSImage *nsImage; + macDraw->flags |= TK_USE_XIMAGE_ALPHA; Tk_RedrawImage(image, 0, 0, width, height, pixmap, 0, 0); nsImage = CreateNSImageWithPixmap(pixmap, width, height); Tk_FreePixmap(display, pixmap); return [nsImage autorelease]; @@ -647,11 +491,11 @@ } /* *---------------------------------------------------------------------- * - * GetCGContextForDrawable -- + * TkMacOSXGetCGContextForDrawable -- * * Get CGContext for given Drawable, creating one if necessary. * * Results: * CGContext. @@ -661,14 +505,14 @@ * *---------------------------------------------------------------------- */ CGContextRef -GetCGContextForDrawable( - Drawable d) +TkMacOSXGetCGContextForDrawable( + Drawable drawable) { - MacDrawable *macDraw = (MacDrawable *) d; + MacDrawable *macDraw = (MacDrawable *) drawable; if (macDraw && (macDraw->flags & TK_IS_PIXMAP) && !macDraw->context) { const size_t bitsPerComponent = 8; size_t bitsPerPixel, bytesPerRow, len; CGColorSpaceRef colorspace = NULL; @@ -683,11 +527,11 @@ if (macDraw->flags & TK_IS_BW_PIXMAP) { bitsPerPixel = 8; bitmapInfo = (CGBitmapInfo)kCGImageAlphaOnly; } else { - colorspace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB); + colorspace = CGColorSpaceCreateDeviceRGB(); bitsPerPixel = 32; bitmapInfo |= kCGImageAlphaPremultipliedFirst; } bytesPerRow = ((size_t) macDraw->size.width * bitsPerPixel + 127) >> 3 & ~15; @@ -709,11 +553,11 @@ } /* *---------------------------------------------------------------------- * - * DrawCGImage -- + * TkMacOSXDrawCGImage -- * * Draw CG image into drawable. * * Results: * None. @@ -723,11 +567,11 @@ * *---------------------------------------------------------------------- */ void -DrawCGImage( +TkMacOSXDrawCGImage( Drawable d, GC gc, CGContextRef context, CGImageRef image, unsigned long imageForeground, @@ -1484,11 +1328,11 @@ * * Scroll a rectangle of the specified window and accumulate * a damage region. * * Results: - * Returns 0 if the scroll genereated no additional damage. + * Returns 0 if the scroll generated no additional damage. * Otherwise, sets the region that needs to be repainted after * scrolling and returns 1. * * Side effects: * Scrolls the bits in the window. @@ -1514,22 +1358,20 @@ int result = 0; if ( view ) { /* Get the scroll area in NSView coordinates (origin at bottom left). */ bounds = [view bounds]; - scrollSrc = NSMakeRect( - macDraw->xOff + x, + scrollSrc = NSMakeRect(macDraw->xOff + x, bounds.size.height - height - (macDraw->yOff + y), width, height); scrollDst = NSOffsetRect(scrollSrc, dx, -dy); /* Limit scrolling to the window content area. */ visRect = [view visibleRect]; scrollSrc = NSIntersectionRect(scrollSrc, visRect); scrollDst = NSIntersectionRect(scrollDst, visRect); if ( !NSIsEmptyRect(scrollSrc) && !NSIsEmptyRect(scrollDst) ) { - /* * Mark the difference between source and destination as damaged. * This region is described in NSView coordinates (y=0 at the bottom) * and converted to Tk coordinates later. */ @@ -1541,42 +1383,18 @@ dmgRgn = HIShapeCreateMutableWithRect(&srcRect); extraRgn = HIShapeCreateWithRect(&dstRect); ChkErr(HIShapeDifference, dmgRgn, extraRgn, (HIMutableShapeRef) dmgRgn); result = HIShapeIsEmpty(dmgRgn) ? 0 : 1; - /* Convert to Tk coordinates. */ + /* Convert to Tk coordinates, offset by the window origin. */ TkMacOSXSetWithNativeRegion(damageRgn, dmgRgn); if (extraRgn) { CFRelease(extraRgn); } /* Scroll the rectangle. */ [view scrollRect:scrollSrc by:NSMakeSize(dx, -dy)]; - - /* Shift the Tk children which meet the source rectangle. */ - TkWindow *winPtr = (TkWindow *)tkwin; - TkWindow *childPtr; - CGRect childBounds; - for (childPtr = winPtr->childList; childPtr != NULL; childPtr = childPtr->nextPtr) { - if (Tk_IsMapped(childPtr) && !Tk_IsTopLevel(childPtr)) { - TkMacOSXWinCGBounds(childPtr, &childBounds); - if (CGRectIntersectsRect(srcRect, childBounds)) { - MacDrawable *macChild = childPtr->privatePtr; - if (macChild) { - macChild->yOff += dy; - macChild->xOff += dx; - childPtr->changes.y = macChild->yOff; - childPtr->changes.x = macChild->xOff; - } - } - } - } - - /* Queue up Expose events for the damage region. */ - int oldMode = Tcl_SetServiceMode(TCL_SERVICE_NONE); - [view generateExposeEvents:dmgRgn childrenOnly:1]; - Tcl_SetServiceMode(oldMode); } } else { dmgRgn = HIShapeCreateEmpty(); TkMacOSXSetWithNativeRegion(damageRgn, dmgRgn); } @@ -1649,11 +1467,11 @@ } if (dontDraw) { goto end; } if (useCG) { - dc.context = GetCGContextForDrawable(d); + dc.context = TkMacOSXGetCGContextForDrawable(d); } if (!dc.context || !(macDraw->flags & TK_IS_PIXMAP)) { isWin = (TkMacOSXDrawableWindow(d) != nil); } if (dc.context) { Index: macosx/tkMacOSXEmbed.c ================================================================== --- macosx/tkMacOSXEmbed.c +++ macosx/tkMacOSXEmbed.c @@ -191,11 +191,11 @@ */ int TkpScanWindowId( Tcl_Interp *interp, - CONST char * string, + const char * string, Window *idPtr) { int code; Tcl_Obj obj; @@ -797,10 +797,17 @@ { TkWindow *winPtr = clientData; Container *containerPtr; Tk_ErrorHandler errHandler; + if (!firstContainerPtr) { + /* + * When the interpreter is being dismantled this can be nil. + */ + return; + } + /* * Ignore any X protocol errors that happen in this procedure (almost any * operation could fail, for example, if the embedded application has * deleted its window). */ Index: macosx/tkMacOSXEvent.c ================================================================== --- macosx/tkMacOSXEvent.c +++ macosx/tkMacOSXEvent.c @@ -12,10 +12,11 @@ */ #include "tkMacOSXPrivate.h" #include "tkMacOSXEvent.h" #include "tkMacOSXDebug.h" +#include "tkMacOSXConstants.h" #pragma mark TKApplication(TKEvent) enum { NSWindowWillMoveEventType = 20 @@ -86,19 +87,17 @@ win = [theEvent window]; break; } case NSCursorUpdate: break; -#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 case NSEventTypeGesture: case NSEventTypeMagnify: case NSEventTypeRotate: case NSEventTypeSwipe: case NSEventTypeBeginGesture: case NSEventTypeEndGesture: break; -#endif #endif default: break; /* return theEvent */ } Index: macosx/tkMacOSXFont.c ================================================================== --- macosx/tkMacOSXFont.c +++ macosx/tkMacOSXFont.c @@ -257,11 +257,11 @@ } else { TkInitFontAttributes(faPtr); } fontPtr->nsFont = nsFont; // some don't like antialiasing on fixed-width even if bigger than limit -// dontAA = [nsFont isFixedPitch] && fontPtr->font.fa.size <= 10; + // dontAA = [nsFont isFixedPitch] && fontPtr->font.fa.size <= 10; if (antialiasedTextEnabled >= 0/* || dontAA*/) { renderingMode = (antialiasedTextEnabled == 0/* || dontAA*/) ? NSFontIntegerAdvancementsRenderingMode : NSFontAntialiasedRenderingMode; } @@ -817,19 +817,10 @@ rangeStart + rangeLength > numBytes || (maxLength == 0 && !(flags & TK_AT_LEAST_ONE))) { *lengthPtr = 0; return 0; } -#if 0 - /* Back-compatibility with ATSUI renderer, appears not to be needed */ - if (rangeStart == 0 && maxLength == 1 && (flags & TK_ISOLATE_END) && - !(flags & TK_AT_LEAST_ONE)) { - length = 0; - fit = 0; - goto done; - } -#endif if (maxLength > 32767) { maxLength = 32767; } string = [[NSString alloc] initWithBytesNoCopy:(void*)source length:numBytes encoding:NSUTF8StringEncoding freeWhenDone:NO]; @@ -919,11 +910,10 @@ flags & TK_PARTIAL_OK ? "partialOk " : "", flags & TK_WHOLE_WORDS ? "wholeWords " : "", flags & TK_AT_LEAST_ONE ? "atLeastOne " : "", flags & TK_ISOLATE_END ? "isolateEnd " : "", length, fit); -//if (!(rangeLength==1 && rangeStart == 0)) fprintf(stderr, " measure len=%d (max=%d, w=%.0f) from %d (nb=%d): source=\"%s\": index=%d return %d\n",rangeLength,maxLength,width,rangeStart,numBytes, source+rangeStart, index, fit); #endif *lengthPtr = length; return fit; } Index: macosx/tkMacOSXHLEvents.c ================================================================== --- macosx/tkMacOSXHLEvents.c +++ macosx/tkMacOSXHLEvents.c @@ -34,11 +34,11 @@ */ static void tkMacOSXProcessFiles(NSAppleEventDescriptor* event, NSAppleEventDescriptor* replyEvent, Tcl_Interp *interp, - char* procedure); + const char* procedure); static int MissedAnyParameters(const AppleEvent *theEvent); static int ReallyKillMe(Tcl_Event *eventPtr, int flags); #pragma mark TKApplication(TKHLEvents) @@ -275,13 +275,13 @@ static void tkMacOSXProcessFiles( NSAppleEventDescriptor* event, NSAppleEventDescriptor* replyEvent, Tcl_Interp *interp, - char* procedure) + const char* procedure) { - Tcl_Encoding utf8 = Tcl_GetEncoding(NULL, "utf-8"); + Tcl_Encoding utf8; const AEDesc *fileSpecDesc = nil; AEDesc contents; char URLString[1 + URL_MAX_LENGTH]; NSURL *fileURL; DescType type; @@ -329,10 +329,11 @@ * paths contained in the AppleEvent as arguments. */ Tcl_DStringInit(&command); Tcl_DStringAppend(&command, procedure, -1); + utf8 = Tcl_GetEncoding(NULL, "utf-8"); for (index = 1; index <= count; index++) { if (noErr != AEGetNthPtr(fileSpecDesc, index, typeFileURL, &keyword, &type, (Ptr) URLString, URL_MAX_LENGTH, &actual)) { continue; @@ -347,10 +348,12 @@ } Tcl_ExternalToUtfDString(utf8, [[fileURL path] UTF8String], -1, &pathName); Tcl_DStringAppendElement(&command, Tcl_DStringValue(&pathName)); Tcl_DStringFree(&pathName); } + + Tcl_FreeEncoding(utf8); AEDisposeDesc(&contents); /* * Handle the event by evaluating the Tcl expression we constructed. */ @@ -359,11 +362,10 @@ Tcl_DStringLength(&command), TCL_EVAL_GLOBAL); if (code != TCL_OK) { Tcl_BackgroundException(interp, code); } Tcl_DStringFree(&command); - return; } /* *---------------------------------------------------------------------- * ADDED macosx/tkMacOSXImage.c Index: macosx/tkMacOSXImage.c ================================================================== --- /dev/null +++ macosx/tkMacOSXImage.c @@ -0,0 +1,580 @@ +/* + * tkMacOSXImage.c -- + * + * The code in this file provides an interface for XImages, + * + * Copyright (c) 1995-1997 Sun Microsystems, Inc. + * Copyright 2001-2009, Apple Inc. + * Copyright (c) 2005-2009 Daniel A. Steffen + * Copyright 2017 Marc Culler. + * + * See the file "license.terms" for information on usage and redistribution + * of this file, and for a DISCLAIMER OF ALL WARRANTIES. + */ + +#include "tkMacOSXPrivate.h" +#include "xbytes.h" + +#pragma mark XImage handling + +int +_XInitImageFuncPtrs( + XImage *image) +{ + return 0; +} + +/* + *---------------------------------------------------------------------- + * + * TkMacOSXCreateCGImageWithXImage -- + * + * Create CGImage from XImage, copying the image data. + * + * Results: + * CGImage, release after use. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +static void ReleaseData(void *info, const void *data, size_t size) { + ckfree(info); +} + +CGImageRef +TkMacOSXCreateCGImageWithXImage( + XImage *image, + int use_ximage_alpha) +{ + CGImageRef img = NULL; + size_t bitsPerComponent, bitsPerPixel; + size_t len = image->bytes_per_line * image->height; + const CGFloat *decode = NULL; + CGBitmapInfo bitmapInfo; + CGDataProviderRef provider = NULL; + char *data = NULL; + CGDataProviderReleaseDataCallback releaseData = ReleaseData; + + if (image->bits_per_pixel == 1) { + /* + * BW image + */ + + /* Reverses the sense of the bits */ + static const CGFloat decodeWB[2] = {1, 0}; + decode = decodeWB; + + bitsPerComponent = 1; + bitsPerPixel = 1; + if (image->bitmap_bit_order != MSBFirst) { + char *srcPtr = image->data + image->xoffset; + char *endPtr = srcPtr + len; + char *destPtr = (data = ckalloc(len)); + + while (srcPtr < endPtr) { + *destPtr++ = xBitReverseTable[(unsigned char)(*(srcPtr++))]; + } + } else { + data = memcpy(ckalloc(len), image->data + image->xoffset, len); + } + if (data) { + provider = CGDataProviderCreateWithData(data, data, len, releaseData); + } + if (provider) { + img = CGImageMaskCreate(image->width, image->height, bitsPerComponent, + bitsPerPixel, image->bytes_per_line, provider, decode, 0); + } + } else if (image->format == ZPixmap && image->bits_per_pixel == 32) { + /* + * Color image + */ + + CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB(); + + bitsPerComponent = 8; + bitsPerPixel = 32; + bitmapInfo = (image->byte_order == MSBFirst ? + kCGBitmapByteOrder32Big : kCGBitmapByteOrder32Little); + if (use_ximage_alpha) { + bitmapInfo |= kCGImageAlphaPremultipliedFirst; + } else { + bitmapInfo |= kCGImageAlphaNoneSkipFirst; + } + data = memcpy(ckalloc(len), image->data + image->xoffset, len); + if (data) { + provider = CGDataProviderCreateWithData(data, data, len, releaseData); + } + if (provider) { + img = CGImageCreate(image->width, image->height, bitsPerComponent, + bitsPerPixel, image->bytes_per_line, colorspace, bitmapInfo, + provider, decode, 0, kCGRenderingIntentDefault); + CFRelease(provider); + } + if (colorspace) { + CFRelease(colorspace); + } + } else { + TkMacOSXDbgMsg("Unsupported image type"); + } + return img; +} + + +/* + *---------------------------------------------------------------------- + * + * XGetImage -- + * + * This function copies data from a pixmap or window into an XImage. + * + * Results: + * Returns a newly allocated XImage containing the data from the given + * rectangle of the given drawable, or NULL if the XImage could not be + * constructed. NOTE: If we are copying from a window on a Retina + * display, the dimensions of the XImage will be 2*width x 2*height. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ +struct pixel_fmt {int r; int g; int b; int a;}; +static struct pixel_fmt bgra = {2, 1, 0, 3}; +static struct pixel_fmt abgr = {3, 2, 1, 0}; + +XImage * +XGetImage( + Display *display, + Drawable drawable, + int x, + int y, + unsigned int width, + unsigned int height, + unsigned long plane_mask, + int format) +{ + NSBitmapImageRep* bitmap_rep = NULL; + NSUInteger bitmap_fmt = 0; + XImage* imagePtr = NULL; + char* bitmap = NULL; + char R, G, B, A; + int depth = 32, offset = 0, bitmap_pad = 0; + unsigned int bytes_per_row, size, row, n, m; + unsigned int scalefactor=1, scaled_height=height, scaled_width=width; + NSWindow *win = TkMacOSXDrawableWindow(drawable); + MacDrawable *macDraw = ((MacDrawable*)drawable); + static enum {unknown, no, yes} has_retina = unknown; + + if (win && has_retina == unknown) { +#ifdef __clang__ + has_retina = [win respondsToSelector:@selector(backingScaleFactor)]? + yes : no; +#else + has_retina = no; +#endif + } + + if (has_retina == yes) { + /* + * We only allow scale factors 1 or 2, as Apple currently does. + */ +#ifdef __clang__ + scalefactor = [win backingScaleFactor] == 2.0 ? 2 : 1; +#endif + scaled_height *= scalefactor; + scaled_width *= scalefactor; + } + + if (format == ZPixmap) { + if (width == 0 || height == 0) { + return NULL; + } + bitmap_rep = TkMacOSXBitmapRepFromDrawableRect(drawable, + x, y, width, height); + if (!bitmap_rep) { + TkMacOSXDbgMsg("XGetImage: Failed to construct NSBitmapRep"); + return NULL; + } + bitmap_fmt = [bitmap_rep bitmapFormat]; + size = [bitmap_rep bytesPerPlane]; + bytes_per_row = [bitmap_rep bytesPerRow]; + bitmap = ckalloc(size); + if (!bitmap || + (bitmap_fmt != 0 && bitmap_fmt != 1) || + [bitmap_rep samplesPerPixel] != 4 || + [bitmap_rep isPlanar] != 0 || + bytes_per_row != 4 * scaled_width || + size != bytes_per_row*scaled_height ) { + TkMacOSXDbgMsg("XGetImage: Unrecognized bitmap format"); + CFRelease(bitmap_rep); + return NULL; + } + + if (macDraw->flags & TK_USE_XIMAGE_ALPHA) { + /* + * When called by TkImgPhotoDisplay we are being asked to return a + * background image to be blended with the photoimage using its + * alpha channel, if it has one. Returning a black pixmap here + * makes TkImgPhotoDisplay create an XImage with a premultiplied + * alpha channel, as favored by Apple. When TkImgPhotoDisplay + * passes this XImage to TkPutImage, targeting a pixmap, it creates + * an image with correct transparency. This is used, for example, + * when creating an iconphoto or a menu image from a PNG + * photoimage. + */ + bzero(bitmap, size); + } else { + memcpy(bitmap, (char *)[bitmap_rep bitmapData], size); + } + CFRelease(bitmap_rep); + + /* + * When Apple extracts a bitmap from an NSView, it may be in + * either BGRA or ABGR format. For an XImage we need RGBA. + */ + struct pixel_fmt pixel = bitmap_fmt == 0 ? bgra : abgr; + + for (row=0, n=0; rowpixelpower = 1; + } + } else { + /* + * There are some calls to XGetImage in the generic Tk + * code which pass an XYPixmap rather than a ZPixmap. + * XYPixmaps should be handled here. + */ + TkMacOSXDbgMsg("XGetImage does not handle XYPixmaps at the moment."); + } + return imagePtr; +} + +/* + *---------------------------------------------------------------------- + * + * DestroyImage -- + * + * Destroys storage associated with an image. + * + * Results: + * None. + * + * Side effects: + * Deallocates the image. + * + *---------------------------------------------------------------------- + */ + +static int +DestroyImage( + XImage *image) +{ + if (image) { + if (image->data) { + ckfree(image->data); + } + ckfree(image); + } + return 0; +} + +/* + *---------------------------------------------------------------------- + * + * ImageGetPixel -- + * + * Get a single pixel from an image. + * + * Results: + * Returns the 32 bit pixel value. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +static unsigned long +ImageGetPixel( + XImage *image, + int x, + int y) +{ + unsigned char r = 0, g = 0, b = 0; + + if (image && image->data) { + unsigned char *srcPtr = ((unsigned char*) image->data) + + (y * image->bytes_per_line) + + (((image->xoffset + x) * image->bits_per_pixel) / NBBY); + + switch (image->bits_per_pixel) { + case 32: { + r = (*((unsigned int*) srcPtr) >> 16) & 0xff; + g = (*((unsigned int*) srcPtr) >> 8) & 0xff; + b = (*((unsigned int*) srcPtr) ) & 0xff; + /*if (image->byte_order == LSBFirst) { + r = srcPtr[2]; g = srcPtr[1]; b = srcPtr[0]; + } else { + r = srcPtr[1]; g = srcPtr[2]; b = srcPtr[3]; + }*/ + break; + } + case 16: + r = (*((unsigned short*) srcPtr) >> 7) & 0xf8; + g = (*((unsigned short*) srcPtr) >> 2) & 0xf8; + b = (*((unsigned short*) srcPtr) << 3) & 0xf8; + break; + case 8: + r = (*srcPtr << 2) & 0xc0; + g = (*srcPtr << 4) & 0xc0; + b = (*srcPtr << 6) & 0xc0; + r |= r >> 2 | r >> 4 | r >> 6; + g |= g >> 2 | g >> 4 | g >> 6; + b |= b >> 2 | b >> 4 | b >> 6; + break; + case 4: { + unsigned char c = (x % 2) ? *srcPtr : (*srcPtr >> 4); + r = (c & 0x04) ? 0xff : 0; + g = (c & 0x02) ? 0xff : 0; + b = (c & 0x01) ? 0xff : 0; + break; + } + case 1: + r = g = b = ((*srcPtr) & (0x80 >> (x % 8))) ? 0xff : 0; + break; + } + } + return (PIXEL_MAGIC << 24) | (r << 16) | (g << 8) | b; +} + +/* + *---------------------------------------------------------------------- + * + * ImagePutPixel -- + * + * Set a single pixel in an image. + * + * Results: + * None. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +static int +ImagePutPixel( + XImage *image, + int x, + int y, + unsigned long pixel) +{ + if (image && image->data) { + unsigned char *dstPtr = ((unsigned char*) image->data) + + (y * image->bytes_per_line) + + (((image->xoffset + x) * image->bits_per_pixel) / NBBY); + if (image->bits_per_pixel == 32) { + *((unsigned int*) dstPtr) = pixel; + } else { + unsigned char r = ((pixel & image->red_mask) >> 16) & 0xff; + unsigned char g = ((pixel & image->green_mask) >> 8) & 0xff; + unsigned char b = ((pixel & image->blue_mask) ) & 0xff; + switch (image->bits_per_pixel) { + case 16: + *((unsigned short*) dstPtr) = ((r & 0xf8) << 7) | + ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); + break; + case 8: + *dstPtr = ((r & 0xc0) >> 2) | ((g & 0xc0) >> 4) | + ((b & 0xc0) >> 6); + break; + case 4: { + unsigned char c = ((r & 0x80) >> 5) | ((g & 0x80) >> 6) | + ((b & 0x80) >> 7); + *dstPtr = (x % 2) ? ((*dstPtr & 0xf0) | (c & 0x0f)) : + ((*dstPtr & 0x0f) | ((c << 4) & 0xf0)); + break; + } + case 1: + *dstPtr = ((r|g|b) & 0x80) ? (*dstPtr | (0x80 >> (x % 8))) : + (*dstPtr & ~(0x80 >> (x % 8))); + break; + } + } + } + return 0; +} + +/* + *---------------------------------------------------------------------- + * + * XCreateImage -- + * + * Allocates storage for a new XImage. + * + * Results: + * Returns a newly allocated XImage. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +XImage * +XCreateImage( + Display* display, + Visual* visual, + unsigned int depth, + int format, + int offset, + char* data, + unsigned int width, + unsigned int height, + int bitmap_pad, + int bytes_per_line) +{ + XImage *ximage; + display->request++; + ximage = ckalloc(sizeof(XImage)); + + ximage->height = height; + ximage->width = width; + ximage->depth = depth; + ximage->xoffset = offset; + ximage->format = format; + ximage->data = data; + ximage->obdata = NULL; + /* The default pixelpower is 0. This must be explicitly set to 1 in the + * case of an XImage extracted from a Retina display. + */ + ximage->pixelpower = 0; + + if (format == ZPixmap) { + ximage->bits_per_pixel = 32; + ximage->bitmap_unit = 32; + } else { + ximage->bits_per_pixel = 1; + ximage->bitmap_unit = 8; + } + if (bitmap_pad) { + ximage->bitmap_pad = bitmap_pad; + } else { + /* Use 16 byte alignment for best Quartz perfomance */ + ximage->bitmap_pad = 128; + } + if (bytes_per_line) { + ximage->bytes_per_line = bytes_per_line; + } else { + ximage->bytes_per_line = ((width * ximage->bits_per_pixel + + (ximage->bitmap_pad - 1)) >> 3) & + ~((ximage->bitmap_pad >> 3) - 1); + } +#ifdef WORDS_BIGENDIAN + ximage->byte_order = MSBFirst; + ximage->bitmap_bit_order = MSBFirst; +#else + ximage->byte_order = LSBFirst; + ximage->bitmap_bit_order = LSBFirst; +#endif + ximage->red_mask = 0x00FF0000; + ximage->green_mask = 0x0000FF00; + ximage->blue_mask = 0x000000FF; + ximage->f.create_image = NULL; + ximage->f.destroy_image = DestroyImage; + ximage->f.get_pixel = ImageGetPixel; + ximage->f.put_pixel = ImagePutPixel; + ximage->f.sub_image = NULL; + ximage->f.add_pixel = NULL; + + return ximage; +} + +/* + *---------------------------------------------------------------------- + * + * TkPutImage -- + * + * Copies a subimage from an in-memory image to a rectangle of + * of the specified drawable. + * + * Results: + * None. + * + * Side effects: + * Draws the image on the specified drawable. + * + *---------------------------------------------------------------------- + */ + +int +TkPutImage( + unsigned long *colors, /* Unused on Macintosh. */ + int ncolors, /* Unused on Macintosh. */ + Display* display, /* Display. */ + Drawable drawable, /* Drawable to place image on. */ + GC gc, /* GC to use. */ + XImage* image, /* Image to place. */ + int src_x, /* Source X & Y. */ + int src_y, + int dest_x, /* Destination X & Y. */ + int dest_y, + unsigned int width, /* Same width & height for both */ + unsigned int height) /* distination and source. */ +{ + TkMacOSXDrawingContext dc; + MacDrawable *macDraw = ((MacDrawable*)drawable); + + display->request++; + if (!TkMacOSXSetupDrawingContext(drawable, gc, 1, &dc)) { + return BadDrawable; + } + if (dc.context) { + CGImageRef img = TkMacOSXCreateCGImageWithXImage(image, + macDraw->flags & TK_USE_XIMAGE_ALPHA); + if (img) { + /* If the XImage has big pixels, rescale the source dimensions.*/ + int pp = image->pixelpower; + TkMacOSXDrawCGImage(drawable, gc, dc.context, + img, gc->foreground, gc->background, + CGRectMake(0, 0, image->width<height< + * Copyright (c) 2017 Marc Culler * * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. */ @@ -30,46 +31,53 @@ long tkMacOSXMacOSXVersion = 0; #pragma mark TKApplication(TKInit) -#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060 -#define NSTextInputContextKeyboardSelectionDidChangeNotification @"NSTextInputContextKeyboardSelectionDidChangeNotification" -static void keyboardChanged(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) { - [[NSNotificationCenter defaultCenter] postNotificationName:NSTextInputContextKeyboardSelectionDidChangeNotification object:nil userInfo:nil]; -} -#endif - @interface TKApplication(TKKeyboard) - (void) keyboardChanged: (NSNotification *) notification; @end -#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 #define TKApplication_NSApplicationDelegate -#else -#define TKApplication_NSApplicationDelegate -#endif @interface TKApplication(TKWindowEvent) TKApplication_NSApplicationDelegate - (void) _setupWindowNotifications; @end @interface TKApplication(TKMenus) - (void) _setupMenus; @end @implementation TKApplication -@synthesize poolProtected = _poolProtected; +@synthesize poolLock = _poolLock; @end +/* + * #define this to see a message on stderr whenever _resetAutoreleasePool is + * called while the pool is locked. + */ +#undef DEBUG_LOCK + @implementation TKApplication(TKInit) - (void) _resetAutoreleasePool { - if(![self poolProtected]) { + if([self poolLock] == 0) { [_mainPool drain]; _mainPool = [NSAutoreleasePool new]; + } else { +#ifdef DEBUG_LOCK + fprintf(stderr, "Pool is locked with count %d!!!!\n", [self poolLock]); +#endif } } +- (void) _lockAutoreleasePool +{ + [self setPoolLock:[self poolLock] + 1]; +} +- (void) _unlockAutoreleasePool +{ + [self setPoolLock:[self poolLock] - 1]; +} #ifdef TK_MAC_DEBUG_NOTIFICATIONS - (void) _postedNotification: (NSNotification *) notification { TKLog(@"-[%@(%p) %s] %@", [self class], self, _cmd, notification); } @@ -85,37 +93,93 @@ observe(NSApplicationDidUnhideNotification, applicationShowHide:); observe(NSApplicationDidHideNotification, applicationShowHide:); observe(NSApplicationDidChangeScreenParametersNotification, displayChanged:); observe(NSTextInputContextKeyboardSelectionDidChangeNotification, keyboardChanged:); #undef observe -#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060 - CFNotificationCenterAddObserver(CFNotificationCenterGetDistributedCenter(), NULL, &keyboardChanged, kTISNotifySelectedKeyboardInputSourceChanged, NULL, CFNotificationSuspensionBehaviorCoalesce); -#endif -} - -- (void) _setupEventLoop -{ - NSAutoreleasePool *pool = [NSAutoreleasePool new]; - [self finishLaunching]; - [self setWindowsNeedUpdate:YES]; - [pool drain]; -} - -- (void) _setup: (Tcl_Interp *) interp -{ - _eventInterp = interp; - _mainPool = [NSAutoreleasePool new]; - [NSApp setPoolProtected:NO]; - _defaultMainMenu = nil; - [self _setupMenus]; - [self setDelegate:self]; +} + +-(void)applicationWillFinishLaunching:(NSNotification *)aNotification +{ + + /* + * Initialize notifications. + */ #ifdef TK_MAC_DEBUG_NOTIFICATIONS [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_postedNotification:) name:nil object:nil]; #endif [self _setupWindowNotifications]; [self _setupApplicationNotifications]; + + /* + * Construct the menu bar. + */ + _defaultMainMenu = nil; + [self _setupMenus]; + + + /* + * Initialize event processing. + */ + TkMacOSXInitAppleEvents(_eventInterp); + + /* + * Initialize the graphics context. + */ + TkMacOSXUseAntialiasedText(_eventInterp, -1); + TkMacOSXInitCGDrawing(_eventInterp, TRUE, 0); +} + +-(void)applicationDidFinishLaunching:(NSNotification *)notification +{ + /* + * It is not safe to force activation of the NSApp until this + * method is called. Activating too early can cause the menu + * bar to be unresponsive. + */ + [NSApp activateIgnoringOtherApps: YES]; +} + +- (void) _setup: (Tcl_Interp *) interp +{ + /* + * Remember our interpreter. + */ + _eventInterp = interp; + + /* + * Install the global autoreleasePool. + */ + _mainPool = [NSAutoreleasePool new]; + [NSApp setPoolLock:0]; + + /* + * Be our own delegate. + */ + [self setDelegate:self]; + + /* + * Make sure we are allowed to open windows. + */ + [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; + + /* + * If no icon has been set from an Info.plist file, use the Wish icon from + * the Tk framework. + */ + NSString *iconFile = [[NSBundle mainBundle] objectForInfoDictionaryKey: + @"CFBundleIconFile"]; + if (!iconFile) { + NSString *path = [NSApp tkFrameworkImagePath:@"Tk.icns"]; + if (path) { + NSImage *image = [[NSImage alloc] initWithContentsOfFile:path]; + if (image) { + [NSApp setApplicationIconImage:image]; + [image release]; + } + } + } } - (NSString *) tkFrameworkImagePath: (NSString *) image { NSString *path = nil; @@ -161,42 +225,10 @@ #pragma mark - /* *---------------------------------------------------------------------- * - * DoWindowActivate -- - * - * Idle handler that sets the application icon to the generic Tk icon. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -static void -SetApplicationIcon( - ClientData clientData) -{ - NSAutoreleasePool *pool = [NSAutoreleasePool new]; - NSString *path = [NSApp tkFrameworkImagePath:@"Tk.icns"]; - if (path) { - NSImage *image = [[NSImage alloc] initWithContentsOfFile:path]; - if (image) { - [NSApp setApplicationIconImage:image]; - [image release]; - } - } - [pool drain]; -} - -/* - *---------------------------------------------------------------------- - * * TkpInit -- * * Performs Mac-specific interpreter initialization related to the * tk_library variable. * @@ -221,24 +253,21 @@ * don't want to do the following initialization multiple times we protect * against doing it more than once. */ if (!initialized) { - int bundledExecutable = 0; - CFBundleRef bundleRef; - CFURLRef bundleUrl = NULL; struct utsname name; struct stat st; initialized = 1; /* * Initialize/check OS version variable for runtime checks. */ -#if MAC_OS_X_VERSION_MIN_REQUIRED < 1050 -# error Mac OS X 10.5 required +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060 +# error Mac OS X 10.6 required #endif if (!uname(&name)) { tkMacOSXMacOSXVersion = (strtod(name.release, NULL) + 96) * 10; } @@ -261,92 +290,16 @@ */ if (Tcl_MacOSXOpenVersionedBundleResources(interp, "com.tcltk.tklibrary", TK_FRAMEWORK_VERSION, 0, PATH_MAX, tkLibPath) != TCL_OK) { + # if 0 /* This is not really an error. Wish still runs fine. */ TkMacOSXDbgMsg("Tcl_MacOSXOpenVersionedBundleResources failed"); + # endif } #endif - { - NSAutoreleasePool *pool = [NSAutoreleasePool new]; - [[NSUserDefaults standardUserDefaults] registerDefaults: - [NSDictionary dictionaryWithObjectsAndKeys: - [NSNumber numberWithBool:YES], - @"_NSCanWrapButtonTitles", - [NSNumber numberWithInt:-1], - @"NSStringDrawingTypesetterBehavior", - nil]]; - [TKApplication sharedApplication]; - [pool drain]; - [NSApp _setup:interp]; - } - - /* Check whether we are a bundled executable: */ - bundleRef = CFBundleGetMainBundle(); - if (bundleRef) { - bundleUrl = CFBundleCopyBundleURL(bundleRef); - } - if (bundleUrl) { - /* - * A bundled executable is two levels down from its main bundle - * directory (e.g. Wish.app/Contents/MacOS/Wish), whereas an - * unbundled executable's main bundle directory is just the - * directory containing the executable. So to check whether we are - * bundled, we delete the last three path components of the - * executable's url and compare the resulting url with the main - * bundle url. - */ - - int j = 3; - CFURLRef url = CFBundleCopyExecutableURL(bundleRef); - - while (url && j--) { - CFURLRef parent = - CFURLCreateCopyDeletingLastPathComponent(NULL, url); - - CFRelease(url); - url = parent; - } - if (url) { - bundledExecutable = CFEqual(bundleUrl, url); - CFRelease(url); - } - CFRelease(bundleUrl); - } - - if (!bundledExecutable) { - /* - * If we are loaded into an executable that is not a bundled - * application, the window server does not let us come to the - * foreground. For such an executable, notify the window server - * that we are now a full GUI application. - */ - - OSStatus err = procNotFound; - ProcessSerialNumber psn = { 0, kCurrentProcess }; - - err = ChkErr(TransformProcessType, &psn, - kProcessTransformToForegroundApplication); - - /* - * Set application icon to generic Tk icon, do it at idle time - * instead of now to ensure tk_library is setup. - */ - - Tcl_DoWhenIdle(SetApplicationIcon, NULL); - } - - { - NSAutoreleasePool *pool = [NSAutoreleasePool new]; - [NSApp _setupEventLoop]; - TkMacOSXInitAppleEvents(interp); - TkMacOSXUseAntialiasedText(interp, -1); - TkMacOSXInitCGDrawing(interp, TRUE, 0); - [pool drain]; - } - /* * FIXME: Close stdin & stdout for remote debugging otherwise we will * fight with gdb for stdin & stdout */ @@ -353,10 +306,28 @@ if (getenv("XCNOSTDIN") != NULL) { close(0); close(1); } + /* + * Instantiate our NSApplication object. This needs to be + * done before we check whether to open a console window. + */ + + NSAutoreleasePool *pool = [NSAutoreleasePool new]; + [[NSUserDefaults standardUserDefaults] registerDefaults: + [NSDictionary dictionaryWithObjectsAndKeys: + [NSNumber numberWithBool:YES], + @"_NSCanWrapButtonTitles", + [NSNumber numberWithInt:-1], + @"NSStringDrawingTypesetterBehavior", + nil]]; + [TKApplication sharedApplication]; + [pool drain]; + [NSApp _setup:interp]; + [NSApp finishLaunching]; + /* * If we don't have a TTY and stdin is a special character file of * length 0, (e.g. /dev/null, which is what Finder sets when double * clicking Wish) then use the Tk based console interpreter. */ @@ -385,10 +356,11 @@ } if (Tk_CreateConsoleWindow(interp) == TCL_ERROR) { return TCL_ERROR; } } + } Tk_MacOSXSetupTkNotifier(); if (tkLibPath[0] != '\0') { Index: macosx/tkMacOSXInt.h ================================================================== --- macosx/tkMacOSXInt.h +++ macosx/tkMacOSXInt.h @@ -85,10 +85,11 @@ #define TK_DRAWN_UNDER_MENU 0x08 #define TK_FOCUSED_VIEW 0x10 #define TK_IS_PIXMAP 0x20 #define TK_IS_BW_PIXMAP 0x40 #define TK_DO_NOT_DRAW 0x80 +#define TK_USE_XIMAGE_ALPHA 0x100 /* * I am reserving TK_EMBEDDED = 0x100 in the MacDrawable flags * This is defined in tk.h. We need to duplicate the TK_EMBEDDED flag in the * TkWindow structure for the window, but in the MacWin. This way we can * still tell what the correct port is after the TKWindow structure has been Index: macosx/tkMacOSXKeyEvent.c ================================================================== --- macosx/tkMacOSXKeyEvent.c +++ macosx/tkMacOSXKeyEvent.c @@ -13,10 +13,11 @@ * this file, and for a DISCLAIMER OF ALL WARRANTIES. */ #include "tkMacOSXPrivate.h" #include "tkMacOSXEvent.h" +#include "tkMacOSXConstants.h" /* #ifdef TK_MAC_DEBUG #define TK_MAC_DEBUG_KEYBOARD #endif Index: macosx/tkMacOSXKeyboard.c ================================================================== --- macosx/tkMacOSXKeyboard.c +++ macosx/tkMacOSXKeyboard.c @@ -11,11 +11,11 @@ * of this file, and for a DISCLAIMER OF ALL WARRANTIES. */ #include "tkMacOSXPrivate.h" #include "tkMacOSXEvent.h" - +#include "tkMacOSXConstants.h" /* * A couple of simple definitions to make code a bit more self-explaining. * * For the assignments of Mod1==meta==command and Mod2==alt==option, see also * tkMacOSXMouseEvent.c. @@ -93,10 +93,28 @@ {105, XK_F13}, {107, XK_F14}, {113, XK_F15}, {0, 0} }; + +#define NUM_MOD_KEYCODES 14 +static KeyCode modKeyArray[NUM_MOD_KEYCODES] = { + XK_Shift_L, + XK_Shift_R, + XK_Control_L, + XK_Control_R, + XK_Caps_Lock, + XK_Shift_Lock, + XK_Meta_L, + XK_Meta_R, + XK_Alt_L, + XK_Alt_R, + XK_Super_L, + XK_Super_R, + XK_Hyper_L, + XK_Hyper_R, +}; static int initialized = 0; static Tcl_HashTable keycodeTable; /* keyArray hashed by keycode value. */ static Tcl_HashTable vkeyTable; /* virtualkeyArray hashed by virtual * keycode value. */ @@ -455,11 +473,10 @@ /* * MacOSX doesn't use the key codes for the modifiers for anything, and we * don't generate them either. So there is no modifier map. */ - modmap = ckalloc(sizeof(XModifierKeymap)); modmap->max_keypermod = 0; modmap->modifiermap = NULL; return modmap; } @@ -546,11 +563,10 @@ XKeysymToMacKeycode( Display *display, KeySym keysym) { KeyInfo *kPtr; - if (keysym <= LATIN1_MAX) { /* * Handle keysyms in the Latin-1 range where keysym and Unicode * character code point are the same. */ @@ -576,10 +592,21 @@ for (kPtr = virtualkeyArray; kPtr->keycode != 0; kPtr++) { if (kPtr->keysym == keysym) { return kPtr->keycode; } } + + /* + * Modifier keycodes only come from generated events. No translation + * is needed. + */ + + for (int i=0; i < NUM_MOD_KEYCODES; i++) { + if (keysym == modKeyArray[i]) { + return keysym; + } + } /* * For other keysyms (not Latin-1 and not special keys), we'd need a * generic keysym-to-unicode table. We don't have that, so we give up here. */ @@ -659,18 +686,24 @@ KeySym keysym, XEvent *eventPtr) { if (keysym == NoSymbol) { eventPtr->xkey.keycode = 0; + } else if ( modKeyArray[0] <= keysym && + keysym <= modKeyArray[NUM_MOD_KEYCODES - 1]) { + /* + * Keysyms for pure modifiers only arise in generated events. + * We should just copy them to the keycode. + */ + eventPtr->xkey.keycode = keysym; } else { Display *display = Tk_Display(tkwin); int macKeycode = XKeysymToMacKeycode(display, keysym); /* * See also XKeysymToKeycode. */ - if ((keysym >= XK_F1) && (keysym <= XK_F35)) { eventPtr->xkey.keycode = 0x0010; } else { eventPtr->xkey.keycode = 0x00FF & keysym; } @@ -732,11 +765,10 @@ * Handle pure modifier keys specially. We use -1 as a signal for * this. */ if (eventPtr->xany.send_event == -1) { - int modifier = eventPtr->xkey.keycode & NSDeviceIndependentModifierFlagsMask; if (modifier == NSCommandKeyMask) { return XK_Meta_L; } else if (modifier == NSShiftKeyMask) { @@ -889,22 +921,24 @@ dispPtr->altModMask = 0; dispPtr->metaModMask = 0; #endif /* - * MacOSX doesn't use the keycodes for the modifiers for anything, and we - * don't generate them either (the keycodes actually given in the simulated - * modifier events are bogus). So there is no modifier map. If we ever want - * to simulate real modifier keycodes, the list will be constant in the - * Carbon implementation. + * MacOSX doesn't create a key event when a modifier key is pressed or + * released. However, it is possible to generate key events for + * modifier keys, and this is done in the tests. So we construct an array + * containing the keycodes of the standard modifier keys from static data. */ if (dispPtr->modKeyCodes != NULL) { ckfree(dispPtr->modKeyCodes); } - dispPtr->numModKeyCodes = 0; - dispPtr->modKeyCodes = NULL; + dispPtr->numModKeyCodes = NUM_MOD_KEYCODES; + dispPtr->modKeyCodes = (KeyCode *)ckalloc(NUM_MOD_KEYCODES * sizeof(KeyCode)); + for (int i = 0; i < NUM_MOD_KEYCODES; i++) { + dispPtr->modKeyCodes[i] = modKeyArray[i]; + } } /* * Local Variables: * mode: objc Index: macosx/tkMacOSXMenu.c ================================================================== --- macosx/tkMacOSXMenu.c +++ macosx/tkMacOSXMenu.c @@ -17,10 +17,11 @@ #include "tkMenu.h" #include "tkColor.h" #include "tkFont.h" #include "tkMacOSXWm.h" #include "tkMacOSXDebug.h" +#include "tkMacOSXConstants.h" /* #ifdef TK_MAC_DEBUG #define TK_MAC_DEBUG_MENUS #endif @@ -114,15 +115,11 @@ - (TkMenu *) tkMenu; - (int) tkIndexOfItem: (NSMenuItem *) menuItem; - (void) insertItem: (NSMenuItem *) newItem atTkIndex: (NSInteger) index; @end -#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 #define TKMenu_NSMenuDelegate -#else -#define TKMenu_NSMenuDelegate -#endif @interface TKMenu(TKMenuDelegate) TKMenu_NSMenuDelegate @end @implementation TKMenu - (void) setSpecial: (NSUInteger) special @@ -771,12 +768,19 @@ } Drawable d = Tk_WindowId(root); NSView *rootview = TkMacOSXGetRootControl(d); NSWindow *win = [rootview window]; + int result; inPostMenu = 1; + + result = TkPreprocessMenu(menuPtr); + if (result != TCL_OK) { + inPostMenu = 0; + return result; + } int oldMode = Tcl_SetServiceMode(TCL_SERVICE_NONE); NSView *view = [win contentView]; NSRect frame = NSMakeRect(x + 9, tkMacOSXZeroScreenHeight - y - 9, 1, 1); Index: macosx/tkMacOSXMenus.c ================================================================== --- macosx/tkMacOSXMenus.c +++ macosx/tkMacOSXMenus.c @@ -11,10 +11,11 @@ * of this file, and for a DISCLAIMER OF ALL WARRANTIES. */ #include "tkMacOSXPrivate.h" #include "tkMenu.h" +#include "tkMacOSXConstants.h" static void GenerateEditEvent(const char *name); static Tcl_Obj * GetWidgetDemoPath(Tcl_Interp *interp); #pragma mark TKApplication(TKMenus) Index: macosx/tkMacOSXMouseEvent.c ================================================================== --- macosx/tkMacOSXMouseEvent.c +++ macosx/tkMacOSXMouseEvent.c @@ -13,10 +13,11 @@ #include "tkMacOSXPrivate.h" #include "tkMacOSXWm.h" #include "tkMacOSXEvent.h" #include "tkMacOSXDebug.h" +#include "tkMacOSXConstants.h" typedef struct { unsigned int state; long delta; Window window; Index: macosx/tkMacOSXNotify.c ================================================================== --- macosx/tkMacOSXNotify.c +++ macosx/tkMacOSXNotify.c @@ -13,12 +13,12 @@ * of this file, and for a DISCLAIMER OF ALL WARRANTIES. */ #include "tkMacOSXPrivate.h" #include "tkMacOSXEvent.h" +#include "tkMacOSXConstants.h" #include -#include #import /* This is not used for anything at the moment. */ typedef struct ThreadSpecificData { int initialized; @@ -138,21 +138,21 @@ /* * Install TkAqua event source in main event loop thread. */ if (CFRunLoopGetMain() == CFRunLoopGetCurrent()) { - if (!pthread_main_np()) { + if (![NSThread isMainThread]) { /* * Panic if main runloop is not on the main application thread. */ Tcl_Panic("Tk_MacOSXSetupTkNotifier: %s", "first [load] of TkAqua has to occur in the main thread!"); } Tcl_CreateEventSource(TkMacOSXEventsSetupProc, TkMacOSXEventsCheckProc, - GetMainEventQueue()); + NULL); TkCreateExitHandler(TkMacOSXNotifyExitHandler, NULL); Tcl_SetServiceMode(TCL_SERVICE_ALL); TclMacOSXNotifierAddRunLoopMode(NSEventTrackingRunLoopMode); TclMacOSXNotifierAddRunLoopMode(NSModalPanelRunLoopMode); } @@ -182,11 +182,11 @@ { TSD_INIT(); Tcl_DeleteEventSource(TkMacOSXEventsSetupProc, TkMacOSXEventsCheckProc, - GetMainEventQueue()); + NULL); tsdPtr->initialized = 0; } /* *---------------------------------------------------------------------- @@ -214,13 +214,14 @@ TkMacOSXEventsSetupProc( ClientData clientData, int flags) { NSString *runloopMode = [[NSRunLoop currentRunLoop] currentMode]; - /* runloopMode will be nil if we are in the Tcl event loop. */ + /* runloopMode will be nil if we are in a Tcl event loop. */ if (flags & TCL_WINDOW_EVENTS && !runloopMode) { static const Tcl_Time zeroBlockTime = { 0, 0 }; + [NSApp _resetAutoreleasePool]; /* Call this with dequeue=NO -- just checking if the queue is empty. */ NSEvent *currentEvent = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:GetRunLoopMode(TkMacOSXGetModalSession()) dequeue:NO]; @@ -254,33 +255,32 @@ TkMacOSXEventsCheckProc( ClientData clientData, int flags) { NSString *runloopMode = [[NSRunLoop currentRunLoop] currentMode]; - /* runloopMode will be nil if we are in the Tcl event loop. */ + /* runloopMode will be nil if we are in a Tcl event loop. */ if (flags & TCL_WINDOW_EVENTS && !runloopMode) { NSEvent *currentEvent = nil; NSEvent *testEvent = nil; NSModalSession modalSession; - + /* It is possible for the SetupProc to be called before this function + * returns. This happens, for example, when we process an event which + * opens a modal window. To prevent premature release of our + * application-wide autorelease pool by a nested call to the SetupProc, + * we must lock it here. + */ + [NSApp _lockAutoreleasePool]; do { - [NSApp _resetAutoreleasePool]; modalSession = TkMacOSXGetModalSession(); - testEvent = [NSApp nextEventMatchingMask:NSAnyEventMask + testEvent = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:GetRunLoopMode(modalSession) dequeue:NO]; /* We must not steal any events during LiveResize. */ -#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 if (testEvent && [[testEvent window] inLiveResize]) { break; } -#else - if (testEvent && [[[testEvent window] contentView] inLiveResize]) { - break; - } -#endif currentEvent = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:GetRunLoopMode(modalSession) dequeue:YES]; if (currentEvent) { @@ -301,10 +301,12 @@ [currentEvent release]; } else { break; } } while (1); + /* Now we can unlock the pool. */ + [NSApp _unlockAutoreleasePool]; } } /* Index: macosx/tkMacOSXPrivate.h ================================================================== --- macosx/tkMacOSXPrivate.h +++ macosx/tkMacOSXPrivate.h @@ -57,31 +57,10 @@ } else { __VA_ARGS__ #define tk_if_mac_os_x_no(chk, cond, ...) \ if (0) { #define tk_else_mac_os_x_no(...) \ } else { __VA_ARGS__ -/* Private mapping macros defined according to Mac OS X version requirements */ -/* 10.5 Leopard */ -#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050 -#define tk_if_mac_os_x_min_10_5 tk_if_mac_os_x_yes -#define tk_else_mac_os_x_min_10_5 tk_else_mac_os_x_yes -#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1050 -#define tk_if_mac_os_x_10_5 tk_if_mac_os_x_yes -#define tk_else_mac_os_x_10_5 tk_else_mac_os_x_yes -#endif /* MAC_OS_X_VERSION_MAX_ALLOWED */ -#else /* MAC_OS_X_VERSION_MIN_REQUIRED */ -#define tk_if_mac_os_x_min_10_5 tk_if_mac_os_x_chk -#define tk_else_mac_os_x_min_10_5 tk_else_mac_os_x_chk -#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1050 -#define tk_if_mac_os_x_10_5 tk_if_mac_os_x_chk -#define tk_else_mac_os_x_10_5 tk_else_mac_os_x_chk -#endif /* MAC_OS_X_VERSION_MAX_ALLOWED */ -#endif /* MAC_OS_X_VERSION_MIN_REQUIRED */ -#if MAC_OS_X_VERSION_MAX_ALLOWED < 1050 -#define tk_if_mac_os_x_10_5 tk_if_mac_os_x_no -#define tk_else_mac_os_x_10_5 tk_else_mac_os_x_no -#endif /* MAC_OS_X_VERSION_MAX_ALLOWED */ /* * Macros for DEBUG_ASSERT_MESSAGE et al from Debugging.h. */ @@ -207,12 +186,18 @@ int activeFlag); MODULE_SCOPE WindowClass TkMacOSXWindowClass(TkWindow *winPtr); MODULE_SCOPE int TkMacOSXIsWindowZoomed(TkWindow *winPtr); MODULE_SCOPE int TkGenerateButtonEventForXPointer(Window window); MODULE_SCOPE EventModifiers TkMacOSXModifierState(void); -MODULE_SCOPE NSBitmapImageRep* BitmapRepFromDrawableRect(Drawable drawable, +MODULE_SCOPE NSBitmapImageRep* TkMacOSXBitmapRepFromDrawableRect(Drawable drawable, int x, int y, unsigned int width, unsigned int height); +MODULE_SCOPE CGImageRef TkMacOSXCreateCGImageWithXImage(XImage *image, + int use_ximage_alpha); +MODULE_SCOPE void TkMacOSXDrawCGImage(Drawable d, GC gc, CGContextRef context, + CGImageRef image, unsigned long imageForeground, + unsigned long imageBackground, CGRect imageBounds, + CGRect srcBounds, CGRect dstBounds); MODULE_SCOPE int TkMacOSXSetupDrawingContext(Drawable d, GC gc, int useCG, TkMacOSXDrawingContext *dcPtr); MODULE_SCOPE void TkMacOSXRestoreDrawingContext( TkMacOSXDrawingContext *dcPtr); MODULE_SCOPE void TkMacOSXSetColorInContext(GC gc, unsigned long pixel, @@ -226,10 +211,11 @@ MODULE_SCOPE NSView* TkMacOSXDrawableView(MacDrawable *macWin); MODULE_SCOPE void TkMacOSXWinCGBounds(TkWindow *winPtr, CGRect *bounds); MODULE_SCOPE HIShapeRef TkMacOSXGetClipRgn(Drawable drawable); MODULE_SCOPE void TkMacOSXInvalidateViewRegion(NSView *view, HIShapeRef rgn); +MODULE_SCOPE CGContextRef TkMacOSXGetCGContextForDrawable(Drawable drawable); MODULE_SCOPE CGImageRef TkMacOSXCreateCGImageWithDrawable(Drawable drawable); MODULE_SCOPE NSImage* TkMacOSXGetNSImageWithTkImage(Display *display, Tk_Image image, int width, int height); MODULE_SCOPE NSImage* TkMacOSXGetNSImageWithBitmap(Display *display, Pixmap bitmap, GC gc, int width, int height); @@ -276,18 +262,21 @@ NSArray *_defaultHelpMenuItems; NSWindow *_windowWithMouse; NSAutoreleasePool *_mainPool; #ifdef __i386__ /* The Objective C runtime used on i386 requires this. */ - BOOL _poolProtected; + int _poolLock; #endif } -@property BOOL poolProtected; +@property int poolLock; + @end @interface TKApplication(TKInit) - (NSString *)tkFrameworkImagePath:(NSString*)image; - (void)_resetAutoreleasePool; +- (void)_lockAutoreleasePool; +- (void)_unlockAutoreleasePool; @end @interface TKApplication(TKEvent) - (NSEvent *)tkProcessEvent:(NSEvent *)theEvent; @end @interface TKApplication(TKMouseEvent) @@ -339,11 +328,10 @@ @end @interface TKContentView(TKWindowEvent) - (void) drawRect: (NSRect) rect; - (void) generateExposeEvents: (HIShapeRef) shape; -- (void) generateExposeEvents: (HIShapeRef) shape childrenOnly: (int) childrenOnly; - (void) viewDidEndLiveResize; - (void) tkToolbarButton: (id) sender; - (BOOL) isOpaque; - (BOOL) wantsDefaultClipping; - (BOOL) acceptsFirstResponder; Index: macosx/tkMacOSXScale.c ================================================================== --- macosx/tkMacOSXScale.c +++ macosx/tkMacOSXScale.c @@ -169,11 +169,14 @@ */ Tcl_Preserve((ClientData) scalePtr); if ((scalePtr->flags & INVOKE_COMMAND) && (scalePtr->command != NULL)) { Tcl_Preserve((ClientData) interp); - sprintf(string, scalePtr->format, scalePtr->value); + if (snprintf(string, TCL_DOUBLE_SPACE, scalePtr->format, + scalePtr->value) < 0) { + string[TCL_DOUBLE_SPACE - 1] = '\0'; + } Tcl_DStringInit(&buf); Tcl_DStringAppend(&buf, scalePtr->command, -1); Tcl_DStringAppend(&buf, " ", -1); Tcl_DStringAppend(&buf, string, -1); result = Tcl_EvalEx(interp, Tcl_DStringValue(&buf), -1, 0); Index: macosx/tkMacOSXSubwindows.c ================================================================== --- macosx/tkMacOSXSubwindows.c +++ macosx/tkMacOSXSubwindows.c @@ -147,15 +147,31 @@ display->request++; macWin->winPtr->flags |= TK_MAPPED; if (Tk_IsTopLevel(macWin->winPtr)) { if (!Tk_IsEmbedded(macWin->winPtr)) { NSWindow *win = TkMacOSXDrawableWindow(window); - [NSApp activateIgnoringOtherApps:YES]; + /* + * We want to activate Tk when a toplevel is mapped + * but we must not supply YES here. This is because + * during Tk initialization the root window is mapped + * before applicationDidFinishLaunching returns. Forcing + * the app to activate too early can make the menu bar + * unresponsive. + */ + [NSApp activateIgnoringOtherApps:NO]; if ( [win canBecomeKeyWindow] ) { [win makeKeyAndOrderFront:NSApp]; } TkMacOSXApplyWindowAttributes(macWin->winPtr, win); + } else { + /* + * Rebuild the container's clipping region and display + * the window. + */ + TkWindow *contWinPtr = TkpGetOtherWindow(macWin->winPtr); + TkMacOSXInvalClipRgns((Tk_Window)contWinPtr); + TkMacOSXInvalidateWindow(macWin, TK_PARENT_WINDOW); } TkMacOSXInvalClipRgns((Tk_Window) macWin->winPtr); /* * We only need to send the MapNotify event for toplevel windows. @@ -170,11 +186,12 @@ event.xmap.event = window; event.xmap.override_redirect = macWin->winPtr->atts.override_redirect; Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL); } else { /* - * Generate damage for that area of the window. + * Rebuild the parent's clipping region and display the window. + * */ TkMacOSXInvalClipRgns((Tk_Window) macWin->winPtr->parentPtr); TkMacOSXInvalidateWindow(macWin, TK_PARENT_WINDOW); } @@ -245,25 +262,26 @@ XUnmapWindow( Display *display, /* Display. */ Window window) /* Window. */ { MacDrawable *macWin = (MacDrawable *) window; + TkWindow *winPtr = macWin->winPtr; + TkWindow *parentPtr = winPtr->parentPtr; XEvent event; display->request++; - macWin->winPtr->flags &= ~TK_MAPPED; - if (Tk_IsTopLevel(macWin->winPtr)) { - if (!Tk_IsEmbedded(macWin->winPtr) && - macWin->winPtr->wmInfoPtr->hints.initial_state!=IconicState) { + if (Tk_IsTopLevel(winPtr)) { + if (!Tk_IsEmbedded(winPtr) && + winPtr->wmInfoPtr->hints.initial_state!=IconicState) { NSWindow *win = TkMacOSXDrawableWindow(window); if ([win isVisible]) { [[win parentWindow] removeChildWindow:win]; [win orderOut:NSApp]; } } - TkMacOSXInvalClipRgns((Tk_Window) macWin->winPtr); + TkMacOSXInvalClipRgns((Tk_Window) winPtr); /* * We only need to send the UnmapNotify event for toplevel windows. */ @@ -276,16 +294,21 @@ event.xunmap.event = window; event.xunmap.from_configure = false; Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL); } else { /* - * Generate damage for that area of the window. + * Rebuild the visRgn clip region for the parent so it will be allowed + * to draw in the space from which this subwindow was removed. */ - - TkMacOSXInvalidateWindow(macWin, TK_PARENT_WINDOW); - TkMacOSXInvalClipRgns((Tk_Window) macWin->winPtr->parentPtr); + if (parentPtr && parentPtr->privatePtr->visRgn) { + TkMacOSXInvalidateViewRegion(TkMacOSXDrawableView(parentPtr->privatePtr), + parentPtr->privatePtr->visRgn); + } + TkMacOSXInvalClipRgns((Tk_Window) parentPtr); + TkMacOSXUpdateClipRgn(parentPtr); } + winPtr->flags &= ~TK_MAPPED; } /* *---------------------------------------------------------------------- * @@ -767,12 +790,12 @@ * contained window in a frame, and don't support any other widgets * in the frame either. This is not currently enforced, however. */ if (!Tk_IsTopLevel(winPtr)) { - TkMacOSXUpdateClipRgn(winPtr->parentPtr); if (winPtr->parentPtr) { + TkMacOSXUpdateClipRgn(winPtr->parentPtr); ChkErr(HIShapeIntersect, winPtr->parentPtr->privatePtr->aboveVisRgn, rgn, rgn); } win2Ptr = winPtr; Index: macosx/tkMacOSXWindowEvent.c ================================================================== --- macosx/tkMacOSXWindowEvent.c +++ macosx/tkMacOSXWindowEvent.c @@ -15,10 +15,11 @@ #include "tkMacOSXPrivate.h" #include "tkMacOSXWm.h" #include "tkMacOSXEvent.h" #include "tkMacOSXDebug.h" +#include "tkMacOSXConstants.h" /* #ifdef TK_MAC_DEBUG #define TK_MAC_DEBUG_EVENTS #define TK_MAC_DEBUG_DRAWING @@ -39,18 +40,12 @@ #ifdef TK_MAC_DEBUG_NOTIFICATIONS extern NSString *NSWindowWillOrderOnScreenNotification; extern NSString *NSWindowDidOrderOnScreenNotification; extern NSString *NSWindowDidOrderOffScreenNotification; - -#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060 -#define NSWindowWillStartLiveResizeNotification @"NSWindowWillStartLiveResizeNotification" -#define NSWindowDidEndLiveResizeNotification @"NSWindowDidEndLiveResizeNotification" -#endif -#endif - -extern BOOL opaqueTag; +#endif + @implementation TKApplication(TKWindowEvent) - (void) windowActivation: (NSNotification *) notification { @@ -355,16 +350,16 @@ event.xany.serial = LastKnownRequestProcessed(Tk_Display(winPtr)); event.xany.send_event = false; event.xany.window = Tk_WindowId(winPtr); event.xany.display = Tk_Display(winPtr); event.type = Expose; - event.xexpose.x = damageBounds.origin.x; - event.xexpose.y = damageBounds.origin.y; + event.xexpose.x = damageBounds.origin.x - bounds.origin.x; + event.xexpose.y = damageBounds.origin.y - bounds.origin.y; event.xexpose.width = damageBounds.size.width; event.xexpose.height = damageBounds.size.height; event.xexpose.count = 0; - Tk_HandleEvent(&event); + Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL); #ifdef TK_MAC_DEBUG_DRAWING NSLog(@"Expose %p {{%d, %d}, {%d, %d}}", event.xany.window, event.xexpose.x, event.xexpose.y, event.xexpose.width, event.xexpose.height); #endif @@ -747,21 +742,11 @@ */ int Tk_MacOSXIsAppInFront(void) { - Boolean isFrontProcess = true; -#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060 - ProcessSerialNumber frontPsn, ourPsn = {0, kCurrentProcess}; - - if (noErr == GetFrontProcess(&frontPsn)){ - SameProcess(&frontPsn, &ourPsn, &isFrontProcess); - } -#else - isFrontProcess = [NSRunningApplication currentApplication].active; -#endif - return (isFrontProcess == true); + return ([NSRunningApplication currentApplication].active == true); } #pragma mark TKContentView #import @@ -856,11 +841,11 @@ /* This can be called from outside the Tk event loop. * Since it calls Tcl_DoOneEvent, we need to make sure we * don't clobber the AutoreleasePool set up by the caller. */ - [NSApp setPoolProtected:YES]; + [NSApp _lockAutoreleasePool]; /* * Try to prevent flickers and flashes. */ [w disableFlushWindow]; @@ -887,11 +872,11 @@ [self generateExposeEvents: shape]; while (Tk_DoOneEvent(TK_ALL_EVENTS|TK_DONT_WAIT)) {} [w enableFlushWindow]; [w flushWindowIfNeeded]; NSEnableScreenUpdates(); - [NSApp setPoolProtected:NO]; + [NSApp _unlockAutoreleasePool]; } } /* * As insurance against bugs that might cause layout glitches during a live @@ -912,20 +897,14 @@ * immediately removed from the Tcl event loop and processed. Typically, they * should be queued, however. */ - (void) generateExposeEvents: (HIShapeRef) shape { - [self generateExposeEvents:shape childrenOnly:0]; -} - -- (void) generateExposeEvents: (HIShapeRef) shape - childrenOnly: (int) childrenOnly -{ - TkWindow *winPtr = TkMacOSXGetTkWindow([self window]); unsigned long serial; CGRect updateBounds; int updatesNeeded; + TkWindow *winPtr = TkMacOSXGetTkWindow([self window]); if (!winPtr) { return; } @@ -977,17 +956,12 @@ - (BOOL) isOpaque { NSWindow *w = [self window]; - if (opaqueTag) { - return YES; - } else { - - return (w && (([w styleMask] & NSTexturedBackgroundWindowMask) || + return (w && (([w styleMask] & NSTexturedBackgroundWindowMask) || ![w isOpaque]) ? NO : YES); - } } - (BOOL) wantsDefaultClipping { return NO; Index: macosx/tkMacOSXWm.c ================================================================== --- macosx/tkMacOSXWm.c +++ macosx/tkMacOSXWm.c @@ -8,10 +8,11 @@ * * Copyright (c) 1994-1997 Sun Microsystems, Inc. * Copyright 2001-2009, Apple Inc. * Copyright (c) 2006-2009 Daniel A. Steffen * Copyright (c) 2010 Kevin Walzer/WordTech Communications LLC. + * Copyright (c) 2017 Marc Culler. * * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. */ @@ -18,10 +19,11 @@ #include "tkMacOSXPrivate.h" #include "tkScrollbar.h" #include "tkMacOSXWm.h" #include "tkMacOSXEvent.h" #include "tkMacOSXDebug.h" +#include "tkMacOSXConstants.h" #define DEBUG_ZOMBIES 0 /* #ifdef TK_MAC_DEBUG @@ -51,13 +53,10 @@ | kWindowOpaqueForEventsAttribute | kWindowIgnoreClicksAttribute \ | kWindowDoesNotCycleAttribute | tkWindowDoesNotHideAttribute \ | tkCanJoinAllSpacesAttribute | tkMoveToActiveSpaceAttribute \ | tkNonactivatingPanelAttribute | tkHUDWindowAttribute) -/*Objects for use in setting background color and opacity of window.*/ -NSColor *colorName = NULL; -BOOL opaqueTag = FALSE; static const struct { const UInt64 validAttrs, defaultAttrs, forceOnAttrs, forceOffAttrs; int flags; NSUInteger styleMask; } macClassAttrs[] = { @@ -195,11 +194,10 @@ static Tcl_HashTable windowTable; static int windowHashInit = false; - #pragma mark NSWindow(TKWm) /* * Conversion of coordinates between window and screen. */ @@ -212,11 +210,10 @@ } - (NSPoint) convertPointFromScreen: (NSPoint)point { return [self convertScreenToBase:point]; } -@end #else - (NSPoint) convertPointToScreen: (NSPoint) point { NSRect pointrect; pointrect.origin = point; @@ -230,12 +227,13 @@ pointrect.origin = point; pointrect.size.width = 0; pointrect.size.height = 0; return [self convertRectFromScreen:pointrect].origin; } -@end #endif + +@end #pragma mark - /* @@ -362,29 +360,34 @@ static void GetMaxSize(TkWindow *winPtr, int *maxWidthPtr, int *maxHeightPtr); static void RemapWindows(TkWindow *winPtr, MacDrawable *parentWin); -#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 -#define TK_GOT_AT_LEAST_SNOW_LEOPARD 1 -#endif - #pragma mark TKWindow(TKWm) -#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060 -@interface NSWindow(TkWm) -- (void) setCanCycle: (BOOL) canCycleFlag; -@end -#endif - @interface NSDrawerWindow : NSWindow { id _i1, _i2; } @end -@implementation TKWindow + +@implementation TKWindow: NSWindow +#if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_12 +/* + * Override automatic fullscreen button on >10.12 because system fullscreen API + * confuses Tk window geometry. + */ +- (void)toggleFullScreen:(id)sender +{ + if ([self isZoomed]) { + TkMacOSXZoomToplevel(self, inZoomIn); + } else { + TkMacOSXZoomToplevel(self, inZoomOut); + } +} +#endif @end @implementation TKWindow(TKWm) - (BOOL) canBecomeKeyWindow @@ -393,10 +396,12 @@ return (winPtr && winPtr->wmInfoPtr && (winPtr->wmInfoPtr->macClass == kHelpWindowClass || winPtr->wmInfoPtr->attributes & kWindowNoActivatesAttribute)) ? NO : YES; } + + #if DEBUG_ZOMBIES - (id) retain { id result = [super retain]; @@ -410,11 +415,10 @@ return result; } - (id) autorelease { - static int xcount = 0; id result = [super autorelease]; const char *title = [[self title] UTF8String]; if (title == nil) { title = "unnamed window"; } @@ -765,10 +769,14 @@ * Map the window. */ XMapWindow(winPtr->display, winPtr->window); + /*Add window to Window menu.*/ + NSWindow *win = TkMacOSXDrawableWindow(winPtr->window); + [win setExcludedFromWindowsMenu:NO]; + } /* *---------------------------------------------------------------------- * @@ -875,35 +883,55 @@ if (window && !Tk_IsEmbedded(winPtr) ) { NSWindow *parent = [window parentWindow]; if (parent) { [parent removeChildWindow:window]; } - [window close]; - TkMacOSXUnregisterMacWindow(window); - if (winPtr->window) { - ((MacDrawable *) winPtr->window)->view = nil; - } #if DEBUG_ZOMBIES > 0 { const char *title = [[window title] UTF8String]; if (title == nil) { title = "unnamed window"; } printf(">>>> Closing <%s>. Count is: %lu\n", title, [window retainCount]); } #endif - [window release]; + [window close]; + TkMacOSXUnregisterMacWindow(window); + if (winPtr->window) { + ((MacDrawable *) winPtr->window)->view = nil; + } wmPtr->window = NULL; + [window release]; /* Activate the highest window left on the screen. */ NSArray *windows = [NSApp orderedWindows]; - if ( [windows count] > 0 ) { - NSWindow *front = [windows objectAtIndex:0]; - if ( front && [front canBecomeKeyWindow] ) { - [front makeKeyAndOrderFront:NSApp]; + for (id nswindow in windows) { + TkWindow *winPtr2 = TkMacOSXGetTkWindow(nswindow); + if (winPtr2 && nswindow != window) { + WmInfo *wmPtr = winPtr2->wmInfoPtr; + BOOL minimized = (wmPtr->hints.initial_state == IconicState || + wmPtr->hints.initial_state == WithdrawnState); + /* + * If no windows are left on the screen and the next + * window is iconified or withdrawn, we don't want to + * make it be the KeyWindow because that would cause + * it to be displayed on the screen. + */ + if ([nswindow canBecomeKeyWindow] && !minimized) { + [nswindow makeKeyAndOrderFront:NSApp]; + break; + } } } + /* + * Process all window events immediately to force the closed window to + * be deallocated. But don't do this for the root window as that is + * unnecessary and can lead to segfaults. + */ + if (winPtr->parentPtr) { + while (Tk_DoOneEvent(TK_WINDOW_EVENTS|TK_DONT_WAIT)) {} + } [NSApp _resetAutoreleasePool]; #if DEBUG_ZOMBIES > 0 fprintf(stderr, "================= Pool dump ===================\n"); [NSAutoreleasePool showPools]; @@ -1933,11 +1961,11 @@ int objc, /* Number of arguments. */ Tcl_Obj *const objv[]) /* Argument objects. */ { register WmInfo *wmPtr = winPtr->wmInfoPtr; int reqWidth, reqHeight, widthInc, heightInc; - char *errorMsg; + const char *errorMsg; if ((objc != 3) && (objc != 7)) { Tcl_WrongNumArgs(interp, 2, objv, "window ?baseWidth baseHeight widthInc heightInc?"); return TCL_ERROR; @@ -2312,18 +2340,18 @@ *---------------------------------------------------------------------- * * WmIconphotoCmd -- * * This procedure is invoked to process the "wm iconphoto" Tcl command. - * See the user documentation for details on what it does. Not yet - * implemented for OS X. + * See the user documentation for details on what it does. * * Results: * A standard Tcl result. * * Side effects: * See the user documentation. + * * *---------------------------------------------------------------------- */ static int @@ -2332,49 +2360,56 @@ TkWindow *winPtr, /* Toplevel to work with */ Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ Tcl_Obj *const objv[]) /* Argument objects. */ { - Tk_PhotoHandle photo; - int i, width, height, isDefault = 0; + Tk_Image tk_icon; + int width, height, isDefault = 0; if (objc < 4) { Tcl_WrongNumArgs(interp, 2, objv, - "window ?-default? image1 ?image2 ...?"); + "window ?-default? image1 ?image2 ...?"); return TCL_ERROR; } + + /*Parse args.*/ if (strcmp(Tcl_GetString(objv[3]), "-default") == 0) { isDefault = 1; if (objc == 4) { Tcl_WrongNumArgs(interp, 2, objv, - "window ?-default? image1 ?image2 ...?"); + "window ?-default? image1 ?image2 ...?"); return TCL_ERROR; } } - /* - * Iterate over all images to retrieve their sizes, in order to allocate a - * buffer large enough to hold all images. - */ - - for (i = 3 + isDefault; i < objc; i++) { - photo = Tk_FindPhoto(interp, Tcl_GetString(objv[i])); - if (photo == NULL) { - Tcl_SetObjResult(interp, Tcl_ObjPrintf( - "can't use \"%s\" as iconphoto: not a photo image", - Tcl_GetString(objv[i]))); - Tcl_SetErrorCode(interp, "TK", "WM", "ICONPHOTO", "PHOTO", NULL); - return TCL_ERROR; - } - Tk_PhotoGetSize(photo, &width, &height); - } - - /* - * TODO: This requires implementation for OS X, but we silently return for - * now. - */ - + /*Get icon name. We only use the first icon name because macOS does not + support multiple images in Tk photos.*/ + char *icon; + if (strcmp(Tcl_GetString(objv[3]), "-default") == 0) { + icon = Tcl_GetString(objv[4]); + } else { + icon = Tcl_GetString(objv[3]); + } + + /*Get image and convert to NSImage that can be displayed as icon.*/ + tk_icon = Tk_GetImage(interp, tkwin, icon, NULL, NULL); + if (tk_icon == NULL) { + Tcl_SetObjResult(interp, Tcl_ObjPrintf( + "can't use \"%s\" as iconphoto: not a photo image", + icon)); + Tcl_SetErrorCode(interp, "TK", "WM", "ICONPHOTO", "PHOTO", NULL); + return TCL_ERROR; + } + + NSImage *newIcon; + Tk_SizeOfImage(tk_icon, &width, &height); + newIcon = TkMacOSXGetNSImageWithTkImage(winPtr->display, tk_icon, width, height); + Tk_FreeImage(tk_icon); + if (newIcon == NULL) { + return TCL_ERROR; + } + [NSApp setApplicationIconImage: newIcon]; return TCL_OK; } /* *---------------------------------------------------------------------- @@ -3473,10 +3508,14 @@ Tcl_GetString(objv[2]), Tk_PathName(wmPtr->iconFor))); Tcl_SetErrorCode(interp, "TK", "WM", "WITHDRAW", "ICON", NULL); return TCL_ERROR; } TkpWmSetState(winPtr, WithdrawnState); + /*Remove window from Window menu.*/ + NSWindow *win = TkMacOSXDrawableWindow(winPtr->window); + [win setExcludedFromWindowsMenu:YES]; + return TCL_OK; } /* * Invoked by those wm subcommands that affect geometry. @@ -4633,48 +4672,54 @@ TkWindow *otherPtr) /* Window relative to which to restack; if * NULL, then winPtr gets restacked above or * below *all* siblings. */ { NSWindow *macWindow; - NSInteger otherMacWindowNumber; - - /* - * Get the mac window. Make sure it exists & is mapped. - */ - - if (winPtr->window == None) { - Tk_MakeWindowExist((Tk_Window) winPtr); - } - if (winPtr->wmInfoPtr->flags & WM_NEVER_MAPPED) { - /* - * Can't set stacking order properly until the window is on the screen - * (mapping it may give it a reparent window), so make sure it's on - * the screen. - */ - - TkWmMapWindow(winPtr); + NSWindow *otherMacWindow; + WmInfo *wmPtr = winPtr->wmInfoPtr; + int macAboveBelow = (aboveBelow == Above ? NSWindowAbove : NSWindowBelow); + int otherNumber = 0; /* 0 will be used when otherPtr is NULL. */ + + /* + * If the Tk windows has no drawable, or is withdrawn do nothing. + */ + if (winPtr->window == None || + wmPtr == NULL || + wmPtr->hints.initial_state == WithdrawnState) { + return; } macWindow = TkMacOSXDrawableWindow(winPtr->window); + if (macWindow == nil) { + return; + } + if (otherPtr) { + /* + * When otherPtr is non-NULL, if the other window has no + * drawable or is withdrawn, do nothing. + */ + WmInfo *otherWmPtr = otherPtr->wmInfoPtr; + if (winPtr->window == None || + otherWmPtr == NULL || + otherWmPtr->hints.initial_state == WithdrawnState) { + return; + } + otherMacWindow = TkMacOSXDrawableWindow(otherPtr->window); + if (otherMacWindow == nil) { + return; + } else { + /* + * If the other window is OK, get its number. + */ + otherNumber = [otherMacWindow windowNumber]; + } + } /* - * Get the window in which a raise or lower is in relation to. + * Just let the Mac window manager deal with all the subtleties + * of keeping track of off-screen windows, etc. */ - - if (otherPtr != NULL) { - if (otherPtr->window == None) { - Tk_MakeWindowExist((Tk_Window) otherPtr); - } - if (otherPtr->wmInfoPtr->flags & WM_NEVER_MAPPED) { - TkWmMapWindow(otherPtr); - } - otherMacWindowNumber = [TkMacOSXDrawableWindow(otherPtr->window) - windowNumber]; - } else { - otherMacWindowNumber = 0; - } - [macWindow orderWindow:(aboveBelow == Above ? NSWindowAbove : NSWindowBelow) - relativeTo:otherMacWindowNumber]; + [macWindow orderWindow:macAboveBelow relativeTo:otherNumber]; } /* *---------------------------------------------------------------------- * @@ -5090,12 +5135,12 @@ /* *---------------------------------------------------------------------- * * TkMacOSXIsWindowZoomed -- * - * Ask Carbon if the given window is in the zoomed out state. Because - * dragging & growing a window can change the Carbon zoom state, we + * Ask Cocoa if the given window is in the zoomed out state. Because + * dragging & growing a window can change the Cocoa zoom state, we * cannot rely on wmInfoPtr->hints.initial_state for this information. * * Results: * True if window is zoomed out, false otherwise. * @@ -5109,10 +5154,11 @@ TkMacOSXIsWindowZoomed( TkWindow *winPtr) { return [TkMacOSXDrawableWindow(winPtr->window) isZoomed]; } + /* *---------------------------------------------------------------------- * * TkMacOSXZoomToplevel -- @@ -5151,16 +5197,17 @@ /* * Do nothing if already in desired zoom state. */ - if (![window isZoomed] == (zoomPart == inZoomIn)) { + if ((![window isZoomed] == (zoomPart == inZoomIn))) { return false; } - [window zoom:NSApp]; - wmPtr->hints.initial_state = - (zoomPart == inZoomIn ? NormalState : ZoomState); + [window zoom:NSApp]; + + wmPtr->hints.initial_state = + (zoomPart == inZoomIn ? NormalState : ZoomState); return true; } /* *---------------------------------------------------------------------- @@ -5194,58 +5241,17 @@ enum SubCmds { TKMWS_STYLE }; Tk_Window tkwin = clientData; TkWindow *winPtr; - int index, i; + int index; if (objc < 3) { Tcl_WrongNumArgs(interp, 1, objv, "option window ?arg ...?"); return TCL_ERROR; } - /* - * Iterate through objc/objv to set correct background color and toggle - * opacity of window. - */ - - for (i= 0; i < objc; i++) { - if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*black*")) { - colorName = [NSColor blackColor]; // use #000000 in Tk scripts to match - } else if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*dark*")) { - colorName = [NSColor darkGrayColor]; //use #545454 in Tk scripts to match - } else if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*light*")) { - colorName = [NSColor lightGrayColor]; //use #ababab in Tk scripts to match - } else if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*white*")) { - colorName = [NSColor whiteColor]; //use #ffffff in Tk scripts to match - } else if (Tcl_StringMatch(Tcl_GetString(objv[i]), "gray*")) { - colorName = [NSColor grayColor]; //use #7f7f7f in Tk scripts to match - } else if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*red*")) { - colorName = [NSColor redColor]; //use #ff0000 in Tk scripts to match - } else if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*green*")) { - colorName = [NSColor greenColor]; //use #00ff00 in Tk scripts to match - } else if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*blue*")) { - colorName = [NSColor blueColor]; //use #0000ff in Tk scripts to match - } else if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*cyan*")) { - colorName = [NSColor cyanColor]; //use #00ffff in Tk scripts to match - } else if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*yellow*")) { - colorName = [NSColor yellowColor]; //use #ffff00 in Tk scripts to match - } else if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*magenta*")) { - colorName = [NSColor magentaColor]; //use #ff00ff in Tk scripts to match - } else if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*orange*")) { - colorName = [NSColor orangeColor]; //use #ff8000 in Tk scripts to match - } else if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*purple*")) { - colorName = [NSColor purpleColor]; //use #800080 in Tk scripts to match - } else if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*brown*")){ - colorName = [NSColor brownColor]; //use #996633 in Tk scripts to match - } else if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*clear*")) { - colorName = [NSColor clearColor]; //use systemTransparent in Tk scripts to match - } - if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*opacity*")) { - opaqueTag = YES; - } - } winPtr = (TkWindow *) Tk_NameToWindow(interp, Tcl_GetString(objv[2]), tkwin); if (winPtr == NULL) { return TCL_ERROR; @@ -5604,10 +5610,11 @@ if (!window) { Tcl_Panic("couldn't allocate new Mac window"); } TKContentView *contentView = [[TKContentView alloc] initWithFrame:NSZeroRect]; + [window setColorSpace:[NSColorSpace deviceRGBColorSpace]]; [window setContentView:contentView]; [contentView release]; [window setDelegate:NSApp]; [window setAcceptsMouseMovedEvents:YES]; [window setReleasedWhenClosed:NO]; @@ -5622,24 +5629,10 @@ * from opaque content. */ [window setMovableByWindowBackground:NO]; } - - /* Set background color and opacity of window if those flags are set. */ - if (colorName != NULL) { - [window setBackgroundColor: colorName]; - } - - if (opaqueTag) { -#ifdef TK_GOT_AT_LEAST_SNOW_LEOPARD - [window setOpaque: opaqueTag]; -#else - [window setOpaque: YES]; -#endif - } - [window setDocumentEdited:NO]; wmPtr->window = window; macWin->view = window.contentView; TkMacOSXApplyWindowAttributes(winPtr, window); @@ -6326,28 +6319,16 @@ if (newAttributes & tkCanJoinAllSpacesAttribute) { b |= NSWindowCollectionBehaviorCanJoinAllSpaces; } else if (newAttributes & tkMoveToActiveSpaceAttribute) { b |= NSWindowCollectionBehaviorMoveToActiveSpace; } -#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 if (newAttributes & kWindowDoesNotCycleAttribute) { b |= NSWindowCollectionBehaviorIgnoresCycle; } else { b |= NSWindowCollectionBehaviorParticipatesInCycle; } -#endif [macWindow setCollectionBehavior:b]; -#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060 - if (((changedAttributes & kWindowDoesNotCycleAttribute) || initial) -#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 - && tkMacOSXMacOSXVersion < 1060 -#endif - ) { - [macWindow setCanCycle: - !(newAttributes & kWindowDoesNotCycleAttribute)]; - } -#endif } if ((wmPtr->flags & WM_TOPMOST) != (oldFlags & WM_TOPMOST)) { [macWindow setLevel:(wmPtr->flags & WM_TOPMOST) ? kCGUtilityWindowLevel : ([macWindow isKindOfClass: [NSPanel class]] && [macWindow isFloatingPanel] ? @@ -6475,13 +6456,11 @@ int fullscreen, Tcl_Interp *interp) { WmInfo *wmPtr = winPtr->wmInfoPtr; int result = TCL_OK, wasFullscreen = (wmPtr->flags & WM_FULLSCREEN); -#ifdef TK_GOT_AT_LEAST_SNOW_LEOPARD static unsigned long prevMask = 0, prevPres = 0; -#endif /*TK_GOT_AT_LEAST_SNOW_LEOPARD*/ if (fullscreen) { int screenWidth = WidthOfScreen(Tk_Screen(winPtr)); int screenHeight = HeightOfScreen(Tk_Screen(winPtr)); @@ -6499,10 +6478,11 @@ "CONSTRAINT_FAILURE", NULL); } result = TCL_ERROR; wmPtr->flags &= ~WM_FULLSCREEN; } else { + Tk_UnmapWindow((Tk_Window) winPtr); NSRect bounds = [window contentRectForFrameRect:[window frame]]; NSRect screenBounds = NSMakeRect(0, 0, screenWidth, screenHeight); if (!NSEqualRects(bounds, screenBounds) && !wasFullscreen) { wmPtr->configX = wmPtr->x; @@ -6517,34 +6497,24 @@ wmPtr->flags &= ~WM_SYNC_PENDING; } wmPtr->flags |= WM_FULLSCREEN; } -#ifdef TK_GOT_AT_LEAST_SNOW_LEOPARD - /* - * We can't set these features on Leopard or earlier, as they don't - * exist (neither options nor API that uses them). This formally means - * that there's a bug with full-screen windows with Tk on old OSX, but - * it isn't worth blocking a build just for this. - */ - prevMask = [window styleMask]; prevPres = [NSApp presentationOptions]; [window setStyleMask: NSBorderlessWindowMask]; [NSApp setPresentationOptions: NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar]; -#endif /*TK_GOT_AT_LEAST_SNOW_LEOPARD*/ + Tk_MapWindow((Tk_Window) winPtr); } else { wmPtr->flags &= ~WM_FULLSCREEN; - -#ifdef TK_GOT_AT_LEAST_SNOW_LEOPARD [NSApp setPresentationOptions: prevPres]; [window setStyleMask: prevMask]; -#endif /*TK_GOT_AT_LEAST_SNOW_LEOPARD*/ } if (wasFullscreen && !(wmPtr->flags & WM_FULLSCREEN)) { + Tk_UnmapWindow((Tk_Window) winPtr); UInt64 oldAttributes = wmPtr->attributes; NSRect bounds = NSMakeRect(wmPtr->configX, tkMacOSXZeroScreenHeight - (wmPtr->configY + wmPtr->yInParent + wmPtr->configHeight), wmPtr->xInParent + wmPtr->configWidth, wmPtr->yInParent + wmPtr->configHeight); @@ -6554,10 +6524,11 @@ ApplyWindowAttributeFlagChanges(winPtr, window, oldAttributes, wmPtr->flags, 1, 0); wmPtr->flags |= WM_SYNC_PENDING; [window setFrame:[window frameRectForContentRect:bounds] display:YES]; wmPtr->flags &= ~WM_SYNC_PENDING; + Tk_MapWindow((Tk_Window) winPtr); } return result; } /* Index: macosx/tkMacOSXXStubs.c ================================================================== --- macosx/tkMacOSXXStubs.c +++ macosx/tkMacOSXXStubs.c @@ -51,18 +51,10 @@ static XID MacXIdAlloc(Display *display); static int DefaultErrorHandler(Display *display, XErrorEvent *err_evt); -/* - * Other declarations - */ - -static int DestroyImage(XImage *image); -static unsigned long ImageGetPixel(XImage *image, int x, int y); -static int ImagePutPixel(XImage *image, int x, int y, - unsigned long pixel); /* *---------------------------------------------------------------------- * * TkMacOSXDisplayChanged -- @@ -181,11 +173,11 @@ } display->vendor = vendor; { int major, minor, patch; -#if MAC_OS_X_VERSION_MIN_REQUIRED < 10100 +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1080 Gestalt(gestaltSystemVersionMajor, (SInt32*)&major); Gestalt(gestaltSystemVersionMinor, (SInt32*)&minor); Gestalt(gestaltSystemVersionBugFix, (SInt32*)&patch); #else NSOperatingSystemVersion systemVersion = [[NSProcessInfo processInfo] operatingSystemVersion]; @@ -206,10 +198,11 @@ screen->ext_data = (XExtData *) &maxBounds; screen->root_visual = ckalloc(sizeof(Visual)); screen->root_visual->visualid = 0; screen->root_visual->class = TrueColor; + screen->root_visual->alpha_mask = 0xFF000000; screen->root_visual->red_mask = 0x00FF0000; screen->root_visual->green_mask = 0x0000FF00; screen->root_visual->blue_mask = 0x000000FF; screen->root_visual->bits_per_rgb = 24; screen->root_visual->map_entries = 256; @@ -381,17 +374,10 @@ { display->request++; return NULL; } -int -_XInitImageFuncPtrs( - XImage *image) -{ - return 0; -} - XErrorHandler XSetErrorHandler( XErrorHandler handler) { return DefaultErrorHandler; @@ -760,392 +746,10 @@ snprintf(buffer2, sizeof(buffer2), " Mac OS X %x", VendorRelease(Tk_Display(tkwin))); Tcl_AppendResult(interp, buffer, ServerVendor(Tk_Display(tkwin)), buffer2, NULL); } - -#pragma mark XImage handling - -/* - *---------------------------------------------------------------------- - * - * XCreateImage -- - * - * Allocates storage for a new XImage. - * - * Results: - * Returns a newly allocated XImage. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -XImage * -XCreateImage( - Display* display, - Visual* visual, - unsigned int depth, - int format, - int offset, - char* data, - unsigned int width, - unsigned int height, - int bitmap_pad, - int bytes_per_line) -{ - XImage *ximage; - display->request++; - ximage = ckalloc(sizeof(XImage)); - - ximage->height = height; - ximage->width = width; - ximage->depth = depth; - ximage->xoffset = offset; - ximage->format = format; - ximage->data = data; - ximage->obdata = NULL; - /* The default pixelpower is 0. This must be explicitly set to 1 in the - * case of an XImage extracted from a Retina display. - */ - ximage->pixelpower = 0; - - if (format == ZPixmap) { - ximage->bits_per_pixel = 32; - ximage->bitmap_unit = 32; - } else { - ximage->bits_per_pixel = 1; - ximage->bitmap_unit = 8; - } - if (bitmap_pad) { - ximage->bitmap_pad = bitmap_pad; - } else { - /* Use 16 byte alignment for best Quartz perfomance */ - ximage->bitmap_pad = 128; - } - if (bytes_per_line) { - ximage->bytes_per_line = bytes_per_line; - } else { - ximage->bytes_per_line = ((width * ximage->bits_per_pixel + - (ximage->bitmap_pad - 1)) >> 3) & - ~((ximage->bitmap_pad >> 3) - 1); - } -#ifdef WORDS_BIGENDIAN - ximage->byte_order = MSBFirst; - ximage->bitmap_bit_order = MSBFirst; -#else - ximage->byte_order = LSBFirst; - ximage->bitmap_bit_order = LSBFirst; -#endif - ximage->red_mask = 0x00FF0000; - ximage->green_mask = 0x0000FF00; - ximage->blue_mask = 0x000000FF; - ximage->f.create_image = NULL; - ximage->f.destroy_image = DestroyImage; - ximage->f.get_pixel = ImageGetPixel; - ximage->f.put_pixel = ImagePutPixel; - ximage->f.sub_image = NULL; - ximage->f.add_pixel = NULL; - - return ximage; -} - -/* - *---------------------------------------------------------------------- - * - * XGetImage -- - * - * This function copies data from a pixmap or window into an XImage. - * - * Results: - * Returns a newly allocated XImage containing the data from the given - * rectangle of the given drawable, or NULL if the XImage could not be - * constructed. NOTE: If we are copying from a window on a Retina - * display, the dimensions of the XImage will be 2*width x 2*height. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -XImage * -XGetImage( - Display *display, - Drawable d, - int x, - int y, - unsigned int width, - unsigned int height, - unsigned long plane_mask, - int format) -{ - NSBitmapImageRep *bitmap_rep; - NSUInteger bitmap_fmt; - XImage * imagePtr = NULL; - char * bitmap = NULL; - char * image_data=NULL; - int depth = 32; - int offset = 0; - int bitmap_pad = 0; - int bytes_per_row = 4*width; - int size; - MacDrawable *macDraw = (MacDrawable *) d; // Where is this variable used? May it be removed? - int scalefactor = 1; -#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 - NSWindow *win = TkMacOSXDrawableWindow(d); - /* This code assumes that backing scale factors are integers. Currently - * Retina displays use a scale factor of 2.0 and normal displays use 1.0. - * We do not support any other values here. - */ - if (win && [win respondsToSelector:@selector(backingScaleFactor)]) { - scalefactor = ([win backingScaleFactor] == 2.0) ? 2 : 1; - } -#endif - int scaled_height = height * scalefactor; - int scaled_width = width * scalefactor; - - if (format == ZPixmap) { - if (width == 0 || height == 0) { - /* This happens all the time. - TkMacOSXDbgMsg("XGetImage: empty image requested"); - */ - return NULL; - } - - bitmap_rep = BitmapRepFromDrawableRect(d, x, y, width, height); - bitmap_fmt = [bitmap_rep bitmapFormat]; - - if ( bitmap_rep == Nil || - (bitmap_fmt != 0 && bitmap_fmt != 1) || - [bitmap_rep samplesPerPixel] != 4 || - [bitmap_rep isPlanar] != 0 ) { - TkMacOSXDbgMsg("XGetImage: Failed to construct NSBitmapRep"); - return NULL; - } - - NSSize image_size = NSMakeSize(width, height); - NSImage* ns_image = [[NSImage alloc]initWithSize:image_size]; - [ns_image addRepresentation:bitmap_rep]; - - /* Assume premultiplied nonplanar data with 4 bytes per pixel.*/ - if ( [bitmap_rep isPlanar ] == 0 && - [bitmap_rep samplesPerPixel] == 4 ) { - bytes_per_row = [bitmap_rep bytesPerRow]; - assert(bytes_per_row == 4 * scaled_width); - assert([bitmap_rep bytesPerPlane] == bytes_per_row * scaled_height); - size = bytes_per_row*scaled_height; - image_data = (char*)[bitmap_rep bitmapData]; - if ( image_data ) { - int row, n, m; - bitmap = ckalloc(size); - /* - Oddly enough, the bitmap has the top row at the beginning, - and the pixels are in BGRA or ABGR format. - */ - if (bitmap_fmt == 0) { - /* BGRA */ - for (row=0, n=0; rowpixelpower = 1; - } - [ns_image removeRepresentation:bitmap_rep]; /*releases the rep*/ - [ns_image release]; - } - } else { - TkMacOSXDbgMsg("Could not extract image from drawable."); - } - return imagePtr; -} - -/* - *---------------------------------------------------------------------- - * - * DestroyImage -- - * - * Destroys storage associated with an image. - * - * Results: - * None. - * - * Side effects: - * Deallocates the image. - * - *---------------------------------------------------------------------- - */ - -static int -DestroyImage( - XImage *image) -{ - if (image) { - if (image->data) { - ckfree(image->data); - } - ckfree(image); - } - return 0; -} - -/* - *---------------------------------------------------------------------- - * - * ImageGetPixel -- - * - * Get a single pixel from an image. - * - * Results: - * Returns the 32 bit pixel value. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -static unsigned long -ImageGetPixel( - XImage *image, - int x, - int y) -{ - unsigned char r = 0, g = 0, b = 0; - - if (image && image->data) { - unsigned char *srcPtr = ((unsigned char*) image->data) - + (y * image->bytes_per_line) - + (((image->xoffset + x) * image->bits_per_pixel) / NBBY); - - switch (image->bits_per_pixel) { - case 32: { - r = (*((unsigned int*) srcPtr) >> 16) & 0xff; - g = (*((unsigned int*) srcPtr) >> 8) & 0xff; - b = (*((unsigned int*) srcPtr) ) & 0xff; - /*if (image->byte_order == LSBFirst) { - r = srcPtr[2]; g = srcPtr[1]; b = srcPtr[0]; - } else { - r = srcPtr[1]; g = srcPtr[2]; b = srcPtr[3]; - }*/ - break; - } - case 16: - r = (*((unsigned short*) srcPtr) >> 7) & 0xf8; - g = (*((unsigned short*) srcPtr) >> 2) & 0xf8; - b = (*((unsigned short*) srcPtr) << 3) & 0xf8; - break; - case 8: - r = (*srcPtr << 2) & 0xc0; - g = (*srcPtr << 4) & 0xc0; - b = (*srcPtr << 6) & 0xc0; - r |= r >> 2 | r >> 4 | r >> 6; - g |= g >> 2 | g >> 4 | g >> 6; - b |= b >> 2 | b >> 4 | b >> 6; - break; - case 4: { - unsigned char c = (x % 2) ? *srcPtr : (*srcPtr >> 4); - r = (c & 0x04) ? 0xff : 0; - g = (c & 0x02) ? 0xff : 0; - b = (c & 0x01) ? 0xff : 0; - break; - } - case 1: - r = g = b = ((*srcPtr) & (0x80 >> (x % 8))) ? 0xff : 0; - break; - } - } - return (PIXEL_MAGIC << 24) | (r << 16) | (g << 8) | b; -} - -/* - *---------------------------------------------------------------------- - * - * ImagePutPixel -- - * - * Set a single pixel in an image. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -static int -ImagePutPixel( - XImage *image, - int x, - int y, - unsigned long pixel) -{ - if (image && image->data) { - unsigned char r = ((pixel & image->red_mask) >> 16) & 0xff; - unsigned char g = ((pixel & image->green_mask) >> 8) & 0xff; - unsigned char b = ((pixel & image->blue_mask) ) & 0xff; - unsigned char *dstPtr = ((unsigned char*) image->data) - + (y * image->bytes_per_line) - + (((image->xoffset + x) * image->bits_per_pixel) / NBBY); - - switch (image->bits_per_pixel) { - case 32: - *((unsigned int*) dstPtr) = (0xff << 24) | (r << 16) | - (g << 8) | b; - /*if (image->byte_order == LSBFirst) { - dstPtr[3] = 0xff; dstPtr[2] = r; dstPtr[1] = g; dstPtr[0] = b; - } else { - dstPtr[0] = 0xff; dstPtr[1] = r; dstPtr[2] = g; dstPtr[3] = b; - }*/ - break; - case 16: - *((unsigned short*) dstPtr) = ((r & 0xf8) << 7) | - ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); - break; - case 8: - *dstPtr = ((r & 0xc0) >> 2) | ((g & 0xc0) >> 4) | - ((b & 0xc0) >> 6); - break; - case 4: { - unsigned char c = ((r & 0x80) >> 5) | ((g & 0x80) >> 6) | - ((b & 0x80) >> 7); - *dstPtr = (x % 2) ? ((*dstPtr & 0xf0) | (c & 0x0f)) : - ((*dstPtr & 0x0f) | ((c << 4) & 0xf0)); - break; - } - case 1: - *dstPtr = ((r|g|b) & 0x80) ? (*dstPtr | (0x80 >> (x % 8))) : - (*dstPtr & ~(0x80 >> (x % 8))); - break; - } - } - return 0; -} /* *---------------------------------------------------------------------- * * XChangeWindowAttributes, XSetWindowBackground, @@ -1367,11 +971,11 @@ void Tk_ResetUserInactiveTime( Display *dpy) { - IOGPoint loc; + IOGPoint loc = {0, 0}; kern_return_t kr; NXEvent nullEvent = {NX_NULLEVENT, {0, 0}, 0, -1, 0}; enum { kNULLEventPostThrottle = 10 }; static io_connect_t io_connection = MACH_PORT_NULL; Index: tests/bind.test ================================================================== --- tests/bind.test +++ tests/bind.test @@ -31,10 +31,23 @@ bind Toplevel {} bind xyz {} bind {a b} {} bind .t {} } + +# This function fills the pattern matcher's ring buffer with events of +# the specified type. This can be used when testing with generated +# events to make sure that there are no stray events in the ring +# buffer which might cause the pattern matcher to find unintended +# matches. The size of the ring buffer is EVENT_BUFFER_SIZE, which is +# currently set to 30. If this changes, the code below will need to +# change. +proc clearRingBuffer {{event}} { + for {set i 0} {$i < 30} {incr i} { + event generate . $event + } +} # move the mouse pointer away of the testing area # otherwise some spurious events may pollute the tests toplevel .top wm geometry .top 50x50-50-50 @@ -646,12 +659,12 @@ update set x {} } -body { bind .t.f "lappend x Key%K" bind .t.f "lappend x Release%K" - event generate .t.f -keycode 0 - event generate .t.f -keycode 0 + event generate .t.f -keycode -1 + event generate .t.f -keycode -1 return $x } -cleanup { destroy .t.f } -result {Key?? Release??} test bind-13.15 {Tk_BindEvent procedure: button detail} -setup { @@ -1380,14 +1393,15 @@ test bind-15.22 {MatchPatterns procedure, time wrap-around} -setup { frame .t.f -class Test -width 150 -height 100 pack .t.f focus -force .t.f update + clearRingBuffer } -body { bind .t.f {set x 1} set x 0 - event generate .t.f -time [expr -100] + event generate .t.f -time -100 event generate .t.f -time 200 event generate .t.f return $x } -cleanup { destroy .t.f @@ -1395,10 +1409,11 @@ test bind-15.23 {MatchPatterns procedure, time wrap-around} -setup { frame .t.f -class Test -width 150 -height 100 pack .t.f focus -force .t.f update + clearRingBuffer } -body { bind .t.f {set x 1} set x 0 event generate .t.f -time -100 event generate .t.f -time 500 @@ -1405,17 +1420,17 @@ event generate .t.f return $x } -cleanup { destroy .t.f } -result {0} - test bind-15.24 {MatchPatterns procedure, virtual event} -setup { frame .t.f -class Test -width 150 -height 100 pack .t.f focus -force .t.f update set x {} + clearRingBuffer } -body { event add <> bind .t.f <> {lappend x paste} event generate .t.f event generate .t.f @@ -1428,10 +1443,11 @@ frame .t.f -class Test -width 150 -height 100 pack .t.f focus -force .t.f update set x {} + clearRingBuffer } -body { event add <> bind .t.f <> {lappend x paste} event generate .t.f event generate .t.f @@ -1444,10 +1460,11 @@ frame .t.f -class Test -width 150 -height 100 pack .t.f focus -force .t.f update set x {} + clearRingBuffer } -body { event add <>