⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 interface.c

📁 嵌入式下基于MiniGUI的Web Browser
💻 C
📖 第 1 页 / 共 4 页
字号:
void Interface_entry_open_url(HWND hwnd, int id, int nc, DWORD add_data){    if (nc == EN_ENTER)    {        BrowserWindow* bw;        gchar* url_string = NULL;        bw = (BrowserWindow*)GetWindowAdditionalData2 (GetDlgItem(GetParent(hwnd), IDC_DILLO));        url_string = a_Interface_get_location_text(bw);        if (url_string)        {            a_Interface_open_url_string (url_string, bw);            g_free (url_string);        }    }}/* * Create the "NEW" button, its location-entry and the search button. */static HWND Interface_locbar_new(HWND hwnd, HWND toolbar_hwnd){    HWND ctrl;    RECT rc_bw, rc_tb;    int x = 2, y = 3, width;    GetWindowRect (hwnd, &rc_bw);    if (toolbar_hwnd != -1)    {        GetWindowRect (toolbar_hwnd, &rc_tb);        x += RECTW(rc_tb);    }    width = RECTW(rc_bw) - x - 10;    ctrl = CreateWindowEx (CTRL_SLEDIT, "",                            WS_CHILD | WS_BORDER | WS_VISIBLE,                           0, IDC_LOCATION, x, y, width, LOCATION_HEIGHT,                           hwnd, 0);	//SetWindowBkColor(ctrl, RGB2Pixel(HDC_SCREEN, 17, 116, 176));	//SetWindowElementColorEx(ctrl, FGC_CAPTION_NORMAL, RGB2Pixel(HDC_SCREEN, 0, 255, 0));    SetNotificationCallback (ctrl, Interface_entry_open_url);    return ctrl;}static void toolbar_notif_proc (HWND hwnd, int id, int nc, DWORD add_data){    HWND parent = GetParent (hwnd);    BrowserWindow* bw = (BrowserWindow*) GetWindowAdditionalData2 (GetDlgItem(parent, IDC_DILLO));    DwViewport* viewport = (DwViewport*)bw->viewport;    switch (nc) {    case IDC_NAV_BACKWARD:        if (viewport == NULL)            break;        a_Nav_back (bw);        break;    case IDC_NAV_FORWARD:        if (viewport == NULL)            break;        a_Nav_forw (bw);#if 0        if ( nc == IDC_NAV_BACKWARD)            url = a_Nav_back (bw);        else             url = a_Nav_forw (bw);        if (url) {            if (open_url (bw, url))                bw->NumImages = 0;                bw->NumImagesGot = 0;                a_Nav_push(bw, url);                viewport->url = url;        }#endif        break;    case IDC_NAV_RESET:        Interface_entry_clear(bw);         break;    case IDC_NAV_STOP:        a_Nav_cancel_expect (bw);        a_Interface_stop (bw);        break;    case IDC_NAV_HOME:    {        char url_buf [256] = "file://";                    getcwd (url_buf + 7, 256 - 8);#ifdef MGDEMO_ENGLISH		strcat (url_buf, "/eindex.html");#else		strcat (url_buf, "/index.html");#endif                 SendDlgItemMessage (parent, IDC_DILLO, MGD_OPENURL, 0, (LPARAM)url_buf);        break;    }    case IDC_NAV_RELOAD:        a_Nav_reload (bw);        break;    case IDC_NAV_EXIT:        break;    }}static HWND create_new_toolbar (HWND hWnd){    HWND ntb;    NTBINFO ntb_info;    NTBITEMINFO ntbii;    ntb_info.nr_cells = 6;    ntb_info.w_cell  = 0;    ntb_info.h_cell  = 0;    ntb_info.nr_cols = 0;    ntb_info.image = &ntb_bmp;    ntb = CreateWindow (CTRL_NEWTOOLBAR,                    "",                    WS_CHILD | WS_VISIBLE,                     IDC_TOOLBAR,                    0, 0, 185, 0,                    hWnd,                    (DWORD) &ntb_info);    if (ntb == HWND_INVALID)        return HWND_INVALID;    SetNotificationCallback (ntb, toolbar_notif_proc);    pixel = GetPixelInBitmap (&ntb_bmp, 0, 0);    SetWindowBkColor (ntb, pixel);    InvalidateRect (ntb, NULL, TRUE);    memset (&ntbii, 0, sizeof (ntbii));    ntbii.flags = NTBIF_PUSHBUTTON;    ntbii.id = IDC_NAV_BACKWARD;    ntbii.bmp_cell = 1;    SendMessage(ntb, TBM_ADDITEM, 0, (LPARAM)&ntbii);    ntbii.flags = NTBIF_PUSHBUTTON;    ntbii.id = IDC_NAV_FORWARD;    ntbii.bmp_cell = 2;    SendMessage (ntb, TBM_ADDITEM, 0, (LPARAM)&ntbii);    ntbii.flags = NTBIF_PUSHBUTTON;    ntbii.id = IDC_NAV_HOME;    ntbii.bmp_cell = 3;    SendMessage (ntb, TBM_ADDITEM, 0, (LPARAM)&ntbii);        ntbii.flags = NTBIF_SEPARATOR;    ntbii.id = 0;    ntbii.bmp_cell = 0;    ntbii.text = NULL;    SendMessage (ntb, TBM_ADDITEM, 0, (LPARAM)&ntbii);    ntbii.flags = NTBIF_PUSHBUTTON;    ntbii.id = IDC_NAV_RELOAD;    ntbii.bmp_cell = 0;    SendMessage (ntb, TBM_ADDITEM, 0, (LPARAM)&ntbii);    ntbii.flags = NTBIF_PUSHBUTTON;    ntbii.id = IDC_NAV_STOP;    ntbii.bmp_cell = 4;    SendMessage (ntb, TBM_ADDITEM, 0, (LPARAM)&ntbii);    ntbii.flags = NTBIF_PUSHBUTTON;    ntbii.id = IDC_NAV_RESET;    ntbii.bmp_cell = 5;    SendMessage (ntb, TBM_ADDITEM, 0, (LPARAM)&ntbii);    return ntb;}/* * Create a new toolbar (Back, Forward, Home, Reload, Save and Stop buttons) */static HWND Interface_toolbar_new(HWND hwnd_parent){    HWND hwnd;    int retval;    if ((retval = LoadBitmap (HDC_SCREEN, &ntb_bmp, "res/newtoolbar.jpg"))) {        fprintf (stderr, "eDillo: Can not load bitmap for toolbar: %d.\n", retval);        return -1;    }    hwnd = create_new_toolbar (hwnd_parent);    if (hwnd == HWND_INVALID) {        fprintf (stderr, "eDillo: Can not create toolbar.\n");        return -1;    }    return hwnd;}/* * Create the progressbar's box */static HWND Interface_progressbar_new(HWND hwnd_parent){    HWND ctrl;    RECT rc_bw;    int  width;    int  title_height;    title_height = GetMainWinMetrics(MWM_CAPTIONY);    GetWindowRect (hwnd_parent, &rc_bw);    width = rc_bw.right - rc_bw.left;    ctrl = CreateWindowEx(CTRL_STATIC, NULL, WS_VISIBLE | SS_CENTER | SS_NOTIFY | WS_BORDER,                                 WS_EX_NONE, IDC_PROGRESSBAR,                                 width - PROGRESSBAR_WIDTH,                                 rc_bw.bottom - STATUSBAR_HEIGHT - title_height - 2,                                 PROGRESSBAR_WIDTH, STATUSBAR_HEIGHT, hwnd_parent, 0);    return ctrl;}/* * Hide/Unhide this bw's control panels. * toggle: Flag [toggle or set]. */#if 0void Interface_toggle_panel(BrowserWindow *bw, gint toggle){   if (toggle)      bw->fullwindow = !bw->fullwindow;   if (bw->fullwindow) {      g_slist_foreach(bw->PanelHandles, (GFunc)gtk_widget_hide, NULL);      gtk_widget_hide(bw->status_box);      gtk_widget_show (bw->full_screen_off_button);      gtk_widget_grab_focus(GTK_BIN(bw->docwin)->child);   } else {      g_slist_foreach(bw->PanelHandles, (GFunc)gtk_widget_show, NULL);      gtk_widget_show(bw->status_box);      gtk_widget_hide (bw->full_screen_off_button);   }}#endif/* * Customize the appearance of the bw. */#if 0static void Interface_browser_window_customize(BrowserWindow *bw){   if ( !prefs.show_back )      gtk_widget_hide(bw->back_button);   if ( !prefs.show_forw )      gtk_widget_hide(bw->forw_button);   if ( !prefs.show_home )      gtk_widget_hide(bw->home_button);   if ( !prefs.show_reload )      gtk_widget_hide(bw->reload_button);   if ( !prefs.show_save )      gtk_widget_hide(bw->save_button);   if ( !prefs.show_stop )      gtk_widget_hide(bw->stop_button);   if ( !prefs.show_bookmarks )      gtk_widget_hide(bw->bookmarks_button);   if ( !prefs.show_menubar )      gtk_widget_hide(bw->menubar);   if ( !prefs.show_clear_url)      gtk_widget_hide(bw->clear_url_button);   if ( !prefs.show_url )      gtk_widget_hide(bw->location);   if ( !prefs.show_search )      gtk_widget_hide(bw->search_button);   if ( !prefs.show_progress_box )      gtk_widget_hide(bw->progress_box);   bw->fullwindow = prefs.fullwindow_start;   Interface_toggle_panel(bw, FALSE);}#endif#if 0static void Interface_full_screen_callback (BrowserWindow *bw){   Interface_toggle_panel(bw, TRUE);}#endif/* * Handler for double-mouse-clicks that don't belong to the viewport. */#if 0static gint Interface_click_callback(BrowserWindow *bw, GdkEventButton *event){   if (event->type == GDK_2BUTTON_PRESS && event->button == 1)      Interface_toggle_panel(bw, TRUE);   return TRUE;}#endif/* * Handler for key presses that don't belong to the viewport. * (Used to customize the interface a bit) */#if 0static void Interface_key_press_handler(GtkWidget *widget,                                        GdkEventKey *event,                                        gpointer client_data){   BrowserWindow *bw = client_data;   switch (event->keyval) {   case GDK_BackSpace:      /* This key is handled here because GTK accel group ignores it */      if (event->state & GDK_SHIFT_MASK)         a_Commands_forw_callback(NULL, bw);      else         a_Commands_back_callback(NULL, bw);      break;   case GDK_slash:      /* This key is handled here because GTK accel group ignores it */      a_Commands_findtext_callback(NULL, bw);      break;   default:      _MSG(">> Key pressed!\n");      break;   }}#endif/* * Add the button for switching into fullscreen mode */#if 0static void Interface_add_full_screen_button (BrowserWindow *bw, GtkBox *box){   /* The button is put into a vbox, so that it is not enlarged vertically. */   GtkWidget *vbox, *dummy, *button, *pixmap;   vbox = gtk_vbox_new (FALSE, 0);   gtk_box_pack_start (GTK_BOX (box), vbox, FALSE, FALSE, 0);   gtk_widget_show (vbox);   /* The dummy will make the button align at the bottom.    * (Important only when using large text fonts.) */   dummy = gtk_vbox_new (FALSE, 0);   gtk_box_pack_start (GTK_BOX (vbox), dummy, TRUE, TRUE, 0);   gtk_widget_show (dummy);   button = gtk_button_new ();   gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);   gtk_tooltips_set_tip (tooltips, button, "Hide Controls", "Show Controls");   GTK_WIDGET_UNSET_FLAGS (button, GTK_CAN_FOCUS);   gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);   gtk_widget_show (button);   pixmap = Interface_pixmap_new(bw->main_window, full_screen_on_xpm);   gtk_container_add (GTK_CONTAINER (button), pixmap);   gtk_widget_show (pixmap);   gtk_signal_connect_object      (GTK_OBJECT (button), "clicked",       GTK_SIGNAL_FUNC (Interface_full_screen_callback), (gpointer)bw);}#endifBrowserWindow* a_BrowserWindow_new (HWND hwnd_parent){    BrowserWindow* bw;    bw = g_new0 (BrowserWindow, 1);    a_List_add(browser_window, num_bw, num_bw_max);    bw->main_window = hwnd_parent;    bw->docwin =       bw->hwnd_location =       bw->hwnd_menubar =       bw->hwnd_toolbar =       bw->hwnd_statusbar =        bw->hwnd_progressbar = -1;    bw->redirect_level = 0;    bw->sens_idle_id = 0;    bw->RootClients = NULL;    bw->NumRootClients = 0;    bw->MaxRootClients = 8;    bw->ImageClients = NULL;    bw->NumImageClients = 0;    bw->MaxImageClients = 8;    bw->NumImages = 0;    bw->NumImagesGot = 0;    bw->PageUrls = NULL;    bw->NumPageUrls = 0;    bw->MaxPageUrls = 8;    a_Nav_init(bw);    return bw;}/* * Create a new browser window and return it. * (the new window is stored in browser_window[]) */BrowserWindow*a_Interface_browser_window_new(HWND hwnd_parent, int width, int height,                               char* start_page,                               BrowserWindowType bw_type){    BrowserWindow* bw;    DwViewport* viewport;    RECT rc = {0, 0, 0, 0};    int y = 0;    bw = a_BrowserWindow_new (hwnd_parent);    browser_window[num_bw++] = bw;    if (bw_type & WITH_TOOLBAR)        bw->hwnd_toolbar = Interface_toolbar_new(hwnd_parent);    if (bw_type & WITH_LOCATION)        bw->hwnd_location = Interface_locbar_new (hwnd_parent,                         bw->hwnd_toolbar);    if (bw_type & WITH_PROGRESSBAR)        bw->hwnd_progressbar = Interface_progressbar_new(hwnd_parent);     if (bw_type & WITH_STATUSBAR)        bw->hwnd_statusbar = Interface_statusbar_new(hwnd_parent,                         bw->hwnd_progressbar);    if (bw_type & WITH_MENUBAR)        printf("create a menu bar \n");    if (bw->hwnd_toolbar != -1 || bw->hwnd_location != -1)     {        if (bw->hwnd_toolbar != -1)            GetWindowRect(bw->hwnd_toolbar, &rc);        else if (bw->hwnd_toolbar == -1 && bw->hwnd_location != -1)            GetWindowRect(bw->hwnd_location, &rc);                    height -= RECTH(rc);        y += RECTH(rc);    }    if (bw->hwnd_statusbar != -1)        height -= STATUSBAR_HEIGHT;    bw->docwin = CreateWindowEx (CTRL_DILLO,                      start_page,                      WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL | WS_HSCROLL,                       WS_EX_CLIPCHILDREN,                      IDC_DILLO,                       0, y,                       width, height, hwnd_parent, 0);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -