123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- //
- // KMSecureLimitAlertView.swift
- // PDF Master
- //
- // Created by tangchao on 2023/2/7.
- //
- import Cocoa
- typealias KMSecureLimitAlertViewItemClick = (Int) -> ()
- class KMSecureLimitAlertView: NSView {
- var titleLabel = NSTextField(labelWithString: "")
- private var despLabel = NSTextField(wrappingLabelWithString: "")
- var deleteButton = NSButton()
-
- var funcButtonVC: KMDesignButton?
-
- var itemClick: KMSecureLimitAlertViewItemClick?
- private var funcButtonSize: NSSize = NSMakeSize(163, 32)
-
- override var isFlipped: Bool {
- return true
- }
-
- override init(frame frameRect: NSRect) {
- super.init(frame: frameRect)
-
- initSubViews()
- }
-
- required init?(coder: NSCoder) {
- super.init(coder: coder)
-
- initSubViews()
- }
-
- public func initSubViews() {
- self.addSubview(self.titleLabel)
- addSubview(despLabel)
- self.addSubview(self.deleteButton)
-
- self.funcButtonVC = KMDesignButton(withType: .Text)
- self.addSubview(self.funcButtonVC!.view)
-
- self.wantsLayer = true
- layer?.backgroundColor = NSColor(hex: "#E8F5FF").cgColor
- layer?.cornerRadius = 8
- self.shadow = NSShadow()
- self.layer?.shadowColor = NSColor(hex: "#00000029").cgColor
- self.layer?.shadowOpacity = 1
- self.layer?.shadowRadius = 8
- self.layer?.shadowOffset = CGSize(width: 0, height: -3)
-
- self.titleLabel.stringValue = NSLocalizedString("File Restricted", comment: "")
- self.titleLabel.textColor = NSColor.titleColor()
- self.titleLabel.font = NSFont.SFProTextRegular(14)
-
- despLabel.stringValue = NSLocalizedString("The file is protected with a password. ", comment: "")
- let ps = NSMutableParagraphStyle()
- ps.lineSpacing = 7
- despLabel.attributedStringValue = NSAttributedString(string: despLabel.stringValue, attributes: [.foregroundColor : NSColor.despColor(),
- .font : NSFont.SFProTextRegular(14),
- .paragraphStyle : ps
- ])
-
- self.deleteButton.isBordered = false
- self.deleteButton.image = NSImage(named: "KMImageNameCloseProgress12")
- self.deleteButton.target = self
- self.deleteButton.action = #selector(deleteButtonAction)
-
- self.funcButtonVC?.stringValue = NSLocalizedString("Enter Password", comment: "")
- self.funcButtonVC?.target = self
- self.funcButtonVC?.action = #selector(funcButtonAction)
- self.funcButtonVC?.button(type: .Ghost, size: .m)
-
- let size = self.funcButtonVC?.stringValue.boundingRect(with: NSMakeSize(1000, self.funcButtonSize.height), options: [.usesLineFragmentOrigin, .usesFontLeading], attributes: [.foregroundColor : NSColor.buttonTitleColor(), .font : NSFont.SFProTextRegular(14)]).size
- if (size == nil || size!.width < 40) {
- self.funcButtonSize.width = 70
- } else {
- self.funcButtonSize.width = size!.width + 34
- }
- }
-
- override func layout() {
- super.layout()
-
- let width: CGFloat = NSWidth(self.bounds)
- let height: CGFloat = NSHeight(self.bounds)
-
- let leftMargin: CGFloat = 16
- self.titleLabel.frame = NSMakeRect(leftMargin, 16+4, width-leftMargin-60, 18)
-
- let despX: CGFloat = 16
- let despY: CGFloat = self.titleLabel.frame.maxY+8+4
- despLabel.frame = NSMakeRect(despX, despY, width-despX-36, height-despY-45)
-
- self.deleteButton.frame = NSMakeRect(width-34, 10, 24, 24)
-
- let funcButtonSize = self.funcButtonSize
- self.funcButtonVC?.view.frame = NSMakeRect(width-funcButtonSize.width-leftMargin, height-funcButtonSize.height-16, funcButtonSize.width, funcButtonSize.height)
- }
-
- @objc private func deleteButtonAction() {
- guard let callback = self.itemClick else {
- return
- }
-
- callback(1)
- }
-
- @objc private func funcButtonAction() {
- guard let callback = self.itemClick else {
- return
- }
-
- callback(2)
- }
- }
|