Insert control action procedure template

Perhaps there is already a way to do this, but I haven't found it.

menu "Procedure"
    submenu "Insert control function"
        "Popup;SetVariable;CheckBox;Button;Listbox;TabControl;Slider;CustomControl", /Q, InsertControlActionCode()
    end
end

function /S InsertControlActionCode()
    GetLastUserMenuInfo
    string strSav = GetScrapText()
    string strFunc = ""
    sprintf strFunc, "function %sProc(STRUCT WM%sAction &s) : %sControl\r\t\r\treturn 0\rend", s_value, s_value, s_value
    strFunc = ReplaceString("PopupControl",strFunc, "PopupMenuControl")
    PutScrapText strFunc
    DoIgorMenu "Edit" "Paste"
    PutScrapText strSav
end

 

Nice, Tony.

I think the ": xxxControl" keyword is missing here. How about this:

sprintf strFunc, "function %sProc(STRUCT WM%sAction &s) : %sControl\r\t\r\treturn 0\rend", s_value, s_value, s_value
strFunc = ReplaceString("PopupControl",strFunc, "PopupMenuControl")

Note that the first entry needs "PopupMenu" for the control keyword, hence the replace command.

What really would be awesome and would make this 10x more useful for me would be to add a comment section at the beginning explaining the parameters of the WMxxxAction structure. I constantly have to go to the manual for this to check (I cannot remember the details even after all these years). Do you happen to know how to get the text contents of help files into a string? Then it would be just a matter of filtering out the struct definition at the beginning of each explanation. An alternative approach would be to have a long helper function which would serve and drop in the respective comment. Something like this (I did just the example for the popup menu, since I am lazy today:     (EDIT: adjusted the help text a bit.)

function /S InsertControlActionCode()
    GetLastUserMenuInfo
    string strSav = GetScrapText()
    string strFunc = ""
    sprintf strFunc, "function %sProc(STRUCT WM%sAction &s) : %sControl\r%s\t\r\treturn 0\rend", s_value, s_value, s_value, actionStructHelp(s_value)
    strFunc = ReplaceString("PopupControl",strFunc, "PopupMenuControl")
    PutScrapText strFunc
    DoIgorMenu "Edit" "Paste"
    PutScrapText strSav
end

static function/S actionStructHelp(string which)
    string comment = "\t// WM"+which+"Action struct info:\r"
    StrSwitch (which)
        case "Popup":
            comment += "\t// char ctrlName[MAX_OBJ_NAME+1] - Control name\r"
            comment += "\t// char win[MAX_WIN_PATH+1] - Host window or subwindow name\r"
            comment += "\t// STRUCT Rect winRect - Local coordinates of host window\r"
            comment += "\t// STRUCT Rect ctrlRect - Enclosing rectangle of the control\r"
            comment += "\t// STRUCT Point mouseLoc - Mouse location\r"
            comment += "\t// Int32 eventCode - -3=receive | -2=loose keyboard focus, -1=killed, 2=mouse up, 3=hovering\r"
            comment += "\t// Int32 eventMod - bits: 0=mouse down, 1=shift, 2=option|alt, 3=command|ctrl, 4=contextual click\r"
            comment += "\t// String userData - Primary unnamed user data\r"
            comment += "\t// Int32 blockReentry - set to 1 to block further entries\r"
            comment += "\t// Int32 popNum - Item number currently selected or hovered over (1-based)\r"
            comment += "\t// char popStr[MAXCMDLEN] - Contents of current popup item or item hovered over\r"
        break
    EndSwitch
    return comment
end

If you think this would be useful, then I may complete above function when I have nothing better to do, like on the weekend. ;)

The : xxxControl part is optional, and because I don't usually bother with it I didn't put it in the template. But you're right, I should have included them so that the functions are selectable in the control editing dialogs.

Whenever I write one of these functions I too have to look up the help for the action structure. I have a key mapped to command help - outside of Igor - so that I can place the cursor on the name of the structure and summons the help. Within Igor the keystroke is cmd-option-F1, which I find thoroughly inconvenient.

I should also note that hovering over the structure name will show the structure definition. But the thing I always need is the list of event codes.

Oh, I didn't know that hovering over structures will show their definition, at least for built-in ones (would be cool if this would work for user-defined structures as well). This indeed reduces the problem to mostly eventCodes (and maybe eventMod descriptions). This could be solved by serving comments via above function. I might compile something at post it here later if that is useful.

Yes, the cmd-option-F1 (or here ctrl-alt-F1) keystroke is only something for professional piano players. On top of that I rather read the description within the help browser. I get easily confused with many help windows open.

OK, here is the eventCode / eventMod helper function. Tony, if you find this useful, then would it be a good idea to merge all this into the Text Editing Tools?

static function/S actionStructHelp(string which)
    string comment = "\t// WM"+which+"Action eventCode info:\r"
    if (!StringMatch(which,"CustomControl"))
        comment += "\t// -3\tControl received keyboard focus\r"
        comment += "\t// -2\tControl lost keyboard focus\r"
        comment += "\t// -1\tControl being killed\r"
    endif
   
    StrSwitch (which)
        case "Popup":
            comment += "\t//  2\tMouse up\r"
            comment += "\t//  3\tHovering\r"
        break
        case "SetVariable":
            comment += "\t//  1\tMouse up\r"
            comment += "\t//  2\tEnter key\r"
            comment += "\t//  3\tLive update\r"
            comment += "\t//  4\tMouse scroll wheel up\r"
            comment += "\t//  5\tMouse scroll wheel down\r"
            comment += "\t//  6\tValue changed by dependency update\r"
            comment += "\t//  7\tBegin edit\r"
            comment += "\t//  8\tEnd edit\r"
            comment += "\t//  9\tMouse down\r"
        break
        case "CheckBox":
            comment += "\t//  2\tMouse up, checkbox toggled\r"
        break
        case "Button":
            comment += "\t//  1\tMouse down\r"
            comment += "\t//  2\tMouse up\r"
            comment += "\t//  3\tMouse up outside control\r"
            comment += "\t//  4\tMouse moved\r"
            comment += "\t//  5\tMouse enter\r"
            comment += "\t//  6\tMouse leave\r"
            comment += "\t//  7\tMouse dragged while outside the control\r"
        break
        case "Listbox":
            comment += "\t//  1\tMouse down\r"
            comment += "\t//  2\tMouse up\r"
            comment += "\t//  3\tDouble click\r"
            comment += "\t//  4\tCell selection (mouse or arrow keys)\r"
            comment += "\t//  5\tCell selection plus Shift key\r"
            comment += "\t//  6\tBegin edit\r"
            comment += "\t//  7\tEnd edit\r"
            comment += "\t//  8\tVertical scroll - See Scroll Event Warnings under ListBox\r"
            comment += "\t//  9\tHorizontal scroll by user or by the hScroll=h keyword\r"
            comment += "\t//  10\tTop row set by row=r or first column set by col=c keywords\r"
            comment += "\t//  11\tColumn divider resized\r"
            comment += "\t//  12\tKeystroke, character code is place in row field- See Note on Keystroke Event under ListBox\r"
            comment += "\t//  13\tCheckbox was clicked. This event is sent after selWave is updated.\r"
        break
        case "TabControl":
            comment += "\t//  2\tMouse up\r"
        break
        case "Slider":
            comment += "\t//  1\tValue set\r"
            comment += "\t//  2\tMouse down\r"
            comment += "\t//  4\tMouse up\r"
            comment += "\t//  8\tMouse moved or arrow key moved the slider\r"
            comment += "\t//  16\tRepeat timer fired (see Repeating Sliders)\r"
        break
        case "CustomControl":
            comment += "\t// kCCE_mousedown = 1\tMouse down in control.\r"
            comment += "\t// kCCE_mouseup = 2\tMouse up in control.\r"
            comment += "\t// kCCE_mouseup_out = 3\tMouse up outside control.\r"
            comment += "\t// kCCE_mousemoved = 4\tMouse moved (only when mouse is over control).\r"
            comment += "\t// kCCE_enter = 5\tMouse entered control.\r"
            comment += "\t// kCCE_leave = 6\tMouse left control.\r"
            comment += "\t// kCCE_mouseDraggedOutside = 7\tMouse moved while it was outside the control (mouse pressed inside and dragged outside).\r"
            comment += "\t// kCCE_draw = 10\tTime to draw custom content.\r"
            comment += "\t// kCCE_mode = 11\tSent when executing CustomControl name, mode=m.\r"
            comment += "\t// kCCE_frame = 12\tSent before drawing a subframe of a custom picture.\r"
            comment += "\t// kCCE_dispose = 13\tSent as the control is killed.\r"
            comment += "\t// kCCE_modernize = 14\tSent when dependency (variable or wave set by value=varName) or draw event fires.\r"
            comment += "\t// kCCE_tab = 15\tSent when user tabs into the control. If you want keystrokes (kCCE_char), then set needAction.\r"
            comment += "\t// kCCE_char = 16\tSent on keyboard events (keyboard character => kbChar and modifiers bit field => kbMods). Sets needAction if key event was used and requires a redraw.\r"
            comment += "\t// kCCE_drawOSBM = 17\tCalled after drawing pict from picture parameter into an offscreen bitmap. You can draw custom content here.\r"
            comment += "\t// kCCE_idle = 18\tIdle event typically used to blink insertion points etc. Set needAction to force the control to redraw. Sent only when host window is on top.\r"
        break
    EndSwitch
   
    comment += "\t// eventMod bits: 0 = mouse down, 1 = shift, 2 = option | alt, 3 = command | ctrl, 4 = contextual click\r"
    return comment
end

 

InsertActionProcedure.ipf

Looks good, chozo. I'll wrap this into the Text Edit Tools. I have a few other things I'd like to edit at the same time.

Once cmd-option-fn-F1 (yes, on a macbook pro it takes four keys) has been mapped to a single key, for me it becomes really useful.

Forum

Support

Gallery

Igor Pro 8

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More