2.3.1.27 GETN_CUSTOM_BUTTON


Name

GETN_CUSTOM_BUTTON

Declaration

#define	GETN_CUSTOM_BUTTON(_STR)		_tmpNode.SetAttribute(STR_CUSTOM_BUTTONS_ATTRIB, _STR)

Remark

This macro is used to add custom button on GetN Dialog.

Parameters

_STR
[input] button string.
make string like "OK=Import" to rename label of OK button to "Import"
make string like "OK=" to hide OK button
make string like "OK=|Cancel=Close|Apply=Plot|Undo" to hide OK button, rename "Cancel" to "Close", show "Apply" and rename it to "Plot", show "Undo" button
make string like "Import|Update" to add two customize buttom "Import" & "Update", and OK & Cancel button will also shown
make string like "OK=|Cancel=|Import|Update" to add two customize buttom and also hidden OK & Cancel button

Return

Examples

EX1

This example shows how to hide the OK|Cancel buttons
#include <GetNbox.h>
#include <..\OriginLab\DialogEx.h>
void GETN_CUSTOM_BUTTON_ex1()
{
	GETN_TREE(tr)
	GETN_CUSTOM_BUTTON("OK=|Cancel=")
	GETN_STRLIST(WksName, "Worksheet Name", "one", "one|two|three|four|five")	GETN_OPTION_EVENT_EX(_update_name)
	GetNBox(tr, _L("Name"));
}

static bool _update_name(TreeNode& myTree, int nRow, int nCol, TreeNode& trNode, DWORD dwCntrl, int nType, WndContainer& theDlg)
{
	if ( GETNEVENT_ON_INIT != dwCntrl )
	{
		out_str(myTree.WksName.strVal);
		theDlg.SendMessage(WM_CLOSE); // close the dialog
	}	
	return true;
}

EX2

This example shows how to customize the Apply button with UTF-8 encoding Unicode character
and set tooltips to the buttons
#include <GetNbox.h>
void GETN_CUSTOM_BUTTON_ex2()
{	
	GETN_TREE(tr)
	GETN_STR(WksName, "Worksheet Name", "Sheet2") 
	
	//hide OK button, change Apply button to lighting icon, change Cancel to Close
	GETN_CUSTOM_BUTTON("OK=|Apply=\xe2\x9a\xa1|Cancel=Close") //UTF-8: \xe2\x9a\xa1
	
	//set button tool tips, this should follow custom button string
	tr.SetAttribute(STR_CUSTOM_BUTTONS_TOOLTIP_ATTRIB, _L("|Add..."));
	
	GetNBox( tr, NULL, "Add Sheet", NULL, NULL, true, AddSheetDlg_Apply);
}

static bool	AddSheetDlg_Apply(TreeNode& tr)
{
	WorksheetPage wp = Project.Pages();
	if(!wp)
	{
		Worksheet wks;
		wks.Create("origin");
		wks.SetName(tr.WksName.strVal);
	}
	else
	{	
		wp.AddLayer(tr.WksName.strVal);
	}
	
	return false;
}

EX3

this example show how to work on more than one custom buttons
#include <GetNbox.h>
void GETN_CUSTOM_BUTTON_ex3()
{	
	GETN_TREE(tr)
	GETN_STR(WksName, "Worksheet Name", "Sheet2") 
	
	//add 2 custom buttons
	GETN_CUSTOM_BUTTON("Add|Delete")
	
	GetNBox(tr, _GetN_event_func);
}

static int _GetN_event_func(TreeNode& trGetN, int nRow, int nEvent, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& getNContainer, string& strAux, string& strErrMsg)
{
	if(GETNE_ON_CUSTOM_BUTTON1 == nEvent) 
	{
		out_str("Add");
	}
	
	if(GETNE_ON_CUSTOM_BUTTON2 == nEvent) 
	{
		out_str("Delete");
	}
	
	return false;
}

EX4

this example show how to use PEVENT_GETN_RET_FORCE_UPDATE and PEVENT_GETN_RET_TO_CLOSE as the return value in custom buttons' event function
#include <GetNbox.h>
void GETN_CUSTOM_BUTTON_ex4()
{	
	GETN_TREE(tr)
	GETN_STR(WksName, "Worksheet Name", "Sheet2") 
	GETN_NUM(CountNum, "", 0) GETN_SHOW(FALSE)
	
	//add 2 custom buttons
	GETN_CUSTOM_BUTTON("Update|Advanced")
	
	GetNBox(tr, _GetN_event_func);
	out_tree(tr);
}

static int _GetN_event_func(TreeNode& trGetN, int nRow, int nEvent, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& getNContainer, string& strAux, string& strErrMsg)
{
	//button1 "Update" event, to update "Worksheet Name" value
	if(GETNE_ON_CUSTOM_BUTTON1 == nEvent) 
	{
		trGetN.CountNum.nVal += 1;
		trGetN.WksName.strVal = "Update" + trGetN.CountNum.nVal;
		return PEVENT_GETN_RET_FORCE_UPDATE; // force getn dlg update
	}
	
	//button2 "Advanced" event, to close getn dlg and show message box
	if(GETNE_ON_CUSTOM_BUTTON2 == nEvent) 
	{
		string strLT = ";type -b Advanced";
		LT_execute(strLT);
		return PEVENT_GETN_RET_TO_CLOSE; // close getn dlg
	}
	
	return false;
}

EX5

this example show how to disable/enable custom button
#include <GetNbox.h>
#include <xfutils.h> //DECLARE_BUTTON_ENABLES
static int _custom_button_and_apply_getn_event(TreeNode& tr, int nRow, int nEvent, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& getNContainer, string& strAux, string& strErrMsg)
{
	DECLARE_BUTTON_ENABLES
	string strNode = lpcszNodeName;
	if(GETNE_ON_CUSTOM_BUTTON1 == nEvent)
	{
		printf("Set Default button clicked\n");
	}
	if ( GETNE_ON_APPLY == nEvent )
	{
		bOKEnable = false;
		bApplyEnable = false;
	}
	if(strNode == "abc" || GETNE_ON_VALUE_CHANGE == nEvent || GETNE_ON_INIT == nEvent) {
		bBTN1Enable = tr.abc.nVal? false:true; //bBTN1Enable for the first custom button, see DECLARE_BUTTON_ENABLES
		if(strNode == "abc")
			printf("Show Default button:%d \n", bBTN1Enable);
		return true;
	}
	return false;
}
void custom_apply()
{
	GETN_TREE(tr)
    GETN_NUM(factor, "Scale Factor", 12.3)
    GETN_CHECK(abc,"Disable Set Default button", false)
	GETN_CUSTOM_BUTTON(_L("Set as Default..."))
	//last true = bApply Button
	GetNBox(tr, _custom_button_and_apply_getn_event, "Custom and Apply", NULL, NULL, true);
}

EX6

this example show how to show menu when you click the custom button and apply button
#include <GetNBox.h>
#include <control.h>
#include <xfutils.h>
static int _custom_button_and_apply_getn_event(TreeNode& tr, int nRow, int nEvent, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& getNContainer, string& strAux, string& strErrMsg)
{
	DECLARE_BUTTON_ENABLES
	string strNode = lpcszNodeName;
	if(GETNE_ON_CUSTOM_BUTTON1 == nEvent)
	{
		Menu menu;
		menu.Add("Active Graph", 1);
		menu.Add("Active Layer", 2);
		int		nCmd = 0;
		POINT pt;
		GetCursorPos(&pt);
		menu.TrackPopupMenu(0, pt.x, pt.y, GetActiveWindow(), &nCmd);
		switch ( nCmd )
		{
		case 1:
			out_str("Apply to Graph");
			break;
		case 2:
			out_str("Apply to Layer");
			break;
		}	
		return 0;
	}

	if ( GETNE_ON_APPLY == nEvent )
	{
		Menu menu;
		menu.Add("All Graphs in Folder", 1);
		menu.Add("All Graphs in Project", 2);
		int		nCmd = 0;
		POINT pt;
		GetCursorPos(&pt);
		menu.TrackPopupMenu(0, pt.x, pt.y, GetActiveWindow(), &nCmd);
		switch ( nCmd )
		{
		case 1:
			out_str("Apply to All Graphs in Folder");
			break;
		case 2:
			out_str("Apply to All Graphs in Project");
			break;
		}	
		return 0;
	}
	return false;
}
void custom_apply_show_menu()
{
	SYS_VALUE_TEMP_CHANGE(EAB, 1); /// Apply button stay Enable after click
	GETN_TREE(tr)
    GETN_NUM(factor, "Scale Factor", 12.3)
	GETN_CUSTOM_BUTTON(_L("Apply To"))
	//last true = bApply Button
	GetNBox(tr, _custom_button_and_apply_getn_event, "Custom and Apply", NULL, NULL, true);
}

See Also

GETN_OPTION_EVENT_EX

Header to Include

GetNBox.h

Reference