gtkshedit.pp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. {
  2. $Id$
  3. GTK implementation for SHEdit
  4. Copyright (C) 1999-2000 by Sebastian Guenther ([email protected])
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. }
  11. unit GtkSHEdit;
  12. interface
  13. {$MODE objfpc}
  14. {$H+}
  15. uses
  16. SysUtils, Classes,
  17. GDK, GTK,
  18. doc_text, SHEdit;
  19. const
  20. colBlack = $000000;
  21. colDarkBlue = $000080;
  22. colBlue = $0000ff;
  23. colDarkGreen = $008000;
  24. colGreen = $00ff00;
  25. colDarkCyan = $008080;
  26. colCyan = $00ffff;
  27. colBrown = $800000;
  28. colRed = $ff0000;
  29. colDarkMagenta = $800080;
  30. colMagenta = $ff00ff;
  31. colDarkYellow = $808000;
  32. colYellow = $ffff00;
  33. colGray = $808080;
  34. colGrey = colGray;
  35. colLightGray = $c0c0c0;
  36. colLightGrey = colLightGray;
  37. colWhite = $ffffff;
  38. colInvalid = $ff000000;
  39. colDefault = $ffffffff;
  40. type
  41. TSHFontStyle = (fsNormal, fsBold, fsItalics, fsBoldItalics);
  42. TSHStyle = record
  43. Name: String[32];
  44. Color, Background: LongWord;
  45. FontStyle: TSHFontStyle;
  46. end;
  47. TSHStyleArray = array[1..255] of TSHStyle; // Notice the 1!
  48. PSHStyleArray = ^TSHStyleArray;
  49. {This class is a kind of widget class which implements the ISHWidget
  50. interface for drawing syntax highlighted text}
  51. TGtkSHWidget = class(ISHWidget)
  52. protected
  53. SHStyles: PSHStyleArray;
  54. SHStyleCount: Integer; // # of currently registered styles
  55. shWhitespace: Integer;
  56. CurGCColor: LongWord;
  57. hadj, vadj: PGtkAdjustment;
  58. PaintBox: PGtkWidget;
  59. FEdit: TSHTextEdit;
  60. LeftIndent: Integer;
  61. CharW, CharH: Integer;
  62. Font: array[TSHFontStyle] of PGdkFont; // Fonts for content drawing
  63. gc: PGdkGC;
  64. GdkWnd: PGdkWindow;
  65. procedure SetGCColor(AColor: LongWord);
  66. // ISHWidget Implemenation:
  67. procedure InvalidateRect(x, y, w, h: Integer); override;
  68. // Drawing
  69. procedure ClearRect(x, y, w, h: Integer); override;
  70. procedure DrawTextLine(x1, x2, y: Integer; s: PChar); override;
  71. // Cursor
  72. procedure ShowCursor(x, y: Integer); override;
  73. procedure HideCursor(x, y: Integer); override;
  74. // Scrolling support
  75. function GetHorzPos: Integer; override;
  76. procedure SetHorzPos(x: Integer); override;
  77. function GetVertPos: Integer; override;
  78. procedure SetVertPos(y: Integer); override;
  79. function GetPageWidth: Integer; override;
  80. function GetPageHeight: Integer; override;
  81. function GetLineWidth: Integer; override;
  82. procedure SetLineWidth(count: Integer); override;
  83. function GetLineCount: Integer; override;
  84. procedure SetLineCount(count: Integer); override;
  85. // Clipboard support
  86. function GetClipboard: String; override;
  87. procedure SetClipboard(Content: String); override;
  88. public
  89. Widget: PGtkWidget; // this is the outer editor widget
  90. constructor Create(ADoc: TTextDoc; AEditClass: TSHTextEditClass);
  91. destructor Destroy; override;
  92. procedure SetFocus;
  93. function AddSHStyle(AName: String; AColor, ABackground: LongWord;
  94. AStyle: TSHFontStyle): Integer;
  95. property Edit: TSHTextEdit read FEdit;
  96. end;
  97. implementation
  98. var
  99. InternalClipboardContent: String;
  100. {*****************************************************************************
  101. GTK/GDK Callbacks
  102. *****************************************************************************}
  103. procedure TGtkSHWidget_Expose(GtkWidget: PGtkWidget; event: PGdkEventExpose;
  104. widget: TGtkSHWidget); cdecl;
  105. var
  106. x, y, w, h: Integer;
  107. begin
  108. x := (event^.area.x - widget.LeftIndent) div widget.CharW;
  109. y := event^.area.y div widget.CharH;
  110. w := (event^.area.x + event^.area.width + widget.CharW - 1) div widget.CharW - x;
  111. h := (event^.area.y + event^.area.height + widget.CharH - 1) div widget.CharH - y;
  112. // WriteLn(Format('Expose(%d/%d, %dx%d) for %s', [x, y, w, h, FEdit.ClassName]));
  113. widget.GdkWnd := widget.PaintBox^.window;
  114. widget.GC := gdk_gc_new(widget.GdkWnd);
  115. widget.CurGCColor := 0; // Reset color, because we have a new GC!
  116. gdk_gc_copy(widget.GC, PGtkStyle(widget.PaintBox^.thestyle)^.
  117. fg_gc[widget.PaintBox^.state]);
  118. widget.FEdit.AdjustCursorToRange;
  119. widget.FEdit.DrawContent(x, y, w, h);
  120. end;
  121. function TGtkSHWidget_KeyPressed(GtkWidget: PGtkWidget; Event: PGdkEventKey;
  122. widget: TGtkSHWidget): Integer; cdecl;
  123. var
  124. KeyState,
  125. KeyCode: LongWord;
  126. KeyMods: TShiftState;
  127. begin
  128. Result := 1;
  129. case Event^.KeyVal of
  130. GDK_Return : KeyCode:=13;
  131. GDK_KP_Insert : KeyCode:=GDK_Insert;
  132. GDK_KP_Home : KeyCode:=GDK_Home;
  133. GDK_KP_Left : KeyCode:=GDK_Left;
  134. GDK_KP_Up : KeyCode:=GDK_Up;
  135. GDK_KP_Right : KeyCode:=GDK_Right;
  136. GDK_KP_Down : KeyCode:=GDK_Down;
  137. GDK_KP_Page_Up : KeyCode:=GDK_Page_Up;
  138. GDK_KP_Page_Down : KeyCode:=GDK_Page_Down;
  139. GDK_KP_End : KeyCode:=GDK_End;
  140. GDK_Scroll_Lock,
  141. GDK_Num_Lock,
  142. GDK_Shift_L..GDK_Hyper_R :
  143. begin
  144. // Don't let modifier keys trough as normal keys
  145. // *** This doesn't work reliably! (sg)
  146. exit;
  147. end;
  148. else
  149. KeyCode:=Event^.KeyVal;
  150. end;
  151. KeyState:=Event^.State;
  152. // WriteLn('KeyCode ', KeyCode,' keystate ',KeyState);
  153. // Calculate the Key modifiers (shiftstate)
  154. KeyMods := [];
  155. if (KeyState and 1) <> 0 then KeyMods := KeyMods + [ssShift];
  156. if (KeyState and 2) <> 0 then KeyMods := KeyMods + [ssCaps];
  157. if (KeyState and 4) <> 0 then KeyMods := KeyMods + [ssCtrl];
  158. if (KeyState and 8) <> 0 then KeyMods := KeyMods + [ssAlt];
  159. if (KeyState and $10) <> 0 then KeyMods := KeyMods + [ssNum];
  160. if (KeyState and $40) <> 0 then KeyMods := KeyMods + [ssSuper];
  161. if (KeyState and $80) <> 0 then KeyMods := KeyMods + [ssScroll];
  162. if (KeyState and $100) <> 0 then KeyMods := KeyMods + [ssLeft];
  163. if (KeyState and $200) <> 0 then KeyMods := KeyMods + [ssMiddle];
  164. if (KeyState and $400) <> 0 then KeyMods := KeyMods + [ssRight];
  165. if (KeyState and $2000) <> 0 then KeyMods := KeyMods + [ssAltGr];
  166. widget.FEdit.KeyPressed(KeyCode,KeyMods);
  167. end;
  168. function TGtkSHWidget_ButtonPressEvent(GtkWidget: PGtkWidget;
  169. event: PGdkEventButton; widget: TGtkSHWidget): Integer; cdecl;
  170. begin
  171. widget.FEdit.CursorX := Round((event^.x - widget.LeftIndent) / widget.CharW);
  172. widget.FEdit.CursorY := Trunc(event^.y) div widget.CharH;
  173. widget.SetFocus;
  174. Result := 1;
  175. end;
  176. function TGtkSHWidget_FocusInEvent(GtkWidget: PGtkWidget;
  177. event: PGdkEventFocus; widget: TGtkSHWidget): Integer; cdecl;
  178. begin
  179. // Writeln('focus in');
  180. widget.FEdit.FocusIn;
  181. result:=1;
  182. end;
  183. function TGtkSHWidget_FocusOutEvent(GtkWidget: PGtkWidget; event: PGdkEventFocus; widget: TGtkSHWidget): Integer; cdecl;
  184. begin
  185. // Writeln('focus out');
  186. widget.FEdit.FocusOut;
  187. result:=1;
  188. end;
  189. {*****************************************************************************
  190. TGtkSHWidget
  191. *****************************************************************************}
  192. constructor TGtkSHWidget.Create(ADoc: TTextDoc; AEditClass: TSHTextEditClass);
  193. var
  194. lfd: String; // Logical font descriptor
  195. i: Integer;
  196. begin
  197. inherited Create;
  198. // Create fonts
  199. for i := 0 to 3 do begin
  200. lfd := '-*-courier-';
  201. if (i and 1) <> 0 then lfd := lfd + 'bold'
  202. else lfd := lfd + 'medium';
  203. lfd := lfd + '-';
  204. if (i and 2) <> 0 then lfd := lfd + 'i'
  205. else lfd := lfd + 'r';
  206. lfd := lfd + '-normal--14-*-*-*-*-*-iso8859-1';
  207. Font[TSHFontStyle(i)] := gdk_font_load(PChar(lfd));
  208. end;
  209. CharW := gdk_char_width(Font[fsBold], ' ');
  210. CharH := 14 {=FontHeight} + 3; // *** find better way to determine max. cell height
  211. LeftIndent := CharW;
  212. // Create scrolled window and drawing area
  213. hadj := PGtkAdjustment(gtk_adjustment_new(0, 0, 200, 1, 10, 100));
  214. vadj := PGtkAdjustment(gtk_adjustment_new(0, 0, 200, 1, 10, 100));
  215. Widget := gtk_scrolled_window_new(hadj, vadj);
  216. PaintBox := gtk_drawing_area_new;
  217. gtk_scrolled_window_add_with_viewport(PGtkScrolledWindow(Widget), PaintBox);
  218. gtk_widget_show(PaintBox);
  219. gtk_widget_set_flags(PGtkWidget(PaintBox),GTK_CAN_FOCUS);
  220. gtk_signal_connect(PGtkObject(PaintBox), 'expose-event',
  221. GTK_SIGNAL_FUNC(@TGtkSHWidget_Expose), self);
  222. gtk_signal_connect_after(PGtkObject(PaintBox), 'key-press-event',
  223. GTK_SIGNAL_FUNC(@TGtkSHWidget_Keypressed), self);
  224. gtk_signal_connect(PGtkObject(PaintBox), 'button-press-event',
  225. GTK_SIGNAL_FUNC(@TGtkSHWidget_ButtonPressEvent), self);
  226. gtk_signal_connect_after(PGtkObject(PaintBox), 'focus-in-event',
  227. GTK_SIGNAL_FUNC(@TGtkSHWidget_FocusInEvent), self);
  228. gtk_signal_connect_after(PGtkObject(PaintBox), 'focus-out-event',
  229. GTK_SIGNAL_FUNC(@TGtkSHWidget_FocusOutEvent), self);
  230. gtk_widget_set_events(PGtkWidget(Paintbox),
  231. GDK_EXPOSURE_MASK or GDK_KEY_PRESS_MASK or GDK_KEY_RELEASE_MASK or
  232. GDK_BUTTON_PRESS_MASK or GDK_ENTER_NOTIFY_MASK or GDK_LEAVE_NOTIFY_MASK);
  233. gtk_widget_show(Widget);
  234. FEdit := AEditClass.Create(ADoc, Self);
  235. shWhitespace := AddSHStyle('Whitespace', colBlack, colWhite, fsNormal);
  236. FEdit.shDefault := AddSHStyle('Default', colBlack, colWhite, fsNormal);
  237. FEdit.shSelected := AddSHStyle('Selected', colWhite, colDarkBlue, fsNormal);
  238. { Install keys }
  239. FEdit.AddKeyDef(@FEdit.CursorUp, selClear, 'Cursor up', GDK_Up, []);
  240. FEdit.AddKeyDef(@FEdit.CursorDown, selClear, 'Cursor down', GDK_Down, []);
  241. FEdit.AddKeyDef(@FEdit.CursorLeft, selClear, 'Cursor left', GDK_Left, []);
  242. FEdit.AddKeyDef(@FEdit.CursorRight, selClear, 'Cursor right', GDK_Right, []);
  243. FEdit.AddKeyDef(@FEdit.CursorHome, selClear, 'Cursor Home', GDK_Home, []);
  244. FEdit.AddKeyDef(@FEdit.CursorEnd, selClear, 'Cursor Home', GDK_End, []);
  245. FEdit.AddKeyDef(@FEdit.CursorPageUp, selClear, 'Cursor PageUp', GDK_Page_Up, []);
  246. FEdit.AddKeyDef(@FEdit.CursorPageDown, selClear, 'Cursor PageDown', GDK_Page_Down, []);
  247. FEdit.AddKeyDef(@FEdit.CursorDocBegin, selClear, 'Cursor Document Start', GDK_Page_Up, [ssCtrl]);
  248. FEdit.AddKeyDef(@FEdit.CursorDocEnd, selClear, 'Cursor Document End', GDK_Page_Down, [ssCtrl]);
  249. FEdit.AddKeyDef(@FEdit.CursorUp, selExtend, 'Selection up', GDK_Up, [ssShift]);
  250. FEdit.AddKeyDef(@FEdit.CursorDown, selExtend, 'Selection down', GDK_Down, [ssShift]);
  251. FEdit.AddKeyDef(@FEdit.CursorLeft, selExtend, 'Selection left', GDK_Left, [ssShift]);
  252. FEdit.AddKeyDef(@FEdit.CursorRight, selExtend, 'Selection right', GDK_Right, [ssShift]);
  253. FEdit.AddKeyDef(@FEdit.CursorHome, selExtend, 'Selection Home', GDK_Home, [ssShift]);
  254. FEdit.AddKeyDef(@FEdit.CursorEnd, selExtend, 'Selection Home', GDK_End, [ssShift]);
  255. FEdit.AddKeyDef(@FEdit.CursorPageUp, selExtend, 'Selection PageUp', GDK_Page_Up, [ssShift]);
  256. FEdit.AddKeyDef(@FEdit.CursorPageDown, selExtend, 'Selection PageDown', GDK_Page_Down, [ssShift]);
  257. FEdit.AddKeyDef(@FEdit.CursorDocBegin, selExtend, 'Selection Document Start', GDK_Page_Up, [ssCtrl,ssShift]);
  258. FEdit.AddKeyDef(@FEdit.CursorDocEnd, selExtend, 'Selection Document End', GDK_Page_Down, [ssCtrl,ssShift]);
  259. FEdit.AddKeyDef(@FEdit.ToggleOverwriteMode, selNothing, 'Toggle overwrite mode', GDK_Insert, []);
  260. FEdit.AddKeyDef(@FEdit.EditDelLeft, selClear, 'Delete char left of cursor', GDK_Backspace, []);
  261. FEdit.AddKeyDef(@FEdit.EditDelRight, selClear, 'Delete char right of cursor', GDK_Delete_Key, []);
  262. FEdit.AddKeyDef(@FEdit.EditDelLine, selClear, 'Delete current line', Ord('Y'), [ssCtrl]);
  263. FEdit.AddKeyDef(@FEdit.EditDelLine, selClear, 'Delete current line', Ord('y'), [ssCtrl]);
  264. FEdit.AddKeyDef(@FEdit.EditUndo, selClear, 'Undo last action', GDK_Backspace, [ssAlt]);
  265. FEdit.AddKeyDef(@FEdit.EditRedo, selClear, 'Redo last undone action', GDK_Backspace, [ssShift, ssAlt]);
  266. end;
  267. destructor TGtkSHWidget.Destroy;
  268. begin
  269. FreeMem(SHStyles);
  270. FEdit.Free;
  271. inherited Destroy;
  272. end;
  273. function TGtkSHWidget.AddSHStyle(AName: String; AColor, ABackground: LongWord; AStyle: TSHFontStyle): Integer;
  274. begin
  275. ReAllocMem(SHStyles, SizeOf(TSHStyle) * (SHStyleCount + 1));
  276. Inc(SHStyleCount);
  277. SHStyles^[SHStyleCount].Name := AName;
  278. SHStyles^[SHStyleCount].Color := AColor;
  279. SHStyles^[SHStyleCount].Background := ABackground;
  280. SHStyles^[SHStyleCount].FontStyle := AStyle;
  281. Result := SHStyleCount;
  282. end;
  283. procedure TGtkSHWidget.SetGCColor(AColor: LongWord);
  284. var
  285. c: TGdkColor;
  286. begin
  287. if AColor <> CurGCColor then begin
  288. c.pixel := 0;
  289. c.red := (((AColor shr 16) and 255) * 65535) div 255;
  290. c.green := (((AColor shr 8) and 255) * 65535) div 255;
  291. c.blue := ((AColor and 255) * 65535) div 255;
  292. gdk_colormap_alloc_color(gdk_colormap_get_system, @c, False, True);
  293. gdk_gc_set_foreground(gc, @c);
  294. CurGCColor := AColor;
  295. end;
  296. end;
  297. procedure TGtkSHWidget.ClearRect(x, y, w, h: Integer);
  298. begin
  299. SetGCColor(SHStyles^[shWhitespace].Background);
  300. gdk_draw_rectangle(PGdkDrawable(GdkWnd), GC, 1,
  301. x * CharW + LeftIndent, y * CharH, w * CharW, h * CharH);
  302. end;
  303. procedure TGtkSHWidget.InvalidateRect(x, y, w, h: Integer);
  304. var
  305. r : TGdkRectangle;
  306. begin
  307. r.x := x * CharW + LeftIndent;
  308. r.y := y * CharH;
  309. r.Width := w * CharW;
  310. r.Height := h * CharH;
  311. gtk_widget_draw(PGtkWidget(PaintBox), @r);
  312. end;
  313. procedure TGtkSHWidget.DrawTextLine(x1, x2, y: Integer; s: PChar);
  314. var
  315. CurColor: LongWord;
  316. CurX1, CurX2: Integer;
  317. procedure DoErase;
  318. begin
  319. SetGCColor(CurColor);
  320. if CurX1 < x1 then
  321. CurX1 := x1;
  322. if CurX2 > CurX1 then begin
  323. gdk_draw_rectangle(PGdkDrawable(GdkWnd), GC, 1,
  324. CurX1 * CharW + LeftIndent, y * CharH, (CurX2 - CurX1) * CharW, CharH);
  325. end;
  326. CurX1 := CurX2;
  327. end;
  328. var
  329. RequestedColor: Integer;
  330. NewColor: LongWord;
  331. hs : PChar;
  332. begin
  333. // Erase the (potentially multi-coloured) background
  334. hs := s;
  335. CurColor := SHStyles^[shWhitespace].Background;
  336. CurX1 := 0;
  337. CurX2 := 0;
  338. while (hs[0] <> #0) and (CurX2 <= x2) do begin
  339. case hs[0] of
  340. LF_Escape: begin
  341. NewColor := SHStyles^[Ord(hs[1])].Background;
  342. if NewColor = colDefault then
  343. NewColor := SHStyles^[shWhitespace].Background;
  344. if NewColor <> CurColor then begin
  345. DoErase;
  346. CurColor := NewColor;
  347. end;
  348. Inc(hs, 2);
  349. end;
  350. #9: begin
  351. repeat
  352. Inc(CurX2);
  353. until (CurX2 and 7) = 0;
  354. Inc(hs);
  355. end;
  356. else begin
  357. Inc(hs);
  358. Inc(CurX2);
  359. end;
  360. end;
  361. end;
  362. CurX2 := x2;
  363. DoErase;
  364. // Draw text line
  365. RequestedColor := shWhitespace;
  366. CurX1 := 0;
  367. while s[0] <> #0 do
  368. case s[0] of
  369. LF_Escape: begin
  370. RequestedColor := Ord(s[1]);
  371. Inc(s, 2);
  372. end;
  373. #9: begin
  374. repeat
  375. Inc(CurX1);
  376. until (CurX1 and 7) = 0;
  377. Inc(s);
  378. end;
  379. ' ': begin
  380. Inc(s);
  381. Inc(CurX1);
  382. end;
  383. else begin
  384. if (CurX1 >= x1) and (CurX1 <= x2) then begin
  385. SetGCColor(SHStyles^[RequestedColor].Color);
  386. gdk_draw_text(PGdkDrawable(GdkWnd),
  387. Font[SHStyles^[RequestedColor].FontStyle], GC,
  388. CurX1 * CharW + LeftIndent, (y + 1) * CharH - 3, s, 1);
  389. end;
  390. Inc(s);
  391. Inc(CurX1);
  392. end;
  393. end;
  394. end;
  395. procedure TGtkSHWidget.SetFocus;
  396. begin
  397. gtk_window_set_focus(PGtkWindow(gtk_widget_get_toplevel(Paintbox)),Paintbox);
  398. end;
  399. procedure TGtkSHWidget.ShowCursor(x, y: Integer);
  400. begin
  401. // writeln('Showcursor ',x,',',y);
  402. if assigned(GdkWnd) then
  403. begin
  404. SetGCColor(colBlack);
  405. gdk_draw_rectangle(PGdkDrawable(GdkWnd), GC, 1, x*CharW + LeftIndent, y*CharH, 2, CharH);
  406. end;
  407. end;
  408. procedure TGtkSHWidget.HideCursor(x, y: Integer);
  409. var
  410. r : TGdkRectangle;
  411. begin
  412. // writeln('Hidecursor ',x,',',y);
  413. r.x := x * CharW + LeftIndent;
  414. r.y := y * CharH;
  415. r.Width := 2;
  416. r.Height := CharH;
  417. gtk_widget_draw(PGtkWidget(PaintBox), @r);
  418. end;
  419. function TGtkSHWidget.GetLineWidth: Integer;
  420. begin
  421. Result := (Trunc(hadj^.upper)-LeftIndent) div CharW;
  422. end;
  423. procedure TGtkSHWidget.SetLineWidth(count: Integer);
  424. begin
  425. hadj^.upper := count * CharW + LeftIndent;
  426. gtk_adjustment_changed(hadj);
  427. gtk_widget_set_usize(PaintBox, Trunc(hadj^.upper), Trunc(vadj^.upper));
  428. end;
  429. function TGtkSHWidget.GetLineCount: Integer;
  430. begin
  431. Result := Trunc(vadj^.upper) div CharH;
  432. end;
  433. procedure TGtkSHWidget.SetLineCount(count: Integer);
  434. begin
  435. vadj^.upper := (count+1) * CharH;
  436. gtk_adjustment_changed(vadj);
  437. gtk_widget_set_usize(PaintBox, Trunc(hadj^.upper), Trunc(vadj^.upper));
  438. end;
  439. function TGtkSHWidget.GetClipboard: String;
  440. begin
  441. Result := InternalClipboardContent;
  442. end;
  443. procedure TGtkSHWidget.SetClipboard(Content: String);
  444. begin
  445. InternalClipboardContent := Content;
  446. end;
  447. function TGtkSHWidget.GetHorzPos: Integer;
  448. begin
  449. Result := Trunc(hadj^.value);
  450. if Result>0 then
  451. Result:=(Result-LeftIndent) div CharW;
  452. end;
  453. procedure TGtkSHWidget.SetHorzPos(x: Integer);
  454. begin
  455. if x>0 then
  456. x:=x*CharW+LeftIndent;
  457. gtk_adjustment_set_value(hadj, x);
  458. end;
  459. function TGtkSHWidget.GetVertPos: Integer;
  460. begin
  461. Result := (Trunc(vadj^.value)+CharH-1) div CharH;
  462. end;
  463. procedure TGtkSHWidget.SetVertPos(y: Integer);
  464. begin
  465. gtk_adjustment_set_value(vadj, y*CharH);
  466. end;
  467. function TGtkSHWidget.GetPageWidth: Integer;
  468. begin
  469. Result := Trunc(hadj^.page_size) div CharW;
  470. end;
  471. function TGtkSHWidget.GetPageHeight: Integer;
  472. begin
  473. Result := Trunc(vadj^.page_size) div CharH;
  474. end;
  475. end.
  476. {
  477. $Log$
  478. Revision 1.4 2002-09-07 15:15:28 peter
  479. * old logs removed and tabs fixed
  480. }