📄 page.h
字号:
/*------------------------------------------------------------------------------*
* File Name: Page.h *
* Creation: TD 10/01/2001 *
* Purpose: Origin C header for Page class and other related functions *
* Copyright (c) OriginLab Corp.2001 *
* All Rights Reserved *
* *
* Modification Log: *
*------------------------------------------------------------------------------*/
#ifndef _PAGE_H
#define _PAGE_H
#include <OC_const.h> // consts used in Origin internal functions
#include <Collection.h>
#include <OrgObj.h>
/** >Internal Origin Objects
The PageBase class provides methods and properties common to all internal Origin
pages (windows). One use of this class is to write functions that accept a PageBase
object rather than a page object of specific type. Another use is to attach a PageBase
object to an active page whose page type is unknown. These uses facilitate writing
general code that can then branch to handle specific page types. The PageBase object
can be cast to an object of its page type in order to access methods and properties
specific to its class. In general, however, the Origin C PageBase class is intended
to be an abstract base class to be used for polymorphic handling of derived page types.
Derived classes, such as Note, GraphPage, WorksheetPage, LayoutPage, and MatrixPage
inherit PageBase class methods and should be used instead.
Example:
// Get active window...if not valid...
PageBase pbActiveWindow;
string strWindowName;
int iPageType;
pbActiveWindow = Project.Pages();
if( !pbActiveWindow.IsValid() )
return 1; // Return an error code
// Get window name and type
strWindowName = pbActiveWindow.GetName();
iPageType = pbActiveWindow.GetType();
// If window is not a worksheet or workbook...
if( iPageType != EXIST_WKS && iPageType != EXIST_EXTERN_WKS )
return 1; // Return an error code
*/
class PageBase : public OriginObject
{
public:
/**
Default constructor for a PageBase object.
Examples:
PageBase pbTemp;
pbTemp = Project.Pages(); // Get the project's active page
if( pbTemp.IsValid() )
printf("Active page is of type %d\n", pbTemp.GetType());
else
printf("Active page is invalid\n");
*/
PageBase(); // Default constructor.
/**
Construct a PageBase object using the name of an existing page.
Parameters:
lpcszName = The name of an existing page.
Example:
void output_page_type(string strName)
{
PageBase pb(strName);
if( pb.IsValid() )
printf("Page %s is of type %d\n", strName, pb.GetType());
else
printf("Page %s is invalid\n", strName);
}
void test_output_page_type()
{
MatrixPage mp;
mp.Create("origin.otm");
if( mp.IsValid() )
output_page_type(mp.GetName());
}
*/
PageBase(LPCSTR lpcszName);
/**
Construct a PageBase object using another PageBase object.
Parameters:
page = An existing PageBase object.
Example:
void output_page_type(PageBase &pb)
{
PageBase pbTemp(pb);
if( pbTemp.IsValid() )
printf("Page is of type %d\n", pbTemp.GetType());
else
printf("Page is invalid\n");
}
void test_output_page_type()
{
MatrixPage mp;
mp.Create("origin.otm");
if( mp.IsValid() )
output_page_type(mp);
}
*/
PageBase(PageBase &page);
/**
Get the page type.
Example:
PageBase pbTemp;
pbTemp = Project.Pages(); // Get the project's active page
if( pbTemp.IsValid() )
printf("Active page is of type %d\n", pbTemp.GetType());
else
printf("Active page is not valid\n");
Return:
A value representing the page type. See the EXIST constants defined in oc_const.h, they are:
EXIST_WKS 2
EXIST_PLOT 3
EXIST_MATRIX 5
EXIST_LAYOUT 11
EXIST_EXTERN_WKS 12 (Excel workbook)
*/
int GetType(); // Get the page type.
/**
Get the name of the page.
Example:
PageBase pb;
pb = Project.Pages(); // Get the project's active page
if( pb.IsValid() )
{
string strName;
if( pb.GetName(strName) )
printf("Active page is named %s\n", strName);
else
printf("Failed to get page name\n");
}
else
printf("Active page is not valid\n");
Parameters:
strName = The string that will recieve the name of the page.
Return:
TRUE for success or FALSE for failure.
SeeAlso:
PageBase::Rename
*/
BOOL GetName(string &strName);
#if _OC_VER < 0x0750
/**
Get the name of the page.
Example:
PageBase pb;
pb = Project.Pages(); // Get the project's active page
if( pb.IsValid() )
printf("Active page is named %s\n", pb.GetName());
else
printf("Active page is not valid\n");
Return:
The name of the page.
SeeAlso:
PageBase::Rename
*/
string GetName();
#endif //_OC_VER < 0x0750
/**
Change the name of the page.
Parameters:
lpcszNewName = Pointer to the string that holds the new name of the page.
bAskIfAlreadyUsed = TRUE will bring up a dialog box to ask for a new name, FALSE will use internal enumeration for the next available name
Return:
1 = given name is used to rename the page successfully,
0 = another name was used to rename the page, either through user input or through internal enumeration.
-1 = user click Cancel when ask for a different name to rename the page when bAskIfAlreadyUsed is set to TRUE.
Example:
void run_this()
{
PageBase pg = Project.Pages(); // Get the active page
if( pg )
{
string strOldName = pg.GetName();
string strNewName = strOldName + "AA";
if( pg.Rename(strNewName) >=0 )
printf("Page renamed from %s to %s\n", strOldName, strNewName);
else
printf("Failed to rename page\n");
}
else
printf("There is no Active page\n");
}
Remarks:
Please note that this function was changed from its original form
BOOL Rename(string strNewName);
to this new form in Origin 7 SR4, or Origin 8 Alpha3. The return values were setup such that old codes will still work
correctly.
SeeAlso:
PageBase::GetName
*/
int Rename(LPCSTR lpcszNewName, BOOL bAskIfAlreadyUsed = FALSE);
/**
Detach a Page object from a page. This will make the object invalid.
Retun:
TRUE for success or FALSE for failure.
Example:
GraphPage gp;
if( gp.Create("origin.otp", CREATE_VISIBLE_SAME) )
{
string strName = gp.GetName();
printf("Created a graph named %s\n", strName);
if( gp.Detach() )
printf("Detached %s, IsValid == %d\n", strName, gp.IsValid());
else
printf("Failed to detach %s\n", strName);
}
else
printf("Failed to create graph page.\n");
*/
BOOL Detach();
/**
This data member contains the labet text associated with the PageBase object.
Example:
WorksheetPage wp;
if( wp.Create("origin.otw", CREATE_VISIBLE_SAME) )
{
wp.Label = "My Label";
printf("Worksheet '%s' has label '%s'\n", wp.GetName(), wp.Label);
}
else
printf("Failed to create worksheet page.\n");
*/
string Label;
/**
This data member controls the display of window names and labels of the PageBase object.
It can be the following values, which defined OC_Const.h:
WIN_TITLE_SHOW_LABEL 1
WIN_TITLE_SHOW_NAME 2
WIN_TITLE_SHOW_BOTH 3
Example:
WorksheetPage wp;
if( wp.Create("origin.otw", CREATE_VISIBLE_SAME) )
{
wp.Label = "My Label";
wp.TitleShow = WIN_TITLE_SHOW_LABEL;
}
*/
int TitleShow;
/**
To open a hidden page, or to show a minimized window
Retun:
the original show state of the page if successful. Returns -1 if operation failed.
Remarks:
This function does the same thing as if double-clicking on the page in the Project explorer window if
PAGE_ACTIVATE is used, which is not one of the show state that can be obtained from GetShow.
Example:
Worksheet wksTemp;
if(wksTemp.Create(NULL, CREATE_HIDDEN))
{
// codes till fill wks with data
// then show it at the end when all is done
wksTemp.GetPage().Rename("MyNewWks");
wksTemp.GetPage().SetShow();
}
*/
int SetShow(int nNewShow = PAGE_ACTIVATE);
/**
To get the show state of the page
Return:
One of the values PAGE_NORMAL, PAGE_MINIMIZED, PAGE_MAXIMIZED, PAGE_HIDDEN,
Example:
void all_pages_show_info()
{
foreach(PageBase pg in Project.Pages)
{
if(pg.GetShow() == PAGE_HIDDEN)
printf("%s is hidden\n", pg.GetName());
else
printf("%s Show state is %d\n", pg.GetName(), pg.GetShow());
}
}
*/
int GetShow();
#if _OC_VER > 0x0703
/**#
This function returns a Window object associated with a page object.
Parameters:
nChildID = Resource ID of a window in the page. Use 0 to get the page's frame window (MDI ChildFrame)
Example:
void test_PageBase_GetWindow()
{
WorksheetPage wpMy("Data1");
Window winMyNN = wpMy.GetWindow();
if (winMyNN)
printf("Get window successfully!\n");
else
printf("Get window error!\n");
}
*/
Window GetWindow(int nChildID = 0);
/**
Print the page.
Parameters:
tn = tree node which stores settings related to printing.
Return:
TRUE if succeded, FALSE if failed.
Example:
GraphPage page("Graph1"); // page to print
Tree tree;
tree.Printing.PrinterName.strVal = "Canon Bubble-Jet BJC-2000"; // ignore default printer, use Canon instead
tree.Printing.NumberOfCopies.nVal = 2; // print 2 copies
tree.Printing.DPI.nVal = 300; // resolution 300 dpi
BOOL bResult = page.Print(tree);
*/
BOOL Print(TreeNode& tn);
#endif // _OC_VER > 0x0703
/**
get the folder of the page
Return:
A valid Folder object if successful, otherwise a NULL object
Example:
PageBase pbTemp = Project.Pages();
if(pbTemp)
{
Folder fd = pbTemp.GetFolder();
if(fd)
printf("%s is at %s\n", pbTemp.GetName(), fd.GetPath());
else
printf("Error: %s is not in any folder, impossible!\n", pbTemp.GetName());
}
*/
Folder GetFolder();
#if _OC_VER >= 0x0750
/**
Get the page's creation and last modified time, size, and number of dependents
Return:
TRUE if succeded, FALSE if failed.
Parameters:
pInfo=the pointer to a structure to receive the information:
typedef struct tagPageSystemInfo
{
double dCreated;
double dModified;
int nSize;
int nDependents;
} PageSystemInfo;
Example:
PageBase pg = Project.Pages();
PageSystemInfo PgInfo;
bool bb = pg.GetPageSystemInfo(&PgInfo);
double dCreated = PgInfo.dCreated;
double dModified = PgInfo.dModified;
int nSize = PgInfo.nSize;
int nDependents = PgInfo.nDependents;
*/
BOOL GetPageSystemInfo(PageSystemInfo *pInfo);
/**
Saves the page to file. It corresponds to the individual window saving from menu. For
Excel it saves it as a native Excel workbook file. For Note it saves it as a text file.
Parameters:
lpcszPathName=full pathname to the file location. The extension must be appropriate for type:
WorksheetPage: .OGW
WorksheetPage if Excel: .XLS
GraphPage: .OGG
Note extension not important
Return:
TRUE if succeded, FALSE if failed.
Example:
void test_SaveToFile()
{
// Make sure that a graph with the name "Graph1" exists.
GraphPage pg("Graph1");
if (!pg)
{
out_str("Invalid page!");
return;
}
// For this to succeed, the folder c:\mydatafolder\ must exist in advance.
BOOL bOK = pg.SaveToFile("c:\\mydatafolder\\save test.ogg");
out_int("OK = ", bOK);
}
*/
BOOL SaveToFile(LPCSTR lpcszPathName);
#endif //_OC_VER >= 0x0750
};
/** >Internal Origin Objects
The Page class provides methods and properties common to all internal Origin pages
that contain one or more layers (all Origin windows except Note windows). The Page
class contains a collection of all layers in the page. An Origin C Page object is a
wrapper object that is a reference to an internal Origin page object. Origin C wrapper
objects do not actually exist in Origin and merely refer to the internal Origin object.
Consequently, multiple Origin C wrapper objects can refer to the same internal Origin
object. The Page class is derived from the PageBase and OriginObject classes from which
it inherits methods and properties.
Example:
// Assumes Origin page with graph (text, arrow, rectangle, etc.) object is active window
Page pg;
pg = (Page) Project.Pages(); // Get the project's active page
if( pg.IsValid() )
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -