gtkshedit.pp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  1. {
  2. $Id$
  3. GTK implementation for shedit
  4. Copyright (C) 1999 Sebastian Guenther ([email protected])
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. }
  17. unit gtkshedit;
  18. interface
  19. {$MODE objfpc}
  20. {$H+}
  21. uses
  22. SysUtils, Classes,
  23. GDK, GTK,
  24. doc_text, SHEdit;
  25. const
  26. colBlack = $000000;
  27. colDarkBlue = $000080;
  28. colBlue = $0000ff;
  29. colDarkGreen = $008000;
  30. colGreen = $00ff00;
  31. colDarkCyan = $008080;
  32. colCyan = $00ffff;
  33. colBrown = $800000;
  34. colRed = $ff0000;
  35. colDarkMagenta = $800080;
  36. colMagenta = $ff00ff;
  37. colDarkYellow = $808000;
  38. colYellow = $ffff00;
  39. colGray = $808080;
  40. colGrey = colGray;
  41. colLightGray = $c0c0c0;
  42. colLightGrey = colLightGray;
  43. colWhite = $ffffff;
  44. colInvalid = $ff000000;
  45. colDefault = $ffffffff;
  46. type
  47. TSHFontStyle = (fsNormal, fsBold, fsItalics, fsBoldItalics);
  48. TSHStyle = record
  49. Name: String[32];
  50. Color, Background: LongWord;
  51. FontStyle: TSHFontStyle;
  52. end;
  53. TSHStyleArray = array[1..1] of TSHStyle; // Notice the 1!
  54. PSHStyleArray = ^TSHStyleArray;
  55. {This class is a kind of widget class which implements the ISHRenderer
  56. interface for drawing syntax highlighted text}
  57. TGtkSHEdit = class(ISHRenderer)
  58. protected
  59. SHStyles: PSHStyleArray;
  60. SHStyleCount: Integer; // # of currently registered styles
  61. shWhitespace: Integer;
  62. CurGCColor: LongWord;
  63. hadj, vadj: PGtkAdjustment;
  64. PaintBox: PGtkWidget;
  65. Edit: TSHTextEdit;
  66. LeftIndent: Integer;
  67. CharW, CharH: Integer;
  68. Font: array[TSHFontStyle] of PGdkFont; // Fonts for content drawing
  69. gc: PGdkGC;
  70. GdkWnd: PGdkWindow;
  71. procedure SetEdit(AEdit: TSHTextEdit);
  72. procedure SetGCColor(AColor: LongWord);
  73. // ISHRenderer Implemenation:
  74. procedure InvalidateRect(x1, y1, x2, y2: Integer); override;
  75. procedure InvalidateLines(y1, y2: Integer); override;
  76. // Drawing
  77. procedure ClearRect(x1, y1, x2, y2: Integer); override;
  78. procedure DrawTextLine(x1, x2, y: Integer; s: PChar); override;
  79. // Cursor
  80. procedure ShowCursor(x, y: Integer); override;
  81. procedure HideCursor(x, y: Integer); override;
  82. // Scrolling support
  83. function GetHorzPos: Integer; override;
  84. procedure SetHorzPos(x: Integer); override;
  85. function GetVertPos: Integer; override;
  86. procedure SetVertPos(y: Integer); override;
  87. function GetPageWidth: Integer; override;
  88. function GetPageHeight: Integer; override;
  89. function GetLineWidth: Integer; override;
  90. procedure SetLineWidth(count: Integer); override;
  91. function GetLineCount: Integer; override;
  92. procedure SetLineCount(count: Integer); override;
  93. // Clipboard support
  94. //function GetClipboard: String; override;
  95. //procedure SetClipboard(Content: String); override;
  96. public
  97. Widget: PGtkWidget; // this is the outer editor widget
  98. constructor Create;
  99. procedure SetFocus;
  100. function AddSHStyle(AName: String; AColor, ABackground: LongWord;
  101. AStyle: TSHFontStyle): Integer;
  102. end;
  103. implementation
  104. {*****************************************************************************
  105. GTK/GDK Callbacks
  106. *****************************************************************************}
  107. procedure TGtkSHEdit_Expose(GtkWidget: PGtkWidget; event: PGdkEventExpose; edit: TGtkSHEdit); cdecl;
  108. var
  109. x1, y1, x2, y2: Integer;
  110. begin
  111. x1:=event^.area.x;
  112. if x1>0 then
  113. dec(x1,edit.LeftIndent);
  114. x2:=x1+event^.area.width - 1;
  115. x1:=x1 div edit.CharW;
  116. x2:=(x2+edit.CharW-1) div edit.CharW;
  117. y1 := event^.area.y div edit.CharH;
  118. y2 := (event^.area.y + event^.area.height - 1) div edit.CharH;
  119. // WriteLn(Format('Expose(%d/%d - %d/%d) for %s', [x1, y1, x2, y2, edit.ClassName]));
  120. edit.GdkWnd := edit.PaintBox^.window;
  121. edit.GC := gdk_gc_new(edit.GdkWnd);
  122. gdk_gc_copy(edit.GC, PGtkStyle(edit.PaintBox^.thestyle)^.
  123. fg_gc[edit.PaintBox^.state]);
  124. edit.Edit.AdjustCursorToRange;
  125. edit.Edit.DrawContent(x1, y1, x2, y2);
  126. end;
  127. function TGtkSHEdit_KeyPressed(GtkWidget: PGtkWidget; Event: PGdkEventKey; edit: TGtkSHEdit): Integer; cdecl;
  128. var
  129. KeyState,
  130. KeyCode: LongWord;
  131. KeyMods: TShiftState;
  132. begin
  133. Result := 1;
  134. Case Event^.KeyVal of
  135. GDK_KP_Insert : KeyCode:=GDK_Insert;
  136. GDK_KP_Home : KeyCode:=GDK_Home;
  137. GDK_KP_Left : KeyCode:=GDK_Left;
  138. GDK_KP_Up : KeyCode:=GDK_Up;
  139. GDK_KP_Right : KeyCode:=GDK_Right;
  140. GDK_KP_Down : KeyCode:=GDK_Down;
  141. GDK_KP_Page_Up : KeyCode:=GDK_Page_Up;
  142. GDK_KP_Page_Down : KeyCode:=GDK_Page_Down;
  143. GDK_KP_End : KeyCode:=GDK_End;
  144. GDK_Scroll_Lock,
  145. GDK_Num_Lock,
  146. GDK_Shift_L..GDK_Hyper_R :
  147. begin
  148. // Don't let modifier keys trough as normal keys
  149. exit;
  150. end;
  151. else
  152. KeyCode:=Event^.KeyVal;
  153. end;
  154. KeyState:=Event^.State;
  155. // WriteLn('KeyCode ', KeyCode,' keystate ',KeyState);
  156. // Calculate the Key modifiers (shiftstate)
  157. KeyMods := [];
  158. if (KeyState and 1) <> 0 then KeyMods := KeyMods + [ssShift];
  159. if (KeyState and 2) <> 0 then KeyMods := KeyMods + [ssCaps];
  160. if (KeyState and 4) <> 0 then KeyMods := KeyMods + [ssCtrl];
  161. if (KeyState and 8) <> 0 then KeyMods := KeyMods + [ssAlt];
  162. if (KeyState and $10) <> 0 then KeyMods := KeyMods + [ssNum];
  163. if (KeyState and $40) <> 0 then KeyMods := KeyMods + [ssSuper];
  164. if (KeyState and $80) <> 0 then KeyMods := KeyMods + [ssScroll];
  165. if (KeyState and $100) <> 0 then KeyMods := KeyMods + [ssLeft];
  166. if (KeyState and $200) <> 0 then KeyMods := KeyMods + [ssMiddle];
  167. if (KeyState and $400) <> 0 then KeyMods := KeyMods + [ssRight];
  168. if (KeyState and $2000) <> 0 then KeyMods := KeyMods + [ssAltGr];
  169. edit.Edit.KeyPressed(KeyCode,KeyMods);
  170. end;
  171. function TGtkSHEdit_ButtonPressEvent(GtkWidget: PGtkWidget; event: PGdkEventButton ; edit: TGtkSHEdit): Integer; cdecl;
  172. begin
  173. Writeln('button press');
  174. Result := 1;
  175. end;
  176. function TGtkShEdit_FocusInEvent(GtkWidget: PGtkWidget; event: PGdkEventFocus; edit: TGtkSHEdit): Integer; cdecl;
  177. begin
  178. // Writeln('focus in');
  179. edit.Edit.FocusIn;
  180. result:=1;
  181. end;
  182. function TGtkShEdit_FocusOutEvent(GtkWidget: PGtkWidget; event: PGdkEventFocus; edit: TGtkSHEdit): Integer; cdecl;
  183. begin
  184. // Writeln('focus out');
  185. edit.Edit.FocusOut;
  186. result:=1;
  187. end;
  188. {*****************************************************************************
  189. TGtkSHEdit
  190. *****************************************************************************}
  191. constructor TGtkSHEdit.Create;
  192. var
  193. lfd: String; // Logical font descriptor
  194. i: Integer;
  195. begin
  196. inherited Create;
  197. // Create fonts
  198. for i := 0 to 3 do begin
  199. lfd := '-*-courier-';
  200. if (i and 1) <> 0 then lfd := lfd + 'bold'
  201. else lfd := lfd + 'medium';
  202. lfd := lfd + '-';
  203. if (i and 2) <> 0 then lfd := lfd + 'i'
  204. else lfd := lfd + 'r';
  205. lfd := lfd + '-normal--14-*-*-*-*-*-iso8859-1';
  206. Font[TSHFontStyle(i)] := gdk_font_load(PChar(lfd));
  207. end;
  208. CharW := gdk_char_width(Font[fsBold], ' ');
  209. CharH := 14 {=FontHeight} + 3; // *** find better way to determine max. cell height
  210. Edit := nil;
  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. PGtkObject(PaintBox)^.flags := PGtkObject(PaintBox)^.flags or GTK_CAN_FOCUS;
  220. gtk_signal_connect(PGtkObject(PaintBox), 'expose-event',
  221. GTK_SIGNAL_FUNC(@TGtkSHEdit_Expose), self);
  222. gtk_signal_connect_after(PGtkObject(PaintBox), 'key-press-event',
  223. GTK_SIGNAL_FUNC(@TGtkSHEdit_KeyPressed), self);
  224. gtk_signal_connect_after(PGtkObject(PaintBox), 'button-press-event',
  225. GTK_SIGNAL_FUNC(@TGtkSHEdit_KeyPressed), self);
  226. gtk_signal_connect_after(PGtkObject(PaintBox), 'focus-in-event',
  227. GTK_SIGNAL_FUNC(@TGtkSHEdit_FocusInEvent), self);
  228. gtk_signal_connect_after(PGtkObject(PaintBox), 'focus-out-event',
  229. GTK_SIGNAL_FUNC(@TGtkSHEdit_FocusOutEvent), self);
  230. gtk_widget_show(Widget);
  231. end;
  232. procedure TGtkSHEdit.SetEdit(AEdit: TSHTextEdit);
  233. begin
  234. Edit := AEdit;
  235. shWhitespace := AddSHStyle('Whitespace', colBlack, colWhite, fsNormal);
  236. Edit.shDefault := AddSHStyle('Default', colBlack, colWhite, fsNormal);
  237. Edit.shSelected := AddSHStyle('Selected', colWhite, colBlue, fsNormal);
  238. { Install keys }
  239. Edit.AddKeyDef(@Edit.CursorUp, selClear, 'Cursor up', GDK_Up, []);
  240. Edit.AddKeyDef(@Edit.CursorDown, selClear, 'Cursor down', GDK_Down, []);
  241. Edit.AddKeyDef(@Edit.CursorLeft, selClear, 'Cursor left', GDK_Left, []);
  242. Edit.AddKeyDef(@Edit.CursorRight, selClear, 'Cursor right', GDK_Right, []);
  243. Edit.AddKeyDef(@Edit.CursorHome, selClear, 'Cursor Home', GDK_Home, []);
  244. Edit.AddKeyDef(@Edit.CursorEnd, selClear, 'Cursor Home', GDK_End, []);
  245. Edit.AddKeyDef(@Edit.CursorPageUp, selClear, 'Cursor PageUp', GDK_Page_Up, []);
  246. Edit.AddKeyDef(@Edit.CursorPageDown, selClear, 'Cursor PageDown', GDK_Page_Down, []);
  247. Edit.AddKeyDef(@Edit.CursorDocBegin, selClear, 'Cursor Document Start', GDK_Page_Up, [ssCtrl]);
  248. Edit.AddKeyDef(@Edit.CursorDocEnd, selClear, 'Cursor Document End', GDK_Page_Down, [ssCtrl]);
  249. Edit.AddKeyDef(@Edit.CursorUp, selExtend, 'Selection up', GDK_Up, [ssShift]);
  250. Edit.AddKeyDef(@Edit.CursorDown, selExtend, 'Selection down', GDK_Down, [ssShift]);
  251. Edit.AddKeyDef(@Edit.CursorLeft, selExtend, 'Selection left', GDK_Left, [ssShift]);
  252. Edit.AddKeyDef(@Edit.CursorRight, selExtend, 'Selection right', GDK_Right, [ssShift]);
  253. Edit.AddKeyDef(@Edit.CursorHome, selExtend, 'Selection Home', GDK_Home, [ssShift]);
  254. Edit.AddKeyDef(@Edit.CursorEnd, selExtend, 'Selection Home', GDK_End, [ssShift]);
  255. Edit.AddKeyDef(@Edit.CursorPageUp, selExtend, 'Selection PageUp', GDK_Page_Up, [ssShift]);
  256. Edit.AddKeyDef(@Edit.CursorPageDown, selExtend, 'Selection PageDown', GDK_Page_Down, [ssShift]);
  257. Edit.AddKeyDef(@Edit.CursorDocBegin, selExtend, 'Selection Document Start', GDK_Page_Up, [ssCtrl,ssShift]);
  258. Edit.AddKeyDef(@Edit.CursorDocEnd, selExtend, 'Selection Document End', GDK_Page_Down, [ssCtrl,ssShift]);
  259. Edit.AddKeyDef(@Edit.ToggleOverwriteMode, selNothing, 'Toggle overwrite mode', GDK_Insert, []);
  260. Edit.AddKeyDef(@Edit.EditDelLeft, selClear, 'Delete char left of cursor', GDK_Backspace, []);
  261. Edit.AddKeyDef(@Edit.EditDelRight, selClear, 'Delete char right of cursor', GDK_Delete, []);
  262. Edit.AddKeyDef(@Edit.EditDelLine, selClear, 'Delete current line', Ord('Y'), [ssCtrl]);
  263. Edit.AddKeyDef(@Edit.EditUndo, selClear, 'Undo last action', GDK_Backspace, [ssAlt]);
  264. Edit.AddKeyDef(@Edit.EditRedo, selClear, 'Redo last undone action', GDK_Backspace, [ssShift, ssAlt]);
  265. end;
  266. function TGtkSHEdit.AddSHStyle(AName: String; AColor, ABackground: LongWord; AStyle: TSHFontStyle): Integer;
  267. begin
  268. ReAllocMem(SHStyles, SizeOf(TSHStyle) * (SHStyleCount + 1));
  269. Inc(SHStyleCount);
  270. SHStyles^[SHStyleCount].Name := AName;
  271. SHStyles^[SHStyleCount].Color := AColor;
  272. SHStyles^[SHStyleCount].Background := ABackground;
  273. SHStyles^[SHStyleCount].FontStyle := AStyle;
  274. Result := SHStyleCount;
  275. end;
  276. procedure TGtkSHEdit.SetGCColor(AColor: LongWord);
  277. var
  278. c: TGdkColor;
  279. begin
  280. if AColor <> CurGCColor then begin
  281. c.pixel := 0;
  282. c.red := (((AColor shr 16) and 255) * 65535) div 255;
  283. c.green := (((AColor shr 8) and 255) * 65535) div 255;
  284. c.blue := ((AColor and 255) * 65535) div 255;
  285. gdk_colormap_alloc_color(gdk_colormap_get_system, @c, False, True);
  286. gdk_gc_set_foreground(gc, @c);
  287. CurGCColor := AColor;
  288. end;
  289. end;
  290. procedure TGtkSHEdit.ClearRect(x1, y1, x2, y2: Integer);
  291. begin
  292. SetGCColor(SHStyles^[shWhitespace].Background);
  293. gdk_draw_rectangle(PGdkDrawable(GdkWnd), GC, 1,
  294. x1 * CharW + LeftIndent, y1 * CharH,
  295. (x2 - x1 + 1) * CharW, (y2 - y1 + 1) * CharH);
  296. end;
  297. procedure TGtkSHEdit.InvalidateRect(x1, y1, x2, y2: Integer);
  298. var
  299. r : TGdkRectangle;
  300. begin
  301. r.x:=x1*CharW+LeftIndent;
  302. r.y:=y1*CharH;
  303. r.Width:=(x1 - x2 + 1) * CharW;
  304. r.Height:=(y2 - y1 + 1) * CharH;
  305. gtk_widget_draw(PGtkWidget(PaintBox), @r);
  306. end;
  307. procedure TGtkSHEdit.InvalidateLines(y1, y2: Integer);
  308. var
  309. r : TGdkRectangle;
  310. w,h : integer;
  311. begin
  312. gdk_window_get_size(PGdkDrawable(GdkWnd),@w,@h);
  313. r.x:=0;
  314. r.y:=y1 * CharH;
  315. r.Width:=w;
  316. r.Height:=(y2 - y1 + 1) * CharH;
  317. gtk_widget_draw(PGtkWidget(PaintBox), @r);
  318. end;
  319. procedure TGtkSHEdit.DrawTextLine(x1, x2, y: Integer; s: PChar);
  320. var
  321. CurColor: LongWord;
  322. rx1,rx2 : Integer;
  323. procedure doerase;
  324. begin
  325. if rx2>x1 then
  326. begin
  327. SetGCColor(CurColor);
  328. gdk_draw_rectangle(PGdkDrawable(GdkWnd), GC, 1,
  329. rx1 * CharW + LeftIndent, y * CharH, (rx2 - rx1 + 1) * CharW, CharH);
  330. rx1:=rx2;
  331. end;
  332. end;
  333. var
  334. RequestedColor: Char;
  335. i, j, px: Integer;
  336. NewColor: LongWord;
  337. hs : pchar;
  338. begin
  339. // WriteLn(Format('DrawTextLine(%d) for %s ', [y, ClassName]));
  340. // Erase the (potentially multi-coloured) background
  341. rx1 := x1;
  342. rx2 := 0;
  343. j := 0;
  344. CurColor := SHStyles^[shWhitespace].Background;
  345. // Clear background
  346. hs:=s;
  347. rx2:=0;
  348. repeat
  349. case hs[0] of
  350. #0 :
  351. break;
  352. LF_Escape :
  353. begin
  354. NewColor := SHStyles^[Ord(hs[1])].Background;
  355. if NewColor = colDefault then
  356. NewColor := SHStyles^[shWhitespace].Background;
  357. if (NewColor <> CurColor) then
  358. begin
  359. DoErase;
  360. CurColor := NewColor;
  361. end;
  362. Inc(hs, 2);
  363. end;
  364. #9 :
  365. begin
  366. repeat
  367. Inc(rx2, CharW);
  368. Inc(i);
  369. until (i and 7) = 0;
  370. Inc(hs);
  371. end;
  372. else
  373. begin
  374. Inc(hs);
  375. Inc(i);
  376. Inc(rx2);
  377. end;
  378. end;
  379. until false;
  380. rx2 := x2;
  381. DoErase;
  382. // Draw text line
  383. RequestedColor := #1;
  384. CurGCColor := colInvalid;
  385. i := 0;
  386. px := 0;
  387. repeat
  388. case s[0] of
  389. #0 :
  390. break;
  391. LF_Escape :
  392. begin
  393. RequestedColor := s[1];
  394. Inc(s, 2);
  395. end;
  396. #9 :
  397. begin
  398. repeat
  399. Inc(px, CharW);
  400. Inc(i);
  401. until (i and 7) = 0;
  402. Inc(s);
  403. end;
  404. else
  405. begin
  406. if (px >= x1) and (px <= x2) then
  407. begin
  408. SetGCColor(SHStyles^[Ord(RequestedColor)].Color);
  409. gdk_draw_text(PGdkDrawable(GdkWnd),
  410. Font[SHStyles^[Ord(RequestedColor)].FontStyle], GC,
  411. px * CharW + LeftIndent, (y + 1) * CharH - 3, s, 1);
  412. end;
  413. Inc(s);
  414. Inc(i);
  415. Inc(px);
  416. end;
  417. end;
  418. until false;
  419. end;
  420. procedure TGtkSHEdit.SetFocus;
  421. begin
  422. gtk_window_set_focus(PGtkWindow(gtk_widget_get_toplevel(Paintbox)),Paintbox);
  423. end;
  424. procedure TGtkSHEdit.ShowCursor(x, y: Integer);
  425. begin
  426. // writeln('Showcursor ',x,',',y);
  427. if assigned(GdkWnd) then
  428. begin
  429. SetGCColor(colBlack);
  430. gdk_draw_rectangle(PGdkDrawable(GdkWnd), GC, 1, x*CharW + LeftIndent, y*CharH, 2, CharH);
  431. end;
  432. end;
  433. procedure TGtkSHEdit.HideCursor(x, y: Integer);
  434. var
  435. r : TGdkRectangle;
  436. begin
  437. // writeln('Hidecursor ',x,',',y);
  438. r.x := x * CharW + LeftIndent;
  439. r.y := y * CharH;
  440. r.Width := 2;
  441. r.Height := CharH;
  442. gtk_widget_draw(PGtkWidget(PaintBox), @r);
  443. end;
  444. function TGtkSHEdit.GetLineWidth: Integer;
  445. begin
  446. Result := (Trunc(hadj^.upper)-LeftIndent) div CharW;
  447. end;
  448. procedure TGtkSHEdit.SetLineWidth(count: Integer);
  449. begin
  450. hadj^.upper := count * CharW + LeftIndent;
  451. gtk_adjustment_changed(hadj);
  452. gtk_widget_set_usize(PaintBox, Trunc(hadj^.upper), Trunc(vadj^.upper));
  453. end;
  454. function TGtkSHEdit.GetLineCount: Integer;
  455. begin
  456. Result := Trunc(vadj^.upper) div CharH;
  457. end;
  458. procedure TGtkSHEdit.SetLineCount(count: Integer);
  459. begin
  460. vadj^.upper := (count+1) * CharH;
  461. gtk_adjustment_changed(vadj);
  462. gtk_widget_set_usize(PaintBox, Trunc(hadj^.upper), Trunc(vadj^.upper));
  463. end;
  464. function TGtkSHEdit.GetHorzPos: Integer;
  465. begin
  466. Result := Trunc(hadj^.value);
  467. if Result>0 then
  468. Result:=(Result-LeftIndent) div CharW;
  469. end;
  470. procedure TGtkSHEdit.SetHorzPos(x: Integer);
  471. begin
  472. if x>0 then
  473. x:=x*CharW+LeftIndent;
  474. gtk_adjustment_set_value(hadj, x);
  475. end;
  476. function TGtkSHEdit.GetVertPos: Integer;
  477. begin
  478. Result := (Trunc(vadj^.value)+CharH-1) div CharH;
  479. end;
  480. procedure TGtkSHEdit.SetVertPos(y: Integer);
  481. begin
  482. gtk_adjustment_set_value(vadj, y*CharH);
  483. end;
  484. function TGtkSHEdit.GetPageWidth: Integer;
  485. begin
  486. Result := Trunc(hadj^.page_size) div CharW;
  487. end;
  488. function TGtkSHEdit.GetPageHeight: Integer;
  489. begin
  490. Result := Trunc(vadj^.page_size) div CharH;
  491. end;
  492. end.
  493. {
  494. $Log$
  495. Revision 1.6 1999-12-10 15:01:02 peter
  496. * first things for selection
  497. * Better Adjusting of range/cursor
  498. Revision 1.5 1999/12/09 23:16:41 peter
  499. * cursor walking is now possible, both horz and vert ranges are now
  500. adapted
  501. * filter key modifiers
  502. * selection move routines added, but still no correct output to the
  503. screen
  504. Revision 1.4 1999/12/08 01:03:15 peter
  505. * changes so redrawing and walking with the cursor finally works
  506. correct
  507. Revision 1.3 1999/12/08 00:42:54 sg
  508. * The cursor should be displayed correctly now
  509. Revision 1.2 1999/12/06 21:27:27 peter
  510. * gtk updates, redrawing works now much better and clears only between
  511. x1 and x2
  512. Revision 1.1 1999/11/15 21:47:36 peter
  513. * first working keypress things
  514. }