void ami_history_redraw(struct history_window *hw) { struct IBox *bbox; ULONG xs,ys; GetAttr(SPACE_AreaBox,hw->objects[GID_BROWSER],(ULONG *)&bbox); GetAttr(SCROLLER_Top,hw->objects[OID_HSCROLL],(ULONG *)&xs); GetAttr(SCROLLER_Top,hw->objects[OID_VSCROLL],(ULONG *)&ys); glob = &hw->gg; ami_clg(0xffffff); history_redraw_rectangle(history_current, xs, ys, bbox->Width + xs, bbox->Height + ys, 0, 0); glob = &browserglob; ami_clearclipreg(&hw->gg); ami_history_update_extent(hw); BltBitMapRastPort(hw->gg.bm, 0, 0, hw->win->RPort, bbox->Left, bbox->Top, bbox->Width, bbox->Height, 0x0C0); }
static int localhistory_redraw(fbtk_widget_t *widget, fbtk_callback_info *cbi) { struct gui_localhistory *glh = cbi->context; nsfb_bbox_t rbox; struct redraw_context ctx = { .interactive = true, .background_images = true, .plot = &fb_plotters }; rbox.x0 = fbtk_get_absx(widget); rbox.y0 = fbtk_get_absy(widget); rbox.x1 = rbox.x0 + fbtk_get_width(widget); rbox.y1 = rbox.y0 + fbtk_get_height(widget); nsfb_claim(fbtk_get_nsfb(widget), &rbox); nsfb_plot_rectangle_fill(fbtk_get_nsfb(widget), &rbox, 0xffffffff); history_redraw_rectangle(glh->bw->history, glh->scrollx, glh->scrolly, fbtk_get_width(widget) + glh->scrollx, fbtk_get_height(widget) + glh->scrolly, 0, 0, &ctx); nsfb_update(fbtk_get_nsfb(widget), &rbox); return 0; } static int localhistory_click(fbtk_widget_t *widget, fbtk_callback_info *cbi) { struct gui_localhistory *glh = cbi->context; if (cbi->event->type != NSFB_EVENT_KEY_UP) return 0; history_click(glh->bw, glh->bw->history, cbi->x, cbi->y, false); fbtk_set_mapping(glh->window, false); return 1; } struct gui_localhistory * fb_create_localhistory(struct browser_window *bw, fbtk_widget_t *parent, int furniture_width) { struct gui_localhistory *glh; glh = calloc(1, sizeof(struct gui_localhistory)); if (glh == NULL) return NULL; glh->bw = bw; /* container window */ glh->window = fbtk_create_window(parent, 0, 0, 0, 0, 0); glh->history = fbtk_create_user(glh->window, 0, 0, -furniture_width, -furniture_width, glh); fbtk_set_handler(glh->history, FBTK_CBT_REDRAW, localhistory_redraw, glh); fbtk_set_handler(glh->history, FBTK_CBT_CLICK, localhistory_click, glh); /* fbtk_set_handler(gw->localhistory, FBTK_CBT_INPUT, fb_browser_window_input, gw); fbtk_set_handler(gw->localhistory, FBTK_CBT_POINTERMOVE, fb_browser_window_move, bw); */ /* create horizontal scrollbar */ glh->hscroll = fbtk_create_hscroll(glh->window, 0, fbtk_get_height(glh->window) - furniture_width, fbtk_get_width(glh->window) - furniture_width, furniture_width, FB_SCROLL_COLOUR, FB_FRAME_COLOUR, NULL, NULL); glh->vscroll = fbtk_create_vscroll(glh->window, fbtk_get_width(glh->window) - furniture_width, 0, furniture_width, fbtk_get_height(glh->window) - furniture_width, FB_SCROLL_COLOUR, FB_FRAME_COLOUR, NULL, NULL); fbtk_create_fill(glh->window, fbtk_get_width(glh->window) - furniture_width, fbtk_get_height(glh->window) - furniture_width, furniture_width, furniture_width, FB_FRAME_COLOUR); return glh; } void fb_localhistory_map(struct gui_localhistory * glh) { fbtk_set_zorder(glh->window, INT_MIN); fbtk_set_mapping(glh->window, true); }
static void nsws_localhistory_up(struct nsws_localhistory *l, struct gui_window *gw) { HDC tmp_hdc; struct redraw_context ctx = { .interactive = true, .background_images = true, .plot = &win_plotters }; LOG(("gui window %p", gw)); l->vscroll = 0; l->hscroll = 0; if (gw->bw != NULL) { /* set global HDC for the plotters */ tmp_hdc = plot_hdc; plot_hdc = GetDC(l->hwnd); history_redraw(gw->bw->history, &ctx); ReleaseDC(l->hwnd, plot_hdc); plot_hdc = tmp_hdc; } nsws_localhistory_scroll_check(l, gw); } /* void history_gui_set_pointer(gui_pointer_shape shape, void *p) { struct nsws_pointers *pointers = nsws_get_pointers(); if (pointers == NULL) return; switch(shape) { case GUI_POINTER_POINT: SetCursor(pointers->hand); break; default: SetCursor(pointers->arrow); break; } } */ void nsws_localhistory_close(struct gui_window *w) { struct nsws_localhistory *l = gui_window_localhistory(w); if (l != NULL) CloseWindow(l->hwnd); } static LRESULT CALLBACK nsws_localhistory_event_callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { int x,y; struct gui_window *gw; LOG_WIN_MSG(hwnd, msg, wparam, lparam); gw = nsws_get_gui_window(hwnd); if (gw == NULL) { LOG(("Unable to find gui window structure for hwnd %p", hwnd)); return DefWindowProc(hwnd, msg, wparam, lparam); } switch(msg) { case WM_CREATE: nsws_localhistory_scroll_check(gw->localhistory, gw); break; case WM_SIZE: gw->localhistory->guiheight = HIWORD(lparam); gw->localhistory->guiwidth = LOWORD(lparam); nsws_localhistory_scroll_check(gw->localhistory, gw); break; case WM_LBUTTONUP: if (gw->bw == NULL) break; x = GET_X_LPARAM(lparam); y = GET_Y_LPARAM(lparam); if (history_click(gw->bw, gw->bw->history, gw->localhistory->hscroll + x, gw->localhistory->vscroll + y, false)) { DestroyWindow(hwnd); } break; case WM_MOUSEMOVE: x = GET_X_LPARAM(lparam); y = GET_Y_LPARAM(lparam); /* if (gw->bw != NULL) history_hover(gw->bw->history, x, y, (void *)hwnd);*/ return DefWindowProc(hwnd, msg, wparam, lparam); break; case WM_VSCROLL: { SCROLLINFO si; int mem; si.cbSize = sizeof(si); si.fMask = SIF_ALL; GetScrollInfo(hwnd, SB_VERT, &si); mem = si.nPos; switch (LOWORD(wparam)) { case SB_TOP: si.nPos = si.nMin; break; case SB_BOTTOM: si.nPos = si.nMax; break; case SB_LINEUP: si.nPos -= 30; break; case SB_LINEDOWN: si.nPos += 30; break; case SB_PAGEUP: si.nPos -= gw->localhistory->guiheight; break; case SB_PAGEDOWN: si.nPos += gw->localhistory->guiheight; break; case SB_THUMBTRACK: si.nPos = si.nTrackPos; break; default: break; } si.nPos = min(si.nPos, gw->localhistory->height); si.nPos = min(si.nPos, 0); si.fMask = SIF_POS; SetScrollInfo(hwnd, SB_VERT, &si, TRUE); GetScrollInfo(hwnd, SB_VERT, &si); if (si.nPos != mem) { gw->localhistory->vscroll += si.nPos - mem; ScrollWindowEx(hwnd, 0, -(si.nPos - mem), NULL, NULL, NULL, NULL, SW_ERASE | SW_INVALIDATE); } break; } case WM_HSCROLL: { SCROLLINFO si; int mem; si.cbSize = sizeof(si); si.fMask = SIF_ALL; GetScrollInfo(hwnd, SB_HORZ, &si); mem = si.nPos; switch (LOWORD(wparam)) { case SB_LINELEFT: si.nPos -= 30; break; case SB_LINERIGHT: si.nPos += 30; break; case SB_PAGELEFT: si.nPos -= gw->localhistory->guiwidth; break; case SB_PAGERIGHT: si.nPos += gw->localhistory->guiwidth; break; case SB_THUMBTRACK: si.nPos = si.nTrackPos; break; default: break; } si.nPos = min(si.nPos, gw->localhistory->width); si.nPos = max(si.nPos, 0); si.fMask = SIF_POS; SetScrollInfo(hwnd, SB_HORZ, &si, TRUE); GetScrollInfo(hwnd, SB_HORZ, &si); if (si.nPos != mem) { gw->localhistory->hscroll += si.nPos - mem; ScrollWindowEx(hwnd, -(si.nPos - mem), 0, NULL, NULL, NULL, NULL, SW_ERASE | SW_INVALIDATE); } break; } case WM_PAINT: { PAINTSTRUCT ps; HDC hdc, tmp_hdc; struct redraw_context ctx = { .interactive = true, .background_images = true, .plot = &win_plotters }; hdc = BeginPaint(hwnd, &ps); if (gw->bw != NULL) { /* set global HDC for the plotters */ tmp_hdc = plot_hdc; plot_hdc = hdc; history_redraw_rectangle(gw->bw->history, gw->localhistory->hscroll + ps.rcPaint.left, gw->localhistory->vscroll + ps.rcPaint.top, gw->localhistory->hscroll + (ps.rcPaint.right - ps.rcPaint.left), gw->localhistory->vscroll + (ps.rcPaint.bottom - ps.rcPaint.top), ps.rcPaint.left, ps.rcPaint.top, &ctx); plot_hdc = tmp_hdc; } EndPaint(hwnd, &ps); break; } case WM_CLOSE: DestroyWindow(hwnd); return 1; case WM_DESTROY: free(gw->localhistory); gw->localhistory = NULL; break; default: return DefWindowProc(hwnd, msg, wparam, lparam); } return 0; } /* exported method documented in windows/localhistory.h */ struct nsws_localhistory *nsws_window_create_localhistory(struct gui_window *gw) { struct nsws_localhistory *localhistory; INITCOMMONCONTROLSEX icc; int margin = 50; RECT r; LOG(("gui window %p", gw)); /* if we already have a window, just update and re-show it */ if (gw->localhistory != NULL) { nsws_localhistory_up(gw->localhistory, gw); UpdateWindow(gw->localhistory->hwnd); ShowWindow(gw->localhistory->hwnd, SW_SHOWNORMAL); return gw->localhistory; } localhistory = calloc(1, sizeof(struct nsws_localhistory)); if (localhistory == NULL) { return NULL; } gw->localhistory = localhistory; localhistory->width = 0; localhistory->height = 0; if ((gw->bw != NULL) && (gw->bw->history != NULL)) { history_size(gw->bw->history, &(localhistory->width), &(localhistory->height)); } GetWindowRect(gw->main, &r); SetWindowPos(gw->main, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE); localhistory->guiwidth = min(r.right - r.left - margin, localhistory->width + margin); localhistory->guiheight = min(r.bottom - r.top - margin, localhistory->height + margin); icc.dwSize = sizeof(icc); icc.dwICC = ICC_BAR_CLASSES | ICC_WIN95_CLASSES; #if WINVER > 0x0501 icc.dwICC |= ICC_STANDARD_CLASSES; #endif InitCommonControlsEx(&icc); LOG(("creating local history window for hInstance %p", hInstance)); localhistory->hwnd = CreateWindow(windowclassname_localhistory, "NetSurf History", WS_THICKFRAME | WS_HSCROLL | WS_VSCROLL | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_SYSMENU | CS_DBLCLKS, r.left + margin/2, r.top + margin/2, localhistory->guiwidth, localhistory->guiheight, NULL, NULL, hInstance, NULL); /* set the gui window associated with this browser */ SetProp(localhistory->hwnd, TEXT("GuiWnd"), (HANDLE)gw); LOG(("gui_window %p width %d height %d hwnd %p", gw, localhistory->guiwidth, localhistory->guiheight, localhistory->hwnd)); nsws_localhistory_up(localhistory, gw); UpdateWindow(localhistory->hwnd); ShowWindow(localhistory->hwnd, SW_SHOWNORMAL); return localhistory; } /* exported method documented in windows/localhistory.h */ nserror nsws_create_localhistory_class(HINSTANCE hinstance) { nserror ret = NSERROR_OK; WNDCLASSEX w; /* localhistory window */ w.cbSize = sizeof(WNDCLASSEX); w.style = 0; w.lpfnWndProc = nsws_localhistory_event_callback; w.cbClsExtra = 0; w.cbWndExtra = 0; w.hInstance = hinstance; w.hIcon = LoadIcon(hinstance, MAKEINTRESOURCE(IDR_NETSURF_ICON)); w.hCursor = LoadCursor(NULL, IDC_ARROW); w.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); w.lpszMenuName = NULL; w.lpszClassName = windowclassname_localhistory; w.hIconSm = LoadIcon(hinstance, MAKEINTRESOURCE(IDR_NETSURF_ICON)); if (RegisterClassEx(&w) == 0) { win_perror("DrawableClass"); ret = NSERROR_INIT_FAILED; } return ret; }
void ami_history_redraw(struct history_window *hw) { struct IBox *bbox; ULONG xs,ys; struct redraw_context ctx = { .interactive = true, .background_images = true, .plot = &amiplot }; GetAttr(SPACE_AreaBox,hw->objects[GID_BROWSER],(ULONG *)&bbox); GetAttr(SCROLLER_Top,hw->objects[OID_HSCROLL],(ULONG *)&xs); GetAttr(SCROLLER_Top,hw->objects[OID_VSCROLL],(ULONG *)&ys); glob = &hw->gg; SetRPAttrs(glob->rp, RPTAG_APenColor, 0xffffffff, TAG_DONE); RectFill(glob->rp, 0, 0, bbox->Width - 1, bbox->Height - 1); history_redraw_rectangle(history_current, xs, ys, bbox->Width + xs, bbox->Height + ys, 0, 0, &ctx); glob = &browserglob; ami_clearclipreg(&hw->gg); ami_history_update_extent(hw); BltBitMapRastPort(hw->gg.bm, 0, 0, hw->win->RPort, bbox->Left, bbox->Top, bbox->Width, bbox->Height, 0x0C0); } /** * Handle mouse clicks in the history window. * * \return true if the event was handled, false to pass it on */ bool ami_history_click(struct history_window *hw,uint16 code) { int x, y; struct IBox *bbox; ULONG width,height,xs,ys; GetAttr(SPACE_AreaBox,hw->objects[GID_BROWSER],(ULONG *)&bbox); GetAttr(SCROLLER_Top,hw->objects[OID_HSCROLL],(ULONG *)&xs); x = hw->win->MouseX - bbox->Left +xs; GetAttr(SCROLLER_Top,hw->objects[OID_VSCROLL],(ULONG *)&ys); y = hw->win->MouseY - bbox->Top + ys; width=bbox->Width; height=bbox->Height; switch(code) { case SELECTUP: history_click(hw->bw,history_current,x,y,false); ami_history_redraw(hw); ami_do_redraw(hw->bw->window->shared); break; case MIDDLEUP: history_click(hw->bw,history_current,x,y,true); ami_history_redraw(hw); break; } return true; }