47static char mainClassName[] =
"G4UIWin32";
48static G4bool exitSession =
true;
49static G4bool exitPause =
true;
50static G4bool exitHelp =
true;
54static WNDPROC origComboEditorWindowProc;
56static G4bool ConvertStringToInt(
const char*,
G4int&);
58static G4int actionIdentifier = 0;
63 : fHWndMainWindow(nullptr),
65 fHWndToolBar(nullptr),
66 fHWndComboBox(nullptr),
67 fHWndComboEditor(nullptr),
68 fHWndHelpTree(nullptr),
82 INITCOMMONCONTROLSEX commCtrls;
83 commCtrls.dwSize =
sizeof(INITCOMMONCONTROLSEX);
84 commCtrls.dwICC = ICC_BAR_CLASSES | ICC_LISTVIEW_CLASSES;
86 InitCommonControlsEx(&commCtrls);
90 static G4bool Done =
false;
94 wc.lpfnWndProc = (WNDPROC)G4UIWin32::MainWindowProc;
97 wc.hInstance = ::GetModuleHandle(
nullptr);
98 wc.hIcon = LoadIcon(
nullptr, IDI_APPLICATION);
99 wc.hCursor = LoadCursor(
nullptr, IDC_ARROW);
100 wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
101 wc.lpszMenuName = (PTSTR)mainClassName;
102 wc.lpszClassName = (PTSTR)mainClassName;
104 if (! RegisterClass(&wc)) {
105 MessageBoxA(
nullptr,
"G4UIWin32: Win32 window registration failed!",
"Error!",
106 MB_ICONEXCLAMATION | MB_OK);
107 G4cout <<
"G4UIWin32: Win32 window registration failed!" <<
G4endl;
114 menuBar = CreateMenu();
117 HMENU hMenu = CreatePopupMenu();
118 AppendMenuA(menuBar, MF_POPUP, (UINT_PTR)hMenu,
"&Geant4");
121 AppendMenuA(hMenu, MF_STRING,
ID_OPEN_MACRO,
"&Open macro...");
123 AppendMenuA(hMenu, MF_SEPARATOR, -1,
"");
125 AppendMenuA(hMenu, MF_SEPARATOR, -1,
"");
126 AppendMenuA(hMenu, MF_STRING,
ID_EXIT_APP,
"E&xit");
128 hMenu = CreatePopupMenu();
129 AppendMenuA(menuBar, MF_POPUP, (UINT_PTR)hMenu,
"&View");
134 AppendMenuA(hMenu, MF_SEPARATOR, -1,
"");
137 AppendMenuA(hMenu, MF_SEPARATOR, -1,
"");
143 hMenu = CreatePopupMenu();
144 AppendMenuA(menuBar, MF_POPUP, (UINT_PTR)hMenu,
"&Zoom");
147 AppendMenuA(hMenu, MF_STRING,
ID_ZOOM_IN,
"Zoom &In");
148 AppendMenuA(hMenu, MF_STRING,
ID_ZOOM_OUT,
"Zoom &Out");
151 char winName[] =
"Geant4";
152 fHWndMainWindow = ::CreateWindowEx(WS_EX_CLIENTEDGE, (PTSTR)mainClassName, (PTSTR)winName,
153 WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
154 CW_USEDEFAULT,
nullptr, menuBar, ::GetModuleHandle(
nullptr),
nullptr);
156 if (fHWndMainWindow ==
nullptr) {
157 MessageBoxA(
nullptr,
"Window Creation Failed!",
"Error!", MB_ICONEXCLAMATION | MB_OK);
160 tmpSession =
nullptr;
161 ::SetWindowLongPtr(fHWndMainWindow, GWLP_USERDATA, (LONG_PTR)
this);
163 ::SetForegroundWindow(fHWndMainWindow);
164 ::ShowWindow(fHWndMainWindow, SW_SHOWDEFAULT);
165 ::UpdateWindow(fHWndMainWindow);
194 if (fHWndStatus !=
nullptr) ::SetWindowLongPtr(fHWndStatus, GWLP_USERDATA, LONG(NULL));
195 if (fHWndHelpTree !=
nullptr) ::SetWindowLongPtr(fHWndHelpTree, GWLP_USERDATA, LONG(NULL));
196 if (fHWndComboBox !=
nullptr) ::SetWindowLongPtr(fHWndComboBox, GWLP_USERDATA, LONG(NULL));
197 if (fHWndToolBar !=
nullptr) ::SetWindowLongPtr(fHWndToolBar, GWLP_USERDATA, LONG(NULL));
198 if (fHWndEditor !=
nullptr) ::SetWindowLongPtr(fHWndEditor, GWLP_USERDATA, LONG(NULL));
199 if (fHWndMainWindow !=
nullptr) {
200 ::SetWindowLongPtr(fHWndMainWindow, GWLP_USERDATA, LONG(NULL));
201 ::DestroyWindow(fHWndMainWindow);
211 if (interactorManager !=
nullptr) {
221 while ((event = interactorManager->
GetEvent()) !=
nullptr) {
223 if (exitSession)
break;
250 if (a_state ==
"G4_pause> ") {
251 SecondaryLoop(
"Pause, type continue to exit this state");
254 if (a_state ==
"EndOfEvent") {
256 SecondaryLoop(
"End of event, type continue to exit this state");
264void G4UIWin32::SecondaryLoop(
const G4String& a_prompt)
266 if (interactorManager !=
nullptr) {
270 while ((event = interactorManager->
GetEvent()) !=
nullptr) {
272 if (exitPause)
break;
286 G4String str = ConvertNewLines(a_string);
288 AddText((LPSTR)str.data());
301 G4String str = ConvertNewLines(a_string);
303 AddText((LPSTR)str.data());
316 G4String str = ConvertNewLines(a_string);
318 AddText((LPSTR)str.data());
331 if (interactorManager !=
nullptr) {
335 while ((event = interactorManager->
GetEvent()) !=
nullptr) {
341 if (! fHelp)
return false;
354void G4UIWin32::ExitHelp()
const {}
362 if (a_name !=
nullptr) {
363 HMENU hMenu = CreatePopupMenu();
364 AppendMenuA(menuBar, MF_POPUP, (UINT_PTR)hMenu, a_label);
366 DrawMenuBar(fHWndMainWindow);
376 if ((a_menu !=
nullptr) && (a_label !=
nullptr) && (a_command !=
nullptr)) {
379 commands[actionIdentifier] = a_command;
380 AppendMenuA(hMenu, MF_STRING, actionIdentifier, a_label);
394LRESULT CALLBACK G4UIWin32::MainWindowProc(
395 HWND aWindow, UINT aMessage, WPARAM wParam, LPARAM lParam)
400 if (This !=
nullptr) {
401 if (! This->CreateComponents(aWindow)) {
402 MessageBoxA(aWindow,
"Could not create components.",
"Error", MB_OK | MB_ICONERROR);
410 auto* This = (
G4UIWin32*)::GetWindowLongPtr(aWindow, GWLP_USERDATA);
411 if (This !=
nullptr) {
412 if (! This->ResizeComponents(aWindow)) {
413 MessageBoxA(aWindow,
"Could not resize components.",
"Error", MB_OK | MB_ICONERROR);
421 DestroyWindow(aWindow);
429 auto* This = (
G4UIWin32*)::GetWindowLongPtr(aWindow, GWLP_USERDATA);
430 if (This !=
nullptr) SetFocus(This->fHWndComboBox);
435 auto* This = (
G4UIWin32*)::GetWindowLongPtr(aWindow, GWLP_USERDATA);
436 if (This !=
nullptr) {
437 switch (((LPNMHDR)lParam)->
code) {
440 auto lpttt = (LPTOOLTIPTEXT)lParam;
441 lpttt->hinst =
nullptr;
442 UINT idButton = lpttt->hdr.idFrom;
443 lpttt->lpszText = (PTSTR)This->GetToolTips(idButton).c_str();
447 case TVN_GETINFOTIP: {
448 auto pTip = (LPNMTVGETINFOTIP)lParam;
449 pTip->pszText = (PTSTR)This->GetHelpTreeToolTips(pTip->hItem).c_str();
454 auto lpnmh = (LPNMHDR)lParam;
455 auto item = TreeView_GetSelection(lpnmh->hwndFrom);
456 This->HelpTreeDoubleClick(item);
464 auto* This = (
G4UIWin32*)::GetWindowLongPtr(aWindow, GWLP_USERDATA);
466 if (! This->ProcessDefaultCommands(LOWORD(wParam)))
468 switch (LOWORD(wParam)) {
471 if (HIWORD(wParam) == EN_ERRSPACE || HIWORD(wParam) == EN_MAXTEXT) {
473 SendMessage(This->fHWndEditor, EM_GETLIMITTEXT, (WPARAM)0, (LPARAM)0);
476 SendMessage(This->fHWndEditor, EM_SETSEL, (WPARAM)0, (LPARAM)bufferSize / 3);
478 SendMessage(This->fHWndEditor, EM_REPLACESEL, (WPARAM)0, (LPARAM)
"");
480 SendMessage(This->fHWndEditor, WM_VSCROLL, SB_BOTTOM, NULL);
485 G4String command = This->GetCommand(wParam);
486 This->ApplyShellCommand(command, exitSession, exitPause);
493 return DefWindowProc(aWindow, aMessage, wParam, lParam);
501LRESULT CALLBACK G4UIWin32::ComboEditorWindowProc(
502 HWND aWindow, UINT aMessage, WPARAM wParam, LPARAM lParam)
505 HWND parent = GetParent(GetParent(aWindow));
506 auto* This = (
G4UIWin32*)::GetWindowLongPtr(parent, GWLP_USERDATA);
512 if (This !=
nullptr) {
513 if (This->fHelp)
break;
515 This->ProcessTabKey();
521 if (This !=
nullptr) This->ProcessEscKey();
526 if (This !=
nullptr) This->ProcessEnterKey();
531 if (This !=
nullptr) This->ProcessUpKey();
536 if (This !=
nullptr) This->ProcessDownKey();
555 return CallWindowProc(origComboEditorWindowProc, aWindow, aMessage, wParam, lParam);
562G4bool G4UIWin32::CreateComponents(HWND aWindow)
569 G4int statwidths[] = {100, -1};
572 char winName[] =
"EDIT";
573 char winParam[] =
"";
574 fHWndEditor = CreateWindowEx(WS_EX_CLIENTEDGE, (PTSTR)winName, (PTSTR)winParam,
575 WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | ES_MULTILINE | ES_AUTOVSCROLL |
576 ES_AUTOHSCROLL | ES_READONLY,
577 0, 0, 100, 100, aWindow, (HMENU)
IDC_MAIN_EDIT, GetModuleHandle(
nullptr),
nullptr);
578 if (fHWndEditor ==
nullptr)
579 MessageBoxA(aWindow,
"Could not create edit box.",
"Error", MB_OK | MB_ICONERROR);
583 hfDefault = CreateFontA(-10, -8, 0, 0, 0,
false, 0, 0, OEM_CHARSET, OUT_RASTER_PRECIS,
584 CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FIXED_PITCH,
"System");
585 SendMessage(fHWndEditor, WM_SETFONT, (WPARAM)hfDefault, MAKELPARAM(
false, 0));
588 SendMessage(fHWndEditor, EM_SETLIMITTEXT, (WPARAM)500000, (LPARAM)0);
591 fHWndToolBar = CreateWindowEx(0, TOOLBARCLASSNAME,
nullptr,
592 WS_CHILD | WS_VISIBLE | TBSTYLE_FLAT | TBSTYLE_TOOLTIPS, 0, 0, 0, 0, aWindow,
594 if (fHWndToolBar ==
nullptr)
595 MessageBoxA(aWindow,
"Could not create tool bar.",
"Error", MB_OK | MB_ICONERROR);
598 SendMessage(fHWndToolBar, TB_BUTTONSTRUCTSIZE, (WPARAM)
sizeof(TBBUTTON), (LPARAM)0);
601 tbab.hInst = HINST_COMMCTRL;
602 tbab.nID = IDB_STD_SMALL_COLOR;
603 SendMessage(fHWndToolBar, TB_ADDBITMAP, (WPARAM)0, (LPARAM)&tbab);
606 tbab.hInst = HINST_COMMCTRL;
607 tbab.nID = IDB_HIST_SMALL_COLOR;
608 SendMessage(fHWndToolBar, TB_ADDBITMAP, (WPARAM)0, (LPARAM)&tbab);
610 G4int btnBMP[
NUM_BUTTONS] = {STD_FILEOPEN, STD_FILESAVE, -1, STD_FIND, STD_FIND, -1,
611 15 + HIST_FORWARD, -1, STD_HELP, -1, STD_FILENEW, STD_FILESAVE};
612 G4int btnSTL[
NUM_BUTTONS] = {TBSTYLE_BUTTON, TBSTYLE_BUTTON, TBSTYLE_SEP, TBSTYLE_BUTTON,
613 TBSTYLE_BUTTON, TBSTYLE_SEP, TBSTYLE_BUTTON, TBSTYLE_SEP, TBSTYLE_BUTTON, TBSTYLE_SEP,
614 TBSTYLE_BUTTON, TBSTYLE_BUTTON};
617 ZeroMemory(tbb,
sizeof(tbb));
619 tbb[i].iBitmap = btnBMP[i];
620 tbb[i].fsState = TBSTATE_ENABLED;
621 tbb[i].fsStyle = btnSTL[i];
622 tbb[i].idCommand = btnCMD[i];
625 SendMessage(fHWndToolBar, TB_ADDBUTTONS,
sizeof(tbb) /
sizeof(TBBUTTON), (LPARAM)&tbb);
628 fHWndComboBox = CreateWindowEx(0, WC_COMBOBOX, TEXT(
""),
629 CBS_DROPDOWN | CBS_HASSTRINGS | WS_CHILD | WS_OVERLAPPED | WS_VISIBLE, 150, 0, 200, 200,
630 aWindow, (HMENU)
IDC_MAIN_COMBO, GetModuleHandle(
nullptr),
nullptr);
633 SendMessage(fHWndComboBox, CB_SETCURSEL, (WPARAM)2, (LPARAM)0);
636 fHWndComboEditor = FindWindowEx(fHWndComboBox,
nullptr, WC_EDIT,
nullptr);
639 origComboEditorWindowProc =
640 (WNDPROC)SetWindowLongPtr(fHWndComboEditor, GWLP_WNDPROC, (LONG_PTR)ComboEditorWindowProc);
646 GetClientRect(aWindow, &rcClient);
647 fHWndHelpTree = CreateWindowEx(0, WC_TREEVIEW, TEXT(
"Tree View"),
648 WS_VISIBLE | WS_CHILD | WS_BORDER | TVS_INFOTIP | TVS_HASBUTTONS | TVS_HASLINES |
651 GetModuleHandle(
nullptr),
nullptr);
660 fHWndStatus = CreateWindowEx(0, STATUSCLASSNAME,
nullptr, WS_CHILD | WS_VISIBLE | SBARS_SIZEGRIP,
661 100, 100, 200, 200, aWindow, (HMENU)
IDC_MAIN_STATUS, GetModuleHandle(
nullptr),
nullptr);
663 SendMessage(fHWndStatus, SB_SETPARTS,
sizeof(statwidths) /
sizeof(
int), (LPARAM)statwidths);
673G4bool G4UIWin32::ResizeComponents(HWND aWindow)
676 G4int iToolHeight, iToolWidth;
682 G4int iComboBoxHeight;
684 G4int iTreeViewHeight, iTreeViewWidth;
685 G4int iEditHeight, iEditWidth;
690 SendMessage(fHWndToolBar, TB_AUTOSIZE, 0, 0);
692 GetWindowRect(fHWndToolBar, &rcTool);
693 iToolHeight = rcTool.bottom - rcTool.top;
694 iToolWidth = rcTool.right - rcTool.left;
697 SendMessage(fHWndStatus, WM_SIZE, 0, 0);
699 GetWindowRect(fHWndStatus, &rcStatus);
700 iStatusHeight = rcStatus.bottom - rcStatus.top;
703 SendMessage(fHWndComboBox, WM_SIZE, 0, 0);
705 GetWindowRect(fHWndComboBox, &rcComboBox);
706 iComboBoxHeight = rcComboBox.bottom - rcComboBox.top;
709 GetClientRect(aWindow, &rcClient);
711 iTreeViewHeight = rcClient.bottom - iToolHeight - iStatusHeight;
712 iTreeViewWidth = iToolWidth / 4;
714 iEditHeight = rcClient.bottom - iToolHeight - iComboBoxHeight - iStatusHeight;
715 iEditWidth = iToolWidth - iTreeViewWidth;
719 fHWndHelpTree,
nullptr, 0, iToolHeight, iTreeViewWidth, iTreeViewHeight, SWP_NOZORDER);
723 fHWndEditor,
nullptr, iTreeViewWidth, iToolHeight, iEditWidth, iEditHeight, SWP_NOZORDER);
727 fHWndComboBox,
nullptr, iTreeViewWidth, iToolHeight + iEditHeight, iEditWidth, 200, 0);
736void G4UIWin32::ProcessTabKey()
741 if (SendMessage(fHWndComboBox, WM_GETTEXT, (WPARAM)
sizeof(buffer), (LPARAM)buffer) != 0) {
744 SetFocus(fHWndComboBox);
747 const char* d = cmd.data();
749 Edit_SetText(fHWndComboEditor, (PTSTR)d);
750 Edit_SetSel(fHWndComboEditor, l, l);
753 if (GetFocus() == fHWndComboEditor)
754 SetFocus(fHWndHelpTree);
756 SetFocus(fHWndComboBox);
764void G4UIWin32::ProcessEscKey()
767 SendMessage(fHWndComboBox, CB_SETCURSEL, (WPARAM)(-1), (LPARAM)0);
769 SetFocus(fHWndComboBox);
776void G4UIWin32::ProcessEnterKey()
779 DWORD dwIndex, numItems;
782 if (SendMessage(fHWndComboBox, WM_GETTEXT, (WPARAM)
sizeof(buffer), (LPARAM)buffer) != 0) {
783 SetFocus(fHWndComboBox);
789 SendMessage(fHWndComboBox, CB_SETCURSEL, (WPARAM)-1, (LPARAM)0);
793 fHelp = ConvertStringToInt(command.data(), fHelpChoice);
796 fHistory.push_back(command);
803 dwIndex = SendMessage(fHWndComboBox, CB_FINDSTRINGEXACT, (WPARAM)(-1), (LPARAM)buffer);
806 if (dwIndex == CB_ERR)
807 dwIndex = SendMessage(fHWndComboBox, CB_INSERTSTRING, (WPARAM)0, (LPARAM)buffer);
809 if (dwIndex != CB_ERR) {
810 SendMessage(fHWndComboBox, CB_DELETESTRING, (WPARAM)dwIndex, (LPARAM)0);
811 dwIndex = SendMessage(fHWndComboBox, CB_INSERTSTRING, (WPARAM)0, (LPARAM)buffer);
814 numItems = SendMessage(fHWndComboBox, CB_GETCOUNT, (WPARAM)0, (LPARAM)0);
816 SendMessage(fHWndComboBox, CB_DELETESTRING, (WPARAM)(numItems - 1), (LPARAM)0);
817 numItems = SendMessage(fHWndComboBox, CB_GETCOUNT, (WPARAM)0, (LPARAM)0);
827void G4UIWin32::ProcessUpKey()
829 G4int pos = fHistoryPos == -1 ? fHistory.size() - 1 : fHistoryPos - 1;
830 if ((pos >= 0) && (pos < (
G4int)fHistory.size())) {
832 const char* d = command.data();
834 Edit_SetText(fHWndComboEditor, (PTSTR)d);
835 Edit_SetSel(fHWndComboEditor, l, l);
845void G4UIWin32::ProcessDownKey()
848 if ((pos >= 0) && (pos < (
G4int)fHistory.size())) {
850 const char* d = command.data();
852 Edit_SetText(fHWndComboEditor, (PTSTR)d);
853 Edit_SetSel(fHWndComboEditor, l, l);
857 else if (pos >= (
G4int)fHistory.size()) {
859 Edit_SetText(fHWndComboEditor, (PTSTR)eName);
860 Edit_SetSel(fHWndComboEditor, 0, 0);
870G4bool G4UIWin32::ProcessDefaultCommands(
G4int idCommand)
874 PostMessage(fHWndMainWindow, WM_CLOSE, 0, 0);
877 DoOpenMacro(fHWndMainWindow);
880 DoSaveViewer(fHWndMainWindow);
892 G4String command =
"/vis/viewer/set/style s";
898 G4String command =
"/vis/viewer/set/style w";
904 G4String command =
"/vis/viewer/set/projection o";
910 G4String command =
"/vis/viewer/set/projection p";
916 G4String command =
"/vis/viewer/zoom 1.2";
922 G4String command =
"/vis/viewer/zoom 0.8";
928 G4String command =
"/vis/viewer/set/viewpointThetaPhi 0. 0.";
934 G4String command =
"/vis/viewer/set/viewpointThetaPhi 90. 0.";
940 G4String command =
"/vis/viewer/set/viewpointThetaPhi 0. 90.";
946 G4String command =
"/vis/viewer/set/viewpointThetaPhi 45. -45.";
955 SetDlgItemText(fHWndMainWindow,
IDC_MAIN_EDIT, (PTSTR)eName);
959 DoSaveLog(fHWndMainWindow);
974 return "Open and execute macro file";
977 return "Save viewer state";
986 return "Beam on (one particle)";
989 return "About G4UIWin32";
1006G4String G4UIWin32::GetHelpTreeToolTips(HTREEITEM item)
1010 if (UI ==
nullptr)
return "";
1013 G4String itemText = GetItemPath(item);
1016 if (TreeView_GetChild(fHWndHelpTree, item) !=
nullptr) itemText +=
"/";
1027 if (path)
return path->
GetTitle().data();
1041 G4String str = std::move(a_string);
1042 size_t index = str.find(
"\n", 0);
1043 while (index < str.length()) {
1044 str.replace(index, 2,
"\r\n");
1046 index = str.find(
"\n", index + 2);
1055void G4UIWin32::HelpTreeDoubleClick(HTREEITEM item)
1057 const char* item_path = GetItemPath(item);
1058 G4int l = strlen(item_path);
1059 Edit_SetText(fHWndComboEditor, (PTSTR)item_path);
1060 Edit_SetSel(fHWndComboEditor, l, l);
1062 SetFocus(fHWndComboEditor);
1069G4bool G4UIWin32::SaveLogFile(LPCTSTR fileName)
1075 CreateFile(fileName, GENERIC_WRITE, 0,
nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,
nullptr);
1076 if (hFile != INVALID_HANDLE_VALUE) {
1079 dwTextLength = GetWindowTextLength(fHWndEditor);
1081 if (dwTextLength > 0) {
1083 DWORD dwBufferSize = dwTextLength + 1;
1085 text = (LPSTR)GlobalAlloc(GPTR, dwBufferSize);
1086 if (text !=
nullptr) {
1087 if (GetWindowTextA(fHWndEditor, text, dwBufferSize)) {
1090 if (WriteFile(hFile, text, dwTextLength, &dwWritten,
nullptr)) bSuccess =
true;
1104void G4UIWin32::AddText(LPSTR text)
1106 if ((fHWndEditor !=
nullptr) && (text !=
nullptr) && (text[0] !=
'\0')) {
1108 G4int ndx = GetWindowTextLength(fHWndEditor);
1111 SendMessage(fHWndEditor, EM_SETSEL, (WPARAM)ndx, (LPARAM)ndx);
1113 SendMessage(fHWndEditor, EM_REPLACESEL, (WPARAM)0, (LPARAM)text);
1115 SendMessage(fHWndEditor, WM_VSCROLL, SB_BOTTOM, NULL);
1123void G4UIWin32::DoOpenMacro(HWND aWindow)
1126 char szFileName[MAX_PATH] =
"";
1128 ZeroMemory(&ofn,
sizeof(ofn));
1130 ofn.lStructSize =
sizeof(ofn);
1131 ofn.hwndOwner = aWindow;
1132 char fName[] =
"Macro Files (*.mac)\0*.mac\0All Files (*.*)\0*.*\0";
1133 ofn.lpstrFilter = (PTSTR)fName;
1134 ofn.lpstrFile = (PTSTR)szFileName;
1135 ofn.nMaxFile = MAX_PATH;
1136 ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
1137 char dName[] =
"mac";
1138 ofn.lpstrDefExt = (PTSTR)dName;
1140 if (GetOpenFileName(&ofn)) {
1144 SendDlgItemMessage(aWindow,
IDC_MAIN_STATUS, SB_SETTEXT, 0, (LPARAM)
"Opened macro...");
1145 SendDlgItemMessage(aWindow,
IDC_MAIN_STATUS, SB_SETTEXT, 1, (LPARAM)szFileName);
1153void G4UIWin32::DoSaveViewer(HWND aWindow)
1156 char szFileName[MAX_PATH] =
"";
1158 ZeroMemory(&ofn,
sizeof(ofn));
1160 ofn.lStructSize =
sizeof(ofn);
1161 ofn.hwndOwner = aWindow;
1162 char fName[] =
"Macro Files (*.mac)\0*.mac\0All Files (*.*)\0*.*\0";
1163 ofn.lpstrFilter = (PTSTR)fName;
1164 ofn.lpstrFile = (PTSTR)szFileName;
1165 ofn.nMaxFile = MAX_PATH;
1166 char dName[] =
"mac";
1167 ofn.lpstrDefExt = (PTSTR)dName;
1168 ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
1170 if (GetSaveFileName(&ofn)) {
1174 SendDlgItemMessage(aWindow,
IDC_MAIN_STATUS, SB_SETTEXT, 0, (LPARAM)
"State saved...");
1175 SendDlgItemMessage(aWindow,
IDC_MAIN_STATUS, SB_SETTEXT, 1, (LPARAM)szFileName);
1183void G4UIWin32::DoSaveLog(HWND aWindow)
1186 char szFileName[MAX_PATH] =
"";
1188 ZeroMemory(&ofn,
sizeof(ofn));
1190 ofn.lStructSize =
sizeof(ofn);
1191 ofn.hwndOwner = aWindow;
1192 char fName[] =
"Log Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
1193 ofn.lpstrFilter = (PTSTR)fName;
1194 ofn.lpstrFile = (PTSTR)szFileName;
1195 ofn.nMaxFile = MAX_PATH;
1196 char dName[] =
"txt";
1197 ofn.lpstrDefExt = (PTSTR)dName;
1198 ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
1200 if (GetSaveFileName(&ofn)) {
1201 if (SaveLogFile((PTSTR)szFileName)) {
1202 SendDlgItemMessage(aWindow,
IDC_MAIN_STATUS, SB_SETTEXT, 0, (LPARAM)
"Saved log file...");
1203 SendDlgItemMessage(aWindow,
IDC_MAIN_STATUS, SB_SETTEXT, 1, (LPARAM)szFileName);
1212G4bool G4UIWin32::InitHelpTreeItems()
1217 if (UI ==
nullptr)
return false;
1222 for (
G4int a = 0; a < treeSize; a++) {
1227 newItem = AddItemToHelpTree((PTSTR)GetShortCommandPath(commandText).c_str());
1229 if (newItem ==
nullptr)
return false;
1232 CreateHelpTree(newItem, treeTop->
GetTree(a + 1));
1242void G4UIWin32::CreateHelpTree(HTREEITEM aParent,
G4UIcommandTree* aCommandTree)
1244 if ((aParent !=
nullptr) && (aCommandTree !=
nullptr)) {
1255 AddItemToHelpTree((PTSTR)GetShortCommandPath(commandText).c_str(), aParent);
1258 CreateHelpTree(newItem, aCommandTree->
GetTree(a + 1));
1266 AddItemToHelpTree((PTSTR)GetShortCommandPath(commandText).c_str(), aParent);
1275HTREEITEM G4UIWin32::AddItemToHelpTree(LPTSTR lpszItem, HTREEITEM aParent)
1278 TVINSERTSTRUCT tvins;
1279 static auto hPrev = (HTREEITEM)TVI_FIRST;
1281 tvi.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM;
1284 tvi.pszText = lpszItem;
1285 tvi.cchTextMax =
sizeof(tvi.pszText) /
sizeof(tvi.pszText[0]);
1289 tvi.lParam = (LPARAM)aParent;
1291 tvins.hInsertAfter = hPrev;
1293 tvins.hParent = aParent;
1296 hPrev = (HTREEITEM)SendMessage(
1297 fHWndHelpTree, TVM_INSERTITEM, (WPARAM)0, (LPARAM)(LPTVINSERTSTRUCT)&tvins);
1299 if (hPrev ==
nullptr)
1311 G4String str = std::move(commandPath);
1313 if (str.find_last_of(
"/") == (str.size() - 1)) str = str.erase(str.size() - 1, 1);
1315 str = str.erase(0, str.find_last_of(
"/") + 1);
1324LPSTR G4UIWin32::GetItemPath(HTREEITEM item)
1328 tvitem.mask = TVIF_TEXT;
1329 tvitem.hItem = item;
1330 TCHAR infoTipBuf[1024];
1331 tvitem.pszText = infoTipBuf;
1332 tvitem.cchTextMax =
sizeof(infoTipBuf) /
sizeof(TCHAR);
1334 std::string str =
"";
1335 while (item !=
nullptr) {
1336 TreeView_GetItem(fHWndHelpTree, &tvitem);
1337 str =
"/" + std::string((PSTR)tvitem.pszText) + str;
1339 item = TreeView_GetParent(fHWndHelpTree, item);
1340 tvitem.hItem = item;
1343 auto* result =
new TCHAR[str.size() + 1];
1344 result[str.size()] = 0;
1345 std::copy(str.begin(), str.end(), result);
1347 return (LPSTR)result;
1354G4bool ConvertStringToInt(
const char* aString,
G4int& aInt)
1357 if (aString ==
nullptr)
return false;
1359 G4long value = strtol(aString, &s, 10);
1360 if (s == aString)
return false;
#define ID_ORIENTATION_YZ
#define ID_ORIENTATION_OBLIQUE
#define IDC_MAIN_TREE_VIEW
#define ID_SAVE_VIEWER_STATE
#define MAX_HISTORY_ITEMS
#define ID_PROJ_ORTHOGRAPHIC
#define ID_ORIENTATION_XY
#define ID_PROJ_PERSPECTIVE
#define ID_ORIENTATION_XZ
#define ID_VIEW_WIREFRAME
G4GLOB_DLL std::ostream G4cout
G4int ReceiveG4debug(const G4String &) override
G4int ReceiveG4cout(const G4String &) override
G4UIsession * SessionStart() override
void AddMenu(const char *, const char *) override
void PauseSessionStart(const G4String &) override
G4String GetCommand(G4int)
void AddButton(const char *, const char *, const char *) override
G4int ReceiveG4cerr(const G4String &) override
void Prompt(const G4String &)
G4int GetCommandEntry() const
G4UIcommand * GetCommand(G4int i)
const G4String & GetPathName() const
G4int GetTreeEntry() const
G4UIcommandTree * GetTree(G4int i)
G4UIcommandTree * FindCommandTree(const char *commandPath)
const G4String GetTitle() const
G4UIcommand * FindPath(const char *commandPath) const
const G4String & GetGuidanceLine(G4int i) const
const G4String & GetCommandPath() const
void SetCoutDestination(G4UIsession *const value)
G4UIcommandTree * GetTree() const
static G4UImanager * GetUIpointer()
void SetSession(G4UIsession *const value)
void SetG4UIWindow(G4UIsession *const value)
G4String Complete(const G4String &)
void ApplyShellCommand(const G4String &, G4bool &, G4bool &)
void AddInteractor(G4String, G4Interactor)
G4Interactor GetInteractor(G4String)
void EnableSecondaryLoop()
void DisableSecondaryLoop()
virtual void * GetEvent()=0
void DispatchEvent(void *)
static G4Win32 * getInstance()