public void ChangeSide(AppBarSide side) { switch (side) { case AppBarSide.Left: Splitter.FlowDirection = FlowDirection.RightToLeft; break; case AppBarSide.Right: Splitter.FlowDirection = FlowDirection.LeftToRight; break; } if (tileObject != null) { tileObject.ChangeSide((int)side); } this.side = side; }
public void SetSide(AppBarSide side) { switch (side) { case AppBarSide.Left: AppBar.SetSidebar(this, AppBarSide.Left, sett.topMost, sett.overlapTaskbar, sett.screen); Bg.FlowDirection = FlowDirection.RightToLeft; BgHighlight.FlowDirection = FlowDirection.RightToLeft; BgHighlight.HorizontalAlignment = HorizontalAlignment.Right; Highlight.FlowDirection = FlowDirection.RightToLeft; Highlight.HorizontalAlignment = HorizontalAlignment.Right; shadow.Left = this.Left + this.Width; shadow.FlowDirection = FlowDirection.RightToLeft; foreach (Tile tile in TilesGrid.Children) { tile.ChangeSide(AppBarSide.Left); } break; case AppBarSide.Right: AppBar.SetSidebar(this, AppBarSide.Right, sett.topMost, sett.overlapTaskbar, sett.screen); Bg.FlowDirection = FlowDirection.LeftToRight; BgHighlight.FlowDirection = FlowDirection.LeftToRight; BgHighlight.HorizontalAlignment = HorizontalAlignment.Left; Highlight.FlowDirection = FlowDirection.LeftToRight; Highlight.HorizontalAlignment = HorizontalAlignment.Left; shadow.Left = this.Left - shadow.Width; shadow.FlowDirection = FlowDirection.LeftToRight; foreach (Tile tile in TilesGrid.Children) { tile.ChangeSide(AppBarSide.Right); } break; } }
internal static int CalculatePos(AppBarSide side) { int pos = 0; Screen[] screens = Screen.AllScreens; switch (side) { case AppBarSide.Left: pos = SystemInformation.VirtualScreen.Left; foreach (Screen scr in screens) { if (scr == AppBar.Screen) { break; } else { pos += scr.Bounds.Width; } } break; case AppBarSide.Right: pos = SystemInformation.VirtualScreen.Right; for (int i = screens.Length - 1; i > 0; i--) { if (screens[i] == AppBar.Screen) { break; } else { pos -= screens[i].Bounds.Width; } } break; } return(pos); }
public static void SetSidebar(Window wnd, AppBarSide side, bool topMost, bool overlapTaskBar, string scrnName) { MainWindow = wnd; Handle = new WindowInteropHelper(wnd).Handle; Side = side; ScreenName = scrnName; Screen = Utils.GetScreenFromName(scrnName); if (topMost) { AlwaysTop = topMost; AppbarNew(); if (!IsOverlapping && overlapTaskBar && side == AppBarSide.Right) { OverlapTaskbar(); } SizeAppbar(); wnd.Topmost = true; } else { AlwaysTop = topMost; wnd.Topmost = false; if (IsOverlapping && side == AppBarSide.Right) { RestoreTaskbar(); } SetPos(); } if (!WindowHooksAdded) { HwndSource.FromHwnd(Handle).AddHook(new HwndSourceHook(WndProc)); HwndSource.FromHwnd(Handle).AddHook(new HwndSourceHook(DwmManager.WndProc)); WindowHooksAdded = true; } }
public void Load(AppBarSide side, double height) { this.side = side; //////////////////////////////////// if (!System.IO.File.Exists(this.File)) { return; } tileAssembly = Assembly.LoadFrom(this.File); tileModelType = GetTileModelType(tileAssembly); switch ((ModelType)tileModelType) { case ModelType.LongBar: foreach (Type type in tileAssembly.GetTypes()) { if (type.BaseType == typeof(TileLib.BaseTile)) { TileType = type; } } foreach (Attribute attr in tileAssembly.GetCustomAttributes(false)) { if (attr.GetType() == typeof(TileLib.TileInfo)) { Info = (TileLib.TileInfo)attr; this.TitleTextBlock.Text = Info.Name; } } break; case ModelType.KarlsSidebar: foreach (Type type in tileAssembly.GetTypes()) { if (type.BaseType != null && type.BaseType.ToString() == "Applications.Sidebar.BaseTile") { TileType = type; } } foreach (Attribute attr in tileAssembly.GetCustomAttributes(false)) { if (attr.GetType().ToString() == "Applications.Sidebar.SidebarTileInfo") { Info = new TileLib.TileInfo(((SidebarTileInfo)attr).Title, false, false); this.TitleTextBlock.Text = Info.Name; if (System.IO.File.Exists(System.IO.Path.GetDirectoryName(this.File) + @"\Icon.png")) { this.TitleIcon.Source = new BitmapImage(new Uri(System.IO.Path.GetDirectoryName(this.File) + @"\Icon.png")); } } } break; } this.Unloaded += new RoutedEventHandler(Tile_Unloaded); this.SizeChanged += new SizeChangedEventHandler(Tile_SizeChanged); if (Info == null) { hasErrors = true; } //////////////////////////// try { switch (tileModelType) { case ModelType.LongBar: tileObject = (TileLib.BaseTile)TileType.InvokeMember(null, flags | BindingFlags.CreateInstance, null, null, null); tileObject.CaptionChanged += new TileLib.BaseTile.CaptionChangedEventHandler(TileObject_CaptionChanged); tileObject.IconChanged += new TileLib.BaseTile.IconChangedEventHandler(TileObject_IconChanged); tileObject.ShowOptionsEvent += new TileLib.BaseTile.ShowOptionsEventHandler(TileObject_ShowOptionsEvent); tileObject.ShowFlyoutEvent += new TileLib.BaseTile.ShowFlyoutEventHandler(TileObject_ShowFlyoutEvent); tileObject.HeightChangedEvent += new TileLib.BaseTile.HeightChangedEventHandler(tileObject_HeightChangedEvent); tileObject._path = SidebarWindow.sett.path; control = tileObject.Load(); control.MouseLeftButtonDown += new MouseButtonEventHandler(TileContentGrid_MouseLeftButtonDown); break; case ModelType.KarlsSidebar: tileKObject = (Applications.Sidebar.Tile)TileType.InvokeMember(null, flags | BindingFlags.CreateInstance, null, null, null); control = tileKObject.SidebarContent; Info = new TileLib.TileInfo(Info.Name, tileKObject.hasFlyout, tileKObject.hasConfigWindow); break; } } catch (Exception ex) { if (SidebarWindow.sett.showErrors) { TaskDialogs.ErrorDialog.ShowDialog("An error occured while loading tile. Please send feedback.", String.Format("Error: {0}\nTile: {1}\nSee log for detailed info.", ex.Message, Info.Name), ex); } if (!System.IO.Directory.Exists(SidebarWindow.sett.path + @"\Logs")) { System.IO.Directory.CreateDirectory(SidebarWindow.sett.path + @"\Logs"); } string logFile = string.Format(@"{0}\Logs\{1}.{2}.{3}.log", SidebarWindow.sett.path, DateTime.Now.Day, DateTime.Now.Month, DateTime.Now.Year); try { System.IO.File.AppendAllText(logFile, String.Format("{0}\r\n{1}\r\n--------------------------------------------------------------------------------------\r\n", DateTime.UtcNow.ToString(), ex)); } catch (Exception ex1) { MessageBox.Show("Can't write to log. Reason: " + ex1.Message, null, MessageBoxButton.OK, MessageBoxImage.Error); } hasErrors = true; return; } DoubleAnimation LoadHeightAnim = (DoubleAnimation)FindResource("LoadHeightAnim"); DoubleAnimation LoadOpacityAnim = (DoubleAnimation)FindResource("LoadOpacityAnim"); LoadHeightAnim.Completed += new EventHandler(LoadHeightAnim_Completed); LoadOpacityAnim.Completed += new EventHandler(LoadOpacityAnim_Completed); if (!double.IsNaN(height)) { LoadHeightAnim.To = height; } else if (double.IsNaN(control.Height)) { LoadHeightAnim.To = 125; } else if (!double.IsNaN(Header.Height) && (DockPanel.GetDock(Header) == Dock.Top || DockPanel.GetDock(Header) == Dock.Bottom)) { LoadHeightAnim.To = control.Height + this.Header.Height + 5; } else { LoadHeightAnim.To = control.Height + 5; } RemoveItem.Header = string.Format((string)TryFindResource("Remove"), Info.Name); CustomizeItem.Header = string.Format((string)TryFindResource("Properties"), Info.Name); MinimizedItem.IsChecked = false; TileContentGrid.Children.Clear(); TileContentGrid.Children.Add(control); if (minimized) { normalHeight = height; this.MinimizedItem.IsChecked = true; } ChangeTheme(SidebarWindow.sett.theme); ChangeLocale(SidebarWindow.sett.locale); isLoaded = true; this.BeginAnimation(HeightProperty, LoadHeightAnim); TileContentGrid.BeginAnimation(OpacityProperty, LoadOpacityAnim); }