mirror of
https://github.com/gryf/wmaker.git
synced 2026-03-19 17:23:33 +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:
committed by
Carlos R. Mafra
parent
b09ac30233
commit
77db6dc649
@@ -853,8 +853,8 @@ static void paintTextField(TextField * tPtr)
|
||||
count = tPtr->viewPosition;
|
||||
}
|
||||
|
||||
rx = tPtr->offsetWidth + 1 + WMWidthOfString(tPtr->font, text, count)
|
||||
- WMWidthOfString(tPtr->font, text, tPtr->viewPosition);
|
||||
rx = tx + WMWidthOfString(tPtr->font, &(text[tPtr->viewPosition]),
|
||||
count - tPtr->viewPosition);
|
||||
|
||||
WMDrawImageString(screen, drawbuffer, color, screen->gray,
|
||||
tPtr->font, rx, ty, &(text[count]), count2);
|
||||
@@ -1405,7 +1405,25 @@ static void handleTextFieldActionEvents(XEvent * event, void *data)
|
||||
tPtr->viewPosition);
|
||||
}
|
||||
|
||||
tPtr->cursorPosition = pointToCursorPosition(tPtr, event->xmotion.x);
|
||||
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);
|
||||
}
|
||||
} 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 */
|
||||
if (tPtr->flags.secure) {
|
||||
@@ -1438,17 +1456,35 @@ static void handleTextFieldActionEvents(XEvent * event, void *data)
|
||||
if (tPtr->flags.enabled && !tPtr->flags.focused) {
|
||||
WMSetFocusToWidget(tPtr);
|
||||
}
|
||||
if (textWidth < tPtr->usableWidth) {
|
||||
tPtr->cursorPosition = pointToCursorPosition(tPtr,
|
||||
event->xbutton.x - tPtr->usableWidth
|
||||
+ textWidth);
|
||||
} else
|
||||
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);
|
||||
} else
|
||||
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);
|
||||
break;
|
||||
|
||||
@@ -1462,29 +1498,31 @@ static void handleTextFieldActionEvents(XEvent * event, void *data)
|
||||
tPtr->selection.count = 0;
|
||||
paintTextField(tPtr);
|
||||
}
|
||||
if (event->xbutton.button == Button2 && tPtr->flags.enabled) {
|
||||
char *text;
|
||||
int n;
|
||||
|
||||
if (!WMRequestSelection(tPtr->view, XA_PRIMARY, XA_STRING,
|
||||
event->xbutton.time, pasteText, NULL)) {
|
||||
text = XFetchBuffer(tPtr->view->screen->display, &n, 0);
|
||||
|
||||
if (text) {
|
||||
text[n] = 0;
|
||||
WMInsertTextFieldText(tPtr, text, tPtr->cursorPosition);
|
||||
XFree(text);
|
||||
NOTIFY(tPtr, didChange, WMTextDidChangeNotification,
|
||||
(void *)WMInsertTextEvent);
|
||||
}
|
||||
} else {
|
||||
tPtr->flags.waitingSelection = 1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (event->xbutton.button == Button2 && tPtr->flags.enabled) {
|
||||
char *text;
|
||||
int n;
|
||||
|
||||
if (!WMRequestSelection(tPtr->view, XA_PRIMARY, XA_STRING,
|
||||
event->xbutton.time, pasteText, NULL)) {
|
||||
text = XFetchBuffer(tPtr->view->screen->display, &n, 0);
|
||||
|
||||
if (text) {
|
||||
text[n] = 0;
|
||||
WMInsertTextFieldText(tPtr, text, tPtr->cursorPosition);
|
||||
XFree(text);
|
||||
NOTIFY(tPtr, didChange, WMTextDidChangeNotification,
|
||||
(void *)WMInsertTextEvent);
|
||||
}
|
||||
} else {
|
||||
tPtr->flags.waitingSelection = 1;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case ButtonRelease:
|
||||
|
||||
Reference in New Issue
Block a user