static void nsws_localhistory_scroll_check(struct nsws_localhistory *l, struct gui_window *gw) { SCROLLINFO si; if ((gw->bw == NULL) || (l->hwnd == NULL)) return; history_size(gw->bw->history, &(l->width), &(l->height)); si.cbSize = sizeof(si); si.fMask = SIF_ALL; si.nMin = 0; si.nMax = l->height; si.nPage = l->guiheight; si.nPos = 0; SetScrollInfo(l->hwnd, SB_VERT, &si, TRUE); si.nMax = l->width; si.nPage = l->guiwidth; SetScrollInfo(l->hwnd, SB_HORZ, &si, TRUE); if (l->guiheight >= l->height) l->vscroll = 0; if (l->guiwidth >= l->width) l->hscroll = 0; SendMessage(l->hwnd, WM_PAINT, 0, 0); }
void ro_gui_history_open(struct browser_window *bw, struct history *history, bool at_pointer) { int width, height; os_box box = {0, 0, 0, 0}; wimp_window_state state; os_error *error; assert(history); history_current = history; history_bw = bw; history_size(history, &width, &height); width *= 2; height *= 2; /* set extent */ box.x1 = width; box.y0 = -height; error = xwimp_set_extent(history_window, &box); if (error) { LOG(("xwimp_set_extent: 0x%x: %s", error->errnum, error->errmess)); warn_user("WimpError", error->errmess); return; } /* open full size */ 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; } state.visible.x0 = 0; state.visible.y0 = 0; state.visible.x1 = width; state.visible.y1 = height; state.next = wimp_HIDDEN; 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; } ro_gui_dialog_open_persistent(bw->window->window, history_window, at_pointer); }
void ami_history_update_extent(struct history_window *hw) { struct IBox *bbox; int width, height; history_size(hw->bw->history, &width, &height); GetAttr(SPACE_AreaBox,hw->objects[GID_BROWSER],(ULONG *)&bbox); RefreshSetGadgetAttrs((APTR)hw->objects[OID_VSCROLL],hw->win,NULL, GA_ID,OID_VSCROLL, SCROLLER_Total,height, SCROLLER_Visible,bbox->Height, // SCROLLER_Top,0, ICA_TARGET,ICTARGET_IDCMP, TAG_DONE); RefreshSetGadgetAttrs((APTR)hw->objects[OID_HSCROLL],hw->win,NULL, GA_ID,OID_HSCROLL, SCROLLER_Total,width, SCROLLER_Visible,bbox->Width, // SCROLLER_Top,0, ICA_TARGET,ICTARGET_IDCMP, TAG_DONE); }
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; }
LRESULT CALLBACK WndProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { // Build list when first playing a file if ( uMsg == WM_USER && lParam == IPC_PLAYING_FILE ) { OutputDebugString( "IPC_PLAYING_FILE" ); OutputDebugString(( char* )wParam ); if ( !master_built ) { OutputDebugString( "Play: Rebuilding track lists" ); build_master(); copy_master(); master_built = 1; } // Restore playing status if ( is_pause ) { OutputDebugString( "Pausing:" ); SendMessage( hwnd, WM_COMMAND, WINAMP_PAUSE, 0 ); } is_pause = 0; } // Mark the playlist as dirty upon any modification if ( uMsg == WM_USER && lParam == IPC_PLAYLIST_MODIFIED ) { master_built = 0; // Clear the history history_clear(); } if ( uMsg == WM_USER && lParam == IPC_GET_PREVIOUS_PLITEM ) { // If plugin not enabled, let winamp do default action if ( !cfg_enabled ) return -1; // If there is history, return that and rebuild the random list if ( history_size() > 0 ) { // Get playing status status = SendMessage( hwnd, WM_WA_IPC, 0, IPC_ISPLAYING ); // Pretend it is paused if anything but playing. is_pause = ( status != IS_PLAY ); if ( is_pause ) OutputDebugString( "Prev track: Is paused" ); OutputDebugString( "Prev track: Rebuilding track lists" ); copy_master(); return history_pop(); } } if ( uMsg == WM_USER && lParam == IPC_GET_NEXT_PLITEM ) { // Playlist is dirty! Rebuild if ( !master_built ) { OutputDebugString( "Next track: Rebuilding track lists" ); build_master(); copy_master(); master_built = 1; } if( atrack_size() == 0 ) { /* Apparently Winamp crashes anyways if your playlist is all separators * and you can't do anything to stop it. This is stupid. */ OutputDebugString( "Next track: No playable tracks" ); return -1; } index = SendMessage( plugin.hwndParent, WM_WA_IPC, 0, IPC_GETLISTPOS ); // Check for any other plugin that wants to modify the next item // Especially JTFE ft_index = CallWindowProc( lpWndProcOld, hwnd, uMsg, wParam, lParam ); if ( ft_index != -1 ) { wsprintf( debug_string, "Next track: Fall through index: %d", ft_index ); OutputDebugString( debug_string ); if ( cfg_enabled ) { history_add( index ); copy_master(); } return ft_index; } // If plugin is not enabled, let Winamp shuffle if ( !cfg_enabled ) { return -1; } playlist_wnd = get_playlist_hwnd(); pl_len = SendMessage( hwnd, WM_WA_IPC, 0, IPC_GETLISTLENGTH ); file.fileindex = index; // This is zero indexed ret = SendMessage( playlist_wnd, WM_WA_IPC, IPC_PE_GETINDEXTITLE, ( LPARAM ) & file ); // If it returns 0 then track information was received if ( !ret ) { // Check the track type to determine our behavior int type = atrack_type( index ); // Get playing status status = SendMessage( hwnd, WM_WA_IPC, 0, IPC_ISPLAYING ); // Pretend it is paused if anything but playing. Don't include separators because they are always stopped. is_pause = ( status != IS_PLAY && type != IS_ALBUM_SEP && type != IS_RANDOM_SEP ); if ( is_pause ) OutputDebugString( "Next track: Is paused" ); wsprintf( debug_string, "Next track: Track type: %d", type ); OutputDebugString( debug_string ); if ( ( type == IS_ALBUM || type == IS_ALBUM_SEP ) && index < pl_len - 1 ) { /* Track is an album separator or is in an album. Do not shuffle. Return * the next in the playlist */ OutputDebugString( "In an album:" ); wsprintf( debug_string, "Old index: %d", index ); OutputDebugString( debug_string ); if ( type == IS_ALBUM ) history_add( index ); return ( index + 1 ) % pl_len; } else { /* Track is a random separator, the end of an album, the last album separator, * or in a random section. * Select a random track from the remaining list */ is_shuffle = SendMessage( hwnd, WM_WA_IPC, 0, IPC_GET_SHUFFLE ); if ( is_shuffle ) { int rand_i; // Return random number in interval [0 atrack_size()] OutputDebugString( "Next track: Not in an album / exiting an album" ); wsprintf( debug_string, "Next track: Items remaining: %d", atrack_size() ); OutputDebugString( debug_string ); // Select random entry and play the entry rand_i = ( unsigned int )( atrack_size() * genrand_real2() ); next = rm_atrack( rand_i ); wsprintf( debug_string, "Next track: Random selected: %d", next ); OutputDebugString( debug_string ); // If the list of random tracks is empty, copy from the master list if ( atrack_size() == 0 ) { OutputDebugString( "Next track: Track list empty, rebuilding the list" ); copy_master(); } // Don't add separators to the history if ( type == IS_ALBUM_LAST || type == IS_RANDOM ) history_add( index ); return next; } else return -1; } } return -1; } return CallWindowProc( lpWndProcOld, hwnd, uMsg, wParam, lParam ); }
void ami_history_open(struct browser_window *bw, struct history *history) { int width, height; struct IBox *bbox; assert(history); history_current = history; if(!hwindow) { hwindow = AllocVec(sizeof(struct history_window),MEMF_CLEAR | MEMF_PRIVATE); ami_init_layers(&hwindow->gg, scrn->Width, scrn->Height); hwindow->bw = bw; history_size(history, &width, &height); hwindow->scrollerhook.h_Entry = (void *)ami_history_scroller_hook; hwindow->scrollerhook.h_Data = hwindow; hwindow->objects[OID_MAIN] = WindowObject, WA_ScreenTitle,nsscreentitle, WA_Title,messages_get("History"), WA_Activate, TRUE, WA_DepthGadget, TRUE, WA_DragBar, TRUE, WA_CloseGadget, TRUE, WA_SizeGadget, TRUE, WA_CustomScreen,scrn, WA_InnerWidth,width, WA_InnerHeight,height + 10, WINDOW_SharedPort,sport, WINDOW_UserData,hwindow, WINDOW_IconifyGadget, FALSE, WINDOW_GadgetHelp, TRUE, WINDOW_Position, WPOS_CENTERSCREEN, WINDOW_HorizProp,1, WINDOW_VertProp,1, WINDOW_IDCMPHook,&hwindow->scrollerhook, WINDOW_IDCMPHookBits,IDCMP_IDCMPUPDATE, // WA_ReportMouse,TRUE, WA_IDCMP,IDCMP_MOUSEBUTTONS | IDCMP_NEWSIZE, // | IDCMP_MOUSEMOVE, WINDOW_ParentGroup, hwindow->objects[GID_MAIN] = VGroupObject, LAYOUT_AddChild, hwindow->objects[GID_BROWSER] = SpaceObject, GA_ID,GID_BROWSER, // SPACE_MinWidth,width, // SPACE_MinHeight,height, SpaceEnd, EndGroup, EndWindow; hwindow->win = (struct Window *)RA_OpenWindow(hwindow->objects[OID_MAIN]); // hwindow->bw->window = hwindow; hwindow->node = AddObject(window_list,AMINS_HISTORYWINDOW); hwindow->node->objstruct = hwindow; GetAttr(WINDOW_HorizObject,hwindow->objects[OID_MAIN],(ULONG *)&hwindow->objects[OID_HSCROLL]); GetAttr(WINDOW_VertObject,hwindow->objects[OID_MAIN],(ULONG *)&hwindow->objects[OID_VSCROLL]); RefreshSetGadgetAttrs((APTR)hwindow->objects[OID_VSCROLL],hwindow->win,NULL, GA_ID,OID_VSCROLL, SCROLLER_Top,0, ICA_TARGET,ICTARGET_IDCMP, TAG_DONE); RefreshSetGadgetAttrs((APTR)hwindow->objects[OID_HSCROLL],hwindow->win,NULL, GA_ID,OID_HSCROLL, SCROLLER_Top,0, ICA_TARGET,ICTARGET_IDCMP, TAG_DONE); } hwindow->bw = bw; bw->window->hw = hwindow; ami_history_redraw(hwindow); }