1 /* 2 KeePass Password Safe - The Open-Source Password Manager 3 Copyright (C) 2003-2021 Dominik Reichl <dominik.reichl@t-online.de> 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 2 of the License, or 8 (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program; if not, write to the Free Software 17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 */ 19 20 using System; 21 using System.Collections.Generic; 22 using System.ComponentModel; 23 using System.Diagnostics; 24 using System.Drawing; 25 using System.Text; 26 27 using KeePass.UI; 28 29 namespace KeePass.App.Configuration 30 { 31 [Flags] 32 public enum AceKeyUIFlags : ulong 33 { 34 None = 0, 35 EnablePassword = 0x1, 36 EnableKeyFile = 0x2, 37 EnableUserAccount = 0x4, 38 EnableHidePassword = 0x8, 39 DisablePassword = 0x100, 40 DisableKeyFile = 0x200, 41 DisableUserAccount = 0x400, 42 DisableHidePassword = 0x800, 43 CheckPassword = 0x10000, 44 CheckKeyFile = 0x20000, 45 CheckUserAccount = 0x40000, 46 CheckHidePassword = 0x80000, 47 UncheckPassword = 0x1000000, 48 UncheckKeyFile = 0x2000000, 49 UncheckUserAccount = 0x4000000, 50 UncheckHidePassword = 0x8000000 51 } 52 53 [Flags] 54 public enum AceUIFlags : ulong 55 { 56 None = 0, 57 58 DisableOptions = 0x1, 59 DisablePlugins = 0x2, 60 DisableTriggers = 0x4, 61 DisableKeyChangeDays = 0x8, 62 HidePwQuality = 0x10, 63 DisableUpdateCheck = 0x20, 64 DisableXmlReplace = 0x40, 65 DisableDbSettings = 0x80, 66 67 HideBuiltInPwGenPrfInEntryDlg = 0x10000, 68 ShowLastAccessTime = 0x20000, 69 HideNewDbInfoDialogs = 0x40000, 70 HideAutoTypeObfInfo = 0x80000, 71 NoQuickSearchClear = 0x100000, 72 SecureDesktopIme = 0x200000 73 } 74 75 [Flags] 76 public enum AceAutoTypeCtxFlags : long 77 { 78 None = 0, 79 80 ColTitle = 0x1, 81 ColUserName = 0x2, 82 ColPassword = 0x4, 83 ColUrl = 0x8, 84 ColNotes = 0x10, 85 ColSequence = 0x20, 86 ColSequenceComments = 0x40, 87 88 Default = (ColTitle | ColUserName | ColUrl | ColSequence) 89 } 90 91 public sealed class AceUI 92 { AceUI()93 public AceUI() 94 { 95 } 96 97 private AceTrayIcon m_tray = new AceTrayIcon(); 98 public AceTrayIcon TrayIcon 99 { 100 get { return m_tray; } 101 set 102 { 103 if(value == null) throw new ArgumentNullException("value"); 104 m_tray = value; 105 } 106 } 107 108 private AceHiding m_uiHiding = new AceHiding(); 109 public AceHiding Hiding 110 { 111 get { return m_uiHiding; } 112 set 113 { 114 if(value == null) throw new ArgumentNullException("value"); 115 m_uiHiding = value; 116 } 117 } 118 119 private bool m_bRepeatPwOnlyWhenHidden = true; 120 [DefaultValue(true)] 121 public bool RepeatPasswordOnlyWhenHidden 122 { 123 get { return m_bRepeatPwOnlyWhenHidden; } 124 set { m_bRepeatPwOnlyWhenHidden = value; } 125 } 126 127 private AceFont m_font = new AceFont(); 128 public AceFont StandardFont 129 { 130 get { return m_font; } 131 set 132 { 133 if(value == null) throw new ArgumentNullException("value"); 134 m_font = value; 135 } 136 } 137 138 private AceFont m_fontPasswords = new AceFont(true); 139 public AceFont PasswordFont 140 { 141 get { return m_fontPasswords; } 142 set 143 { 144 if(value == null) throw new ArgumentNullException("value"); 145 m_fontPasswords = value; 146 } 147 } 148 149 private bool m_bForceSysFont = true; 150 [DefaultValue(true)] 151 public bool ForceSystemFontUnix 152 { 153 get { return m_bForceSysFont; } 154 set { m_bForceSysFont = value; } 155 } 156 157 private BannerStyle m_bannerStyle = BannerStyle.WinVistaBlack; 158 public BannerStyle BannerStyle 159 { 160 get { return m_bannerStyle; } 161 set { m_bannerStyle = value; } 162 } 163 164 private bool m_bShowImportStatusDlg = false; 165 [DefaultValue(false)] 166 public bool ShowImportStatusDialog 167 { 168 get { return m_bShowImportStatusDlg; } 169 set { m_bShowImportStatusDlg = value; } 170 } 171 172 private bool m_bShowRecycleDlg = true; 173 [DefaultValue(true)] 174 public bool ShowRecycleConfirmDialog 175 { 176 get { return m_bShowRecycleDlg; } 177 set { m_bShowRecycleDlg = value; } 178 } 179 180 private bool m_bShowDbMntncResDlg = true; 181 [DefaultValue(true)] 182 public bool ShowDbMntncResultsDialog 183 { 184 get { return m_bShowDbMntncResDlg; } 185 set { m_bShowDbMntncResDlg = value; } 186 } 187 188 private bool m_bShowEmSheetDlg = true; 189 [DefaultValue(true)] 190 public bool ShowEmSheetDialog 191 { 192 get { return m_bShowEmSheetDlg; } 193 set { m_bShowEmSheetDlg = value; } 194 } 195 196 private bool m_bShowDbOpenUnkVerDlg = true; 197 [DefaultValue(true)] 198 public bool ShowDbOpenUnkVerDialog 199 { 200 get { return m_bShowDbOpenUnkVerDlg; } 201 set { m_bShowDbOpenUnkVerDlg = value; } 202 } 203 204 // private bool m_bUseCustomTsRenderer = true; 205 // [DefaultValue(true)] 206 // public bool UseCustomToolStripRenderer 207 // { 208 // get { return m_bUseCustomTsRenderer; } 209 // set { m_bUseCustomTsRenderer = value; } 210 // } 211 212 private string m_strToolStripRenderer = string.Empty; 213 [DefaultValue("")] 214 public string ToolStripRenderer 215 { 216 get { return m_strToolStripRenderer; } 217 set 218 { 219 if(value == null) throw new ArgumentNullException("value"); 220 m_strToolStripRenderer = value; 221 } 222 } 223 224 private bool m_bTreeViewShowLines = false; 225 [DefaultValue(false)] 226 public bool TreeViewShowLines 227 { 228 get { return m_bTreeViewShowLines; } 229 set { m_bTreeViewShowLines = value; } 230 } 231 232 private bool m_bOptScreenReader = false; 233 [DefaultValue(false)] 234 public bool OptimizeForScreenReader 235 { 236 get { return m_bOptScreenReader; } 237 set { m_bOptScreenReader = value; } 238 } 239 240 private string m_strDataViewerRect = string.Empty; 241 [DefaultValue("")] 242 public string DataViewerRect 243 { 244 get { return m_strDataViewerRect; } 245 set 246 { 247 if(value == null) throw new ArgumentNullException("value"); 248 m_strDataViewerRect = value; 249 } 250 } 251 252 private string m_strDataEditorRect = string.Empty; 253 [DefaultValue("")] 254 public string DataEditorRect 255 { 256 get { return m_strDataEditorRect; } 257 set 258 { 259 if(value == null) throw new ArgumentNullException("value"); 260 m_strDataEditorRect = value; 261 } 262 } 263 264 private AceFont m_deFont = new AceFont(); 265 public AceFont DataEditorFont 266 { 267 get { return m_deFont; } 268 set 269 { 270 if(value == null) throw new ArgumentNullException("value"); 271 m_deFont = value; 272 } 273 } 274 275 private bool m_bDeWordWrap = true; 276 [DefaultValue(true)] 277 public bool DataEditorWordWrap 278 { 279 get { return m_bDeWordWrap; } 280 set { m_bDeWordWrap = value; } 281 } 282 283 private string m_strCharPickerRect = string.Empty; 284 [DefaultValue("")] 285 public string CharPickerRect 286 { 287 get { return m_strCharPickerRect; } 288 set 289 { 290 if(value == null) throw new ArgumentNullException("value"); 291 m_strCharPickerRect = value; 292 } 293 } 294 295 private string m_strAutoTypeCtxRect = string.Empty; 296 [DefaultValue("")] 297 public string AutoTypeCtxRect 298 { 299 get { return m_strAutoTypeCtxRect; } 300 set 301 { 302 if(value == null) throw new ArgumentNullException("value"); 303 m_strAutoTypeCtxRect = value; 304 } 305 } 306 307 private long m_lAutoTypeCtxFlags = (long)AceAutoTypeCtxFlags.Default; 308 [DefaultValue((long)AceAutoTypeCtxFlags.Default)] 309 public long AutoTypeCtxFlags 310 { 311 get { return m_lAutoTypeCtxFlags; } 312 set { m_lAutoTypeCtxFlags = value; } 313 } 314 315 private string m_strAutoTypeCtxColWidths = string.Empty; 316 [DefaultValue("")] 317 public string AutoTypeCtxColumnWidths 318 { 319 get { return m_strAutoTypeCtxColWidths; } 320 set 321 { 322 if(value == null) throw new ArgumentNullException("value"); 323 m_strAutoTypeCtxColWidths = value; 324 } 325 } 326 327 private ulong m_uUIFlags = (ulong)AceUIFlags.None; 328 public ulong UIFlags 329 { 330 get { return m_uUIFlags; } 331 set { m_uUIFlags = value; } 332 } 333 334 private ulong m_uKeyCreationFlags = (ulong)AceKeyUIFlags.None; 335 public ulong KeyCreationFlags 336 { 337 get { return m_uKeyCreationFlags; } 338 set { m_uKeyCreationFlags = value; } 339 } 340 341 private ulong m_uKeyPromptFlags = (ulong)AceKeyUIFlags.None; 342 public ulong KeyPromptFlags 343 { 344 get { return m_uKeyPromptFlags; } 345 set { m_uKeyPromptFlags = value; } 346 } 347 348 // private bool m_bEditCancelConfirmation = true; 349 // public bool EntryEditCancelConfirmation 350 // { 351 // get { return m_bEditCancelConfirmation; } 352 // set { m_bEditCancelConfirmation = value; } 353 // } 354 355 private bool m_bAdvATCmds = false; 356 [DefaultValue(false)] 357 public bool ShowAdvAutoTypeCommands 358 { 359 get { return m_bAdvATCmds; } 360 set { m_bAdvATCmds = value; } 361 } 362 363 private bool m_bSecDeskSound = true; 364 [DefaultValue(true)] 365 public bool SecureDesktopPlaySound 366 { 367 get { return m_bSecDeskSound; } 368 set { m_bSecDeskSound = value; } 369 } 370 } 371 372 public sealed class AceHiding 373 { AceHiding()374 public AceHiding() 375 { 376 } 377 378 private bool m_bRememberHidePwsMain = true; 379 [DefaultValue(true)] 380 public bool RememberHidingPasswordsMain 381 { 382 get { return m_bRememberHidePwsMain; } 383 set { m_bRememberHidePwsMain = value; } 384 } 385 386 private bool m_bSepHiding = false; 387 [DefaultValue(false)] 388 public bool SeparateHidingSettings 389 { 390 get { return m_bSepHiding; } 391 set { m_bSepHiding = value; } 392 } 393 394 private bool m_bHideInEntryDialog = true; 395 [DefaultValue(true)] 396 public bool HideInEntryWindow 397 { 398 get { return m_bHideInEntryDialog; } 399 set { m_bHideInEntryDialog = value; } 400 } 401 402 private bool m_bUnhideBtnAlsoUnhidesSec = false; 403 [DefaultValue(false)] 404 public bool UnhideButtonAlsoUnhidesSource 405 { 406 get { return m_bUnhideBtnAlsoUnhidesSec; } 407 set { m_bUnhideBtnAlsoUnhidesSec = value; } 408 } 409 } 410 411 public sealed class AceFont 412 { 413 private Font m_fCached = null; 414 private bool m_bCacheValid = false; 415 416 private string m_strFamily = "Microsoft Sans Serif"; 417 public string Family 418 { 419 get { return m_strFamily; } 420 set 421 { 422 if(value == null) throw new ArgumentNullException("value"); 423 m_strFamily = value; 424 m_bCacheValid = false; 425 } 426 } 427 428 private float m_fSize = 8.25f; 429 public float Size 430 { 431 get { return m_fSize; } 432 set { m_fSize = value; m_bCacheValid = false; } 433 } 434 435 private GraphicsUnit m_gu = GraphicsUnit.Point; 436 public GraphicsUnit GraphicsUnit 437 { 438 get { return m_gu; } 439 set { m_gu = value; m_bCacheValid = false; } 440 } 441 442 private FontStyle m_fStyle = FontStyle.Regular; 443 public FontStyle Style 444 { 445 get { return m_fStyle; } 446 set { m_fStyle = value; m_bCacheValid = false; } 447 } 448 449 private bool m_bOverrideUIDefault = false; 450 public bool OverrideUIDefault 451 { 452 get { return m_bOverrideUIDefault; } 453 set { m_bOverrideUIDefault = value; } 454 } 455 AceFont()456 public AceFont() 457 { 458 } 459 AceFont(Font f)460 public AceFont(Font f) 461 { 462 if(f == null) throw new ArgumentNullException("f"); 463 464 this.Family = f.FontFamily.Name; 465 m_fSize = f.Size; 466 m_fStyle = f.Style; 467 m_gu = f.Unit; 468 } 469 AceFont(bool bMonospace)470 public AceFont(bool bMonospace) 471 { 472 if(bMonospace) m_strFamily = "Courier New"; 473 } 474 ToFont()475 public Font ToFont() 476 { 477 if(m_bCacheValid) return m_fCached; 478 479 m_fCached = FontUtil.CreateFont(m_strFamily, m_fSize, m_fStyle, m_gu); 480 m_bCacheValid = true; 481 return m_fCached; 482 } 483 } 484 } 485