Is there any way of changing the case (upper/lower/normal) of an edit control ?
If not is it possible to turn caps lock on/off programmatically ?
Do you mean in a script dialog? That's a property you can set in the dialog editor.
Yes - but I would like to change this programmitically through Jscript by clicking on an icon in the dialog
toUpper() and toLower() will not change case of current letters being entered.
(changing case whilst editing results in dreaded infinite loop)
Set a variable which says you're the one making the change (then clear it after the change is made), so you don't react to it.
not sure what yuou mean, a few lines of example code please
Not working. I have tried changing the focus to edit2 control then updating edit1 control. If focus is not changed back then no infinite loop but the input is now in another edit control. If the focus is changed back it results in an infinite loop.
Lesson: value of an edit control cannot be changed whilst being edited.
The answer is in the OP I believe, being able to toggle Caps Lock programmitically would work, is this possible ?
It's not a big problem to implement it as per Leo's advice to avoid infinite loops, but there is still a problem when you type and replace the text programmatically the cursor position will be reset (current workaround is to force the cursor position to the end to prevent the text reversing while typing at least).
Button to download, run and inspect:
Force case demo.dcf (5.4 KB)
Screenshot:
Code (but code comments are not rendering here for some reason)
function OnClick(clickData)
{
var dlg = clickData.func.Dlg;
dlg.template = "dialog1";
dlg.Create();
// --------------
var dlgEditBox1 = dlg.control("edit1");
var mode = "disabled";
var modeChanged = false;
// --------------
function forceCase() {
if (mode === "disabled") {
return;
}
modeChanged = true;
switch (mode) {
case "lower":
dlgEditBox1.value(dlgEditBox1.value.toLowerCase());
break;
case "upper":
dlgEditBox1.value(dlgEditBox1.value.toUpperCase());
break;
}
dlgEditBox1.SelectRange(dlgEditBox1.value.length); // Move cursor to end (workaround).
}
function setMode(aMode) {
mode = aMode;
forceCase();
}
// Main loop ----
var msg = null;
while (true)
{
msg = dlg.GetMsg();
if (msg != true) {
break;
}
switch (msg.control)
{
case "radioDisabled":
if (msg.event === "click") {
setMode("disabled");
}
break;
case "radioLower":
if (msg.event === "click") {
setMode("lower");
}
break;
case "radioUpper":
if (msg.event === "click") {
setMode("upper");
}
break;
case "edit1":
if (modeChanged) {
DOpus.Output(msg.event);
modeChanged = false;
break; // Ignore this event (infinite loop).
}
forceCase();
break;
}
}
}
We'll add a way to change this in the next beta.
Thanks all, @bytespiller solution works great, just annoying when editing the middle of a string as cursor is always forced to end.