From ab077d82dd4686536107520fa94470998087074b Mon Sep 17 00:00:00 2001 From: Chris Young Date: Mon, 25 Aug 2008 13:32:26 +0000 Subject: Moved Amiga menu code into separate file. svn path=/trunk/netsurf/; revision=5199 --- amiga/gui.c | 178 +++++++++++++++++++++++++++++++++++++---------------------- amiga/menu.c | 91 ++++++++++++++++++++++++++++++ amiga/menu.h | 29 ++++++++++ amiga/utf8.c | 14 +++++ amiga/utf8.h | 1 + 5 files changed, 247 insertions(+), 66 deletions(-) create mode 100755 amiga/menu.c create mode 100755 amiga/menu.h (limited to 'amiga') diff --git a/amiga/gui.c b/amiga/gui.c index 2694bc5c9..641c4a05d 100755 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -48,6 +48,10 @@ #include "utils/utf8.h" #include "amiga/utf8.h" #include "amiga/hotlist.h" +#include "amiga/menu.h" +#include "amiga/options.h" +#include +#include "desktop/textinput.h" #ifdef WITH_HUBBUB #include @@ -77,7 +81,6 @@ struct browser_window *curbw; char *default_stylesheet_url; char *adblock_stylesheet_url; struct gui_window *search_current_window = NULL; - struct MinList *window_list; struct MsgPort *msgport; @@ -150,7 +153,9 @@ void gui_init(int argc, char** argv) /* need to do some proper checking that components are opening */ - verbose_log = 0; + options_read("Resources/Options"); + + verbose_log = option_verbose_log; nsscreentitle = ASPrintf("NetSurf %s",netsurf_version); @@ -195,8 +200,6 @@ void gui_init(int argc, char** argv) default_stylesheet_url = "file://NetSurf/Resources/default.css"; //"http://www.unsatisfactorysoftware.co.uk/newlook.css"; //path_to_url(buf); adblock_stylesheet_url = "file://NetSurf/Resources/adblock.css"; - options_read("Resources/Options"); - #ifdef WITH_HUBBUB if(hubbub_initialise("Resources/Aliases",myrealloc,NULL) != HUBBUB_OK) { @@ -207,8 +210,16 @@ void gui_init(int argc, char** argv) if((!option_cookie_file) || (option_cookie_file[0] == '\0')) option_cookie_file = strdup("Resources/Cookies"); + if((!option_hotlist_file) || (option_hotlist_file[0] == '\0')) + option_hotlist_file = strdup("Resources/Hotlist"); + + if((!option_url_file) || (option_url_file[0] == '\0')) + option_url_file = strdup("Resources/URLs"); + +/* if((!option_cookie_jar) || (option_cookie_jar[0] == '\0')) option_cookie_jar = strdup("Resources/CookieJar"); +*/ if((!option_ca_bundle) || (option_ca_bundle[0] == '\0')) option_ca_bundle = strdup("devs:curl-ca-bundle.crt"); @@ -225,7 +236,7 @@ void gui_init(int argc, char** argv) if((!option_font_cursive) || (option_font_cursive[0] == '\0')) option_font_cursive = strdup("DejaVu Sans.font"); - if((!option_font_fantasy) || (option_font_cursive[0] == '\0')) + if((!option_font_fantasy) || (option_font_fantasy[0] == '\0')) option_font_fantasy = strdup("DejaVu Serif.font"); if(!option_window_width) option_window_width = 800; @@ -235,12 +246,14 @@ void gui_init(int argc, char** argv) plot=amiplot; + ami_init_menulabs(); + schedule_list = NewObjList(); window_list = NewObjList(); - urldb_load("Resources/URLs"); + urldb_load(option_url_file); urldb_load_cookies(option_cookie_file); - hotlist = options_load_tree("Resources/Hotlist"); + hotlist = options_load_tree(option_hotlist_file); if(!hotlist) ami_hotlist_init(&hotlist); } @@ -261,13 +274,27 @@ void gui_init2(int argc, char** argv) /* need some bestmodeid() in here, or grab modeid from options file */ - id = p96BestModeIDTags(P96BIDTAG_NominalWidth,option_window_screen_width, + if(option_modeid) + { + id = option_modeid; + } + else + { + id = p96BestModeIDTags(P96BIDTAG_NominalWidth,option_window_screen_width, P96BIDTAG_NominalHeight,option_window_screen_height, P96BIDTAG_Depth,32); - if(id == INVALID_ID) die(messages_get("NoMode")); + if(id == INVALID_ID) die(messages_get("NoMode")); + } - scrn = OpenScreenTags(NULL, + if(option_use_wb) + { + scrn = LockPubScreen("Workbench"); + UnlockPubScreen(NULL,scrn); + } + else + { + scrn = OpenScreenTags(NULL, SA_Width,option_window_screen_width, SA_Height,option_window_screen_height, SA_Depth,32, @@ -275,6 +302,7 @@ void gui_init2(int argc, char** argv) SA_Title,nsscreentitle, SA_LikeWorkbench,TRUE, TAG_DONE); + } bw = browser_window_create(option_homepage_url, 0, 0, true,false); // curbw = temp } @@ -464,6 +492,14 @@ void ami_get_msg(void) case 1: // paste gui_paste_from_clipboard(gwin,0,0); break; + + case 2: // select all + browser_window_key_press(gwin->bw, 1); + break; + + case 3: // clear selection + browser_window_key_press(gwin->bw, 26); + break; } break; @@ -482,7 +518,24 @@ void ami_get_msg(void) } break; + case 3: // settings + switch(itemnum) + { + case 0: // snapshot + option_window_x = gwin->win->LeftEdge; + option_window_y = gwin->win->TopEdge; + option_window_width = gwin->win->Width; + option_window_height = gwin->win->Height; + break; + + case 1: // save settings + options_write("Resources/Options"); + break; + } + break; + } + if(win_destroyed) break; code = item->NextSelect; } break; @@ -495,6 +548,28 @@ void ami_get_msg(void) browser_window_key_press(gwin->bw,storage); break; + case WMHI_RAWKEY: + storage = result & WMHI_GADGETMASK; + switch(storage) + { + case RAWKEY_CRSRUP: + browser_window_key_press(gwin->bw,KEY_UP); + break; + case RAWKEY_CRSRDOWN: + browser_window_key_press(gwin->bw,KEY_DOWN); + break; + case RAWKEY_CRSRLEFT: + browser_window_key_press(gwin->bw,KEY_LEFT); + break; + case RAWKEY_CRSRRIGHT: + browser_window_key_press(gwin->bw,KEY_RIGHT); + break; + case RAWKEY_ESC: + browser_window_key_press(gwin->bw,27); + break; + } + break; + case WMHI_NEWSIZE: GetAttr(SPACE_AreaBox,gwin->gadgets[GID_BROWSER],(ULONG *)&bbox); browser_window_reformat(gwin->bw,bbox->Width,bbox->Height); @@ -561,18 +636,20 @@ void gui_poll(bool active) void gui_quit(void) { -// urldb_save("resources/URLs"); + urldb_save(option_url_file); urldb_save_cookies(option_cookie_file); - options_save_tree(hotlist,"Resources/Hotlist","NetSurf hotlist"); + options_save_tree(hotlist,option_hotlist_file,messages_get("TreeHotlist")); #ifdef WITH_HUBBUB hubbub_finalise(myrealloc,NULL); #endif - CloseScreen(scrn); + if(!option_use_wb) CloseScreen(scrn); p96FreeBitMap(dummyrp.BitMap); FreeVec(nsscreentitle); + ami_free_menulabs(); + if(iffh->iff_Stream) CloseClipboard((struct ClipboardHandle *)iffh->iff_Stream); if(iffh) FreeIFF(iffh); @@ -618,55 +695,24 @@ void ami_update_buttons(struct gui_window *gwin) RefreshSetGadgetAttrs(gwin->gadgets[GID_FORWARD],gwin->win,NULL, GA_Disabled,forward, TAG_DONE); - - -} - -struct NewMenu *ami_create_menu(ULONG type) -{ - ULONG menuflags = 0; - if(type != BROWSER_WINDOW_NORMAL) - { - menuflags = NM_ITEMDISABLED; - } - - STATIC struct NewMenu menu[] = { - {NM_TITLE,0,0,0,0,0,}, // project - { NM_ITEM,0,"N",0,0,0,}, // new window - { NM_ITEM,NM_BARLABEL,0,0,0,0,}, - { NM_ITEM,0,"K",0,0,0,}, // close window - {NM_TITLE,0,0,0,0,0,}, // edit - { NM_ITEM,0,"C",0,0,0,}, // copy - { NM_ITEM,0,"V",0,0,0,}, // paste - {NM_TITLE,0,0,0,0,0,}, // hotlist - { NM_ITEM,0,0,0,0,0,}, // add to hotlist - { NM_ITEM,0,"H",0,0,0,}, // show hotlist - { NM_END,0,0,0,0,0,}, - }; - - menu[0].nm_Label = messages_get("Project"); - menu[1].nm_Label = messages_get("NewWindow"); - menu[1].nm_Flags = menuflags; - menu[3].nm_Label = messages_get("Close"); - menu[3].nm_Flags = menuflags; - menu[4].nm_Label = messages_get("Edit"); - menu[5].nm_Label = messages_get("Copy"); - menu[6].nm_Label = messages_get("Paste"); - menu[7].nm_Label = messages_get("Hotlist"); - menu[8].nm_Label = messages_get("HotlistAdd"); - menu[9].nm_Label = messages_get("HotlistShow"); - - return(menu); } struct gui_window *gui_create_browser_window(struct browser_window *bw, struct browser_window *clone, bool new_tab) { // tabs are ignored for the moment - + struct NewMenu *menu; struct gui_window *gwin = NULL; bool closegadg=TRUE; - struct NewMenu *menu = ami_create_menu(bw->browser_window_type); + +/* + if(bw->browser_window_type == BROWSER_WINDOW_IFRAME) + { + gwin = bw->parent->window; + printf("%lx\n",gwin); + return gwin; + } +*/ gwin = AllocVec(sizeof(struct gui_window),MEMF_CLEAR); @@ -679,26 +725,27 @@ struct gui_window *gui_create_browser_window(struct browser_window *bw, return 0; } + menu = ami_create_menu(bw->browser_window_type); + switch(bw->browser_window_type) { + case BROWSER_WINDOW_IFRAME: case BROWSER_WINDOW_FRAMESET: case BROWSER_WINDOW_FRAME: - case BROWSER_WINDOW_IFRAME: - gwin->objects[OID_MAIN] = WindowObject, WA_ScreenTitle,nsscreentitle, WA_Title, messages_get("NetSurf"), - WA_Activate, TRUE, + WA_Activate, FALSE, WA_DepthGadget, TRUE, WA_DragBar, TRUE, WA_CloseGadget, FALSE, - WA_Width,200, - WA_Height,200, + WA_Width,200, + WA_Height,200, WA_SizeGadget, TRUE, WA_CustomScreen,scrn, WA_ReportMouse,TRUE, WA_IDCMP,IDCMP_MENUPICK | IDCMP_MOUSEMOVE | IDCMP_MOUSEBUTTONS | - IDCMP_NEWSIZE | IDCMP_VANILLAKEY | IDCMP_GADGETUP | IDCMP_IDCMPUPDATE, + IDCMP_NEWSIZE | IDCMP_VANILLAKEY | IDCMP_RAWKEY | IDCMP_GADGETUP | IDCMP_IDCMPUPDATE, // WINDOW_IconifyGadget, TRUE, WINDOW_NewMenu,menu, WINDOW_HorizProp,1, @@ -731,14 +778,14 @@ struct gui_window *gui_create_browser_window(struct browser_window *bw, WA_DragBar, TRUE, WA_CloseGadget, TRUE, WA_SizeGadget, TRUE, - WA_Top,option_window_x, - WA_Left,option_window_y, + WA_Top,option_window_y, + WA_Left,option_window_x, WA_Width,option_window_width, WA_Height,option_window_height, WA_CustomScreen,scrn, WA_ReportMouse,TRUE, WA_IDCMP,IDCMP_MENUPICK | IDCMP_MOUSEMOVE | IDCMP_MOUSEBUTTONS | - IDCMP_NEWSIZE | IDCMP_VANILLAKEY | IDCMP_GADGETUP | IDCMP_IDCMPUPDATE, + IDCMP_NEWSIZE | IDCMP_VANILLAKEY | IDCMP_RAWKEY | IDCMP_GADGETUP | IDCMP_IDCMPUPDATE, // WINDOW_IconifyGadget, TRUE, WINDOW_NewMenu,menu, WINDOW_HorizProp,1, @@ -904,8 +951,7 @@ void gui_window_destroy(struct gui_window *g) if(IsMinListEmpty(window_list)) { /* last window closed, so exit */ - gui_quit(); - exit(0); + netsurf_quit = true; } win_destroyed = true; @@ -1470,7 +1516,7 @@ void gui_create_form_select_menu(struct browser_window *bw, while(opt) { - IDoMethod(gwin->objects[OID_MENU],PM_INSERT,NewObject( POPUPMENU_GetItemClass(), NULL, PMIA_Title, (ULONG)opt->text,PMIA_ID,i,PMIA_CheckIt,TRUE,PMIA_Checked,opt->selected,TAG_DONE),~0); + IDoMethod(gwin->objects[OID_MENU],PM_INSERT,NewObject( POPUPMENU_GetItemClass(), NULL, PMIA_Title, (ULONG)ami_utf8_easy(opt->text),PMIA_ID,i,PMIA_CheckIt,TRUE,PMIA_Checked,opt->selected,TAG_DONE),~0); opt = opt->next; i++; diff --git a/amiga/menu.c b/amiga/menu.c new file mode 100755 index 000000000..172316e6d --- /dev/null +++ b/amiga/menu.c @@ -0,0 +1,91 @@ +/* + * Copyright 2008 Chris Young + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "desktop/browser.h" +#include "amiga/menu.h" +#include "utils/messages.h" +#include "amiga/utf8.h" +#include + +void ami_free_menulabs(void) +{ + int i; + + for(i=0;i<=AMI_MENU_MAX;i++) + { + if(menulab[i] != NM_BARLABEL) ami_utf8_free(menulab[i]); + } +} + +void ami_init_menulabs(void) +{ + menulab[0] = ami_utf8_easy((char *)messages_get("Project")); + menulab[1] = ami_utf8_easy((char *)messages_get("NewWindow")); + menulab[2] = NM_BARLABEL; + menulab[3] = ami_utf8_easy((char *)messages_get("CloseWindow")); + menulab[4] = ami_utf8_easy((char *)messages_get("Edit")); + menulab[5] = ami_utf8_easy((char *)messages_get("Copy")); + menulab[6] = ami_utf8_easy((char *)messages_get("Paste")); + menulab[7] = ami_utf8_easy((char *)messages_get("SelectAll")); + menulab[8] = ami_utf8_easy((char *)messages_get("Clear")); + menulab[9] = ami_utf8_easy((char *)messages_get("Hotlist")); + menulab[10] = ami_utf8_easy((char *)messages_get("HotlistAdd")); + menulab[11] = ami_utf8_easy((char *)messages_get("HotlistShow")); + menulab[12] = ami_utf8_easy((char *)messages_get("Settings")); + menulab[13] = ami_utf8_easy((char *)messages_get("SnapshotWindow")); + menulab[14] = ami_utf8_easy((char *)messages_get("SettingsSave")); +} + +struct NewMenu *ami_create_menu(ULONG type) +{ + int i; + ULONG menuflags = 0; + STATIC struct NewMenu menu[] = { + {NM_TITLE,0,0,0,0,0,}, // project + { NM_ITEM,0,"N",0,0,0,}, // new window + { NM_ITEM,NM_BARLABEL,0,0,0,0,}, + { NM_ITEM,0,"K",0,0,0,}, // close window + {NM_TITLE,0,0,0,0,0,}, // edit + { NM_ITEM,0,"C",0,0,0,}, // copy + { NM_ITEM,0,"V",0,0,0,}, // paste + { NM_ITEM,0,"A",0,0,0,}, // select all + { NM_ITEM,0,"Z",0,0,0,}, // clear selection + {NM_TITLE,0,0,0,0,0,}, // hotlist + { NM_ITEM,0,0,0,0,0,}, // add to hotlist + { NM_ITEM,0,"H",0,0,0,}, // show hotlist + {NM_TITLE,0,0,0,0,0,}, // settings + { NM_ITEM,0,0,0,0,0,}, // snapshot window + { NM_ITEM,0,0,0,0,0,}, // save settings + { NM_END,0,0,0,0,0,}, + }; + + if(type != BROWSER_WINDOW_NORMAL) + { + menuflags = NM_ITEMDISABLED; + } + + for(i=0;i<=AMI_MENU_MAX;i++) + { + menu[i].nm_Label = menulab[i]; + } + + menu[1].nm_Flags = menuflags; + menu[3].nm_Flags = menuflags; + + return(menu); +} diff --git a/amiga/menu.h b/amiga/menu.h new file mode 100755 index 000000000..d53d3bc73 --- /dev/null +++ b/amiga/menu.h @@ -0,0 +1,29 @@ +/* + * Copyright 2008 Chris Young + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef AMIGA_MENU_H +#define AMIGA_MENU_H +#include + +#define AMI_MENU_MAX 14 +char *menulab[AMI_MENU_MAX]; + +struct NewMenu *ami_create_menu(ULONG type); +void ami_init_menulabs(void); +void ami_free_menulabs(void); +#endif diff --git a/amiga/utf8.c b/amiga/utf8.c index 87c95d58a..9ea649216 100755 --- a/amiga/utf8.c +++ b/amiga/utf8.c @@ -75,3 +75,17 @@ void ami_utf8_free(char *ptr) { if(ptr) CodesetsFreeA(ptr,NULL); } + +char *ami_utf8_easy(char *string) +{ + char *localtext; + + if(utf8_to_local_encoding(string,strlen(string),&localtext) == UTF8_CONVERT_OK) + { + return localtext; + } + else + { + return NULL; + } +} diff --git a/amiga/utf8.h b/amiga/utf8.h index 9a11ee1bd..e4074c69f 100755 --- a/amiga/utf8.h +++ b/amiga/utf8.h @@ -21,4 +21,5 @@ //char *ami_utf8_alloc(char *string); ULONG ami_utf8_to_any(const char *string, size_t len, char **result); void ami_utf8_free(char *ptr); +char *ami_utf8_easy(char *string); #endif -- cgit v1.2.3