PMJP.MOD 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. (*-------------------------------------------------------------------------*
  2. * *
  3. * PMJP.MOD - Presentation manager demo *
  4. * *
  5. * COPYRIGHT (C) 1989..1992 Clarion Software Corporation. *
  6. * All Rights Reserved *
  7. * *
  8. *--------------------------------------------------------------------------*)
  9. MODULE PMJP;
  10. (* Simple demonstation of a PM Application using Win and Gpi calls *)
  11. (* This application can be used as the basis of a shell for your own
  12. application
  13. *)
  14. (*# call(same_ds => off) *)
  15. (*# data(heap_size=> 3000) *)
  16. IMPORT OS2DEF,Win,Gpi,Dos,Lib,SYSTEM;
  17. FROM OS2DEF IMPORT HDC,HRGN,HAB,HPS,HBITMAP,HWND,HMODULE,HSEM,
  18. POINTL,RECTL,PID,TID,LSET,NULL,
  19. COLOR,NullVar,NullStr,BOOL ;
  20. CONST
  21. WindowId = 255;
  22. VAR
  23. Hab : HAB;
  24. Hps : HPS;
  25. BackColor : COLOR;
  26. ForeColor : COLOR;
  27. ChangeBack: BOOLEAN;
  28. (*-------------------- Error reporting procedure ---------------------*)
  29. PROCEDURE Error;
  30. VAR
  31. errinf : Win.PERRINFO;
  32. (*# save,
  33. data(near_ptr=>off) *)
  34. emsg : POINTER TO ARRAY[0..255] OF CHAR;
  35. (*# restore *)
  36. mbid : Win.MBID;
  37. win : HWND;
  38. BEGIN
  39. errinf := Win.GetErrorInfo(Hab);
  40. IF errinf=FarNIL THEN RETURN END;
  41. emsg := [SYSTEM.Seg(errinf^):CARDINAL([SYSTEM.Seg(errinf^):errinf^.Msg]^)];
  42. win := Win.QueryActiveWindow(Win.HWND_DESKTOP,B_FALSE);
  43. mbid := Win.MessageBox(Win.HWND_DESKTOP,win,emsg^,'Error Returned',0,
  44. Win.MB_ICONHAND+Win.MB_CANCEL+Win.MB_MOVEABLE);
  45. IF Win.FreeErrorInfo(errinf^) THEN END;
  46. END Error;
  47. (*-------------------- JP drawing ---------------------------------------*)
  48. PROCEDURE DrawTitle;
  49. (* Creates font and displays message *)
  50. CONST
  51. Title1 = 'TopSpeed Modula-2 Demonstration Program';
  52. Title2 = 'Mouse button 1 cycles Foreground';
  53. Title3 = 'Mouse button 2 cycles Background';
  54. Title4 = 'F3 exits program';
  55. VAR
  56. pt : POINTL;
  57. b : Gpi.SIZEF;
  58. BEGIN
  59. pt.x := 1; pt.y := 1;
  60. IF NOT Gpi.SetCharShear(Hps,pt) THEN Error END;
  61. pt.x := 20; pt.y := 220;
  62. IF Gpi.CharStringAt(Hps,pt,SIZE(Title1),Title1)<0 THEN Error END;
  63. pt.x := 20; pt.y := 200;
  64. IF Gpi.CharStringAt(Hps,pt,SIZE(Title2),Title2)<0 THEN Error END;
  65. pt.x := 20; pt.y := 190;
  66. IF Gpi.CharStringAt(Hps,pt,SIZE(Title3),Title3)<0 THEN Error END;
  67. pt.x := 20; pt.y := 180;
  68. IF Gpi.CharStringAt(Hps,pt,SIZE(Title4),Title4)<0 THEN Error END;
  69. END DrawTitle;
  70. PROCEDURE DrawJp;
  71. TYPE
  72. Shade = (normal,light,dark);
  73. A10 = ARRAY[0..9] OF CARDINAL;
  74. A6 = ARRAY[0..5] OF CARDINAL;
  75. A4 = ARRAY[0..3] OF CARDINAL;
  76. A3 = ARRAY[0..2] OF CARDINAL;
  77. CONST
  78. Lx = A6(0,30,60,52,30,10);
  79. Ly = A6(50,40,53,57,48,55);
  80. Jx = A10(0, 30,30,0,0, 10,10,20,20,0);
  81. Jy = A10(50,40,0,10,25,21,15,12,33,40);
  82. Px = A6(60,30,30,40,40,60);
  83. Py = A6(53,40,0,5,15,25);
  84. P1x = A4(10,10,20,20);
  85. P1y = A4(15,21,26,20);
  86. P2x = A3(40,50,40);
  87. P2y = A3(25,30,35);
  88. P3x = A4(0, 10,20,10);
  89. P3y = A4(25,21,26,30);
  90. P4x = A3(10,20,20);
  91. P4y = A3(15,20,12);
  92. P5x = A3(50,50,40);
  93. P5y = A3(40,30,35);
  94. PROCEDURE Xlat(x,y:CARDINAL;VAR xo,yo:CARDINAL);
  95. BEGIN
  96. xo := x*3+80; yo := y*3;
  97. END Xlat;
  98. PROCEDURE Polygon(xa,ya :ARRAY OF CARDINAL;
  99. c:Shade);
  100. VAR
  101. xt,yt: A10;
  102. i,n : CARDINAL;
  103. pt : POINTL;
  104. BEGIN
  105. n := HIGH(xa)+1;
  106. FOR i := 0 TO n-1 DO Xlat(xa[i],ya[i],xt[i],yt[i]); END;
  107. pt.x := LONGINT(xt[0]);
  108. pt.y := LONGINT(yt[0]);
  109. IF NOT Gpi.Move(Hps,pt) THEN Error END;
  110. CASE c OF
  111. | normal : IF NOT Gpi.SetPattern(Hps,Gpi.PATSYM_DENSE4) THEN Error END;
  112. | dark : IF NOT Gpi.SetPattern(Hps,Gpi.PATSYM_DENSE2) THEN Error END;
  113. | light : IF NOT Gpi.SetPattern(Hps,Gpi.PATSYM_DENSE6) THEN Error END;
  114. END;
  115. IF NOT Gpi.SetBackMix(Hps,Gpi.BM_OVERPAINT) THEN Error END;
  116. IF NOT Gpi.BeginArea(Hps,Gpi.BA_BOUNDARY) THEN Error END;
  117. FOR i := 1 TO n-1 DO
  118. pt.x := LONGINT(xt[i]);
  119. pt.y := LONGINT(yt[i]);
  120. IF Gpi.Line(Hps,pt)<0 THEN Error END;
  121. END ;
  122. IF Gpi.EndArea(Hps)<0 THEN Error END;
  123. END Polygon;
  124. BEGIN
  125. Polygon(Lx,Ly,dark);
  126. Polygon(Jx,Jy,light);
  127. Polygon(Px,Py,normal);
  128. Polygon(P1x,P1y,normal);
  129. Polygon(P2x,P2y,dark);
  130. Polygon(P3x,P3y,dark);
  131. Polygon(P4x,P4y,dark);
  132. Polygon(P5x,P5y,light);
  133. END DrawJp;
  134. (*-------------------- Start of window procedure ---------------------*)
  135. (*# save,
  136. call(near_call=>off, reg_param=>(), reg_saved=>(di,si,ds,es,st1,st2)) *)
  137. PROCEDURE WindowProc(hwnd : HWND;msg:CARDINAL;mp1,mp2:Win.MPARAM):Win.MRESULT;
  138. VAR
  139. rc : RECTL;
  140. pt : POINTL;
  141. r : CARDINAL;
  142. hr : Gpi.HITSRET;
  143. cm : Win.CHARMSG;
  144. BEGIN
  145. CASE msg OF
  146. | Win.WM_PAINT:
  147. (*----------------------------------------------------------------*)
  148. (* Window contents are drawn here in WM_PAINT processing. *)
  149. (*----------------------------------------------------------------*)
  150. (* Obtain a cached micro PS *)
  151. Hps := Win.BeginPaint( hwnd, HPS(NULL), rc );
  152. IF ChangeBack THEN
  153. IF NOT Win.FillRect( Hps, rc, BackColor ) THEN (* Fill invalid rectangle *)
  154. Error;
  155. END ;
  156. END ;
  157. ChangeBack := TRUE ;
  158. IF NOT Gpi.SetColor( Hps, Gpi.CLR_RED) THEN (* Set color of the text *)
  159. Error;
  160. END;
  161. DrawTitle;
  162. IF NOT Gpi.SetColor( Hps, ForeColor) THEN (* Set color of the Block *)
  163. Error;
  164. END;
  165. DrawJp;
  166. IF NOT Win.EndPaint( Hps ) THEN (* Drawing is complete *)
  167. Error;
  168. END;
  169. | Win.WM_BUTTON1DOWN:
  170. (*---------------------------------------------------------------*)
  171. (* Mouse button 1 has been clicked, so first ensure we have the *)
  172. (* input focus and then cycle the foreground color and cause the *)
  173. (* the window to be redrawn. *)
  174. (*---------------------------------------------------------------*)
  175. IF NOT Win.SetFocus( Win.HWND_DESKTOP, hwnd ) THEN
  176. Error;
  177. END;
  178. REPEAT
  179. IF ForeColor=15 THEN ForeColor := 1 ELSE INC(ForeColor) END;
  180. UNTIL ForeColor<>BackColor;
  181. ChangeBack := FALSE ;
  182. IF NOT Win.InvalidateRect( hwnd, RECTL(NullVar), B_TRUE ) THEN
  183. Error;
  184. END;
  185. | Win.WM_BUTTON2DOWN:
  186. (*---------------------------------------------------------------*)
  187. (* Mouse button 2 has been clicked, so first ensure we have the *)
  188. (* input focus and then cycle the background color and cause the *)
  189. (* the window to be redrawn. *)
  190. (*---------------------------------------------------------------*)
  191. IF NOT Win.SetFocus( Win.HWND_DESKTOP, hwnd ) THEN
  192. Error;
  193. END;
  194. REPEAT
  195. IF BackColor=15 THEN BackColor := 1 ELSE INC(BackColor) END;
  196. UNTIL ForeColor<>BackColor;
  197. ChangeBack := TRUE;
  198. IF NOT Win.InvalidateRect( hwnd, RECTL(NullVar), B_TRUE ) THEN
  199. Error;
  200. END;
  201. | Win.WM_CHAR:
  202. (*----------------------------------------------------------------*)
  203. (* Character input is processed here. *)
  204. (* The first two bytes of message parameter 2 contain *)
  205. (* the character code. *)
  206. (*----------------------------------------------------------------*)
  207. cm := Win.CHARMSG(mp2);
  208. IF cm.vkey = Win.VK_F3 THEN (* If the key pressed is F3,*)
  209. IF NOT Win.PostMsg( hwnd, Win.WM_QUIT, 0, 0 ) THEN
  210. Error;
  211. END; (* post a quit message to *)
  212. END; (* end the application. *)
  213. | Win.WM_CLOSE:
  214. (*----------------------------------------------------------------*)
  215. (* This is the place to put your termination routines *)
  216. (*----------------------------------------------------------------*)
  217. IF NOT Win.PostMsg( hwnd, Win.WM_QUIT, 0, 0 ) THEN (* Cause termination *)
  218. Error;
  219. END;
  220. ELSE
  221. (*----------------------------------------------------------------*)
  222. (* Everything else comes here. This call MUST exist *)
  223. (* in your window procedure. *)
  224. (*----------------------------------------------------------------*)
  225. RETURN Win.DefWindowProc( hwnd, msg, mp1, mp2 );
  226. END;
  227. RETURN Win.MPARAM(FALSE);
  228. END WindowProc;
  229. (*# restore *)
  230. (*--------------------- End of window procedure ----------------------*)
  231. PROCEDURE Main;
  232. VAR
  233. hmq : Win.HMQ;
  234. qmsg : Win.QMSG;
  235. client : HWND;
  236. frame : HWND;
  237. createfl : LSET;
  238. b : BOOLEAN;
  239. r : Win.MRESULT;
  240. BEGIN
  241. ForeColor := Gpi.CLR_BLUE;
  242. BackColor := Gpi.CLR_CYAN;
  243. ChangeBack := TRUE ;
  244. Hab := Win.Initialize( NULL ); (* Initialize PM *)
  245. hmq := Win.CreateMsgQueue( Hab, 0 ); (* Create a message queue *)
  246. IF NOT Win.RegisterClass( (* Register window class *)
  247. Hab, (* Anchor block handle *)
  248. FarADR("MyWindow"), (* Window class name *)
  249. WindowProc, (* Address of window procedure *)
  250. 0, (* No special Class Style *)
  251. 0 (* No extra window words *)
  252. ) THEN Error END;
  253. createfl := Win.FCF_TITLEBAR; (* Set Frame Control Flag *)
  254. frame := Win.CreateStdWindow(
  255. Win.HWND_DESKTOP, (* Desktop window is parent *)
  256. Win.FS_TASKLIST, (* Class Style *)
  257. createfl, (* Frame control flag *)
  258. FarADR("MyWindow"), (* Client window class name *)
  259. ', TopSpeed Demo', (* Title *)
  260. 0, (* No special class style *)
  261. NULL, (* Resource is in .EXE file *)
  262. WindowId, (* Frame window identifier *)
  263. client (* Client window handle *)
  264. );
  265. IF NOT Win.SetWindowPos( frame, (* Set the size and position of *)
  266. Win.HWND_TOP, (* the window before showing. *)
  267. 100, 60, 350, 260,
  268. Win.SWP_SIZE+Win.SWP_MOVE+Win.SWP_ACTIVATE+Win.SWP_SHOW
  269. ) THEN Error END;
  270. (*----------------------------------------------------------------------*)
  271. (* Get and dispatch messages from the application message queue *)
  272. (* until WinGetMsg returns FALSE, indicating a WM_QUIT message. *)
  273. (*----------------------------------------------------------------------*)
  274. WHILE( Win.GetMsg( Hab, qmsg, HWND(NULL), 0, 0 ) ) DO
  275. r := Win.DispatchMsg( Hab, qmsg );
  276. END;
  277. IF NOT Win.DestroyWindow( frame ) THEN (* Tidy up... *)
  278. Error;
  279. END;
  280. IF NOT Win.DestroyMsgQueue( hmq ) THEN (* and *)
  281. Error;
  282. END;
  283. IF NOT Win.Terminate( Hab ) THEN (* terminate the application *)
  284. Error;
  285. END;
  286. END Main;
  287. (*---------------------- End of main procedure -----------------------*)
  288. BEGIN
  289. Main;
  290. END PMJP.
  291.