Пример #1
0
void ro_gui_history_redraw(wimp_draw *redraw)
{
	osbool more;
	os_error *error;
	struct redraw_context ctx = {
		.interactive = true,
		.background_images = true,
		.plot = &ro_plotters
	};

	error = xwimp_redraw_window(redraw, &more);
	if (error) {
		LOG(("xwimp_redraw_window: 0x%x: %s",
				error->errnum, error->errmess));
		warn_user("WimpError", error->errmess);
		return;
	}
	while (more) {
		ro_plot_origin_x = redraw->box.x0 - redraw->xscroll;
		ro_plot_origin_y = redraw->box.y1 - redraw->yscroll;
		history_redraw(history_current, &ctx);
		error = xwimp_get_rectangle(redraw, &more);
		if (error) {
			LOG(("xwimp_get_rectangle: 0x%x: %s",
					error->errnum, error->errmess));
			warn_user("WimpError", error->errmess);
			return;
		}
	}
}


/**
 * Handle Pointer Entering Window events the history window.
 *
 * \param *entering		The Wimp_PointerEnteringWindow block.
 */

void ro_gui_history_pointer_entering(wimp_entering *entering)
{
	ro_mouse_track_start(ro_gui_history_track_end,
			ro_gui_history_mouse_at, NULL);
} 
Пример #2
0
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;
}
Пример #3
0
void ro_gui_history_redraw(wimp_draw *redraw)
{
	osbool more;
	os_error *error;
	struct redraw_context ctx = {
		.interactive = true,
		.background_images = true,
		.plot = &ro_plotters
	};

	error = xwimp_redraw_window(redraw, &more);
	if (error) {
		LOG(("xwimp_redraw_window: 0x%x: %s",
				error->errnum, error->errmess));
		warn_user("WimpError", error->errmess);
		return;
	}
	while (more) {
		ro_plot_origin_x = redraw->box.x0 - redraw->xscroll;
		ro_plot_origin_y = redraw->box.y1 - redraw->yscroll;
		history_redraw(history_current, &ctx);
		error = xwimp_get_rectangle(redraw, &more);
		if (error) {
			LOG(("xwimp_get_rectangle: 0x%x: %s",
					error->errnum, error->errmess));
			warn_user("WimpError", error->errmess);
			return;
		}
	}
}


/**
 * Handle mouse movements over the history window.
 */

void ro_gui_history_mouse_at(wimp_pointer *pointer)
{
	int x, y;
	int width;
	const char *url;
	wimp_window_state state;
	wimp_icon_state ic;
	os_box box = {0, 0, 0, 0};
	os_error *error;

	/* If the mouse hasn't moved, or if we don't want tooltips, exit */
	if ((mouse_x == pointer->pos.x && mouse_y == pointer->pos.y) ||
	    !nsoption_bool(history_tooltip))
		return;

	/* Update mouse position */
	mouse_x = pointer->pos.x;
	mouse_y = pointer->pos.y;

	/* Find history tree entry under mouse */
	state.w = history_window;
	error = xwimp_get_window_state(&state);
	if (error) {
		LOG(("xwimp_get_window_state: 0x%x: %s",
				error->errnum, error->errmess));
		warn_user("WimpError", error->errmess);
		return;
	}

	x = (pointer->pos.x - (state.visible.x0 - state.xscroll)) / 2;
	y = -(pointer->pos.y - (state.visible.y1 - state.yscroll)) / 2;
	url = history_position_url(history_current, x, y);
	if (!url) {
		/* not over a tree entry => close tooltip window. */
		error = xwimp_close_window(dialog_tooltip);
		if (error) {
			LOG(("xwimp_close_window: 0x%x: %s",
					error->errnum, error->errmess));
			warn_user("WimpError", error->errmess);
			return;
		}
		return;
	}

	/* get width of string */
	error = xwimptextop_string_width(url,
			strlen(url) > 256 ? 256 : strlen(url),
			&width);
	if (error) {
		LOG(("xwimptextop_string_width: 0x%x: %s",
				error->errnum, error->errmess));
		warn_user("WimpError", error->errmess);
		return;
	}

	ro_gui_set_icon_string(dialog_tooltip, 0, url, true);

	/* resize icon appropriately */
	ic.w = dialog_tooltip;
	ic.i = 0;
	error = xwimp_get_icon_state(&ic);
	if (error) {
		LOG(("xwimp_get_icon_state: 0x%x: %s",
				error->errnum, error->errmess));
		warn_user("WimpError", error->errmess);
		return;
	}
	error = xwimp_resize_icon(dialog_tooltip, 0,
			ic.icon.extent.x0, ic.icon.extent.y0,
			width + 16, ic.icon.extent.y1);
	if (error) {
		LOG(("xwimp_resize_icon: 0x%x: %s",
				error->errnum, error->errmess));
		warn_user("WimpError", error->errmess);
		return;
	}

	state.w = dialog_tooltip;
	error = xwimp_get_window_state(&state);
	if (error) {
		LOG(("xwimp_get_window_state: 0x%x: %s",
				error->errnum, error->errmess));
		warn_user("WimpError", error->errmess);
		return;
	}

	/* update window extent */
	box.x1 = width + 16;
	box.y0 = -36;
	error = xwimp_set_extent(dialog_tooltip, &box);
	if (error) {
		LOG(("xwimp_set_extent: 0x%x: %s",
				error->errnum, error->errmess));
		warn_user("WimpError", error->errmess);
		return;
	}

	/* set visible area */
	state.visible.x0 = pointer->pos.x + 24;
	state.visible.y0 = pointer->pos.y - 22 - 36;
	state.visible.x1 = pointer->pos.x + 24 + width + 16;
	state.visible.y1 = pointer->pos.y - 22;
	state.next = wimp_TOP;
	/* open window */
	error = xwimp_open_window(PTR_WIMP_OPEN(&state));
	if (error) {
		LOG(("xwimp_open_window: 0x%x: %s",
				error->errnum, error->errmess));
		warn_user("WimpError", error->errmess);
		return;
	}
}