BOOL HexCreateNewFile(MAINWND *mainWnd) { // create a new int count; TCITEM tci = { TCIF_TEXT|TCIF_PARAM, 0, 0, TEXT("(Untitled)"), 0, 0 }; tci.lParam = (LPARAM)CreateHexViewCtrl(mainWnd->hwndMain); g_fFileChanged = FALSE; // reset to an empty file SetWindowFileName(mainWnd->hwndMain, TEXT("Untitled"), FALSE, FALSE); g_szFileTitle[0] = '\0'; g_szFileName[0] = '\0'; g_fFileChanged = FALSE; // insert at the end of the tab-list count = TabCtrl_GetItemCount(mainWnd->hwndTabView); TabCtrl_InsertItem(mainWnd->hwndTabView, count, &tci); HexSetCurFile(mainWnd->hwndMain, count, TRUE); return TRUE; }
// // Open the specified file // BOOL DoOpenFile(HWND hwndMain, TCHAR *szFileName, TCHAR *szFileTitle) { int fmt, fmtlook[] = { IDM_VIEW_ASCII, IDM_VIEW_UTF8, IDM_VIEW_UTF16, IDM_VIEW_UTF16BE }; if(TextView_OpenFile(g_hwndTextView, szFileName)) { SetWindowFileName(hwndMain, szFileTitle, FALSE); g_fFileChanged = FALSE; fmt = TextView_GetFormat(g_hwndTextView); CheckMenuRadioItem(GetMenu(hwndMain), IDM_VIEW_ASCII, IDM_VIEW_UTF16BE, fmtlook[fmt], MF_BYCOMMAND); NotifyFileChange(szFileName, hwndMain, 0); return TRUE; } else { FmtErrorMsg(hwndMain, MB_OK|MB_ICONWARNING, GetLastError(), _T("Error opening \'%s\'\r\n\r\n"), szFileName); //FormatMessage //MessageBox(hwndMain, _T("Error opening file"), APP_TITLE, MB_ICONEXCLAMATION); return FALSE; } }
void UpdateCurFileName(HWND hwndMain, HWND hwndHV, LPCTSTR szFileName, BOOL fChanged) { TCHAR szFullPath[MAX_PATH]; TCHAR *pszFileTitle; if(GetFullPathName(szFileName, MAX_PATH, szFullPath, &pszFileTitle)) { lstrcpy(g_szFileName, szFullPath); lstrcpy(g_szFileTitle, pszFileTitle); SetWindowFileName(hwndMain, pszFileTitle, fChanged, HexView_IsReadOnly(hwndHV)); } AddRecentFile(szFileName); UpdateRecentMenu(GetSubMenu(GetMenu(hwndMain), 0)); }
BOOL HexSetCurFile(HWND hwndMain, int iItem, BOOL fSetFocus) { TCITEM tci = { TCIF_PARAM }; HWND hwndHV, hwndOld; TCHAR szFilePath[MAX_PATH]; TCHAR *name; RECT rect; // get specied item if(!TabCtrl_GetItem(g_hwndTabView, iItem, &tci)) return FALSE; TabCtrl_SetCurSel(g_hwndTabView, iItem); hwndHV = (HWND)tci.lParam; hwndOld = g_hwndHexView; GetWindowRect(hwndOld, &rect); MapWindowPoints(0, hwndMain, (POINT *)&rect, 2); MoveWindow(hwndHV, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,0); g_hwndHexView = hwndHV; ForceClientResize(hwndMain); if(fSetFocus) SetFocus(hwndHV); HexView_GetFileName(hwndHV, szFilePath, MAX_PATH); name = _tcsrchr(szFilePath, '\\'); name = name ? name+1 : TEXT("Untitled"); SetWindowFileName(hwndMain, name, HexView_CanUndo(hwndHV), HexView_IsReadOnly(hwndHV)); if(hwndOld != hwndHV) ShowWindow(hwndOld, SW_HIDE); UpdateStatusBarText(g_hwndStatusBar, hwndHV); UpdateTypeView(); return TRUE; }
// // WM_NOTIFY handler for the TextView notification messages // UINT TextViewNotifyHandler(HWND hwnd, NMHDR *nmhdr) { switch(nmhdr->code) { // document has changed due to text input / undo / redo, update // the main window-title to show an asterisk next to the filename case TVN_CHANGED: if(g_szFileTitle[0]) { BOOL fModified = TextView_CanUndo(g_hwndTextView); if(fModified != g_fFileChanged) { SetWindowFileName(hwnd, g_szFileTitle, fModified); g_fFileChanged = fModified; } } break; // cursor position has changed, update the statusbar info case TVN_CURSOR_CHANGE: SetStatusBarText(g_hwndStatusbar, 1, 0, _T(" Ln %d, Col %d"), TextView_GetCurLine(g_hwndTextView) + 1, TextView_GetCurCol(g_hwndTextView) + 1 ); break; // edit/insert mode changed, update statusbar info case TVN_EDITMODE_CHANGE: SetStatusBarText(g_hwndStatusbar, 2, 0, g_szEditMode[TextView_GetEditMode(g_hwndTextView)] ); break; default: break; } return 0; }
LONG HexViewNotifyHandler(MAINWND *mainWnd, HWND hwnd, NMHDR *hdr) { HWND hwndHV = GetActiveHexView(hwnd);//g_hwndHexView; NMHVPROGRESS *hvp; switch(hdr->code) { case HVN_CHANGED: mainWnd->fChanged = TRUE; UpdateToolbarState(mainWnd->hwndToolbar, hwndHV); if(g_szFileTitle[0]) { BOOL fModified = HexView_CanUndo(hwndHV); if(fModified != g_fFileChanged) { SetWindowFileName(hwnd, g_szFileTitle, fModified, FALSE); g_fFileChanged = fModified; } } UpdateTypeView(); return 0; case HVN_EDITMODE_CHANGE: // show the unicode value under the cursor //SetStatusBarText(g_hwndStatusbar, 1, 0, TEXT(" U+%04X"), // TextView_GetCurChar(g_hwndTextView) ); UpdateStatusBarText(mainWnd->hwndStatusBar, hwndHV); //SetStatusBarText(mainWnd->hwndStatusBar, 4, 0, // g_szEditMode[HexView_GetEditMode(hwndHV)] ); return 0; case HVN_CURSOR_CHANGE: UpdateStatusBarText(mainWnd->hwndStatusBar, hwndHV); UpdateToolbarState(mainWnd->hwndStatusBar, hwndHV); UpdateTypeView(); return 0; case HVN_PROGRESS: hvp = (NMHVPROGRESS *)hdr; return UpdateProgress(mainWnd, TRUE, hvp->pos, hvp->len); //return 0; case HVN_BOOKCLOSE: //HexView_DelBookmark(((NMHVBOOKMARK *)hdr)->hdr.hwndFrom, 0); //RemoveBookmark((NMHVBOOKMARK *)hdr); return 0; default: return 0; } }
// // WM_COMMAND message handler for main window // UINT CommandHandler(HWND hwnd, UINT nCtrlId, UINT nCtrlCode, HWND hwndFrom) { RECT rect; switch(nCtrlId) { case IDM_FILE_NEW: // reset to an empty file SetWindowFileName(hwnd, _T("Untitled"), FALSE); TextView_Clear(g_hwndTextView); g_szFileTitle[0] = '\0'; g_fFileChanged = FALSE; return 0; case IDM_FILE_OPEN: // get a filename to open if(ShowOpenFileDlg(hwnd, g_szFileName, g_szFileTitle)) { DoOpenFile(hwnd, g_szFileName, g_szFileTitle); } return 0; case IDM_FILE_SAVE: MessageBox(hwnd, _T("Not implemented"), APP_TITLE, MB_ICONINFORMATION); return 0; case IDM_FILE_SAVEAS: // does nothing yet if(ShowSaveFileDlg(hwnd, g_szFileName, g_szFileTitle)) { MessageBox(hwnd, _T("Not implemented"), APP_TITLE, MB_ICONINFORMATION); } return 0; case IDM_FILE_PRINT: DeleteDC( ShowPrintDlg(hwnd) ); return 0; case IDM_FILE_EXIT: PostMessage(hwnd, WM_CLOSE, 0, 0); return 0; case IDM_EDIT_UNDO: case WM_UNDO: SendMessage(g_hwndTextView, WM_UNDO, 0, 0); return 0; case IDM_EDIT_REDO: SendMessage(g_hwndTextView, TXM_REDO, 0, 0); return 0; case IDM_EDIT_COPY: case WM_COPY: SendMessage(g_hwndTextView, WM_COPY, 0, 0); return 0; case IDM_EDIT_CUT: case WM_CUT: SendMessage(g_hwndTextView, WM_CUT, 0, 0); return 0; case IDM_EDIT_PASTE: case WM_PASTE: SendMessage(g_hwndTextView, WM_PASTE, 0, 0); return 0; case IDM_EDIT_DELETE: case WM_CLEAR: SendMessage(g_hwndTextView, WM_CLEAR, 0, 0); return 0; case IDM_EDIT_FIND: ShowFindDlg(hwnd, FIND_PAGE); return 0; case IDM_EDIT_REPLACE: ShowFindDlg(hwnd, REPLACE_PAGE); return 0; case IDM_EDIT_GOTO: ShowFindDlg(hwnd, GOTO_PAGE); return 0; case IDM_EDIT_SELECTALL: TextView_SelectAll(g_hwndTextView); return 0; case IDM_VIEW_OPTIONS: ShowOptions(hwnd); return 0; case IDM_VIEW_LINENUMBERS: g_fLineNumbers = !g_fLineNumbers; TextView_SetStyleBool(g_hwndTextView, TXS_LINENUMBERS, g_fLineNumbers); return 0; case IDM_VIEW_LONGLINES: g_fLongLines = !g_fLongLines; TextView_SetStyleBool(g_hwndTextView, TXS_LONGLINES, g_fLongLines); return 0; case IDM_VIEW_STATUSBAR: g_fShowStatusbar = !g_fShowStatusbar; ShowWindow(g_hwndStatusbar, SW_HIDE); GetClientRect(hwnd, &rect); PostMessage(hwnd, WM_SIZE, 0, MAKEWPARAM(rect.right, rect.bottom)); return 0; case IDM_VIEW_SAVEEXIT: g_fSaveOnExit = !g_fSaveOnExit; return 0; case IDM_VIEW_SAVENOW: SaveRegSettings(); return 0; case IDM_HELP_ABOUT: ShowAboutDlg(hwnd); return 0; default: return 0; } }