From 31d6a09990eadc115f5de4226b54752ab79b48d1 Mon Sep 17 00:00:00 2001 From: Vadim Lopatin Date: Fri, 8 Sep 2017 10:07:03 +0300 Subject: [PATCH] implement #423 - sort order indicators in file dialog --- src/dlangui/dialogs/filedlg.d | 20 +++++-- src/dlangui/graphics/fonts.d | 61 ++++++++++++++++++++++ src/dlangui/graphics/ftfonts.d | 61 +++------------------- src/dlangui/platforms/windows/win32fonts.d | 12 +++++ 4 files changed, 98 insertions(+), 56 deletions(-) diff --git a/src/dlangui/dialogs/filedlg.d b/src/dlangui/dialogs/filedlg.d index f2896c13..92814b86 100644 --- a/src/dlangui/dialogs/filedlg.d +++ b/src/dlangui/dialogs/filedlg.d @@ -279,6 +279,7 @@ class FileDialog : Dialog, CustomGridCellAdapter { if (currentRow >= 0 && currentRow < _entries.length) { selectedItemPath = _entries[currentRow].name; } + updateColumnHeaders(); sortEntries(); entriesToCells(selectedItemPath); requestLayout(); @@ -769,9 +770,7 @@ class FileDialog : Dialog, CustomGridCellAdapter { _fileList.fullRowOnTop(false); _fileList.resize(4, 3); _fileList.setColTitle(0, " "d); - _fileList.setColTitle(1, UIString.fromId("COL_NAME"c).value); - _fileList.setColTitle(2, UIString.fromId("COL_SIZE"c).value); - _fileList.setColTitle(3, UIString.fromId("COL_MODIFIED"c).value); + updateColumnHeaders(); _fileList.showRowHeaders = false; _fileList.rowSelect = true; _fileList.multiSelect = _allowMultipleFiles; @@ -817,6 +816,21 @@ class FileDialog : Dialog, CustomGridCellAdapter { } + /// get sort order suffix for column title + protected dstring appendSortOrderSuffix(dstring columnName, FileListSortOrder arrowUp, FileListSortOrder arrowDown) { + if (_sortOrder == arrowUp) + return columnName ~ " ▲"; + if (_sortOrder == arrowDown) + return columnName ~ " ▼"; + return columnName; + } + + protected void updateColumnHeaders() { + _fileList.setColTitle(1, appendSortOrderSuffix(UIString.fromId("COL_NAME"c).value, FileListSortOrder.NAME_DESC, FileListSortOrder.NAME)); + _fileList.setColTitle(2, appendSortOrderSuffix(UIString.fromId("COL_SIZE"c).value, FileListSortOrder.SIZE_DESC, FileListSortOrder.SIZE)); + _fileList.setColTitle(3, appendSortOrderSuffix(UIString.fromId("COL_MODIFIED"c).value, FileListSortOrder.TIMESTAMP_DESC, FileListSortOrder.TIMESTAMP)); + } + protected void onHeaderCellClicked(GridWidgetBase source, int col, int row) { debug Log.d("onHeaderCellClicked col=", col, " row=", row); if (row == 0 && col >= 2 && col <= 4) { diff --git a/src/dlangui/graphics/fonts.d b/src/dlangui/graphics/fonts.d index 41bc4398..1176a334 100644 --- a/src/dlangui/graphics/fonts.d +++ b/src/dlangui/graphics/fonts.d @@ -926,5 +926,66 @@ private: double _gamma = 1.0; } +/// find some suitable replacement for important characters missing in font +dchar getReplacementChar(dchar code) { + switch (code) { + case UNICODE_SOFT_HYPHEN_CODE: + return '-'; + case 0x0401: // CYRILLIC CAPITAL LETTER IO + return 0x0415; //CYRILLIC CAPITAL LETTER IE + case 0x0451: // CYRILLIC SMALL LETTER IO + return 0x0435; // CYRILLIC SMALL LETTER IE + case UNICODE_NO_BREAK_SPACE: + return ' '; + case 0x2010: + case 0x2011: + case 0x2012: + case 0x2013: + case 0x2014: + case 0x2015: + return '-'; + case 0x2018: + case 0x2019: + case 0x201a: + case 0x201b: + return '\''; + case 0x201c: + case 0x201d: + case 0x201e: + case 0x201f: + case 0x00ab: + case 0x00bb: + return '\"'; + case 0x2039: + return '<'; + case 0x203A: + case '‣': + case '►': + return '>'; + case 0x2044: + return '/'; + case 0x2022: // css_lst_disc: + return '*'; + case 0x26AA: // css_lst_disc: + case 0x25E6: // css_lst_disc: + case 0x25CF: // css_lst_disc: + return 'o'; + case 0x25CB: // css_lst_circle: + return '*'; + case 0x25A0: // css_lst_square: + return '-'; + case '↑': // + return '▲'; + case '↓': // + return '▼'; + case '▲': // + return '^'; + case '▼': // + return 'v'; + default: + return 0; + } +} + __gshared glyph_gamma_table!65 _gamma65; __gshared glyph_gamma_table!256 _gamma256; diff --git a/src/dlangui/graphics/ftfonts.d b/src/dlangui/graphics/ftfonts.d index 0849d2bb..3baa395a 100644 --- a/src/dlangui/graphics/ftfonts.d +++ b/src/dlangui/graphics/ftfonts.d @@ -195,58 +195,6 @@ class FreeTypeFontFile { return true; // successfully opened } - /// find some suitable replacement for important characters missing in font - static dchar getReplacementChar(dchar code) { - switch (code) { - case UNICODE_SOFT_HYPHEN_CODE: - return '-'; - case 0x0401: // CYRILLIC CAPITAL LETTER IO - return 0x0415; //CYRILLIC CAPITAL LETTER IE - case 0x0451: // CYRILLIC SMALL LETTER IO - return 0x0435; // CYRILLIC SMALL LETTER IE - case UNICODE_NO_BREAK_SPACE: - return ' '; - case 0x2010: - case 0x2011: - case 0x2012: - case 0x2013: - case 0x2014: - case 0x2015: - return '-'; - case 0x2018: - case 0x2019: - case 0x201a: - case 0x201b: - return '\''; - case 0x201c: - case 0x201d: - case 0x201e: - case 0x201f: - case 0x00ab: - case 0x00bb: - return '\"'; - case 0x2039: - return '<'; - case 0x203A: - case '‣': - case '►': - return '>'; - case 0x2044: - return '/'; - case 0x2022: // css_lst_disc: - return '*'; - case 0x26AA: // css_lst_disc: - case 0x25E6: // css_lst_disc: - case 0x25CF: // css_lst_disc: - return 'o'; - case 0x25CB: // css_lst_circle: - return '*'; - case 0x25A0: // css_lst_square: - return '-'; - default: - return 0; - } - } /// find glyph index for character FT_UInt getCharIndex(dchar code, dchar def_char = 0) { @@ -255,8 +203,15 @@ class FreeTypeFontFile { FT_UInt ch_glyph_index = FT_Get_Char_Index(_face, code); if (ch_glyph_index == 0) { dchar replacement = getReplacementChar(code); - if (replacement) + if (replacement) { ch_glyph_index = FT_Get_Char_Index(_face, replacement); + if (ch_glyph_index == 0) { + dchar replacement = getReplacementChar(replacement); + if (replacement) { + ch_glyph_index = FT_Get_Char_Index(_face, replacement); + } + } + } if (ch_glyph_index == 0 && def_char) ch_glyph_index = FT_Get_Char_Index( _face, def_char ); } diff --git a/src/dlangui/platforms/windows/win32fonts.d b/src/dlangui/platforms/windows/win32fonts.d index 2d660c3d..b4d545b2 100644 --- a/src/dlangui/platforms/windows/win32fonts.d +++ b/src/dlangui/platforms/windows/win32fonts.d @@ -270,6 +270,18 @@ class Win32Font : Font { if (found !is null) return found; uint glyphIndex = getGlyphIndex(ch); + if (!glyphIndex) { + ch = getReplacementChar(ch); + if (!ch) + return null; + glyphIndex = getGlyphIndex(ch); + if (!glyphIndex) { + ch = getReplacementChar(ch); + if (!ch) + return null; + glyphIndex = getGlyphIndex(ch); + } + } if (!glyphIndex) return null; if (glyphIndex >= 0xFFFF)