Mercurial > dwindows
comparison dwtestoo.cpp @ 2964:2d9521396112
C++: Step 6 of the std::string transition.
Fix build issues on OS/2, warnings and makefile dependencies.
Also while fixing these issues I discovered more needed changes.
Switch to using the std::string version of FileBrowse().
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sun, 26 Feb 2023 17:48:08 +0000 |
parents | 531d36ebf37a |
children | ac880987a2c4 |
comparison
equal
deleted
inserted
replaced
2963:531d36ebf37a | 2964:2d9521396112 |
---|---|
210 else if((mask & KC_ALT)) | 210 else if((mask & KC_ALT)) |
211 return "KC_ALT"; | 211 return "KC_ALT"; |
212 else return "none"; | 212 else return "none"; |
213 } | 213 } |
214 | 214 |
215 char *ReadFile(char *filename) { | 215 char *ReadFile(std::string filename) { |
216 char *errors = NULL; | 216 char *errors = NULL; |
217 FILE *fp=NULL; | 217 FILE *fp=NULL; |
218 #ifdef __ANDROID__ | 218 #ifdef __ANDROID__ |
219 int fd = -1; | 219 int fd = -1; |
220 | 220 |
221 // Special way to open for URIs on Android | 221 // Special way to open for URIs on Android |
222 if(strstr(filename, "://")) | 222 if(strstr(filename.c_str(), "://")) |
223 { | 223 { |
224 fd = dw_file_open(filename, O_RDONLY); | 224 fd = dw_file_open(filename.c_str(), O_RDONLY); |
225 fp = fdopen(fd, "r"); | 225 fp = fdopen(fd, "r"); |
226 } | 226 } |
227 else | 227 else |
228 #endif | 228 #endif |
229 fp = fopen(filename, "r"); | 229 fp = fopen(filename.c_str(), "r"); |
230 if(!fp) | 230 if(!fp) |
231 errors = strerror(errno); | 231 errors = strerror(errno); |
232 else | 232 else |
233 { | 233 { |
234 int i,len; | 234 int i,len; |
267 DW::Pixmap *pixmap = hpm ? hpm : pixmap2; | 267 DW::Pixmap *pixmap = hpm ? hpm : pixmap2; |
268 char buf[16] = {0}; | 268 char buf[16] = {0}; |
269 int i,y,fileline; | 269 int i,y,fileline; |
270 char *pLine; | 270 char *pLine; |
271 | 271 |
272 if(current_file) | 272 if(current_file.size()) |
273 { | 273 { |
274 pixmap->SetForegroundColor(DW_CLR_WHITE); | 274 pixmap->SetForegroundColor(DW_CLR_WHITE); |
275 if(!hpm) | 275 if(!hpm) |
276 pixmap1->DrawRect(DW_DRAW_FILL | DW_DRAW_NOAA, 0, 0, (int)pixmap1->GetWidth(), (int)pixmap1->GetHeight()); | 276 pixmap1->DrawRect(DW_DRAW_FILL | DW_DRAW_NOAA, 0, 0, (int)pixmap1->GetWidth(), (int)pixmap1->GetHeight()); |
277 pixmap->DrawRect(DW_DRAW_FILL | DW_DRAW_NOAA, 0, 0, (int)pixmap->GetWidth(), (int)pixmap->GetHeight()); | 277 pixmap->DrawRect(DW_DRAW_FILL | DW_DRAW_NOAA, 0, 0, (int)pixmap->GetWidth(), (int)pixmap->GetHeight()); |
715 #endif | 715 #endif |
716 | 716 |
717 // Connect signals | 717 // Connect signals |
718 browsefilebutton->ConnectClicked([this, entryfield, copypastefield]() -> int | 718 browsefilebutton->ConnectClicked([this, entryfield, copypastefield]() -> int |
719 { | 719 { |
720 char *tmp = this->app->FileBrowse("Pick a file", "dwtest.c", "c", DW_FILE_OPEN); | 720 std::string tmp = this->app->FileBrowse("Pick a file", "dwtest.c", "c", DW_FILE_OPEN); |
721 if(tmp) | 721 if(tmp.size()) |
722 { | 722 { |
723 char *errors = ReadFile(tmp); | 723 char *errors = ReadFile(tmp); |
724 std::string title = "New file load"; | 724 std::string title = "New file load"; |
725 std::string image = "image/test.png"; | 725 std::string image = "image/test.png"; |
726 DW::Notification *notification; | 726 DW::Notification *notification; |
728 if(errors) | 728 if(errors) |
729 notification = new DW::Notification(title, image, std::string(APP_TITLE) + " failed to load the file into the file browser."); | 729 notification = new DW::Notification(title, image, std::string(APP_TITLE) + " failed to load the file into the file browser."); |
730 else | 730 else |
731 notification = new DW::Notification(title, image, std::string(APP_TITLE) + " loaded the file into the file browser on the Render tab, with \"File Display\" selected from the drop down list."); | 731 notification = new DW::Notification(title, image, std::string(APP_TITLE) + " loaded the file into the file browser on the Render tab, with \"File Display\" selected from the drop down list."); |
732 | 732 |
733 if(current_file) | |
734 this->app->Free(current_file); | |
735 current_file = tmp; | 733 current_file = tmp; |
736 entryfield->SetText(current_file); | 734 entryfield->SetText(current_file); |
737 current_col = current_row = 0; | 735 current_col = current_row = 0; |
738 | 736 |
739 RenderDraw(); | 737 RenderDraw(); |
747 return FALSE; | 745 return FALSE; |
748 }); | 746 }); |
749 | 747 |
750 browsefolderbutton->ConnectClicked([this]() -> int | 748 browsefolderbutton->ConnectClicked([this]() -> int |
751 { | 749 { |
752 char *tmp = this->app->FileBrowse("Pick a folder", ".", "c", DW_DIRECTORY_OPEN); | 750 std::string tmp = this->app->FileBrowse("Pick a folder", ".", "c", DW_DIRECTORY_OPEN); |
753 this->app->Debug("Folder picked: %s\n", tmp ? tmp : "None"); | 751 this->app->Debug("Folder picked: " + (tmp.size() ? tmp : "None") + "\n"); |
754 return FALSE; | 752 return FALSE; |
755 }); | 753 }); |
756 | 754 |
757 copybutton->ConnectClicked([this, copypastefield, entryfield]() -> int { | 755 copybutton->ConnectClicked([this, copypastefield, entryfield]() -> int { |
758 std::string test = copypastefield->GetText(); | 756 std::string test = copypastefield->GetText(); |
1090 { | 1088 { |
1091 // Get the font size for this printer context... | 1089 // Get the font size for this printer context... |
1092 int fheight, fwidth; | 1090 int fheight, fwidth; |
1093 | 1091 |
1094 // If we have a file to display... | 1092 // If we have a file to display... |
1095 if(current_file) | 1093 if(current_file.size()) |
1096 { | 1094 { |
1097 int nrows; | 1095 int nrows; |
1098 | 1096 |
1099 // Calculate new dimensions | 1097 // Calculate new dimensions |
1100 pixmap->GetTextExtents("(g", NULL, &fheight); | 1098 pixmap->GetTextExtents("(g", NULL, &fheight); |
1361 buf = "\r\nDW_SIGNAL_ITEM_SELECT: Item: " + sitem + " Text: " + text + " Itemdata: " + sitemdata + "\r\n"; | 1359 buf = "\r\nDW_SIGNAL_ITEM_SELECT: Item: " + sitem + " Text: " + text + " Itemdata: " + sitemdata + "\r\n"; |
1362 this->mle_point = container_mle->Import(buf, mle_point); | 1360 this->mle_point = container_mle->Import(buf, mle_point); |
1363 std::string str = container->QueryStart(DW_CRA_SELECTED); | 1361 std::string str = container->QueryStart(DW_CRA_SELECTED); |
1364 while(str.size()) | 1362 while(str.size()) |
1365 { | 1363 { |
1366 std::string buf = "Selected: " + str + "%s\r\n"; | 1364 std::string buf = "Selected: " + str + "\r\n"; |
1367 mle_point = container_mle->Import(buf, mle_point); | 1365 mle_point = container_mle->Import(buf, mle_point); |
1368 str = container->QueryNext(DW_CRA_SELECTED); | 1366 str = container->QueryNext(DW_CRA_SELECTED); |
1369 } | 1367 } |
1370 // Make the last inserted point the cursor location | 1368 // Make the last inserted point the cursor location |
1371 container_mle->SetCursor(mle_point); | 1369 container_mle->SetCursor(mle_point); |
1915 int num_lines=0, max_linewidth=0; | 1913 int num_lines=0, max_linewidth=0; |
1916 int current_row=0,current_col=0; | 1914 int current_row=0,current_col=0; |
1917 unsigned int render_type = SHAPES_DOUBLE_BUFFERED; | 1915 unsigned int render_type = SHAPES_DOUBLE_BUFFERED; |
1918 | 1916 |
1919 char **lp; | 1917 char **lp; |
1920 char *current_file = NULL; | 1918 std::string current_file; |
1921 | 1919 |
1922 // Page 4 | 1920 // Page 4 |
1923 int mle_point=-1; | 1921 int mle_point=-1; |
1924 | 1922 |
1925 // Page 8 | 1923 // Page 8 |