Autor Beitrag
starsurfer
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 334

Win 95, Win 98, Win XP, Win Vista, Linux
D5 Enterprise ,D2005, D6 Personal, Visual C++ Express 2005, C++ Builder 6 E, Dev-C++
BeitragVerfasst: Mo 10.04.06 10:36 
Für mein Editor möchte ich es jetzt ermöglichen das eine "Wortvervollständigung" möglich ist, ähnlich der Codevervollständigung in Delphi....

Bsp
geschrieben ist:
"doo"
als Vorschlag soll erscheinen:
"doof"
"doodeln"//ka was das sein soll, steht im Duden^^

Dazu brauch ich ja die aktuellen Position vom Cursor im Memo aber in Pixeln.
Das funktioniert auch so weit ganz gut, ABER es beachtet in der Berechnung kein Tabulator(siehe Highlight).
Wird der Tabulator genutzt erscheint die Listbox dann über dem zu schreibenen Text und das ist ja ziemlich unschön.

Gibt es da ne Möglichkeit das zu ändern?
(Für die die es ganz genau nehmen: WIE kann ich das ändern :) )

so sieht das zZ aus:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
function get_text_befor(txt:string):string;
var i:integer;
begin
result:='';
for i:=length(txt) downto 1 do
    begin
    if txt[i]in [#32,#9,#10] then exit else
       begin
       result:=result+txt[i];
       end;
    end;
end;

procedure TForm1.amemoChange(Sender: TObject);
var bild:tbitmap;
    z1,z2,z3,hoehe,breite:integer;
    text:string;
begin
bild:=tbitmap.Create;
with amemo do
     begin
     z1:=SendMessage(handle, EM_GETFIRSTVISIBLELINE, 0, 0);
     z2:=SendMessage(handle, EM_LINEfromchar, selstart, 0);
     end;
z3:=z2-z1;
with bild do
     begin
     font.Name:=amemo.Font.Name;
     font.Size:=amemo.Font.Size;
     font.style:=amemo.Font.Style;
     end;
text:=get_text_befor(copy(amemo.Lines.Text,0,amemo.SelStart));
if length(text)>=3 then
   begin
   listbox1.Visible:=true;
   hoehe:=bild.Canvas.TextHeight('A');
   breite:=bild.Canvas.TextWidth(amemo.Lines.Strings[z2])+10;
   listbox1.Left:=breite;
   listbox1.top:=z3*hoehe;
   end
  else
   begin
   listbox1.Visible:=false;
   end;
bild.free;
end;


//Edit: für die die jetzt sagen nehm doch die Komponente die kann das schon... ich WILLS selber machen, ich will ja auch mal irgendwie weiter mit Delphi kommen und wenn ich nur vorgefertigtes Zeug nehme wird das nix :wink:

_________________
GEIZ IST GEIL! - Ihr Sozialamt
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Mo 10.04.06 23:36 
Hallo,

der Code berücksichtigt auch Tabulatoren:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
procedure TForm1.ListBoxToCursor(Memo: TMemo;ListBox: TListBox);
var pos : TPoint;
    h,i   : integer;
    bmp : TBitmap;
begin
  bmp := TBitmap.Create;
  bmp.Canvas.Font := Memo.Font;
  h := bmp.Canvas.TextHeight('A');
  i := SendMessage(Memo.handle, EM_POSFROMCHAR, Memo.SelStart, 0);
  pos.x := LoWord(i);
  pos.y := HiWord(i);
  pos := ScreenToClient(Memo.ClientToScreen(pos));
  ListBox.Left := pos.x;
  ListBox.Top := pos.y+h;
  bmp.Free;
end;

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
starsurfer Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 334

Win 95, Win 98, Win XP, Win Vista, Linux
D5 Enterprise ,D2005, D6 Personal, Visual C++ Express 2005, C++ Builder 6 E, Dev-C++
BeitragVerfasst: Di 11.04.06 12:33 
Ah danke funktioniert super :wink:

aber eine Kleinigkeit musste ich noch ändern....
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
procedure TForm1.ListBoxToCursor(Memo: TMemo;ListBox: TListBox);  
var pos : TPoint;  
    h,i   : integer;  
    bmp : TBitmap;  
begin  
  bmp := TBitmap.Create;  
  bmp.Canvas.Font := Memo.Font;  
  h := bmp.Canvas.TextHeight('A');  
  i := SendMessage(Memo.handle, EM_POSFROMCHAR, Memo.SelStart-1, 0);  
  pos.x := LoWord(i);  
  pos.y := HiWord(i);  
  pos := ScreenToClient(Memo.ClientToScreen(pos));  
  ListBox.Left := pos.x;  
  ListBox.Top := pos.y+h;  
  bmp.Free;  
end;

_________________
GEIZ IST GEIL! - Ihr Sozialamt