Skip to content

Commit e717feb

Browse files
committed
Add examples
1 parent 8e7a348 commit e717feb

File tree

2 files changed

+258
-0
lines changed

2 files changed

+258
-0
lines changed

User Interface/GetNBoxExamples.cpp

+135
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
/*------------------------------------------------------------------------------*
2+
* File Name: *
3+
* Creation: *
4+
* Purpose: OriginC Source C file *
5+
* Copyright (c) ABCD Corp. 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 *
6+
* All Rights Reserved *
7+
* *
8+
* Modification Log: *
9+
*------------------------------------------------------------------------------*/
10+
11+
////////////////////////////////////////////////////////////////////////////////////
12+
// Including the system header file Origin.h should be sufficient for most Origin
13+
// applications and is recommended. Origin.h includes many of the most common system
14+
// header files and is automatically pre-compiled when Origin runs the first time.
15+
// Programs including Origin.h subsequently compile much more quickly as long as
16+
// the size and number of other included header files is minimized. All NAG header
17+
// files are now included in Origin.h and no longer need be separately included.
18+
//
19+
// Right-click on the line below and select 'Open "Origin.h"' to open the Origin.h
20+
// system header file.
21+
#include <Origin.h>
22+
////////////////////////////////////////////////////////////////////////////////////
23+
24+
//#pragma labtalk(0) // to disable OC functions for LT calling.
25+
26+
////////////////////////////////////////////////////////////////////////////////////
27+
#include <GetNbox.h>
28+
29+
////////////////////////////////////////////////////////////////////////////////////
30+
31+
//#pragma labtalk(0) // to disable OC functions for LT calling.
32+
33+
34+
////////////////////////////////////////////////////////////////////////////////////
35+
//This example is about GetNBox and PEVENT_GETN
36+
////////////////////////////////////////////////////////////////////////////////////
37+
#include <Control.h>
38+
void GetNBox_ex()
39+
{
40+
GETN_TREE(tr)
41+
GETN_COMBO_BUTTON(test, ">", "List", "User", "AAA|BBB", "")
42+
GETN_CHECK(check, "Yes or No", 0)
43+
44+
if( GetNBox(tr, _event_func_ex, "Test Event Function", "Test...") )
45+
{
46+
out_str("Done"); // if OK button clicked
47+
}
48+
}
49+
static int _event_func_ex(TreeNode& tr, int nRow, int nEvent, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& getNContainer, string& strAux, string& strErrMsg)
50+
{
51+
//1. show how to use tr, nRow and nEvent
52+
if(GETNE_ON_VALUE_CHANGE == nEvent)
53+
{
54+
//get the value-changed node
55+
TreeNode trEdited = tree_get_node(tr, nRow);
56+
if( trEdited )
57+
printf("changed node: %s\n", trEdited.tagName);
58+
}
59+
60+
61+
//show how to use nEvent, lpcszNodeName, and getNContainer
62+
if(ONODETYPE_BROWSECOMBO == nEvent && lstrcmpi(lpcszNodeName,"test") == 0)
63+
{
64+
//click the ">" button to show menu
65+
Menu myMenu;
66+
myMenu.Add("Item1", 1, MF_STRING);
67+
myMenu.Add("Item2", 2, MF_STRING);
68+
69+
int nSelCmd;
70+
POINT pt;
71+
GetCursorPos(&pt);
72+
myMenu.TrackPopupMenu(0, pt.x, pt.y, getNContainer.GetSafeHwnd(), &nSelCmd);
73+
if(nSelCmd > 0)
74+
{
75+
string strName;
76+
myMenu.GetMenuString(nSelCmd, strName, MF_STRING);
77+
tr.test.strVal = strName;
78+
}
79+
}
80+
81+
82+
//shows how to use strErrMsg and disable OK button
83+
if( tr.check )
84+
{
85+
// disable OK button if "Yes or No" checkbox is unchecked.
86+
bool bEnable = ( 1 == tr.check.nVal );
87+
O_SET_BIT(dwEnables, GETNGEVT_OK_ENABLE, bEnable);
88+
if( !bEnable )
89+
strErrMsg = "Error! Yes or No checkbox is unchecked";
90+
}
91+
return true;
92+
}
93+
94+
95+
////////////////////////////////////////////////////////////////////////////////////
96+
//This example shows the difference in
97+
//GETN_STR_GROUP, GETN_MULTISEL_STR_LISTBOX and GETN_MULTISEL_LISTBOX
98+
////////////////////////////////////////////////////////////////////////////////////
99+
static int Dialog1Node_event(TreeNode& tr, int nRow, int nEvent, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& getNContainer, string& strAux, string& strErrMsg)
100+
{
101+
string strNode = lpcszNodeName;
102+
103+
if(strNode == "list") {
104+
vector<int> vnSel;
105+
vnSel = tr.list.nVals;
106+
for(int ii = 0; ii < vnSel.GetSize(); ii++) {
107+
printf("%d: %d\n", ii+1, vnSel[ii]);
108+
}
109+
}
110+
111+
return true;
112+
}
113+
114+
void GetNMultiBox_ex()
115+
{
116+
vector<string> vsFruits = {"Apple", "Orange", "Banana", "Berries", "Grapes"};
117+
string strCombo;
118+
strCombo.SetTokens(vsFruits, '|');
119+
120+
GETN_TREE(tr)
121+
GETN_STR_GROUP(stats, "Please pick a few US Stats", "MA", "|MA|CA|RI|VT|NY")
122+
GETN_MULTISEL_STR_LISTBOX(StateList, _L("Positive State Value"), "", "a|b|c")
123+
GETN_MULTISEL_LISTBOX(list, "Select", 0, strCombo)
124+
125+
if(GetNBox(tr, Dialog1Node_event , "Dialog title"))
126+
{
127+
out_tree( tr );
128+
129+
vector<int> vnSel;vnSel = tr.list.nVals;
130+
for(int ii = 0; ii < vnSel.GetSize(); ii++) {
131+
string strName = vsFruits[vnSel[ii]];
132+
printf("%d: %s\n", ii+1, strName);
133+
}
134+
}
135+
}

Worksheet/WorksheetExamples.cpp

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/*------------------------------------------------------------------------------*
2+
* File Name: *
3+
* Creation: *
4+
* Purpose: OriginC Source C file *
5+
* Copyright (c) ABCD Corp. 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 *
6+
* All Rights Reserved *
7+
* *
8+
* Modification Log: *
9+
*------------------------------------------------------------------------------*/
10+
11+
////////////////////////////////////////////////////////////////////////////////////
12+
// Including the system header file Origin.h should be sufficient for most Origin
13+
// applications and is recommended. Origin.h includes many of the most common system
14+
// header files and is automatically pre-compiled when Origin runs the first time.
15+
// Programs including Origin.h subsequently compile much more quickly as long as
16+
// the size and number of other included header files is minimized. All NAG header
17+
// files are now included in Origin.h and no longer need be separately included.
18+
//
19+
// Right-click on the line below and select 'Open "Origin.h"' to open the Origin.h
20+
// system header file.
21+
#include <Origin.h>
22+
////////////////////////////////////////////////////////////////////////////////////
23+
24+
//#pragma labtalk(0) // to disable OC functions for LT calling.
25+
26+
////////////////////////////////////////////////////////////////////////////////////
27+
// Include your own header files here.
28+
29+
30+
////////////////////////////////////////////////////////////////////////////////////
31+
// Start your functions here.
32+
33+
34+
////////////////////////////////////////////////////////////////////////////////////
35+
//This example shows how to extract data with LT condition expression
36+
////////////////////////////////////////////////////////////////////////////////////
37+
enum
38+
{
39+
EXTRACT_TO_NEW_WKS = 1,
40+
EXTRACT_WITH_HIGH_LIGHT,
41+
EXTRACT_WITH_NEW_TAG_COL
42+
};
43+
44+
void Worksheet_Extract_Example(int nOption = EXTRACT_TO_NEW_WKS)
45+
{
46+
Worksheet wks = Project.ActiveLayer();
47+
if( !wks )
48+
return;
49+
50+
// prepare test condition string
51+
string strCondition = "abs(a) >= 1 && abs(b) >= 1"; //Note: here used "&&" not "AND". And || for "OR".
52+
string strLTRunBeforeloop = "range a=1; range b=2"; // define range objects, a is column 1 and b is column 2.
53+
54+
// check worksheet with strCondition and result the number of rows base on the condition expression.
55+
// vnRowIndices included the row index as result.
56+
vector<uint> vnRowIndices;
57+
int nn = wks.SelectRows(strCondition, vnRowIndices, 0, -1, -1, strLTRunBeforeloop);
58+
59+
if(nn < 0)
60+
{
61+
out_str("User cancel");
62+
return;
63+
}
64+
65+
if(nn == 0)
66+
{
67+
out_str("No matching row");
68+
return;
69+
}
70+
71+
printf("%d rows selected with condition -- %s\n", nn, strCondition);
72+
73+
switch(nOption)
74+
{
75+
case EXTRACT_TO_NEW_WKS:
76+
Worksheet wksResult;
77+
wksResult.Create();
78+
79+
// Extract data to new worksheet with column indices "vsCols" and row indices "vnRowIndices"
80+
vector<uint> vnCols = {0, 1}; // only extract the first two columns to new worksheet
81+
BOOL bRet = wks.Extract(wksResult, vnRowIndices, vnCols);
82+
if(bRet)
83+
printf("Extract selected rows to [%s]!%s.\n", wksResult.GetPage().GetName(), wksResult.GetName());
84+
break;
85+
86+
case EXTRACT_WITH_HIGH_LIGHT:
87+
// hight light rows by vnRowIndices
88+
vector<int> vnRows;
89+
vnRows = vnRowIndices; // convert vector<uint> to vector<int>
90+
wks.SetSelectedRange(vnRows);
91+
break;
92+
93+
case EXTRACT_WITH_NEW_TAG_COL:
94+
// add a new column with 0/1 to mark if not fit or fit condiftion
95+
Dataset ds(wks, wks.AddCol());
96+
ds.SetSize(wks.GetNumRows());
97+
ds = 0;
98+
ds.Replace(vnRowIndices, 1);
99+
break;
100+
101+
default:
102+
break;
103+
}
104+
}
105+
106+
void Before_Running()
107+
{
108+
// prepare worksheet with data to do extract
109+
Worksheet wks;
110+
wks.Create();
111+
wks.SetSize(30, 3); // set worksheet with 3o rows and 3 columns
112+
113+
// set random data for the first TWO columns
114+
for(int nCol = 0; nCol < wks.GetNumCols()-1; nCol++)
115+
{
116+
Dataset ds(wks, nCol);
117+
ds.Normal(wks.GetNumRows());
118+
}
119+
120+
// fill row numbers to Column C
121+
Dataset dsC(wks, 2);
122+
dsC.Data(1, wks.GetNumRows(), 1);
123+
}

0 commit comments

Comments
 (0)