Home » Developing U++ » UppHub » Simple app-wide "macros"
Simple app-wide "macros" [message #13110] |
Wed, 12 December 2007 17:35  |
 |
mirek
Messages: 14257 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);
}
|
|
|
Goto Forum:
Current Time: Thu May 08 07:55:17 CEST 2025
Total time taken to generate the page: 0.02909 seconds
|