Ghidra is a software reverse engineering (SRE) framework
GT-3015 - PR-451 - Field Panel horizontal scrolling fixup for Byte Viewer; added option; updated help
dragonmachercc138893a14e
diff --git a/Ghidra/Features/Base/src/main/help/help/topics/CodeBrowserPlugin/CodeBrowser.htm b/Ghidra/Features/Base/src/main/help/help/topics/CodeBrowserPlugin/CodeBrowser.htmindex b8d8989483..e0214e2014 100644--- a/Ghidra/Features/Base/src/main/help/help/topics/CodeBrowserPlugin/CodeBrowser.htm+++ b/Ghidra/Features/Base/src/main/help/help/topics/CodeBrowserPlugin/CodeBrowser.htm@@ -128,7 +128,7 @@dialog.</P></BLOCKQUOTE>- <H2>Keyboard Controls</H2>+ <H2><A NAME="Keyboard_Controls">Keyboard Controls</H2><BLOCKQUOTE><P>The following key mappings are used by the Listing:</P>@@ -198,6 +198,39 @@<TD width="79%">Move the cursor to the right one position. If at the end of a line,move the cursor to first position of the next line.</TD></TR>++ <TR>+ <A NAME="Keyboard_Controls_Shift">+ <TD width="21%" valign="top"><Shift></TD>++ <TD width="79%">Press shift when using the mouse scroll wheel to perform+ horizontal scrolling. This will only work when the horizontal scroll+ bar is visible.++ <BLOCKQUOTE>++ <P>+ <IMG border="0" src="../../shared/note.png" alt="">+ <SPAN style="font-size: 0.8em;">+ You can disable horizontal scrolling in the Listing (and all other+ Field Panels) via the Tool Options at+ <B>Edit+ <IMG alt="" border="0" src="../../shared/arrow.gif">+ Tool Options...+ <IMG alt="" border="0" src="../../shared/arrow.gif">+ Listing Fields+ <IMG alt="" border="0" src="../../shared/arrow.gif">+ Mouse+ <IMG alt="" border="0" src="../../shared/arrow.gif">+ Horizontal Scrolling+ </B>+ </SPAN>+ </P>+ </BLOCKQUOTE>++ </TD>++ </TR></TBODY></TABLE></CENTER>diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/codebrowser/CodeBrowserPlugin.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/codebrowser/CodeBrowserPlugin.javaindex 084d6ec6e4..395014e116 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/codebrowser/CodeBrowserPlugin.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/codebrowser/CodeBrowserPlugin.java@@ -101,6 +101,7 @@ public class CodeBrowserPlugin extends Pluginprivate static final String CURSOR_COLOR = "Cursor.Cursor Color - Focused";private static final String UNFOCUSED_CURSOR_COLOR = "Cursor.Cursor Color - Unfocused";private static final String BLINK_CURSOR = "Cursor.Blink Cursor";+ private static final String MOUSE_WHEEL_HORIZONTAL_SCROLLING = "Mouse.Horizontal Scrolling";// - Icon -private ImageIcon CURSOR_LOC_ICON =@@ -621,16 +622,19 @@ public class CodeBrowserPlugin extends Pluginpublic void optionsChanged(ToolOptions options, String optionName, Object oldValue,Object newValue) {+ ListingPanel listingPanel = connectedProvider.getListingPanel();if (options.getName().equals(GhidraOptions.CATEGORY_BROWSER_DISPLAY)) {if (optionName.equals(OptionsGui.BACKGROUND.getColorOptionName())) {Color c = (Color) newValue;- connectedProvider.getListingPanel().setTextBackgroundColor(c);+ listingPanel.setTextBackgroundColor(c);}}else if (options.getName().equals(GhidraOptions.CATEGORY_BROWSER_FIELDS)) {++ FieldPanel fieldPanel = listingPanel.getFieldPanel();if (optionName.equals(GhidraOptions.OPTION_SELECTION_COLOR)) {Color color = ((Color) newValue);- connectedProvider.getListingPanel().getFieldPanel().setSelectionColor(color);+ fieldPanel.setSelectionColor(color);MarkerSet selectionMarkers = getSelectionMarkers(currentProgram);if (selectionMarkers != null) {selectionMarkers.setMarkerColor(color);@@ -642,7 +646,7 @@ public class CodeBrowserPlugin extends Plugin}else if (optionName.equals(GhidraOptions.OPTION_HIGHLIGHT_COLOR)) {Color color = ((Color) newValue);- connectedProvider.getListingPanel().getFieldPanel().setHighlightColor(color);+ fieldPanel.setHighlightColor(color);MarkerSet highlightMarkers = getHighlightMarkers(currentProgram);if (highlightMarkers != null) {highlightMarkers.setMarkerColor(color);@@ -650,15 +654,15 @@ public class CodeBrowserPlugin extends Plugin}else if (optionName.equals(CURSOR_COLOR)) {Color color = ((Color) newValue);- connectedProvider.getListingPanel().getFieldPanel().setFocusedCursorColor(color);+ fieldPanel.setFocusedCursorColor(color);}else if (optionName.equals(UNFOCUSED_CURSOR_COLOR)) {Color color = ((Color) newValue);- connectedProvider.getListingPanel().getFieldPanel().setNonFocusCursorColor(color);+ fieldPanel.setNonFocusCursorColor(color);}else if (optionName.equals(BLINK_CURSOR)) {Boolean isBlinkCursor = ((Boolean) newValue);- connectedProvider.getListingPanel().getFieldPanel().setBlinkCursor(isBlinkCursor);+ fieldPanel.setBlinkCursor(isBlinkCursor);}else if (optionName.equals(GhidraOptions.HIGHLIGHT_CURSOR_LINE_COLOR)) {cursorHighlightColor = (Color) newValue;@@ -672,6 +676,10 @@ public class CodeBrowserPlugin extends PlugincurrentCursorMarkers.setColoringBackground(isHighlightCursorLine);}}+ else if (optionName.equals(MOUSE_WHEEL_HORIZONTAL_SCROLLING)) {+ fieldPanel.setHorizontalScrollingEnabled((Boolean) newValue);+ }+connectedProvider.fieldOptionChanged(optionName, newValue);}@@ -833,6 +841,11 @@ public class CodeBrowserPlugin extends PluginfieldOptions.registerOption(GhidraOptions.HIGHLIGHT_CURSOR_LINE, true, helpLocation,"Toggles highlighting background color of line containing the cursor");+ helpLocation = new HelpLocation(getName(), "Keyboard_Controls_Shift");+ fieldOptions.registerOption(MOUSE_WHEEL_HORIZONTAL_SCROLLING, true, helpLocation,+ "Enables horizontal scrolling by holding the Shift key while " ++ "using the mouse scroll wheel");+Color color = fieldOptions.getColor(GhidraOptions.OPTION_SELECTION_COLOR,GhidraOptions.DEFAULT_SELECTION_COLOR);@@ -860,6 +873,10 @@ public class CodeBrowserPlugin extends PluginBoolean isBlinkCursor = fieldOptions.getBoolean(BLINK_CURSOR, true);fieldPanel.setBlinkCursor(isBlinkCursor);+ boolean horizontalScrollingEnabled =+ fieldOptions.getBoolean(MOUSE_WHEEL_HORIZONTAL_SCROLLING, true);+ fieldPanel.setHorizontalScrollingEnabled(horizontalScrollingEnabled);+cursorHighlightColor =fieldOptions.getColor(GhidraOptions.HIGHLIGHT_CURSOR_LINE_COLOR, CURSOR_LINE_COLOR);@@ -919,8 +936,8 @@ public class CodeBrowserPlugin extends PlugintableFromSelectionAction.setMenuBarData(new MenuData(new String[] { ToolConstants.MENU_SELECTION, "Create Table From Selection" }, null,"SelectUtils"));- tableFromSelectionAction- .setHelpLocation(new HelpLocation("CodeBrowserPlugin", "Selection_Table"));+ tableFromSelectionAction.setHelpLocation(+ new HelpLocation("CodeBrowserPlugin", "Selection_Table"));// don't add the actions initially if the service isn't thereTableService tableService = tool.getService(TableService.class);@@ -1001,8 +1018,8 @@ public class CodeBrowserPlugin extends Pluginpublic boolean goToField(Address a, String fieldName, int occurrence, int row, int col,boolean scroll) {- boolean result = SystemUtilities- .runSwingNow(() -> doGoToField(a, fieldName, occurrence, row, col, scroll));+ boolean result = SystemUtilities.runSwingNow(+ () -> doGoToField(a, fieldName, occurrence, row, col, scroll));return result;}diff --git a/Ghidra/Framework/Docking/src/main/java/docking/widgets/fieldpanel/FieldPanel.java b/Ghidra/Framework/Docking/src/main/java/docking/widgets/fieldpanel/FieldPanel.javaindex 00d4d5ddf3..38885a27db 100644--- a/Ghidra/Framework/Docking/src/main/java/docking/widgets/fieldpanel/FieldPanel.java+++ b/Ghidra/Framework/Docking/src/main/java/docking/widgets/fieldpanel/FieldPanel.java@@ -15,7 +15,7 @@*/package docking.widgets.fieldpanel;-import static docking.widgets.EventTrigger.INTERNAL_ONLY;+import static docking.widgets.EventTrigger.*;import java.awt.*;import java.awt.event.*;@@ -58,6 +58,7 @@ public class FieldPanel extends JPanelprivate KeyHandler keyHandler = new KeyHandler();private HoverHandler hoverHandler;private SelectionHandler selectionHandler = new SelectionHandler();+ private boolean horizontalScrollingEnabled = true;private FieldLocation cursorPosition = new FieldLocation();private FieldSelection selection = new FieldSelection();@@ -335,6 +336,14 @@ public class FieldPanel extends JPanelcursorHandler.setBlinkCursor(blinkCursor);}+ public void enableSelection(boolean b) {+ selectionHandler.enableSelection(b);+ }++ public void setHorizontalScrollingEnabled(boolean enabled) {+ horizontalScrollingEnabled = enabled;+ }+/*** Returns the default background color.*/@@ -1171,15 +1180,11 @@ public class FieldPanel extends JPanelprivate JViewport getViewport() {Container c = getParent();- if (c == null) {- return null;- }- if (c instanceof JViewport) {- return (JViewport) c;- }- c = c.getParent();- if (c instanceof JViewport) {- return (JViewport) c;+ while (c != null) {+ if (c instanceof JViewport) {+ return (JViewport) c;+ }+ c = c.getParent();}return null;}@@ -1429,13 +1434,8 @@ public class FieldPanel extends JPanelelse {hoverHandler.stopHover();- if (e.isShiftDown()) {- // horizontal scroll (only move viewport)- if (viewport != null) {- Point pos = viewport.getViewPosition();- viewport.setViewPosition(- new Point(Math.max(0, pos.x + scrollAmount), pos.y));- }+ if (e.isShiftDown() && horizontalScrollingEnabled) {+ scrollViewHorizontally(scrollAmount);}else {scrollView(scrollAmount);@@ -1443,6 +1443,19 @@ public class FieldPanel extends JPanel}e.consume();}++ private void scrollViewHorizontally(int scrollAmount) {++ JViewport vp = getViewport();+ if (vp == null) {+ // this will happen for Field Panels not placed inside of scroll panes+ return;+ }++ // horizontal scroll (only move viewport)+ Point pos = vp.getViewPosition();+ vp.setViewPosition(new Point(Math.max(0, pos.x + scrollAmount), pos.y));+ }}public class MouseHandler implements ActionListener {@@ -2061,8 +2074,4 @@ public class FieldPanel extends JPanel}}}-- public void enableSelection(boolean b) {- selectionHandler.enableSelection(b);- }}