comparison dwtestoo.cpp @ 2916:fe43f8667d3d

C++: Implement Notification class, and enable dwtestoo code that relied on it.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Wed, 28 Dec 2022 03:28:31 +0000
parents 0cde119fc945
children 77e5d6743013
comparison
equal deleted inserted replaced
2915:0cde119fc945 2916:fe43f8667d3d
132 else if((mask & KC_ALT)) 132 else if((mask & KC_ALT))
133 return "KC_ALT"; 133 return "KC_ALT";
134 else return "none"; 134 else return "none";
135 } 135 }
136 136
137 char *ReadFile(char *filename)
138 {
139 char *errors = NULL;
140 #ifdef __ANDROID__
141 int fd = -1;
142
143 /* Special way to open for URIs on Android */
144 if(strstr(filename, "://"))
145 {
146 fd = dw_file_open(filename, O_RDONLY);
147 fp = fdopen(fd, "r");
148 }
149 else
150 #endif
151 fp = fopen(filename, "r");
152 if(!fp)
153 errors = strerror(errno);
154 else
155 {
156 int i,len;
157
158 lp = (char **)calloc(1000,sizeof(char *));
159 /* should test for out of memory */
160 max_linewidth=0;
161 for(i=0; i<1000; i++)
162 {
163 lp[i] = (char *)calloc(1, 1025);
164 if (fgets(lp[i], 1024, fp) == NULL)
165 break;
166 len = (int)strlen(lp[i]);
167 if (len > max_linewidth)
168 max_linewidth = len;
169 if(lp[i][len - 1] == '\n')
170 lp[i][len - 1] = '\0';
171 }
172 num_lines = i;
173 fclose(fp);
174 #if 0
175 hscrollbar->SetRange(max_linewidth, cols);
176 hscrollbar->SetPos(0);
177 vscrollbar->SetRange(num_lines, rows);
178 vscrollbar->SetPos(0);
179 #endif
180 }
181 #ifdef __ANDROID__
182 if(fd != -1)
183 close(fd);
184 #endif
185 return errors;
186 }
187
188 void RenderDraw() {
189 // Draw page 2
190 }
191
137 // Add the menus to the window 192 // Add the menus to the window
138 void CreateMenus() { 193 void CreateMenus() {
139 // Setup the menu 194 // Setup the menu
140 DW::MenuBar *menubar = this->MenuBarNew(); 195 DW::MenuBar *menubar = this->MenuBarNew();
141 196
283 browsefilebutton->ConnectClicked([this, entryfield, copypastefield]() -> int 338 browsefilebutton->ConnectClicked([this, entryfield, copypastefield]() -> int
284 { 339 {
285 char *tmp = this->app->FileBrowse("Pick a file", "dwtest.c", "c", DW_FILE_OPEN); 340 char *tmp = this->app->FileBrowse("Pick a file", "dwtest.c", "c", DW_FILE_OPEN);
286 if(tmp) 341 if(tmp)
287 { 342 {
288 #if 0 343 char *errors = ReadFile(tmp);
289 char *errors = read_file(tmp); 344 const char *title = "New file load";
290 char *title = "New file load"; 345 const char *image = "image/test.png";
291 char *image = "image/test.png";
292 DW::Notification *notification; 346 DW::Notification *notification;
293 347
294 if(errors) 348 if(errors)
295 notification = new DW::Notification(title, image, "dwtest failed to load \"%s\" into the file browser, %s.", tmp, errors); 349 notification = new DW::Notification(title, image, APP_TITLE " failed to load the file into the file browser.");
296 else 350 else
297 notification = new DW::Notification(title, image, "dwtest loaded \"%s\" into the file browser on the Render tab, with \"File Display\" selected from the drop down list.", tmp); 351 notification = new DW::Notification(title, image, APP_TITLE " loaded the file into the file browser on the Render tab, with \"File Display\" selected from the drop down list.");
298 #endif
299 352
300 if(current_file) 353 if(current_file)
301 this->app->Free(current_file); 354 this->app->Free(current_file);
302 current_file = tmp; 355 current_file = tmp;
303 entryfield->SetText(current_file); 356 entryfield->SetText(current_file);
304 current_col = current_row = 0; 357 current_col = current_row = 0;
305 358
306 #if 0 359 RenderDraw();
307 render_draw();
308 notification->ConnectClicked([this]() -> int { 360 notification->ConnectClicked([this]() -> int {
361 this->app->Debug("Notification clicked\n");
309 return TRUE; 362 return TRUE;
310 }); 363 });
311 notification->Send(); 364 notification->Send();
312 #endif
313 } 365 }
314 copypastefield->SetFocus(); 366 copypastefield->SetFocus();
315 return FALSE; 367 return FALSE;
316 }); 368 });
317 369