3 Copyright (c
) 1999 by Michael van Canneyt
and Goran Andersson
10 Changes by Goeran Andersson
:
13 Handles WM_DrawBkgnd to reduce flicker
14 Changes to also compile
in FPC mode
16 Changes by Morten Skovrup
:
22 Changes by Goeran Andersson
:
28 Client edge added to editor
29 Changes to also compile
in FPC mode
30 Handles Edit modify flag
32 Key codes added to edit menu
33 Undo
, Cut
, Copy
& Paste implemented
34 WM_Paint sections commented
42 EditCreate styles corrected
56 TFileName
= Array
[0..Max_Path
] Of Char
;
60 HWindow
,HStatus
,HEdit
: HWnd
;
62 TheLogFont
: TLogFont
;
66 {********************************************************************}
68 Procedure
SetStatusText(Num
: Integer
; Const Text
: string
);
70 StatText
: array
[0..255] of Char
;
73 StatText
[0] := ' ' // Add space to text
in first item
75 StatText
[0] := #9; // Center the rest
76 StrPCopy(@StatText[1],Text
);
77 SendMessage(HStatus
,SB_SETTEXT
,Num
,LongInt(@StatText));
80 {********************************************************************}
82 Function
SelectFile(Var FName
:TFileName; Open
:Boolean): Boolean
;
84 Filter
: PChar
= 'Text files (*.txt)'#0'*.txt'#0+
85 'All files (*.*)'#0'*.*'#0#0;
88 NameRec
: OpenFileName
;
90 FillChar(NameRec
,SizeOf(NameRec
),0);
94 LStructSize
:= SizeOf(NameRec
);
96 LpStrFilter
:= Filter
;
99 Flags
:= OFN_Explorer Or OFN_HideReadOnly
;
102 Flags
:= Flags Or OFN_FileMustExist
;
107 SelectFile
:= GetOpenFileName(@NameRec)
109 SelectFile
:= GetSaveFileName(@NameRec);
112 {********************************************************************}
121 If
SelectFile(FName
,False
) Then
125 Len
:= GetWindowTextLength(HEdit
);
130 GetWindowText(HEdit
,P
,Len
+1);
131 BlockWrite(F
,P^
,Len
);
135 StrCopy(FileName
,FName
);
136 SetStatusText(0,StrPas(FileName
));
138 SendMessage(HEdit
,EM_SetModify
,0,0);
142 {********************************************************************}
146 BoxType
= MB_IconQuestion Or MB_YesNo
;
148 If
SendMessage(HEdit
,EM_GetModify
,0,0)<>0 Then
150 If
MessageBox(HWindow
,'Save text?','Edited',BoxType
)=IdYes Then
157 {********************************************************************}
166 If
SelectFile(FileName
,True
) Then
173 If Len
>0 Then
BlockRead(F
,P^
,Len
);
175 SetWindowText(HEdit
,P
);
176 SendMessage(HEdit
,EM_SetModify
,0,0);
178 SetStatusText(0,StrPas(FileName
));
183 {********************************************************************}
190 FileName
:= 'Unsaved';
191 SetStatusText(0,StrPas(FileName
));
192 SendMessage(HEdit
,WM_SetText
,1,LongInt(Empty
));
193 SendMessage(HEdit
,EM_SetModify
,0,0);
196 {********************************************************************}
198 procedure SelectFont
;
200 ChooseFontRec
: TChooseFont
;
202 with ChooseFontRec
do
204 lStructSize
:= SizeOf(ChooseFontRec
);
205 hwndOwner
:= HWindow
;
207 lpLogFont
:= @TheLogFont;
209 Flags
:= CF_INITTOLOGFONTSTRUCT
or CF_SCREENFONTS
or CF_EFFECTS
;
210 rgbColors
:= TheColor
;
213 lpTemplateName
:= nil;
220 if ChooseFont(@ChooseFontRec) then
222 DeleteObject(TheFont
);
223 TheColor
:= ChooseFontRec
.rgbColors
;
224 TheFont
:= CreateFontIndirect(@TheLogFont);
225 SendMessage(HEdit
,WM_SETFONT
,TheFont
,1);
229 {********************************************************************}
231 Function
WindowProc (Window
:HWnd;AMessage
,WParam
,LParam
:Longint): Longint
;
260 GetClientRect(HStatus
,@R);
261 StatH
:= R
.Bottom-R
.Top
;
262 GetClientRect(Window
,@R);
263 MoveWindow (HEdit
,0,0,R
.Right
,R
.Bottom-StatH
,False
);
264 MoveWindow (HStatus
,0,R
.Bottom-StatH
,R
.Right
,R
.Bottom
,False
);
268 NotiCode
:= HiWord(WParam
);
270 en_Change
: //Editor has changed
272 If
SendMessage(HEdit
,EM_GetModify
,0,0)<>0 then
273 SetStatusText(1,'Modified')
279 NrMenu
:= LoWord(WParam
);
284 104 : PostMessage(Window
,WM_Close
,0,0);
285 201 : SendMessage(HEdit
,WM_Undo
,0,0);
286 202 : SendMessage(HEdit
,WM_Cut
,0,0);
287 203 : SendMessage(HEdit
,WM_Copy
,0,0);
288 204 : SendMessage(HEdit
,WM_Paste
,0,0);
290 401 : MessageBox(Window
,'Help','Not implemented',
291 MB_OK Or MB_IconInformation
);
298 SetTextColor(WParam
,TheColor
);
299 Exit(GetSysColorBrush(COLOR_WINDOW
));
302 WindowProc
:= DefWindowProc(Window
,AMessage
,WParam
,LParam
);
305 {********************************************************************}
307 Function WinRegister
: Boolean
;
309 WindowClass
: WndClass
;
313 Style
:= cs_hRedraw Or cs_vRedraw
;
314 lpfnWndProc
:= WndProc(@WindowProc);
317 hInstance
:= system
.MainInstance
;
318 hIcon
:= LoadIcon (0,idi_Application
);
319 hCursor
:= LoadCursor (0,idc_Arrow
);
320 hbrBackground
:= GetStockObject(GRAY_BRUSH
);
322 lpszClassName
:= AppName
;
324 WinRegister
:= RegisterClass (WindowClass
)<>0;
327 {********************************************************************}
329 Function
EditCreate(ParentWindow
,Status
:HWnd): HWnd
;
331 CS_Start
= WS_Child
or WS_HScroll
or WS_VScroll
or ES_MultiLine
or ES_Left
;
332 CS_Ex
= WS_EX_ClientEdge
;
333 EdiTText
: PChar
= '';
339 GetClientRect(Status
,@R);
340 StatH
:= R
.Bottom-R
.Top
;
341 GetClientRect(ParentWindow
,@R);
342 HEdit
:= CreateWindowEx (CS_Ex
,'EDIT',EditText
,CS_Start
,0,0,
343 R
.Right-R
.Left
,R
.Bottom-R
.Top-StatH
,ParentWindow
,0,
347 //Set Courier new as default font
350 lfHeight
:= 0; // Default logical height of font
351 lfWidth
:= 0; // Default logical average character width
352 lfEscapement
:= 0; // angle of escapement
353 lfOrientation
:= 0; // base-line orientation angle
354 lfWeight
:= FW_NORMAL
; // font weight
355 lfItalic
:= 0; // italic attribute flag
356 lfUnderline
:= 0; // underline attribute flag
357 lfStrikeOut
:= 0; // strikeout attribute flag
358 lfCharSet
:= DEFAULT_CHARSET
; // character set identifier
359 lfOutPrecision
:= OUT_DEFAULT_PRECIS
; // output precision
360 lfClipPrecision
:= CLIP_DEFAULT_PRECIS
; // clipping precision
361 lfQuality
:= DEFAULT_QUALITY
; // output quality
362 lfPitchAndFamily
:= DEFAULT_PITCH
; // pitch
and family
363 Strcopy(lfFaceName
,'Courier New'); // pointer to typeface name string
365 TheColor
:= GetSysColor(COLOR_WINDOWTEXT
);
366 TheFont
:= CreateFontIndirect(@TheLogFont);
367 SendMessage(HEdit
,WM_SETFONT
,TheFont
,1);
368 ShowWindow(Hedit
,SW_Show
);
374 {********************************************************************}
376 Function WinCreate
: HWnd
;
382 hWindow
:= CreateWindow (AppName
,'EditDemo',ws_OverlappedWindow
,
383 cw_UseDefault
,cw_UseDefault
,cw_UseDefault
,
384 cw_UseDefault
,0,0,MainInstance
,Nil
);
388 SubMenu
:= CreateMenu
;
389 AppendMenu(Submenu
,MF_STRING
,101,'&New...');
390 AppendMenu(Submenu
,MF_STRING
,102,'&Open...');
391 AppendMenu(Submenu
,MF_STRING
,103,'&Save...');
392 AppendMenu(Submenu
,MF_SEPARATOR
,0,Nil
);
393 AppendMenu(SubMenu
,MF_String
,104,'E&xit');
394 AppendMenu(Menu
,MF_POPUP
,SubMenu
,'&File');
395 SubMenu
:= CreateMenu
;
396 AppendMenu(SubMenu
,MF_String
,201,'&Undo'#8'Ctrl+Z');
397 AppendMenu(Submenu
,MF_SEPARATOR
,0,Nil
);
398 AppendMenu(SubMenu
,MF_String
,202,'&Cut'#8'Ctrl+X');
399 AppendMenu(SubMenu
,MF_String
,203,'&Copy'#8'Ctrl+C');
400 AppendMenu(SubMenu
,MF_STRING
,204,'&Paste'#8'Ctrl+V');
401 AppendMenu(Menu
,MF_POPUP
,SubMenu
,'&Edit');
402 SubMenu
:= CreateMenu
;
403 AppendMenu(SubMenu
,MF_String
,301,'&Font...');
404 AppendMenu(Menu
,MF_POPUP
,SubMenu
,'&Options');
405 AppendMenu(Menu
,MF_STRING
,401,'&Help');
406 SetMenu(hWindow
,menu
);
407 ShowWindow(hWindow
,SW_Show
);
408 UpdateWindow(hWindow
);
410 WinCreate
:= hWindow
;
413 {********************************************************************}
415 Function
StatusCreate (parent
:hwnd): HWnd
;
418 Edges
: array
[1..2] of LongInt
;
420 FileName
:= 'Unsaved';
421 AWnd
:= CreateStatusWindow(WS_CHILD
or WS_VISIBLE
,FileName
,Parent
,$7712);
427 SendMessage(AWnd
,SB_SETPARTS
,2,LongInt(@Edges));
429 StatusCreate
:= AWnd
;
432 {********************************************************************}
435 If Not WinRegister Then
437 MessageBox (0,'Register failed',Nil
, mb_Ok
);
441 hWindow
:= WinCreate
;
442 If
longint(hWindow
)=0 Then
444 MessageBox (0,'WinCreate failed',Nil
,MB_OK
);
448 HStatus
:= statuscreate(hwindow
);
449 HEdit
:= EditCreate(HWindow
,HStatus
);
451 While
GetMessage(@AMessage,0,0,0) Do
453 TranslateMessage(AMessage
);
454 DispatchMessage(AMessage
);
456 DeleteObject(TheFont
);
457 Halt(AMessage
.wParam
);
464 Revision
1.1 2002/02/19 08:24:25 sasu
467 Revision
1.1 2000/07/13 06:30:20 michael
470 Revision
1.3 2000/07/11 08:51:05 michael
471 + Fixed Font handling
473 Revision
1.2 2000/02/27 21:07:58 florian
474 * updated
version from Goran
and Morton
476 Revision
1.1 2000/02/20 20:33:37 florian