summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2020-05-21 16:44:10 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2020-05-21 16:44:10 (GMT)
commitfe47d608d0455a3b06522f85f4ccc238e76549bd (patch)
tree5ed0d5752ddf00acb5159003f2af1f47e31e11ff /generic
parent29df448c956c297a8f4c1dfda0ee2c257c48e030 (diff)
downloadtk-fe47d608d0455a3b06522f85f4ccc238e76549bd.zip
tk-fe47d608d0455a3b06522f85f4ccc238e76549bd.tar.gz
tk-fe47d608d0455a3b06522f85f4ccc238e76549bd.tar.bz2
Use more size_t for *Sel*-related functions, in case compiling with Tcl 9
Diffstat (limited to 'generic')
-rw-r--r--generic/tk.h10
-rw-r--r--generic/tkCanvText.c20
-rw-r--r--generic/tkCanvas.c10
-rw-r--r--generic/tkClipboard.c50
-rw-r--r--generic/tkEntry.c24
-rw-r--r--generic/tkListbox.c16
-rw-r--r--generic/tkSelect.c18
-rw-r--r--generic/tkText.c14
-rw-r--r--generic/ttk/ttkEntry.c18
9 files changed, 95 insertions, 85 deletions
diff --git a/generic/tk.h b/generic/tk.h
index c378aea..5bed741 100644
--- a/generic/tk.h
+++ b/generic/tk.h
@@ -1067,8 +1067,13 @@ typedef int (Tk_ItemIndexProc)(Tcl_Interp *interp, Tk_Canvas canvas,
#endif /* USE_OLD_CANVAS */
typedef void (Tk_ItemCursorProc)(Tk_Canvas canvas, Tk_Item *itemPtr,
int index);
+#if TCL_MAJOR_VERSION > 8
+typedef size_t (Tk_ItemSelectionProc)(Tk_Canvas canvas, Tk_Item *itemPtr,
+ size_t offset, char *buffer, size_t maxBytes);
+#else
typedef int (Tk_ItemSelectionProc)(Tk_Canvas canvas, Tk_Item *itemPtr,
int offset, char *buffer, int maxBytes);
+#endif
#ifdef USE_OLD_CANVAS
typedef void (Tk_ItemInsertProc)(Tk_Canvas canvas, Tk_Item *itemPtr,
int beforeThis, char *string);
@@ -1579,8 +1584,13 @@ typedef int (Tk_GetSelProc) (ClientData clientData, Tcl_Interp *interp,
typedef void (Tk_LostSelProc) (ClientData clientData);
typedef Tk_RestrictAction (Tk_RestrictProc) (ClientData clientData,
XEvent *eventPtr);
+#if TCL_MAJOR_VERSION > 8
+typedef size_t (Tk_SelectionProc) (ClientData clientData, size_t offset,
+ char *buffer, size_t maxBytes);
+#else
typedef int (Tk_SelectionProc) (ClientData clientData, int offset,
char *buffer, int maxBytes);
+#endif
/*
*----------------------------------------------------------------------
diff --git a/generic/tkCanvText.c b/generic/tkCanvText.c
index ab7b882..7a68ff2 100644
--- a/generic/tkCanvText.c
+++ b/generic/tkCanvText.c
@@ -146,9 +146,9 @@ static void DeleteText(Tk_Canvas canvas,
static void DisplayCanvText(Tk_Canvas canvas,
Tk_Item *itemPtr, Display *display, Drawable dst,
int x, int y, int width, int height);
-static int GetSelText(Tk_Canvas canvas,
- Tk_Item *itemPtr, int offset, char *buffer,
- int maxBytes);
+static TkSizeT GetSelText(Tk_Canvas canvas,
+ Tk_Item *itemPtr, TkSizeT offset, char *buffer,
+ TkSizeT maxBytes);
static int GetTextIndex(Tcl_Interp *interp,
Tk_Canvas canvas, Tk_Item *itemPtr,
Tcl_Obj *obj, int *indexPtr);
@@ -1516,14 +1516,14 @@ SetTextCursor(
*--------------------------------------------------------------
*/
-static int
+static TkSizeT
GetSelText(
Tk_Canvas canvas, /* Canvas containing selection. */
Tk_Item *itemPtr, /* Text item containing selection. */
- int offset, /* Byte offset within selection of first
+ TkSizeT offset, /* Byte offset within selection of first
* character to be returned. */
char *buffer, /* Location in which to place selection. */
- int maxBytes) /* Maximum number of bytes to place at buffer,
+ TkSizeT maxBytes) /* Maximum number of bytes to place at buffer,
* not including terminating NULL
* character. */
{
@@ -1534,7 +1534,7 @@ GetSelText(
Tk_CanvasTextInfo *textInfoPtr = textPtr->textInfoPtr;
(void)canvas;
- if ((textInfoPtr->selectFirst < 0) ||
+ if ((textInfoPtr->selectFirst == -1) ||
(textInfoPtr->selectFirst > textInfoPtr->selectLast)) {
return 0;
}
@@ -1542,13 +1542,13 @@ GetSelText(
selStart = Tcl_UtfAtIndex(text, textInfoPtr->selectFirst);
selEnd = Tcl_UtfAtIndex(selStart,
textInfoPtr->selectLast + 1 - textInfoPtr->selectFirst);
+ if (selEnd <= selStart + offset) {
+ return 0;
+ }
byteCount = selEnd - selStart - offset;
if (byteCount > maxBytes) {
byteCount = maxBytes;
}
- if (byteCount <= 0) {
- return 0;
- }
memcpy(buffer, selStart + offset, byteCount);
buffer[byteCount] = '\0';
return byteCount;
diff --git a/generic/tkCanvas.c b/generic/tkCanvas.c
index d3868d5..54087e6 100644
--- a/generic/tkCanvas.c
+++ b/generic/tkCanvas.c
@@ -223,8 +223,8 @@ static void CanvasCmdDeletedProc(ClientData clientData);
static void CanvasDoEvent(TkCanvas *canvasPtr, XEvent *eventPtr);
static void CanvasEventProc(ClientData clientData,
XEvent *eventPtr);
-static int CanvasFetchSelection(ClientData clientData, int offset,
- char *buffer, int maxBytes);
+static TkSizeT CanvasFetchSelection(ClientData clientData, TkSizeT offset,
+ char *buffer, TkSizeT maxBytes);
static Tk_Item * CanvasFindClosest(TkCanvas *canvasPtr,
double coords[2]);
static void CanvasFocusProc(TkCanvas *canvasPtr, int gotFocus);
@@ -5689,13 +5689,13 @@ CanvasSelectTo(
*--------------------------------------------------------------
*/
-static int
+static TkSizeT
CanvasFetchSelection(
ClientData clientData, /* Information about canvas widget. */
- int offset, /* Offset within selection of first character
+ TkSizeT offset, /* Offset within selection of first character
* to be returned. */
char *buffer, /* Location in which to place selection. */
- int maxBytes) /* Maximum number of bytes to place at buffer,
+ TkSizeT maxBytes) /* Maximum number of bytes to place at buffer,
* not including terminating NULL
* character. */
{
diff --git a/generic/tkClipboard.c b/generic/tkClipboard.c
index f09958e..308be14 100644
--- a/generic/tkClipboard.c
+++ b/generic/tkClipboard.c
@@ -19,12 +19,12 @@
* Prototypes for functions used only in this file:
*/
-static int ClipboardAppHandler(ClientData clientData,
- int offset, char *buffer, int maxBytes);
-static int ClipboardHandler(ClientData clientData,
- int offset, char *buffer, int maxBytes);
-static int ClipboardWindowHandler(ClientData clientData,
- int offset, char *buffer, int maxBytes);
+static TkSizeT ClipboardAppHandler(ClientData clientData,
+ TkSizeT offset, char *buffer, TkSizeT maxBytes);
+static TkSizeT ClipboardHandler(ClientData clientData,
+ TkSizeT offset, char *buffer, TkSizeT maxBytes);
+static TkSizeT ClipboardWindowHandler(ClientData clientData,
+ TkSizeT offset, char *buffer, TkSizeT maxBytes);
static void ClipboardLostSel(ClientData clientData);
static int ClipboardGetProc(ClientData clientData,
Tcl_Interp *interp, const char *portion);
@@ -48,20 +48,20 @@ static int ClipboardGetProc(ClientData clientData,
*----------------------------------------------------------------------
*/
-static int
+static TkSizeT
ClipboardHandler(
ClientData clientData, /* Information about data to fetch. */
- int offset, /* Return selection bytes starting at this
+ TkSizeT offset, /* Return selection bytes starting at this
* offset. */
char *buffer, /* Place to store converted selection. */
- int maxBytes) /* Maximum # of bytes to store at buffer. */
+ TkSizeT maxBytes) /* Maximum # of bytes to store at buffer. */
{
TkClipboardTarget *targetPtr = (TkClipboardTarget *)clientData;
TkClipboardBuffer *cbPtr;
char *srcPtr, *destPtr;
- size_t count = 0;
- size_t scanned = 0;
- size_t length, freeCount;
+ TkSizeT count = 0;
+ TkSizeT scanned = 0;
+ TkSizeT length, freeCount;
/*
* Skip to buffer containing offset byte
@@ -71,7 +71,7 @@ ClipboardHandler(
if (cbPtr == NULL) {
return 0;
}
- if (scanned + cbPtr->length > (size_t)offset) {
+ if (scanned + cbPtr->length > offset) {
break;
}
scanned += cbPtr->length;
@@ -102,7 +102,7 @@ ClipboardHandler(
srcPtr = cbPtr->buffer;
length = cbPtr->length;
}
- return (int)count;
+ return count;
}
/*
@@ -126,30 +126,30 @@ ClipboardHandler(
*----------------------------------------------------------------------
*/
-static int
+static TkSizeT
ClipboardAppHandler(
ClientData clientData, /* Pointer to TkDisplay structure. */
- int offset, /* Return selection bytes starting at this
+ TkSizeT offset, /* Return selection bytes starting at this
* offset. */
char *buffer, /* Place to store converted selection. */
- int maxBytes) /* Maximum # of bytes to store at buffer. */
+ TkSizeT maxBytes) /* Maximum # of bytes to store at buffer. */
{
TkDisplay *dispPtr = (TkDisplay *)clientData;
- size_t length;
+ TkSizeT length;
const char *p;
p = dispPtr->clipboardAppPtr->winPtr->nameUid;
length = strlen(p);
- length -= offset;
- if (length <= 0) {
+ if (length <= offset) {
return 0;
}
- if (length > (size_t) maxBytes) {
+ length -= offset;
+ if (length > maxBytes) {
length = maxBytes;
}
memcpy(buffer, p, length);
buffer[length] = 0;
- return (int)length;
+ return length;
}
/*
@@ -171,13 +171,13 @@ ClipboardAppHandler(
*----------------------------------------------------------------------
*/
-static int
+static TkSizeT
ClipboardWindowHandler(
ClientData dummy, /* Not used. */
- int offset, /* Return selection bytes starting at this
+ TkSizeT offset, /* Return selection bytes starting at this
* offset. */
char *buffer, /* Place to store converted selection. */
- int maxBytes) /* Maximum # of bytes to store at buffer. */
+ TkSizeT maxBytes) /* Maximum # of bytes to store at buffer. */
{
(void)dummy;
(void)offset;
diff --git a/generic/tkEntry.c b/generic/tkEntry.c
index 1e0f0c4..815b261 100644
--- a/generic/tkEntry.c
+++ b/generic/tkEntry.c
@@ -412,8 +412,8 @@ static void EntryComputeGeometry(Entry *entryPtr);
static void EntryEventProc(ClientData clientData,
XEvent *eventPtr);
static void EntryFocusProc(Entry *entryPtr, int gotFocus);
-static int EntryFetchSelection(ClientData clientData, int offset,
- char *buffer, int maxBytes);
+static TkSizeT EntryFetchSelection(ClientData clientData, TkSizeT offset,
+ char *buffer, TkSizeT maxBytes);
static void EntryLostSelection(ClientData clientData);
static void EventuallyRedraw(Entry *entryPtr);
static void EntryScanTo(Entry *entryPtr, int y);
@@ -2680,7 +2680,7 @@ GetEntryIndex(
*indexPtr = entryPtr->insertPos;
break;
case 's':
- if (entryPtr->selectFirst < 0) {
+ if (entryPtr->selectFirst == -1) {
Tcl_ResetResult(interp);
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"selection isn't in widget %s",
@@ -2885,21 +2885,21 @@ EntrySelectTo(
*----------------------------------------------------------------------
*/
-static int
+static TkSizeT
EntryFetchSelection(
ClientData clientData, /* Information about entry widget. */
- int offset, /* Byte offset within selection of first
+ TkSizeT offset, /* Byte offset within selection of first
* character to be returned. */
char *buffer, /* Location in which to place selection. */
- int maxBytes) /* Maximum number of bytes to place at buffer,
+ TkSizeT maxBytes) /* Maximum number of bytes to place at buffer,
* not including terminating NUL character. */
{
Entry *entryPtr = (Entry *)clientData;
- int byteCount;
+ TkSizeT byteCount;
const char *string;
const char *selStart, *selEnd;
- if ((entryPtr->selectFirst < 0) || (!entryPtr->exportSelection)
+ if ((entryPtr->selectFirst == -1) || (!entryPtr->exportSelection)
|| Tcl_IsSafe(entryPtr->interp)) {
return -1;
}
@@ -2907,14 +2907,14 @@ EntryFetchSelection(
selStart = Tcl_UtfAtIndex(string, entryPtr->selectFirst);
selEnd = Tcl_UtfAtIndex(selStart,
entryPtr->selectLast - entryPtr->selectFirst);
+ if (selEnd <= selStart + offset) {
+ return 0;
+ }
byteCount = selEnd - selStart - offset;
if (byteCount > maxBytes) {
byteCount = maxBytes;
}
- if (byteCount <= 0) {
- return 0;
- }
- memcpy(buffer, selStart + offset, (size_t) byteCount);
+ memcpy(buffer, selStart + offset, byteCount);
buffer[byteCount] = '\0';
return byteCount;
}
diff --git a/generic/tkListbox.c b/generic/tkListbox.c
index 1445f7a..58e6d17 100644
--- a/generic/tkListbox.c
+++ b/generic/tkListbox.c
@@ -409,8 +409,8 @@ static void ListboxComputeGeometry(Listbox *listPtr,
int fontChanged, int maxIsStale, int updateGrid);
static void ListboxEventProc(ClientData clientData,
XEvent *eventPtr);
-static int ListboxFetchSelection(ClientData clientData,
- int offset, char *buffer, int maxBytes);
+static TkSizeT ListboxFetchSelection(ClientData clientData,
+ TkSizeT offset, char *buffer, TkSizeT maxBytes);
static void ListboxLostSelection(ClientData clientData);
static void GenerateListboxSelectEvent(Listbox *listPtr);
static void EventuallyRedrawRange(Listbox *listPtr,
@@ -3112,13 +3112,13 @@ ListboxSelect(
*----------------------------------------------------------------------
*/
-static int
+static TkSizeT
ListboxFetchSelection(
ClientData clientData, /* Information about listbox widget. */
- int offset, /* Offset within selection of first byte to be
+ TkSizeT offset, /* Offset within selection of first byte to be
* returned. */
char *buffer, /* Location in which to place selection. */
- int maxBytes) /* Maximum number of bytes to place at buffer,
+ TkSizeT maxBytes) /* Maximum number of bytes to place at buffer,
* not including terminating NULL
* character. */
{
@@ -3163,12 +3163,12 @@ ListboxFetchSelection(
* Copy the requested portion of the selection to the buffer.
*/
- if (length <= (TkSizeT)offset) {
+ if (length <= offset) {
count = 0;
} else {
count = length - offset;
- if (count > maxBytes) {
- count = maxBytes;
+ if (count > (int)maxBytes) {
+ count = (int)maxBytes;
}
memcpy(buffer, Tcl_DStringValue(&selection) + offset, count);
}
diff --git a/generic/tkSelect.c b/generic/tkSelect.c
index a6548b6..81c6bfe 100644
--- a/generic/tkSelect.c
+++ b/generic/tkSelect.c
@@ -59,8 +59,8 @@ static Tcl_ThreadDataKey dataKey;
* Forward declarations for functions defined in this file:
*/
-static int HandleTclCommand(ClientData clientData,
- int offset, char *buffer, int maxBytes);
+static TkSizeT HandleTclCommand(ClientData clientData,
+ TkSizeT offset, char *buffer, TkSizeT maxBytes);
static void LostSelection(ClientData clientData);
static int SelGetProc(ClientData clientData,
Tcl_Interp *interp, const char *portion);
@@ -1319,13 +1319,13 @@ SelGetProc(
*----------------------------------------------------------------------
*/
-static int
+static TkSizeT
HandleTclCommand(
ClientData clientData, /* Information about command to execute. */
- int offset, /* Return selection bytes starting at this
+ TkSizeT offset, /* Return selection bytes starting at this
* offset. */
char *buffer, /* Place to store converted selection. */
- int maxBytes) /* Maximum # of bytes to store at buffer. */
+ TkSizeT maxBytes) /* Maximum # of bytes to store at buffer. */
{
CommandInfo *cmdInfoPtr = (CommandInfo *)clientData;
int length;
@@ -1349,7 +1349,7 @@ HandleTclCommand(
* character.
*/
- if (offset == cmdInfoPtr->byteOffset) {
+ if ((int)offset == cmdInfoPtr->byteOffset) {
charOffset = cmdInfoPtr->charOffset;
extraBytes = strlen(cmdInfoPtr->buffer);
if (extraBytes > 0) {
@@ -1369,7 +1369,7 @@ HandleTclCommand(
* the offset and maximum # of bytes.
*/
- command = Tcl_ObjPrintf("%s %d %d",
+ command = Tcl_ObjPrintf("%s %d %" TCL_Z_MODIFIER "d",
cmdInfoPtr->command, charOffset, maxBytes);
Tcl_IncrRefCount(command);
@@ -1387,7 +1387,7 @@ HandleTclCommand(
*/
string = Tcl_GetStringFromObj(Tcl_GetObjResult(interp), &length);
- count = (length > maxBytes) ? maxBytes : length;
+ count = (length > (int)maxBytes) ? (int)maxBytes : length;
memcpy(buffer, string, count);
buffer[count] = '\0';
@@ -1397,7 +1397,7 @@ HandleTclCommand(
*/
if (cmdInfoPtr->interp != NULL) {
- if (length <= maxBytes) {
+ if (length <= (int)maxBytes) {
cmdInfoPtr->charOffset += Tcl_NumUtfChars(string, -1);
cmdInfoPtr->buffer[0] = '\0';
} else {
diff --git a/generic/tkText.c b/generic/tkText.c
index 6ba2c6f..1255a3e 100644
--- a/generic/tkText.c
+++ b/generic/tkText.c
@@ -365,8 +365,8 @@ static int CreateWidget(TkSharedText *sharedPtr, Tk_Window tkwin,
int objc, Tcl_Obj *const objv[]);
static void TextEventProc(ClientData clientData,
XEvent *eventPtr);
-static int TextFetchSelection(ClientData clientData, int offset,
- char *buffer, int maxBytes);
+static TkSizeT TextFetchSelection(ClientData clientData, TkSizeT offset,
+ char *buffer, TkSizeT maxBytes);
static int TextIndexSortProc(const void *first,
const void *second);
static int TextInsertCmd(TkSharedText *sharedTextPtr,
@@ -3413,13 +3413,13 @@ DeleteIndexRange(
*----------------------------------------------------------------------
*/
-static int
+static TkSizeT
TextFetchSelection(
ClientData clientData, /* Information about text widget. */
- int offset, /* Offset within selection of first character
+ TkSizeT offset, /* Offset within selection of first character
* to be returned. */
char *buffer, /* Location in which to place selection. */
- int maxBytes) /* Maximum number of bytes to place at buffer,
+ TkSizeT maxBytes) /* Maximum number of bytes to place at buffer,
* not including terminating NULL
* character. */
{
@@ -3489,8 +3489,8 @@ TextFetchSelection(
}
segPtr = TkTextIndexToSeg(&textPtr->selIndex, &offsetInSeg);
chunkSize = segPtr->size - offsetInSeg;
- if (chunkSize > maxBytes) {
- chunkSize = maxBytes;
+ if (chunkSize > (int)maxBytes) {
+ chunkSize = (int)maxBytes;
}
if (textPtr->selIndex.linePtr == search.curIndex.linePtr) {
int leftInRange;
diff --git a/generic/ttk/ttkEntry.c b/generic/ttk/ttkEntry.c
index 4c1581b..1d04059 100644
--- a/generic/ttk/ttkEntry.c
+++ b/generic/ttk/ttkEntry.c
@@ -350,32 +350,32 @@ EntryEditable(Entry *entryPtr)
/* EntryFetchSelection --
* Selection handler for entry widgets.
*/
-static int
+static TkSizeT
EntryFetchSelection(
- ClientData clientData, int offset, char *buffer, int maxBytes)
+ ClientData clientData, TkSizeT offset, char *buffer, TkSizeT maxBytes)
{
Entry *entryPtr = (Entry *)clientData;
- int byteCount;
+ TkSizeT byteCount;
const char *string;
const char *selStart, *selEnd;
- if (entryPtr->entry.selectFirst < 0 || (!entryPtr->entry.exportSelection)
+ if (entryPtr->entry.selectFirst == -1 || (!entryPtr->entry.exportSelection)
|| Tcl_IsSafe(entryPtr->core.interp)) {
- return -1;
+ return TCL_INDEX_NONE;
}
string = entryPtr->entry.displayString;
selStart = Tcl_UtfAtIndex(string, entryPtr->entry.selectFirst);
selEnd = Tcl_UtfAtIndex(selStart,
entryPtr->entry.selectLast - entryPtr->entry.selectFirst);
+ if (selEnd <= selStart + offset) {
+ return 0;
+ }
byteCount = selEnd - selStart - offset;
if (byteCount > maxBytes) {
/* @@@POSSIBLE BUG: Can transfer partial UTF-8 sequences. Is this OK? */
byteCount = maxBytes;
}
- if (byteCount <= 0) {
- return 0;
- }
memcpy(buffer, selStart + offset, byteCount);
buffer[byteCount] = '\0';
return byteCount;
@@ -1389,7 +1389,7 @@ EntryIndex(
} else if (strncmp(string, "right", length) == 0) { /* for debugging */
*indexPtr = entryPtr->entry.xscroll.last;
} else if (strncmp(string, "sel.", 4) == 0) {
- if (entryPtr->entry.selectFirst < 0) {
+ if (entryPtr->entry.selectFirst == -1) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"selection isn't in widget %s",
Tk_PathName(entryPtr->core.tkwin)));