mirror of https://github.com/buggins/dlangui.git
commit
b5b15d0b44
|
@ -467,6 +467,8 @@ enum State : uint {
|
|||
WindowFocused = 256,
|
||||
/// widget is default control for form (should be focused when window gains focus first time)
|
||||
Default = 512, // widget is default for form (e.g. default button will be focused on show)
|
||||
/// widget has been focused by keyboard navigation
|
||||
KeyboardFocused = 1024,
|
||||
/// return state of parent instead of widget's state when requested
|
||||
Parent = 0x10000, // use parent's state
|
||||
}
|
||||
|
|
|
@ -523,19 +523,22 @@ class Window : CustomEventTarget {
|
|||
}
|
||||
|
||||
/// change focus to widget
|
||||
Widget setFocus(Widget newFocus) {
|
||||
Widget setFocus(Widget newFocus, FocusReason reason = FocusReason.Unspecified) {
|
||||
if (!isChild(_focusedWidget))
|
||||
_focusedWidget = null;
|
||||
Widget oldFocus = _focusedWidget;
|
||||
auto targetState = State.Focused;
|
||||
if(reason == FocusReason.TabFocus)
|
||||
targetState = State.Focused | State.KeyboardFocused;
|
||||
if (oldFocus is newFocus)
|
||||
return oldFocus;
|
||||
if (oldFocus !is null)
|
||||
oldFocus.resetState(State.Focused);
|
||||
oldFocus.resetState(targetState);
|
||||
if (newFocus is null || isChild(newFocus)) {
|
||||
if (newFocus !is null) {
|
||||
// when calling, setState(focused), window.focusedWidget is still previously focused widget
|
||||
debug(DebugFocus) Log.d("new focus: ", newFocus.id);
|
||||
newFocus.setState(State.Focused);
|
||||
newFocus.setState(targetState);
|
||||
}
|
||||
_focusedWidget = newFocus;
|
||||
// after focus change, ask for actions update automatically
|
||||
|
|
|
@ -241,6 +241,9 @@ class EditWidgetBase : ScrollWidgetBase, EditableContentListener, MenuItemAction
|
|||
protected int _iconsWidth = 0;
|
||||
protected int _foldingWidth = 0;
|
||||
|
||||
protected bool _selectAllWhenFocusedWithTab = false;
|
||||
protected bool _deselectAllWhenUnfocused = false;
|
||||
|
||||
protected bool _replaceMode;
|
||||
|
||||
// TODO: move to styles
|
||||
|
@ -920,13 +923,20 @@ class EditWidgetBase : ScrollWidgetBase, EditableContentListener, MenuItemAction
|
|||
}
|
||||
|
||||
/// override to handle focus changes
|
||||
override protected void handleFocusChange(bool focused) {
|
||||
override protected void handleFocusChange(bool focused, bool receivedFocusFromKeyboard = false) {
|
||||
if (focused)
|
||||
startCaretBlinking();
|
||||
else {
|
||||
stopCaretBlinking();
|
||||
cancelHoverTimer();
|
||||
|
||||
if(_deselectAllWhenUnfocused) {
|
||||
_selectionRange.start = _caretPos;
|
||||
_selectionRange.end = _caretPos;
|
||||
}
|
||||
}
|
||||
if(focused && _selectAllWhenFocusedWithTab && receivedFocusFromKeyboard)
|
||||
handleAction(ACTION_EDITOR_SELECT_ALL);
|
||||
super.handleFocusChange(focused);
|
||||
}
|
||||
|
||||
|
@ -1643,7 +1653,9 @@ class EditWidgetBase : ScrollWidgetBase, EditableContentListener, MenuItemAction
|
|||
if (event.doubleClick) {
|
||||
selectWordByMouse(event.x - _clientRect.left, event.y - _clientRect.top);
|
||||
} else {
|
||||
updateCaretPositionByMouse(event.x - _clientRect.left, event.y - _clientRect.top, false);
|
||||
auto doSelect = cast(bool)(event.keyFlags & MouseFlag.Shift);
|
||||
updateCaretPositionByMouse(event.x - _clientRect.left, event.y - _clientRect.top, doSelect);
|
||||
|
||||
if (event.keyFlags == MouseFlag.Control)
|
||||
onControlClick();
|
||||
}
|
||||
|
@ -1730,6 +1742,8 @@ class EditLine : EditWidgetBase {
|
|||
super(ID, ScrollBarMode.Invisible, ScrollBarMode.Invisible);
|
||||
_content = new EditableContent(false);
|
||||
_content.contentChanged = this;
|
||||
_selectAllWhenFocusedWithTab = true;
|
||||
_deselectAllWhenUnfocused = true;
|
||||
wantTabs = false;
|
||||
styleId = STYLE_EDIT_LINE;
|
||||
text = initialContent;
|
||||
|
|
|
@ -732,7 +732,7 @@ class ListWidget : WidgetGroup, OnScrollHandler, OnAdapterChangeHandler {
|
|||
}
|
||||
|
||||
/// override to handle focus changes
|
||||
override protected void handleFocusChange(bool focused) {
|
||||
override protected void handleFocusChange(bool focused, bool receivedFocusFromKeyboard = false) {
|
||||
updateSelectedItemFocus();
|
||||
}
|
||||
|
||||
|
|
|
@ -887,7 +887,7 @@ class MainMenu : MenuWidgetBase {
|
|||
}
|
||||
|
||||
/// override to handle focus changes
|
||||
override protected void handleFocusChange(bool focused) {
|
||||
override protected void handleFocusChange(bool focused, bool receivedFocusFromKeyboard = false) {
|
||||
debug(DebugMenus) Log.d("menu ", id, "handling focus change to ", focused);
|
||||
if (focused && _openedPopup is null) {
|
||||
// activating!
|
||||
|
|
|
@ -71,6 +71,11 @@ enum Orientation : ubyte {
|
|||
Horizontal
|
||||
}
|
||||
|
||||
enum FocusReason : ubyte {
|
||||
TabFocus,
|
||||
Unspecified
|
||||
}
|
||||
|
||||
/// interface - slot for onClick
|
||||
interface OnClickHandler {
|
||||
bool onClick(Widget source);
|
||||
|
@ -280,7 +285,7 @@ public:
|
|||
return _state | State.WindowFocused; // TODO:
|
||||
}
|
||||
/// override to handle focus changes
|
||||
protected void handleFocusChange(bool focused) {
|
||||
protected void handleFocusChange(bool focused, bool receivedFocusFromKeyboard = false) {
|
||||
invalidate();
|
||||
focusChange(this, focused);
|
||||
}
|
||||
|
@ -300,7 +305,7 @@ public:
|
|||
if ((oldState & State.Focused) && !(newState & State.Focused))
|
||||
handleFocusChange(false);
|
||||
else if (!(oldState & State.Focused) && (newState & State.Focused))
|
||||
handleFocusChange(true);
|
||||
handleFocusChange(true, cast(bool)(newState & State.KeyboardFocused));
|
||||
// notify checked changes
|
||||
if ((oldState & State.Checked) && !(newState & State.Checked))
|
||||
handleCheckChange(false);
|
||||
|
@ -990,7 +995,7 @@ public:
|
|||
Widget nextWidget = findNextFocusWidget(direction);
|
||||
if (!nextWidget)
|
||||
return false;
|
||||
nextWidget.setFocus();
|
||||
nextWidget.setFocus(FocusReason.TabFocus);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1009,7 +1014,7 @@ public:
|
|||
}
|
||||
|
||||
/// sets focus to this widget or suitable focusable child, returns previously focused widget
|
||||
Widget setFocus() {
|
||||
Widget setFocus(FocusReason reason = FocusReason.Unspecified) {
|
||||
if (window is null)
|
||||
return null;
|
||||
if (!visible)
|
||||
|
@ -1020,11 +1025,11 @@ public:
|
|||
if (!w)
|
||||
w = findFocusableChild(false);
|
||||
if (w)
|
||||
return window.setFocus(w);
|
||||
return window.setFocus(w, reason);
|
||||
// try to find focusable child
|
||||
return window.focusedWidget;
|
||||
}
|
||||
return window.setFocus(this);
|
||||
return window.setFocus(this, reason);
|
||||
}
|
||||
/// searches children for first focusable item, returns null if not found
|
||||
Widget findFocusableChild(bool defaultOnly) {
|
||||
|
|
Loading…
Reference in New Issue