BimboMail.Mod 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. MODULE BimboMail; (** AUTHOR "TF"; PURPOSE "Simple Mail Reader"; *)
  2. IMPORT
  3. Modules, WMGrids, WMStringGrids, MailStorage, WMGraphics,
  4. WMMessages, WMStandardComponents, WMComponents,
  5. WMEditors, Strings, TextUtilities, Texts,
  6. WM := WMWindowManager;
  7. CONST
  8. TempFilename = "BimboMail.Temp";
  9. TYPE
  10. KillerMsg = OBJECT
  11. END KillerMsg;
  12. Window* = OBJECT (WMComponents.FormWindow)
  13. VAR currentMailbox : MailStorage.Storage;
  14. messageList : WMStringGrids.StringGrid;
  15. messageText : WMEditors.Editor;
  16. PROCEDURE CreateForm(): WMComponents.VisualComponent;
  17. VAR
  18. panel : WMStandardComponents.Panel;
  19. toolbar, mailboxSelection, mailContentPanel : WMStandardComponents.Panel;
  20. mailboxEntries : WMStringGrids.StringGrid;
  21. mailText : WMEditors.Editor;
  22. vResizer : WMStandardComponents.Resizer;
  23. BEGIN
  24. NEW(panel); panel.bounds.SetExtents(800, 700); panel.fillColor.Set(0FFFFFFFFH); panel.takesFocus.Set(TRUE);
  25. NEW(toolbar); toolbar.fillColor.Set(000FF00FFH); toolbar.bounds.SetHeight(20); toolbar.alignment.Set(WMComponents.AlignTop);
  26. panel.AddContent(toolbar);
  27. NEW(mailboxSelection); mailboxSelection.fillColor.Set(0FF0000FFH); mailboxSelection.bounds.SetWidth(64);
  28. mailboxSelection.alignment.Set(WMComponents.AlignLeft);
  29. panel.AddContent(mailboxSelection);
  30. NEW(mailContentPanel); mailContentPanel.fillColor.Set(0FFFFFFFFH); mailContentPanel.bounds.SetHeight(350);
  31. mailContentPanel.alignment.Set(WMComponents.AlignBottom);
  32. panel.AddContent(mailContentPanel);
  33. NEW(mailboxEntries); mailboxEntries.alignment.Set(WMComponents.AlignClient);
  34. panel.AddContent(mailboxEntries);
  35. messageList := mailboxEntries;
  36. NEW(vResizer); vResizer.bounds.SetHeight(5); vResizer.alignment.Set(WMComponents.AlignTop);
  37. mailContentPanel.AddContent(vResizer);
  38. NEW(mailText); mailText.alignment.Set(WMComponents.AlignClient); mailText.tv.showBorder.Set(TRUE);
  39. mailContentPanel.AddContent(mailText);
  40. messageText := mailText;
  41. mailText.multiLine.Set(TRUE);
  42. mailText.readOnly.Set(TRUE);
  43. RETURN panel
  44. END CreateForm;
  45. PROCEDURE SetMailbox(mb : MailStorage.Storage);
  46. VAR i : LONGINT;
  47. hFrom, hTo, hSubject, hDate : ARRAY 128 OF CHAR;
  48. BEGIN
  49. currentMailbox := mb;
  50. messageList.model.Acquire;
  51. messageList.model.SetNofCols(3);
  52. messageList.model.SetNofRows(mb.GetCount());
  53. FOR i := 0 TO mb.GetCount() - 1 DO
  54. currentMailbox.GetHeader(i, hFrom, hTo, hSubject, hDate);
  55. messageList.model.SetCellText(0, i + 1, Strings.NewString(hFrom));
  56. messageList.model.SetTextAlign(0, i + 1, WMGraphics.AlignCenter);
  57. messageList.model.SetCellText(1, i + 1, Strings.NewString(hSubject));
  58. messageList.model.SetTextAlign(1, i + 1, WMGraphics.AlignCenter);
  59. messageList.model.SetCellText(2, i + 1, Strings.NewString(hDate));
  60. messageList.model.SetTextAlign(2, i + 1, WMGraphics.AlignCenter)
  61. END;
  62. messageList.model.Release;
  63. END SetMailbox;
  64. PROCEDURE &New*;
  65. VAR vc : WMComponents.VisualComponent;
  66. mb : MailStorage.Storage;
  67. colWidths : WMGrids.Spacings;
  68. i : LONGINT;
  69. str : ARRAY 32 OF CHAR;
  70. BEGIN
  71. IncCount;
  72. vc := CreateForm();
  73. Init(vc.bounds.GetWidth(), vc.bounds.GetHeight(), FALSE);
  74. SetContent(vc);
  75. manager := WM.GetDefaultManager();
  76. manager.Add(100, 100, SELF, {WM.FlagFrame});
  77. SetTitle(Strings.NewString("Bimbo Mail"));
  78. messageList.fixedRows.Set(1);
  79. NEW(colWidths, 4);
  80. colWidths[0] := messageList.bounds.GetWidth() DIV 3;
  81. colWidths[1] := 0;
  82. colWidths[2] := messageList.bounds.GetWidth() DIV 3;
  83. colWidths[3] := messageList.bounds.GetWidth() DIV 3;
  84. messageList.SetColSpacings(colWidths);
  85. messageList.onClick.Add(MessageClick);
  86. messageList.SetSelectionMode(WMGrids.GridSelectSingleRow);
  87. messageList.model.Acquire;
  88. messageList.model.SetNofCols(3);
  89. messageList.model.SetNofRows(2);
  90. FOR i := 0 TO 3 - 1 DO
  91. GetTitleStr(i, str);
  92. messageList.model.SetCellText(i, 0, Strings.NewString(str));
  93. messageList.model.SetTextAlign(i, 0, WMGraphics.AlignCenter)
  94. END;
  95. messageList.SetColSpacings(colWidths);
  96. messageList.model.Release;
  97. NEW(mb); mb.Open("MailMessages", "");
  98. SetMailbox(mb);
  99. END New;
  100. PROCEDURE GetTitleStr(col: LONGINT; VAR x : ARRAY OF CHAR);
  101. BEGIN
  102. CASE col OF
  103. | 0 : COPY("From", x)
  104. | 1 : COPY("Subject", x)
  105. | 2 : COPY("Date", x)
  106. ELSE COPY("", x);
  107. END
  108. END GetTitleStr;
  109. PROCEDURE Close*;
  110. BEGIN
  111. Close^;
  112. DecCount
  113. END Close;
  114. PROCEDURE Handle*(VAR x: WMMessages.Message);
  115. BEGIN
  116. IF (x.msgType = WMMessages.MsgExt) & (x.ext # NIL) & (x.ext IS KillerMsg) THEN Close
  117. ELSE Handle^(x)
  118. END
  119. END Handle;
  120. (*PROCEDURE DrawCell(canvas : WMGraphics.Canvas; w, h : LONGINT; state : SET; x, y : LONGINT);
  121. VAR color: LONGINT; str, hFrom, hTo, hSubject, hDate : ARRAY 128 OF CHAR;
  122. BEGIN
  123. color := WMGraphics.RGBAToColor(255, 255, 255, 255);
  124. IF state * {WMGrids.CellFixed, WMGrids.CellSelected} = {WMGrids.CellFixed, WMGrids.CellSelected} THEN
  125. color := WMGraphics.RGBAToColor(0, 128, 255, 255)
  126. ELSIF WMGrids.CellFixed IN state THEN
  127. color := WMGraphics.RGBAToColor(196, 196, 196, 255)
  128. ELSIF WMGrids.CellSelected IN state THEN
  129. color := WMGraphics.RGBAToColor(196, 196, 255, 255)
  130. ELSIF WMGrids.CellFocused IN state THEN
  131. color := WMGraphics.RGBAToColor(255, 255, 196, 255)
  132. END;
  133. canvas.SetColor(WMGraphics.RGBAToColor(0, 0, 0, 255));
  134. canvas.SetFont(WMBitmapFont.bimbofont);
  135. canvas.Fill(WMRectangles.MakeRect(0, 0, w, h), color, WMGraphics.ModeCopy);
  136. IF (WMGrids.CellFocused IN state) & ~(WMGrids.CellHighlighted IN state) THEN
  137. WMGraphicUtilities.DrawBevel(canvas, WMRectangles.MakeRect(0, 0, w, h), 1, TRUE, WMGraphics.RGBAToColor(0, 0, 0, 196),
  138. WMGraphics.ModeSrcOverDst)
  139. END;
  140. IF y = 0 THEN
  141. CASE x OF
  142. | 0 : str := "From"
  143. | 1 : str := "To"
  144. | 2 : str := "Subject"
  145. | 3 : str := "Date"
  146. ELSE
  147. END
  148. ELSIF (currentMailbox # NIL) & (y - 1 >= 0) & (y - 1 < currentMailbox.GetCount()) THEN
  149. currentMailbox.GetHeader(y - 1, hFrom, hTo, hSubject, hDate);
  150. CASE x OF
  151. | 0 : COPY(hFrom, str)
  152. | 1 : COPY(hTo, str)
  153. | 2 : COPY(hSubject, str)
  154. | 3 : COPY(hDate, str)
  155. ELSE
  156. END
  157. END;
  158. canvas.DrawString(4, h-4, str)
  159. END DrawCell; *)
  160. PROCEDURE MessageClick(sender, data : ANY);
  161. VAR scol, srow, ecol, erow, y, res : LONGINT; text : Texts.Text;
  162. BEGIN
  163. messageList.GetSelection(scol, srow, ecol, erow);
  164. y := srow - 1;
  165. IF (currentMailbox # NIL) & (y >= 0) & (y < currentMailbox.GetCount()) THEN
  166. IF currentMailbox.ToFile(y, TempFilename) THEN
  167. text := messageText.text;
  168. text.AcquireWrite;
  169. text.Delete(0, text.GetLength());
  170. TextUtilities.LoadOberonText(text, TempFilename, res);
  171. text.ReleaseWrite;
  172. messageText.tv.firstLine.Set(0);
  173. END
  174. END
  175. END MessageClick;
  176. END Window;
  177. VAR
  178. nofWindows : LONGINT;
  179. PROCEDURE Open*;
  180. VAR winstance : Window;
  181. BEGIN
  182. NEW(winstance);
  183. END Open;
  184. PROCEDURE IncCount;
  185. BEGIN {EXCLUSIVE}
  186. INC(nofWindows)
  187. END IncCount;
  188. PROCEDURE DecCount;
  189. BEGIN {EXCLUSIVE}
  190. DEC(nofWindows)
  191. END DecCount;
  192. PROCEDURE Cleanup;
  193. VAR die : KillerMsg;
  194. msg : WMMessages.Message;
  195. m : WM.WindowManager;
  196. BEGIN {EXCLUSIVE}
  197. NEW(die);
  198. msg.ext := die;
  199. msg.msgType := WMMessages.MsgExt;
  200. m := WM.GetDefaultManager();
  201. m.Broadcast(msg);
  202. AWAIT(nofWindows = 0)
  203. END Cleanup;
  204. BEGIN
  205. Modules.InstallTermHandler(Cleanup)
  206. END BimboMail.
  207. BimboMail.Open ~
  208. SystemTools.Free BimboMail MailStorage POP3Client ~
  209. PET.Open MailStorage.Mod ~
  210. PET.Open POP3Client.Mod ~