DTPRect.Mod 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. MODULE DTPRect; (** AUTHOR "PL"; PURPOSE "Simple Rectangle Plugin for DTPEditor"; *)
  2. IMPORT
  3. Modules, Files, XML,
  4. XMLObjects, WMStandardComponents, WMGraphics, WMGraphicUtilities,
  5. WMComponents, WMRectangles, WMEditors, Strings, WMWindowManager, WMPopups,
  6. DTPData, DTPEditor, DTPUtilities; (* , DTPFrame *)
  7. CONST
  8. pluginVersion = 1.00;
  9. pluginName = "Rectangle";
  10. pluginDesc = "Draws a Rectangle with a given Bordercolor and Fillcolor";
  11. fillModeSolid = 0;
  12. fillModeGradient = 1;
  13. fillModeGradientReflected = 2;
  14. TYPE
  15. ContextMenuData = OBJECT
  16. VAR val: LONGINT;
  17. PROCEDURE &New*(val: LONGINT);
  18. BEGIN
  19. SELF.val := val;
  20. END New;
  21. END ContextMenuData;
  22. RectObject* = OBJECT(DTPData.ContentObject);
  23. VAR
  24. lineColor, rectColor, rectColor2: LONGINT;
  25. lineWidth : REAL;
  26. fillMode : LONGINT;
  27. gradientHorizontal: BOOLEAN;
  28. properties : RectPropWindow;
  29. PROCEDURE &New*;
  30. BEGIN
  31. (* default values *)
  32. lineColor := 0000000FFH;
  33. rectColor := LONGINT(0FFFFFFFFH);
  34. rectColor2 := 000FFFFH;
  35. lineWidth := 0.0;
  36. gradientHorizontal := TRUE;
  37. fillMode := fillModeSolid;
  38. NEW(properties, SELF);
  39. END New;
  40. PROCEDURE Draw*(canvas : WMGraphics.Canvas; x, y, w, h : LONGINT; zoomFactor: REAL; quality, preview: BOOLEAN);
  41. VAR rw, rh: REAL; linePixel: LONGINT;
  42. BEGIN
  43. rw := w/zoomFactor; rh := h/zoomFactor; linePixel := ENTIER(lineWidth * zoomFactor);
  44. (* fill *)
  45. IF fillMode = 2 THEN
  46. IF gradientHorizontal THEN
  47. WMGraphicUtilities.FillGradientHorizontal(canvas, WMRectangles.MakeRect(x+linePixel, y+linePixel, x+(w DIV 2)+1, y+h+1-linePixel), rectColor, rectColor2, WMGraphics.ModeSrcOverDst);
  48. WMGraphicUtilities.FillGradientHorizontal(canvas, WMRectangles.MakeRect(x+ (w DIV 2), y+linePixel, x+w+1-linePixel, y+h+1-linePixel), rectColor2, rectColor, WMGraphics.ModeSrcOverDst);
  49. ELSE
  50. WMGraphicUtilities.FillGradientVertical(canvas, WMRectangles.MakeRect(x+linePixel, y+linePixel, x+w+1-linePixel, y+(h DIV 2)+1), rectColor, rectColor2, WMGraphics.ModeSrcOverDst);
  51. WMGraphicUtilities.FillGradientVertical(canvas, WMRectangles.MakeRect(x+linePixel, y+(h DIV 2), x+w+1-linePixel, y+h+1-linePixel), rectColor2, rectColor, WMGraphics.ModeSrcOverDst);
  52. END;
  53. ELSIF fillMode = 1 THEN
  54. IF gradientHorizontal THEN
  55. WMGraphicUtilities.FillGradientHorizontal(canvas, WMRectangles.MakeRect(x+linePixel, y+linePixel, x+w+1-linePixel, y+h+1-linePixel), rectColor, rectColor2, WMGraphics.ModeSrcOverDst);
  56. ELSE
  57. WMGraphicUtilities.FillGradientVertical(canvas, WMRectangles.MakeRect(x+linePixel, y+linePixel, x+w+1-linePixel, y+h+1-linePixel), rectColor, rectColor2, WMGraphics.ModeSrcOverDst);
  58. END;
  59. ELSE
  60. canvas.Fill(WMRectangles.MakeRect(x+linePixel, y+linePixel, x+w+1-linePixel, y+h+1-linePixel), rectColor, WMGraphics.ModeSrcOverDst);
  61. END;
  62. (* line *)
  63. IF linePixel >0 THEN
  64. canvas.Fill(WMRectangles.MakeRect(x, y, x+w+1, y+linePixel), lineColor, WMGraphics.ModeSrcOverDst);
  65. canvas.Fill(WMRectangles.MakeRect(x, y+linePixel, x+linePixel, y+h+1-linePixel), lineColor, WMGraphics.ModeSrcOverDst);
  66. canvas.Fill(WMRectangles.MakeRect(x, y+h+1-linePixel, x+w+1,y+h+1), lineColor, WMGraphics.ModeSrcOverDst);
  67. canvas.Fill(WMRectangles.MakeRect(x+w+1-linePixel, y+linePixel, x+w+1, y+h+1-linePixel), lineColor, WMGraphics.ModeSrcOverDst);
  68. END;
  69. END Draw;
  70. PROCEDURE Redraw*;
  71. BEGIN
  72. Redraw^;
  73. END Redraw;
  74. PROCEDURE Clone*(): DTPData.ContentObject;
  75. VAR newObj: RectObject;
  76. BEGIN
  77. NEW(newObj); newObj.contentName := Strings.NewString(contentName^);
  78. newObj.redrawProc := redrawProc; newObj.updatePropsPosition := updatePropsPosition;
  79. newObj.contentWidth := contentWidth; newObj.contentHeight := contentHeight; newObj.zoomFactor := zoomFactor;
  80. newObj.ownerDoc := ownerDoc;
  81. newObj.lineColor := lineColor;
  82. newObj.rectColor := rectColor;
  83. newObj.rectColor2 := rectColor2;
  84. newObj.lineWidth := lineWidth;
  85. newObj.fillMode := fillMode;
  86. newObj.gradientHorizontal := gradientHorizontal;
  87. RETURN newObj;
  88. END Clone;
  89. PROCEDURE Load*(elem: XML.Element);
  90. VAR name : Strings.String;
  91. cont: XMLObjects.Enumerator;
  92. ptr: ANY;
  93. tempInt : LONGINT; res: WORD;
  94. tempReal : LONGREAL;
  95. BEGIN
  96. cont := elem.GetContents(); cont.Reset();
  97. WHILE cont.HasMoreElements() DO
  98. ptr := cont.GetNext();
  99. IF ptr IS XML.Element THEN (* read attributes *)
  100. name := ptr(XML.Element).GetAttributeValue("name");
  101. IF (name # NIL) & (name^ = "line-width") THEN
  102. name := ptr(XML.Element).GetAttributeValue("value");
  103. IF (name # NIL) THEN Strings.StrToFloat(name^, tempReal); lineWidth := SHORT(tempReal); END;
  104. ELSIF (name # NIL) & (name^ = "line-color") THEN
  105. name := ptr(XML.Element).GetAttributeValue("value");
  106. IF (name # NIL) THEN Strings.HexStrToInt(name^, tempInt, res); lineColor := tempInt; END;
  107. ELSIF (name # NIL) & (name^ = "fill-color") THEN
  108. name := ptr(XML.Element).GetAttributeValue("value");
  109. IF (name # NIL) THEN Strings.HexStrToInt(name^, tempInt, res); rectColor := tempInt; END;
  110. ELSIF (name # NIL) & (name^ = "fill-color2") THEN
  111. name := ptr(XML.Element).GetAttributeValue("value");
  112. IF (name # NIL) THEN Strings.HexStrToInt(name^, tempInt, res); rectColor2 := tempInt; END;
  113. ELSIF (name # NIL) & (name^ = "fill-mode") THEN
  114. name := ptr(XML.Element).GetAttributeValue("value");
  115. IF (name # NIL) THEN Strings.StrToInt(name^, tempInt); fillMode := tempInt; END;
  116. ELSIF (name # NIL) & (name^ = "gradient-horizontal") THEN
  117. name := ptr(XML.Element).GetAttributeValue("value");
  118. IF (name # NIL) THEN
  119. IF (name^ = "1") THEN gradientHorizontal := TRUE ELSE gradientHorizontal := FALSE; END;
  120. END;
  121. ELSE
  122. END;
  123. END;
  124. END;
  125. END Load;
  126. PROCEDURE Store*(VAR w: Files.Writer);
  127. VAR tempString: ARRAY 256 OF CHAR;
  128. BEGIN
  129. w.String(' <node-attribute name="type" value="Rectangle" />'); w.Ln;
  130. w.String(' <node-attribute name="line-width" value="'); Strings.FloatToStr(lineWidth, 0,4,0, tempString); Strings.TrimLeft(tempString, " "); w.String(tempString); w.String('" />'); w.Ln;
  131. w.String(' <node-attribute name="line-color" value="'); w.Hex(lineColor, 8); w.String('" />'); w.Ln;
  132. w.String(' <node-attribute name="fill-color" value="'); w.Hex(rectColor, 8); w.String('" />'); w.Ln;
  133. w.String(' <node-attribute name="fill-color2" value="'); w.Hex(rectColor2, 8); w.String('" />'); w.Ln;
  134. w.String(' <node-attribute name="fill-mode" value="'); w.Int(fillMode, 0); w.String('" />'); w.Ln;
  135. w.String(' <node-attribute name="gradient-horizontal" value="'); IF gradientHorizontal THEN w.Int(1, 0); ELSE w.Int(0, 0); END; w.String('" />'); w.Ln;
  136. END Store;
  137. PROCEDURE Show*(x, y: LONGINT);
  138. BEGIN
  139. properties.Show(x, y);
  140. END Show;
  141. PROCEDURE Hide*;
  142. VAR viewport: WMWindowManager.ViewPort;
  143. BEGIN
  144. viewport := WMWindowManager.GetDefaultView();
  145. UpdatePosition(properties.bounds.l-ENTIER(viewport.range.l), properties.bounds.t-ENTIER(viewport.range.t));
  146. properties.Hide;
  147. END Hide;
  148. PROCEDURE Close*;
  149. BEGIN
  150. Hide;
  151. END Close;
  152. END RectObject;
  153. RectPropWindow = OBJECT(WMComponents.FormWindow)
  154. VAR theCaller : RectObject;
  155. shown: BOOLEAN;
  156. leftPanel, rightPanel: WMStandardComponents.Panel;
  157. lineButton, rectButton, rect2Button, modeButton: WMStandardComponents.Button;
  158. lineWidthEdit, lineColorEdit, rectColorEdit, rectColorEdit2, fillModeEdit, gradHorizEdit: WMEditors.Editor;
  159. popup: WMPopups.Popup;
  160. PROCEDURE &New*(caller: RectObject);
  161. VAR vc: WMComponents.VisualComponent;
  162. BEGIN
  163. theCaller := caller;
  164. manager := WMWindowManager.GetDefaultManager();
  165. vc := CreatePropertyForm();
  166. Init(vc.bounds.GetWidth(), vc.bounds.GetHeight(), TRUE);
  167. SetContent(vc);
  168. SetTitle(Strings.NewString("Content"));
  169. shown := FALSE;
  170. END New;
  171. PROCEDURE CreatePropertyForm(): WMComponents.VisualComponent;
  172. VAR panel, container: WMStandardComponents.Panel;
  173. label: WMStandardComponents.Label;
  174. colorString: ARRAY 16 OF CHAR;
  175. button: WMStandardComponents.Button;
  176. windowStyle : WMWindowManager.WindowStyle;
  177. panelColor : LONGINT;
  178. BEGIN
  179. windowStyle := manager.GetStyle();
  180. panelColor := windowStyle.bgColor;
  181. NEW(panel); panel.bounds.SetExtents(190 , 120); panel.fillColor.Set(panelColor);
  182. panel.takesFocus.Set(TRUE);
  183. NEW(leftPanel); leftPanel.bounds.SetWidth(90); leftPanel.alignment.Set(WMComponents.AlignLeft);
  184. panel.AddContent(leftPanel);
  185. NEW(rightPanel); rightPanel.alignment.Set(WMComponents.AlignClient);
  186. panel.AddContent(rightPanel);
  187. NEW(label); label.bounds.SetHeight(20); label.alignment.Set(WMComponents.AlignTop);
  188. label.SetCaption(" LineWidth:"); label.textColor.Set(0000000FFH);
  189. leftPanel.AddContent(label);
  190. NEW(lineWidthEdit); lineWidthEdit.bounds.SetHeight(20); lineWidthEdit.alignment.Set(WMComponents.AlignTop);
  191. lineWidthEdit.tv.showBorder.Set(TRUE); lineWidthEdit.multiLine.Set(FALSE); lineWidthEdit.fillColor.Set(0FFFFFFFFH);
  192. lineWidthEdit.tv.textAlignV.Set(WMGraphics.AlignCenter);
  193. lineWidthEdit.onEnter.Add(SetValueHandler); lineWidthEdit.tv.borders.Set(WMRectangles.MakeRect(3,3,1,1));
  194. Strings.FloatToStr(theCaller.lineWidth, 0, 5, 0, colorString);
  195. lineWidthEdit.SetAsString(colorString);
  196. rightPanel.AddContent(lineWidthEdit);
  197. NEW(label); label.bounds.SetHeight(20); label.alignment.Set(WMComponents.AlignTop);
  198. label.SetCaption(" LineColor:"); label.textColor.Set(0000000FFH);
  199. leftPanel.AddContent(label);
  200. NEW(button); button.bounds.SetWidth(20); button.caption.SetAOC("+"); button.alignment.Set(WMComponents.AlignRight);
  201. NEW(container); container.bounds.SetHeight(20); container.alignment.Set(WMComponents.AlignTop);
  202. lineButton := button;
  203. container.AddContent(lineButton); button.SetExtPointerDownHandler(LineColorHandler);
  204. NEW(lineColorEdit); lineColorEdit.bounds.SetHeight(20); lineColorEdit.alignment.Set(WMComponents.AlignClient);
  205. lineColorEdit.tv.showBorder.Set(TRUE); lineColorEdit.multiLine.Set(FALSE); lineColorEdit.fillColor.Set(0FFFFFFFFH);
  206. lineColorEdit.tv.textAlignV.Set(WMGraphics.AlignCenter);
  207. lineColorEdit.onEnter.Add(SetValueHandler); lineColorEdit.tv.borders.Set(WMRectangles.MakeRect(3,3,1,1));
  208. Strings.IntToStr(theCaller.lineColor, colorString);
  209. lineColorEdit.SetAsString(colorString);
  210. container.AddContent(lineColorEdit);
  211. rightPanel.AddContent(container);
  212. NEW(label); label.bounds.SetHeight(20); label.alignment.Set(WMComponents.AlignTop);
  213. label.SetCaption(" FillColor:"); label.textColor.Set(0000000FFH);
  214. leftPanel.AddContent(label);
  215. NEW(button); button.bounds.SetWidth(20); button.caption.SetAOC("+"); button.alignment.Set(WMComponents.AlignRight);
  216. NEW(container); container.bounds.SetHeight(20); container.alignment.Set(WMComponents.AlignTop);
  217. rectButton := button;
  218. container.AddContent(rectButton); button.SetExtPointerDownHandler(RectColorHandler);
  219. NEW(rectColorEdit); rectColorEdit.bounds.SetHeight(20); rectColorEdit.alignment.Set(WMComponents.AlignClient);
  220. rectColorEdit.tv.showBorder.Set(TRUE); rectColorEdit.multiLine.Set(FALSE); rectColorEdit.fillColor.Set(0FFFFFFFFH);
  221. rectColorEdit.tv.textAlignV.Set(WMGraphics.AlignCenter);
  222. rectColorEdit.onEnter.Add(SetValueHandler); rectColorEdit.tv.borders.Set(WMRectangles.MakeRect(3,3,1,1));
  223. Strings.IntToStr(theCaller.rectColor, colorString);
  224. rectColorEdit.SetAsString(colorString);
  225. container.AddContent(rectColorEdit);
  226. rightPanel.AddContent(container);
  227. NEW(label); label.bounds.SetHeight(20); label.alignment.Set(WMComponents.AlignTop);
  228. label.SetCaption(" FillColor2:"); label.textColor.Set(0000000FFH);
  229. leftPanel.AddContent(label);
  230. NEW(button); button.bounds.SetWidth(20); button.caption.SetAOC("+"); button.alignment.Set(WMComponents.AlignRight);
  231. NEW(container); container.bounds.SetHeight(20); container.alignment.Set(WMComponents.AlignTop);
  232. rect2Button := button;
  233. container.AddContent(rect2Button); button.SetExtPointerDownHandler(RectColor2Handler);
  234. NEW(rectColorEdit2); rectColorEdit2.bounds.SetHeight(20); rectColorEdit2.alignment.Set(WMComponents.AlignClient);
  235. rectColorEdit2.tv.showBorder.Set(TRUE); rectColorEdit2.multiLine.Set(FALSE); rectColorEdit2.fillColor.Set(0FFFFFFFFH);
  236. rectColorEdit2.tv.textAlignV.Set(WMGraphics.AlignCenter);
  237. rectColorEdit2.onEnter.Add(SetValueHandler); rectColorEdit2.tv.borders.Set(WMRectangles.MakeRect(3,3,1,1));
  238. Strings.IntToStr(theCaller.rectColor2, colorString);
  239. rectColorEdit2.SetAsString(colorString);
  240. container.AddContent(rectColorEdit2);
  241. rightPanel.AddContent(container);
  242. NEW(label); label.bounds.SetHeight(20); label.alignment.Set(WMComponents.AlignTop);
  243. label.SetCaption(" FillMode:"); label.textColor.Set(0000000FFH);
  244. leftPanel.AddContent(label);
  245. NEW(button); button.bounds.SetWidth(20); button.caption.SetAOC("+"); button.alignment.Set(WMComponents.AlignRight);
  246. NEW(container); container.bounds.SetHeight(20); container.alignment.Set(WMComponents.AlignTop);
  247. modeButton := button;
  248. container.AddContent(modeButton); button.SetExtPointerDownHandler(FillModeHandler);
  249. NEW(fillModeEdit); fillModeEdit.bounds.SetHeight(20); fillModeEdit.alignment.Set(WMComponents.AlignClient);
  250. fillModeEdit.tv.showBorder.Set(TRUE); fillModeEdit.multiLine.Set(FALSE); fillModeEdit.fillColor.Set(0FFFFFFFFH);
  251. fillModeEdit.tv.textAlignV.Set(WMGraphics.AlignCenter);
  252. fillModeEdit.onEnter.Add(SetValueHandler); fillModeEdit.tv.borders.Set(WMRectangles.MakeRect(3,3,1,1));
  253. Strings.IntToStr(theCaller.fillMode, colorString);
  254. fillModeEdit.SetAsString(colorString);
  255. container.AddContent(fillModeEdit);
  256. rightPanel.AddContent(container);
  257. NEW(label); label.bounds.SetHeight(20); label.alignment.Set(WMComponents.AlignTop);
  258. label.SetCaption(" Horizontal:"); label.textColor.Set(0000000FFH);
  259. leftPanel.AddContent(label);
  260. NEW(gradHorizEdit); gradHorizEdit.bounds.SetHeight(20); gradHorizEdit.alignment.Set(WMComponents.AlignTop);
  261. gradHorizEdit.tv.showBorder.Set(TRUE); gradHorizEdit.multiLine.Set(FALSE); gradHorizEdit.fillColor.Set(0FFFFFFFFH);
  262. gradHorizEdit.tv.textAlignV.Set(WMGraphics.AlignCenter);
  263. gradHorizEdit.onEnter.Add(SetValueHandler); gradHorizEdit.tv.borders.Set(WMRectangles.MakeRect(3,3,1,1));
  264. Strings.BoolToStr(theCaller.gradientHorizontal, colorString);
  265. gradHorizEdit.SetAsString(colorString);
  266. rightPanel.AddContent(gradHorizEdit);
  267. RETURN panel;
  268. END CreatePropertyForm;
  269. PROCEDURE LineColorHandler(x, y : LONGINT; keys : SET; VAR handled : BOOLEAN);
  270. VAR colorChooser: DTPUtilities.ColorChooserWindow;
  271. rectangle: WMRectangles.Rectangle;
  272. result: LONGINT;
  273. replaceColor: BOOLEAN;
  274. colorString: ARRAY 16 OF CHAR;
  275. BEGIN
  276. NEW(colorChooser);
  277. rectangle := lineButton.bounds.Get();
  278. replaceColor := colorChooser.Show(bounds.l, bounds.t+rectangle.b+20, result);
  279. IF replaceColor THEN
  280. Strings.IntToHexStr(result, 7, colorString);
  281. lineColorEdit.SetAsString(colorString);
  282. theCaller.lineColor := result;
  283. theCaller.Redraw;
  284. END;
  285. handled := TRUE;
  286. END LineColorHandler;
  287. PROCEDURE RectColorHandler(x, y : LONGINT; keys : SET; VAR handled : BOOLEAN);
  288. VAR colorChooser: DTPUtilities.ColorChooserWindow;
  289. rectangle: WMRectangles.Rectangle;
  290. result: LONGINT;
  291. replaceColor: BOOLEAN;
  292. colorString: ARRAY 16 OF CHAR;
  293. BEGIN
  294. NEW(colorChooser);
  295. rectangle := rectButton.bounds.Get();
  296. replaceColor := colorChooser.Show(bounds.l, bounds.t+rectangle.b+40, result);
  297. IF replaceColor THEN
  298. Strings.IntToHexStr(result, 7, colorString);
  299. rectColorEdit.SetAsString(colorString);
  300. theCaller.rectColor := result;
  301. theCaller.Redraw;
  302. END;
  303. handled := TRUE;
  304. END RectColorHandler;
  305. PROCEDURE RectColor2Handler(x, y : LONGINT; keys : SET; VAR handled : BOOLEAN);
  306. VAR colorChooser: DTPUtilities.ColorChooserWindow;
  307. rectangle: WMRectangles.Rectangle;
  308. result: LONGINT;
  309. replaceColor: BOOLEAN;
  310. colorString: ARRAY 16 OF CHAR;
  311. BEGIN
  312. NEW(colorChooser);
  313. rectangle := rect2Button.bounds.Get();
  314. replaceColor := colorChooser.Show(bounds.l, bounds.t+rectangle.b+60, result);
  315. IF replaceColor THEN
  316. Strings.IntToHexStr(result, 7, colorString);
  317. rectColorEdit2.SetAsString(colorString);
  318. theCaller.rectColor2 := result;
  319. theCaller.Redraw;
  320. END;
  321. handled := TRUE;
  322. END RectColor2Handler;
  323. PROCEDURE FillModeHandler(x, y : LONGINT; keys : SET; VAR handled : BOOLEAN);
  324. VAR rectangle: WMRectangles.Rectangle;
  325. BEGIN
  326. NEW(popup);
  327. popup.AddParButton("Solid", FillModePopupHandler, ctxFillModeSolid);
  328. popup.AddParButton("Gradient", FillModePopupHandler, ctxFillModeGradient);
  329. popup.AddParButton("Grad. Reflected", FillModePopupHandler, ctxFillModeGradientReflected);
  330. handled := TRUE;
  331. rectangle := modeButton.bounds.Get();
  332. popup.Popup(bounds.l+rectangle.l, bounds.t+rectangle.t+rectangle.b+80);
  333. END FillModeHandler;
  334. PROCEDURE FillModePopupHandler(sender, data: ANY);
  335. VAR colorString: ARRAY 16 OF CHAR;
  336. BEGIN
  337. IF (data # NIL) THEN
  338. popup.Close;
  339. Strings.IntToStr(data(ContextMenuData).val, colorString);
  340. fillModeEdit.SetAsString(colorString);
  341. theCaller.fillMode := data(ContextMenuData).val;
  342. theCaller.Redraw;
  343. END;
  344. END FillModePopupHandler;
  345. PROCEDURE Show*(x, y: LONGINT);
  346. BEGIN
  347. IF ~shown THEN
  348. shown := TRUE;
  349. RefreshValues;
  350. WMWindowManager.ExtAddWindow(SELF, x, y,
  351. {WMWindowManager.FlagFrame, WMWindowManager.FlagStayOnTop, WMWindowManager.FlagClose, WMWindowManager.FlagMinimize});
  352. END;
  353. END Show;
  354. PROCEDURE Hide*;
  355. BEGIN
  356. IF shown THEN
  357. shown := FALSE;
  358. manager.Remove(SELF);
  359. END;
  360. END Hide;
  361. PROCEDURE RefreshValues;
  362. VAR colorString: ARRAY 16 OF CHAR;
  363. BEGIN
  364. Strings.FloatToStr(theCaller.lineWidth, 0, 5,0, colorString);
  365. lineWidthEdit.SetAsString(colorString);
  366. lineWidthEdit.Invalidate;
  367. Strings.IntToHexStr(theCaller.lineColor, 7, colorString);
  368. lineColorEdit.SetAsString(colorString);
  369. lineColorEdit.Invalidate;
  370. Strings.IntToHexStr(theCaller.rectColor, 7, colorString);
  371. rectColorEdit.SetAsString(colorString);
  372. rectColorEdit.Invalidate;
  373. Strings.IntToHexStr(theCaller.rectColor2, 7, colorString);
  374. rectColorEdit2.SetAsString(colorString);
  375. rectColorEdit2.Invalidate;
  376. Strings.IntToStr(theCaller.fillMode, colorString);
  377. fillModeEdit.SetAsString(colorString);
  378. fillModeEdit.Invalidate;
  379. Strings.BoolToStr(theCaller.gradientHorizontal, colorString);
  380. gradHorizEdit.SetAsString(colorString);
  381. gradHorizEdit.Invalidate;
  382. END RefreshValues;
  383. PROCEDURE SetValueHandler(sender, data: ANY);
  384. VAR
  385. colorString, origString : ARRAY 128 OF CHAR;
  386. color : LONGINT; res: WORD;
  387. width: LONGREAL;
  388. bool: BOOLEAN;
  389. BEGIN
  390. IF (sender = rectColorEdit) THEN
  391. rectColorEdit.GetAsString(colorString);
  392. Strings.IntToHexStr(theCaller.rectColor, 7, origString);
  393. IF origString # colorString THEN (* Set new FillColor *)
  394. Strings.HexStrToInt(colorString, color, res);
  395. theCaller.rectColor := color;
  396. END;
  397. ELSIF (sender = rectColorEdit2) THEN
  398. rectColorEdit2.GetAsString(colorString);
  399. Strings.IntToHexStr(theCaller.rectColor2, 7, origString);
  400. IF origString # colorString THEN (* Set new 2nd FillColor *)
  401. Strings.HexStrToInt(colorString, color, res);
  402. theCaller.rectColor2 := color;
  403. END;
  404. ELSIF (sender = lineColorEdit) THEN
  405. lineColorEdit.GetAsString(colorString);
  406. Strings.IntToHexStr(theCaller.lineColor, 7, origString);
  407. IF origString # colorString THEN (* Set new LineColor *)
  408. Strings.HexStrToInt(colorString, color, res);
  409. theCaller.lineColor := color;
  410. END;
  411. ELSIF (sender = lineWidthEdit) THEN
  412. lineWidthEdit.GetAsString(colorString);
  413. Strings.FloatToStr(theCaller.lineWidth, 0, 5, 0, origString);
  414. IF origString # colorString THEN (* Set new LineWidth *)
  415. Strings.StrToFloat(colorString, width);
  416. theCaller.lineWidth := SHORT(width);
  417. END;
  418. ELSIF (sender = fillModeEdit) THEN
  419. fillModeEdit.GetAsString(colorString);
  420. Strings.IntToStr(theCaller.fillMode, origString);
  421. IF origString # colorString THEN (* Set new FillMode *)
  422. Strings.StrToInt(colorString, color);
  423. theCaller.fillMode := color;
  424. END;
  425. ELSIF (sender = gradHorizEdit) THEN
  426. gradHorizEdit.GetAsString(colorString);
  427. Strings.BoolToStr(theCaller.gradientHorizontal, origString);
  428. IF origString # colorString THEN (* Set new GradientType *)
  429. Strings.StrToBool(colorString, bool);
  430. theCaller.gradientHorizontal := bool;
  431. END;
  432. ELSE
  433. END;
  434. theCaller.Redraw;
  435. RefreshValues;
  436. END SetValueHandler;
  437. PROCEDURE Close*;
  438. BEGIN
  439. shown := FALSE;
  440. Hide;
  441. Close^;
  442. END Close;
  443. END RectPropWindow;
  444. (* ----------------------------------------------------------------------- *)
  445. VAR
  446. ctxFillModeSolid, ctxFillModeGradient, ctxFillModeGradientReflected: ContextMenuData;
  447. PROCEDURE GenRect*(): DTPData.ContentObject;
  448. VAR rectangle: RectObject;
  449. BEGIN
  450. NEW(rectangle);
  451. RETURN rectangle;
  452. END GenRect;
  453. PROCEDURE Register*;
  454. BEGIN
  455. DTPEditor.plugRegistry.RegisterPlugin(pluginName, GenRect);
  456. END Register;
  457. PROCEDURE Cleanup;
  458. BEGIN
  459. DTPEditor.plugRegistry.UnregisterPlugin(pluginName);
  460. END Cleanup;
  461. BEGIN
  462. Modules.InstallTermHandler(Cleanup);
  463. NEW(ctxFillModeSolid, fillModeSolid);
  464. NEW(ctxFillModeGradient, fillModeGradient);
  465. NEW(ctxFillModeGradientReflected, fillModeGradientReflected);
  466. END DTPRect.