#include "ApplicationInterface.h" #include "Main.h" #include "swordce.h" #ifdef SIMPLE #include "SimpleNavigator.h" #define NAVIGATOR SimpleNavigator #include "../simplegui/resource.h" #else #include "Navigator.h" #define NAVIGATOR Navigator #include "resource.h" #endif #include #include NAVIGATOR* g_navigator; SWConfig *g_swordConf; static SHACTIVATEINFO s_sai; int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { MSG msg; HACCEL hAccelTable; bool ignoreMsgs = false; DWORD ignoreTill = GetTickCount(); // Some visual indication things are taking place... HCURSOR hOldCursor = SetCursor(LoadCursor(NULL, IDC_WAIT)); g_tMain = GetCurrentThreadId(); // Perform application initialization: if (!InitInstance (hInstance, nCmdShow)) { return FALSE; } hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_BIBLEREADER); // Turn off the wait icon... SetCursor(hOldCursor); // Main message loop: while (GetMessage(&msg, NULL, 0, 0)) { if(msg.message == WM_TXT_START){ ignoreMsgs = true; }else if(msg.message == WM_TXT_END){ ignoreMsgs = false; ignoreTill = msg.time; } // If we have a button or key event, and we are in the ignore message // window of time we ignore this message if((msg.message == WM_LBUTTONDOWN || msg.message == WM_KEYDOWN) && (ignoreMsgs || msg.time < ignoreTill)) continue; if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } return msg.wParam; } ATOM MyRegisterClass(HINSTANCE hInstance, LPTSTR szWindowClass) { WNDCLASS wc; wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = (WNDPROC) WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_BIBLEREADER)); wc.hCursor = 0; wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH); // Setting this does not prevent us from drawing our ownbackground. dtrotzjr wc.lpszMenuName = 0; wc.lpszClassName = szWindowClass; return RegisterClass(&wc); } BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { g_hWnd = NULL; g_hwndCB = NULL; TCHAR szTitle[MAX_LOADSTRING]; // The title bar text TCHAR szWindowClass[MAX_LOADSTRING]; // The window class name g_hInst = hInstance; // Store instance handle in our global variable // Create a general options file for storing options // and navigaiton history const char *cwd = getWorkingDirectory(); char confFName[MAX_PATH]; _snprintf(confFName, MAX_PATH, "%s\\options.conf", cwd); g_swordConf = new SWConfig(confFName); g_swordConf->Load(); // Initialize global strings LoadString(hInstance, IDC_BIBLEREADER, szWindowClass, MAX_LOADSTRING); LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); //If it is already running, then focus on the window g_hWnd = FindWindow(szWindowClass, NULL); if (g_hWnd) { // set focus to foremost child window // The "| 0x01" is used to bring any owned windows to the foreground and // activate them. SetForegroundWindow((HWND)((ULONG) g_hWnd | 0x00000001)); return 0; } MyRegisterClass(hInstance, szWindowClass); RECT rect; GetClientRect(g_hWnd, &rect); g_hWnd = CreateWindow(szWindowClass, szTitle, WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); if (!g_hWnd) { return FALSE; } //When the main window is created using CW_USEDEFAULT the height of the menubar (if one // is created is not taken into account). So we resize the window after creating it // if a menubar is present { RECT rc; GetWindowRect(g_hWnd, &rc); rc.bottom -= MENU_HEIGHT; if (g_hwndCB) MoveWindow(g_hWnd, rc.left, rc.top, rc.right, rc.bottom, FALSE); } if (!g_navigator->initialized()) { DialogBox(g_hInst, (LPCTSTR)IDD_ERROR_NOBIBLES, g_hWnd, (DLGPROC)Error); return FALSE; } initApplicationInterface(); g_navigator->updateTitle(); ShowWindow(g_hWnd, nCmdShow); g_navigator->setMode(MODE_TEXT); SetForegroundWindow((HWND)((ULONG) g_hWnd | 0x00000001)); UpdateWindow(g_hWnd); return TRUE; } LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; NMHDR *nm; switch (message) { case WM_NOTIFY: nm = (NMHDR *)lParam; switch (nm->code) { case NM_HOTSPOT: g_navigator->urlClicked(((NM_HTMLVIEW *)lParam)->szTarget); } break; case WM_LBUTTONDOWN: g_navigator->mouseDown(LOWORD(lParam),HIWORD(lParam));//x,y break; case WM_KEYDOWN: g_navigator->keyDown(wParam, lParam); break; case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); switch (wmId) { case IDOK: SendMessage(hWnd, WM_ACTIVATE, MAKEWPARAM(WA_INACTIVE, 0), (LPARAM)hWnd); SendMessage (hWnd, WM_CLOSE, 0, 0); break; case MENU_ABOUT: MessageBox(0, L"Sword reader program for Pocket PC ver. 1.0.1\n\nsee: http://www.crosswire.org/sword/swordreader/\n\nGUI by Johan Gorter, 2004\nNow being maintained by B. Drake, Robin Randall and David Trotz\nProverbs 16:3", L"About", MB_OK); break; case MENU_SHUTDOWN: SendMessage(hWnd, WM_ACTIVATE, MAKEWPARAM(WA_INACTIVE, 0), (LPARAM)hWnd); SendMessage (hWnd, WM_CLOSE, 0, 0); exit(0); default: if ((wmId>=USERBUTTONS)&&(wmIdbuttonClicked(wmId-USERBUTTONS); break; } else if (g_navigator->menuClicked(wmId)) {} else return DefWindowProc(hWnd, message, wParam, lParam); break; } break; case WM_CREATE: g_hWnd=hWnd; RECT clientRect; GetClientRect(g_hWnd,&clientRect); clientRect.bottom -= MENU_HEIGHT; g_navigator=new NAVIGATOR(&clientRect); g_hwndCB = CreateRpCommandBar(hWnd); setMenuSelected(g_hwndCB,MENU_TEXT,1); // Fill up the translation popup menu makeTranslations(); // Fill up the options popup menu makeGlobalOptions(); // Initialize the shell activate info structure memset (&s_sai, 0, sizeof (s_sai)); s_sai.cbSize = sizeof (s_sai); break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); SetBkMode(hdc,OPAQUE); SetBkColor(hdc,(COLORREF)GetSysColor(COLOR_WINDOW)); g_navigator->paint(); EndPaint(hWnd, &ps); break; case WM_DESTROY: CommandBar_Destroy(g_hwndCB); delete g_navigator; PostQuitMessage(0); g_swordConf->Save(); delete g_swordConf; closeApplicationInterface(); break; case WM_ACTIVATE: // Notify shell of our activate message SHHandleWMActivate(hWnd, wParam, lParam, &s_sai, FALSE); break; case WM_SETTINGCHANGE: SHHandleWMSettingChange(hWnd, wParam, lParam, &s_sai); break; case WM_SIZE: break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; } HWND CreateRpCommandBar(HWND hwnd) { SHMENUBARINFO mbi; memset(&mbi, 0, sizeof(SHMENUBARINFO)); mbi.cbSize = sizeof(SHMENUBARINFO); mbi.hwndParent = hwnd; mbi.nToolBarId = IDM_MENU; mbi.hInstRes = g_hInst; mbi.nBmpId = 0; mbi.cBmpImages = 0; if (!SHCreateMenuBar(&mbi)) return NULL; return mbi.hwndMB; } void makeTranslations() { HMENU menuMenu = getSubMenu(g_hwndCB,MENU_MENU); HMENU menuTranslations=CreatePopupMenu(); InsertMenu(menuMenu,0,MF_BYPOSITION | MF_POPUP,(UINT)menuTranslations,L"Translation"); g_navigator->fillTranslationsMenu(menuTranslations); DrawMenuBar(g_hwndCB); } void makeGlobalOptions() { HMENU menuMenu = getSubMenu(g_hwndCB,MENU_MENU); HMENU menuGlobalOptions=CreatePopupMenu(); InsertMenu(menuMenu,0,MF_BYPOSITION | MF_POPUP,(UINT)menuGlobalOptions,L"Options"); g_navigator->fillGlobalOptionsMenu(menuGlobalOptions); g_navigator->toggleOptionMenu(-1); // get all checked menu choiced correct, but don't change anything DrawMenuBar(g_hwndCB); } LRESULT CALLBACK Error(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { SHINITDLGINFO shidi; switch (message) { case WM_INITDIALOG: // Create a Done button and size it. shidi.dwMask = SHIDIM_FLAGS; shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN | SHIDIF_SIZEDLGFULLSCREEN; shidi.hDlg = hDlg; SHInitDialog(&shidi); return TRUE; case WM_COMMAND: if (LOWORD(wParam) == IDOK) { EndDialog(hDlg, LOWORD(wParam)); return TRUE; } break; } return FALSE; } namespace sword { char *SWBuf::nullStr = ""; }