1
0
mirror of https://github.com/gryf/wmaker.git synced 2026-03-22 11:23:31 +01:00

WINGs: fix right and center aligned wtextfield

This patch is fixing some issues in how right and center aligned
wtextfields are handled.
-text selection with mouse was not working properly especially
setting and identifying the cursor position
-middle button paste was only working for left aligned text
This commit is contained in:
David Maciejak
2026-01-25 14:11:23 -05:00
committed by Carlos R. Mafra
parent b09ac30233
commit 77db6dc649

View File

@@ -853,8 +853,8 @@ static void paintTextField(TextField * tPtr)
count = tPtr->viewPosition; count = tPtr->viewPosition;
} }
rx = tPtr->offsetWidth + 1 + WMWidthOfString(tPtr->font, text, count) rx = tx + WMWidthOfString(tPtr->font, &(text[tPtr->viewPosition]),
- WMWidthOfString(tPtr->font, text, tPtr->viewPosition); count - tPtr->viewPosition);
WMDrawImageString(screen, drawbuffer, color, screen->gray, WMDrawImageString(screen, drawbuffer, color, screen->gray,
tPtr->font, rx, ty, &(text[count]), count2); tPtr->font, rx, ty, &(text[count]), count2);
@@ -1405,7 +1405,25 @@ static void handleTextFieldActionEvents(XEvent * event, void *data)
tPtr->viewPosition); tPtr->viewPosition);
} }
if (tPtr->flags.alignment == WARight) {
int textWidth = WMWidthOfString(tPtr->font, tPtr->text, tPtr->textLen);
if (textWidth < tPtr->usableWidth) {
tPtr->cursorPosition = pointToCursorPosition(tPtr,
event->xmotion.x - tPtr->usableWidth + textWidth);
} else {
tPtr->cursorPosition = pointToCursorPosition(tPtr, event->xmotion.x); tPtr->cursorPosition = pointToCursorPosition(tPtr, event->xmotion.x);
}
} else if (tPtr->flags.alignment == WACenter) {
int textWidth = WMWidthOfString(tPtr->font, tPtr->text, tPtr->textLen);
if (textWidth < tPtr->usableWidth) {
tPtr->cursorPosition = pointToCursorPosition(tPtr,
event->xmotion.x - (tPtr->usableWidth - textWidth) / 2);
} else {
tPtr->cursorPosition = pointToCursorPosition(tPtr, event->xmotion.x);
}
} else {
tPtr->cursorPosition = pointToCursorPosition(tPtr, event->xmotion.x);
}
/* Do not allow text selection in secure textfields */ /* Do not allow text selection in secure textfields */
if (tPtr->flags.secure) { if (tPtr->flags.secure) {
@@ -1438,10 +1456,6 @@ static void handleTextFieldActionEvents(XEvent * event, void *data)
if (tPtr->flags.enabled && !tPtr->flags.focused) { if (tPtr->flags.enabled && !tPtr->flags.focused) {
WMSetFocusToWidget(tPtr); WMSetFocusToWidget(tPtr);
} }
if (tPtr->flags.focused) {
tPtr->selection.position = tPtr->cursorPosition;
tPtr->selection.count = 0;
}
if (textWidth < tPtr->usableWidth) { if (textWidth < tPtr->usableWidth) {
tPtr->cursorPosition = pointToCursorPosition(tPtr, tPtr->cursorPosition = pointToCursorPosition(tPtr,
event->xbutton.x - tPtr->usableWidth event->xbutton.x - tPtr->usableWidth
@@ -1449,6 +1463,28 @@ static void handleTextFieldActionEvents(XEvent * event, void *data)
} else } else
tPtr->cursorPosition = pointToCursorPosition(tPtr, event->xbutton.x); tPtr->cursorPosition = pointToCursorPosition(tPtr, event->xbutton.x);
if (tPtr->flags.focused) {
tPtr->selection.position = tPtr->cursorPosition;
tPtr->selection.count = 0;
}
paintTextField(tPtr);
break;
case WACenter:
textWidth = WMWidthOfString(tPtr->font, tPtr->text, tPtr->textLen);
if (tPtr->flags.enabled && !tPtr->flags.focused) {
WMSetFocusToWidget(tPtr);
}
if (textWidth < tPtr->usableWidth) {
tPtr->cursorPosition = pointToCursorPosition(tPtr,
event->xbutton.x - (tPtr->usableWidth - textWidth) / 2);
} else {
tPtr->cursorPosition = pointToCursorPosition(tPtr, event->xbutton.x);
}
if (tPtr->flags.focused) {
tPtr->selection.position = tPtr->cursorPosition;
tPtr->selection.count = 0;
}
paintTextField(tPtr); paintTextField(tPtr);
break; break;
@@ -1462,6 +1498,11 @@ static void handleTextFieldActionEvents(XEvent * event, void *data)
tPtr->selection.count = 0; tPtr->selection.count = 0;
paintTextField(tPtr); paintTextField(tPtr);
} }
break;
default:
break;
}
if (event->xbutton.button == Button2 && tPtr->flags.enabled) { if (event->xbutton.button == Button2 && tPtr->flags.enabled) {
char *text; char *text;
int n; int n;
@@ -1481,10 +1522,7 @@ static void handleTextFieldActionEvents(XEvent * event, void *data)
tPtr->flags.waitingSelection = 1; tPtr->flags.waitingSelection = 1;
} }
} }
break;
default:
break;
}
break; break;
case ButtonRelease: case ButtonRelease: