brauchste gar nicht, mit folgendem Code wird ein autom. Zeilenumbruch aktiviert:
Kannst beliebig lange Texte in´n Editor übertragen...
Code: Alles auswählen
;+-------------------------------------------------------------------------+
;| PureBasic-QuellCode "Temp_B927" mit allen ModulBody´s |
;| erstellt durch Programm "PB_Mod2Body", Vers. 8A08a am 27.11.2008, 20:45 |
;+-------------------------------------------------------------------------+
;Modul Editor_ZeilenUmbruch Version 1.00 vom 27.03.2006
;
;Funktion: prüft aktuelle Textzeilen-Länge in einem Editor-Gadget (Zeilen=
; breite [Pixel] größer Editor-Breite [Pixel] und führt ggf. einen
; Zeilenumbruch durch incl. Cursor-Nachführung
; !!! WM_GETFONT funktioniert _nicht_ mit EditorGadget´s, daher muss
; !!! die FontID hier als Parameter angegeben werden !!! (daher auch
; !!! die spez. Fnc GetEditTextLen(), Variation von GetGadgetTextLen()...
;
;Aufruf: Editor_ZeilenUmbruch(#GadNr, FontID) - führt ggf. ZeilenUmbruch durch incl. Cursor-Nachführung
; #GadNr = GadgetNr des Editor-Gadget´s
; FontID = Handle des aktiven Font´s des Editor-Gadget´s
;
; Anwendung in WindowsEvent()-Schleife:
; Case #PB_EventGadget ;---------- Eingabe-Reaktionen ----------
; If EventGadgetID() = EditNr ;/========== Änderungen im Text ==========
; Editor_ZeilenUmbruch(EditNr, FontID)
; EndIf
;
;#jaPBeExt exit
;========== Begin Modul "C:\ALSTERSOFT\PB4.10\MODULE\GADGET\EDITOR\CRSPOSGET.PBI" ==========
Procedure Editor_GetCrsX(Gnr)
Protected GadID, Range.CHARRANGE
GadID = GadgetID(Gnr)
SendMessage_(GadID,#EM_EXGETSEL,0,Range)
ProcedureReturn (Range\cpMax-(SendMessage_(GadID,#EM_LINEINDEX,SendMessage_(GadID,#EM_EXLINEFROMCHAR,0,Range\cpMin),0))+1)
EndProcedure
Procedure Editor_GetCrsY(Gnr)
Protected GadID, Range.CHARRANGE
GadID = GadgetID(Gnr)
SendMessage_(GadID,#EM_EXGETSEL,0,Range)
ProcedureReturn SendMessage_(GadID,#EM_EXLINEFROMCHAR,0,Range\cpMin)+1
EndProcedure
;========== Ende Modul "C:\ALSTERSOFT\PB4.10\MODULE\GADGET\EDITOR\CRSPOSGET.PBI" ==========
;========== Begin Modul "C:\ALSTERSOFT\PB4.10\MODULE\GADGET\EDITOR\CRSPOSSET.PBI" ==========
Procedure Editor_CrsPosSet(GNR,x,y)
Protected Range.CHARRANGE, GadID, LLength, CharIdx
GadID = GadgetID(GNR)
CharIdx = SendMessage_(GadID,#EM_LINEINDEX,y-1,0)
LLength = SendMessage_(GadID,#EM_LINELENGTH,CharIdx,0)
If LLength >= x-1 : CharIdx + x-1 : EndIf
Range\cpMin = CharIdx
Range\cpMax = CharIdx
SendMessage_(GadID,#EM_EXSETSEL,0,Range)
EndProcedure
;========== Ende Modul "C:\ALSTERSOFT\PB4.10\MODULE\GADGET\EDITOR\CRSPOSSET.PBI" ==========
;========== Begin Modul "C:\ALSTERSOFT\PB4.10\MODULE\MAX.PBI" ==========
Procedure.l Max(w1.l,w2.l)
If w1>w2
ProcedureReturn w1
Else
ProcedureReturn w2
EndIf
EndProcedure
;========== Ende Modul "C:\ALSTERSOFT\PB4.10\MODULE\MAX.PBI" ==========
;========== Begin Modul "C:\ALSTERSOFT\PB4.10\MODULE\TRENNEN.PBI" ==========
Global Trenn_Kz$
Procedure.s trennen(*TrennText,TrennPos)
Protected Trenn_Out$,TrennChar,TrennText$, Trenn_Kz$
TrennText$=PeekS(*TrennText)
TrennChar = FindString(TrennText$,Chr(13),1)
If TrennChar>0 And TrennChar<=TrennPos
TrennText$=Left(TrennText$,TrennChar-1)+Mid(TrennText$,TrennChar+1,99999)
TrennChar=TrennChar-1
Else
If Trenn_Kz$="" : Trenn_Kz$=")}],:;_!?-= ({[$%&/´*+#^_"+Chr(34) : EndIf
If Mid(TrennText$,TrennPos+1,1)=" " : TrennChar = TrennPos+1 : Else : TrennChar=TrennPos : EndIf
While FindString(Trenn_Kz$,Mid(TrennText$,TrennChar,1),1)=0 And TrennChar>0 : TrennChar = TrennChar-1 : Wend
If TrennChar<3 : TrennChar = TrennPos : EndIf
TrennPos = FindString(Trenn_Kz$," ",1)
If FindString(Trenn_Kz$,Mid(TrennText$,TrennChar,1),1)>TrennPos : TrennChar = TrennChar-1 : EndIf
EndIf
Trenn_Out$ = RTrim(Left(TrennText$,TrennChar))
PokeS(*TrennText,LTrim(Mid(TrennText$,TrennChar+1,99999)))
ProcedureReturn Trenn_Out$
EndProcedure
;========== Ende Modul "C:\ALSTERSOFT\PB4.10\MODULE\TRENNEN.PBI" ==========
Procedure GetEditTextLen(GadNr, ED_FontID.l, Text$) ;liefert Textlänge [Pixel] in einem Editor-Gadget
Protected TextLang, GadID, hdc, TextSize.SIZE
GadID = GadgetID(GadNr)
If GadID
hdc = GetDC_(GadID)
If ED_FontID : SelectObject_(hdc, ED_FontID) : EndIf
If GetTextExtentPoint32_(hdc, Text$, Len(Text$), @TextSize) : TextLang = TextSize\cx : EndIf
ReleaseDC_(GadID, hdc)
EndIf
ProcedureReturn TextLang
EndProcedure
Procedure Editor_ZeilenUmbruch(EZ_GNR, EZ_FontID) ;- ZeilenUmbruch prüfen & ggf. durchführen incl. CursorNachführung
Protected Zeile, Zeile$, Pos, CrsX, CrsY
CrsX = Editor_GetCrsX(EZ_GNR)
CrsY = Editor_GetCrsY(EZ_GNR) - 1
Zeile$ = GetGadgetItemText(EZ_GNR, CrsY, 0)
If GetEditTextLen(EZ_GNR, EZ_FontID, Zeile$ + " ")>GadgetWidth(EZ_GNR)
Pos = Len(Zeile$) - 1
While GetEditTextLen(EZ_GNR, EZ_FontID, Left(Zeile$, Pos) + " ")>GadgetWidth(EZ_GNR) : Pos - 1 : Wend
SetGadgetItemText(EZ_GNR, CrsY, trennen(@Zeile$, Pos), 0)
AddGadgetItem(EZ_GNR, CrsY + 1, "")
SetGadgetItemText(EZ_GNR, CrsY + 1, Zeile$, 0)
If CrsX>Len(GetGadgetItemText(EZ_GNR, CrsY, 0))
CrsX = Max(1, CrsX - Len(GetGadgetItemText(EZ_GNR, CrsY, 0)) - 1) ;+ Len(Zeile$)
CrsY + 1
Editor_ZeilenUmbruch(EZ_GNR, EZ_FontID)
EndIf
Editor_CrsPosSet(EZ_GNR, CrsX, CrsY + 1)
EndIf
EndProcedure
WinNr=OpenWindow(#PB_Any,0,0,700,600,"Test",#PB_Window_SystemMenu)
CreateGadgetList(WindowID(WinNr))
EditGad=EditorGadget(#PB_Any,0,0,700,600)
AddGadgetItem(EditGad,-1,"format MS COFF extrn _ExitProcess@4 extrn _GetModuleFileNameA@12 extrn _GetModuleHandleA@4 extrn _HeapAlloc@12 extrn _HeapCreate@12 extrn _HeapDestroy@4 extrn _HeapFree@12 extrn _MultiByteToWideChar@24 extrn _RtlZeroMemory@8 extrn _SendMessageA@16 extrn _SetCurrentDirectoryA@4 extrn PB_CreateGadgetList extrn PB_FreeWindows extrn PB_GadgetID extrn PB_InitGadget extrn PB_InitMisc extrn PB_InitWindow extrn PB_Len extrn _PB_ListIconGadget2@32 extrn PB_OpenWindow extrn PB_PeekS extrn PB_PokeL extrn PB_ResizeGadget extrn PB_Space extrn PB_Str extrn PB_WaitWindowEvent extrn PB_WindowHeight extrn PB_WindowID2 extrn PB_WindowWidth extrn SYS_AllocateString extrn SYS_FastAllocateString extrn SYS_FastAllocateStringFree extrn SYS_FreeString extrn SYS_CopyString extrn SYS_StringEqual extrn SYS_StringSup extrn SYS_StringInf public PB_NullString public _PB_Instance public _PBV_ExecutableType public _PB_FullPath public _PB_MemoryBase public PB_Instance public PB_MemoryBase public _PB_EndFunctions public _PB_StringBase public ")
SetGadgetFont(EditGad,LoadFont(1,"ARIAL",14))
FontID=GetGadgetFont(EditGad)
Editor_ZeilenUmbruch(EditGad, FontID)
Repeat
Until WaitWindowEvent()=#PB_Event_CloseWindow
End