diff --git a/apps/file_manager/ui.cpp b/apps/file_manager/ui.cpp index ecd6150..adaaf36 100644 --- a/apps/file_manager/ui.cpp +++ b/apps/file_manager/ui.cpp @@ -181,6 +181,12 @@ void InstanceRefreshViewType(Instance *instance) { } } +void InstanceRemoveItemSelectionCommands(EsInstance *instance) { + EsCommandSetCallback(EsCommandByID(instance, ES_COMMAND_CUT), nullptr); + EsCommandSetCallback(EsCommandByID(instance, ES_COMMAND_COPY), nullptr); + EsCommandSetCallback(EsCommandByID(instance, ES_COMMAND_PASTE), nullptr); +} + void InstanceUpdateItemSelectionCountCommands(Instance *instance) { EsCommandSetEnabled(&instance->commandRename, instance->selectedItemCount == 1 && instance->folder->itemHandler->renameItem && !instance->folder->readOnly); @@ -724,10 +730,12 @@ int ListCallback(EsElement *element, EsMessage *message) { if (message->type == ES_MSG_FOCUSED_START || message->type == ES_MSG_PRIMARY_CLIPBOARD_UPDATED) { InstanceUpdateItemSelectionCountCommands(instance); return 0; + } else if (message->type == ES_MSG_DESTROY) { + if (EsElementIsFocused(element)) { + InstanceRemoveItemSelectionCommands(instance); + } } else if (message->type == ES_MSG_FOCUSED_END) { - EsCommandSetCallback(EsCommandByID(instance, ES_COMMAND_CUT), nullptr); - EsCommandSetCallback(EsCommandByID(instance, ES_COMMAND_COPY), nullptr); - EsCommandSetCallback(EsCommandByID(instance, ES_COMMAND_PASTE), nullptr); + InstanceRemoveItemSelectionCommands(instance); return 0; } else if (message->type == ES_MSG_LIST_VIEW_GET_CONTENT) { int column = message->getContent.columnID, index = message->getContent.index; diff --git a/desktop/desktop.cpp b/desktop/desktop.cpp index 2c74d72..520923d 100644 --- a/desktop/desktop.cpp +++ b/desktop/desktop.cpp @@ -793,6 +793,10 @@ int WindowTabMessage(EsElement *element, EsMessage *message) { WindowTabBand *band = (WindowTabBand *) tab->parent; if (message->type == ES_MSG_DESTROY) { + if (tab->dragging) { + EsElementSetDisabled(band->GetChild(0), false); + } + band->container->openTabs.FindAndDelete(tab, false); if (tab->notRespondingInstance) { diff --git a/desktop/gui.cpp b/desktop/gui.cpp index ea4b8d9..2ca8c41 100644 --- a/desktop/gui.cpp +++ b/desktop/gui.cpp @@ -3710,8 +3710,8 @@ EsDialog *EsDialogShow(EsWindow *window, const char *title, ptrdiff_t titleBytes if (window->focused) { window->inactiveFocus = window->focused; window->inactiveFocus->Repaint(true); - UIRemoveFocusFromElement(window->focused); window->focused = nullptr; + UIRemoveFocusFromElement(window->focused); } EsElement *mainStack = window->children[0]; @@ -6101,10 +6101,6 @@ void EsElement::Destroy(bool manual) { } } - if (state & UI_STATE_FOCUSED) { - UIRemoveFocusFromElement(this); - } - state |= UI_STATE_DESTROYING | UI_STATE_DESTROYING_CHILD | UI_STATE_BLOCK_INTERACTION; if (parent) { @@ -6712,6 +6708,7 @@ void EsElementSetDisabled(EsElement *element, bool disabled) { EsMessageMutexCheck(); if (element->window->focused == element) { + element->window->focused = nullptr; UIRemoveFocusFromElement(element); } @@ -6727,10 +6724,6 @@ void EsElementSetDisabled(EsElement *element, bool disabled) { else element->flags &= ~ES_ELEMENT_DISABLED; element->MaybeRefreshStyle(); - - if (element->window->focused == element) { - element->window->focused = nullptr; - } } void EsElementDestroy(EsElement *element) { @@ -7792,6 +7785,10 @@ void UIProcessWindowManagerMessage(EsWindow *window, EsMessage *message, Process window->hovering = true; } else if (message->type == ES_MSG_WINDOW_DEACTIVATED) { if (window->activated) { + if (window->pressed) { + UIMouseUp(window, nullptr, false); + } + AccessKeyModeExit(); if (window->windowStyle == ES_WINDOW_MENU) { @@ -7804,8 +7801,8 @@ void UIProcessWindowManagerMessage(EsWindow *window, EsMessage *message, Process if (window->focused) { window->inactiveFocus = window->focused; window->inactiveFocus->Repaint(true); - UIRemoveFocusFromElement(window->focused); window->focused = nullptr; + UIRemoveFocusFromElement(window->focused); } EsMessageSend(window, message); @@ -7815,8 +7812,6 @@ void UIProcessWindowManagerMessage(EsWindow *window, EsMessage *message, Process gui.leftModifiers = message->windowActivated.leftModifiers; gui.rightModifiers = message->windowActivated.rightModifiers; - UIMouseUp(window, nullptr, false); - if (!window->activated) { AccessKeyModeExit(); diff --git a/desktop/list_view.cpp b/desktop/list_view.cpp index ea17dd4..a02e960 100644 --- a/desktop/list_view.cpp +++ b/desktop/list_view.cpp @@ -1778,6 +1778,10 @@ struct EsListView : EsElement { groups.Free(); activeColumns.Free(); registeredColumns.Free(); + + if (EsElementIsFocused(this)) { + EsCommandSetCallback(EsCommandByID(instance, ES_COMMAND_SELECT_ALL), nullptr); + } } else if (message->type == ES_MSG_KEY_UP) { if (message->keyboard.scancode == ES_SCANCODE_LEFT_CTRL || message->keyboard.scancode == ES_SCANCODE_RIGHT_CTRL) { SelectPreview(); @@ -1833,6 +1837,7 @@ struct EsListView : EsElement { item->element->MaybeRefreshStyle(); } + // Also done in ES_MSG_DESTROY: EsCommandSetCallback(EsCommandByID(instance, ES_COMMAND_SELECT_ALL), nullptr); } else if (message->type == ES_MSG_MOUSE_RIGHT_DOWN) { // Make sure that right clicking will focus the list. diff --git a/desktop/os.header b/desktop/os.header index d25ae32..59e595a 100644 --- a/desktop/os.header +++ b/desktop/os.header @@ -954,7 +954,7 @@ enum EsMessageType { // this allows messageUser to block input processing by returning ES_REJECTED. ES_MSG_SCROLL_X = 0x2012 // The element has been horizontally scrolled. ES_MSG_SCROLL_Y = 0x2013 // The element has been vertically scrolled. - ES_MSG_STRONG_FOCUS_END = 0x2014 // Sent once when the user 'clicks off' the element, even if a new element was not necessarily focused. + ES_MSG_STRONG_FOCUS_END = 0x2014 // Sent once when the user 'clicks off' the element, even if a new element was not necessarily focused. Not sent when destroying the element! ES_MSG_BEFORE_Z_ORDER = 0x2015 // Sent before a batch of Z_ORDER messages. ES_MSG_AFTER_Z_ORDER = 0x2016 // Sent after a batch of Z_ORDER messages. ES_MSG_PAINT_CHILDREN = 0x2017 // Paint the element's children. Useful for animations, with EsPaintTargetTake/Return. @@ -982,13 +982,13 @@ enum EsMessageType { // State change messages: (causes a style refresh) ES_MSG_STATE_CHANGE_MESSAGE_START = 0x2080 ES_MSG_HOVERED_START = 0x2081 // Sent when the mouse starts hovering over an element. - ES_MSG_HOVERED_END = 0x2082 // Opposite of ES_MSG_HOVERED_START. Sent before ES_MSG_HOVERED_START is sent to the new hovered element. + ES_MSG_HOVERED_END = 0x2082 // Opposite of ES_MSG_HOVERED_START. Sent before ES_MSG_HOVERED_START is sent to the new hovered element. Not sent when destroying the element! ES_MSG_PRESSED_START = 0x2083 // Sent when an element is pressed. - ES_MSG_PRESSED_END = 0x2084 // Opposite of ES_MSG_PRESSED_START. + ES_MSG_PRESSED_END = 0x2084 // Opposite of ES_MSG_PRESSED_START. Not sent when destroying the element! ES_MSG_FOCUSED_START = 0x2085 // Sent when an element is focused. - ES_MSG_FOCUSED_END = 0x2086 // Opposite of ES_MSG_FOCUSED_START. + ES_MSG_FOCUSED_END = 0x2086 // Opposite of ES_MSG_FOCUSED_START. Not sent when destroying the element! ES_MSG_FOCUS_WITHIN_START = 0x2087 // Sent when an element is focused. - ES_MSG_FOCUS_WITHIN_END = 0x2088 // Opposite of ES_MSG_FOCUSED_START. + ES_MSG_FOCUS_WITHIN_END = 0x2088 // Opposite of ES_MSG_FOCUSED_START. Not sent when destroying the element! ES_MSG_STATE_CHANGE_MESSAGE_END = 0x20FF // Element messages: diff --git a/desktop/textbox.cpp b/desktop/textbox.cpp index 06b0fb7..3c69e95 100644 --- a/desktop/textbox.cpp +++ b/desktop/textbox.cpp @@ -1510,6 +1510,14 @@ void TextboxAddSmartContextMenu(EsTextbox *textbox, EsMenu *menu) { } } +void TextboxUnregisterCommands(EsTextbox *textbox) { + EsCommandSetCallback(EsCommandByID(textbox->instance, ES_COMMAND_SELECT_ALL), nullptr); + EsCommandSetCallback(EsCommandByID(textbox->instance, ES_COMMAND_DELETE), nullptr); + EsCommandSetCallback(EsCommandByID(textbox->instance, ES_COMMAND_COPY), nullptr); + EsCommandSetCallback(EsCommandByID(textbox->instance, ES_COMMAND_CUT), nullptr); + EsCommandSetCallback(EsCommandByID(textbox->instance, ES_COMMAND_PASTE), nullptr); +} + int ProcessTextboxMessage(EsElement *element, EsMessage *message) { EsTextbox *textbox = (EsTextbox *) element; @@ -1608,6 +1616,7 @@ int ProcessTextboxMessage(EsElement *element, EsMessage *message) { TextboxRefreshVisibleLines(textbox); } else if (message->type == ES_MSG_DESTROY) { + if (EsElementIsFocused(textbox)) TextboxUnregisterCommands(textbox); textbox->visibleLines.Free(); textbox->lines.Free(); UndoManagerDestroy(&textbox->localUndo); @@ -1757,11 +1766,7 @@ int ProcessTextboxMessage(EsElement *element, EsMessage *message) { EsInstanceSetActiveUndoManager(textbox->instance, textbox->undo); textbox->Repaint(true); } else if (message->type == ES_MSG_FOCUSED_END) { - EsCommandSetCallback(EsCommandByID(textbox->instance, ES_COMMAND_SELECT_ALL), nullptr); - EsCommandSetCallback(EsCommandByID(textbox->instance, ES_COMMAND_DELETE), nullptr); - EsCommandSetCallback(EsCommandByID(textbox->instance, ES_COMMAND_COPY), nullptr); - EsCommandSetCallback(EsCommandByID(textbox->instance, ES_COMMAND_CUT), nullptr); - EsCommandSetCallback(EsCommandByID(textbox->instance, ES_COMMAND_PASTE), nullptr); + TextboxUnregisterCommands(textbox); EsInstanceSetActiveUndoManager(textbox->instance, textbox->instance->undoManager); textbox->Repaint(true); } else if (message->type == ES_MSG_STRONG_FOCUS_END) {