Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Developing U++ » UppHub » Simple app-wide "macros"
Simple app-wide "macros" [message #13110] Wed, 12 December 2007 17:35 Go to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
I was asked by application user to provide some means to insert often repeated texts ("e.g. if I press F4, I want xyz to be inserted here).

This simple module allows you do define selection as macro using Ctrl+F1-10 a insert using F1-10, in EditField, DocEdit, LineEdit, RichEdit:

static WString s_macro[10];

bool MacroKeyHook(Ctrl *ctrl, dword key, int count)
{
	if(key >= K_CTRL_F1 && key <= K_CTRL_F10) {
		WString& txt = s_macro[key - K_CTRL_F1];
		int l, h;
		if(EditField *e = dynamic_cast<EditField *>(ctrl))
			if(e->GetSelection(l, h)) {
				txt = e->GetText().Mid(l, h - l);
				return true;
			}
		if(TextCtrl *e = dynamic_cast<TextCtrl *>(ctrl))
			if(e->GetSelection(l, h)) {
				txt = e->GetW(l, h - l);
				return true;
			}
		if(RichEdit *e = dynamic_cast<RichEdit *>(ctrl)) {
			txt = e->GetSelection().GetPlainText();
			return true;
		}
	}
	if(key >= K_F1 && key <= K_F10) {
		WString txt = s_macro[key - K_F1];
		if(EditField *e = dynamic_cast<EditField *>(ctrl)) {
			e->Insert(txt);
			return true;
		}
		if(TextCtrl *e = dynamic_cast<TextCtrl *>(ctrl)) {
			e->Paste(txt);
			return true;
		}
		if(RichEdit *e = dynamic_cast<RichEdit *>(ctrl)) {
			e->PasteText(AsRichText(txt, e->GetFormatInfo()));
			return true;
		}
	}
	return false;
}

void SerializeTextMacros(Stream& s)
{
	int version = 0;
	s / version;
	for(int i = 0; i < 10; i++)
		s % s_macro[i];
}

INITBLOCK {
	Ctrl::InstallKeyHook(MacroKeyHook);
}
Re: Simple app-wide "macros" [message #30214 is a reply to message #13110] Thu, 16 December 2010 00:07 Go to previous message
alendar is currently offline  alendar
Messages: 47
Registered: January 2010
Location: Idaho, USA
Member
Thanks, Mirek!

The snippet below was really helpful.
PasteText(AsRichText(txt, GetFormatInfo()));


I'll also try adding the entire logic to use for capturing text macros.


cd7651feeb698f6ac6cec1f6deda5e5b
Previous Topic: Leptonica library support
Next Topic: More new functions
Goto Forum:
  


Current Time: Fri Mar 29 02:32:51 CET 2024

Total time taken to generate the page: 0.01453 seconds