///<summary>Set userNumSelected to automatically select the corresponding user in the list (if available). ///Set isSimpleSwitch true if temporarily switching users for some reason. This will leave Security.CurUser alone and will instead ///indicate which user was chosen / successfully logged in via CurUserSimpleSwitch.</summary> public FormLogOn(long userNumSelected = 0, bool isSimpleSwitch = false, bool doRefreshSecurityCache = true) { InitializeComponent(); Plugins.HookAddCode(this, "FormLogOn.InitializeComponent_end"); Lan.F(this); if (userNumSelected > 0) { _userNameAutoSelect = Userods.GetUserNameNoCache(userNumSelected); } else if (Security.CurUser != null) { _userNameAutoSelect = Security.CurUser.UserName; } _isSimpleSwitch = isSimpleSwitch; _doRefreshSecurityCache = doRefreshSecurityCache; if (!isSimpleSwitch) //Not a temporary login. { try { //Use office default theme after we have the database data and until the user logs in below (the user may have a them override set). ODColorTheme.SetTheme((OdTheme)PrefC.GetInt(PrefName.ColorTheme)); } catch { //try/catch in case you are trying to convert from an older version of OD and need to update the DB. } } }
///<summary>This should be called when the user is changed (excluding temporay logins such as job review logins). ///In the future, we could also call this if we detect the office theme has changed via signal preference cache refresh or if ///another person using the same login information changes the theme for a group of users.</summary> public static void SetThemeForUserIfNeeded() { OdTheme themeDefault = OdTheme.Standard; try { themeDefault = (OdTheme)PrefC.GetInt(PrefName.ColorTheme); } catch { //try/catch in case you are trying to convert from an older version of OD and need to update the DB. } if (Security.CurUser == null) //no current user, set to the default practice theme. { ODColorTheme.SetTheme(themeDefault); return; } UserOdPref themePref = UserOdPrefs.GetByUserAndFkeyType(Security.CurUser.UserNum, UserOdFkeyType.UserTheme).FirstOrDefault(); //user theme not allowed or hasn't been set if (!PrefC.GetBool(PrefName.ThemeSetByUser) || themePref == null) { ODColorTheme.SetTheme(themeDefault); } else if (themePref != null) //user theme allowed but needs to update for user pref { ODColorTheme.SetTheme((OdTheme)themePref.Fkey); } }
///<summary></summary> public ODToolBar() { InitializeComponent(); // This call is required by the Windows.Forms Form Designer. ReloadBrushes(); ODColorTheme.AddOnThemeChanged(() => { ReloadBrushes(); }); toolTip1 = new ToolTip(); toolTip1.InitialDelay = 1100; }
private void DrawButton(Graphics g, ODToolBarButton button, Pen outlinePen, Pen dividerPen, SolidBrush textBrush, SolidBrush textBrushDisabled, LinearGradientBrush brushTogglePushed, LinearGradientBrush brushHover, LinearGradientBrush brushMedium, LinearGradientBrush brushPushed) { const int dropDownWidth = 15; //The width of the dropdown rectangle where the triangle shows. bool isNotify = (button.Style == ODToolBarButtonStyle.DropDownButton && !string.IsNullOrWhiteSpace(button.NotificationText)); //Notifies even when disabled. #region Separator if (button.Style == ODToolBarButtonStyle.Separator) { //was 112,128,144 //medium stripe g.DrawLine(new Pen(Color.FromArgb(190, 200, 210)), button.Bounds.Left, button.Bounds.Top + 1, button.Bounds.Left, button.Bounds.Bottom - 2); //dark stripe g.DrawLine(new Pen(Color.FromArgb(130, 140, 160)), button.Bounds.Left + 1, button.Bounds.Top, button.Bounds.Left + 1, button.Bounds.Bottom - 1); //white stripe g.DrawLine(new Pen(Color.FromArgb(255, 255, 255)), button.Bounds.Left + 2, button.Bounds.Top + 1, button.Bounds.Left + 2, button.Bounds.Bottom - 2); return; } #endregion //draw background if (!button.Enabled) { g.FillRectangle(brushMedium, button.Bounds); } else if (button.Style == ODToolBarButtonStyle.ToggleButton && button.Pushed) { g.FillRectangle(brushTogglePushed, button.Bounds); } else if (button.Style == ODToolBarButtonStyle.Label || button.Style == ODToolBarButtonStyle.PageNav) { g.FillRectangle(brushMedium, button.Bounds); } else { switch (button.State) { case ToolBarButtonState.Normal: //Control is 224,223,227 (==Ryan. This is not always true. Control is 240,240,240 for me.) g.FillRectangle(brushMedium, button.Bounds); break; case ToolBarButtonState.Hover: //this is lighter than control g.FillRectangle(brushHover, button.Bounds); break; case ToolBarButtonState.Pressed: //slightly darker than control g.FillRectangle(brushPushed, button.Bounds); break; case ToolBarButtonState.DropPressed: //left half looks like hover: g.FillRectangle(brushHover, new Rectangle(button.Bounds.X, button.Bounds.Y, button.Bounds.Width - 15, button.Bounds.Height)); //right section looks like Pressed: g.FillRectangle(brushPushed, new Rectangle(button.Bounds.X + button.Bounds.Width - 15, button.Bounds.Y, 15, button.Bounds.Height)); break; } } if (isNotify) //Override dropdown background to show notification color. { Rectangle rectDropDown = new Rectangle(button.Bounds.X + button.Bounds.Width - dropDownWidth, button.Bounds.Y, dropDownWidth, button.Bounds.Height); g.FillRectangle(_brushNotify, rectDropDown); //Fill the dropdown background area with the notification color. } //draw image and/or text Rectangle textRect; int textWidth = button.Bounds.Width; if (button.Style == ODToolBarButtonStyle.DropDownButton) { textWidth -= 15; } if (imageList != null && button.ImageIndex != -1 && button.ImageIndex < imageList.Images.Count) //draw image and text { Image img = imageList.Images[button.ImageIndex]; if (!button.Enabled) { ControlPaint.DrawImageDisabled(g, ODColorTheme.InvertImageIfNeeded(img) , button.Bounds.X + 3, button.Bounds.Y + 1, SystemColors.Control); textRect = new Rectangle(button.Bounds.X + imageList.ImageSize.Width + 3 , button.Bounds.Y, textWidth - imageList.ImageSize.Width - 3, button.Bounds.Height); } else if (button.State == ToolBarButtonState.Pressed) //draw slightly down and right { g.DrawImage(ODColorTheme.InvertImageIfNeeded(img), button.Bounds.X + 4, button.Bounds.Y + 2); textRect = new Rectangle(button.Bounds.X + 1 + imageList.ImageSize.Width + 3 , button.Bounds.Y + 1, textWidth - imageList.ImageSize.Width - 3, button.Bounds.Height); } else { g.DrawImage(ODColorTheme.InvertImageIfNeeded(img), button.Bounds.X + 3, button.Bounds.Y + 1); textRect = new Rectangle(button.Bounds.X + imageList.ImageSize.Width + 3 , button.Bounds.Y, textWidth - imageList.ImageSize.Width - 3, button.Bounds.Height); } } else //only draw text { if (button.Style == ODToolBarButtonStyle.Label || button.Style == ODToolBarButtonStyle.PageNav) { textRect = new Rectangle(button.Bounds.X, button.Bounds.Y , textWidth, button.Bounds.Height); } else if (button.State == ToolBarButtonState.Pressed) //draw slightly down and right { textRect = new Rectangle(button.Bounds.X + 1, button.Bounds.Y + 1 , textWidth, button.Bounds.Height); } else { textRect = new Rectangle(button.Bounds.X, button.Bounds.Y , textWidth, button.Bounds.Height); } } StringFormat format; if (imageList != null && button.ImageIndex != -1) //if there is an image //draw text very close to image { format = new StringFormat(); format.Alignment = StringAlignment.Near; format.LineAlignment = StringAlignment.Center; if (button.Enabled) { g.DrawString(button.Text, Font, textBrush, textRect, format); } else { g.DrawString(button.Text, Font, textBrushDisabled, textRect, format); } } else { format = new StringFormat(); format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center; if (button.Enabled) { g.DrawString(button.Text, Font, textBrush, textRect, format); //For page navigation buttons we ALWAYS show the text box so that users know they can type in the box to change pages. if (button.Style == ODToolBarButtonStyle.PageNav) { //Because we do not display zeros to users (e.g. 001 / 135) and instead leave them off (e.g. 1 / 135) the width will be lopsided //We need to draw each side of the page navigation (and pad a little) individually. SizeF size = g.MeasureString("/", Font); g.DrawString(button.PageValue.ToString(), Font, textBrush , new Rectangle(textRect.Location, new Size((textRect.Width / 2) - (int)(size.Width / 2) - 2, textRect.Height)) , new StringFormat() { Alignment = StringAlignment.Far, LineAlignment = StringAlignment.Center }); g.DrawString(button.PageMax.ToString(), Font, textBrush , new Rectangle(new Point(textRect.X + (textRect.Width / 2) + (int)(size.Width / 2) + 2, textRect.Y) , new Size((textRect.Width / 2) - (int)(size.Width / 2), textRect.Height)) , new StringFormat() { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Center }); //Only add the text box for page navigation once. //However, we need to add the text box here in the paint otherwise we don't know how large to make the text box. if (textPageNav == null) { textPageNav = new ValidNum(); textPageNav.Size = new Size((button.Bounds.Width - 10) / 2, button.Bounds.Height); textPageNav.KeyDown += TextPageNav_KeyDown; textPageNav.MinVal = 1; //There is no such thing as 0 pages in a preview, always set min to 1. textPageNav.RightToLeft = RightToLeft.Yes; this.Controls.Add(textPageNav); } //Always recalculate the location of the button just in case someone changes the size of another button on the toolbar. textPageNav.Location = new Point(button.Bounds.X + 1, button.Bounds.Y + 2); //Nav text changes constantly so we need to update it when redrawing. textPageNav.Text = button.PageValue.ToString(); if (button.PageMax != 0) { textPageNav.MaxVal = button.PageMax; } } } else { g.DrawString(button.Text, Font, textBrushDisabled, textRect, format); } } //draw outline //Pen penR=penMedium;//new Pen(Color.FromArgb(180,180,180)); if (!button.Enabled) { //no outline g.DrawLine(dividerPen, button.Bounds.Right - 1, button.Bounds.Top, button.Bounds.Right - 1, button.Bounds.Bottom - 1); //vertical line on the right side } else if (button.Style == ODToolBarButtonStyle.ToggleButton && button.Pushed) { g.DrawRectangle(outlinePen, new Rectangle(button.Bounds.X, button.Bounds.Y , button.Bounds.Width - 1, button.Bounds.Height - 1)); } else if (button.Style == ODToolBarButtonStyle.Label || button.Style == ODToolBarButtonStyle.PageNav) { //no outline g.DrawLine(dividerPen, button.Bounds.Right - 1, button.Bounds.Top, button.Bounds.Right - 1, button.Bounds.Bottom - 1); //vertical line on the right side } else { switch (button.State) { case ToolBarButtonState.Normal: //no outline g.DrawLine(dividerPen, button.Bounds.Right - 1, button.Bounds.Top, button.Bounds.Right - 1, button.Bounds.Bottom - 1); break; case ToolBarButtonState.Hover: g.DrawRectangle(outlinePen, new Rectangle(button.Bounds.X, button.Bounds.Y, button.Bounds.Width - 1, button.Bounds.Height - 1)); break; case ToolBarButtonState.Pressed: g.DrawRectangle(outlinePen, new Rectangle(button.Bounds.X, button.Bounds.Y, button.Bounds.Width - 1, button.Bounds.Height - 1)); break; case ToolBarButtonState.DropPressed: g.DrawRectangle(outlinePen, new Rectangle(button.Bounds.X, button.Bounds.Y, button.Bounds.Width - 1, button.Bounds.Height - 1)); break; } } if (button.Style == ODToolBarButtonStyle.DropDownButton) { int adjDown = 0; //The distance to push the triangle down to show the notification text. if (isNotify) { adjDown = 6; //Draw the notification text. Size sizeText = TextRenderer.MeasureText(button.NotificationText, Font); g.DrawString(button.NotificationText, Font, (button.Enabled?textBrush:textBrushDisabled), button.Bounds.X + button.Bounds.Width + 1 - (dropDownWidth + sizeText.Width) / 2f, button.Bounds.Y + 2 + sizeText.Height / 2f, format); } Point[] triangle = new Point[3]; triangle[0] = new Point(button.Bounds.X + button.Bounds.Width - 11 , button.Bounds.Y + button.Bounds.Height / 2 - 2 + adjDown); triangle[1] = new Point(button.Bounds.X + button.Bounds.Width - 4 , button.Bounds.Y + button.Bounds.Height / 2 - 2 + adjDown); triangle[2] = new Point(button.Bounds.X + button.Bounds.Width - 8 , button.Bounds.Y + button.Bounds.Height / 2 + 2 + adjDown); if (button.Enabled) { g.FillPolygon(textBrush, triangle); } else { g.FillPolygon(textBrushDisabled, triangle); } if (button.State != ToolBarButtonState.Normal && button.Enabled) { g.DrawLine(outlinePen, button.Bounds.X + button.Bounds.Width - 15, button.Bounds.Y , button.Bounds.X + button.Bounds.Width - 15, button.Bounds.Y + button.Bounds.Height); } } }