static void gui_init(int argc, char** argv) { const char *addr; nsurl *url; nserror error; char buf[PATH_MAX]; if (pipe(sEventPipe) < 0) return; if (!replicated) { sBAppThreadID = spawn_thread(bapp_thread, "BApplication(NetSurf)", B_NORMAL_PRIORITY, (void *)find_thread(NULL)); if (sBAppThreadID < B_OK) return; /* #### handle errors */ if (resume_thread(sBAppThreadID) < B_OK) return; } nsbeos_update_system_ui_colors(); fetch_rsrc_register(); check_homedir(); // make sure the cache dir exists create_directory(TEMP_FILENAME_PREFIX, 0700); //nsbeos_completion_init(); /* This is an ugly hack to just get the new-style throbber going. * It, along with the PNG throbber loader, need making more generic. */ { #define STROF(n) #n #define FIND_THROB(n) filenames[(n)] = \ "throbber/throbber" STROF(n) ".png"; char *filenames[9]; FIND_THROB(0); FIND_THROB(1); FIND_THROB(2); FIND_THROB(3); FIND_THROB(4); FIND_THROB(5); FIND_THROB(6); FIND_THROB(7); FIND_THROB(8); nsbeos_throbber_initialise_from_png(9, filenames[0], filenames[1], filenames[2], filenames[3], filenames[4], filenames[5], filenames[6], filenames[7], filenames[8]); #undef FIND_THROB #undef STROF } if (nsbeos_throbber == NULL) die("Unable to load throbber image.\n"); find_resource(buf, "Choices", "%/Choices"); LOG(("Using '%s' as Preferences file", buf)); options_file_location = strdup(buf); nsoption_read(buf, NULL); /* check what the font settings are, setting them to a default font * if they're not set - stops Pango whinging */ #define SETFONTDEFAULT(OPTION,y) if (nsoption_charp(OPTION) == NULL) nsoption_set_charp(OPTION, strdup((y))) //XXX: use be_plain_font & friends, when we can check if font is serif or not. /* font_family family; font_style style; be_plain_font->GetFamilyAndStyle(&family, &style); SETFONTDEFAULT(font_sans, family); SETFONTDEFAULT(font_serif, family); SETFONTDEFAULT(font_mono, family); SETFONTDEFAULT(font_cursive, family); SETFONTDEFAULT(font_fantasy, family); */ #ifdef __HAIKU__ SETFONTDEFAULT(font_sans, "DejaVu Sans"); SETFONTDEFAULT(font_serif, "DejaVu Serif"); SETFONTDEFAULT(font_mono, "DejaVu Mono"); SETFONTDEFAULT(font_cursive, "DejaVu Sans"); SETFONTDEFAULT(font_fantasy, "DejaVu Sans"); #else SETFONTDEFAULT(font_sans, "Bitstream Vera Sans"); SETFONTDEFAULT(font_serif, "Bitstream Vera Serif"); SETFONTDEFAULT(font_mono, "Bitstream Vera Sans Mono"); SETFONTDEFAULT(font_cursive, "Bitstream Vera Serif"); SETFONTDEFAULT(font_fantasy, "Bitstream Vera Serif"); #endif nsbeos_options_init(); if (nsoption_charp(cookie_file) == NULL) { find_resource(buf, "Cookies", "%/Cookies"); LOG(("Using '%s' as Cookies file", buf)); nsoption_set_charp(cookie_file, strdup(buf)); } if (nsoption_charp(cookie_jar) == NULL) { find_resource(buf, "Cookies", "%/Cookies"); LOG(("Using '%s' as Cookie Jar file", buf)); nsoption_set_charp(cookie_jar, strdup(buf)); } if ((nsoption_charp(cookie_file) == NULL) || (nsoption_charp(cookie_jar) == NULL)) die("Failed initialising cookie options"); if (nsoption_charp(url_file) == NULL) { find_resource(buf, "URLs", "%/URLs"); LOG(("Using '%s' as URL file", buf)); nsoption_set_charp(url_file, strdup(buf)); } if (nsoption_charp(ca_path) == NULL) { find_resource(buf, "certs", "/etc/ssl/certs"); LOG(("Using '%s' as certificate path", buf)); nsoption_set_charp(ca_path, strdup(buf)); } //find_resource(buf, "mime.types", "/etc/mime.types"); beos_fetch_filetype_init(); urldb_load(nsoption_charp(url_file)); urldb_load_cookies(nsoption_charp(cookie_file)); //nsbeos_download_initialise(); if (!replicated) be_app->Unlock(); if (argc > 1) { addr = argv[1]; } else if (nsoption_charp(homepage_url) != NULL) { addr = nsoption_charp(homepage_url); } else { addr = NETSURF_HOMEPAGE; } /* create an initial browser window */ error = nsurl_create(addr, &url); if (error == NSERROR_OK) { error = browser_window_create( BW_CREATE_HISTORY, url, NULL, NULL, NULL); nsurl_unref(url); } if (error != NSERROR_OK) { warn_user(messages_get_errorcode(error), 0); } if (gFirstRefsReceived) { // resend the refs we got before having a window to send them to be_app_messenger.SendMessage(gFirstRefsReceived); delete gFirstRefsReceived; gFirstRefsReceived = NULL; } }
void nsbeos_dispatch_event(BMessage *message) { struct gui_window *gui = NULL; NSBrowserFrameView *view = NULL; struct beos_scaffolding *scaffold = NULL; NSBrowserWindow *window = NULL; //message->PrintToStream(); if (message->FindPointer("View", (void **)&view) < B_OK) view = NULL; if (message->FindPointer("gui_window", (void **)&gui) < B_OK) gui = NULL; if (message->FindPointer("Window", (void **)&window) < B_OK) window = NULL; if (message->FindPointer("scaffolding", (void **)&scaffold) < B_OK) scaffold = NULL; struct gui_window *z; for (z = window_list; z && gui && z != gui; z = z->next) continue; struct gui_window *y; for (y = window_list; y && scaffold && y->scaffold != scaffold; y = y->next) continue; if (gui && gui != z) { LOG(("discarding event for destroyed gui_window")); delete message; return; } if (scaffold && (!y || scaffold != y->scaffold)) { LOG(("discarding event for destroyed scaffolding")); delete message; return; } // messages for top-level if (scaffold) { LOG(("dispatching to top-level")); nsbeos_scaffolding_dispatch_event(scaffold, message); delete message; return; } //LOG(("processing message")); switch (message->what) { case B_QUIT_REQUESTED: // from the BApplication netsurf_quit = true; break; case B_ABOUT_REQUESTED: { nsbeos_about(gui); /* XXX: doesn't work yet! bug in rsrc:/ BString url("rsrc:/about.en.html,text/html"); browser_window_create(url.String(), NULL, NULL, true, false); */ break; } case _UPDATE_: if (gui && view) nsbeos_window_expose_event(view, gui, message); break; case B_MOUSE_MOVED: { if (gui == NULL) break; BPoint where; int32 mods; // where refers to Window coords !? // check be:view_where first if (message->FindPoint("be:view_where", &where) < B_OK) { if (message->FindPoint("where", &where) < B_OK) break; } if (message->FindInt32("modifiers", &mods) < B_OK) mods = 0; if (gui->mouse.state & BROWSER_MOUSE_PRESS_1) { /* Start button 1 drag */ browser_window_mouse_click(gui->bw, BROWSER_MOUSE_DRAG_1, gui->mouse.pressed_x, gui->mouse.pressed_y); /* Replace PRESS with HOLDING and declare drag in progress */ gui->mouse.state ^= (BROWSER_MOUSE_PRESS_1 | BROWSER_MOUSE_HOLDING_1); gui->mouse.state |= BROWSER_MOUSE_DRAG_ON; } else if (gui->mouse.state & BROWSER_MOUSE_PRESS_2) { /* Start button 2 drag */ browser_window_mouse_click(gui->bw, BROWSER_MOUSE_DRAG_2, gui->mouse.pressed_x, gui->mouse.pressed_y); /* Replace PRESS with HOLDING and declare drag in progress */ gui->mouse.state ^= (BROWSER_MOUSE_PRESS_2 | BROWSER_MOUSE_HOLDING_2); gui->mouse.state |= BROWSER_MOUSE_DRAG_ON; } bool shift = mods & B_SHIFT_KEY; bool ctrl = mods & B_CONTROL_KEY; /* Handle modifiers being removed */ if (gui->mouse.state & BROWSER_MOUSE_MOD_1 && !shift) gui->mouse.state ^= BROWSER_MOUSE_MOD_1; if (gui->mouse.state & BROWSER_MOUSE_MOD_2 && !ctrl) gui->mouse.state ^= BROWSER_MOUSE_MOD_2; browser_window_mouse_track(gui->bw, (browser_mouse_state)gui->mouse.state, (int)(where.x / gui->bw->scale), (int)(where.y / gui->bw->scale)); gui->last_x = (int)where.x; gui->last_y = (int)where.y; break; } case B_MOUSE_DOWN: { if (gui == NULL) break; BPoint where; int32 buttons; int32 mods; BPoint screenWhere; if (message->FindPoint("be:view_where", &where) < B_OK) { if (message->FindPoint("where", &where) < B_OK) break; } if (message->FindInt32("buttons", &buttons) < B_OK) break; if (message->FindPoint("screen_where", &screenWhere) < B_OK) break; if (message->FindInt32("modifiers", &mods) < B_OK) mods = 0; if (buttons & B_SECONDARY_MOUSE_BUTTON) { /* 2 == right button on BeOS */ nsbeos_scaffolding_popup_menu(gui->scaffold, screenWhere); break; } gui->mouse.state = BROWSER_MOUSE_PRESS_1; if (buttons & B_TERTIARY_MOUSE_BUTTON) /* 3 == middle button on BeOS */ gui->mouse.state = BROWSER_MOUSE_PRESS_2; if (mods & B_SHIFT_KEY) gui->mouse.state |= BROWSER_MOUSE_MOD_1; if (mods & B_CONTROL_KEY) gui->mouse.state |= BROWSER_MOUSE_MOD_2; gui->mouse.pressed_x = where.x / gui->bw->scale; gui->mouse.pressed_y = where.y / gui->bw->scale; // make sure the view is in focus if (view && view->LockLooper()) { if (!view->IsFocus()) view->MakeFocus(); view->UnlockLooper(); } browser_window_mouse_click(gui->bw, (browser_mouse_state)gui->mouse.state, gui->mouse.pressed_x, gui->mouse.pressed_y); break; } case B_MOUSE_UP: { if (gui == NULL) break; BPoint where; int32 buttons; int32 mods; BPoint screenWhere; if (message->FindPoint("be:view_where", &where) < B_OK) { if (message->FindPoint("where", &where) < B_OK) break; } if (message->FindInt32("buttons", &buttons) < B_OK) break; if (message->FindPoint("screen_where", &screenWhere) < B_OK) break; if (message->FindInt32("modifiers", &mods) < B_OK) mods = 0; /* If the mouse state is PRESS then we are waiting for a release to emit * a click event, otherwise just reset the state to nothing*/ if (gui->mouse.state & BROWSER_MOUSE_PRESS_1) gui->mouse.state ^= (BROWSER_MOUSE_PRESS_1 | BROWSER_MOUSE_CLICK_1); else if (gui->mouse.state & BROWSER_MOUSE_PRESS_2) gui->mouse.state ^= (BROWSER_MOUSE_PRESS_2 | BROWSER_MOUSE_CLICK_2); bool shift = mods & B_SHIFT_KEY; bool ctrl = mods & B_CONTROL_KEY; /* Handle modifiers being removed */ if (gui->mouse.state & BROWSER_MOUSE_MOD_1 && !shift) gui->mouse.state ^= BROWSER_MOUSE_MOD_1; if (gui->mouse.state & BROWSER_MOUSE_MOD_2 && !ctrl) gui->mouse.state ^= BROWSER_MOUSE_MOD_2; /* if (view && view->LockLooper()) { view->MakeFocus(); view->UnlockLooper(); } */ if (gui->mouse.state & (BROWSER_MOUSE_CLICK_1|BROWSER_MOUSE_CLICK_2)) browser_window_mouse_click(gui->bw, (browser_mouse_state)gui->mouse.state, where.x / gui->bw->scale, where.y / gui->bw->scale); else browser_window_mouse_track(gui->bw, (browser_mouse_state)0, where.x, where.y); gui->mouse.state = 0; break; } case B_KEY_DOWN: if (gui && view) nsbeos_window_keypress_event(view, gui, message); break; case B_VIEW_RESIZED: if (gui && view) nsbeos_window_resize_event(view, gui, message); break; case B_VIEW_MOVED: if (gui && view) nsbeos_window_moved_event(view, gui, message); break; case B_MOUSE_WHEEL_CHANGED: break; case B_UI_SETTINGS_CHANGED: nsbeos_update_system_ui_colors(); break; case 'nsLO': // login { BString url; BString realm; BString auth; if (message->FindString("URL", &url) < B_OK) break; if (message->FindString("Realm", &realm) < B_OK) break; if (message->FindString("Auth", &auth) < B_OK) break; //printf("login to '%s' with '%s'\n", url.String(), auth.String()); urldb_set_auth_details(url.String(), realm.String(), auth.String()); browser_window_go(gui->bw, url.String(), 0, true); break; } default: break; } delete message; }
void gui_init(int argc, char** argv) { char buf[PATH_MAX]; if (pipe(sEventPipe) < 0) return; if (!replicated) { sBAppThreadID = spawn_thread(bapp_thread, "BApplication(NetSurf)", B_NORMAL_PRIORITY, (void *)find_thread(NULL)); if (sBAppThreadID < B_OK) return; /* #### handle errors */ if (resume_thread(sBAppThreadID) < B_OK) return; } // ui_color() gives hardcoded values before BApplication is created. nsbeos_update_system_ui_colors(); fetch_rsrc_register(); check_homedir(); // make sure the cache dir exists create_directory(TEMP_FILENAME_PREFIX, 0600); //nsbeos_completion_init(); /* This is an ugly hack to just get the new-style throbber going. * It, along with the PNG throbber loader, need making more generic. */ { #define STROF(n) #n #define FIND_THROB(n) filenames[(n)] = \ "throbber" STROF(n) ".png"; char *filenames[9]; FIND_THROB(0); FIND_THROB(1); FIND_THROB(2); FIND_THROB(3); FIND_THROB(4); FIND_THROB(5); FIND_THROB(6); FIND_THROB(7); FIND_THROB(8); nsbeos_throbber_initialise_from_png(9, filenames[0], filenames[1], filenames[2], filenames[3], filenames[4], filenames[5], filenames[6], filenames[7], filenames[8]); #undef FIND_THROB #undef STROF } if (nsbeos_throbber == NULL) die("Unable to load throbber image.\n"); find_resource(buf, "Choices", "%/Choices"); LOG(("Using '%s' as Preferences file", buf)); options_file_location = strdup(buf); nsoption_read(buf); /* check what the font settings are, setting them to a default font * if they're not set - stops Pango whinging */ #define SETFONTDEFAULT(OPTION,y) if (nsoption_charp(OPTION) == NULL) nsoption_set_charp(OPTION, strdup((y))) //XXX: use be_plain_font & friends, when we can check if font is serif or not. /* font_family family; font_style style; be_plain_font->GetFamilyAndStyle(&family, &style); SETFONTDEFAULT(font_sans, family); SETFONTDEFAULT(font_serif, family); SETFONTDEFAULT(font_mono, family); SETFONTDEFAULT(font_cursive, family); SETFONTDEFAULT(font_fantasy, family); */ #ifdef __HAIKU__ SETFONTDEFAULT(font_sans, "DejaVu Sans"); SETFONTDEFAULT(font_serif, "DejaVu Serif"); SETFONTDEFAULT(font_mono, "DejaVu Mono"); SETFONTDEFAULT(font_cursive, "DejaVu Sans"); SETFONTDEFAULT(font_fantasy, "DejaVu Sans"); #else SETFONTDEFAULT(font_sans, "Bitstream Vera Sans"); SETFONTDEFAULT(font_serif, "Bitstream Vera Serif"); SETFONTDEFAULT(font_mono, "Bitstream Vera Sans Mono"); SETFONTDEFAULT(font_cursive, "Bitstream Vera Serif"); SETFONTDEFAULT(font_fantasy, "Bitstream Vera Serif"); #endif nsbeos_options_init(); if (nsoption_charp(cookie_file) == NULL) { find_resource(buf, "Cookies", "%/Cookies"); LOG(("Using '%s' as Cookies file", buf)); nsoption_set_charp(cookie_file, strdup(buf)); } if (nsoption_charp(cookie_jar) == NULL) { find_resource(buf, "Cookies", "%/Cookies"); LOG(("Using '%s' as Cookie Jar file", buf)); nsoption_set_charp(cookie_jar, strdup(buf)); } if ((nsoption_charp(cookie_file) == NULL) || (nsoption_charp(cookie_jar) == NULL)) die("Failed initialising cookie options"); if (nsoption_charp(url_file) == NULL) { find_resource(buf, "URLs", "%/URLs"); LOG(("Using '%s' as URL file", buf)); nsoption_set_charp(url_file, strdup(buf)); } if (nsoption_charp(ca_path) == NULL) { find_resource(buf, "certs", "/etc/ssl/certs"); LOG(("Using '%s' as certificate path", buf)); nsoption_set_charp(ca_path, strdup(buf)); } //find_resource(buf, "mime.types", "/etc/mime.types"); beos_fetch_filetype_init(); urldb_load(nsoption_charp(url_file)); urldb_load_cookies(nsoption_charp(cookie_file)); //nsbeos_download_initialise(); if (!replicated) be_app->Unlock(); }