Click here to Skip to main content
11,572,389 members (48,553 online)
Click here to Skip to main content
Add your own
alternative version

Brainchild, A syntax coloring edit control

, 16 Jun 2005 CPOL 514.6K 23.1K 257
Syntax coloring, multi-level undo/redo editor control.
bcc_cpl.zip
BCC
ABOUT.ICO
bcc.def
BCC.dsp
BCC.DSW
CLIST.BMP
datetime.ico
EMAIL.ICO
FILES.ICO
GENERAL.ICO
INDENTIO.ICO
keyboard.ico
KEYWORDS.BMP
main.bmp
MAIN.ICO
PRINTER.ICO
Release
Brainchild.lib
SYNTAX.ICO
toolbar.bmp
TREE.BMP
WWW.ICO
bcdemo.zip
BCDemo
bcdemo.exe.manifest
bcdemo.ico
BITMAP1.BMP
CLOCK.ICO
PIN.BMP
Release
Brainchild.lib
toolbar.bmp
brainchild_bin.zip
BCC.cpl
BCDemo.exe
Brainchild.ocx
Brainchild.dll
brainchild_dll.zip
HTMLHelp
Programmer
pattern.bmp
drag_sel.cur
cursor1.cur
cur00001.cur
brainchild.def
Defaults
C#.bcp
c++.bcp
DEF.BCP
DEFAULT.BCP
HTML.BCP
INI.BCP
innosetup.bcp
JAVA.BCP
JSCRIPT.BCP
PARSER.BCP
RESOURCE.BCP
T-SQL.bcp
VBSCRIPT.BCP
brainchild_help.zip
Brainchild.chm
brainchild_ocx.zip
Brainchild
Brainchild.def
Brainchild.dll
BrainchildCtrl.bmp
Release
Brainchild.dll
Brainchild.lib
brainchild_wtl.zip
Destination
BCC.cpl
Brainchild.dll
BrainChildEdit.exe
res
BrainChildEdit.exe.manifest
BrainChildEdit.ico
c++.bcp
JSCRIPT.BCP
toolbar.bmp
VBSCRIPT.BCP
Brainchild.lib
BrainChildEdit.dsp
BrainChildEdit.dsw
#pragma once

//
//	brainchildctrl.h
//
//	(C) Copyright 2004 by Jan van den Baard.
//	    All Rights Reserved.
//
// Declaration of the CBrainchildCtrl ActiveX Control class.

#include "brainchilddispatch.h"

// CBrainchildCtrl : See BrainchildCtrl.cpp for implementation.
class CBrainchildCtrl : public COleControl
{
	DECLARE_DYNCREATE(CBrainchildCtrl)

// Constructor
public:
	CBrainchildCtrl();

// Overrides
public:
	virtual void OnDraw( CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid );
	virtual void DoPropExchange( CPropExchange* pPX );
	virtual void OnResetState();

// Implementation
protected:
	~CBrainchildCtrl();

	DECLARE_OLECREATE_EX( CBrainchildCtrl )		// Class factory and guid
	DECLARE_OLETYPELIB(   CBrainchildCtrl )		// GetTypeInfo
	DECLARE_PROPPAGEIDS(  CBrainchildCtrl )		// Property page IDs
	DECLARE_OLECTLTYPE(   CBrainchildCtrl )		// Type name and misc status

// Message maps
	DECLARE_MESSAGE_MAP()

// Dispatch maps
	DECLARE_DISPATCH_MAP()

// Event maps
	DECLARE_EVENT_MAP()

// Dispatch and event IDs
public:
	enum {
		eventidOnFilenameChanged	= 3L,		
		eventidOnStatusUpdate		= 2L,		
		eventidOnCaretPosition		= 1L,		
		
		// Properties.
		dispidFireStockEvents		= 41L,		
		dispidAnyText			= 40L,		
		dispidNumberOfLines		= 39L,		
		dispidReadonly			= 38L,		
		dispidOverwriteMode		= 37L,		
		dispidModified			= 36L,		
		dispidCanDelete			= 35L,		
		dispidCanPaste			= 34L,		
		dispidCanCopy			= 33L,		
		dispidCanCut			= 32L,		
		dispidUnicodeFlag		= 31L,		
		dispidCanRedo			= 30L,		
		dispidCanUndo			= 29L,		
		dispidBorder			= 28L,		

		// Methods.
		dispidPageSetupDialog		= 46L,
		dispidInsertText		= 45L,
		dispidGetSelectionPoints	= 44L,
		dispidSetSelectionPoints	= 43L,		
		dispidGoto			= 42L,
		dispidSettingsDialog		= 27L,		
		dispidPropertiesDialog		= 26L,		
		dispidReplaceDialog		= 25L,		
		dispidFindDialog		= 24L,		
		dispidGotoDialog		= 23L,			
		dispidReplaceSelection		= 22L,		
		dispidLoadParser		= 21L,		
		dispidInsertLine		= 20L,		
		dispidGetColor			= 19L,		
		dispidSetColor			= 18L,		
		dispidSyntaxColoring		= 17L,		
		dispidSetText			= 16L,		
		dispidCheckModified		= 15L,		
		dispidGetSelectionLength	= 14L,		
		dispidGetSelection		= 13L,		
		dispidGetLineLength		= 12L,		
		dispidGetLine			= 11L,		
		dispidGetWordLength		= 10L,		
		dispidGetWord			= 9L,		
		dispidGetTextLength		= 8L,		
		dispidGetText			= 7L,		
		dispidExecuteCommand		= 6L,		
		dispidGotoLine			= 5L,		
		dispidSetLogFont		= 4L,		
		dispidSaveFile			= 3L,		
		dispidLoadFile			= 2L,		
		dispidSetFileName		= 1L
	};
protected:
	HWND m_hBrainchildCtrl;
	CBrainchildDispatch m_BrainchildMsg;

public:
	afx_msg int OnCreate( LPCREATESTRUCT lpCreateStruct );
	afx_msg void OnSize( UINT nType, int cx, int cy );
	afx_msg UINT OnGetDlgCode();
	afx_msg void OnSetFocus( CWnd* pOldWnd );
	afx_msg void OnDestroy();
	virtual BOOL PreTranslateMessage( MSG* pMsg );

protected:
	// Methods.
	LONG LoadFile( VARIANT_BOOL bForce, LPCTSTR pszFilename );
	LONG SaveFile( LPCTSTR pszFilename );
	VARIANT_BOOL SetFont( LPCTSTR pszName, LONG nSize, VARIANT_BOOL bBold, VARIANT_BOOL bItalic, VARIANT_BOOL bUnderline );
	VARIANT_BOOL GotoLine( LONG nLine );
	VARIANT_BOOL SetFileName( LPCTSTR pszFilename );
	void ExecuteCommand( LONG nCommand );
	BSTR GetText( void );
	LONG GetTextLength( void );
	BSTR GetWord( void );
	LONG GetWordLength( void );
	BSTR GetLine( LONG nLine );
	LONG GetLineLength( LONG nLine );
	BSTR GetSelection( void );
	LONG GetSelectionLength( void );
	VARIANT_BOOL CheckModified( void );
	VARIANT_BOOL SetText( VARIANT_BOOL bForce, LPCTSTR pszText );
	void SyntaxColoring( VARIANT_BOOL bOn, VARIANT_BOOL bGlobal );
	OLE_COLOR SetColor( LONG nColorIndex, OLE_COLOR crColor );
	OLE_COLOR GetColor( LONG nColorIndex );
	VARIANT_BOOL InsertLine( LONG nIndex, LPCTSTR pszText );
	VARIANT_BOOL LoadParser( LPCTSTR pszFilename );
	VARIANT_BOOL ReplaceSelection( LPCTSTR pszText );
	void GotoDialog( void );
	void FindDialog( void );
	void ReplaceDialog( void );
	void PropertiesDialog( void );
	void SettingsDialog( void );
	void PageSetupDialog( void );
	VARIANT_BOOL Goto(LONG nLine, LONG nColumn);
	VARIANT_BOOL SetSelectionPoints(LONG xStart, LONG yStart, LONG xEnd, LONG yEnd);
	VARIANT_BOOL GetSelectionPoints(LONG* xStart, LONG* yStart, LONG* xEnd, LONG* yEnd);
	VARIANT_BOOL InsertText(LPCTSTR pszText);
	virtual BOOL OnNotify( WPARAM wParam, LPARAM lParam, LRESULT* pResult );

	// Events.
	void OnCaretPosition( LONG xPos, LONG yPos )
	{
		FireEvent( eventidOnCaretPosition, EVENT_PARAM( VTS_I4 VTS_I4 ), xPos, yPos );
	}

	void OnStatusUpdate( LONG AnyText, LONG CanUndo, LONG CanRedo, LONG CanCut, LONG CanCopy, LONG CanPaste, LONG CanDelete, LONG Modified, LONG Overwrite, LONG Readonly, LONG Bookmarks, LONG FileMode )
	{
		FireEvent( eventidOnStatusUpdate, EVENT_PARAM( VTS_I4 VTS_I4 VTS_I4 VTS_I4 VTS_I4 VTS_I4 VTS_I4 VTS_I4 VTS_I4 VTS_I4 VTS_I4 VTS_I4 ), AnyText, CanUndo, CanRedo, CanCut, CanCopy, CanPaste, CanDelete, Modified, Overwrite, Readonly, Bookmarks, FileMode );
	}

	void OnFilenameChanged( LPCTSTR pszFilename, LPCTSTR pszFileTypeDesc, LONG *hFileTypeIconSmall, LONG *hFileTypeIconLarge )
	{
		FireEvent( eventidOnFilenameChanged, EVENT_PARAM( VTS_BSTR VTS_BSTR VTS_I4 VTS_I4 ), pszFilename, pszFileTypeDesc, ( LONG * )hFileTypeIconSmall, ( LONG * )hFileTypeIconLarge );
	}

	// Properties.
	VARIANT_BOOL GetBorder( void );
	void SetBorder( VARIANT_BOOL newVal );
	VARIANT_BOOL GetCanUndo( void );
	VARIANT_BOOL GetCanRedo( void );
	VARIANT_BOOL GetUnicodeFlag( void );
	void SetUnicodeFlag( VARIANT_BOOL newVal );
	VARIANT_BOOL GetCanCut( void );
	VARIANT_BOOL GetCanCopy( void );
	VARIANT_BOOL GetCanPaste( void );
	VARIANT_BOOL GetCanDelete( void );
	VARIANT_BOOL GetModified( void );
	VARIANT_BOOL GetOverwriteMode( void );
	VARIANT_BOOL GetReadonly( void );
	void SetReadonly( VARIANT_BOOL newVal );
	LONG GetNumberOfLines( void );
	VARIANT_BOOL GetAnyText( void );
	VARIANT_BOOL GetFireStockEvents( void );
	void SetFireStockEvents( VARIANT_BOOL newVal );

	// Another hack to work around Microsoft "by design" features.
	// See http://support.microsoft.com/?scid=kb;EN-US;Q187988
	static LRESULT CALLBACK GetMsgHook(int nCode, WPARAM wParam, LPARAM lParam);
	static HHOOK m_hMsgHook;
};

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Jan van den Baard
Software Developer (Senior)
Netherlands Netherlands
I have been programming for a hobby since 1985. I have started programming on the C= 64. After that I migrated to the C= Amiga which I traded in for a PC back in 1997 I believe. Back in 2000 I decided to lose a hobby and start developing software for a living.

Currently I am working mainly in developing software for building security and access control systems.

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150624.2 | Last Updated 17 Jun 2005
Article Copyright 2002 by Jan van den Baard
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid