3 //define homeLocation = "localhost:8080";
4 //define homeLocation = "www.ecere.com";
5 define homeLocation = "google.com";
7 class AddressBar : Window
9 background = activeBorder;
13 this, bevelOver = true, inactive = true, anchor = Anchor { left = 0, top = 0, bottom = 0 }, size = Size { 24 }, hotKey = altLeft, bitmap = { "<:ecere>actions/goPrevious.png" };
16 bool NotifyClicked(Button button, int x, int y, Modifiers mods)
18 ((Explorer)parent).Back();
24 this, bevelOver = true, inactive = true, anchor = Anchor { left = 24, top = 0, bottom = 0 }, size = Size { 24 }, hotKey = altRight, bitmap = { "<:ecere>actions/goNext.png" };
27 bool NotifyClicked(Button button, int x, int y, Modifiers mods)
29 ((Explorer)parent).Forward();
35 this, bevelOver = true, inactive = true, anchor = Anchor { left = 52, top = 0, bottom = 0 }, size = Size { 24 }, hotKey = ctrlH, bitmap = { "<:ecere>actions/goHome.png" };
37 bool NotifyClicked(Button button, int x, int y, Modifiers mods)
39 ((Explorer)parent).Go(homeLocation);
45 this, bevelOver = true, inactive = true, anchor = Anchor { left = 76, top = 0, bottom = 0 }, size = Size { 24 }, hotKey = f5, bitmap = { "<:ecere>actions/viewRefresh.png" };
47 bool NotifyClicked(Button button, int x, int y, Modifiers mods)
49 ((Explorer)parent).Refresh();
53 Label { this, anchor = Anchor { left = (96+12) }, labeledWindow = address };
56 this, text = "Address:", anchor = Anchor { left = (16+48+96), right = 60, top = 0, bottom = 0 }, hotKey = altD;
58 bool NotifyKeyDown(EditBox editBox, Key key, unichar ch)
60 if(!go.disabled && (SmartKey)key == enter)
61 ((Explorer)parent).Go(editBox.contents);
65 void NotifyUpdate(EditBox editBox)
67 String location = ((Explorer)parent).htmlView.location;
68 go.disabled = !strcmp(location ? location : "", editBox.contents);
73 this, bevelOver = true, inactive = true, text = "Go!", anchor = Anchor { top = 0, right = 0, bottom = 0 }, size = Size { 60 }, hotKey = altG;
75 bool NotifyClicked(Button button, int x, int y, Modifiers mods)
77 ((Explorer)parent).Go(address.contents);
82 bool OnKeyHit(Key key, unichar ch)
85 ((Explorer)parent).htmlView.MakeActive();
90 class Explorer : Window
92 FileDialog openFileDialog { caption = "Select a file or enter a URL... " };
93 FileDialog saveFileDialog { type = save, caption = "Save to file... " };
95 icon = { ":newb.png" };
98 background = activeBorder;
101 borderStyle = sizable;
105 text = "Ecere Web Browser";
106 size = Size { 800, 600 };
109 AddressBar addressBar { this, borderStyle = bevel, anchor = Anchor { top = 0, left = 0, right = 0 }, size.h = 26, hotKey = altD };
110 HTMLView htmlView { this, borderStyle = deep, hasVertScroll = true, hasHorzScroll = true, anchor = Anchor { left = 0, right = 0, top = 26, bottom = 0 }, NotifyPageOpened = PageOpened, OnOpen = OnOpen };
114 Menu fileMenu { menu, "File", f };
115 MenuItem newWindowItem
117 fileMenu, "New Window\tCtrl+N", n, ctrlN;
119 bool NotifySelect(MenuItem selection, Modifiers mods)
121 Explorer { state = normal }.Create();
127 fileMenu, "Open...\tCtrl+O", o, ctrlO;
129 bool NotifySelect(MenuItem selection, Modifiers mods)
131 if(openFileDialog.Modal() == ok)
132 Go(openFileDialog.filePath);
136 // MenuItem closeItem { fileMenu, "Close\tCtrl-F4", c, NotifySelect = MenuFileClose };
137 MenuDivider { fileMenu };
140 fileMenu, "Save As...";
142 bool NotifySelect(MenuItem selection, Modifiers mods)
144 char fileName[MAX_LOCATION];
145 GetLastDirectory(htmlView.location, fileName);
146 strcpy(fileName, saveFileDialog.currentDirectory);
147 PathCat(fileName, fileName);
148 saveFileDialog.filePath = fileName;
150 if(saveFileDialog.Modal() == ok)
152 File f = FileOpen(htmlView.location, read);
155 if(!f.CopyTo(saveFileDialog.filePath))
157 String e = PrintString("Error saving to ", saveFileDialog.filePath);
158 MessageBox { contents = e }.Modal();
166 MenuDivider { fileMenu };
167 MenuItem exitItem { fileMenu, "Exit\tAlt+F4", x, NotifySelect = MenuFileExit };
171 char caption[MAX_LOCATION];
173 strcpy(caption, "Ecere Web Browser - ");
174 strcat(caption, htmlView.title);
177 addressBar.address.Clear();
178 addressBar.address.PutS(htmlView.fileName);
184 addressBar.MakeActive();
188 Array<String> history { };
196 bool HTMLView::OnOpen(char * href)
199 char newLocation[MAX_LOCATION];
200 Explorer explorer = (Explorer)parent;
202 strcpy(newLocation, location ? location : "");
203 if(newLocation[strlen(newLocation)-1] != '/')
204 PathCat(newLocation, "..");
205 if(href[0] == '/' && href[1] == '/')
207 strcpy(newLocation, "http:");
208 strcat(newLocation, href);
211 PathCat(newLocation, href);
213 if(explorer.history.count > explorer.historyPos+1)
216 for(i = explorer.historyPos+1; i < explorer.history.count; i++)
217 delete explorer.history[i];
218 explorer.history.count = explorer.historyPos+1;
220 explorer.historyPos = explorer.history.count-1;
221 explorer.addressBar.back.disabled = (explorer.historyPos == 0);
222 explorer.addressBar.forward.disabled = (explorer.historyPos >= explorer.history.count-1);
224 Open(newLocation, null);
226 explorer.history.Add(CopyString(location));
227 explorer.historyPos = explorer.history.count-1;
229 explorer.addressBar.back.disabled = (explorer.historyPos == 0);
230 explorer.addressBar.forward.disabled = (explorer.historyPos >= explorer.history.count-1);
234 void Go(const String location)
236 if(history.count > historyPos+1)
239 for(i = historyPos+1; i < history.count; i++)
241 history.count = historyPos+1;
243 history.Add(CopyString(location));
244 historyPos = history.count-1;
245 addressBar.back.disabled = (historyPos == 0);
246 addressBar.forward.disabled = (historyPos >= history.count-1);
247 htmlView.MakeActive();
248 htmlView.location = location;
253 htmlView.MakeActive();
255 htmlView.location = history[historyPos];
260 if(historyPos < history.count-1)
263 addressBar.back.disabled = (historyPos == 0);
264 addressBar.forward.disabled = (historyPos >= history.count-1);
265 htmlView.location = history[historyPos];
276 addressBar.back.disabled = (historyPos == 0);
277 addressBar.forward.disabled = (historyPos >= history.count-1);
278 htmlView.location = history[historyPos];
284 bool OnKeyHit(Key key, unichar ch)
297 class BrowserApp : GuiApplication
300 Explorer explorerWindow {};
308 explorerWindow.Go(argv[1]);
311 explorerWindow.Go(homeLocation);
320 extern GuiApplication app;