curtis
14小時前 3af5c004b4f2d2005d22ee85dccc2c80a66b1556
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import { ref, onMounted } from 'vue';
 
export function usePatchFomLogic() {
  // --- State Mapped from Delphi UI Components ---
  
  // ScannerGB
  const isDpiEnabled = ref<boolean>(false); // Enabled = False in DFM
  const dpi = ref<string>('240');
  const borderClear = ref<boolean>(false);
  const deskew = ref<boolean>(false);
  const reverse = ref<boolean>(false);
  const duplex = ref<boolean>(false); // Enabled = False in DFM
  
  // ImgSetGB
  const imgSetUse = ref<boolean>(false);
  const bright = ref<number>(0);
  const contrast = ref<number>(0);
  
  // ScanShowRG (0 = 清楚影像, 1 = 模糊影像, 2 = 無影像)
  const scanShowMode = ref<string>('0');
  
  // ScanRotateRG (0 = 無, 1 = 左轉90度, 2 = 轉180度, 3 = 右轉90度)
  const scanRotate = ref<string>('0');
  
  // BlankGB
  const blankUse = ref<boolean>(false);
  const blankSize = ref<number>(0);
  
  // Public property equivalent
  const SelectOk = ref<boolean>(false);
 
  // --- Mock external Global Variables from CB_IMGPSScanImp ---
  // In a real application, these would be imported from a store or context
  const mockGlobalState = {
    Def_DeviceDelete: false,
    Def_DeviceDeleteSize: 1024,
    Def_ScanDpi: 240,
    Def_ScanDuplex: true,
    Def_ScannerReverse: false,
    Def_BoardClear: true,
    Def_ScanDeskew: true,
    Def_ScanImgSetUse: false,
    Def_ScanBright: 10,
    Def_ScanContrast: 20,
    Def_ScanRotate: 90, // Mapped to 3 (右轉90度) in switch statement
    Def_ScanImgShowMode: 1 // Mapped to 1 (模糊影像)
  };
 
  // --- Methods ---
 
  const FormCreate = () => {
    // Equivalent to PostMessage(Handle,WM_ACTIVATE,WA_CLICKACTIVE,0);
    console.log('FormCreate: PatchDlg activated');
  };
 
  const BlankuseCBClick = () => {
    // If BlankuseCB.Checked Then SpinEdit5.Enabled := True Else SpinEdit5.Enabled := False;
    // handled via Vue binding `:disabled="!blankUse"` in template, 
    // but kept here for logical representation
    console.log('BlankuseCBClick triggered, blankUse:', blankUse.value);
  };
 
  const DefaultBtClick = () => {
    // Reset to defaults
    blankUse.value = mockGlobalState.Def_DeviceDelete;
    blankSize.value = mockGlobalState.Def_DeviceDeleteSize;
    
    dpi.value = mockGlobalState.Def_ScanDpi.toString();
    duplex.value = mockGlobalState.Def_ScanDuplex;
    reverse.value = mockGlobalState.Def_ScannerReverse;
    borderClear.value = mockGlobalState.Def_BoardClear;
    deskew.value = mockGlobalState.Def_ScanDeskew;
    
    imgSetUse.value = mockGlobalState.Def_ScanImgSetUse;
    bright.value = mockGlobalState.Def_ScanBright;
    contrast.value = mockGlobalState.Def_ScanContrast;
    
    switch (mockGlobalState.Def_ScanRotate) {
      case 0: scanRotate.value = '0'; break;
      case 270: scanRotate.value = '1'; break;
      case 180: scanRotate.value = '2'; break;
      case 90: scanRotate.value = '3'; break;
      default: scanRotate.value = '0'; break;
    }
    
    switch (mockGlobalState.Def_ScanImgShowMode) {
      case 0: scanShowMode.value = '0'; break;
      case 1: scanShowMode.value = '1'; break;
      case 2: scanShowMode.value = '2'; break;
      default: scanShowMode.value = '0'; break;
    }
    
    console.log('Default values loaded');
  };
 
  const OkBtClick = () => {
    SelectOk.value = true;
    closeForm('ok');
  };
 
  const CancelBtClick = () => {
    SelectOk.value = false;
    closeForm('cancel');
  };
 
  const ComboBox1KeyPress = (e: KeyboardEvent) => {
    // IF ((Ord(Key) < 48) or (ord(Key) > 57)) and (ord(key) <> 8) Then key := Chr(0);
    const charCode = e.charCode;
    if ((charCode < 48 || charCode > 57) && e.key !== 'Backspace') {
      e.preventDefault();
    }
  };
 
  const ComboBox1Exit = () => {
    // IF ComboBox1.Text = '' Then ComBoBox1.Text := '240';
    if (!dpi.value) {
      dpi.value = '240';
    }
  };
 
  // Helper function to simulate modal close
  const closeForm = (result: string) => {
    console.log(`PatchDlg closing with result: ${result}`);
  };
 
  onMounted(() => {
    FormCreate();
    // Usually you'd call DefaultBtClick() here or in the parent before opening
  });
 
  return {
    // State
    isDpiEnabled,
    dpi,
    borderClear,
    deskew,
    reverse,
    duplex,
    imgSetUse,
    bright,
    contrast,
    scanShowMode,
    scanRotate,
    blankUse,
    blankSize,
    
    // Actions
    BlankuseCBClick,
    DefaultBtClick,
    OkBtClick,
    CancelBtClick,
    ComboBox1KeyPress,
    ComboBox1Exit
  };
}