NB. WM_APP+ message handler.

NB. This defines the <wdmsg_handler> in the base locale.  Locales can register
NB. their window messages with it and receive <msg_handler> callbacks when
NB. those messages are received.



NB. wdmsgregister - register a message number for a locale
NB.   [x] - locale name
NB.    y  - windows message number
wdmsgregister_z_=: verb define
(>coname '') wdmsgregister y.
:
'message registered to another locale' assert -.1 e. 1 0-:"1 WDMSG_j_="1 r=. y.;x.
empty WDMSG_j_=: ~.WDMSG_j_,r
)


NB. wdmsgunregister - unregister a message number
NB.   [x] - locale name
NB.    y  - windows message number
wdmsgunregister_z_=: verb define
(>coname '') wdmsgregister y.
:
'message not registered to this locale' assert (#WDMSG_j_)~:i=. 1 i.~ WDMSG_j_="1 y.;x.
empty WDMSG_j_=: WDMSG_j_#~i~:i.#WDMSG_j_
)


wdmsgreset_z_=: verb define
WDMSG_j_=: 0 2$a:
)

NB. reset upon first load.
verb define ''
if. _1=nc <'WDMSG_j_' do. wdmsgreset '' end.
)



NB. Call msg_handler in registered locale, if any.  Otherwise ignore message.
wdmsg_handler_base_=: verb define
if. (#WDMSG_j_)~:i=. (>{."1 WDMSG_j_) i. {.y. do.
	('msg_handler_',(>{:i{WDMSG_j_),'_')~ y.
end.
empty ''
)