Project

General

Profile

signature_wiki_example.p

signature wiki example to test with simulator - Sergey Ivanovskiy, 11/13/2026 12:52 AM

Download (2.89 KB)

 
1
/*------------------------------------------------------------------------
2
    File        : signature_wiki_example.p
3
    Purpose     : The "Pure" 4GL Widget Usage Example of the wiki page
4
                  [[p2j:Signature Tablet Widget]] (#11409), kept identical
5
                  to the wiki text so the published example is verified.
6

    
7
    Notes       : The user signs on the pad (with
8
                  webClient/signaturePadInSimMode = TRUE: on the widget
9
                  canvas with the mouse), each PEN-UP shows the number of
10
                  captured points, Clear erases the ink and Accept saves the
11
                  signature as a monochrome BMP in SESSION:TEMP-DIRECTORY
12
                  (on the FWD server).
13

    
14
                  Run: https://localhost:7443/gui?prog=signature/signature_wiki_example.p
15
  ----------------------------------------------------------------------*/
16

    
17
DEFINE VARIABLE hSig  AS HANDLE    NO-UNDO.
18
DEFINE VARIABLE mImg  AS MEMPTR    NO-UNDO.
19
DEFINE VARIABLE cFile AS CHARACTER NO-UNDO.
20

    
21
DEFINE BUTTON btnStart  LABEL "Start"  SIZE-PIXELS 80 BY 26.
22
DEFINE BUTTON btnClear  LABEL "Clear"  SIZE-PIXELS 80 BY 26.
23
DEFINE BUTTON btnAccept LABEL "Accept" SIZE-PIXELS 80 BY 26.
24

    
25
DEFINE FRAME fMain
26
   btnStart  AT X 10  Y 320
27
   btnClear  AT X 100 Y 320
28
   btnAccept AT X 190 Y 320
29
   WITH SIZE-PIXELS 420 BY 360 THREE-D NO-BOX.
30

    
31
/* the window must hold the frame, or the widget extends past its right edge */
32
ASSIGN
33
   CURRENT-WINDOW:TITLE         = "Signature"
34
   CURRENT-WINDOW:WIDTH-PIXELS  = 420
35
   CURRENT-WINDOW:HEIGHT-PIXELS = 360.
36

    
37
CREATE SIGNATURE hSig
38
   ASSIGN FRAME         = FRAME fMain:HANDLE
39
          X             = 10
40
          Y             = 10
41
          WIDTH-PIXELS  = 400
42
          HEIGHT-PIXELS = 300
43
          SENSITIVE     = TRUE
44
          VISIBLE       = TRUE.
45

    
46
ON "PEN-UP" OF hSig DO:
47
   MESSAGE STRING(hSig:NumberOfTabletPoints()) "points captured".
48
END.
49

    
50
ON CHOOSE OF btnStart IN FRAME fMain DO:
51
   hSig:SetTabletState(1).
52
   hSig:ClearTablet().
53
   /* persistent ink on the LCD */
54
   hSig:SetLCDCaptureMode(2).
55
END.
56

    
57
ON CHOOSE OF btnClear IN FRAME fMain DO:
58
   hSig:ClearTablet().
59
   /* mode 0: clear the LCD */
60
   hSig:LCDRefresh(0, 0, 0, 400, 300).
61
END.
62

    
63
ON CHOOSE OF btnAccept IN FRAME fMain DO:
64
   IF hSig:NumberOfTabletPoints() = 0 THEN
65
   DO:
66
      MESSAGE "Please sign first." VIEW-AS ALERT-BOX.
67
      RETURN NO-APPLY.
68
   END.
69

    
70
   /* monochrome BMP, 571 x 200, centered and zoomed */
71
   hSig:SetImageFileFormat(2).
72
   hSig:SetImageXSize(571).
73
   hSig:SetImageYSize(200).
74
   hSig:SetImagePenWidth(11).
75
   hSig:SetJustifyMode(5).
76

    
77
   mImg  = hSig:GetSignatureImage("bmp", "Format1bppIndexed").
78
   cFile = SESSION:TEMP-DIRECTORY + "signature.bmp".
79
   COPY-LOB FROM mImg TO FILE cFile NO-CONVERT.
80
   SET-SIZE(mImg) = 0.
81

    
82
   hSig:SetTabletState(0).
83
   MESSAGE "Signature saved to" cFile VIEW-AS ALERT-BOX.
84
END.
85

    
86
ENABLE btnStart btnClear btnAccept WITH FRAME fMain.
87
WAIT-FOR CLOSE OF CURRENT-WINDOW.