|
1 | 1 | /*
|
2 |
| - * Copyright 2020 DiffPlug |
| 2 | + * Copyright (C) 2020-2021 DiffPlug |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
16 | 16 | package com.diffplug.common.swt;
|
17 | 17 |
|
18 | 18 |
|
| 19 | +import com.diffplug.common.swt.os.OS; |
19 | 20 | import java.util.ArrayList;
|
20 | 21 | import java.util.Collections;
|
21 | 22 | import java.util.List;
|
@@ -109,12 +110,43 @@ protected static Table buildTable(Composite parent, int style, boolean linesVisi
|
109 | 110 | // create the columns and layout
|
110 | 111 | Function<ColumnBuilder, TableColumn> buildFunc = builder -> builder.build(control);
|
111 | 112 | List<TableColumn> columns = columnBuilders.stream().map(buildFunc).collect(Collectors.toList());
|
112 |
| - buildLayout(control, new TableColumnLayout(), columns, columnBuilders); |
| 113 | + |
| 114 | + boolean needsSpecialLayout = SwtMisc.flagIsSet(SWT.CHECK, style) && OS.getNative().isMac(); |
| 115 | + TableColumnLayout layout = needsSpecialLayout ? new MacCheckTableColumnLayout() : new TableColumnLayout(); |
| 116 | + buildLayout(control, layout, columns, columnBuilders); |
113 | 117 |
|
114 | 118 | // return the control
|
115 | 119 | return control;
|
116 | 120 | }
|
117 | 121 |
|
| 122 | + /** Adds a phantom column for the checkboxes so that the rest of the space is calculated correctly. */ |
| 123 | + private static class MacCheckTableColumnLayout extends TableColumnLayout { |
| 124 | + private static final int CHECK_COLUMN_WIDTH = 15; |
| 125 | + |
| 126 | + @Override |
| 127 | + protected int getColumnCount(Scrollable tableTree) { |
| 128 | + return super.getColumnCount(tableTree) + 1; |
| 129 | + } |
| 130 | + |
| 131 | + @Override |
| 132 | + protected void setColumnWidths(Scrollable tableTree, int[] widths) { |
| 133 | + TableColumn[] columns = ((Table) tableTree).getColumns(); |
| 134 | + for (int i = 0; i < columns.length; i++) { |
| 135 | + columns[i].setWidth(widths[i]); |
| 136 | + } |
| 137 | + } |
| 138 | + |
| 139 | + @Override |
| 140 | + protected ColumnLayoutData getLayoutData(Scrollable tableTree, int columnIndex) { |
| 141 | + Table table = (Table) tableTree; |
| 142 | + if (columnIndex < table.getColumnCount()) { |
| 143 | + return (ColumnLayoutData) table.getColumn(columnIndex).getData(LAYOUT_DATA); |
| 144 | + } else { |
| 145 | + return new ColumnPixelData(CHECK_COLUMN_WIDTH); |
| 146 | + } |
| 147 | + } |
| 148 | + } |
| 149 | + |
118 | 150 | /** Builds a table with the given columns. */
|
119 | 151 | protected static Tree buildTree(Composite parent, int style, boolean linesVisible, boolean headerVisible, List<? extends ColumnBuilder> columnBuilders) {
|
120 | 152 | SwtMisc.assertClean(parent);
|
|
0 commit comments