diff --git a/Win32/DwmApi.cs b/Win32/DwmApi.cs index cec38324..fcf6eb86 100755 --- a/Win32/DwmApi.cs +++ b/Win32/DwmApi.cs @@ -71,6 +71,8 @@ public sealed class DwmApi [DllImport("dwmapi.dll")] public static extern int DwmRegisterThumbnail(IntPtr dest, IntPtr src, out IntPtr thumb); [DllImport("dwmapi.dll")] + public static extern int DwmQueryThumbnailSourceSize(IntPtr thumb, out SIZE size); + [DllImport("dwmapi.dll")] public static extern int DwmUpdateThumbnailProperties(IntPtr hThumbnail, ref DWM_THUMBNAIL_PROPERTIES props); [DllImport("dwmapi.dll")] public static extern int DwmUnregisterThumbnail(IntPtr hThumbnail); diff --git a/WtProgram/GroupEditor.fs b/WtProgram/GroupEditor.fs index 3b828703..982f52f5 100644 --- a/WtProgram/GroupEditor.fs +++ b/WtProgram/GroupEditor.fs @@ -61,6 +61,13 @@ module GroupEditorMetrics = /// allows and centred in it, so the window is seen as it is rather than cut to the cell's shape /// (filling the cell was tried: a window not of the cell's shape lost its edges). module GroupEditorPicture = + /// The carried title can be much narrower than its preview card. Keep the grab point + /// inside that title at the same relative position, including a bottom-corner press. + let dragOffset (source:Size) (carried:Size) (point:Point) = + let along value extent target = + if extent<=0 || target<=0 then 0 + else min (target-1) (max 0 (int(int64 value*int64 target/int64 extent))) + Point(along point.X source.Width carried.Width,along point.Y source.Height carried.Height) let fit (picture:Rectangle) (source:Sz) = if source.width<=0 || source.height<=0 || picture.Width<=0 || picture.Height<=0 then picture else @@ -138,7 +145,7 @@ type GhostPlace = /// A row growing or folding: the picture as it was, with where its rows, loose row and bottom /// stood, blended towards the picture as it is over a few frames. -type GroupEditorMorph = { from:Bitmap; fromRows:Rectangle list; fromLoose:int; fromHeight:int; start:DateTime } +type GroupEditorMorph = { from:Bitmap; fromRows:Rectangle list; fromPanels:Rectangle list; fromTabs:Map; fromLoose:int; fromHeight:int; start:DateTime } /// Where the picture's parts are, in the popup's own coordinates before scrolling. type GroupEditorLayout = { @@ -196,13 +203,19 @@ type GroupEditorDragImage(owner:Form) = /// `front` is the frame of the window in front as it opens: the popup opens centred on that /// window's screen. -type GroupEditorForm(draft:DesktopDraft, rows:GroupEditorRow list, windows:GroupEditorWindow list, expanded:int option, ?front:Rect) = +type GroupEditorForm(draft:DesktopDraft, rows:GroupEditorRow list, windows:GroupEditorWindow list, expanded:int option, ?front:Rect, ?previews:bool) = let palette = SettingsColors.current() let highContrast = SystemInformation.HighContrast let scale = Dpi.scale let bodyFont = SettingsUi.bodyFont() let hintFont = SettingsUi.font (SettingsUi.smallFamily()) 9.0f FontStyle.Regular let before = draft + let mutable previews = defaultArg previews (SettingsCatalog.toggleDefault "groupEditorPreviews" false) + let mutable pendingPreviews : bool option = None + let previewChanged = Event() + let previewThumbs = new GroupEditorPreviews() + let dragScrollTimer = new Timer(Interval=30) + let mutable pointer = Point.Empty let mutable current = draft /// The group of the row expanded, by its strip, or by its first tab for a group made here. let mutable expandedKey : (IntPtr option * IntPtr) option = @@ -274,6 +287,10 @@ type GroupEditorForm(draft:DesktopDraft, rows:GroupEditorRow list, windows:Group let t = min 1.0 ((DateTime.UtcNow-m.start).TotalMilliseconds/GroupEditorMetrics.morphMs) 1.0-(1.0-t)*(1.0-t)*(1.0-t)) |> Option.defaultValue 1.0 let morphLerp (t:float) (a:int) (b:int) = a+int(Math.Round(float(b-a)*t)) + let morphRect t (a:Rectangle) (b:Rectangle) = + Rectangle(morphLerp t a.X b.X,morphLerp t a.Y b.Y,morphLerp t a.Width b.Width,morphLerp t a.Height b.Height) + let animatedTab hwnd rect = + morph |> Option.bind(fun m -> m.fromTabs.TryFind hwnd) |> Option.map(fun before -> morphRect (morphT()) before rect) |> Option.defaultValue rect let endMorph() = morphTimer.Stop() morph |> Option.iter(fun m -> m.from.Dispose()) @@ -289,6 +306,7 @@ type GroupEditorForm(draft:DesktopDraft, rows:GroupEditorRow list, windows:Group /// The screen the popup opens on: the one with the window in front, or the first row's. let area = Screen.FromRectangle((defaultArg front fallbackFrame).Rectangle).WorkingArea let pad = scale GroupEditorMetrics.padding + let headerHeight = scale 44 /// The popup's width and height follow its window: as it opens, what the rows need within /// the screen; sized by the user, maximized or not, whatever they made it. let mutable width = min (scale GroupEditorMetrics.width) (area.Width-scale 32) @@ -397,10 +415,11 @@ type GroupEditorForm(draft:DesktopDraft, rows:GroupEditorRow list, windows:Group let gapBetween (inPane:IntPtr -> bool) a b = if inPane a && inPane b then scale GroupEditorMetrics.paneGap else scale GroupEditorMetrics.tabGap /// Tabs wrapped into lines within the width, from the top left. let wrapTabs (inPane:IntPtr -> bool) (order:IntPtr list) (left:int) (top:int) (width:int) = - let lineGap,tabHeight = scale GroupEditorMetrics.wrapGap,scale GroupEditorMetrics.tabHeight + let lineGap = scale GroupEditorMetrics.wrapGap + let tabHeight = scale (GroupEditorMetrics.tabHeight + if previews then GroupEditorPreview.height else 0) let placed,(_,y,_) = order |> List.mapFold(fun (x,y,prev) hwnd -> - let w = min width (tabWidth hwnd) + let w = min width (if previews then scale GroupEditorPreview.width else tabWidth hwnd) let x = match prev with Some p -> x+gapBetween inPane p hwnd | None -> x let x,y = if x>left && x+w>left+width then left,y+tabHeight+lineGap else x,y (hwnd,Rectangle(x,y,w,tabHeight)),(x+w,y,Some hwnd)) (left,top,None) @@ -456,11 +475,17 @@ type GroupEditorForm(draft:DesktopDraft, rows:GroupEditorRow list, windows:Group let noteHeight() = min (2*hintFont.Height) (TextRenderer.MeasureText(noteText(),hintFont,Size(noteWidth(),Int32.MaxValue),noteFlags).Height) + let panelBand (row:GroupEditorRowLayout) = + if previews && row.expanded then Rectangle.Inflate(row.picture,rowPad,rowPad) else Rectangle.Empty + + let rowBounds (row:GroupEditorRowLayout) = + if previews && row.expanded then Rectangle.Union(row.band,panelBand row) else row.band + /// The layout for the width, the expanded row's content as tall as its frame's shape asks /// within its bounds, the upper one raised by the room the window leaves under the rows. let computeLayout (room:int) : GroupEditorLayout = let expandedIndex = expandedRow() - let mutable y = pad + let mutable y = headerHeight+pad/2 // The ghost holds the place the tab in hand came from among the tabs there. let ghost = ghostPlace() let ghostHwnd = drag |> Option.map(fun d -> d.hwnd) |> Option.defaultValue IntPtr.Zero @@ -481,19 +506,51 @@ type GroupEditorForm(draft:DesktopDraft, rows:GroupEditorRow list, windows:Group for _,h,_ in vacated |> List.filter(fun (p,_,_) -> p=index) do vacatedRects.Add(Rectangle(pad,y,inner,h)) y <- y+h+scale GroupEditorMetrics.rowGap - let rowLayouts = + let gap = scale GroupEditorMetrics.rowGap + let halfWidth = (inner-gap)/2 + let measured = groups() |> List.mapi(fun index g -> + let order = rowTabs index g + let naturalWidth = + order.Length*scale GroupEditorPreview.width+2*rowPad+ + (order |> List.pairwise |> List.sumBy(fun (a,b) -> gapBetween (paneOf g) a b)) + index,g,previews && naturalWidth<=halfWidth) + let mutable halfPending = false + let mutable lineBottom = y + let finishLine() = + if halfPending then + y <- lineBottom+gap + halfPending <- false + let rowLayouts = + measured |> List.map(fun (index,g,fitsHalf) -> + if vacated |> List.exists(fun (p,_,_) -> p=index) then finishLine() placeholders index + let order = rowTabs index g + let small = fitsHalf + if not small then finishLine() let top = y + let left = if small && halfPending then pad+halfWidth+gap else pad + let bandWidth = if small then halfWidth else inner + let advance bottom = + if small && not halfPending then + halfPending <- true + lineBottom <- bottom + elif small then + lineBottom <- max lineBottom bottom + finishLine() + else y <- bottom+gap let info = infoOf index if expandedIndex=Some index then let stripTop = top+rowPad - let tabs = stripTabs (paneOf g) (rowTabs index g) (pad+rowPad) (stripTop+scale GroupEditorMetrics.stripHeight-scale GroupEditorMetrics.tabHeight) (inner-2*rowPad) - let contentWidth = inner-2*rowPad + let tabs,stripBottom = + if previews then wrapTabs (paneOf g) (rowTabs index g) (left+rowPad) stripTop (bandWidth-2*rowPad) + else stripTabs (paneOf g) (rowTabs index g) (left+rowPad) stripTop (bandWidth-2*rowPad),stripTop+scale GroupEditorMetrics.stripHeight + let contentWidth = (if previews then inner else bandWidth)-2*rowPad let contentHeight = let byFrame = if info.frame.width>0 then int(int64 contentWidth*int64 info.frame.height/int64 info.frame.width) else contentWidth*9/16 max (scale GroupEditorMetrics.contentMin) (min (scale GroupEditorMetrics.contentMax+room) byFrame) - let content = Rectangle(pad+rowPad,stripTop+scale GroupEditorMetrics.stripHeight,contentWidth,contentHeight) + let contentTop = if previews then stripBottom+2*rowPad+gap else stripBottom + let content = Rectangle((if previews then pad else left)+rowPad,contentTop,contentWidth,contentHeight) let cells,ownCell = cellsOf g selected content (scale GroupEditorMetrics.cellGap) let focused = match cellFocus with @@ -512,16 +569,18 @@ type GroupEditorForm(draft:DesktopDraft, rows:GroupEditorRow list, windows:Group let panelTop = button.Y-scale 8-fpad*2-h GroupDraft.shapes |> List.mapi(fun i shape -> shape,Rectangle(left+fpad+i*(w+fgap),panelTop+fpad,w,h)) | _ -> [] - y <- content.Bottom+rowPad+scale GroupEditorMetrics.rowGap - {index=index; band=Rectangle(pad,top,inner,content.Bottom+rowPad-top); expanded=true; tabs=tabs; picture=content; cells=cells + advance (content.Bottom+rowPad) + {index=index; band=Rectangle(left,top,bandWidth,(if previews then stripBottom+rowPad else content.Bottom+rowPad)-top); expanded=true; tabs=tabs; picture=content; cells=cells focused=focused; splitButton=splitButton; shapes=shapes} else - // Folded: the tabs alone. - let tabs,tabsBottom = wrapTabs (paneOf g) (rowTabs index g) (pad+rowPad) (top+rowPad) (inner-2*rowPad) + // Adjacent small groups share a line without changing their order. + let tabs,tabsBottom = wrapTabs (paneOf g) order (left+rowPad) (top+rowPad) (bandWidth-2*rowPad) let bottom = max tabsBottom (top+rowPad+scale GroupEditorMetrics.tabHeight)+rowPad - y <- bottom+scale GroupEditorMetrics.rowGap - {index=index; band=Rectangle(pad,top,inner,bottom-top); expanded=false; tabs=tabs; picture=Rectangle.Empty; cells=[] + advance bottom + {index=index; band=Rectangle(left,top,bandWidth,bottom-top); expanded=false; tabs=tabs; picture=Rectangle.Empty; cells=[] focused=None; splitButton=None; shapes=[]}) + |> List.sortBy(fun row -> row.index) + finishLine() placeholders (groups()).Length let looseTop = y let looseTabs,looseBottom = wrapTabs (fun _ -> false) looseNow (pad+rowPad) (looseTop+rowPad) (inner-3*rowPad-scale GroupEditorMetrics.labelWidth) @@ -601,7 +660,7 @@ type GroupEditorForm(draft:DesktopDraft, rows:GroupEditorRow list, windows:Group /// content, a cell's edge, the whole content's edge or a cell's middle; the loose row; the /// new group's band. let aimAt (l:GroupEditorLayout) (pt:Point) (dragged:IntPtr) = - let inRow = l.rows |> List.tryFind(fun row -> row.band.Contains pt) + let inRow = l.rows |> List.tryFind(fun row -> (row.band.Contains pt || row.picture.Contains pt)) match inRow with | Some row when row.expanded -> if pt.YtitleHeight then + let picture = Rectangle(r.X+scale 2,r.Y+titleHeight,r.Width-scale 4,r.Height-titleHeight-scale 2) + use back = new SolidBrush(contentFill) + g.FillRectangle(back,picture) + let side = min (scale 32) (min picture.Width picture.Height) + if side>0 then drawIconOn g (iconOf hwnd) (Rectangle(picture.X+(picture.Width-side)/2,picture.Y+(picture.Height-side)/2,side,side)) let iconSize = scale GroupEditorMetrics.iconSize - let iconBounds = Rectangle(r.X+scale 8,r.Y+(r.Height-iconSize)/2,iconSize,iconSize) + let iconBounds = Rectangle(r.X+scale 8,r.Y+(titleHeight-iconSize)/2,iconSize,iconSize) drawIconOn g (iconOf hwnd) iconBounds let trailing = if look.seamAfter then scale 8 else 0 // The measured name runs a little past its glyphs, so the room kept after it is less // than the room before the icon, and the two look alike. - let textBounds = Rectangle(iconBounds.Right+scale 6,r.Y,max 0 (r.Right-scale 5-trailing-iconBounds.Right-scale 6),r.Height) + let textBounds = Rectangle(iconBounds.Right+scale 6,r.Y,max 0 (r.Right-scale 5-trailing-iconBounds.Right-scale 6),titleHeight) TextRenderer.DrawText(g,nameOf hwnd,bodyFont,textBounds,textOn,fill,textFlags ||| TextFormatFlags.PreserveGraphicsTranslateTransform ||| TextFormatFlags.PreserveGraphicsClipping) if look.ghost then use veil = new SolidBrush(Color.FromArgb(170,look.band)) @@ -788,7 +854,7 @@ type GroupEditorForm(draft:DesktopDraft, rows:GroupEditorRow list, windows:Group for (a,ra),(b,rb) in List.pairwise row.tabs do match GroupDraft.partingAxis a b group with | Some axis when ra.Y=rb.Y && rb.X>=ra.Right && still (a,ra) && still (b,rb) -> - let h = max (scale 11) (ra.Height*38/100) + let h = max (scale 11) (min ra.Height (scale GroupEditorMetrics.tabHeight)*38/100) let size = Sz(h*3/2,h) let fill = looks |> List.tryFind(fun (each,look) -> each=a && look.rect=ra) |> Option.map(fun (_,look) -> if look.selected then contentFill else tabFill) |> Option.defaultValue tabFill let sprite = {owner=box b; axis=axis; size=size; fill=fill; ink=textOn; hover=false} : SplitJunctionSprite @@ -867,6 +933,9 @@ type GroupEditorForm(draft:DesktopDraft, rows:GroupEditorRow list, windows:Group use band = rounded row.band (scale 8) use fill = new SolidBrush(rowFill) g.FillPath(fill,band) + if previews && row.expanded then + use panel = rounded (panelBand row) (scale 8) + g.FillPath(fill,panel) if row.expanded then use shape = rounded row.picture (scale 6) use fill = new SolidBrush(if highContrast then SystemColors.Control else palette.background) @@ -988,7 +1057,7 @@ type GroupEditorForm(draft:DesktopDraft, rows:GroupEditorRow list, windows:Group match List.tryItem slot others,List.tryItem (slot-1) others with | Some(_,r),_ -> r.X-scale GroupEditorMetrics.tabGap/2,r.Y,r.Height | None,Some(_,r) -> r.Right+scale GroupEditorMetrics.tabGap/2,r.Y,r.Height - | None,None -> pad+rowPad,row.band.Y+rowPad,scale GroupEditorMetrics.tabHeight + | None,None -> row.band.X+rowPad,row.band.Y+rowPad,scale GroupEditorMetrics.tabHeight use pen = new Pen(accent,float32(scale 3)) g.DrawLine(pen,x,y,x,y+h)) | Some(CellMiddle _ | CellEdge _ as aim) -> @@ -1058,8 +1127,9 @@ type GroupEditorForm(draft:DesktopDraft, rows:GroupEditorRow list, windows:Group if l.body<=track || track<=0 then None else let bar = scale GroupEditorMetrics.scrollbar - let h = max (scale 24) (int(int64 track*int64 track/int64 l.body)) - let y = int(int64 (track-h)*int64 scroll/int64 (l.body-track)) + let available = max 1 (track-headerHeight) + let h = min available (max (scale 24) (int(int64 available*int64 available/int64 (max 1 (l.body-headerHeight))))) + let y = headerHeight+int(int64 (available-h)*int64 scroll/int64 (l.body-track)) Some(Rectangle(width-bar-scale 2,y,bar,h)) /// Where the rows scroll: a row cut at the top or the bottom fades into the surface rather /// than ending at a hard edge, and the thumb shows how far down the rows are. @@ -1068,17 +1138,14 @@ type GroupEditorForm(draft:DesktopDraft, rows:GroupEditorRow list, windows:Group let fade = scale GroupEditorMetrics.fade let clear = Color.FromArgb(0,surface) if scroll>0 then - let r = Rectangle(0,0,width,fade) + let r = Rectangle(0,headerHeight,width,fade) use brush = new Drawing2D.LinearGradientBrush(r,surface,clear,Drawing2D.LinearGradientMode.Vertical) g.FillRectangle(brush,r) if scroll + let t = morphT() + let body = clientHeight-(l.height-l.body) + use back = new SolidBrush(surface) + g.FillRectangle(back,Rectangle(0,0,width,body)) + g.SetClip(Rectangle(0,headerHeight,width,max 0 (body-headerHeight))) + g.TranslateTransform(0.0f,float32 -scroll) + List.iter2 (fun before (row:GroupEditorRowLayout) -> + use shape = rounded (morphRect t before row.band) (scale 8) + use fill = new SolidBrush(rowFill) + g.FillPath(fill,shape)) m.fromRows l.rows + List.iter2 (fun (before:Rectangle) row -> + let after = panelBand row + if not before.IsEmpty || not after.IsEmpty then + let source,rect = if after.IsEmpty then m.from,before else bitmap,after + let h = morphLerp t before.Height after.Height + if h>0 then + let area = Rectangle(rect.X,rect.Y,rect.Width,min h rect.Height) + g.DrawImage(source,area,area,GraphicsUnit.Pixel)) m.fromPanels l.rows + for hwnd,look in tabLooks l |> List.filter(fun (_,look) -> look.rect.Y // Each row at its height on the way, cut from whichever picture has // it at the larger, the loose row and the bottom along with them. @@ -1199,6 +1292,25 @@ type GroupEditorForm(draft:DesktopDraft, rows:GroupEditorRow list, windows:Group f.BackColor <- surface f + let previewSwitch = new SettingsToggle(Checked=previews, + BackColor=surface,ForeColor=textOn,Font=bodyFont, + AccessibleName=tr Strings.GroupEditor.previews, + AccessibleDescription=tr Strings.GroupEditor.previewSetting.description) + let previewHeader = new Panel(Dock=DockStyle.Top,Height=headerHeight,BackColor=surface) + let previewLabel = new Label(Text=tr Strings.GroupEditor.previews,AutoSize=true,Font=bodyFont,ForeColor=textOn,BackColor=surface) + // Share the settings scrollbar's hover animation, hit area and keyboard navigation. + let scrollBar = new SettingsScrollBar(BackColor=surface,Visible=false) + let positionPreviewSwitch() = + previewSwitch.Location <- Point(width-pad-previewSwitch.Width,(headerHeight-previewSwitch.Height)/2) + previewLabel.Location <- Point(previewSwitch.Left-scale 10-previewLabel.PreferredWidth,(headerHeight-previewLabel.PreferredHeight)/2) + do + previewHeader.Controls.Add previewLabel + previewHeader.Controls.Add previewSwitch + form.Controls.Add previewHeader + form.Controls.Add scrollBar + previewLabel.Click.Add(fun _ -> previewSwitch.Checked <- not previewSwitch.Checked) + positionPreviewSwitch() + /// The popup's bounds: centred on its screen at first, as tall as the overview or any one /// row expanded needs; moved by the user, it stays where it was put and keeps its height; /// sized by the user, it keeps the size they gave it. @@ -1270,6 +1382,7 @@ type GroupEditorForm(draft:DesktopDraft, rows:GroupEditorRow list, windows:Group window.Show(image,form.PointToScreen(Point(view.X-d.offset.X-offset.x,view.Y-d.offset.Y-offset.y))) let releaseThumbnails() = + previewThumbs.Clear() for KeyValue(_,thumb) in thumbs do DwmApi.DwmUnregisterThumbnail(thumb) |> ignore for KeyValue(_,thumb) in corners do DwmApi.DwmUnregisterThumbnail(thumb) |> ignore thumbs.Clear() @@ -1280,8 +1393,21 @@ type GroupEditorForm(draft:DesktopDraft, rows:GroupEditorRow list, windows:Group /// cell's edge, the picture keeps to the half the cell would keep, so the zone shows beside /// it; aimed at its middle, which takes the pane, it is hidden, as it is while the flyout is up. let updateThumbnails (l:GroupEditorLayout) = + let viewport = max 1 (viewBody l-headerHeight) + scrollBar.Bounds <- Rectangle(width-scale 14,headerHeight,scale 14,viewport) + scrollBar.configure(max 0 (l.body-viewBody l),viewport,scroll) if form.IsHandleCreated && form.Visible then - let view = Rectangle(0,0,width,(if morph.IsSome then form.ClientSize.Height-(l.height-l.body) else viewBody l)) + let viewBottom = if morph.IsSome then form.ClientSize.Height-(l.height-l.body) else viewBody l + let view = Rectangle(0,headerHeight,width,max 0 (viewBottom-headerHeight)) + let cards = + if not previews || flyout || (rowDrag |> Option.exists(fun d -> d.begun)) then [] + else + tabLooks l |> List.choose(fun (hwnd,look) -> + if look.blank || look.ghost || sliding.ContainsKey hwnd then None + else + let r = animatedTab hwnd look.rect + Some(hwnd,Rectangle(r.X+scale 2,r.Y+scale GroupEditorMetrics.tabHeight-scroll,r.Width-scale 4,r.Height-scale GroupEditorMetrics.tabHeight-scale 2))) + previewThumbs.Update(form.Handle,true,view,cards) let other side = if side=First then Second else First /// None: the whole picture; Some None: hidden; Some(Some r): the part of the cell kept. let kept index path (r:Rectangle) = @@ -1311,10 +1437,13 @@ type GroupEditorForm(draft:DesktopDraft, rows:GroupEditorRow list, windows:Group // While its row grows or folds, the picture follows the row and is cut at its edge. let t = morphT() let placed index = - morph |> Option.bind(fun m -> List.tryItem index m.fromRows) |> Option.map(fun a -> - let b = l.rows.[index].band - let y,h = morphLerp t a.Y b.Y,morphLerp t a.Height b.Height - y-b.Y,Rectangle(0,y-scroll,width,h)) + morph |> Option.bind(fun m -> + List.tryItem index m.fromRows |> Option.map(fun band -> + let panel = m.fromPanels.[index] + if panel.IsEmpty then band else Rectangle.Union(band,panel))) |> Option.map(fun a -> + let b = rowBounds l.rows.[index] + let rect = morphRect t a b + rect.Y-b.Y,Rectangle(rect.X,rect.Y-scroll,rect.Width,rect.Height)) for hwnd,r,index,kept,corner in wanted do let hidden = kept=Some None let thumbIn (table:Dictionary) = @@ -1362,6 +1491,15 @@ type GroupEditorForm(draft:DesktopDraft, rows:GroupEditorRow list, windows:Group thumbIn corners |> Option.iter(fun piece -> show piece beside) | None -> show thumb shown) + do scrollBar.changed.Add(fun value -> + if not closed then + hideTitle() + scrollTimer.Stop() + scrollTarget <- None + scroll <- value + updateThumbnails (layout()) + form.Invalidate()) + let refresh() = if not closed then // The tabs may move under a resting pointer: the title shown is put away. @@ -1374,6 +1512,7 @@ type GroupEditorForm(draft:DesktopDraft, rows:GroupEditorRow list, windows:Group if form.Text<>title then form.Text <- title if form.IsHandleCreated then place (layout()) let l = layout() + positionPreviewSwitch() clampScroll l updateThumbnails l let previous = bitmap @@ -1381,6 +1520,27 @@ type GroupEditorForm(draft:DesktopDraft, rows:GroupEditorRow list, windows:Group if not (isNull previous) then previous.Dispose() if form.IsHandleCreated then form.Invalidate() + let setPreviews value = + if not closed && (drag.IsSome || rowDrag.IsSome) then + if previewSwitch.Checked<>previews then previewSwitch.Checked <- previews + pendingPreviews <- Some value + elif not closed && previews<>value then + pendingPreviews <- None + let old = layout() + let anchor = tabLooks old |> List.tryFind(fun (_,look) -> look.rect.Bottom>scroll) + endMorph() + sliding <- Map.empty + slideTimer.Stop() + previews <- value + layoutKey <- None + previewSwitch.Checked <- value + anchor |> Option.iter(fun (hwnd,look) -> + tabLooks (layout()) |> List.tryFind(fun (h,_) -> h=hwnd) |> Option.iter(fun (_,next) -> + scroll <- max 0 (next.rect.Y-(look.rect.Y-scroll)))) + refresh() + previewChanged.Trigger value + do previewSwitch.CheckedChanged.Add(fun _ -> setPreviews previewSwitch.Checked) + /// A point of the popup as the picture has it: the rows scrolled, the footer in place. let unscroll (pt:Point) = let l = layout() @@ -1421,6 +1581,8 @@ type GroupEditorForm(draft:DesktopDraft, rows:GroupEditorRow list, windows:Group // Not inside its own event: on the next turn of the loop. let dispose() = form.Dispose() + dragScrollTimer.Dispose() + (previewThumbs :> IDisposable).Dispose() titleTimer.Dispose() titleTip |> Option.iter(fun tip -> tip.Dispose()) titleTip <- None @@ -1534,8 +1696,8 @@ type GroupEditorForm(draft:DesktopDraft, rows:GroupEditorRow list, windows:Group let showRow (i:int) = let l = layout() l.rows |> List.tryItem i |> Option.iter(fun row -> - let top = pad - if row.band.Y-scrollviewBody l then + let top = headerHeight+pad/2 + if row.band.Y-scrollviewBody l then scrollTarget <- None scroll <- row.band.Y-top clampScroll l @@ -1564,9 +1726,12 @@ type GroupEditorForm(draft:DesktopDraft, rows:GroupEditorRow list, windows:Group /// The rows slid from where the picture had them to where it has them now, over a few frames. let startMorph (fromL:GroupEditorLayout) (from:Bitmap) = let l = layout() - if isNull from || fromL.rows.Length<>l.rows.Length || not form.Visible then (if not (isNull from) then from.Dispose()) + if not SystemInformation.UIEffectsEnabled || isNull from || fromL.rows.Length<>l.rows.Length || not form.Visible then (if not (isNull from) then from.Dispose()) else - morph <- Some {from=from; fromRows=fromL.rows |> List.map(fun row -> row.band); fromLoose=fromL.loose.Y; fromHeight=fromL.height; start=DateTime.UtcNow} + morph <- Some {from=from; fromRows=fromL.rows |> List.map(fun row -> row.band); + fromPanels=fromL.rows |> List.map panelBand; + fromTabs=Map.ofList ((fromL.rows |> List.collect(fun row -> row.tabs))@fromL.looseTabs@fromL.closingTabs); + fromLoose=fromL.loose.Y; fromHeight=fromL.height; start=DateTime.UtcNow} morphTimer.Start() morphFrame() @@ -1579,7 +1744,7 @@ type GroupEditorForm(draft:DesktopDraft, rows:GroupEditorRow list, windows:Group | Some i when i<(groups()).Length -> let g = (groupAt i).Value expandedKey <- Some(g.group,List.head g.tabs) - selected <- (infoOf i).active + if not(List.contains selected g.tabs) then selected <- (infoOf i).active | _ -> expandedKey <- None selected <- IntPtr.Zero @@ -1667,6 +1832,10 @@ type GroupEditorForm(draft:DesktopDraft, rows:GroupEditorRow list, windows:Group elif flyout then (flyout <- false; refresh()) elif (expandedRow()).IsSome then expand None else cancel() + if drag.IsNone && rowDrag.IsNone then + match pendingPreviews with + | Some value -> pendingPreviews <- None; setPreviews value + | None -> () let showTitle() = titleTimer.Stop() @@ -1706,7 +1875,8 @@ type GroupEditorForm(draft:DesktopDraft, rows:GroupEditorRow list, windows:Group batch <- if marked.IsEmpty && not modifiedPress then [hwnd] else marked refresh() if not modifiedPress || selection.contains hwnd then - drag <- Some {hwnd=hwnd; start=pt; at=pt; aim=None; fits=true; begun=false; offset=Point(pt.X-r.X,pt.Y-r.Y) + let offset = GroupEditorPicture.dragOffset r.Size (Size(tabWidth hwnd,scale GroupEditorMetrics.tabHeight)) (Point(pt.X-r.X,pt.Y-r.Y)) + drag <- Some {hwnd=hwnd; start=pt; at=pt; aim=None; fits=true; begun=false; offset=offset origin=current; originSelected=selected} let hitTab = (l.rows |> List.collect(fun row -> row.tabs)) @ l.looseTabs @ l.closingTabs if not(hitTab |> List.exists(fun (_,r) -> r.Contains pt)) && not((selection.items (ordered())).IsEmpty) then @@ -1732,7 +1902,7 @@ type GroupEditorForm(draft:DesktopDraft, rows:GroupEditorRow list, windows:Group elif l.save.Contains pt then save() elif l.cancel.Contains pt then cancel() else - match l.rows |> List.tryFind(fun row -> row.band.Contains pt) with + match l.rows |> List.tryFind(fun row -> (row.band.Contains pt || row.picture.Contains pt)) with | Some row -> if row.splitButton |> Option.exists(fun r -> r.Contains pt) then flyout <- true @@ -1769,7 +1939,7 @@ type GroupEditorForm(draft:DesktopDraft, rows:GroupEditorRow list, windows:Group /// footer or out of the popup, where a tab in hand is aimed at nothing. let offRows (l:GroupEditorLayout) (view:Point) (pt:Point) = ignore pt - view.X<0 || view.X>=width || view.Y<0 || view.Y>=viewBody l + view.X<0 || view.X>=width || view.Y=viewBody l /// The thumb in hand: the rows follow the pointer along the track. let thumbMove (view:Point) (fromY:int) (fromScroll:int) = @@ -1778,7 +1948,7 @@ type GroupEditorForm(draft:DesktopDraft, rows:GroupEditorRow list, windows:Group let thumbHeight = scrollThumb l track |> Option.map(fun r -> r.Height) |> Option.defaultValue track if track>thumbHeight then scrollTarget <- None - scroll <- fromScroll+int(int64 (view.Y-fromY)*int64 (l.body-track)/int64 (track-thumbHeight)) + scroll <- fromScroll+int(int64 (view.Y-fromY)*int64 (l.body-track)/int64 (max 1 (track-headerHeight-thumbHeight))) clampScroll l updateThumbnails l if form.IsHandleCreated then form.Invalidate() @@ -1789,11 +1959,12 @@ type GroupEditorForm(draft:DesktopDraft, rows:GroupEditorRow list, windows:Group if begun then let l = layout() let aim = - match l.rows |> List.tryFind(fun row -> row.band.Contains pt) with + match l.rows |> List.tryFind(fun row -> (row.band.Contains pt || row.picture.Contains pt)) with | Some row when row.index<>d.index -> Some(IntoRow row.index) | Some _ -> None | None -> if l.closing.Contains pt then Some CloseAll else None rowDrag <- Some {d with at=pt; aim=aim; begun=true} + updateThumbnails l if form.IsHandleCreated then form.Invalidate() let batchAim l view pt hwnd = @@ -1811,7 +1982,24 @@ type GroupEditorForm(draft:DesktopDraft, rows:GroupEditorRow list, windows:Group | Some d -> let threshold = SystemInformation.DragSize let begun = d.begun || abs(pt.X-d.start.X)>threshold.Width/2 || abs(pt.Y-d.start.Y)>threshold.Height/2 - if begun && batch.Length>1 then + if begun && previews then + // Keep every target in place until release, including a group about to grow + // from half a line to a full line or a source about to disappear. + let l = layout() + let aim,fits = + if batch.Length>1 then batchAim l view pt d.hwnd,true + elif offRows l view pt then None,true + else + match aimAt l pt d.hwnd with + | Some aim -> + match dropped d.hwnd aim current with + | Some(next,Some at) -> Some aim,fitsIn at next.groups.[at] + | Some(_,None) -> Some aim,true + | None -> None,true + | None -> None,true + drag <- Some {d with at=pt; aim=aim; fits=fits; begun=true} + if not d.begun || aim<>d.aim || fits<>d.fits then refresh() + elif begun && batch.Length>1 then let l = layout() let aim = batchAim l view pt d.hwnd drag <- Some {d with at=pt; begun=true; aim=aim} @@ -1928,11 +2116,15 @@ type GroupEditorForm(draft:DesktopDraft, rows:GroupEditorRow list, windows:Group let mouseMove (pt:Point) = if not closed then + pointer <- pt match scrollDrag with | Some(fromY,fromScroll) -> thumbMove pt fromY fromScroll - | None -> dragMove pt (unscroll pt) + | None -> + dragMove pt (unscroll pt) + if drag.IsSome || rowDrag.IsSome then dragScrollTimer.Start() let tabUp (view:Point) (pt:Point) = + let mutable expansion : int option option = None match drag with | Some d -> let before = tabsNow() @@ -1974,23 +2166,24 @@ type GroupEditorForm(draft:DesktopDraft, rows:GroupEditorRow list, windows:Group // is selected, or, selected already, folds the row. match DesktopDraft.find d.hwnd current,expandedRow() with | InGroup index,Some row when index=row -> - if selected=d.hwnd then expand None + if selected=d.hwnd then expansion <- Some None else selected <- d.hwnd cellFocus <- None | InGroup index,_ -> - expand (Some index) selected <- d.hwnd - refresh() + expansion <- Some(Some index) | _ -> () if d.begun then selection.clear() vacated <- [] slide before refresh() + expansion |> Option.iter expand | None -> () let mouseUp (pt:Point) = if not closed then + dragScrollTimer.Stop() scrollDrag <- None hideDragImage() let view = pt @@ -2007,6 +2200,9 @@ type GroupEditorForm(draft:DesktopDraft, rows:GroupEditorRow list, windows:Group batch <- [] modifiedPress <- false completeClick <- ignore + match pendingPreviews with + | Some value -> pendingPreviews <- None; setPreviews value + | None -> () /// A right click on a tab of a group: a menu to take the window out of it; on a row's empty /// room, the row's menu. @@ -2020,7 +2216,7 @@ type GroupEditorForm(draft:DesktopDraft, rows:GroupEditorRow list, windows:Group showMenu (tabMenuItems hwnd) view | Some _ -> () | None -> - l.rows |> List.tryFind(fun row -> row.band.Contains pt && not(row.expanded && row.picture.Contains pt)) + l.rows |> List.tryFind(fun row -> (row.band.Contains pt || row.picture.Contains pt) && not(row.expanded && row.picture.Contains pt)) |> Option.iter(fun row -> rowMenu row.index view) /// A button pressed, then released, at a point of the popup. The left click that closed a @@ -2078,6 +2274,29 @@ type GroupEditorForm(draft:DesktopDraft, rows:GroupEditorRow list, windows:Group if hovered.IsSome || hoveredCell.IsSome || hoveredButton.IsSome || hoveredAction.IsSome then hovered <- None; hoveredCell <- None; hoveredButton <- None; hoveredAction <- None; form.Invalidate()) titleTimer.Tick.Add(fun _ -> showTitle()) + dragScrollTimer.Tick.Add(fun _ -> + if closed || not ((drag |> Option.exists(fun d -> d.begun)) || (rowDrag |> Option.exists(fun d -> d.begun))) then + dragScrollTimer.Stop() + if drag.IsNone && rowDrag.IsNone then + match pendingPreviews with + | Some value -> pendingPreviews <- None; setPreviews value + | None -> () + else + let l = layout() + let body = viewBody l + let step = + if pointer.X<0 || pointer.X>=width || pointer.Y=body then 0 + elif pointer.Ybody-scale 24 then scale 12 + else 0 + if step<>0 then + let was = scroll + scroll <- scroll+step + clampScroll l + if scroll<>was then + dragMove pointer (unscroll pointer) + updateThumbnails (layout()) + form.Invalidate()) // The frames of a slide; the last one leaves the tabs in place until the next picture. scrollTimer.Tick.Add(fun _ -> if closed then scrollTimer.Stop() else scrollFrame()) slideTimer.Tick.Add(fun _ -> @@ -2098,6 +2317,10 @@ type GroupEditorForm(draft:DesktopDraft, rows:GroupEditorRow list, windows:Group member _.Handle = form.Handle /// The draft as edited so far. member _.Draft = current + member _.Previews = previews + member _.SetPreviews(value) = setPreviews value + member _.PreviewChanged = previewChanged.Publish + member _.PreviewCount = previewThumbs.Count member _.Selected = selected member _.MarkedTabs = selection.items (ordered()) /// The row expanded, if one is. @@ -2122,6 +2345,8 @@ type GroupEditorForm(draft:DesktopDraft, rows:GroupEditorRow list, windows:Group scrollTarget <- None scroll <- y clampScroll (layout()) + updateThumbnails (layout()) + if form.IsHandleCreated then form.Invalidate() /// The window sized, as by the user. member _.Resize(size:Size) = resized size /// A key pressed in the popup, as pressing it would. diff --git a/WtProgram/GroupEditorPreview.fs b/WtProgram/GroupEditorPreview.fs new file mode 100644 index 00000000..397d0356 --- /dev/null +++ b/WtProgram/GroupEditorPreview.fs @@ -0,0 +1,65 @@ +namespace Bemo +open System +open System.Collections.Generic +open System.Drawing +open System.Windows.Forms + +module GroupEditorPreview = + let height = 96 + let width = 180 + /// Clip the destination and source together so scrolling never stretches the picture. + let projection crop (source:Size) (target:Rectangle) (viewport:Rectangle) = + if source.Width<=0 || source.Height<=0 || target.Width<=0 || target.Height<=0 then None + else + let factor = if crop then float target.Width/float source.Width else min (float target.Width/float source.Width) (float target.Height/float source.Height) + let w,h = max 1 (int(float source.Width*factor)),max 1 (int(float source.Height*factor)) + let dest = Rectangle(target.X+(target.Width-w)/2,target.Y+(if crop then 0 else (target.Height-h)/2),w,h) + let shown = Rectangle.Intersect(Rectangle.Intersect(dest,target),viewport) + if shown.Width<=0 || shown.Height<=0 then None + else + let sx = (shown.X-dest.X)*source.Width/dest.Width + let sy = (shown.Y-dest.Y)*source.Height/dest.Height + let sw = max 1 (shown.Width*source.Width/dest.Width) + let sh = max 1 (shown.Height*source.Height/dest.Height) + Some(shown,Rectangle(sx,sy,min sw (source.Width-sx),min sh (source.Height-sy))) + +/// Only visible cards own DWM registrations; no screenshots or capture workers are needed. +type GroupEditorPreviews() = + let thumbnails = Dictionary() + let release hwnd = + DwmApi.DwmUnregisterThumbnail(thumbnails.[hwnd]) |> ignore + thumbnails.Remove hwnd |> ignore + member _.Clear() = for hwnd in List.ofSeq thumbnails.Keys do release hwnd + member _.Count = thumbnails.Count + member _.Update(owner:IntPtr, crop:bool, viewport:Rectangle, cards:(IntPtr * Rectangle) list) = + let wanted = cards |> List.filter(fun (hwnd,r) -> r.IntersectsWith viewport && WinUserApi.IsWindow hwnd && not(WinUserApi.IsIconic hwnd)) + for hwnd in List.ofSeq thumbnails.Keys do + if not(wanted |> List.exists(fun (h,_) -> h=hwnd)) then release hwnd + for hwnd,target in wanted do + let thumb = + match thumbnails.TryGetValue hwnd with + | true,value -> Some value + | _ -> + let mutable value = IntPtr.Zero + if DwmApi.DwmRegisterThumbnail(owner,hwnd,&value)=0 then + thumbnails.[hwnd] <- value + Some value + else None + thumb |> Option.iter(fun thumb -> + let mutable size = SIZE() + let projection = + if DwmApi.DwmQueryThumbnailSourceSize(thumb,&size)=0 then + GroupEditorPreview.projection crop (Size(size.cx,size.cy)) target viewport + else None + let mutable props = DWM_THUMBNAIL_PROPERTIES() + props.dwFlags <- 1 ||| 2 ||| 4 ||| 8 + props.opacity <- 255uy + match projection with + | Some(dest,source) -> + props.rcDestination <- RECT.FromRectangle dest + props.rcSource <- RECT.FromRectangle source + props.fVisible <- 1 + | None -> props.fVisible <- 0 + DwmApi.DwmUpdateThumbnailProperties(thumb,&props) |> ignore) + interface IDisposable with + member this.Dispose() = this.Clear() diff --git a/WtProgram/ManagerViewService/Views/AppearanceView.fs b/WtProgram/ManagerViewService/Views/AppearanceView.fs index cf9db6cc..09e665a1 100644 --- a/WtProgram/ManagerViewService/Views/AppearanceView.fs +++ b/WtProgram/ManagerViewService/Views/AppearanceView.fs @@ -262,7 +262,7 @@ type AppearanceView(?settings:ISettings) = let ts : TabStripSprite = { tabs=Map2(List2([1,info 1 (tr Strings.Settings.tabActiveBgColor.caption);2,info 2 (tr Strings.Settings.tabHighlightBgColor.caption);3,info 4 (tr Strings.Settings.tabNormalBgColor.caption)])) lorder=List2([1;2;3]);zorder=List2([1;2;3]);size=Sz(tabs.Width,tabs.Height) - slide=None;direction=(if vertical then TabDown else TabUp);alignment=TabLeft;onlyIcons=((settings.getValue("showIconsOnly") :?> bool) || (vertical && preview.ColumnWidth=fst SettingsCatalog.columnWidthRange));transparent=true;held=None;position=None;rowSlide=None;showAddButton=TabAddButton.visible (settings.getValue("tabAddButton") :?> string) previewHovered; reserveAddButton=preview.ReserveAddButton; buttonScreen=None; windowRight=None; centerShift=0.0;blocked=[]; dock=preview.Position; scrollOffset=0 + slide=None;direction=(if vertical then TabDown else TabUp);alignment=TabLeft;onlyIcons=((settings.getValue("showIconsOnly") :?> bool) || (vertical && preview.ColumnWidth=fst SettingsCatalog.columnWidthRange));transparent=true;held=None;position=None;rowSlide=None;showAddButton=TabAddButton.visible (settings.getValue("tabAddButton") :?> string) previewHovered; reserveAddButton=preview.ReserveAddButton; buttonScreen=None; windowRight=None; centerShift=0.0;blocked=[]; dock=preview.Position; scrollOffset=0; scrollExpansion=0.0f appearance=appearance;hover=Some(2,TabBackground);captured=None } use bitmap = ts.render.bitmap previewButton <- diff --git a/WtProgram/ManagerViewService/Views/WorkspaceView.fs b/WtProgram/ManagerViewService/Views/WorkspaceView.fs index 66cf2006..ca1c8cf8 100755 --- a/WtProgram/ManagerViewService/Views/WorkspaceView.fs +++ b/WtProgram/ManagerViewService/Views/WorkspaceView.fs @@ -89,7 +89,7 @@ type WorkspaceRestoreDialog(first:WorkspaceRestoreResult, ?launch:WorkspaceResto Margin=Padding(-Dpi.scale 3,0,(if i0 // The summary is centred; the list reads from the left and, empty, still // keeps the dialog at its width. - let holder = new Panel(AutoScroll=true,Margin=Padding(0,(if listed then Dpi.scale 20 else 0),0,0)) + let holder = new Panel(Margin=Padding(0,(if listed then Dpi.scale 20 else 0),0,0)) + let scroll = new SettingsScrollBar(TabStop=false) + let mutable offset = 0 + let maximum() = max 0 (details.Height-holder.ClientSize.Height) + let apply value = + offset <- max 0 (min (maximum()) value) + details.Top <- -offset + scroll.configure(maximum(),holder.ClientSize.Height,offset) + let smooth = new SmoothScroller((fun () -> offset),(fun n -> max 0 (min (maximum()) n)),apply) holder.Controls.Add(details) + holder.Controls.Add(scroll) + scroll.BringToFront() + scroll.changed.Add(smooth.jump) + holder.SizeChanged.Add(fun _ -> + scroll.Bounds <- Rectangle(holder.ClientSize.Width-scroll.Width,0,scroll.Width,holder.ClientSize.Height) + apply offset) + details.SizeChanged.Add(fun _ -> apply offset) + holder.MouseWheel.Add(fun e -> + smooth.by(SmoothScroller.wheelStep e.Delta holder.ClientSize.Height) + match e with :? HandledMouseEventArgs as handled -> handled.Handled <- true | _ -> ()) + holder.Disposed.Add(fun _ -> (smooth :> IDisposable).Dispose()) table.Controls.Add(holder) let buttons = new FlowLayoutPanel(AutoSize=true,AutoSizeMode=AutoSizeMode.GrowAndShrink,WrapContents=false, FlowDirection=FlowDirection.RightToLeft,Anchor=AnchorStyles.Right,Margin=Padding(0,Dpi.scale 24,0,0)) diff --git a/WtProgram/Program.fs b/WtProgram/Program.fs index 97393814..3678448d 100644 --- a/WtProgram/Program.fs +++ b/WtProgram/Program.fs @@ -1220,7 +1220,10 @@ type Program(lifetime:LifetimeScope, ?settings:Settings) as this = let draft = DesktopDraft.ofDesktop drafts loose // Every row folded, the overview first; the popup opens on the screen of the window in front. let front = if hwnd=IntPtr.Zero then None else Some(os.windowFromHwnd(hwnd).visibleBounds) - let editor = GroupEditorForm(draft,rows |> List.map fst,windows,None,?front=front) + let editor = GroupEditorForm(draft,rows |> List.map fst,windows,None,?front=front,previews=(Services.settings.getValue "groupEditorPreviews" :?> bool)) + editor.PreviewChanged.Add(fun value -> Services.settings.setValue("groupEditorPreviews",box value)) + let previewSubscription = Services.settings.notifyValue "groupEditorPreviews" (fun value -> editor.SetPreviews(unbox value)) + editor.Ended.Add(fun () -> previewSubscription.Dispose()) editor.Ended.Add(fun () -> groupEditorCell.set None) editor.Saved.Add(fun plan -> if DesktopPlan.isEmpty plan then Notice.show (tr Strings.GroupEditor.title) (tr Strings.GroupEditor.nothingChanged) diff --git a/WtProgram/Settings.fs b/WtProgram/Settings.fs index 0dfdab06..1057dc17 100755 --- a/WtProgram/Settings.fs +++ b/WtProgram/Settings.fs @@ -220,6 +220,7 @@ type Settings(isStandAlone, ?saveDelay:int) as this = enableCtrlScroll = settingsJson.getBool("enableCtrlScroll").def(SettingsCatalog.toggleDefault "enableCtrlScroll" hasExistingSettings) enableMiddleClickClose = settingsJson.getBool("enableMiddleClickClose").def(SettingsCatalog.toggleDefault "enableMiddleClickClose" hasExistingSettings) tabHoverPreview = settingsJson.getBool("tabHoverPreview").def(SettingsCatalog.toggleDefault "tabHoverPreview" hasExistingSettings) + groupEditorPreviews = settingsJson.getBool("groupEditorPreviews").def(SettingsCatalog.toggleDefault "groupEditorPreviews" hasExistingSettings) pauseInFullScreen = settingsJson.getBool("pauseInFullScreen").def(SettingsCatalog.toggleDefault "pauseInFullScreen" hasExistingSettings) recordResources = settingsJson.getBool("recordResources").def(SettingsCatalog.toggleDefault "recordResources" hasExistingSettings) version = settingsJson.getString("version").def(String.Empty) @@ -325,6 +326,7 @@ type Settings(isStandAlone, ?saveDelay:int) as this = settingsJson.setBool("enableCtrlScroll", settings.enableCtrlScroll) settingsJson.setBool("enableMiddleClickClose", settings.enableMiddleClickClose) settingsJson.setBool("tabHoverPreview", settings.tabHoverPreview) + settingsJson.setBool("groupEditorPreviews", settings.groupEditorPreviews) settingsJson.setBool("pauseInFullScreen", settings.pauseInFullScreen) settingsJson.setBool("recordResources", settings.recordResources) settingsJson.setString("tabPosition",settings.tabPosition) diff --git a/WtProgram/Shared/ProgramTypes.fs b/WtProgram/Shared/ProgramTypes.fs index fb54f850..34b41532 100755 --- a/WtProgram/Shared/ProgramTypes.fs +++ b/WtProgram/Shared/ProgramTypes.fs @@ -93,6 +93,7 @@ type SettingsRec = { enableMiddleClickClose: bool /// A picture of a tab's window while the pointer rests on the tab. tabHoverPreview: bool + groupEditorPreviews: bool /// While a full-screen app is in front, shortcuts let go of their keys and notices wait. pauseInFullScreen: bool /// The Support page's charts: a reading every five seconds in the background, kept in memory. diff --git a/WtProgram/Shared/SettingsCatalog.fs b/WtProgram/Shared/SettingsCatalog.fs index 36477b8a..843f6e63 100644 --- a/WtProgram/Shared/SettingsCatalog.fs +++ b/WtProgram/Shared/SettingsCatalog.fs @@ -29,6 +29,7 @@ module SettingsCatalog = let opacityDefault = 100 let leaderKeyPresets = List.zip ["123456789";"QWERTYUIOP";"ASDFGHJKL;"] (Array.toList Strings.Settings.leaderKeyPresets) let all = [ + { id="group-editor-previews"; page=GeneralSettings; text=Strings.GroupEditor.previewSetting; binding=Toggle("groupEditorPreviews",false,false) } { id="tab-color-mode"; page=AppearanceSettings; text=Strings.Settings.tabColorMode; binding=Choice("tabColorMode",["Off";"ByWindow";"ByApp"],"Off") } { id="tab-color-style"; page=AppearanceSettings; text=Strings.Settings.tabColorStyle; binding=Choice("tabColorStyle",["Fill";"Stripe"],"Fill") } // Kept in the appearance, not under a key of its own: the palette lists the presets itself. diff --git a/WtProgram/Shared/Strings.fs b/WtProgram/Shared/Strings.fs index 1b3ef595..c21c5e58 100644 --- a/WtProgram/Shared/Strings.fs +++ b/WtProgram/Shared/Strings.fs @@ -910,6 +910,11 @@ module Strings = /// Written to the console a command line was given from. /// The group editor's popup. module GroupEditor = + let previews = { en="Window previews"; zh="窗口预览"; ja="ウィンドウのプレビュー"; ar="معاينات النوافذ"; ko="창 미리 보기" } + let previewSetting = { + caption={ en="Window previews in Edit groups"; zh="编辑分组中的窗口预览"; ja="グループ編集のウィンドウプレビュー"; ar="معاينات النوافذ في تحرير المجموعات"; ko="그룹 편집에서 창 미리 보기" } + description={ en="Show wrapping preview cards in the group editor."; zh="在分组编辑器中显示自动换行的预览卡片。"; ja="グループ編集で折り返すプレビューカードを表示します。"; ar="عرض بطاقات معاينة تلتف تلقائيًا في محرر المجموعات."; ko="그룹 편집기에서 줄 바꿈되는 미리 보기 카드를 표시합니다." } + keywords={ en="group editor thumbnail preview"; zh="分组编辑器 缩略图 预览"; ja="グループ 編集 サムネイル プレビュー"; ar="مجموعة محرر مصغرة معاينة"; ko="그룹 편집기 썸네일 미리 보기" } } let title = { en="Edit groups"; zh="编辑分组"; ja="グループを編集"; ar="تحرير المجموعات"; ko="그룹 편집" } let windows count = { en=(if count=1 then "1 window" else sprintf "%d windows" count); zh=sprintf "%d 个窗口" count; ja=sprintf "%d 個のウィンドウ" count; ar=sprintf "%d نافذة" count; ko=sprintf "창 %d개" count } diff --git a/WtProgram/TabStrip.fs b/WtProgram/TabStrip.fs index 982e1726..4f528769 100755 --- a/WtProgram/TabStrip.fs +++ b/WtProgram/TabStrip.fs @@ -72,6 +72,10 @@ type TabStrip(monitor:ITabStripMonitor) as this = | "Right" -> TabDockRight | _ -> TabDockTop) let scrollOffsetCell = Cell.create(0) + let scrollExpansionCell = Cell.create(0.0f) + let mutable scrollHover = false + let mutable scrollCollapseAt = DateTime.MinValue + let scrollAnimation = new Timer(Interval=15) let dockChangedEvent = Event() let layoutChangedEvent = Event() let mutable columnWidthValue = Services.settings.getValue("tabColumnWidth") :?> int @@ -237,6 +241,12 @@ type TabStrip(monitor:ITabStripMonitor) as this = titleTimer.Tick.Add(fun _ -> titleTimer.Stop(); this.showTitle()) hoverOpenTimer.Tick.Add(fun _ -> this.stepHoverOpen()) hoverOpenAnimation.Tick.Add(fun _ -> this.stepHoverOpenAnimation()) + scrollAnimation.Tick.Add(fun _ -> + let active = scrollHover || columnScroll.IsSome || DateTime.UtcNowvalue then scrollExpansionCell.set(next) + elif DateTime.UtcNow>=scrollCollapseAt then scrollAnimation.Stop()) captureWatch.Tick.Add(fun _ -> if this.isVertical && WinUserApi.GetCapture()=IntPtr.Zero then this.refreshHover(trackLeave=false) @@ -347,6 +357,7 @@ type TabStrip(monitor:ITabStripMonitor) as this = windowRight = windowRight buttonScreen = this.buttonScreen scrollOffset = scrollOffsetCell.value + scrollExpansion = scrollExpansionCell.value held = heldLayoutCell.value position = positionCell.value rowSlide = rowSlideCell.value @@ -372,10 +383,15 @@ type TabStrip(monitor:ITabStripMonitor) as this = this.withUpdate(fun () -> match mouse with | MouseMove(pt) -> + let over = this.ts.scrollThumb.IsSome && this.ts.scrollTrack.containsPoint(pt) + if over<>scrollHover then + scrollHover <- over + if not over then scrollCollapseAt <- DateTime.UtcNow.AddMilliseconds(600.0) + scrollAnimation.Start() pointerOverCell.set(true) if this.window.hasCapture.not && defaultArg trackLeave true then this.window.trackMouseLeave() - let hit = this.hitAt pt + let hit = if over then None else this.hitAt pt hoverCell.set(hit) let tabHit = hit |> Option.filter(fun (_,part) -> not part.isAddButton) this.pointTitle(hit |> Option.map(fun (tab,part) -> if part.isAddButton then AddTabHint else TabTitle tab)) @@ -413,6 +429,9 @@ type TabStrip(monitor:ITabStripMonitor) as this = if action=MouseUp then capturedCell.set(None) if pointerOverCell.value then hoverCell.set(this.hitAt pt) | MouseLeave -> + scrollHover <- false + scrollCollapseAt <- DateTime.UtcNow.AddMilliseconds(600.0) + scrollAnimation.Start() tipTarget <- None this.hideTitle() this.closeHoverOpen() @@ -616,6 +635,8 @@ type TabStrip(monitor:ITabStripMonitor) as this = if btn=MouseLeft && (columnResize.IsSome || columnScroll.IsSome) then columnResize <- None columnScroll <- None + scrollCollapseAt <- DateTime.UtcNow.AddMilliseconds(600.0) + scrollAnimation.Start() this.window.releaseCapture() this.refreshHover() elif btn=MouseRight && this.endRowDrag() then this.refreshHover() @@ -978,6 +999,8 @@ type TabStrip(monitor:ITabStripMonitor) as this = true elif this.ts.scrollThumb.IsSome && this.ts.scrollTrack.containsPoint(pt) then this.hideTitle() + scrollHover <- true + scrollAnimation.Start() let thumb = this.ts.scrollThumb.Value if thumb.containsPoint(pt) then columnScroll <- Some(pt.y,scrollOffsetCell.value) @@ -1485,6 +1508,7 @@ type TabStrip(monitor:ITabStripMonitor) as this = titleTimer.Dispose() hoverOpenTimer.Dispose() hoverOpenAnimation.Dispose() + scrollAnimation.Dispose() tipRequest <- tipRequest+1 tipTarget <- None titleTip |> Option.iter(fun tip -> tip.Dispose()) diff --git a/WtProgram/TabStripSprite.fs b/WtProgram/TabStripSprite.fs index abebae46..d6a5e97f 100644 --- a/WtProgram/TabStripSprite.fs +++ b/WtProgram/TabStripSprite.fs @@ -976,6 +976,7 @@ type TabStripSprite<'id> when 'id : equality = { windowRight: int option buttonScreen: Rectangle option scrollOffset: int + scrollExpansion: float32 } with member this.isVertical = this.dock=TabDockLeft || this.dock=TabDockRight @@ -992,7 +993,7 @@ type TabStripSprite<'id> when 'id : equality = { else this.size.height member this.columnContentHeight = TabMetrics.columnHeight this.lorder.count this.appearance.tabHeight member this.scrollMaximum = max 0 (this.columnContentHeight-this.tabAreaHeight) - member this.scrollTrack = Rect(Pt(this.size.width-Dpi.scale 12,Dpi.scale 4),Sz(Dpi.scale 6,max 1 (this.tabAreaHeight-Dpi.scale 8))) + member this.scrollTrack = Rect(Pt(this.size.width-Dpi.scale 14,Dpi.scale 4),Sz(Dpi.scale 14,max 1 (this.tabAreaHeight-Dpi.scale 8))) member this.scrollThumb = if not this.isVertical || this.scrollMaximum=0 then None else @@ -1146,8 +1147,21 @@ type TabStripSprite<'id> when 'id : equality = { gr.ResetClip() else gr.FillRectangle(brush, bounds.Rectangle) this.scrollThumb |> Option.iter(fun thumb -> - use ink = new SolidBrush(this.appearance.tabBorderColor) - gr.FillRectangle(ink,thumb.Rectangle)) + let t = if System.Windows.Forms.SystemInformation.HighContrast then 1.0f else this.scrollExpansion + let thickness = float32(Dpi.scale 2)+float32(Dpi.scale 4)*t + let x = float32(this.scrollTrack.x+this.scrollTrack.width-Dpi.scale 3)-thickness + let pill y height color = + use path = new System.Drawing.Drawing2D.GraphicsPath() + path.AddArc(x,y,thickness,thickness,180.0f,180.0f) + path.AddArc(x,y+height-thickness,thickness,thickness,0.0f,180.0f) + path.CloseFigure() + use brush = new SolidBrush(color) + gr.FillPath(brush,path) + gr.SmoothingMode <- System.Drawing.Drawing2D.SmoothingMode.AntiAlias + if t>0.0f && not System.Windows.Forms.SystemInformation.HighContrast then + pill (float32 this.scrollTrack.y) (float32 this.scrollTrack.height) (Color.FromArgb(int(35.0f*t),this.appearance.tabBorderColor)) + pill (float32 thumb.y) (float32 thumb.height) + (if System.Windows.Forms.SystemInformation.HighContrast then SystemColors.WindowText else this.appearance.tabBorderColor)) img /// Narrowest a tab gets: its icon with room either side to click it. Tabs that still do diff --git a/WtProgram/WtProgram.fsproj b/WtProgram/WtProgram.fsproj index 7ac15997..22e4bc3d 100755 --- a/WtProgram/WtProgram.fsproj +++ b/WtProgram/WtProgram.fsproj @@ -154,6 +154,7 @@ + diff --git a/docs/architecture.md b/docs/architecture.md index 6c779667..ce553b19 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -507,6 +507,21 @@ trees release their owned icons. Closing the view cancels its worker. ## Settings and diagnostics +The group editor's `groupEditorPreviews` preference is shared with the command +palette through `SettingsCatalog`. Adjacent preview groups that fit within half +the available width share a line without reordering groups. Larger groups use the +full width. Expanding a group keeps both preview bands and all cards in their +original positions. A separate full-width content panel opens below their shared +line, pushing only subsequent lines down without changing draft order. Preview +drags only show a destination until release, so changing membership cannot resize +or remove a drop target mid-drag. Preview cards wrap in the existing tab order +and preserve the draft, expanded split and scroll anchor when toggled. Only visible +cards register DWM thumbnails; their source rectangles are clipped with the viewport +so scrolling does not distort the image. Hovering never opens a separate window +preview. Clicking a card expands or collapses the split editor with a short +transition; subsequent rows and their inline thumbnails move together while the +selected row's cards stay in place. Closing releases all DWM registrations. + Taskbar button visibility is remembered per HWND, so unchanged z-order notifications do not repeatedly call Explorer to add or delete a button. A new Shell_TrayWnd handle invalidates this state after Explorer restarts; diff --git a/tests/GroupEditor.fsx b/tests/GroupEditor.fsx index dfd3cb41..9b948972 100644 --- a/tests/GroupEditor.fsx +++ b/tests/GroupEditor.fsx @@ -210,6 +210,215 @@ let main() = let api = settings :> ISettings api.setValue("enableCtrlNumberHotKey",box false) api.setValue("autoHideMode",box "Never") + // Preview cards wrap without changing the draft, and clipping keeps the source scale. + check (GroupEditorPicture.dragOffset (Size(180,126)) (Size(60,30)) (Point(179,125))=Point(59,29)) "A corner grab lay outside the carried title" + check (GroupEditorPicture.dragOffset (Size(60,30)) (Size(60,30)) (Point(20,15))=Point(20,15)) "A compact tab changed its grab point" + let cropped = GroupEditorPreview.projection true (Size(1000,800)) (Rectangle(10,20,200,96)) (Rectangle(0,50,500,500)) + check (cropped=Some(Rectangle(10,50,200,66),Rectangle(0,150,1000,330))) "Scrolling stretched or exposed the cropped source" + let fitted = GroupEditorPreview.projection false (Size(1000,800)) (Rectangle(0,0,400,200)) (Rectangle(0,0,400,200)) + check (fitted=Some(Rectangle(75,0,250,200),Rectangle(0,0,1000,800))) "The hover preview cropped the complete window" + let previewHandles = [1..8] |> List.map(fun i -> IntPtr(10000+i)) + let previewDraft = DesktopDraft.ofDesktop [GroupDraft.ofGroup (IntPtr 90) previewHandles Set.empty Single] [] + let previewWindows = previewHandles |> List.map(fun h -> {hwnd=h;name="Window "+string h;icon=None;minimized=true}) + let previewFrame = Rect(Pt(0,0),Sz(1200,800)) + let previewEditor = GroupEditorForm(previewDraft,[{group=Some(IntPtr 90);frame=previewFrame;active=previewHandles.Head}],previewWindows,None) + try + previewEditor.Resize(Size(Dpi.scale 820,Dpi.scale 600)) + previewEditor.SetPreviews true + let row = previewEditor.Layout.rows.Head + check ((row.tabs |> List.map fst)=previewHandles) "Preview wrapping changed tab order" + check ((row.tabs |> List.map(fun (_,r) -> r.Y) |> List.distinct).Length=2) "Eight preview cards did not wrap into two rows" + check (row.tabs |> List.forall(fun (_,r) -> r.Height=Dpi.scale 126 && r.Right<=row.band.Right)) "Preview cards escaped the group or changed height" + check (previewEditor.Draft=previewDraft && DesktopPlan.isEmpty previewEditor.Plan) "Changing preview mode edited the draft" + previewEditor.Resize(Size(Dpi.scale 820,Dpi.scale 320)) + previewEditor.Show() + let host = Control.FromHandle(previewEditor.Handle) + let bar = host.Controls |> Seq.cast |> Seq.pick(fun c -> match c with :? SettingsScrollBar as bar -> Some bar | _ -> None) + check bar.Visible "Overflowing preview rows did not show the settings scrollbar" + if not SystemInformation.HighContrast then + let sample() = + use image = new Bitmap(bar.Width,bar.Height) + bar.DrawToBitmap(image,bar.ClientRectangle) + image.GetPixel(Dpi.scale 6,Dpi.scale 8).ToArgb() + let thin = sample() + typeof.GetMethod("OnMouseEnter",Reflection.BindingFlags.Instance ||| Reflection.BindingFlags.Public ||| Reflection.BindingFlags.NonPublic).Invoke(bar,[|box EventArgs.Empty|]) |> ignore + pumpUntil "The editor scrollbar did not widen on hover" (fun () -> sample()<>thin) + previewEditor.Resize(Size(Dpi.scale 820,Dpi.scale 600)) + use previewImage = previewEditor.Render() + previewImage.Save(Path.Combine(__SOURCE_DIRECTORY__,"Debug","group-editor-previews.png")) + let start = snd row.tabs.[4] + let target = snd row.tabs.[1] + previewEditor.MouseDown(Point(start.X+10,start.Y+10)) + previewEditor.MouseMove(Point(target.X+2,target.Y+10)) + previewEditor.MouseUp(Point(target.X+2,target.Y+10)) + check (previewEditor.Draft.groups.Head.tabs.[1]=previewHandles.[4]) "Dragging across wrapped preview rows did not reorder" + let tab = snd previewEditor.Layout.rows.Head.tabs.Head + let click = Point(tab.X+10,tab.Y+10) + previewEditor.MouseDown click + previewEditor.MouseUp click + let expandedPreview = previewEditor.Layout.rows.Head + check (expandedPreview.expanded && expandedPreview.picture.Y>=(expandedPreview.tabs |> List.map(fun (_,r) -> r.Bottom) |> List.max)) "Expanded content overlapped wrapped preview cards" + check expandedPreview.splitButton.IsSome "Preview mode removed the existing split editor" + let edited = previewEditor.Draft + previewEditor.SetPreviews false + check (previewEditor.Draft=edited && previewEditor.Layout.rows.Head.tabs |> List.forall(fun (_,r) -> r.Height=Dpi.scale 30)) "Turning previews off lost edits or kept card heights" + let r = snd previewEditor.Layout.rows.Head.tabs.Head + previewEditor.MouseDown(Point(r.X+10,r.Y+10)) + previewEditor.SetPreviews true + check (not previewEditor.Previews) "A preference change rearranged cards during a gesture" + previewEditor.Press Keys.Escape + check (previewEditor.Previews && previewEditor.Draft=edited) "Cancelling the gesture lost edits or the pending preview preference" + finally previewEditor.Close() + // Half-width groups pair in order; crossing the size threshold waits for the drop. + let packingDpi = Dpi.value() + try + for dpi in [96;144;192] do + Dpi.set dpi + let handles = [21..28] |> List.map IntPtr + let drafts = [[handles.[0];handles.[1]];[handles.[2];handles.[3]];[handles.[4];handles.[5];handles.[6]];[handles.[7]]] + |> List.mapi(fun i tabs -> GroupDraft.ofGroup (IntPtr(200+i)) tabs Set.empty Single) + let packedDraft = DesktopDraft.ofDesktop drafts [] + let rows = drafts |> List.map(fun g -> {group=g.group;frame=previewFrame;active=g.tabs.Head}) + let windows = handles |> List.map(fun h -> {hwnd=h;name="W";icon=None;minimized=true}) + let packed = GroupEditorForm(packedDraft,rows,windows,None,previews=true) + try + packed.Resize(Size(Dpi.scale 1000,Dpi.scale 900)) + let bands() = packed.Layout.rows |> List.map(fun r -> r.band) + let original = bands() + let grab = snd packed.Layout.rows.Head.tabs.Head + let corner = Point(grab.Right-2,grab.Bottom-2) + packed.MouseDown corner + let offset = packed.Drag.Value.offset + check (offset.X>=0 && offset.X=0 && offset.Yoriginal.[0].Width && original.[2].Y>=original.[0].Bottom) "A large group did not occupy a full line" + check (original.[3].Width=original.[0].Width && original.[3].Left=original.[0].Left && original.[3].Y>=original.[2].Bottom) "An unpaired group moved out of order or filled the line" + for index in [1;0] do + let beforeTabs = packed.Layout.rows.[index].tabs + let r = snd beforeTabs.Head + let click = Point(r.X+10,r.Y+10) + packed.MouseDown click + packed.MouseUp click + let expanded = packed.Layout.rows.[index] + let neighbour = packed.Layout.rows.[1-index] + check (expanded.expanded && expanded.band=original.[index] && expanded.tabs=beforeTabs) "Expansion moved the original group or its preview cards" + check (expanded.picture.Left=original.[2].Left+Dpi.scale 10 && expanded.picture.Width=original.[2].Width-Dpi.scale 20 && expanded.picture.Top>original.[index].Bottom) "Expanded content did not span the width below the original row" + check (neighbour.band=original.[1-index]) "Expansion moved the paired neighbour" + check (packed.Draft=packedDraft && (packed.Layout.rows |> List.map(fun row -> row.index))=[0;1;2;3]) "Visual expansion reordered draft groups or layout indices" + check (packed.Layout.rows.[2].band.Top>expanded.picture.Bottom) "Expansion overlapped the following row" + if dpi=96 && index=1 then + use image = packed.Render() + image.Save(Path.Combine(__SOURCE_DIRECTORY__,"Debug","group-editor-expanded-inline.png")) + let neighbourTab = snd neighbour.tabs.Head + packed.MouseDown(Point(neighbourTab.X+10,neighbourTab.Y+10)) + packed.MouseMove(Point(expanded.picture.Left+1,expanded.picture.Top+expanded.picture.Height/2)) + check (packed.Drag |> Option.exists(fun d -> match d.aim with Some(CellEdge(row,_,_,_)) -> row=index | _ -> false)) "The full-width panel did not accept a drop outside its original half row" + packed.Press Keys.Escape + check (packed.Draft=packedDraft && packed.Layout.rows.[1-index].band=original.[1-index]) "Cancelling a panel drag moved or edited the neighbouring group" + while packed.Expanded.IsSome do packed.Press Keys.Escape + check (bands()=original) "Collapsing a half-row group did not restore the layout" + if dpi=96 then + use image = packed.Render() + image.Save(Path.Combine(__SOURCE_DIRECTORY__,"Debug","group-editor-packed.png")) + let source = snd packed.Layout.rows.[0].tabs.Head + let target = snd packed.Layout.rows.[1].tabs.[1] + let at = Point(target.Right+3,target.Y+10) + packed.MouseDown(Point(source.X+10,source.Y+10)) + packed.MouseMove at + check (bands()=original && packed.Draft=packedDraft) "A half-width target moved or changed membership before release" + packed.Press Keys.Escape + check (bands()=original && packed.Draft=packedDraft) "Cancelling a preview drag changed its layout" + packed.MouseDown(Point(source.X+10,source.Y+10)) + packed.MouseMove at + packed.MouseUp at + check (packed.Draft.groups.[1].tabs=[handles.[2];handles.[3];handles.[0]]) "Dropping into the right-hand group lost tab order" + check (packed.Layout.rows.[1].band.Width=original.[2].Width) "A group crossing half-width did not grow after release" + let tab = snd packed.Layout.rows.[0].tabs.Head + let click = Point(tab.X+10,tab.Y+10) + packed.MouseDown click + packed.MouseUp click + check (packed.Layout.rows.Head.expanded && packed.Layout.rows.Head.picture.Width=original.[2].Width-Dpi.scale 20) "An expanded small group did not have full-width content" + while packed.Expanded.IsSome do packed.Press Keys.Escape + let beforeLast = bands() + let lastSource = snd packed.Layout.rows.Head.tabs.Head + let lastTarget = snd packed.Layout.rows.[1].tabs.Head + let lastAt = Point(lastTarget.X+2,lastTarget.Y+10) + packed.MouseDown(Point(lastSource.X+10,lastSource.Y+10)) + packed.MouseMove lastAt + let lastDrag = packed.Drag + check (bands()=beforeLast && packed.Draft.groups.Length=4) "A group's last tab removed its band before release" + packed.MouseUp lastAt + check (packed.Draft.groups.Length=3) (sprintf "The emptied group remained after release: dpi=%d closed=%b expanded=%A drag=%A source=%A target=%A groups=%A" dpi packed.IsClosed packed.Expanded lastDrag lastSource lastTarget (packed.Draft.groups |> List.map(fun g -> g.tabs))) + // A narrow editor cannot fit even one card into a half row. + packed.Resize(Size(Dpi.scale 400,Dpi.scale 900)) + let narrow = packed.Layout.rows + check (narrow |> List.pairwise |> List.forall(fun (a,b) -> a.band.Bottom<=b.band.Top)) "Narrow groups overlapped instead of using full lines" + finally packed.Close() + let multi = GroupEditorForm(packedDraft,rows,windows,None,previews=true) + try + multi.Resize(Size(Dpi.scale 1000,Dpi.scale 900)) + for _,r in multi.Layout.rows.Head.tabs do + let pt = Point(r.X+10,r.Y+10) + multi.MouseDown(pt,keys=Keys.Control) + multi.MouseUp pt + let before = multi.Layout.rows |> List.map(fun r -> r.band) + let source = snd multi.Layout.rows.Head.tabs.Head + let target = snd multi.Layout.rows.[1].tabs.[1] + let at = Point(target.Right+3,target.Y+10) + multi.MouseDown(Point(source.X+10,source.Y+10)) + multi.MouseMove at + check (multi.Draft=packedDraft && (multi.Layout.rows |> List.map(fun r -> r.band))=before) "Moving multiple cards rearranged groups before release" + multi.MouseUp at + check (multi.Draft.groups.Head.tabs=[handles.[2];handles.[3];handles.[0];handles.[1]]) "A block drop lost the destination or selected order" + finally multi.Close() + finally Dpi.set packingDpi + // Live DWM cards remain inline; clicking expands and collapses with a transition. + use previewSource = new Form(Text="Preview fixture",Size=Size(640,480)) + previewSource.Show() + let sourceHandle = previewSource.Handle + let nativeDraft = DesktopDraft.ofDesktop [GroupDraft.ofGroup (IntPtr 91) [sourceHandle] Set.empty Single] [] + let nativeEditor = GroupEditorForm(nativeDraft,[{group=Some(IntPtr 91);frame=previewFrame;active=sourceHandle}], + [{hwnd=sourceHandle;name="Preview fixture";icon=None;minimized=false}],None,previews=true) + try + nativeEditor.Show() + Application.DoEvents() + check (nativeEditor.PreviewCount=1) "The visible card did not register a live thumbnail" + let r = snd nativeEditor.Layout.rows.Head.tabs.Head + nativeEditor.MouseMove(Point(r.X+10,r.Y+Dpi.scale 40)) + let host = Control.FromHandle(nativeEditor.Handle) :?> Form + let owned = host.OwnedForms.Length + Thread.Sleep(450) + Application.DoEvents() + check (host.OwnedForms.Length=owned) "Hovering a card opened an unwanted preview window" + let click = Point(r.X+10,r.Y+10) + nativeEditor.MouseDown click + nativeEditor.MouseUp click + check (nativeEditor.Expanded=Some 0) "Clicking a preview card did not expand the group" + if SystemInformation.UIEffectsEnabled then check nativeEditor.Morphing "Click expansion lost its transition" + pumpUntil "Expansion animation did not finish" (fun () -> not nativeEditor.Morphing) + let expandedTab = snd nativeEditor.Layout.rows.Head.tabs.Head + let collapse = Point(expandedTab.X+10,expandedTab.Y+10) + nativeEditor.MouseDown collapse + nativeEditor.MouseUp collapse + check nativeEditor.Expanded.IsNone "Clicking the selected card did not collapse the group" + if SystemInformation.UIEffectsEnabled then check nativeEditor.Morphing "Click collapse lost its transition" + pumpUntil "Collapse animation did not finish" (fun () -> not nativeEditor.Morphing) + nativeEditor.ScrollTo 0 + nativeEditor.SetPreviews false + check (nativeEditor.PreviewCount=0) "Turning previews off retained thumbnail registrations" + nativeEditor.SetPreviews true + check (nativeEditor.PreviewCount=1) "Turning previews back on lost the live thumbnail" + for _ in 1..10 do + nativeEditor.SetPreviews false + check (nativeEditor.PreviewCount=0) "Repeated toggles retained live thumbnails" + nativeEditor.SetPreviews true + previewSource.Close() + nativeEditor.ScrollTo 0 + check (nativeEditor.PreviewCount=0) "A destroyed source retained its thumbnail" + finally nativeEditor.Close() // The popup with one row expanded, drawn without a screen, in both looks: the tabs along // the top with the selected one in the accent, the content under them; keys select, move // and take out; Save plans what changed. @@ -321,6 +530,8 @@ let main() = let frame = Rect(Pt(100,100),Sz(1600,900)) let desk = DesktopDraft.ofDesktop [GroupDraft.ofGroup (IntPtr 1) [a;b;c;d] Set.empty (Split(pair a b))] [] let editor = GroupEditorForm(desk,[{group=Some(IntPtr 1); frame=frame; active=a}],shown,Some 0) + // This fixture uses layout coordinates; keep its controls visible on small CI desktops. + editor.Resize(Size(Dpi.scale 900,Dpi.scale 900)) let centre (r:Rectangle) = Point(r.X+r.Width/2,r.Y+r.Height/2) let cellRect path = editor.Layout.rows.[0].cells |> List.find(fun (each,_,_) -> each=path) |> fun (_,_,r) -> r let tabRect hwnd = editor.Layout.rows.[0].tabs |> List.find(fun (each,_) -> each=hwnd) |> snd @@ -392,8 +603,20 @@ let main() = editor.MouseDown(centre (tabRect a)) editor.MouseUp(centre (tabRect a)) check (editor.Selected=a && editor.Layout.rows.[0].focused=Some [Second] && editor.Layout.rows.[0].splitButton.IsSome) "Clicking a pane tab did not focus its cell" - editor.MouseDown(centre editor.Layout.rows.[0].splitButton.Value) - check (editor.FlyoutOpen && editor.Layout.rows.[0].shapes.Length=GroupDraft.shapes.Length) "The split button did not open the shapes" + // A short viewport needs scrolling and client coordinates, just like a real click. + let fullSize = editor.Size + editor.Resize(Size(fullSize.Width,Dpi.scale 480)) + let shortLayout = editor.Layout + let button = shortLayout.rows.[0].splitButton.Value + let body = editor.Size.Height-(shortLayout.height-shortLayout.body) + let offset = button.Bottom-body+Dpi.scale 8 + check (offset>0) "The short viewport did not put the split button below the visible rows" + editor.ScrollTo offset + let at = centre button + editor.MouseDown(Point(at.X,at.Y-offset)) + check (editor.FlyoutOpen && editor.Layout.rows.[0].shapes.Length=GroupDraft.shapes.Length) "The visible split button did not open the shapes after scrolling" + editor.Resize fullSize + editor.ScrollTo 0 editor.MouseDown(centre (editor.Layout.rows.[0].shapes |> List.find(fun (shape,_) -> shape=StackedPair) |> snd)) check (not editor.FlyoutOpen && GroupDraft.emptyCells editor.Draft.groups.[0]=[[Second;Second]] && panes()=[c;a]) (sprintf "A shape did not cut the cell with an empty slot: %A" editor.Draft.groups.[0].panes) check (editor.Plan.groups.Head.layout=Some(Split {pair c a with focused=[Second]})) "The empty slot did not close in the plan" diff --git a/tests/RenderingPerf/Program.fs b/tests/RenderingPerf/Program.fs index 2cfe1c18..d4956f3f 100644 --- a/tests/RenderingPerf/Program.fs +++ b/tests/RenderingPerf/Program.fs @@ -35,7 +35,7 @@ let strip count dpi font = textFont=font; textBrush=Brushes.Black; splitTrail=None; isPinned=false; closeButton="ActiveAndHover" }))) lorder=List2(ids); zorder=List2(ids); size=Dpi.scaleSize(Sz(min 1800 (count*210),28)) slide=None; direction=TabUp; alignment=TabLeft; onlyIcons=false - transparent=true; held=None; position=None; rowSlide=None; blocked=[]; showAddButton=true; reserveAddButton=false; buttonScreen=None; windowRight=None; centerShift=0.0; dock=TabDockTop; scrollOffset=0; appearance=appearance; hover=None; captured=None } + transparent=true; held=None; position=None; rowSlide=None; blocked=[]; showAddButton=true; reserveAddButton=false; buttonScreen=None; windowRight=None; centerShift=0.0; dock=TabDockTop; scrollOffset=0; scrollExpansion=0.0f; appearance=appearance; hover=None; captured=None } /// Times each action alone; setup and cleanup run around it, untimed but within cpuMs. let measureWith name iterations (setup:int -> 'state) (action:'state -> unit) (cleanup:'state -> unit) = diff --git a/tests/SettingsEditors.fsx b/tests/SettingsEditors.fsx index 8eb9e835..7a233d35 100644 --- a/tests/SettingsEditors.fsx +++ b/tests/SettingsEditors.fsx @@ -1277,6 +1277,14 @@ otepad.exe"]}, Application.DoEvents() let rec all (control:Control) = seq { yield control; for child in control.Controls do yield! all child } assertTrue dialog.TopMost "Restore result could be covered by the windows being restored" + use longResult = new WorkspaceRestoreDialog(WorkspaceRestoreResult.Of("Long workspace",0,[for i in 1..40 -> "app.exe",sprintf "%d %s" i longTitle],[])) + longResult.StartPosition <- FormStartPosition.Manual + longResult.Location <- Point(-20000,-20000) + longResult.Show() + Application.DoEvents() + assertTrue (all longResult |> Seq.exists(function :? SettingsScrollBar as bar -> bar.Visible | _ -> false)) "A long restore result did not use the shared scrollbar" + assertTrue (all longResult |> Seq.forall(function :? ScrollableControl as panel -> not panel.AutoScroll | _ -> true)) "A restore result retained a system scrollbar" + longResult.Close() let marks = all dialog |> Seq.choose(function :? RestoreMark as mark -> Some(mark.State,mark.Active) | _ -> None) |> Seq.truncate 3 |> List.ofSeq assertTrue (marks=[Restored,true;NotFound,true;Failed,true]) (sprintf "Restore states lack their marks: %A" marks) // A clean restore shows only its restored count, not states with none in them. diff --git a/tests/SettingsTheme.fsx b/tests/SettingsTheme.fsx index 3b30e4ab..ede40d76 100644 --- a/tests/SettingsTheme.fsx +++ b/tests/SettingsTheme.fsx @@ -119,7 +119,7 @@ let main() = let ids = [0..count-1] let strip : TabStripSprite = { tabs=Map2(List2(ids |> List.map(fun i -> i,info i))); lorder=List2(ids); zorder=List2(ids); size=Sz(900,27) - slide=None; direction=TabUp; alignment=TabLeft; onlyIcons=false; transparent=true; held=None; position=None; rowSlide=None; showAddButton=false; reserveAddButton=false; buttonScreen=None; windowRight=None; centerShift=0.0; blocked=[]; dock=TabDockTop; scrollOffset=0 + slide=None; direction=TabUp; alignment=TabLeft; onlyIcons=false; transparent=true; held=None; position=None; rowSlide=None; showAddButton=false; reserveAddButton=false; buttonScreen=None; windowRight=None; centerShift=0.0; blocked=[]; dock=TabDockTop; scrollOffset=0; scrollExpansion=0.0f appearance=appearance; hover=None; captured=None } let fills = strip.tabSprites.list |> List.filter(fun (_,sprite) -> not sprite.isTop) |> List.map(fun (_,sprite) -> sprite.fillColor) let spread (colors:Color list) = diff --git a/tests/SplitView.fsx b/tests/SplitView.fsx index d15fb9a6..05e6dbe2 100644 --- a/tests/SplitView.fsx +++ b/tests/SplitView.fsx @@ -357,7 +357,7 @@ let main() = textFont=font; textBrush=Brushes.Black; splitTrail=Map.tryFind id sides; isPinned=false; closeButton="ActiveAndHover" }))) lorder=List2([1;2;3]); zorder=List2([1;2;3]); size=Sz(630,Dpi.scale 28) slide=None; direction=TabUp; alignment=TabLeft; onlyIcons=false - transparent=true; held=None; position=None; rowSlide=None; showAddButton=false; reserveAddButton=false; buttonScreen=None; windowRight=None; centerShift=0.0; blocked=[]; dock=TabDockTop; scrollOffset=0; appearance=appearance; hover=None; captured=None } + transparent=true; held=None; position=None; rowSlide=None; showAddButton=false; reserveAddButton=false; buttonScreen=None; windowRight=None; centerShift=0.0; blocked=[]; dock=TabDockTop; scrollOffset=0; scrollExpansion=0.0f; appearance=appearance; hover=None; captured=None } let paired = strip (Map.ofList [1,[SideBySide,First];2,[SideBySide,Second]]) let seam = paired.tabLocation 2 // Near the bottom edge, where the button sits clear of the icons; the middle of the seam stays the tabs'. diff --git a/tests/TabShadow.fsx b/tests/TabShadow.fsx index 5a7ce6ad..b4d54abc 100644 --- a/tests/TabShadow.fsx +++ b/tests/TabShadow.fsx @@ -107,7 +107,7 @@ let main () = let ts : TabStripSprite = { tabs=Map2(List2([1,info "Active tab"; 2,info "Another window"])) lorder=List2([1;2]); zorder=List2([1;2]); size=Sz(420,28) - slide=None; direction=TabUp; alignment=TabLeft; onlyIcons=false; held=None; position=None; rowSlide=None; showAddButton=false; reserveAddButton=false; buttonScreen=None; windowRight=None; centerShift=0.0; blocked=[]; dock=TabDockTop; scrollOffset=0 + slide=None; direction=TabUp; alignment=TabLeft; onlyIcons=false; held=None; position=None; rowSlide=None; showAddButton=false; reserveAddButton=false; buttonScreen=None; windowRight=None; centerShift=0.0; blocked=[]; dock=TabDockTop; scrollOffset=0; scrollExpansion=0.0f transparent=true; appearance=appearance; hover=None; captured=None } let originalVerticalDpi = Dpi.value() try @@ -322,6 +322,11 @@ let main () = check overflow.scrollThumb.IsSome "An overflowing column has no scrollbar" let thumb = overflow.scrollThumb.Value check (thumb.x+thumb.width<=overflow.size.width) "Scrollbar escaped the column at high DPI" + if not System.Windows.Forms.SystemInformation.HighContrast then + use thin = overflow.render.bitmap + use wide = { overflow with scrollExpansion=1.0f }.render.bitmap + let different = seq { for y in 0..thin.Height-1 do for x in max 0 (thin.Width-Dpi.scale 14)..thin.Width-1 do yield thin.GetPixel(x,y)<>wide.GetPixel(x,y) } |> Seq.exists id + check different "Hovering did not widen the vertical tab scrollbar" let bottom = { overflow with scrollOffset=overflow.scrollMaximum } check (bottom.scrollThumb.Value.bottom=bottom.scrollTrack.bottom) "Scrollbar thumb cannot reach the last row" check (column.scrollThumb.IsNone) "A short column shows an unnecessary scrollbar"