📄 widgetsetup.cpp
字号:
XmStringFree(label);
XtAddCallback(g_saveButton, XmNactivateCallback, SaveClick, NULL);
// Create a file selection dialog with a *.mxd mask
XmString mask = XmStringCreateLocalized("*.mxd");
Arg args[1];
XtSetArg(args[0], XmNdirMask, mask);
g_selectFile = XmCreateFileSelectionDialog(mainForm, "Select File", args, 1);
XtAddCallback(g_selectFile, XmNokCallback, FileSelected, NULL);
XtAddCallback(g_selectFile, XmNnoMatchCallback, FileSelected, NULL);
XtAddCallback(g_selectFile, XmNcancelCallback, FileSelected, NULL);
// Disable the Help button
XtSetSensitive(XmFileSelectionBoxGetChild(g_selectFile, XmDIALOG_HELP_BUTTON), False);
// Set the name of the FileSelectionDialog
XtVaSetValues(g_selectFile,
XmNdialogTitle, XmStringCreateLocalized("Browse to Map Document"),
NULL);
// Create a file save dialog with a *.mxd mask
g_saveFile = XmCreateFileSelectionDialog(mainForm, "Save", args, 1);
XtAddCallback(g_saveFile, XmNokCallback, SaveAsSelected, NULL);
XtAddCallback(g_saveFile, XmNnoMatchCallback, SaveAsSelected, NULL);
XtAddCallback(g_saveFile, XmNcancelCallback, SaveAsSelected, NULL);
// Disable the Help button
XtSetSensitive(XmFileSelectionBoxGetChild(g_saveFile, XmDIALOG_HELP_BUTTON), False);
// Have the OK button display "save" instead
Widget saveButton = XmFileSelectionBoxGetChild(g_saveFile, XmDIALOG_OK_BUTTON);
XtVaSetValues(saveButton, XmNlabelString, XmStringCreateLocalized("Save"), NULL);
// Set the name of the FileSelectionDialog
XtVaSetValues(g_saveFile,
XmNdialogTitle, XmStringCreateLocalized("Save Map Document As"),
NULL);
XtManageChild(g_mainWindow);
XtManageChild(mainForm);
XtManageChild(rightPanel);
XtManageChild(leftPanel);
XtManageChild(g_currentMapText);
XtManageChild(controlsPanel);
XtManageChild(toolbarWidget);
XtManageChild(tocPLPanel);
XtManageChild(tocWidget);
XtManageChild(pageLayoutWidget);
XtManageChild(openButton);
XtManageChild(g_saveAsButton);
XtManageChild(g_saveButton);
// Buddy the toolbar and the TOC with the PageLayout
g_ipTOCControl->SetBuddyControl(g_ipPageLayoutControl);
g_ipToolbarControl->SetBuddyControl(g_ipPageLayoutControl);
AddToolbarItems();
// Handle the window manager message that the window is about to be closed
Atom wm_delete_window = XmInternAtom(XtDisplay(topLevel), "WM_DELETE_WINDOW", FALSE);
XmAddWMProtocolCallback(topLevel, wm_delete_window, CloseAppCallback, NULL);
// Start the application running
XtRealizeWidget(topLevel);
}
// Dispay a MessageDialog
void ShowMessage(char *dialogtitle, char *text)
{
// Create a MessageDialog
Widget msgBox;
Arg args[1];
int n = 0;
XtSetArg(args[n], XmNmessageString, XmStringCreateLocalized(text));
n++;
msgBox = XmCreateMessageDialog(g_mainWindow, "error", args, n);
// Remove the help and cancel buttons
XtUnmanageChild(XmMessageBoxGetChild(msgBox, XmDIALOG_HELP_BUTTON));
XtUnmanageChild(XmMessageBoxGetChild(msgBox, XmDIALOG_CANCEL_BUTTON));
// Set the title of the MessageDialog
XtVaSetValues(msgBox, XmNdialogTitle, XmStringCreateLocalized(dialogtitle), NULL);
XtManageChild(msgBox);
}
void OpenClick(Widget w, XtPointer client_data, XtPointer call_data)
{
XtManageChild(g_selectFile);
}
void FileSelected(Widget w, XtPointer client_data, XtPointer call_data)
{
char* fileName;
XmFileSelectionBoxCallbackStruct *cbs;
cbs = (XmFileSelectionBoxCallbackStruct *)call_data;
// Hide the dialog if they canceled
if (cbs->reason == XmCR_CANCEL)
{
XtUnmanageChild(w);
return;
}
// Get the file name and check for errors
if (!XmStringGetLtoR(cbs->value, XmFONTLIST_DEFAULT_TAG, &fileName))
{
ShowMessage("ERROR", "INTERNAL ERROR PROCESSING FILE");
XtUnmanageChild(w);
return;
}
if (!*fileName)
{
ShowMessage("ERROR", "NO FILE SELECTED");
XtUnmanageChild(w);
return;
}
bool bOpened;
if (cbs->reason != XmCR_NO_MATCH)
{
bOpened = OpenDocument(fileName);
}
// Hide file selection dialog
XtUnmanageChild(w);
if (bOpened)
{
// Enable the saving buttons
XtVaSetValues(g_saveAsButton, XmNsensitive, true, NULL);
XtVaSetValues(g_saveButton, XmNsensitive, true, NULL);
}
}
void SaveAsClick(Widget w, XtPointer client_data, XtPointer call_data)
{
XtManageChild(g_saveFile);
}
void SaveAsSelected(Widget w, XtPointer client_data, XtPointer call_data)
{
char* fileName;
XmFileSelectionBoxCallbackStruct *cbs;
cbs = (XmFileSelectionBoxCallbackStruct *)call_data;
// Hide the dialog if they canceled
if (cbs->reason == XmCR_CANCEL)
{
XtUnmanageChild(w);
return;
}
// Get the file name and check for errors
if (!XmStringGetLtoR(cbs->value, XmFONTLIST_DEFAULT_TAG, &fileName))
{
ShowMessage("ERROR", "INTERNAL ERROR PROCESSING FILE");
XtUnmanageChild(w);
return;
}
if (!*fileName)
{
ShowMessage("ERROR", "NO FILE SELECTED");
XtUnmanageChild(w);
return;
}
if (cbs->reason != XmCR_NO_MATCH)
{
SaveDocumentAs(fileName);
}
// Hide file selection dialog
XtUnmanageChild(w);
}
void SaveClick(Widget w, XtPointer client_data, XtPointer call_data)
{
SaveDocument();
}
void AddToolbarItems()
{
long itemIndex;
CComVariant varTool;
varTool = L"esriControlCommands.ControlsPageLayoutToolbar";
g_ipToolbarControl->AddItem(varTool, 0, -1, VARIANT_FALSE, 0,
esriCommandStyleIconOnly, &itemIndex);
varTool = L"esriControlCommands.ControlsGraphicElementToolbar";
g_ipToolbarControl->AddItem(varTool, 0, -1, VARIANT_TRUE, 0,
esriCommandStyleIconOnly, &itemIndex);
}
// Function called when WM_DELETE_WINDOW protocol is passed
void CloseAppCallback(Widget w, XtPointer client_data, XtPointer call_data)
{
g_ipPageLayoutControl = 0;
g_ipToolbarControl = 0;
g_ipTOCControl = 0;
g_ipMapDoc = 0;
// Uninitialize the engine
{
IAoInitializePtr ipInit(CLSID_AoInitialize);
ipInit->Shutdown();
}
::AoUninitialize();
exit(0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -