From 8315a9a0a2b070801b74a3235386191e33fefc60 Mon Sep 17 00:00:00 2001 From: Mohammed Alyousef Date: Sat, 24 May 2025 21:41:47 +0300 Subject: [PATCH] add theming to menu bar and scrollbars --- .gitignore | 2 +- src/csvapplication.cpp | 16 +++++++++++++--- src/csvapplication.hh | 14 ++------------ src/csvdatastorage.cpp | 4 ++++ src/csvdatastorage.hh | 12 ++++-------- src/csvgrid.cpp | 16 +++++++++++++--- src/csvgrid.hh | 10 +++++----- src/csvmenu.cpp | 8 +++++--- src/csvmenu.hh | 4 ---- src/csvparser.cpp | 6 ++++++ src/csvparser.hh | 22 +++++++--------------- src/csvtable.cpp | 11 +++++++++++ src/csvtable.hh | 15 ++------------- src/csvwidgets.cpp | 7 ++++--- src/csvwidgets.hh | 6 ++---- src/csvwindow.cpp | 21 +++++++++++++++++++-- src/csvwindow.hh | 26 ++++++-------------------- src/globals.hh | 19 +++++-------------- src/helper.cpp | 3 +++ src/helper.hh | 14 +++----------- src/macro.hh | 8 +++----- src/main.cpp | 6 ++---- src/recentfiles.hh | 4 ++-- src/simplefifo.hh | 1 - 24 files changed, 122 insertions(+), 133 deletions(-) diff --git a/.gitignore b/.gitignore index 48b007c..bfcfd0f 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,4 @@ docs/doxygen/ CMakeSettings.json scripts/*.exe scripts/appimagetool-x86_64.AppImage - +bin/ diff --git a/src/csvapplication.cpp b/src/csvapplication.cpp index adb49bf..e809c22 100644 --- a/src/csvapplication.cpp +++ b/src/csvapplication.cpp @@ -20,12 +20,21 @@ */ +#include "colorthemes.hh" #include "csvapplication.hh" #include "csvmenu.hh" - +#include "csvparser.hh" +#include "csvwindow.hh" +#include "helper.hh" #include "icons/abouticon.xpm" +#include "macro.hh" - +#include +#include +#include +#include +#include +#include /************************************************************************************ * @@ -363,6 +372,7 @@ int CsvApplication::createNewWindow() { remainOpenWin->hide(); #endif // setMenuBar(windows[newWindowIndex].win); + windows[newWindowIndex].applyTheme(); windows[newWindowIndex].win->show(); return newWindowIndex; } @@ -872,7 +882,7 @@ std::pair CsvApplication::guessDefinition(std::istream *in float confidence; CsvParser *parser = new CsvParser(); CsvDataStorage localStorage; - + // Define definitions for probing std::vector< std::tuple > definitions; definitions.push_back( std::tuple(CsvDefinition(),0,0) ); diff --git a/src/csvapplication.hh b/src/csvapplication.hh index 86751ef..f44e5f5 100644 --- a/src/csvapplication.hh +++ b/src/csvapplication.hh @@ -25,27 +25,21 @@ #include "globals.hh" -#include "colorthemes.hh" #include "csvdatastorage.hh" -#include "csvwindow.hh" #include "csvtable.hh" #include "csvgrid.hh" +#include "csvwidgets.hh" #include "csvmenu.hh" -#include "macro.hh" + #include #include -#include #include #include #include #include -#include -#include #include -#include -#include #ifdef _WIN64 #include @@ -68,8 +62,6 @@ #include #include - -#include "utf8.h" #include "recentfiles.hh" @@ -100,8 +92,6 @@ namespace ui_icons { #undef None #endif #endif -#include "httplib.h" - #ifndef MY_VERSION #define MY_VERSION 0.0.0.0 diff --git a/src/csvdatastorage.cpp b/src/csvdatastorage.cpp index 745692c..4c79ae5 100644 --- a/src/csvdatastorage.cpp +++ b/src/csvdatastorage.cpp @@ -22,6 +22,10 @@ #include "csvdatastorage.hh" +#include +#include // needed for dump() +#include // needed for dump() +#include /* diff --git a/src/csvdatastorage.hh b/src/csvdatastorage.hh index 3944301..856cb9c 100644 --- a/src/csvdatastorage.hh +++ b/src/csvdatastorage.hh @@ -22,18 +22,14 @@ #ifndef _CSVDATASTORAGE_HH #define _CSVDATASTORAGE_HH +#include "globals.hh" + #include // called by sort() to update UI -#include -#include #include -#include -#include // needed for dump() -#include // needed for dump() -#include +#include + -#include "globals.hh" -#include "utf8-cpp-utils/utf8_cpp_utils.hh" /** diff --git a/src/csvgrid.cpp b/src/csvgrid.cpp index b773a92..fd397ee 100644 --- a/src/csvgrid.cpp +++ b/src/csvgrid.cpp @@ -26,17 +26,20 @@ * ************************************************************************************/ -#include "csvwindow.hh" -#include "csvtable.hh" +#include "colorthemes.hh" +#include "csvapplication.hh" #include "csvgrid.hh" +#include "csvtable.hh" +#include "csvwindow.hh" +#include "helper.hh" +#include extern CsvWindow windows[]; extern CsvApplication app; - CsvGrid::CsvGrid(int X,int Y,int W,int H,const char* L) : Fl_Table(X,Y,W,H,L) { DEBUG_PRINTF("#### CsvGrid::CsvGrid: %d, %d, %d, %d\n", X, Y, W, H); text_font_size = TCRUNCHER_INITIAL_FONT_SIZE; @@ -57,6 +60,13 @@ CsvGrid::CsvGrid(int X,int Y,int W,int H,const char* L) : Fl_Table(X,Y,W,H,L) { redraw(); } +Fl_Scrollbar *CsvGrid::vscrollbar() { + return Fl_Table::vscrollbar; +} + +Fl_Scrollbar *CsvGrid::hscrollbar() { + return Fl_Table::hscrollbar; +} CsvGrid::~CsvGrid() { DEBUG_PRINTF("#### CsvGrid::~CsvGrid\n"); diff --git a/src/csvgrid.hh b/src/csvgrid.hh index 07737a0..2f83efe 100644 --- a/src/csvgrid.hh +++ b/src/csvgrid.hh @@ -23,8 +23,10 @@ #ifndef _CSVGRID_HH #define _CSVGRID_HH +#include "globals.hh" +#include "csvtable.hh" -#include +#include #include #include @@ -32,10 +34,6 @@ #include #include -#include "globals.hh" -#include "csvwindow.hh" -#include "csvtable.hh" - /** @@ -67,6 +65,8 @@ public: void selectAll(); // deletes the content of the selected cells int handle(int); int innerWidth(); // return the inner width of the table grid + Fl_Scrollbar *vscrollbar(); + Fl_Scrollbar *hscrollbar(); protected: diff --git a/src/csvmenu.cpp b/src/csvmenu.cpp index f7e3fcf..2c84623 100644 --- a/src/csvmenu.cpp +++ b/src/csvmenu.cpp @@ -23,6 +23,9 @@ #include "csvmenu.hh" #include "csvapplication.hh" +#include +#include + extern Fl_Preferences preferences; extern CsvApplication app; @@ -44,9 +47,8 @@ void CsvMenu::init() { int flags = 0; std::string prefTheme = app.getPreference(&preferences, TCRUNCHER_PREF_THEME, "BRIGHT"); std::string prefFont = app.getPreference(&preferences, TCRUNCHER_PREF_GRID_TEXT_FONT, TCRUNCHER_FALLBACK_FONT); - + Fl::menu_linespacing(12); // undoLabelText = TCRUNCHER_MENUTEXT_UNDO; - box(FL_NO_BOX); down_box(FL_NO_BOX); add("&File/&New", FL_COMMAND + 'n', MyMenuCallback, 0, FL_MENU_DIVIDER); @@ -129,7 +131,7 @@ void CsvMenu::init() { #endif #ifndef __APPLE__ - down_box(FL_NO_BOX); + down_box(FL_FLAT_BOX); #endif } diff --git a/src/csvmenu.hh b/src/csvmenu.hh index 69d13eb..74e3ea7 100644 --- a/src/csvmenu.hh +++ b/src/csvmenu.hh @@ -23,12 +23,8 @@ #ifndef _CSVMENU_HH #define _CSVMENU_HH -#include #include -#include #include -#include - #include diff --git a/src/csvparser.cpp b/src/csvparser.cpp index acc96d2..fad7de8 100644 --- a/src/csvparser.cpp +++ b/src/csvparser.cpp @@ -28,6 +28,12 @@ #include "csvparser.hh" +#include "helper.hh" + +#include +// for reading utf16 +#include +#include #ifndef TCRUNCHER_PARSER_WITHOUT_UPDATE diff --git a/src/csvparser.hh b/src/csvparser.hh index 62198c9..57aaeca 100644 --- a/src/csvparser.hh +++ b/src/csvparser.hh @@ -23,21 +23,6 @@ #ifndef _CSVPARSER_HH #define _CSVPARSER_HH - -#include -#include -#include -#include -#include -#include -#include - -// for reading utf16 -#include -#include - - -#include "helper.hh" #include "globals.hh" #include "csvdatastorage.hh" @@ -46,6 +31,13 @@ #include "csvwindow.hh" #endif +#include +#include +#include +#include +#include +#include + #define CSVPARSER_CONST_ENCLOSED 1 #define CSVPARSER_CONST_NOT_ENCLOSED 0 diff --git a/src/csvtable.cpp b/src/csvtable.cpp index 5b830e8..97e8501 100644 --- a/src/csvtable.cpp +++ b/src/csvtable.cpp @@ -28,8 +28,19 @@ #include "csvtable.hh" +#include "helper.hh" #include "macro.hh" +#include +#include +#include +#include +#include +#include + +// Used for stringstream and std::quoted in replaceUtf8String +#include +#include extern Macro macro; // to use JS for searching diff --git a/src/csvtable.hh b/src/csvtable.hh index a058553..c3f94cf 100644 --- a/src/csvtable.hh +++ b/src/csvtable.hh @@ -23,30 +23,19 @@ #ifndef _CSVTABLE_HH #define _CSVTABLE_HH +#include "globals.hh" +#include "csvdatastorage.hh" #include #include #include -#include #include -#include -#include #include // #include // #include -#include "json/json.hpp" - -#include "helper.hh" -#include "globals.hh" -#include "csvdatastorage.hh" - -// Used for stringstream and std::quoted in replaceUtf8String -#include -#include - /** diff --git a/src/csvwidgets.cpp b/src/csvwidgets.cpp index de186c8..8e7aed9 100644 --- a/src/csvwidgets.cpp +++ b/src/csvwidgets.cpp @@ -23,6 +23,7 @@ #include "csvwidgets.hh" #include "csvwindow.hh" #include "csvapplication.hh" +#include "colorthemes.hh" extern CsvApplication app; @@ -58,7 +59,7 @@ My_Toolbar::My_Toolbar(int X,int Y,int W,int H) : Fl_Pack(X,Y,W,H) { @param shortName If given, it is used as the button text (if no image is present) @return Newly created button. */ -Fl_Button *My_Toolbar::AddButton(const char *name, Fl_RGB_Image *img, Fl_Callback *cb, void *data, int width, std::string shortName, int fontSize) { +Fl_Button *My_Toolbar::AddButton(const char *name, Fl_RGB_Image *img, Fl_Callback *cb, void *data, int width, const char *shortName, int fontSize) { begin(); if( !width ) { width = 40; @@ -74,8 +75,8 @@ Fl_Button *My_Toolbar::AddButton(const char *name, Fl_RGB_Image *img, Fl_Callbac b->labelcolor(ColorThemes::getColor(app.getTheme(), "toolbar_text")); if( fontSize > 0 ) b->labelsize(fontSize); - if( shortName != "" ) { - b->copy_label(shortName.c_str()); + if( strcmp(shortName, "") ) { + b->copy_label(shortName); } else { b->copy_label(name); } diff --git a/src/csvwidgets.hh b/src/csvwidgets.hh index d5346a3..acc8780 100644 --- a/src/csvwidgets.hh +++ b/src/csvwidgets.hh @@ -32,9 +32,7 @@ #include #include #include - - -#include "globals.hh" +#include /** \file csvwidgets.hh * \brief Contains several classes that override FLTK widgets @@ -46,7 +44,7 @@ class My_Toolbar : public Fl_Pack { public: My_Toolbar(int X,int Y,int W,int H); - Fl_Button *AddButton(const char *name, Fl_RGB_Image *img=0, Fl_Callback *cb=0, void *data=0, int width=0, std::string shortName="", int fontSize = 0); + Fl_Button *AddButton(const char *name, Fl_RGB_Image *img=0, Fl_Callback *cb=0, void *data=0, int width=0, const char *shortName="", int fontSize = 0); Fl_Light_Button *AddCheckButton(const char *name, Fl_Callback *cb=0, void *data=0, int width=0); }; diff --git a/src/csvwindow.cpp b/src/csvwindow.cpp index 9781abe..cb61a50 100644 --- a/src/csvwindow.cpp +++ b/src/csvwindow.cpp @@ -20,8 +20,17 @@ */ +#include "colorthemes.hh" +#include "csvapplication.hh" +#include "csvparser.hh" #include "csvwindow.hh" +#include "helper.hh" +#include +#include +#include +#include +#include extern CsvApplication app; @@ -620,10 +629,18 @@ void CsvWindow::applyTheme() { statusbar->color(ColorThemes::getColor(app.getTheme(), "statusbar_bg")); statusbar->labelcolor(ColorThemes::getColor(app.getTheme(), "statusbar_text")); grid->color(ColorThemes::getColor(app.getTheme(), "table_bg")); + grid->vscrollbar()->color(ColorThemes::getColor(app.getTheme(), "header_row_bg")); + grid->vscrollbar()->selection_color(ColorThemes::getColor(app.getTheme(), "win_bg")); + grid->vscrollbar()->labelcolor(ColorThemes::getColor(app.getTheme(), "statusbar_text")); + grid->hscrollbar()->color(ColorThemes::getColor(app.getTheme(), "header_row_bg")); + grid->hscrollbar()->selection_color(ColorThemes::getColor(app.getTheme(), "win_bg")); + grid->hscrollbar()->labelcolor(ColorThemes::getColor(app.getTheme(), "statusbar_text")); win->color(ColorThemes::getColor(app.getTheme(), "win_bg")); #ifndef __APPLE__ winMenuBar->textcolor(ColorThemes::getColor(app.getTheme(), "toolbar_text")); - winMenuBar->color(ColorThemes::getColor(app.getTheme(), "toolbar_bg")); + winMenuBar->color(ColorThemes::getColor(app.getTheme(), "win_bg")); + #else + // winMenuBar->color(ColorThemes::getColor(app.getTheme(), "win_bg")); #endif Fl::redraw(); } @@ -686,7 +703,7 @@ void CsvWindow::readWindowPreferences() { void CsvWindow::setTypeButton(CsvDefinition definition) { std::string str = "NONE"; - str = CsvDefinition::getEncodingName(definition.encoding) + "\n" + CsvDefinition::getDelimiterName(definition.delimiter); + str = std::string(CsvDefinition::getEncodingName(definition.encoding)) + "\n" + CsvDefinition::getDelimiterName(definition.delimiter); typeButton->copy_label(str.c_str()); } diff --git a/src/csvwindow.hh b/src/csvwindow.hh index e072ebf..abab393 100644 --- a/src/csvwindow.hh +++ b/src/csvwindow.hh @@ -23,18 +23,16 @@ #ifndef _CSVWINDOW_HH #define _CSVWINDOW_HH +#include "csvwidgets.hh" +#include "globals.hh" +#include "csvundo.hh" +#include "csvgrid.hh" +#include "csvmenu.hh" +#include "csvtable.hh" #include -#include -#include -#include -#include #include #include -#include -#include -#include // for hash - #include #include @@ -46,18 +44,6 @@ #include #include -#include "json/json.hpp" - -#include "helper.hh" -#include "csvwidgets.hh" -#include "globals.hh" -#include "csvundo.hh" -#include "csvgrid.hh" -#include "csvmenu.hh" -#include "csvtable.hh" -#include "csvapplication.hh" -#include "csvparser.hh" - namespace ui_icons { #ifndef _WIN64 diff --git a/src/globals.hh b/src/globals.hh index 36d47fd..bc9f798 100644 --- a/src/globals.hh +++ b/src/globals.hh @@ -24,15 +24,6 @@ #define _GLOBALS_HH -#include -#include -#include -#include -#include -#include - - - typedef int table_index_t; @@ -161,12 +152,12 @@ public: char quote = '"'; // Quote character char escape = '"'; // Escape character int bomBytes = 0; // length of a ByteOrderMarker (zero if no BOM present) - std::string linebreak = "\n"; // linebreak + const char *linebreak = "\n"; // linebreak bool cancelled = false; // Used by setTypeByUser() to signal a user abortion QuoteStyles quoteStyle = QUOTE_STYLE_RFC; // the quote style used for exports - static std::string getEncodingName(Encodings encoding) { - std::string str = ""; + static const char *getEncodingName(Encodings encoding) { + const char *str = ""; switch( encoding ) { case ENC_UTF8: str = "UTF-8"; @@ -192,8 +183,8 @@ public: } return str; } - static std::string getDelimiterName(char delimiter) { - std::string str = "undef"; + static const char *getDelimiterName(char delimiter) { + const char *str = "undef"; switch(delimiter) { case ',': str = "COMMA"; diff --git a/src/helper.cpp b/src/helper.cpp index dcb8cf6..2910c11 100644 --- a/src/helper.cpp +++ b/src/helper.cpp @@ -29,6 +29,9 @@ #include "helper.hh" +#include +#include +#include /** Calculates the memory usage of tableData diff --git a/src/helper.hh b/src/helper.hh index ba0f1fc..a739e13 100644 --- a/src/helper.hh +++ b/src/helper.hh @@ -24,26 +24,19 @@ #define _HELPER_HH -#include -#include #include #include #include -#include -#include -#include #include -#include #include -#include #include - -#include "utf8.h" +#include +#include #ifdef __APPLE__ #include #include -#include "CoreFoundation/CoreFoundation.h" +#include #endif #ifdef _WIN64 @@ -51,7 +44,6 @@ #endif - class Helper { public: enum parseNumberType {NONE, INT, FLOAT}; diff --git a/src/macro.hh b/src/macro.hh index 4a5761b..39c07dc 100644 --- a/src/macro.hh +++ b/src/macro.hh @@ -23,14 +23,12 @@ #ifndef _MACRO_HH #define _MACRO_HH -#include +#include "csvtable.hh" + #include #include -#include -#include "duktape/duktape.h" - -#include "csvtable.hh" +#include extern void updateMacroLogBuffer(void *logBuffer, std::string str); diff --git a/src/main.cpp b/src/main.cpp index c9ef7ec..c65c523 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -34,15 +34,12 @@ #include "globals.hh" -#include "csvtable.hh" #include "csvapplication.hh" #include "csvwindow.hh" +#include "helper.hh" #include "macro.hh" -#include #include -#include -#include #include @@ -74,6 +71,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR lpCmdLine, #else int main(int argc, char** argv) { #endif + Fl_Window::default_xclass("tablecruncher"); int runState; std::string homeDir; diff --git a/src/recentfiles.hh b/src/recentfiles.hh index 9bbe07a..a773339 100644 --- a/src/recentfiles.hh +++ b/src/recentfiles.hh @@ -23,12 +23,12 @@ #ifndef _RECENTFILES_HH #define _RECENTFILES_HH -#include +#include "globals.hh" + #include #include #include -#include "globals.hh" diff --git a/src/simplefifo.hh b/src/simplefifo.hh index d089ed4..f67aac1 100644 --- a/src/simplefifo.hh +++ b/src/simplefifo.hh @@ -29,7 +29,6 @@ #include - class SimpleFifo { public: