Function CW_Input_Get, id ; This is the function that GETS a value out of the compound widget. ; The parameter, ID, is the top-level base of the compound widget. In ; the widget definition module it is identifed as "cw_tlb". We have ; decided that to "get" a value in this compound widget is to return ; a two-element array: the first element is the text currently in the ; LABEL; the second element is the text currently in the TEXT WIDGET. ; Find the widget identifier of the first child of ID. child = Widget_Info(id, /Child) ; Get the state information out of the first child where it is stored. Widget_Control, child, Get_UValue=state, /No_Copy ; Get the LABEL and TEXT WIDGET current values Widget_Control, state.labelID, Get_Value=label_text Widget_Control, state.textID, Get_Value=field_text ; Stuff the state structure back into the first child Widget_Control, child, Set_UValue=state, /No_Copy ; Return the "value" of the compound widget RETURN, [label_text, field_text(0)] END ; ******************************************************************** Pro CW_Input_Set, id, value ; This is the procedure that SETS a value in the compound widget. ; The parameter, ID, is the top-level base of the compound widget. In ; the widget definition module it is identifed as "cw_tlb". We have ; decided that to "set" a value in this compound widget is to receive ; a two-element array: the first element is the text to be put into the ; LABEL; the second element is the text to be put into the TEXT WIDGET. ; Find the widget identifier of the first child of ID. child = Widget_Info(id, /Child) ; Get the state information out of the first child where it is stored. Widget_Control, child, Get_UValue=state, /No_Copy ; Set the LABEL and TEXT WIDGET values from the values passed in. Widget_Control, state.labelID, Set_Value=value(0) Widget_Control, state.textID, Set_Value=value(1) ; Stuff the state structure back into the first child Widget_Control, child, Set_UValue=state, /No_Copy END ; ******************************************************************** Pro CW_Input_Event, event ; This is the event handler for the top-level base of the compound ; widget. This is NOT, however, the top-level base of the program. ; Thus, event.top does not point to this base, but to the base at ; the top of the widget hierarchy to which this base may be a distant ; relative. We know where we are however, because we know that THIS ; base is associated with the event handler for all events occuring ; in the compound widget. Thus, THIS base is identified in this ; module as event.handler. ; Get the state information out of the first child of THIS base. child = Widget_Info(event.handler, /Child) Widget_Control, child, Get_UValue=state, /No_Copy ; Only one thing can generate an event in this comound widget: ; a Carriage Return from the TEXT WIDGET. If we get an event, ; simply print out whatever is in the TEXT WIDGET right now. Widget_Control, state.textID, Get_Value=currentText Print, currentText(0) ; Stuff the state information back into the first child. Widget_Control, child, Set_UValue=state, /No_Copy END ; ******************************************************************** Function CW_Input, parent, UValue=uval, Title=labelText, Value=valueText ; All compound widgets are FUNCTIONS that have one positional parameter, ; the parent widget of its top-level base. By convention, all compound ; widgets also are defined with a UValue keyword for the convenience of ; the user of this compound widget. ; Do some error checking and define defaults for keywords not used IF N_Params() NE 1 THEN Message,'Must have one parameter' IF N_Elements(uval) EQ 0 THEN uval = 0 IF N_Elements(labelText) EQ 0 THEN labelText = 'Label:' IF N_Elements(valueText) EQ 0 THEN valueText = 'text' ; Create the top-level base of this compound widget. Note that this ; base is not really a top-level base, since it is a child of some ; other widget. Identify the IDL modules that will be used as the ; event handler, the procedure that sets values, and the function ; that gets values from this base. Notice that the UValue of this ; base is going to be used to store the User Value passed into the ; program. This means we will have to find somewhere else to store ; our state information. cw_tlb = Widget_Base( parent, $ Row=1, $ Event_Pro='CW_Input_Event', $ Pro_Set_Value='CW_Input_Set', $ Func_Get_Value='CW_Input_Get', $ UValue=uval) ; In this program the first child of the top-level base of the ; compound widget is going to be the LABEL. The second child will ; be the TEXT WIDGET. labelID = Widget_Label(cw_tlb, Value=labelText) textLen = StrLen(valueText) textID = Widget_Text(cw_tlb, /Editable, /No_Newline, $ XSize=(1.5*textLen > 40), Value=valueText) ; Create a state structure with the information we need in the event ; handler and in the other modules that GET and SET values. Here we ; need the widget identifies of the LABEL and the TEXT WIDGET so we ; can GET and SET their values. state = {labelID:labelID, textID:textID} ; Notice we don't realize the compound widget, nor do we call ; XManager. The program that is using this compound widget will ; do all of that for us. ; Store the state structure in the first child of the top-level ; base of this compound widget. Widget_Control, labelID, Set_UValue=state, /No_Copy ; Return the widget ID of the top-level base of this compound widget RETURN, cw_tlb END ; ********************************************************************