?? asmedit.inc
字號:
; Assembly Editor interface for Win32 IDE
; Copyright (c) 2001-2006, Tomasz Grysztar.
; All rights reserved.
SEGMENT_LENGTH = 100h
BLOCK_LENGTH = 100h * SEGMENT_LENGTH
SEGMENT_HEADER_LENGTH = 16
SEGMENT_DATA_LENGTH = SEGMENT_LENGTH - SEGMENT_HEADER_LENGTH
proc AsmEdit hwnd,wmsg,wparam,lparam
locals
editor_memory dd ?
editor_style dd ?
label editor_data
first_line dd ?
lines_count dd ?
peak_line_length dd ?
maximum_position dd ?
window_line dd ?
window_position dd ?
window_line_number dd ?
caret_line dd ?
caret_position dd ?
caret_line_number dd ?
selection_line dd ?
selection_position dd ?
selection_line_number dd ?
editor_mode dd ?
editor_status_size = $ - editor_data
editor_font dd ?
font_width dd ?
font_height dd ?
screen_base dd ?
screen_offset dd ?
screen_width dd ?
screen_height dd ?
screen_size dd ?
window_width dd ?
window_height dd ?
background_color dd ?
text_color dd ?
selection_background dd ?
selection_text dd ?
syntax_proc dd ?
syntax_colors dd ?
menu_handle dd ?
menu_window dd ?
line_buffer dd ?
line_buffer_size dd ?
unallocated_segments dd ?
unallocated_segments_end dd ?
released_segments dd ?
memory_search_block dd ?
memory_search_segment dd ?
lengths_table dd ?
undo_data dd ?
search_data dd ?
search_flags dd ?
caret_x dd ?
caret_y dd ?
current_operation db ?
last_operation db ?
mouse_select db ?
focus db ?
editor_data_size = $ - editor_data
return_value dd ?
background_brush dd ?
selection_brush dd ?
ps PAINTSTRUCT
tm TEXTMETRIC
sc SCROLLINFO
point POINT
rect RECT
size SIZE
char dd ?
kbstate rb 100h
was_selection db ?
line_selection db ?
clipboard_opened db ?
redraw_now db ?
notification db ?
endl
push ebx esi edi
invoke GetWindowLong,[hwnd],GWL_STYLE
mov [editor_style],eax
cmp [wmsg],WM_CREATE
je wm_create
cmp [wmsg],WM_GETDLGCODE
je wm_getdlgcode
invoke GetWindowLong,[hwnd],0
or eax,eax
jz defwndproc
mov [editor_memory],eax
lea esi,[eax+8]
lea edi,[editor_data]
mov ecx,editor_data_size shr 2
rep movsd
mov [return_value],0
mov [notification],0
mov [redraw_now],0
mov [clipboard_opened],0
cmp [wmsg],WM_DESTROY
je wm_destroy
cmp [wmsg],WM_PAINT
je wm_paint
invoke HideCaret,[hwnd]
cmp [wmsg],WM_HSCROLL
je wm_hscroll
cmp [wmsg],WM_VSCROLL
je wm_vscroll
cmp [wmsg],WM_SIZE
je wm_size
cmp [selection_line],0
setnz al
mov [was_selection],al
xor al,al
xchg [current_operation],al
mov [last_operation],al
mov eax,[wmsg]
cmp eax,WM_SETFOCUS
je wm_setfocus
cmp eax,WM_KILLFOCUS
je wm_killfocus
cmp eax,WM_KEYDOWN
je wm_keydown
cmp eax,WM_SYSKEYDOWN
je wm_syskeydown
cmp eax,WM_CHAR
je wm_char
cmp eax,WM_LBUTTONDOWN
je wm_lbuttondown
cmp eax,WM_LBUTTONUP
je wm_lbuttonup
cmp eax,WM_MOUSEMOVE
je wm_mousemove
cmp eax,WM_LBUTTONDBLCLK
je wm_lbuttondblclk
cmp eax,WM_MOUSEWHEEL
je wm_mousewheel
cmp eax,WM_RBUTTONDOWN
je wm_rbuttondown
cmp eax,WM_COPY
je wm_copy
cmp eax,WM_CUT
je wm_cut
cmp eax,WM_PASTE
je wm_paste
cmp eax,WM_CLEAR
je wm_clear
cmp eax,WM_SETTEXT
je wm_settext
cmp eax,WM_GETTEXTLENGTH
je wm_gettextlength
cmp eax,WM_GETTEXT
je wm_gettext
cmp eax,WM_SETFONT
je wm_setfont
cmp eax,WM_GETFONT
je wm_getfont
cmp eax,WM_UNDO
je wm_undo
cmp eax,EM_UNDO
je wm_undo
cmp eax,EM_CANUNDO
je em_canundo
cmp eax,EM_EMPTYUNDOBUFFER
je em_emptyundobuffer
cmp eax,EM_REPLACESEL
je em_replacesel
cmp eax,AEM_SETMODE
je aem_setmode
cmp eax,AEM_GETMODE
je aem_getmode
cmp eax,AEM_SETSYNTAXHIGHLIGHT
je aem_setsyntaxhighlight
cmp eax,AEM_SETRIGHTCLICKMENU
je aem_setrightclickmenu
cmp eax,AEM_GETLINELENGTH
je aem_getlinelength
cmp eax,AEM_GETLINE
je aem_getline
cmp eax,AEM_SETPOS
je aem_setpos
cmp eax,AEM_GETPOS
je aem_getpos
cmp eax,AEM_FINDFIRST
je aem_findfirst
cmp eax,AEM_FINDNEXT
je aem_findnext
cmp eax,AEM_CANFINDNEXT
je aem_canfindnext
cmp eax,AEM_GETWORDATCARET
je aem_getwordatcaret
cmp eax,AEM_SETTEXTCOLOR
je aem_settextcolor
cmp eax,AEM_SETSELCOLOR
je aem_setselcolor
invoke ShowCaret,[hwnd]
defwndproc:
invoke DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
jmp finish_wndproc
wm_create:
call init_editor_memory
jc create_failed
invoke SetWindowLong,[hwnd],0,[editor_memory]
mov [syntax_proc],SyntaxProc
mov [syntax_colors],0
mov [current_operation],0
mov [focus],0
mov [mouse_select],0
mov [menu_handle],0
mov eax,SEGMENT_DATA_LENGTH*2
mov [line_buffer_size],eax
invoke VirtualAlloc,0,eax,MEM_COMMIT,PAGE_READWRITE
or eax,eax
jz create_failed
mov [line_buffer],eax
mov [screen_base],0
invoke GetSysColor,COLOR_WINDOW
mov [background_color],eax
invoke GetSysColor,COLOR_WINDOWTEXT
mov [text_color],eax
invoke GetSysColor,COLOR_HIGHLIGHT
mov [selection_background],eax
invoke GetSysColor,COLOR_HIGHLIGHTTEXT
mov [selection_text],eax
mov eax,[asmedit_font]
mov [editor_font],eax
invoke GetDC,[hwnd]
mov ebx,eax
invoke SelectObject,ebx,[editor_font]
lea edi,[char]
mov byte [edi],20h
lea eax,[size]
invoke GetTextExtentPoint32,ebx,edi,1,eax
mov eax,[size.cy]
mov [font_height],eax
mov eax,[size.cx]
mov [font_width],eax
invoke ReleaseDC,[hwnd],ebx
mov [return_value],0
jmp done
create_failed:
or eax,-1
jmp finish_wndproc
wm_destroy:
invoke VirtualFree,[line_buffer],0,MEM_RELEASE
invoke VirtualFree,[screen_base],0,MEM_RELEASE
call release_search_data
call release_editor_memory
invoke SetWindowLong,[hwnd],0,0
xor eax,eax
jmp finish_wndproc
wm_getdlgcode:
mov eax,DLGC_WANTCHARS+DLGC_WANTARROWS
jmp finish_wndproc
wm_paint:
lea eax,[rect]
invoke GetUpdateRect,[hwnd],eax,FALSE
or eax,eax
jz finish_wndproc
cmp [screen_base],0
je finish_wndproc
lea eax,[ps]
invoke BeginPaint,[hwnd],eax
mov ebx,eax
invoke CreateSolidBrush,[background_color]
mov [background_brush],eax
invoke CreateSolidBrush,[selection_background]
mov [selection_brush],eax
invoke SelectObject,ebx,[editor_font]
mov esi,[screen_base]
add esi,[screen_offset]
mov eax,[screen_width]
mul [screen_height]
lea edi,[esi+eax]
mov [rect.top],0
mov eax,[font_height]
mov [rect.bottom],eax
mov ecx,[screen_height]
paint_screen:
push ecx
mov [rect.left],0
mov ecx,[screen_width]
paint_line:
cmp byte [esi],0
je paint_empty_block
mov edx,1
mov al,[edi]
get_characters_block:
cmp edx,ecx
je get_color
cmp al,[edi+edx]
jne get_color
cmp byte [esi+edx],0
je get_color
inc edx
jmp get_characters_block
paint_empty_block:
mov edx,1
test byte [edi],80h
jnz get_empty_selection
get_empty_block:
cmp edx,ecx
je fill_empty_block
cmp byte [esi+edx],0
jne fill_empty_block
test byte [edi+edx],80h
jnz fill_empty_block
inc edx
jmp get_empty_block
fill_empty_block:
push ecx edx
mov eax,[font_width]
mul edx
add eax,[rect.left]
mov [rect.right],eax
lea eax,[rect]
invoke FillRect,ebx,eax,[background_brush]
jmp paint_next_block
get_empty_selection:
cmp edx,ecx
je fill_empty_selection
cmp byte [esi+edx],0
jne fill_empty_selection
test byte [edi+edx],80h
jz fill_empty_selection
inc edx
jmp get_empty_selection
fill_empty_selection:
push ecx edx
mov eax,[font_width]
mul edx
add eax,[rect.left]
mov [rect.right],eax
lea eax,[rect]
invoke FillRect,ebx,eax,[selection_brush]
jmp paint_next_block
get_color:
push ecx edx
test byte [edi],80h
jnz highlight_color
invoke SetBkColor,ebx,[background_color]
mov al,[edi]
or al,al
jnz syntax_color
default_color:
invoke SetTextColor,ebx,[text_color]
jmp color_ok
syntax_color:
movzx eax,al
mov edx,[syntax_colors]
or edx,edx
jz default_color
mov eax,[edx+(eax-1)*4]
invoke SetTextColor,ebx,eax
jmp color_ok
highlight_color:
invoke SetBkColor,ebx,[selection_background]
invoke SetTextColor,ebx,[selection_text]
color_ok:
mov ecx,[esp]
mov eax,[font_width]
mul ecx
add eax,[rect.left]
mov [rect.right],eax
lea eax,[rect]
invoke DrawText,ebx,esi,ecx,eax,DT_LEFT+DT_NOPREFIX+DT_SINGLELINE
paint_next_block:
pop edx ecx
sub ecx,edx
add esi,edx
add edi,edx
mov eax,[rect.right]
mov [rect.left],eax
or ecx,ecx
jnz paint_line
mov eax,[font_height]
add [rect.top],eax
add [rect.bottom],eax
pop ecx
dec ecx
jnz paint_screen
invoke DeleteObject,[background_brush]
invoke DeleteObject,[selection_brush]
lea eax,[ps]
invoke EndPaint,[hwnd],eax
xor eax,eax
jmp finish_wndproc
wm_setfocus:
or [focus],-1
call create_caret
mov [notification],AEN_SETFOCUS
cmp [was_selection],0
je done
jmp moved_window
wm_killfocus:
mov [focus],0
invoke DestroyCaret
mov [notification],AEN_KILLFOCUS
cmp [was_selection],0
je done
jmp moved_window
wm_hscroll:
mov [sc.cbSize],sizeof.SCROLLINFO
mov [sc.fMask],SIF_ALL
lea eax,[sc]
invoke GetScrollInfo,[hwnd],SB_HORZ,eax
movzx eax,word [wparam]
cmp eax,SB_LINEUP
je hscroll_left
cmp eax,SB_LINEDOWN
je hscroll_right
cmp eax,SB_THUMBTRACK
je hscroll_pos
cmp eax,SB_PAGEUP
je hscroll_wleft
cmp eax,SB_PAGEDOWN
je hscroll_wright
hscroll_ignore:
jmp done
hscroll_left:
cmp [window_position],0
je hscroll_ignore
dec [window_position]
jmp moved_window
hscroll_right:
mov eax,[maximum_position]
sub eax,[sc.nPage]
cmp [window_position],eax
jge hscroll_ignore
inc [window_position]
jmp moved_window
hscroll_pos:
mov eax,[sc.nTrackPos]
mov [window_position],eax
jmp moved_window
hscroll_wleft:
mov eax,[sc.nPage]
sub [window_position],eax
jnc moved_window
mov [window_position],0
jmp moved_window
hscroll_wright:
mov eax,[sc.nPage]
mov ecx,[maximum_position]
sub ecx,eax
add [window_position],eax
cmp [window_position],ecx
jbe moved_window
mov [window_position],ecx
jmp moved_window
wm_vscroll:
mov [sc.cbSize],sizeof.SCROLLINFO
mov [sc.fMask],SIF_ALL
lea eax,[sc]
invoke GetScrollInfo,[hwnd],SB_VERT,eax
movzx eax,word [wparam]
cmp eax,SB_LINEUP
je vscroll_up
cmp eax,SB_LINEDOWN
je vscroll_down
cmp eax,SB_THUMBTRACK
je vscroll_pos
cmp eax,SB_PAGEUP
je vscroll_pageup
cmp eax,SB_PAGEDOWN
je vscroll_pagedown
vscroll_ignore:
jmp done
vscroll_up:
mov esi,[window_line]
mov esi,[esi+4]
or esi,esi
jz vscroll_ignore
dec [window_line_number]
mov [window_line],esi
jmp moved_window
vscroll_down:
mov eax,[sc.nPos]
add eax,[sc.nPage]
cmp eax,[sc.nMax]
ja vscroll_ignore
mov esi,[window_line]
vscroll_skip_line:
mov esi,[esi]
btr esi,0
jc vscroll_skip_line
or esi,esi
jz vscroll_ignore
inc [window_line_number]
mov [window_line],esi
jmp moved_window
vscroll_pos:
mov eax,[sc.nTrackPos]
call find_line
or esi,esi
jz vscroll_ignore
mov [window_line],esi
mov [window_line_number],ecx
jmp moved_window
vscroll_pageup:
mov esi,[window_line]
mov ecx,[sc.nPage]
scroll_up:
mov eax,[esi+4]
or eax,eax
jz scroll_ok
dec [window_line_number]
mov esi,eax
loop scroll_up
jmp scroll_ok
vscroll_pagedown:
mov esi,[window_line]
mov eax,[sc.nPos]
add eax,[sc.nPage]
mov ecx,[sc.nMax]
sub ecx,eax
inc ecx
cmp ecx,[sc.nPage]
jbe scroll_down
mov ecx,[sc.nPage]
scroll_down:
mov eax,[esi]
btr eax,0
jnc scroll_next_line
mov esi,eax
jmp scroll_down
scroll_next_line:
or eax,eax
jz scroll_ok
inc [window_line_number]
mov esi,eax
loop scroll_down
scroll_ok:
mov [window_line],esi
jmp moved_window
wm_mousewheel:
mov esi,[window_line]
mov eax,[wparam]
sar eax,16
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -