From 000d884d3658a9fa01fc3a23b38029362d406da0 Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Wed, 22 Aug 2007 21:16:19 +0000 Subject: [PATCH] partial work on the converting tab git-svn-id: svn://ttmath.org/publicrep/ttcalc/trunk@52 e52654a7-88a9-db11-a3e9-0013d4bc506e --- src/languages.cpp | 146 +++++++++++++++++++++++++++++++++++++++ src/languages.h | 33 ++++++++- src/programresources.cpp | 15 ++++ src/programresources.h | 17 ++++- src/resource.rc | 2 +- src/tabs.cpp | 49 ++++++++++++- src/tabs.h | 2 + 7 files changed, 259 insertions(+), 5 deletions(-) diff --git a/src/languages.cpp b/src/languages.cpp index 89c5c49..4d90755 100644 --- a/src/languages.cpp +++ b/src/languages.cpp @@ -432,3 +432,149 @@ void Languages::InitGuiMessagesTab() InsertGuiPair(cant_open_project_page, "Nie mogę otworzyć strony projektu"); } + + +void Languages::ConvertingAddType(const char * name) +{ + if( converting_type.empty() ) + return; + + ConvType temp; + temp.name = name; + + converting_type.back().push_back(temp); +} + + +void Languages::ConvertingAddUnit(const char * name) +{ + if( converting_type.empty() || converting_unit.empty() ) + return; + + ConvUnit temp; + temp.name = name; + temp.type = static_cast(converting_type.size()-1); + + converting_unit.back().push_back(temp); +} + + +void Languages::InitConverting() +{ + + + + // en + converting_type.push_back( std::vector() ); + converting_unit.push_back( std::vector() ); + + ConvertingAddType("none"); + + ConvertingAddType("length"); + ConvertingAddUnit("metre"); + ConvertingAddUnit("mile"); + + ConvertingAddType("area"); + ConvertingAddUnit("are"); + ConvertingAddUnit("square metre"); + + + // pl + converting_type.push_back( std::vector() ); + converting_unit.push_back( std::vector() ); + + ConvertingAddType("brak"); + + ConvertingAddType("długość"); + ConvertingAddUnit("metr"); + ConvertingAddUnit("mila"); + + ConvertingAddType("obszar"); + ConvertingAddUnit("ar"); + ConvertingAddUnit("metr kwadratowy"); +} + + +const char * Languages::ConvertingType(Country country, unsigned int id) +{ +const char * unk_err = "unknown"; + + if( converting_type.empty() ) + InitConverting(); + + unsigned int cid = static_cast( country ); + if( cid >= converting_type.size() ) + return unk_err; + + if( id >= converting_type[cid].size() ) + return unk_err; + +return converting_type[cid][id].name.c_str(); +} + + +const char * Languages::ConvertingUnit(Country country, unsigned int id) +{ +const char * unk_err = "unknown"; + + if( converting_unit.empty() ) + InitConverting(); + + unsigned int cid = static_cast( country ); + if( cid >= converting_unit.size() ) + return unk_err; + + if( id >= converting_unit[cid].size() ) + return unk_err; + +return converting_unit[cid][id].name.c_str(); +} + + +const char * Languages::ConvertingType(unsigned int id) +{ + return ConvertingType(current_country, id); + +} + +const char * Languages::ConvertingUnit(unsigned int id) +{ + return ConvertingUnit(current_country, id); +} + + +unsigned int Languages::ConvertingTypeSize(Country country) +{ + if( converting_type.empty() ) + InitConverting(); + + unsigned int cid = static_cast( country ); + if( cid >= converting_type.size() ) + return 0; + +return static_cast(converting_type[cid].size()); +} + + +unsigned int Languages::ConvertingUnitSize(Country country) +{ + if( converting_unit.empty() ) + InitConverting(); + + unsigned int cid = static_cast( country ); + if( cid >= converting_unit.size() ) + return 0; + +return static_cast(converting_unit[cid].size()); +} + + +unsigned int Languages::ConvertingTypeSize() +{ + return ConvertingTypeSize(current_country); +} + +unsigned int Languages::ConvertingUnitSize() +{ + return ConvertingUnitSize(current_country); +} diff --git a/src/languages.h b/src/languages.h index e861591..7b6ac02 100644 --- a/src/languages.h +++ b/src/languages.h @@ -146,6 +146,20 @@ public: en = 0, pl }; + struct ConvType + { + std::string name; + // int id; + }; + + struct ConvUnit + { + std::string name; + // int id; + unsigned int type; + }; + + private: Country current_country; @@ -159,10 +173,16 @@ private: void InsertGuiPair(GuiMsg code, const char * message); void InitGuiMessagesTab(); + std::vector > converting_type; + std::vector > converting_unit; + + void ConvertingAddType(const char * name); + void ConvertingAddUnit(const char * name); + + void InitConverting(); + public: - - Languages() { current_country = en; @@ -183,6 +203,15 @@ public: const char * GuiMessage(Country country, GuiMsg code); const char * GuiMessage(GuiMsg code); + const char * ConvertingType(Country country, unsigned int id); + const char * ConvertingUnit(Country country, unsigned int id); + unsigned int ConvertingTypeSize(Country country); + unsigned int ConvertingUnitSize(Country country); + const char * ConvertingType(unsigned int id); + const char * ConvertingUnit(unsigned int id); + unsigned int ConvertingTypeSize(); + unsigned int ConvertingUnitSize(); + }; diff --git a/src/programresources.cpp b/src/programresources.cpp index a85c850..8afea46 100644 --- a/src/programresources.cpp +++ b/src/programresources.cpp @@ -390,6 +390,8 @@ ProgramResources::ProgramResources() y_size_normal = 0; y_size_compact = 0; x_size_min = 0; + + conv_type = 0; } @@ -574,6 +576,9 @@ void ProgramResources::CheckCoordinates() } + + + IniParser::Error ProgramResources::ReadFromFile() { IniParser iparser; @@ -706,4 +711,14 @@ int ProgramResources::GetBadLine() } +void ProgramResources::SetConvType(int c) +{ + conv_type = c; +} + + +int ProgramResources::GetConvType() +{ + return conv_type; +} diff --git a/src/programresources.h b/src/programresources.h index f89af32..0e20cf1 100644 --- a/src/programresources.h +++ b/src/programresources.h @@ -268,12 +268,25 @@ public: /*! - it returns a number of line where there was an error + it returns a number of a line where there was an error during last parsing */ int GetBadLine(); + + + /*! + these methods set and return the kind of conversion which should be performed + + 0 - none + 1 - ... + 2 - ... + */ + void SetConvType(int c); + int GetConvType(); + + private: bool IsWhiteCharacter(int c); @@ -318,6 +331,8 @@ private: int display_rounding; int bad_line; + + int conv_type; }; diff --git a/src/resource.rc b/src/resource.rc index 61f1970..aedf69f 100644 --- a/src/resource.rc +++ b/src/resource.rc @@ -200,7 +200,7 @@ BEGIN LTEXT "Conversion type",IDC_STATIC_UNIT_CONVERSION,3,2,63,8 LTEXT "Input",IDC_STATIC_UNIT_INPUT,80,2,73,8 LTEXT "Output",IDC_STATIC_UNIT_OUTPUT,167,2,80,8 - CONTROL "List1",IDC_LIST_UNIT_TYPE,"SysListView32",LVS_REPORT | + CONTROL "List1",IDC_LIST_UNIT_TYPE,"SysListView32",LVS_SHOWSELALWAYS | LVS_SINGLESEL | LVS_REPORT | LVS_NOCOLUMNHEADER | WS_BORDER | WS_TABSTOP,3,12,67,56 CONTROL "List2",IDC_LIST_UNIT_INPUT1,"SysListView32",LVS_REPORT | LVS_NOCOLUMNHEADER | WS_BORDER | WS_TABSTOP,80,12,26,56 diff --git a/src/tabs.cpp b/src/tabs.cpp index eb6d874..fe28a85 100644 --- a/src/tabs.cpp +++ b/src/tabs.cpp @@ -446,6 +446,21 @@ int i; } +/*! + +-1 if there's no such item +*/ +int FindItem(HWND list, int i) +{ +LVFINDINFO info; + + info.flags = LVFI_PARAM; + info.lParam = i; + +return ListView_FindItem(list, -1, &info); +} + + void SetLanguageTabConvert(HWND hWnd) { Languages * plang = GetPrgRes()->GetLanguages(); @@ -454,10 +469,34 @@ Languages * plang = GetPrgRes()->GetLanguages(); SetDlgItemText(hWnd, IDC_STATIC_UNIT_INPUT, plang->GuiMessage(Languages::convert_input) ); SetDlgItemText(hWnd, IDC_STATIC_UNIT_OUTPUT, plang->GuiMessage(Languages::convert_output) ); SetDlgItemText(hWnd, IDC_COMBO_DYNAMIC_OUTPUT, plang->GuiMessage(Languages::convert_dynamic_output) ); + + HWND list1 = GetDlgItem(hWnd, IDC_LIST_UNIT_TYPE); + + ListView_DeleteAllItems(list1); + + LVITEM item; + item.mask = LVIF_PARAM | LVIF_TEXT; + item.iSubItem = 0; + + unsigned int conv_type_size = plang->ConvertingTypeSize(); + + for(unsigned int i = 0 ; i(plang->ConvertingType(i)); + + ListView_InsertItem(list1, &item); + } + + int type = FindItem(list1, GetPrgRes()->GetConvType() ); + if( type != -1 ) + ListView_SetItemState(list1, type, LVIS_FOCUSED|LVIS_SELECTED, LVIS_FOCUSED|LVIS_SELECTED); } + void SetLanguage(HWND hTab) { TCITEM tab; @@ -1014,13 +1053,21 @@ char buffer[20]; return true; } + + BOOL WmInitTabConvert(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { +HWND list1 = GetDlgItem(hWnd, IDC_LIST_UNIT_TYPE); + ListView_SetExtendedListViewStyle(list1, LVS_EX_FULLROWSELECT); + LVCOLUMN col; + col.mask = LVCF_FMT | LVCF_WIDTH; + col.fmt = LVCFMT_LEFT; + col.cx = 90; - + ListView_InsertColumn(list1, 0, &col); return true; diff --git a/src/tabs.h b/src/tabs.h index c77e7ec..76f4d61 100644 --- a/src/tabs.h +++ b/src/tabs.h @@ -99,4 +99,6 @@ extern ttmath::ErrorCode last_code; } +using TabWindowFunctions::Variables::GetSelectedItem; + #endif