diff --git a/xpfe/xpviewer/src/JSConsole.cpp b/xpfe/xpviewer/src/JSConsole.cpp new file mode 100644 index 000000000000..d5e69985c5c3 --- /dev/null +++ b/xpfe/xpviewer/src/JSConsole.cpp @@ -0,0 +1,970 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +//is case this is defined from the outside... MMP +#ifdef WIN32_LEAN_AND_MEAN +#undef WIN32_LEAN_AND_MEAN +#endif + +#include "JSConsole.h" +#include "jsconsres.h" +#include "nsIScriptContext.h" +#include +#include "jsapi.h" + +HINSTANCE JSConsole::sAppInstance = 0; +HACCEL JSConsole::sAccelTable = 0; +CHAR JSConsole::sDefaultCaption[] = "JavaScript Console"; +BOOL JSConsole::mRegistered = FALSE; + + +// display an error string along with the error returned from +// the GetLastError functions +#define MESSAGE_LENGTH 256 +void DisplayError(LPSTR lpMessage) +{ + CHAR lpMsgBuf[MESSAGE_LENGTH * 2]; + CHAR lpLastError[MESSAGE_LENGTH]; + + ::FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, + NULL, + GetLastError(), + 0, + (LPTSTR)&lpLastError, + MESSAGE_LENGTH, + NULL); + + strcpy(lpMsgBuf, lpMessage); + strcat(lpMsgBuf, "\nThe WWS (Worthless Windows System) reports:\n"); + strcat(lpMsgBuf, lpLastError); + + // Display the string. + ::MessageBox(NULL, lpMsgBuf, "JSConsole Error", MB_OK | MB_ICONSTOP); +} + +#if defined(_DEBUG) + #define VERIFY(value, errorCondition, message) \ + if((value) == (errorCondition)) DisplayError(message); +#else // !_DEBUG + #define VERIFY(value, errorCondition, message) (value) +#endif // _DEBUG + +// +// Register the window class +// +BOOL JSConsole::RegisterWidget() +{ + WNDCLASS wc; + + wc.style = 0; + wc.lpfnWndProc = JSConsole::WindowProc; + wc.cbClsExtra = 0; + wc.cbWndExtra = 0; + wc.hInstance = JSConsole::sAppInstance; + wc.hIcon = NULL; + wc.hCursor = NULL; + wc.hbrBackground = (HBRUSH)(COLOR_WINDOW); + wc.lpszMenuName = MAKEINTRESOURCE(JSCONSOLE_MENU); + wc.lpszClassName = "JavaScript Console"; + + return (BOOL)::RegisterClass(&wc); +} + +// +// Create the main application window +// +JSConsole* JSConsole::CreateConsole() +{ + if (!JSConsole::mRegistered){ + JSConsole::mRegistered = RegisterWidget(); + } + + HWND hWnd = ::CreateWindowEx(WS_EX_ACCEPTFILES | + WS_EX_CLIENTEDGE | + WS_EX_CONTROLPARENT, + "JavaScript Console", + JSConsole::sDefaultCaption, + WS_OVERLAPPEDWINDOW, + CW_USEDEFAULT, + CW_USEDEFAULT, + 450, + 500, + NULL, + NULL, + JSConsole::sAppInstance, + NULL); + if (hWnd) { + ::ShowWindow(hWnd, SW_SHOW); + ::UpdateWindow(hWnd); + + JSConsole *console = (JSConsole*)::GetWindowLong(hWnd, GWL_USERDATA); + return console; + } + + return NULL; +} + +// +// Window Procedure +// +LRESULT CALLBACK JSConsole::WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + JSConsole *console = (JSConsole*)::GetWindowLong(hWnd, GWL_USERDATA); + + // just ignore the message unless is WM_NCCREATE + if (!console) { + if (uMsg == WM_NCCREATE) { + HWND hWndEdit = ::CreateWindow("EDIT", + NULL, + WS_CHILDWINDOW | WS_VISIBLE | ES_MULTILINE | + ES_AUTOHSCROLL | ES_AUTOVSCROLL | + WS_HSCROLL | WS_VSCROLL, + 0, 0, 0, 0, + hWnd, + NULL, + JSConsole::sAppInstance, + NULL); + if (!hWndEdit) { + ::DisplayError("Cannot Create Edit Window"); + return FALSE; + } + ::SendMessage(hWndEdit, EM_SETLIMITTEXT, (WPARAM)0, (LPARAM)0); + + console = new JSConsole(hWnd, hWndEdit); + ::SetWindowLong(hWnd, GWL_USERDATA, (DWORD)console); + + ::SetFocus(hWndEdit); + } + +#if defined(STRICT) + return ::CallWindowProc((WNDPROC)::DefWindowProc, hWnd, uMsg, + wParam, lParam); +#else + return ::CallWindowProc((FARPROC)::DefWindowProc, hWnd, uMsg, + wParam, lParam); +#endif /* STRICT */ + } + + switch(uMsg) { + + // make sure the edit window covers the whole client area + case WM_SIZE: + return console->OnSize(wParam, (UINT)LOWORD(lParam), (UINT)HIWORD(lParam)); + + // exit the application + case WM_DESTROY: + console->OnDestroy(); + +#if defined(STRICT) + return ::CallWindowProc((WNDPROC)::DefWindowProc, hWnd, uMsg, + wParam, lParam); +#else + return ::CallWindowProc((FARPROC)::DefWindowProc, hWnd, uMsg, + wParam, lParam); +#endif /* STRICT */ + + // enable/disable menu items + case WM_INITMENUPOPUP: + return console->OnInitMenu((HMENU)wParam, (UINT)LOWORD(lParam), (BOOL)HIWORD(lParam)); + + case WM_COMMAND: + // menu or accelerator + if (HIWORD(wParam) == 0 || HIWORD(wParam) == 1) { + switch(LOWORD(wParam)) { + + case ID_FILENEW: + console->OnFileNew(); + break; + + case ID_FILEOPEN: + if (console->OpenFileDialog(OPEN_DIALOG)) { + console->LoadFile(); + } + + break; + + case ID_FILESAVE: + if (console->CanSave()) { + console->SaveFile(); + break; + } + // fall through so it can "Save As..." + + case ID_FILESAVEAS: + if (console->OpenFileDialog(SAVE_DIALOG)) { + console->SaveFile(); + } + break; + + case ID_FILEEXIT: + ::DestroyWindow(hWnd); + break; + + case ID_EDITUNDO: + console->OnEditUndo(); + break; + + case ID_EDITCUT: + console->OnEditCut(); + break; + + case ID_EDITCOPY: + console->OnEditCopy(); + break; + + case ID_EDITPASTE: + console->OnEditPaste(); + break; + + case ID_EDITDELETE: + console->OnEditDelete(); + break; + + case ID_EDITSELECTALL: + console->OnEditSelectAll(); + break; + + case ID_COMMANDSEVALALL: + console->OnCommandEvaluateAll(); + break; + + case ID_COMMANDSEVALSEL: + console->OnCommandEvaluateSelection(); + break; + + case ID_COMMANDSINSPECTOR: + console->OnCommandInspector(); + break; + + } + } + + break; + + case WM_DROPFILES: + { + HDROP hDropInfo = (HDROP)wParam; + if (::DragQueryFile(hDropInfo, (UINT)-1L, NULL, 0) != 1) { + ::MessageBox(hWnd, "Just One File Please...", "JSConsole Error", MB_OK | MB_ICONINFORMATION); + } + else { + CHAR fileName[MAX_PATH]; + ::DragQueryFile(hDropInfo, 0, fileName, MAX_PATH); + console->SetFileName(fileName); + console->LoadFile(); + } + break; + } + + case WM_SETFOCUS: + return console->OnSetFocus((HWND)wParam); + + default: +#if defined(STRICT) + return ::CallWindowProc((WNDPROC)::DefWindowProc, hWnd, uMsg, + wParam, lParam); +#else + return ::CallWindowProc((FARPROC)::DefWindowProc, hWnd, uMsg, + wParam, lParam); +#endif /* STRICT */ + } + + return 0; +} + +// +// Constructor +// The main window and the edit control must have been created already +// +JSConsole::JSConsole(HWND aMainWindow, HWND aEditControl) : + mMainWindow(aMainWindow), + mEditWindow(aEditControl), + mContext(NULL) +{ + mFileInfo.Init(); +} + +// +// Destructor +// +JSConsole::~JSConsole() +{ +} + +// +// Load a file into the edit field +// +BOOL JSConsole::LoadFile() +{ + BOOL result = FALSE; + + if (mMainWindow) { + // open the file + HANDLE file = ::CreateFile(mFileInfo.mCurrentFileName, + GENERIC_READ, + FILE_SHARE_READ, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, + NULL); + if (file != INVALID_HANDLE_VALUE) { + // check the file size. Max is 64k + DWORD sizeHiWord; + DWORD sizeLoWord = ::GetFileSize(file, &sizeHiWord); + if (sizeLoWord < 0x10000 && sizeHiWord == 0) { + // alloc a buffer big enough to contain the file (account for '\0' + CHAR *buffer = new CHAR[sizeLoWord + 1]; + if (buffer) { + // read the file in memory + if (::ReadFile(file, + buffer, + sizeLoWord, + &sizeHiWord, + NULL)) { + NS_ASSERTION(sizeLoWord == sizeHiWord, "ReadFile inconsistency"); + buffer[sizeLoWord] = '\0'; // terminate the buffer + // write the file to the edit field + ::SendMessage(mEditWindow, WM_SETTEXT, (WPARAM)0, (LPARAM)buffer); + + // update the caption + CHAR caption[80]; + ::wsprintf(caption, + "%s - %s", + mFileInfo.mCurrentFileName + mFileInfo.mFileOffset, + sDefaultCaption); + ::SendMessage(mMainWindow, WM_SETTEXT, (WPARAM)0, (LPARAM)caption); + + result = TRUE; + } + else { + ::DisplayError("Error Reading the File"); + } + + // free the allocated buffer + delete[] buffer; + } + else { + ::MessageBox(mMainWindow, + "Cannot Allocate Enough Memory to Copy the File in Memory", + "JSConsole Error", + MB_OK | MB_ICONSTOP); + } + } + else { + ::MessageBox(mMainWindow, + "File too big. Max is 64k", + "JSConsole Error", + MB_OK | MB_ICONSTOP); + } + + // close the file handle + ::CloseHandle(file); + } +#ifdef _DEBUG + else { + CHAR message[MAX_PATH + 20]; + wsprintf(message, "Cannot Open File: %s", mFileInfo.mCurrentFileName); + ::DisplayError(message); + } +#endif + } + + return result; +} + +// +// Save the current text into a file +// +BOOL JSConsole::SaveFile() +{ + BOOL result = FALSE; + + if (mMainWindow && mFileInfo.mCurrentFileName[0] != '\0') { + // create the new file + HANDLE file = ::CreateFile(mFileInfo.mCurrentFileName, + GENERIC_WRITE, + FILE_SHARE_READ, + NULL, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, + NULL); + if (file != INVALID_HANDLE_VALUE) { + DWORD size; + // get the text size + size = ::SendMessage(mEditWindow, WM_GETTEXTLENGTH, (WPARAM)0, (LPARAM)0); + + // alloc a buffer big enough to contain the file + CHAR *buffer = new CHAR[++size]; + if (buffer) { + DWORD byteRead; + // read the text area content + ::SendMessage(mEditWindow, WM_GETTEXT, (WPARAM)size, (LPARAM)buffer); + + // write the buffer to disk + if (::WriteFile(file, + buffer, + size, + &byteRead, + NULL)) { + NS_ASSERTION(byteRead == size, "WriteFile inconsistency"); + // update the caption + CHAR caption[80]; + ::wsprintf(caption, + "%s - %s", + mFileInfo.mCurrentFileName + mFileInfo.mFileOffset, + sDefaultCaption); + ::SendMessage(mMainWindow, WM_SETTEXT, (WPARAM)0, (LPARAM)caption); + + result = TRUE; + } + else { + ::DisplayError("Error Writing the File"); + } + + // free the allocated buffer + delete[] buffer; + } + else { + ::MessageBox(mMainWindow, + "Cannot Allocate Enough Memory to Copy the Edit Text in Memory", + "JSConsole Error", + MB_OK | MB_ICONSTOP); + } + + // close the file handle + ::CloseHandle(file); + } +#ifdef _DEBUG + else { + CHAR message[MAX_PATH + 20]; + wsprintf(message, "Cannot Open File: %s", mFileInfo.mCurrentFileName); + ::DisplayError(message); + } +#endif + } + + return result; +} + +// +// Open a FileOpen or FileSave dialog +// +BOOL JSConsole::OpenFileDialog(UINT aWhichDialog) +{ + BOOL result = FALSE; + OPENFILENAME ofn; + + if (mMainWindow) { + + // *.js is the standard File Name on the Save/Open Dialog + if (mFileInfo.mCurrentFileName[0] == '\0') + ::strcpy(mFileInfo.mCurrentFileName, "*.js"); + + // fill the OPENFILENAME sruct + ofn.lStructSize = sizeof(OPENFILENAME); + ofn.hwndOwner = mMainWindow; + ofn.hInstance = JSConsole::sAppInstance; + ofn.lpstrFilter = "JavaScript Files (*.js)\0*.js\0Text Files (*.txt)\0*.txt\0All Files\0*.*\0\0"; + ofn.lpstrCustomFilter = NULL; + ofn.nMaxCustFilter = 0; + ofn.nFilterIndex = 1; // the first one in lpstrFilter + ofn.lpstrFile = mFileInfo.mCurrentFileName; // contains the file path name on return + ofn.nMaxFile = sizeof(mFileInfo.mCurrentFileName); + ofn.lpstrFileTitle = NULL; + ofn.nMaxFileTitle = 0; + ofn.lpstrInitialDir = NULL; // use default + ofn.lpstrTitle = NULL; // use default + ofn.Flags = OFN_CREATEPROMPT | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST; + ofn.nFileOffset = 0; + ofn.nFileExtension = 0; + ofn.lpstrDefExt = "js"; // default extension is .js + ofn.lCustData = NULL; + ofn.lpfnHook = NULL; + ofn.lpTemplateName = NULL; + + // call the open file dialog or the save file dialog according to aIsOpenDialog + if (aWhichDialog == OPEN_DIALOG) { + result = ::GetOpenFileName(&ofn); + } + else if (aWhichDialog == SAVE_DIALOG) { + result = ::GetSaveFileName(&ofn); + } + + if (!result) { + mFileInfo.mCurrentFileName[0] = '\0'; + ::CommDlgExtendedError(); + } + else { + mFileInfo.mFileOffset = ofn.nFileOffset; + mFileInfo.mFileExtension = ofn.nFileExtension; + } + } + + return result; +} + +// +// set the mFileInfo structure with the proper value given a generic path +// +void JSConsole::SetFileName(LPSTR aFileName) +{ + strcpy(mFileInfo.mCurrentFileName, aFileName); + for (int i = strlen(aFileName); i >= 0; i--) { + if (mFileInfo.mCurrentFileName[i] == '.') { + mFileInfo.mFileExtension = i; + } + + if (mFileInfo.mCurrentFileName[i] == '\\') { + mFileInfo.mFileOffset = i + 1; + break; + } + } +} + +// +// Move the edit window to cover the all client area +// +LRESULT JSConsole::OnSize(DWORD aResizeFlags, UINT aWidth, UINT aHeight) +{ + ::MoveWindow(mEditWindow, 0, 0, aWidth, aHeight, TRUE); + RECT textArea; + textArea.left = 3; + textArea.top = 1; + textArea.right = aWidth - 20; + textArea.bottom = aHeight - 17; + ::SendMessage(mEditWindow, EM_SETRECTNP, (WPARAM)0, (LPARAM)&textArea); + return 0L; +} + +// +// Initialize properly menu items +// +LRESULT JSConsole::OnInitMenu(HMENU aMenu, UINT aPos, BOOL aIsSystem) +{ + if (!aIsSystem) { + if (aPos == EDITMENUPOS) { + InitEditMenu(aMenu); + } + else if (aPos == COMMANDSMENUPOS) { + InitCommandMenu(aMenu); + } + } + + return 0L; +} + +// +// Pass the focus to the edit window +// +LRESULT JSConsole::OnSetFocus(HWND aWnd) +{ + ::SetFocus(mEditWindow); + return 0L; +} + +// +// Destroy message +// +void JSConsole::OnDestroy() +{ + if (mDestroyNotification) + (*mDestroyNotification)(); +} + +// +// File/New. Reset caption, text area and file info +// +void JSConsole::OnFileNew() +{ + SendMessage(mEditWindow, WM_SETTEXT, (WPARAM)0, (LPARAM)0); + SendMessage(mMainWindow, WM_SETTEXT, (WPARAM)0, (LPARAM)JSConsole::sDefaultCaption); + mFileInfo.Init(); +} + +// +// Edit/Undo. Undo the last operation on the edit field +// +void JSConsole::OnEditUndo() +{ + SendMessage(mEditWindow, WM_UNDO, (WPARAM)0, (LPARAM)0); +} + +// +// Edit/Cut. Cut the current selection +// +void JSConsole::OnEditCut() +{ + SendMessage(mEditWindow, WM_CUT, (WPARAM)0, (LPARAM)0); +} + +// +// Edit/Copy. Copy the current selection +// +void JSConsole::OnEditCopy() +{ + SendMessage(mEditWindow, WM_COPY, (WPARAM)0, (LPARAM)0); +} + +// +// Edit/Paste. Paste from the clipboard +// +void JSConsole::OnEditPaste() +{ + SendMessage(mEditWindow, WM_PASTE, (WPARAM)0, (LPARAM)0); +} + +// +// Edit/Delete. Delete the current selection +// +void JSConsole::OnEditDelete() +{ + SendMessage(mEditWindow, WM_CLEAR, (WPARAM)0, (LPARAM)0); +} + +// +// Edit/Select All. Select the whole text in the text area +// +void JSConsole::OnEditSelectAll() +{ + SendMessage(mEditWindow, EM_SETSEL, (WPARAM)0, (LPARAM)-1); +} + +// +// Command/Evaluate All. Take the text area content and evaluate in the js context +// +void JSConsole::OnCommandEvaluateAll() +{ + EvaluateText(0, (UINT)-1); +} + +// +// Command/Evaluate Selection. Take the current text area selection and evaluate in the js context +// +void JSConsole::OnCommandEvaluateSelection() +{ + // + // get the selection and evaluate it + // + DWORD startSel, endSel; + + // get selection range + ::SendMessage(mEditWindow, EM_GETSEL, (WPARAM)&startSel, (LPARAM)&endSel); + + EvaluateText(startSel, endSel); +} + +// +// Command/Inspector. Run the js inspector on the global object +// +void JSConsole::OnCommandInspector() +{ + ::MessageBox(mMainWindow, "Inspector not yet available", "JSConsole Error", MB_OK | MB_ICONINFORMATION); +} + +// +// Help +// +void JSConsole::OnHelp() +{ +} + +// +// private method. Deal with the "Edit" menu +// +void JSConsole::InitEditMenu(HMENU aMenu) +{ + CHAR someText[2] = {'\0', '\0'}; // some buffer + + // set flags to "disable" + UINT undoFlags = MF_BYPOSITION | MF_DISABLED | MF_GRAYED; + UINT cutFlags = MF_BYPOSITION | MF_DISABLED | MF_GRAYED; + UINT copyFlags = MF_BYPOSITION | MF_DISABLED | MF_GRAYED; + UINT pasteFlags = MF_BYPOSITION | MF_DISABLED | MF_GRAYED; + UINT deleteFlags = MF_BYPOSITION | MF_DISABLED | MF_GRAYED; + UINT selectAllFlags = MF_BYPOSITION | MF_DISABLED | MF_GRAYED; + + // check if the edit area has any text + SendMessage(mEditWindow, WM_GETTEXT, (WPARAM)2, (LPARAM)someText); + if (someText[0] != '\0') { + // enable the "Select All" + selectAllFlags = MF_BYPOSITION | MF_ENABLED; + + // enable "Copy/Cut/Paste" if there is any selection + UINT startPos, endPos; + SendMessage(mEditWindow, EM_GETSEL, (WPARAM)&startPos, (LPARAM)&endPos); + if (startPos != endPos) { + cutFlags = MF_BYPOSITION | MF_ENABLED; + copyFlags = MF_BYPOSITION | MF_ENABLED; + deleteFlags = MF_BYPOSITION | MF_ENABLED; + } + } + + // undo is available if the edit control says so + if (SendMessage(mEditWindow, EM_CANUNDO, (WPARAM)0, (LPARAM)0)) { + undoFlags = MF_BYPOSITION | MF_ENABLED; + } + + // check whether or not the clipboard contains text data + if (IsClipboardFormatAvailable(CF_TEXT)) { + pasteFlags = MF_BYPOSITION | MF_ENABLED; + } + + // do enable/disable + VERIFY(EnableMenuItem(aMenu, + ID_EDITUNDO - ID_EDITMENU - 1, + undoFlags), + -1L, + "Disable/Enable \"Undo\" Failed"); + VERIFY(EnableMenuItem(aMenu, + ID_EDITCUT - ID_EDITMENU - 1, + cutFlags), + -1L, + "Disable/Enable \"Cut\" Failed"); + VERIFY(EnableMenuItem(aMenu, + ID_EDITCOPY - ID_EDITMENU - 1, + copyFlags), + -1L, + "Disable/Enable \"Copy\" Failed"); + VERIFY(EnableMenuItem(aMenu, + ID_EDITPASTE - ID_EDITMENU - 1, + pasteFlags), + -1L, + "Disable/Enable \"Paste\" Failed"); + VERIFY(EnableMenuItem(aMenu, + ID_EDITDELETE - ID_EDITMENU - 1, + deleteFlags), + -1L, + "Disable/Enable \"Delete\" Failed"); + VERIFY(EnableMenuItem(aMenu, + ID_EDITSELECTALL - ID_EDITMENU - 1, + selectAllFlags), + -1L, + "Disable/Enable \"Select All\" Failed"); +} + +// +// private method. Deal with the "Command" menu +// +void JSConsole::InitCommandMenu(HMENU aMenu) +{ + CHAR someText[2] = {'\0', '\0'}; // some buffer + + // set flags to "disable" + UINT evaluateAllFlags = MF_BYPOSITION | MF_DISABLED | MF_GRAYED; + UINT evaluateSelectionFlags = MF_BYPOSITION | MF_DISABLED | MF_GRAYED; + + // check if the edit area has any text + SendMessage(mEditWindow, WM_GETTEXT, (WPARAM)2, (LPARAM)someText); + if (someText[0] != 0) { + // if there is some text enable "Evaluate All" + evaluateAllFlags = MF_BYPOSITION | MF_ENABLED; + + // enable "Evaluate Selection" if there is any selection + UINT startPos, endPos; + SendMessage(mEditWindow, EM_GETSEL, (WPARAM)&startPos, (LPARAM)&endPos); + if (startPos != endPos) { + evaluateSelectionFlags = MF_BYPOSITION | MF_ENABLED; + } + } + + // disable/enable commands + VERIFY(EnableMenuItem(aMenu, + ID_COMMANDSEVALALL - ID_COMMANDSMENU - 1, + evaluateAllFlags), + -1L, + "Disable/Enable \"Evaluate All\" Failed"); + VERIFY(EnableMenuItem(aMenu, + ID_COMMANDSEVALSEL - ID_COMMANDSMENU - 1, + evaluateSelectionFlags), + -1L, + "Disable/Enable \"Evaluate Selection\" Failed"); +} + +// +// normailize a buffer of char coming from a text area. +// Basically get rid of the 0x0D char +// +LPSTR NormalizeBuffer(LPSTR aBuffer) +{ + // trim all the 0x0D at the beginning (should be 1 at most, but hey...) + while (*aBuffer == 0x0D) { + aBuffer++; + } + + LPSTR readPointer = aBuffer; + LPSTR writePointer = aBuffer; + + do { + // compact the buffer if needed + *writePointer = *readPointer; + + // skip the 0x0D + if (*readPointer != 0x0D) { + writePointer++; + } + + } while (*readPointer++ != '\0'); + + return aBuffer; +} + +LPSTR PrepareForTextArea(LPSTR aBuffer, PRInt32 aSize) +{ + PRInt32 count = 0; + LPSTR newBuffer = aBuffer; + LPSTR readPointer = aBuffer; + + // count the '\n' + while (*readPointer != '\0' && (*readPointer++ != '\n' || ++count)); + + if (0 != count) { + readPointer = aBuffer; + newBuffer = new CHAR[aSize + count + 1]; + LPSTR writePointer = newBuffer; + while (*readPointer != '\0') { + if (*readPointer == '\n') { + *writePointer++ = 0x0D; + } + *writePointer++ = *readPointer++; + } + *writePointer = '\0'; + } + + return newBuffer; +} + +// +// Evaluate the text enclosed between startSel and endSel +// +void JSConsole::EvaluateText(UINT aStartSel, UINT aEndSel) +{ + if (mContext) { + // get the text size + UINT size = ::SendMessage(mEditWindow, WM_GETTEXTLENGTH, (WPARAM)0, (LPARAM)0); + + // alloc a buffer big enough to contain the file + CHAR *buffer = new CHAR[++size]; + if (buffer) { + + // get the whole text + ::SendMessage(mEditWindow, WM_GETTEXT, (WPARAM)size, (LPARAM)buffer); + + // get the portion of the text to be evaluated + if (aEndSel != (UINT)-1) { + size = aEndSel - aStartSel; + strncpy(buffer, buffer + aStartSel, size); + buffer[size] = '\0'; + } + else { + aEndSel = size; + } + + + // change the 0x0D0x0A couple in 0x0A ('\n') + // no new buffer allocation, the pointer may be in the middle + // of the old buffer though, so keep buffer to call delete + LPSTR cleanBuffer = ::NormalizeBuffer(buffer); + + // evaluate the string + jsval returnValue; + if (mContext->EvaluateString(cleanBuffer, + strlen(cleanBuffer), + nsnull, + 0, + &returnValue)) { + // output the result on the console and on the edit area + CHAR result[128]; + LPSTR res = result; + int bDelete = 0; + + JSContext *cx = (JSContext *)mContext->GetNativeContext(); + JSString *jsstring = JS_ValueToString(cx, returnValue); + char *str = JS_GetStringBytes(jsstring); + + ::printf("The return value is "); + if (JSVAL_IS_OBJECT(returnValue)) { + ::printf("an object\n"); + } + else if (JSVAL_IS_INT(returnValue)) { + ::printf("an int [%d]\n", JSVAL_TO_INT(returnValue)); + } + else if (JSVAL_IS_DOUBLE(returnValue)) { + ::printf("a double [%f]\n", *JSVAL_TO_DOUBLE(returnValue)); + } + else if (JSVAL_IS_STRING(returnValue)) { + ::printf("a string [%s]\n", JS_GetStringBytes(JSVAL_TO_STRING(returnValue))); + } + else if (JSVAL_IS_BOOLEAN(returnValue)) { + ::printf("a boolean [%d]\n", JSVAL_TO_BOOLEAN(returnValue)); + } + else if (JSVAL_IS_NULL(returnValue)) { + printf("null\n"); + } + else if (JSVAL_IS_VOID(returnValue)) { + printf("void\n"); + } + else { + printf("error: unknow return type!\n"); + } + + // make a string with 0xA changed to 0xD0xA + res = PrepareForTextArea(str, JS_GetStringLength(jsstring)); + if (res != str) { + bDelete = 1; // if the buffer was new'ed + } + + // set the position at the end of the selection + ::SendMessage(mEditWindow, EM_SETSEL, (WPARAM)aEndSel, (LPARAM)aEndSel); + // write the result + ::SendMessage(mEditWindow, EM_REPLACESEL, (WPARAM)TRUE, (LPARAM)res); + // highlight the result + ::SendMessage(mEditWindow, EM_SETSEL, (WPARAM)aEndSel - 1, (LPARAM)(aEndSel + strlen(res))); + + // deal with the "big string" case + if (bDelete > 0) { + delete[] res; + } + + // clean up a bit + JS_GC((JSContext *)mContext->GetNativeContext()); + } + else { + ::MessageBox(mMainWindow, + "Error evaluating the Script", + "JSConsole Error", + MB_OK | MB_ICONERROR); + } + + delete[] buffer; + } + else { + ::MessageBox(mMainWindow, + "Not Enough Memory to Allocate a Buffer to Evaluate the Script", + "JSConsole Error", + MB_OK | MB_ICONSTOP); + } + } + else { + ::MessageBox(mMainWindow, + "Java Script Context not initialized", + "JSConsole Error", + MB_OK | MB_ICONSTOP); + } +} + + diff --git a/xpfe/xpviewer/src/JSConsole.h b/xpfe/xpviewer/src/JSConsole.h new file mode 100644 index 000000000000..21e8d29a554c --- /dev/null +++ b/xpfe/xpviewer/src/JSConsole.h @@ -0,0 +1,106 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#ifndef jsconsole_h__ +#define jsconsole_h__ + +#include + +class nsIScriptContext; + +#define OPEN_DIALOG 0 +#define SAVE_DIALOG 1 + +typedef void (*DESTROY_NOTIFICATION) (); + +class JSConsole { + +private: + HWND mMainWindow; + HWND mEditWindow; + + DESTROY_NOTIFICATION mDestroyNotification; + + // keep info from the OPENFILENAME struct + struct FileInfo { + CHAR mCurrentFileName[MAX_PATH]; + WORD mFileOffset; + WORD mFileExtension; + + void Init() {mCurrentFileName[0] = '\0'; mFileOffset = 0; mFileExtension = 0;} + } mFileInfo; + + // one context per window + nsIScriptContext *mContext; + +public: + static HINSTANCE sAppInstance; + static HACCEL sAccelTable; + static CHAR sDefaultCaption[]; + + static BOOL RegisterWidget(); + static JSConsole* CreateConsole(); + static LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); + +private: + static BOOL mRegistered; + +public: + JSConsole(HWND aMainWindow, HWND aEditControl); + ~JSConsole(); + + BOOL LoadFile(); + BOOL SaveFile(); + + BOOL OpenFileDialog(UINT aOpenOrSave); + inline BOOL CanSave() { return mFileInfo.mCurrentFileName[0] != '\0'; } + void SetFileName(LPSTR aFileName); + + HWND GetMainWindow() { return mMainWindow; } + void SetNotification(DESTROY_NOTIFICATION aNotification) { mDestroyNotification = aNotification; } + void SetContext(nsIScriptContext *aContext) { mContext = aContext; } + + void EvaluateText(UINT aStartSel, UINT aEndSel); + + // windows messages + LRESULT OnSize(DWORD aResizeFlags, UINT aWidth, UINT aHeight); + LRESULT OnInitMenu(HMENU aMenu, UINT aPos, BOOL aIsSystem); + LRESULT OnSetFocus(HWND aWnd); + + void OnDestroy(); + + // menu items + void OnFileNew(); + void OnEditUndo(); + void OnEditCut(); + void OnEditCopy(); + void OnEditPaste(); + void OnEditDelete(); + void OnEditSelectAll(); + void OnCommandEvaluateAll(); + void OnCommandEvaluateSelection(); + void OnCommandInspector(); + void OnHelp(); + +private: + void InitEditMenu(HMENU aMenu); + void InitCommandMenu(HMENU aMenu); +}; + +#endif // jsconsole_h__ + diff --git a/xpfe/xpviewer/src/jsconsres.h b/xpfe/xpviewer/src/jsconsres.h new file mode 100644 index 000000000000..ba69fac35386 --- /dev/null +++ b/xpfe/xpviewer/src/jsconsres.h @@ -0,0 +1,67 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#ifndef jsconsres_h___ +#define jsconsres_h___ + + +// Main menu id +#define JSCONSOLE_MENU 20100 + +#define FILEMENUPOS 0 +#define ID_FILEMENU 20200 +// File menu items ids +#define ID_FILENEW 20201 +#define ID_FILEOPEN 20202 +#define ID_FILESAVE 20203 +#define ID_FILESAVEAS 20204 +// separator +#define ID_FILEEXIT 20206 + +#define EDITMENUPOS 1 +#define ID_EDITMENU 20300 +// Edit menu items ids +#define ID_EDITUNDO 20301 +// separator +#define ID_EDITCUT 20303 +#define ID_EDITCOPY 20304 +#define ID_EDITPASTE 20305 +#define ID_EDITDELETE 20306 +// separator +#define ID_EDITSELECTALL 20308 + +#define COMMANDSMENUPOS 2 +#define ID_COMMANDSMENU 20400 +// Commands menu items ids +#define ID_COMMANDSEVALALL 20401 +#define ID_COMMANDSEVALSEL 20402 +// separator +#define ID_COMMANDSINSPECTOR 20404 + +#define HELPMENUPOS 3 +#define ID_HELPMENU 20500 +// Help menu items +#define ID_NOHELP 20501 + +// +// Accelerators table ids +// +#define ACCELERATOR_TABLE 1000 + +#endif // jsconsres_h___ + diff --git a/xpfe/xpviewer/src/makefile.win b/xpfe/xpviewer/src/makefile.win new file mode 100644 index 000000000000..65a1885aa963 --- /dev/null +++ b/xpfe/xpviewer/src/makefile.win @@ -0,0 +1,215 @@ +#!nmake +# +# The contents of this file are subject to the Netscape Public License +# Version 1.0 (the "NPL"); you may not use this file except in +# compliance with the NPL. You may obtain a copy of the NPL at +# http://www.mozilla.org/NPL/ +# +# Software distributed under the NPL is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL +# for the specific language governing rights and limitations under the +# NPL. +# +# The Initial Developer of this code under the NPL is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All Rights +# Reserved. + +DEPTH=..\..\.. +IGNORE_MANIFEST=1 + +MAKE_OBJ_TYPE = EXE +PROGRAM = .\$(OBJDIR)\xpviewer.exe +RESFILE = xpviewer.res + +MISCDEP= \ + $(DIST)\lib\raptorweb.lib \ + $(DIST)\lib\xpcom32.lib \ + $(LIBNSPR) \ + $(DIST)\lib\libplc21.lib + + +OBJS = \ + .\$(OBJDIR)\nsBrowserWindow.obj \ + .\$(OBJDIR)\nsSetupRegistry.obj \ + .\$(OBJDIR)\nsViewerApp.obj \ + .\$(OBJDIR)\nsBrowserMain.obj \ + .\$(OBJDIR)\JSConsole.obj \ + $(NULL) + +LINCS= \ + -I$(PUBLIC)\raptor \ + -I$(PUBLIC)\xpcom \ + -I$(PUBLIC)\dom \ + -I$(PUBLIC)\js \ + -I$(PUBLIC)\netlib \ + -I$(PUBLIC)\java \ + -I$(PUBLIC)\plugin \ + -I$(PUBLIC)\pref + +MYLIBS= \ + $(DIST)\lib\raptorbase.lib \ + $(DIST)\lib\raptorgfxwin.lib \ + $(DIST)\lib\raptorhtml.lib \ + $(DIST)\lib\raptorweb.lib \ + $(DIST)\lib\raptorwidget.lib \ + $(DIST)\lib\raptorhtmlpars.lib \ + $(DIST)\lib\xpcom32.lib \ + $(DIST)\lib\js32$(VERSION_NUMBER).lib \ + $(LIBNSPR) \ + $(DIST)\lib\libplc21.lib \ + $(DIST)\lib\netlib.lib \ + $(DIST)\lib\jsdom.lib \ + comdlg32.lib \ + $(NULL) + +LLIBS= $(MYLIBS) \ + shell32.lib \ + -SUBSYSTEM:CONSOLE + +include <$(DEPTH)\config\rules.mak> + +!ifdef MOZ_NO_DEBUG_RTL +OS_CFLAGS = $(OS_CFLAGS) -DMOZ_NO_DEBUG_RTL +!endif + +install:: $(PROGRAM) + $(MAKE_INSTALL) $(PROGRAM) $(DIST)\bin + $(MAKE_INSTALL) resources\throbber\LargeAnimation00.gif $(DIST)\bin\res\throbber + $(MAKE_INSTALL) resources\throbber\LargeAnimation01.gif $(DIST)\bin\res\throbber + $(MAKE_INSTALL) resources\throbber\LargeAnimation02.gif $(DIST)\bin\res\throbber + $(MAKE_INSTALL) resources\throbber\LargeAnimation03.gif $(DIST)\bin\res\throbber + $(MAKE_INSTALL) resources\throbber\LargeAnimation04.gif $(DIST)\bin\res\throbber + $(MAKE_INSTALL) resources\throbber\LargeAnimation05.gif $(DIST)\bin\res\throbber + $(MAKE_INSTALL) resources\throbber\LargeAnimation06.gif $(DIST)\bin\res\throbber + $(MAKE_INSTALL) resources\throbber\LargeAnimation07.gif $(DIST)\bin\res\throbber + $(MAKE_INSTALL) resources\throbber\LargeAnimation08.gif $(DIST)\bin\res\throbber + $(MAKE_INSTALL) resources\throbber\LargeAnimation09.gif $(DIST)\bin\res\throbber + $(MAKE_INSTALL) resources\throbber\LargeAnimation10.gif $(DIST)\bin\res\throbber + $(MAKE_INSTALL) resources\throbber\LargeAnimation11.gif $(DIST)\bin\res\throbber + $(MAKE_INSTALL) resources\throbber\LargeAnimation12.gif $(DIST)\bin\res\throbber + $(MAKE_INSTALL) resources\throbber\LargeAnimation13.gif $(DIST)\bin\res\throbber + $(MAKE_INSTALL) resources\throbber\LargeAnimation14.gif $(DIST)\bin\res\throbber + $(MAKE_INSTALL) resources\throbber\LargeAnimation15.gif $(DIST)\bin\res\throbber + $(MAKE_INSTALL) resources\throbber\LargeAnimation16.gif $(DIST)\bin\res\throbber + $(MAKE_INSTALL) resources\throbber\LargeAnimation17.gif $(DIST)\bin\res\throbber + $(MAKE_INSTALL) resources\throbber\LargeAnimation18.gif $(DIST)\bin\res\throbber + $(MAKE_INSTALL) resources\throbber\LargeAnimation19.gif $(DIST)\bin\res\throbber + $(MAKE_INSTALL) resources\throbber\LargeAnimation20.gif $(DIST)\bin\res\throbber + $(MAKE_INSTALL) resources\throbber\LargeAnimation21.gif $(DIST)\bin\res\throbber + $(MAKE_INSTALL) resources\throbber\LargeAnimation22.gif $(DIST)\bin\res\throbber + $(MAKE_INSTALL) resources\throbber\LargeAnimation23.gif $(DIST)\bin\res\throbber + $(MAKE_INSTALL) resources\throbber\LargeAnimation24.gif $(DIST)\bin\res\throbber + $(MAKE_INSTALL) resources\throbber\LargeAnimation25.gif $(DIST)\bin\res\throbber + $(MAKE_INSTALL) resources\throbber\LargeAnimation26.gif $(DIST)\bin\res\throbber + $(MAKE_INSTALL) resources\throbber\LargeAnimation27.gif $(DIST)\bin\res\throbber + $(MAKE_INSTALL) resources\throbber\LargeAnimation28.gif $(DIST)\bin\res\throbber + $(MAKE_INSTALL) resources\throbber\LargeAnimation29.gif $(DIST)\bin\res\throbber + $(MAKE_INSTALL) resources\throbber\LargeAnimation30.gif $(DIST)\bin\res\throbber + $(MAKE_INSTALL) resources\throbber\LargeAnimation31.gif $(DIST)\bin\res\throbber + $(MAKE_INSTALL) resources\throbber\LargeAnimation32.gif $(DIST)\bin\res\throbber + $(MAKE_INSTALL) resources\throbber\LargeAnimation33.gif $(DIST)\bin\res\throbber + $(MAKE_INSTALL) resources\throbber\LargeAnimation34.gif $(DIST)\bin\res\throbber + $(MAKE_INSTALL) resources\throbber\LargeAnimation35.gif $(DIST)\bin\res\throbber + $(MAKE_INSTALL) resources\throbber\LargeAnimation36.gif $(DIST)\bin\res\throbber + $(MAKE_INSTALL) resources\throbber\LargeAnimation37.gif $(DIST)\bin\res\throbber + $(MAKE_INSTALL) resources\throbber\LargeAnimation38.gif $(DIST)\bin\res\throbber + + $(MAKE_INSTALL) resources\toolbar\DialogAddrIcon.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\DialogAddrIcon_mo.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\DialogCompIcon.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\DialogCompIcon_mo.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\DialogMailIcon.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\DialogMailIcon_mo.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\DialogNavIcon.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\DialogNavIcon_mo.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\TB_Back.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\TB_Back_dis.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\TB_Back_mo.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\TB_Bookmarks.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\TB_Bookmarks_mo.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\TB_Edit.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\TB_Forward.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\TB_Forward_dis.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\TB_Forward_mo.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\TB_Home.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\TB_Home_mo.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\TB_HTab.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\TB_HTab_mo.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\TB_LoadImages.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\TB_LoadImages.mo.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\TB_Location.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\TB_Location_mo.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\TB_MiniAddr.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\TB_MiniComp.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\TB_MiniMail.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\TB_MiniNav.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\TB_MiniTab.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\TB_MixSecurity.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\TB_MixSecurity.mo.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\TB_Netscape.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\TB_Netscape_mo.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\TB_PersonalIcon.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\TB_Places.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\TB_Places_mo.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\TB_Print.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\TB_Print_mo.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\TB_Reload.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\TB_Reload_mo.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\TB_Search.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\TB_Search_mo.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\TB_Secure.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\TB_Secure_mo.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\TB_Stop.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\TB_Stop.mo.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\TB_Stop_dis.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\TB_Stop_mo.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\TB_Tab.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\TB_TabSmall.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\TB_TabSmall_mo.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\TB_Tab_mo.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\TB_Unsecure.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\TB_Unsecure.mo.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\TB_WhatsRelated.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\TB_WhatsRelated_mo.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\StatusBar-insecure.gif $(DIST)\bin\res\toolbar + $(MAKE_INSTALL) resources\toolbar\StatusBar-secure.gif $(DIST)\bin\res\toolbar + + +clobber:: + rm -f $(DIST)\bin\xpviewer.exe + rm -f $(DIST)\bin\res\samples\test0.html + rm -f $(DIST)\bin\res\samples\test1.html + rm -f $(DIST)\bin\res\samples\test2.html + rm -f $(DIST)\bin\res\samples\test3.html + rm -f $(DIST)\bin\res\samples\test4.html + rm -f $(DIST)\bin\res\samples\test5.html + rm -f $(DIST)\bin\res\samples\test6.html + rm -f $(DIST)\bin\res\samples\test7.html + rm -f $(DIST)\bin\res\samples\test8.html + rm -f $(DIST)\bin\res\samples\test8siz.html + rm -f $(DIST)\bin\res\samples\test8sca.html + rm -f $(DIST)\bin\res\samples\test8tab.html + rm -f $(DIST)\bin\res\samples\test_ed.html + rm -f $(DIST)\bin\res\samples\test9.html + rm -f $(DIST)\bin\res\samples\test9a.html + rm -f $(DIST)\bin\res\samples\test9b.html + rm -f $(DIST)\bin\res\samples\raptor.jpg + rm -f $(DIST)\bin\res\samples\Anieyes.gif + rm -f $(DIST)\bin\res\samples\gear1.gif + rm -f $(DIST)\bin\res\samples\rock_gra.gif + rm -f $(DIST)\bin\res\samples\bg.jpg + rm -f $(DIST)\bin\res\throbber\anims00.gif + rm -f $(DIST)\bin\res\throbber\anims01.gif + rm -f $(DIST)\bin\res\throbber\anims02.gif + rm -f $(DIST)\bin\res\throbber\anims03.gif + rm -f $(DIST)\bin\res\throbber\anims04.gif + rm -f $(DIST)\bin\res\throbber\anims05.gif + rm -f $(DIST)\bin\res\throbber\anims06.gif + rm -f $(DIST)\bin\res\throbber\anims07.gif + rm -f $(DIST)\bin\res\throbber\anims08.gif + rm -f $(DIST)\bin\res\throbber\anims09.gif + rm -f $(DIST)\bin\res\throbber\anims10.gif + rm -f $(DIST)\bin\res\throbber\anims11.gif + rm -f $(DIST)\bin\res\throbber\anims12.gif + rm -f $(DIST)\bin\res\throbber\anims13.gif diff --git a/xpfe/xpviewer/src/nsBrowserMain.cpp b/xpfe/xpviewer/src/nsBrowserMain.cpp new file mode 100644 index 000000000000..673fbad171b4 --- /dev/null +++ b/xpfe/xpviewer/src/nsBrowserMain.cpp @@ -0,0 +1,118 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are Copyright (C) 1998 + * Netscape Communications Corporation. All Rights Reserved. + */ +#include +#include "nsViewerApp.h" +#include "nsBrowserWindow.h" +#include "nsITimer.h" +#include "JSConsole.h" +#include "plevent.h" + +JSConsole *gConsole; +HINSTANCE gInstance, gPrevInstance; +static nsITimer* gNetTimer; + +/*nsNativeViewerApp::nsNativeViewerApp() +{ +} + +nsNativeViewerApp::~nsNativeViewerApp() +{ +} + +int +nsNativeViewerApp::Run() +{ + OpenWindow(); + + // Process messages + MSG msg; + while (::GetMessage(&msg, NULL, 0, 0)) { + if (!JSConsole::sAccelTable || + !gConsole || + !gConsole->GetMainWindow() || + !TranslateAccelerator(gConsole->GetMainWindow(), + JSConsole::sAccelTable, &msg)) { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } + return msg.wParam; +} +*/ +//---------------------------------------------------------------------- + +/*nsNativeBrowserWindow::nsNativeBrowserWindow() +{ +} + +nsNativeBrowserWindow::~nsNativeBrowserWindow() +{ +} + +nsresult +nsBrowserWindow::CreateMenuBar(PRInt32 aWidth) +{ + HMENU menu = ::LoadMenu(gInstance, "Viewer"); + HWND hwnd = (HWND)mWindow->GetNativeData(NS_NATIVE_WIDGET); + ::SetMenu(hwnd, menu); + + + + return NS_OK; +} + +nsEventStatus +nsNativeBrowserWindow::DispatchMenuItem(PRInt32 aID) +{ + // Dispatch windows-only menu code goes here + + // Dispatch xp menu items + return nsBrowserWindow::DispatchMenuItem(aID); +}*/ + +//---------------------------------------------------------------------- + +int main(int argc, char **argv) +{ + PL_InitializeEventsLib(""); + nsViewerApp* app = new nsViewerApp(); + NS_ADDREF(app); + app->Initialize(argc, argv); + app->OpenWindow(); + app->Run(); + NS_RELEASE(app); + + return 0; +} + +int PASCAL +WinMain(HINSTANCE instance, HINSTANCE prevInstance, LPSTR cmdParam, + int nCmdShow) +{ + gInstance = instance; + gPrevInstance = prevInstance; + PL_InitializeEventsLib(""); + nsViewerApp* app = new nsViewerApp(); + app->Initialize(0, nsnull); + app->OpenWindow(); + + int result = app->Run(); + delete app; + return result; +} diff --git a/xpfe/xpviewer/src/nsBrowserWindow.cpp b/xpfe/xpviewer/src/nsBrowserWindow.cpp new file mode 100644 index 000000000000..581feb4404b3 --- /dev/null +++ b/xpfe/xpviewer/src/nsBrowserWindow.cpp @@ -0,0 +1,3571 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are Copyright (C) 1998 + * Netscape Communications Corporation. All Rights Reserved. + */ +#ifdef XP_MAC +#include "nsBrowserWindow.h" +#define NS_IMPL_IDS +#else +#define NS_IMPL_IDS +#include "nsBrowserWindow.h" +#endif +#include "nsIStreamListener.h" +#include "nsIAppShell.h" +#include "nsIWidget.h" +#include "nsITextWidget.h" +#include "nsIButton.h" +#include "nsILabel.h" +#include "nsIImageGroup.h" +#include "nsITimer.h" +#include "nsIThrobber.h" +#include "nsIDOMDocument.h" +#include "nsIURL.h" +#include "nsIFileWidget.h" +#include "nsILookAndFeel.h" +#include "nsRepository.h" +#include "nsIFactory.h" +#include "nsCRT.h" +#include "nsWidgetsCID.h" +#include "nsViewerApp.h" +#include "prprf.h" +#include "nsRepository.h" +#include "nsParserCIID.h" + +#include "nsIDocument.h" +#include "nsIPresContext.h" +#include "nsIDocumentViewer.h" +#include "nsIContentViewer.h" +#include "nsIPresShell.h" +#include "nsIDocument.h" +#include "nsXIFDTD.h" +#include "nsIParser.h" +#include "nsHTMLContentSinkStream.h" +#include "nsGUIEvent.h" +//#include "nsEditorMode.h" + +// Needed for "Find" GUI +#include "nsIDialog.h" +#include "nsICheckButton.h" +#include "nsIRadioButton.h" +#include "nsILabel.h" +#include "nsIMenuBar.h" + +// Menus +#include "nsIMenu.h" +#include "nsIMenuItem.h" +#include "nsWidgetSupport.h" +#include "nsIPopUpMenu.h" +#include "nsIMenuButton.h" + +// ImageButtons +#include "nsIImageButton.h" +#include "nsIToolbar.h" +#include "nsIToolbarManager.h" +#include "nsIToolbarItem.h" +#include "nsIToolbarItemHolder.h" + +#include "resources.h" + +#if defined(WIN32) +#include +#else +#if defined(XP_MAC) +#include "ostrstream.h" +#else +#include +#endif +#endif + +#if defined(WIN32) +#include +#endif + + +// XXX For font setting below +#include "nsFont.h" +#include "nsUnitConversion.h" +#include "nsIDeviceContext.h" + +// XXX greasy constants +//#define THROBBER_WIDTH 32 +//#define THROBBER_HEIGHT 32 +#define THROBBER_WIDTH 42 +#define THROBBER_HEIGHT 42 + +#define BUTTON_WIDTH 90 +#define BUTTON_HEIGHT THROBBER_HEIGHT + +#ifdef INSET_WEBSHELL +#define WEBSHELL_LEFT_INSET 5 +#define WEBSHELL_RIGHT_INSET 5 +#define WEBSHELL_TOP_INSET 5 +#define WEBSHELL_BOTTOM_INSET 5 +#else +#define WEBSHELL_LEFT_INSET 0 +#define WEBSHELL_RIGHT_INSET 0 +#define WEBSHELL_TOP_INSET 0 +#define WEBSHELL_BOTTOM_INSET 0 +#endif + +static NS_DEFINE_IID(kLookAndFeelCID, NS_LOOKANDFEEL_CID); +static NS_DEFINE_IID(kBrowserWindowCID, NS_BROWSER_WINDOW_CID); +static NS_DEFINE_IID(kButtonCID, NS_BUTTON_CID); +static NS_DEFINE_IID(kFileWidgetCID, NS_FILEWIDGET_CID); +static NS_DEFINE_IID(kTextFieldCID, NS_TEXTFIELD_CID); +static NS_DEFINE_IID(kThrobberCID, NS_THROBBER_CID); +static NS_DEFINE_IID(kWebShellCID, NS_WEB_SHELL_CID); +static NS_DEFINE_IID(kWindowCID, NS_WINDOW_CID); +static NS_DEFINE_IID(kDialogCID, NS_DIALOG_CID); +static NS_DEFINE_IID(kCheckButtonCID, NS_CHECKBUTTON_CID); +static NS_DEFINE_IID(kRadioButtonCID, NS_RADIOBUTTON_CID); +static NS_DEFINE_IID(kLabelCID, NS_LABEL_CID); +static NS_DEFINE_IID(kMenuBarCID, NS_MENUBAR_CID); +static NS_DEFINE_IID(kMenuCID, NS_MENU_CID); +static NS_DEFINE_IID(kMenuItemCID, NS_MENUITEM_CID); +static NS_DEFINE_IID(kImageButtonCID, NS_IMAGEBUTTON_CID); +static NS_DEFINE_IID(kToolbarCID, NS_TOOLBAR_CID); +static NS_DEFINE_IID(kToolbarManagerCID, NS_TOOLBARMANAGER_CID); +static NS_DEFINE_IID(kToolbarItemHolderCID, NS_TOOLBARITEMHOLDER_CID); +static NS_DEFINE_IID(kToolbarItemCID, NS_TOOLBARITEM_CID); +static NS_DEFINE_IID(kPopUpMenuCID, NS_POPUPMENU_CID); +static NS_DEFINE_IID(kMenuButtonCID, NS_MENUBUTTON_CID); + +static NS_DEFINE_IID(kILookAndFeelIID, NS_ILOOKANDFEEL_IID); +static NS_DEFINE_IID(kIBrowserWindowIID, NS_IBROWSER_WINDOW_IID); +static NS_DEFINE_IID(kIButtonIID, NS_IBUTTON_IID); +static NS_DEFINE_IID(kIDOMDocumentIID, NS_IDOMDOCUMENT_IID); +static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID); +static NS_DEFINE_IID(kIFileWidgetIID, NS_IFILEWIDGET_IID); +static NS_DEFINE_IID(kIStreamObserverIID, NS_ISTREAMOBSERVER_IID); +static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); +static NS_DEFINE_IID(kITextWidgetIID, NS_ITEXTWIDGET_IID); +static NS_DEFINE_IID(kIThrobberIID, NS_ITHROBBER_IID); +static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID); +static NS_DEFINE_IID(kIWebShellContainerIID, NS_IWEB_SHELL_CONTAINER_IID); +static NS_DEFINE_IID(kIWidgetIID, NS_IWIDGET_IID); +static NS_DEFINE_IID(kIDialogIID, NS_IDIALOG_IID); +static NS_DEFINE_IID(kICheckButtonIID, NS_ICHECKBUTTON_IID); +static NS_DEFINE_IID(kIRadioButtonIID, NS_IRADIOBUTTON_IID); +static NS_DEFINE_IID(kILabelIID, NS_ILABEL_IID); +static NS_DEFINE_IID(kIMenuBarIID, NS_IMENUBAR_IID); +static NS_DEFINE_IID(kIMenuIID, NS_IMENU_IID); +static NS_DEFINE_IID(kIMenuItemIID, NS_IMENUITEM_IID); +static NS_DEFINE_IID(kIImageButtonIID, NS_IIMAGEBUTTON_IID); +static NS_DEFINE_IID(kIToolbarIID, NS_ITOOLBAR_IID); +static NS_DEFINE_IID(kIToolbarManagerIID, NS_ITOOLBARMANAGER_IID); +static NS_DEFINE_IID(kIToolbarItemHolderIID, NS_ITOOLBARITEMHOLDER_IID); +static NS_DEFINE_IID(kIToolbarItemIID, NS_ITOOLBARITEM_IID); +static NS_DEFINE_IID(kIPopUpMenuIID, NS_IPOPUPMENU_IID); +static NS_DEFINE_IID(kIMenuButtonIID, NS_IMENUBUTTON_IID); + +static const char* gsAOLFormat = "AOLMAIL"; +static const char* gsHTMLFormat = "text/html"; + +static PRInt32 gBtnWidth = 54; +static PRInt32 gBtnHeight = 42; + +///////////////////////////////////////////////////////////// +// This part is temporary until we get the XML/HTML code working +///////////////////////////////////////////////////////////// + +typedef struct { + PRInt32 mGap; + PRInt32 mImgWidth; + PRInt32 mImgHeight; + PRBool mEnabled; + PRInt32 mCommand; + char * mLabel; + char * mRollOverDesc; + char * mUpName; + char * mPressedName; + char * mDisabledName; + char * mRolloverName; +} ButtonCreateInfo; + +const PRInt32 gBackBtnInx = 0; +const PRInt32 gForwardBtnInx = 1; +const PRInt32 gReloadBtnInx = 2; +const PRInt32 gHomeBtnInx = 3; +const PRInt32 gSearchBtnInx = 4; +const PRInt32 gNetscapeBtnInx = 5; +const PRInt32 gPrintBtnInx = 6; +const PRInt32 gSecureBtnInx = 7; +const PRInt32 gStopBtnInx = 8; + +const PRInt32 kBackCmd = 3000; +const PRInt32 kForwardCmd = 3001; +const PRInt32 kReloadCmd = 3002; +const PRInt32 kHomeCmd = 3003; +const PRInt32 kSearchCmd = 3004; +const PRInt32 kNetscapeCmd = 3005; +const PRInt32 kPrintCmd = 3006; +const PRInt32 kSecureCmd = 3007; +const PRInt32 kStopCmd = 3008; + +const PRInt32 kMiniTabCmd = 3009; +const PRInt32 kMiniNavCmd = 3010; +const PRInt32 kBookmarksCmd = 3011; +const PRInt32 kWhatsRelatedCmd = 3012; + +const PRInt32 kPersonalCmd = 4000; + +ButtonCreateInfo gBtnToolbarInfo[] = { +{10, 23, 21, PR_FALSE, kBackCmd, "Back", "Return to previous document in history list", "TB_Back.gif", "TB_Back.gif", "TB_Back_dis.gif", "TB_Back_mo.gif"}, +{2, 23, 21, PR_FALSE, kForwardCmd, "Forward", "Move forward to next document in history list", "TB_Forward.gif", "TB_Forward.gif", "TB_Forward_dis.gif", "TB_Forward_mo.gif"}, +{2, 23, 21, PR_TRUE, kReloadCmd, "Reload", "Reload the current page", "TB_Reload.gif", "TB_Reload.gif", "TB_Reload.gif", "TB_Reload_mo.gif"}, +{2, 23, 21, PR_TRUE, kHomeCmd, "Home", "Go to the Home page", "TB_Home.gif", "TB_Home.gif", "TB_Home.gif", "TB_Home_mo.gif"}, +{2, 23, 21, PR_TRUE, kSearchCmd, "Search", "Search the internet for information", "TB_Search.gif", "TB_Search.gif", "TB_Search.gif", "TB_Search_mo.gif"}, +{2, 23, 21, PR_TRUE, kNetscapeCmd, "Netscape","Go to your personal start page", "TB_Netscape.gif","TB_Netscape.gif","TB_Netscape.gif", "TB_Netscape_mo.gif"}, +{2, 23, 21, PR_TRUE, kPrintCmd, "Print", "Print this page", "TB_Print.gif", "TB_Print.gif", "TB_Print.gif", "TB_Print_mo.gif"}, +{2, 23, 21, PR_TRUE, kSecureCmd, "Security","Show security information", "TB_Secure.gif", "TB_Secure.gif", "TB_Secure.gif", "TB_Secure_mo.gif"}, +{2, 23, 21, PR_FALSE, kStopCmd, "Stop", "Stop the current transfer", "TB_Stop.gif", "TB_Stop.gif", "TB_Stop_dis.gif", "TB_Stop_mo.gif"}, +{0, 0, 0, PR_FALSE, 0, NULL, NULL, NULL, NULL, NULL} +}; + +ButtonCreateInfo gMiniAppsToolbarInfo[] = { +{0, 11, 14, PR_TRUE, kMiniTabCmd, "", "Expand toolbar", "TB_MiniTab.gif", "TB_MiniTab.gif", "TB_MiniTab.gif", "TB_MiniTab.gif"}, +{1, 30, 14, PR_TRUE, kMiniNavCmd, "", "Start a Navigator session", "TB_MiniNav.gif", "TB_MiniNav.gif", "TB_MiniNav.gif", "TB_MiniNav.gif"}, +{1, 30, 14, PR_TRUE, kMiniNavCmd, "", "Start a Mail session", "TB_MiniMail.gif", "TB_MiniMail.gif", "TB_MiniMail.gif", "TB_MiniMail.gif"}, +{1, 30, 14, PR_TRUE, kMiniNavCmd, "", "Start a Address Book session", "TB_MiniAddr.gif", "TB_MiniAddr.gif", "TB_MiniAddr.gif", "TB_MiniAddr.gif"}, +{1, 30, 14, PR_TRUE, kMiniNavCmd, "", "Start a Composer session", "TB_MiniComp.gif", "TB_MiniComp.gif", "TB_MiniComp.gif", "TB_MiniComp.gif"}, +{0, 0, 0, PR_FALSE, 0, NULL, NULL, NULL, NULL, NULL} +}; + +ButtonCreateInfo gMiniAppsDialogInfo[] = { +{2, 36, 22, PR_TRUE, kMiniNavCmd, "", "Start a Navigator session", "DialogNavIcon.gif", "DialogNavIcon.gif", "DialogNavIcon.gif", "DialogNavIcon_mo.gif"}, +{2, 36, 22, PR_TRUE, kMiniNavCmd, "", "Start a Mail session", "DialogMailIcon.gif", "DialogMailIcon.gif", "DialogMailIcon.gif", "DialogMailIcon_mo.gif"}, +{2, 36, 22, PR_TRUE, kMiniNavCmd, "", "Start a ddress Book session", "DialogAddrIcon.gif", "DialogAddrIcon.gif", "DialogAddrIcon.gif", "DialogAddrIcon_mo.gif"}, +{2, 36, 22, PR_TRUE, kMiniNavCmd, "", "Start a Composer session", "DialogCompIcon.gif", "DialogCompIcon.gif", "DialogCompIcon.gif", "DialogCompIcon_mo.gif"}, +{0, 0, 0, PR_FALSE, 0, NULL, NULL, NULL, NULL, NULL} +}; + +ButtonCreateInfo gPersonalToolbarInfo[] = { +{10, 18, 18, PR_TRUE, kPersonalCmd, "Phone Book", "http://phonebook/", "TB_PersonalIcon.gif", "TB_PersonalIcon.gif", "TB_PersonalIcon.gif", "TB_PersonalIcon.gif"}, +{2, 18, 18, PR_TRUE, kPersonalCmd+1, "Stocks", "http://quicken.excite.com/", "TB_PersonalIcon.gif", "TB_PersonalIcon.gif", "TB_PersonalIcon.gif", "TB_PersonalIcon.gif"}, +{2, 18, 18, PR_TRUE, kPersonalCmd+2, "Weather", "http://www.weather.com", "TB_PersonalIcon.gif", "TB_PersonalIcon.gif", "TB_PersonalIcon.gif", "TB_PersonalIcon.gif"}, +{2, 18, 18, PR_TRUE, kPersonalCmd+3, "Sports", "http://cnnsi.com/", "TB_PersonalIcon.gif", "TB_PersonalIcon.gif", "TB_PersonalIcon.gif", "TB_PersonalIcon.gif"}, +{2, 18, 18, PR_TRUE, kPersonalCmd+4, "News", "http://www.cnn.com/", "TB_PersonalIcon.gif", "TB_PersonalIcon.gif", "TB_PersonalIcon.gif", "TB_PersonalIcon.gif"}, +{2, 18, 18, PR_TRUE, kPersonalCmd+5, "IMDB", "www.imdb.com", "TB_PersonalIcon.gif", "TB_PersonalIcon.gif", "TB_PersonalIcon.gif", "TB_PersonalIcon.gif"}, +{0, 0, 0, PR_FALSE, 0, NULL, NULL, NULL, NULL, NULL} +}; + +char * gPersonalURLS[] = {"http://phonebook/", "http://quicken.excite.com/", "http://www.weather.com", + "http://cnnsi.com/", "http://www.cnn.com/", "www.imdb.com"}; + +////////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////// + +// prototypes +static nsEventStatus PR_CALLBACK HandleGUIEvent(nsGUIEvent *aEvent); +static void* GetItemsNativeData(nsISupports* aObject); + +//---------------------------------------------------------------------- + +nsVoidArray nsBrowserWindow::gBrowsers; + +nsBrowserWindow* +nsBrowserWindow::FindBrowserFor(nsIWidget* aWidget, PRIntn aWhich) +{ + nsIWidget* widget; + nsBrowserWindow* result = nsnull; + + PRInt32 i, n = gBrowsers.Count(); + for (i = 0; i < n; i++) { + nsBrowserWindow* bw = (nsBrowserWindow*) gBrowsers.ElementAt(i); + if (nsnull != bw) { + switch (aWhich) { + case FIND_WINDOW: + bw->mWindow->QueryInterface(kIWidgetIID, (void**) &widget); + if (widget == aWidget) { + result = bw; + } + NS_IF_RELEASE(widget); + break; + case FIND_LOCATION: + if (bw->mLocation) { + bw->mLocation->QueryInterface(kIWidgetIID, (void**) &widget); + if (widget == aWidget) { + result = bw; + } + NS_IF_RELEASE(widget); + } + break; + } + } + } + + if (nsnull != result) { + NS_ADDREF(result); + } + + return result; +} + +//--------------------------------------------------------- +nsBrowserWindow* +nsBrowserWindow::FindBrowserFor(nsIWidget* aWidget) +{ + nsBrowserWindow* widgetBrowser; + nsBrowserWindow* result = nsnull; + + if (NS_OK != aWidget->GetClientData((void *&)widgetBrowser)) { + return NULL; + } + + PRInt32 i, n = gBrowsers.Count(); + for (i = 0; i < n; i++) { + nsBrowserWindow* bw = (nsBrowserWindow*) gBrowsers.ElementAt(i); + if (nsnull != bw && widgetBrowser == bw) { + result = bw; + } + } + + if (nsnull != result) { + NS_ADDREF(result); + } + return result; +} + +//--------------------------------------------------------- +void +nsBrowserWindow::AddBrowser(nsBrowserWindow* aBrowser) +{ + gBrowsers.AppendElement(aBrowser); + NS_ADDREF(aBrowser); +} + +//--------------------------------------------------------- +void +nsBrowserWindow::RemoveBrowser(nsBrowserWindow* aBrowser) +{ + nsViewerApp* app = aBrowser->mApp; + gBrowsers.RemoveElement(aBrowser); + NS_RELEASE(aBrowser); +} + +//--------------------------------------------------------- +void +nsBrowserWindow::CloseAllWindows() +{ + while (0 != gBrowsers.Count()) { + nsBrowserWindow* bw = (nsBrowserWindow*) gBrowsers.ElementAt(0); + NS_ADDREF(bw); + bw->Close(); + NS_RELEASE(bw); + } + gBrowsers.Clear(); +} + +//--------------------------------------------------------------- +static nsEventStatus PR_CALLBACK +HandleBrowserEvent(nsGUIEvent *aEvent) +{ + nsEventStatus result = nsEventStatus_eIgnore; + nsBrowserWindow* bw = nsBrowserWindow::FindBrowserFor(aEvent->widget, FIND_WINDOW); + + if (nsnull != bw) { + nsSizeEvent* sizeEvent; + switch(aEvent->message) { + case NS_SIZE: + sizeEvent = (nsSizeEvent*)aEvent; + bw->Layout(sizeEvent->windowSize->width, + sizeEvent->windowSize->height); + result = nsEventStatus_eConsumeNoDefault; + break; + + case NS_DESTROY: + { + nsViewerApp* app = bw->mApp; + result = nsEventStatus_eConsumeDoDefault; + bw->Close(); + NS_RELEASE(bw); + + // XXX Really shouldn't just exit, we should just notify somebody... + if (0 == nsBrowserWindow::gBrowsers.Count()) { + app->Exit(); + } + } + return result; + + case NS_MENU_SELECTED: + result = bw->DispatchMenuItem(((nsMenuEvent*)aEvent)->menuItem); + break; + + // XXX This is a hack, but a needed one + // It draws one line between the layout window and the status bar + case NS_PAINT: + nsIWidget * statusWidget; + if (NS_OK == bw->mStatusBar->QueryInterface(kIWidgetIID,(void**)&statusWidget)) { + nsRect rect; + statusWidget->GetBounds(rect); + + nsRect r; + aEvent->widget->GetBounds(r); + r.x = 0; + r.y = 0; + nsIRenderingContext *drawCtx = ((nsPaintEvent*)aEvent)->renderingContext; + drawCtx->SetColor(NS_RGB(192, 192, 192));//aEvent->widget->GetBackgroundColor()); + rect.y -= 1; + drawCtx->DrawLine(0, rect.y, r.width, rect.y); + NS_RELEASE(statusWidget); + } break; + + default: + break; + } + NS_RELEASE(bw); + } + return result; +} + +//--------------------------------------------------------------- +static nsEventStatus PR_CALLBACK +HandleToolbarEvent(nsGUIEvent *aEvent) +{ + nsEventStatus result = nsEventStatus_eIgnore; + nsBrowserWindow* bw = nsBrowserWindow::FindBrowserFor(aEvent->widget, FIND_BACK); + if (nsnull != bw) { + switch(aEvent->message) { + case NS_MOUSE_LEFT_BUTTON_UP: + //bw->Back(); + break; + } + NS_RELEASE(bw); + } + nsIToolbar * toolbar; + if (NS_OK == aEvent->widget->QueryInterface(kIToolbarIID,(void**)&toolbar)) { + result = toolbar->HandleEvent(aEvent); + NS_RELEASE(toolbar); + } + + + return result; +} + +//--------------------------------------------------------------- +static nsEventStatus PR_CALLBACK +HandleToolbarMgrEvent(nsGUIEvent *aEvent) +{ + nsEventStatus result = nsEventStatus_eIgnore; + + switch(aEvent->message) { + case NS_PAINT: { + nsRect r; + aEvent->widget->GetBounds(r); + r.x = 0; + r.y = 0; + nsIRenderingContext *drawCtx = ((nsPaintEvent*)aEvent)->renderingContext; + drawCtx->SetColor(aEvent->widget->GetBackgroundColor()); + drawCtx->FillRect(r); + + //nsRect rect(*(((nsPaintEvent*)aEvent)->rect)); + nsRect rect(r); + drawCtx->SetColor(NS_RGB(255,255,255)); + drawCtx->DrawLine(0,0,rect.width,0); + drawCtx->SetColor(NS_RGB(128,128,128)); + drawCtx->DrawLine(0,rect.height-1,rect.width,rect.height-1); + } + break; + } //switch + + return result; +} + +//--------------------------------------------------------------- +static nsEventStatus PR_CALLBACK +HandleLocationEvent(nsGUIEvent *aEvent) +{ + nsEventStatus result = nsEventStatus_eIgnore; + nsBrowserWindow* bw = + nsBrowserWindow::FindBrowserFor(aEvent->widget, FIND_LOCATION); + if (nsnull != bw) { + switch (aEvent->message) { + case NS_KEY_UP: + if (NS_VK_RETURN == ((nsKeyEvent*)aEvent)->keyCode) { + nsAutoString text; + PRUint32 size; + bw->mLocation->GetText(text, 1000, size); + bw->GoTo(text); + } + break; + default: + break; + } + NS_RELEASE(bw); + } + return result; +} + +//--------------------------------------------------------------- +void +nsBrowserWindow::UpdateToolbarBtns() +{ + if (nsnull != mToolbarBtns) { + mToolbarBtns[gBackBtnInx]->Enable(mWebShell->CanBack() == NS_OK); + mToolbarBtns[gBackBtnInx]->Invalidate(PR_TRUE); + mToolbarBtns[gForwardBtnInx]->Enable(mWebShell->CanForward() == NS_OK); + mToolbarBtns[gForwardBtnInx]->Invalidate(PR_TRUE); + } +} + +//--------------------------------------------------------------- +nsEventStatus +nsBrowserWindow::DispatchMenuItem(PRInt32 aID) +{ +#ifdef NS_DEBUG + nsEventStatus result = DispatchDebugMenu(aID); + if (nsEventStatus_eIgnore != result) { + return result; + } +#endif + switch (aID) { + case VIEWER_EXIT: + mApp->Exit(); + return nsEventStatus_eConsumeNoDefault; + + case VIEWER_WINDOW_OPEN: + mApp->OpenWindow(); + break; + + case VIEWER_FILE_OPEN: + DoFileOpen(); + break; + + case VIEWER_EDIT_COPY: + DoCopy(); + break; + + case VIEWER_EDIT_SELECTALL: + DoSelectAll(); + break; + + case VIEWER_EDIT_FINDINPAGE: + DoFind(); + break; + + case VIEWER_DEMO0: + case VIEWER_DEMO1: + case VIEWER_DEMO2: + case VIEWER_DEMO3: + case VIEWER_DEMO4: + case VIEWER_DEMO5: + case VIEWER_DEMO6: + case VIEWER_DEMO7: + case VIEWER_DEMO8: + case VIEWER_DEMO9: + { + PRIntn ix = aID - VIEWER_DEMO0; + nsAutoString url(SAMPLES_BASE_URL); + url.Append("/test"); + url.Append(ix, 10); + url.Append(".html"); + mWebShell->LoadURL(url); + + UpdateToolbarBtns(); + } + break; + case JS_CONSOLE: + DoJSConsole(); + break; + + case EDITOR_MODE: + DoEditorMode(mWebShell); + break; + } + + return nsEventStatus_eIgnore; +} + +void +nsBrowserWindow::Back() +{ + mWebShell->Back(); +} + +void +nsBrowserWindow::Forward() +{ + mWebShell->Forward(); +} + +void +nsBrowserWindow::GoTo(const PRUnichar* aURL) +{ + mWebShell->LoadURL(aURL, nsnull); + UpdateToolbarBtns(); +} + +#define FILE_PROTOCOL "file://" + +static PRBool GetFileNameFromFileSelector(nsIWidget* aParentWindow, + nsString* aFileName) +{ + PRBool selectedFileName = PR_FALSE; + nsIFileWidget *fileWidget; + nsString title("Open HTML"); + nsresult rv = nsRepository::CreateInstance(kFileWidgetCID, + nsnull, + kIFileWidgetIID, + (void**)&fileWidget); + if (NS_OK == rv) { + nsString titles[] = {"all files","html" }; + nsString filters[] = {"*.*", "*.html"}; + fileWidget->SetFilterList(2, titles, filters); + fileWidget->Create(aParentWindow, + title, + eMode_load, + nsnull, + nsnull); + + PRUint32 result = fileWidget->Show(); + if (result) { + fileWidget->GetFile(*aFileName); + selectedFileName = PR_TRUE; + } + + NS_RELEASE(fileWidget); + } + + return selectedFileName; +} + +//----------------------------------------------------- +void +nsBrowserWindow::DoFileOpen() +{ + nsAutoString fileName; + char szFile[1000]; + if (GetFileNameFromFileSelector(mWindow, &fileName)) { + fileName.ToCString(szFile, sizeof(szFile)); + PRInt32 len = strlen(szFile); + PRInt32 sum = len + sizeof(FILE_PROTOCOL); + char* lpszFileURL = new char[sum]; + + // Translate '\' to '/' + for (PRInt32 i = 0; i < len; i++) { + if (szFile[i] == '\\') { + szFile[i] = '/'; + } + } + + // Build the file URL + PR_snprintf(lpszFileURL, sum, "%s%s", FILE_PROTOCOL, szFile); + + // Ask the Web widget to load the file URL + mWebShell->LoadURL(nsString(lpszFileURL)); + delete lpszFileURL; + } +} + +#define DIALOG_FONT "Helvetica" +#define DIALOG_FONT_SIZE 10 + +/**-------------------------------------------------------------------------------- + * Main Handler + *-------------------------------------------------------------------------------- + */ +nsEventStatus PR_CALLBACK HandleGUIEvent(nsGUIEvent *aEvent) +{ + //printf("HandleGUIEvent aEvent->message %d\n", aEvent->message); + nsEventStatus result = nsEventStatus_eIgnore; + if (aEvent == nsnull || aEvent->widget == nsnull) { + return result; + } + + if (aEvent->message == 301 || aEvent->message == 302) { + int x = 0; + } + + void * data; + aEvent->widget->GetClientData(data); + + if (data == nsnull) { + nsIWidget * parent = aEvent->widget->GetParent(); + if (parent != nsnull) { + parent->GetClientData(data); + NS_RELEASE(parent); + } + } + + if (data != nsnull) { + nsBrowserWindow * browserWindow = (nsBrowserWindow *)data; + result = browserWindow->ProcessDialogEvent(aEvent); + } + + return result; +} + + + +static void* GetItemsNativeData(nsISupports* aObject) +{ + void* result = nsnull; + nsIWidget* widget; + if (NS_OK == aObject->QueryInterface(kIWidgetIID,(void**)&widget)) + { + result = widget->GetNativeData(NS_NATIVE_WIDGET); + NS_RELEASE(widget); + } + return result; +} + +/**-------------------------------------------------------------------------------- + * Main Handler + *-------------------------------------------------------------------------------- + */ + + + +nsEventStatus nsBrowserWindow::ProcessDialogEvent(nsGUIEvent *aEvent) +{ + nsEventStatus result = nsEventStatus_eIgnore; + + //printf("aEvent->message %d\n", aEvent->message); + switch(aEvent->message) { + + case NS_KEY_DOWN: { + nsKeyEvent* keyEvent = (nsKeyEvent*)aEvent; + if (NS_VK_RETURN == keyEvent->keyCode) { + PRBool matchCase = PR_FALSE; + mMatchCheckBtn->GetState(matchCase); + PRBool findDwn = PR_FALSE; + mDwnRadioBtn->GetState(findDwn); + nsString searchStr; + PRUint32 actualSize; + mTextField->GetText(searchStr, 255,actualSize); + + nsIPresShell* shell = GetPresShell(); + if (nsnull != shell) { + nsIDocument* doc = shell->GetDocument(); + if (nsnull != doc) { + PRBool foundIt = PR_FALSE; + doc->FindNext(searchStr, matchCase, findDwn, foundIt); + if (!foundIt) { + // Display Dialog here + } + ForceRefresh(); + NS_RELEASE(doc); + } + NS_RELEASE(shell); + } + } + } break; + + case NS_MOUSE_LEFT_BUTTON_UP: { + nsIWidget* dialogWidget = nsnull; + if (NS_OK != mDialog->QueryInterface(kIWidgetIID,(void**)&dialogWidget)) + break; + + if (aEvent->widget->GetNativeData(NS_NATIVE_WIDGET) == GetItemsNativeData(mCancelBtn)) { + dialogWidget->Show(PR_FALSE); + } else if (aEvent->widget->GetNativeData(NS_NATIVE_WIDGET) == GetItemsNativeData(mFindBtn)) { + + PRBool matchCase = PR_FALSE; + mMatchCheckBtn->GetState(matchCase); + PRBool findDwn = PR_FALSE; + mDwnRadioBtn->GetState(findDwn); + PRUint32 actualSize; + nsString searchStr; + mTextField->GetText(searchStr, 255,actualSize); + + nsIPresShell* shell = GetPresShell(); + if (nsnull != shell) { + nsIDocument* doc = shell->GetDocument(); + if (nsnull != doc) { + PRBool foundIt = PR_FALSE; + doc->FindNext(searchStr, matchCase, findDwn, foundIt); + if (!foundIt) { + // Display Dialog here + } + ForceRefresh(); + NS_RELEASE(doc); + } + NS_RELEASE(shell); + } + + } else if (aEvent->widget->GetNativeData(NS_NATIVE_WIDGET) == GetItemsNativeData(mUpRadioBtn)) { + mUpRadioBtn->SetState(PR_TRUE); + mDwnRadioBtn->SetState(PR_FALSE); + } else if (aEvent->widget->GetNativeData(NS_NATIVE_WIDGET) == GetItemsNativeData(mDwnRadioBtn)) { + mDwnRadioBtn->SetState(PR_TRUE); + mUpRadioBtn->SetState(PR_FALSE); + } else if (aEvent->widget->GetNativeData(NS_NATIVE_WIDGET) == GetItemsNativeData(mMatchCheckBtn)) { + PRBool state = PR_FALSE; + mMatchCheckBtn->GetState(state); + mMatchCheckBtn->SetState(!state); + } + } break; + + case NS_PAINT: +#ifndef XP_UNIX + // paint the background + if (aEvent->widget->GetNativeData(NS_NATIVE_WIDGET) == GetItemsNativeData(mDialog)) { + nsIRenderingContext *drawCtx = ((nsPaintEvent*)aEvent)->renderingContext; + drawCtx->SetColor(aEvent->widget->GetBackgroundColor()); + drawCtx->FillRect(*(((nsPaintEvent*)aEvent)->rect)); + + return nsEventStatus_eIgnore; + } +#endif + break; + + case NS_DESTROY: { + mStatusAppBarWidget->Show(PR_TRUE); + mStatusBar->DoLayout(); + NS_RELEASE(mAppsDialog); + + PRInt32 i; + for (i=0;iGetMetric(nsILookAndFeel::eMetric_TextFieldHeight, txtHeight); + lookAndFeel->GetColor(nsILookAndFeel::eColor_TextBackground, textBGColor); + lookAndFeel->GetColor(nsILookAndFeel::eColor_TextForeground, textFGColor); + NS_RELEASE(lookAndFeel); + } + + + nsIDeviceContext* dc = mWindow->GetDeviceContext(); + float t2d; + dc->GetTwipsToDevUnits(t2d); + nsFont font(DIALOG_FONT, NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL, + NS_FONT_WEIGHT_NORMAL, 0, + nscoord(t2d * NSIntPointsToTwips(DIALOG_FONT_SIZE))); + NS_RELEASE(dc); + + // create a Dialog + // + nsRect rect; + rect.SetRect(0, 0, 380, 110); + + nsRepository::CreateInstance(kDialogCID, nsnull, kIDialogIID, (void**)&mDialog); + nsIWidget* widget = nsnull; + NS_CreateDialog(mWindow,mDialog,rect,HandleGUIEvent,&font); + if (NS_OK == mDialog->QueryInterface(kIWidgetIID,(void**)&widget)) { + widget->SetClientData(this); + NS_RELEASE(widget); + } + mDialog->SetLabel("Find"); + + nscoord xx = 5; + // Create Label + rect.SetRect(xx, 8, 75, 24); + nsRepository::CreateInstance(kLabelCID, nsnull, kILabelIID, (void**)&mLabel); + NS_CreateLabel(mDialog,mLabel,rect,HandleGUIEvent,&font); + if (NS_OK == mLabel->QueryInterface(kIWidgetIID,(void**)&widget)) { + widget->SetClientData(this); + mLabel->SetAlignment(eAlign_Right); + mLabel->SetLabel("Find what:"); + NS_RELEASE(widget); + } + xx += 75 + 5; + + // Create TextField + rect.SetRect(xx, 5, 200, txtHeight); + nsRepository::CreateInstance(kTextFieldCID, nsnull, kITextWidgetIID, (void**)&mTextField); + NS_CreateTextWidget(mDialog,mTextField,rect,HandleGUIEvent,&font); + if (NS_OK == mTextField->QueryInterface(kIWidgetIID,(void**)&widget)) { + widget->SetBackgroundColor(textBGColor); + widget->SetForegroundColor(textFGColor); + widget->SetClientData(this); + widget->SetFocus(); + NS_RELEASE(widget); + } + xx += 200 + 5; + + nscoord w = 65; + nscoord x = 205+80-w; + nscoord y = txtHeight + 10; + nscoord h = 19; + + // Create Up RadioButton + rect.SetRect(x, y, w, h); + nsRepository::CreateInstance(kRadioButtonCID, nsnull, kIRadioButtonIID, (void**)&mUpRadioBtn); + NS_CreateRadioButton(mDialog,mUpRadioBtn,rect,HandleGUIEvent,&font); + if (NS_OK == mUpRadioBtn->QueryInterface(kIWidgetIID,(void**)&widget)) { + widget->SetClientData(this); + mUpRadioBtn->SetLabel("Up"); + NS_RELEASE(widget); + } + y += h + 2; + + // Create Up RadioButton + rect.SetRect(x, y, w, h); + nsRepository::CreateInstance(kRadioButtonCID, nsnull, kIRadioButtonIID, (void**)&mDwnRadioBtn); + NS_CreateRadioButton(mDialog,mDwnRadioBtn,rect,HandleGUIEvent,&font); + if (NS_OK == mDwnRadioBtn->QueryInterface(kIWidgetIID,(void**)&widget)) { + widget->SetClientData(this); + mDwnRadioBtn->SetLabel("Down"); + NS_RELEASE(widget); + } + + // Create Match CheckButton + rect.SetRect(5, y, 125, 24); + nsRepository::CreateInstance(kCheckButtonCID, nsnull, kICheckButtonIID, (void**)&mMatchCheckBtn); + NS_CreateCheckButton(mDialog,mMatchCheckBtn,rect,HandleGUIEvent,&font); + if (NS_OK == mMatchCheckBtn->QueryInterface(kIWidgetIID,(void**)&widget)) { + widget->SetClientData(this); + mMatchCheckBtn->SetLabel("Match Case"); + NS_RELEASE(widget); + } + + mUpRadioBtn->SetState(PR_FALSE); + mDwnRadioBtn->SetState(PR_TRUE); + + // Create Find Next Button + rect.SetRect(xx, 5, 75, 24); + nsRepository::CreateInstance(kButtonCID, nsnull, kIButtonIID, (void**)&mFindBtn); + NS_CreateButton(mDialog,mFindBtn,rect,HandleGUIEvent,&font); + if (NS_OK == mFindBtn->QueryInterface(kIWidgetIID,(void**)&widget)) { + widget->SetClientData(this); + mFindBtn->SetLabel("Find Next"); + NS_RELEASE(widget); + } + + // Create Cancel Button + rect.SetRect(xx, 35, 75, 24); + nsRepository::CreateInstance(kButtonCID, nsnull, kIButtonIID, (void**)&mCancelBtn); + NS_CreateButton(mDialog,mCancelBtn,rect,HandleGUIEvent,&font); + if (NS_OK == mCancelBtn->QueryInterface(kIWidgetIID,(void**)&widget)) { + widget->SetClientData(this); + mCancelBtn->SetLabel("Cancel"); + NS_RELEASE(widget); + } + } + mTextField->SelectAll(); + +} + +void +nsBrowserWindow::DoSelectAll() +{ + + nsIPresShell* shell = GetPresShell(); + if (nsnull != shell) { + nsIDocument* doc = shell->GetDocument(); + if (nsnull != doc) { + doc->SelectAll(); + ForceRefresh(); + NS_RELEASE(doc); + } + NS_RELEASE(shell); + } +} + +void +nsBrowserWindow::ForceRefresh() +{ + nsIPresShell* shell = GetPresShell(); + if (nsnull != shell) { + nsIViewManager* vm = shell->GetViewManager(); + if (nsnull != vm) { + nsIView* root; + vm->GetRootView(root); + if (nsnull != root) { + vm->UpdateView(root, (nsIRegion*)nsnull, NS_VMREFRESH_IMMEDIATE); + } + NS_RELEASE(vm); + } + NS_RELEASE(shell); + } +} + + +//---------------------------------------------------------------------- + +// Note: operator new zeros our memory +nsBrowserWindow::nsBrowserWindow() +{ + AddBrowser(this); +} + +nsBrowserWindow::~nsBrowserWindow() +{ +} + +NS_IMPL_ADDREF(nsBrowserWindow) +NS_IMPL_RELEASE(nsBrowserWindow) + +nsresult +nsBrowserWindow::QueryInterface(const nsIID& aIID, + void** aInstancePtrResult) +{ + NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer"); + if (nsnull == aInstancePtrResult) { + return NS_ERROR_NULL_POINTER; + } + + *aInstancePtrResult = NULL; + + if (aIID.Equals(kIBrowserWindowIID)) { + *aInstancePtrResult = (void*) ((nsIBrowserWindow*)this); + NS_ADDREF_THIS(); + return NS_OK; + } + if (aIID.Equals(kIStreamObserverIID)) { + *aInstancePtrResult = (void*) ((nsIStreamObserver*)this); + NS_ADDREF_THIS(); + return NS_OK; + } + if (aIID.Equals(kIWebShellContainerIID)) { + *aInstancePtrResult = (void*) ((nsIWebShellContainer*)this); + NS_ADDREF_THIS(); + return NS_OK; + } + if (aIID.Equals(kINetSupportIID)) { + *aInstancePtrResult = (void*) ((nsINetSupport*)this); + NS_ADDREF_THIS(); + return NS_OK; + } + if (aIID.Equals(kISupportsIID)) { + *aInstancePtrResult = (void*) ((nsISupports*)((nsIBrowserWindow*)this)); + NS_ADDREF_THIS(); + return NS_OK; + } + return NS_NOINTERFACE; +} + +nsresult +nsBrowserWindow::Init(nsIAppShell* aAppShell, + nsIPref* aPrefs, + const nsRect& aBounds, + PRUint32 aChromeMask, + PRBool aAllowPlugins) +{ + mChromeMask = aChromeMask; + mAppShell = aAppShell; + mPrefs = aPrefs; + mAllowPlugins = aAllowPlugins; + + // Create top level window + nsresult rv = nsRepository::CreateInstance(kWindowCID, nsnull, kIWidgetIID, + (void**)&mWindow); + if (NS_OK != rv) { + return rv; + } + nsRect r(0, 0, aBounds.width, aBounds.height); + mWindow->Create((nsIWidget*)NULL, r, HandleBrowserEvent, + nsnull, aAppShell); + mWindow->GetBounds(r); + mWindow->SetBackgroundColor(NS_RGB(192,192,192)); + + // Create web shell + rv = nsRepository::CreateInstance(kWebShellCID, nsnull, + kIWebShellIID, + (void**)&mWebShell); + if (NS_OK != rv) { + return rv; + } + r.x = r.y = 0; + rv = mWebShell->Init(mWindow->GetNativeData(NS_NATIVE_WIDGET), + r.x, r.y, r.width, r.height, + nsScrollPreference_kAuto, aAllowPlugins); + mWebShell->SetContainer((nsIWebShellContainer*) this); + mWebShell->SetObserver((nsIStreamObserver*)this); + mWebShell->SetPrefs(aPrefs); + mWebShell->Show(); + + if (NS_CHROME_MENU_BAR_ON & aChromeMask) { + rv = CreateMenuBar(r.width); + if (NS_OK != rv) { + return rv; + } + mWindow->GetBounds(r); + r.x = r.y = 0; + } + + if (NS_CHROME_TOOL_BAR_ON & aChromeMask) { + rv = CreateToolBar(r.width); + if (NS_OK != rv) { + return rv; + } + } + + if (NS_CHROME_STATUS_BAR_ON & aChromeMask) { + rv = CreateStatusBar(r.width); + if (NS_OK != rv) { + return rv; + } + } + + // Now lay it all out + Layout(r.width, r.height); + + + return NS_OK; +} + +// XXX This sort of thing should be in a resource +#define TOOL_BAR_FONT "Helvetica" +#define TOOL_BAR_FONT_SIZE 12 +#define STATUS_BAR_FONT "Helvetica" +#define STATUS_BAR_FONT_SIZE 10 + + +//------------------------------------------------------------------ +// This method needs to be moved into nsWidgetSupport +nsresult +NS_CreateImageButton(nsISupports *aParent, + nsIImageButton *&aButton, + nsIWidget *&aButtonWidget, + const nsString &aLabel, + const nsRect &aRect, + EVENT_CALLBACK aHandleEventFunction, + const nsFont *aFont, + const nsString &aBaseURL, + const nsString &aUpURL, + const nsString &aPressedURL, + const nsString &aDisabledURL, + const nsString &aRollOverURL, + PRInt32 anImageWidth, + PRInt32 anImageHeight + ) +{ + nsIWidget* parent = nsnull; + if (aParent != nsnull) { + aParent->QueryInterface(kIWidgetIID,(void**)&parent); + } else { + return NS_ERROR_FAILURE; + } + + // Create MenuButton + nsresult rv = nsRepository::CreateInstance(kImageButtonCID, nsnull, kIImageButtonIID, + (void**)&aButton); + if (NS_OK != rv) { + return rv; + } + + if (NS_OK == aButton->QueryInterface(kIWidgetIID,(void**)&aButtonWidget)) { + aButtonWidget->Create(parent, aRect, aHandleEventFunction, NULL); + aButtonWidget->Show(PR_TRUE); + if (aFont != nsnull) + aButtonWidget->SetFont(*aFont); + } + + aButton->SetLabel(aLabel); + aButton->SetShowText(aLabel.Length() > 0); + aButton->SetShowButtonBorder(PR_TRUE); + aButton->SetImageDimensions(anImageWidth, anImageHeight); + + // Load URLs + if (aBaseURL.Length() > 0) { + nsString upURL(aBaseURL); + nsString pressedURL(aBaseURL); + nsString disabledURL(aBaseURL); + nsString rolloverURL(aBaseURL); + + upURL.Append(aUpURL); + pressedURL.Append(aPressedURL); + disabledURL.Append(aDisabledURL); + rolloverURL.Append(aRollOverURL); + + aButton->SetImageURLs(upURL, pressedURL, disabledURL, rolloverURL); + } else { + aButton->SetShowImage(PR_FALSE); + } + + NS_IF_RELEASE(parent); + + return NS_OK; +} + +//------------------------------------------------------------------ +// This method needs to be moved into nsWidgetSupport +nsresult +NS_CreateMenuButton(nsISupports *aParent, + nsIMenuButton *&aButton, + nsIWidget *&aButtonWidget, + const nsString &aLabel, + const nsRect &aRect, + EVENT_CALLBACK aHandleEventFunction, + const nsFont *aFont, + const nsString &aBaseURL, + const nsString &aUpURL, + const nsString &aPressedURL, + const nsString &aDisabledURL, + const nsString &aRollOverURL, + PRInt32 anImageWidth, + PRInt32 anImageHeight) +{ + nsIWidget* parent = nsnull; + if (aParent != nsnull) { + aParent->QueryInterface(kIWidgetIID,(void**)&parent); + } else { + return NS_ERROR_FAILURE; + } + + // Create MenuButton + nsresult rv = nsRepository::CreateInstance(kMenuButtonCID, nsnull, kIMenuButtonIID, + (void**)&aButton); + if (NS_OK != rv) { + return rv; + } + + if (NS_OK == aButton->QueryInterface(kIWidgetIID,(void**)&aButtonWidget)) { + aButtonWidget->Create(parent, aRect, aHandleEventFunction, NULL); + aButtonWidget->Show(PR_TRUE); + if (aFont != nsnull) + aButtonWidget->SetFont(*aFont); + } + + aButton->SetLabel(aLabel); + aButton->SetShowText(aLabel.Length() > 0); + aButton->SetShowButtonBorder(PR_TRUE); + aButton->SetImageDimensions(anImageWidth, anImageHeight); + + // Load URLs + if (aBaseURL.Length() > 0) { + nsString upURL(aBaseURL); + nsString pressedURL(aBaseURL); + nsString disabledURL(aBaseURL); + nsString rolloverURL(aBaseURL); + + upURL.Append(aUpURL); + pressedURL.Append(aPressedURL); + disabledURL.Append(aDisabledURL); + rolloverURL.Append(aRollOverURL); + + aButton->SetImageURLs(upURL, pressedURL, disabledURL, rolloverURL); + aButton->SetShowImage(PR_TRUE); + } else { + aButton->SetShowImage(PR_FALSE); + } + + NS_IF_RELEASE(parent); + + return NS_OK; +} + +//----------------------------------------------------------- +nsresult +nsBrowserWindow::AddToolbarItem(nsIToolbar *aToolbar, + PRInt32 aGap, + PRBool aEnable, + nsIWidget * aButtonWidget) +{ + + // Create the generic toolbar holder for widget + nsIToolbarItemHolder * toolbarItemHolder; + nsresult rv = nsRepository::CreateInstance(kToolbarItemHolderCID, nsnull, kIToolbarItemHolderIID, + (void**)&toolbarItemHolder); + if (NS_OK != rv) { + return rv; + } + + // Get the ToolbarItem interface for adding it to the toolbar + nsIToolbarItem * toolbarItem; + if (NS_OK != toolbarItemHolder->QueryInterface(kIToolbarItemIID,(void**)&toolbarItem)) { + return NS_OK; + } + + // Set client data for callback purposes + aButtonWidget->SetClientData(this); + + aButtonWidget->Enable(aEnable); + + // Add to widget to item holder + toolbarItemHolder->SetWidget(aButtonWidget); + + // Add item holder to toolbar + aToolbar->AddItem(toolbarItem, aGap, PR_FALSE); + + NS_RELEASE(toolbarItem); + NS_RELEASE(toolbarItemHolder); + + + return NS_OK; +} + + +void +nsBrowserWindow::DoAppsDialog() +{ + if (mAppsDialog == nsnull) { + nscoord txtHeight = 24; + nscolor textBGColor = NS_RGB(0, 0, 0); + nscolor textFGColor = NS_RGB(255, 255, 255); + + nsILookAndFeel * lookAndFeel; + if (NS_OK == nsRepository::CreateInstance(kLookAndFeelCID, nsnull, kILookAndFeelIID, (void**)&lookAndFeel)) { + lookAndFeel->GetMetric(nsILookAndFeel::eMetric_TextFieldHeight, txtHeight); + lookAndFeel->GetColor(nsILookAndFeel::eColor_TextBackground, textBGColor); + lookAndFeel->GetColor(nsILookAndFeel::eColor_TextForeground, textFGColor); + NS_RELEASE(lookAndFeel); + } + + nsIDeviceContext* dc = mWindow->GetDeviceContext(); + float t2d; + dc->GetTwipsToDevUnits(t2d); + nsFont font(DIALOG_FONT, NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL, + NS_FONT_WEIGHT_NORMAL, 0, + nscoord(t2d * NSIntPointsToTwips(DIALOG_FONT_SIZE))); + NS_RELEASE(dc); + + // create a Dialog + // + nsRect rect(0, 0, (40*4)+8, 23+31); + + nsRepository::CreateInstance(kDialogCID, nsnull, kIDialogIID, (void**)&mAppsDialog); + nsIWidget* widget = nsnull; + NS_CreateDialog(mWindow, mAppsDialog, rect, HandleGUIEvent, &font); + if (NS_OK == mAppsDialog->QueryInterface(kIWidgetIID,(void**)&widget)) { + widget->SetClientData(this); + widget->Resize(rect.x, rect.y, rect.width, rect.height, PR_TRUE); + NS_RELEASE(widget); + } + mAppsDialog->SetLabel(""); + + nsString label(""); + nsString baseURL("resource:/res/toolbar/"); + + // Count number of buttons and create array to hold them + mNumAppsDialogBtns = 0; + while (gMiniAppsDialogInfo[mNumAppsDialogBtns].mImgWidth > 0) { + mNumAppsDialogBtns++; + } + mAppsDialogBtns = (nsIWidget **)new PRInt32[mNumAppsDialogBtns]; + + // Create buttons + PRInt32 i = 0; + PRInt32 x = 2; + while (gMiniAppsDialogInfo[i].mImgWidth > 0) { + nsIImageButton * btn; + nsIWidget * widget; + rect.SetRect(x, 2, gMiniAppsDialogInfo[i].mImgWidth+4, gMiniAppsDialogInfo[i].mImgHeight+4); + NS_CreateImageButton(mAppsDialog, btn, widget, gMiniAppsDialogInfo[i].mLabel, + rect, nsnull, + &font, baseURL, + gMiniAppsDialogInfo[i].mUpName, + gMiniAppsDialogInfo[i].mPressedName, + gMiniAppsDialogInfo[i].mDisabledName, + gMiniAppsDialogInfo[i].mRolloverName, + gMiniAppsDialogInfo[i].mImgWidth, + gMiniAppsDialogInfo[i].mImgHeight); + btn->SetShowText(PR_FALSE); + btn->SetCommand(gMiniAppsDialogInfo[i].mCommand); + btn->SetRollOverDesc(gMiniAppsDialogInfo[i].mRollOverDesc); + btn->AddListener(this); + mAppsDialogBtns[i] = widget; + widget->Enable(gMiniAppsDialogInfo[i].mEnabled); + + NS_RELEASE(btn); + x += 40; + i++; + } + + } + mDialog = mAppsDialog; +} + +//------------------------------------------------------------------- +nsresult +nsBrowserWindow::CreateToolBar(PRInt32 aWidth) +{ + nsresult rv; + + PRInt32 imageWidth = 23; + PRInt32 imageHeight = 21; + + nsIDeviceContext* dc = mWindow->GetDeviceContext(); + float t2d; + dc->GetTwipsToDevUnits(t2d); + nsFont font(TOOL_BAR_FONT, NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL, + NS_FONT_WEIGHT_NORMAL, 0, + nscoord(t2d * NSIntPointsToTwips(TOOL_BAR_FONT_SIZE))); + NS_RELEASE(dc); + + //---------------------------------------------------- + // Create Toolbar Manager + //---------------------------------------------------- + rv = nsRepository::CreateInstance(kToolbarManagerCID, nsnull, kIToolbarManagerIID, + (void**)&mToolbarMgr); + if (NS_OK != rv) { + return rv; + } + nsIWidget * toolbarMgrWidget; + nsRect rr(0, 0, 200, 32); + if (NS_OK != mToolbarMgr->QueryInterface(kIWidgetIID,(void**)&toolbarMgrWidget)) { + return rv; + } + toolbarMgrWidget->Create(mWindow, rr, HandleToolbarMgrEvent, NULL); + toolbarMgrWidget->Show(PR_TRUE); + mToolbarMgr->AddToolbarListener(this); + mToolbarMgr->SetCollapseTabURLs("resource:/res/toolbar/TB_Tab.gif", "resource:/res/toolbar/TB_Tab.gif", "resource:/res/toolbar/TB_Tab.gif", "resource:/res/toolbar/TB_Tab_mo.gif"); + mToolbarMgr->SetExpandTabURLs("resource:/res/toolbar/TB_HTab.gif", "resource:/res/toolbar/TB_HTab.gif", "resource:/res/toolbar/TB_HTab.gif", "resource:/res/toolbar/TB_HTab_mo.gif"); + + //---------------------------------------------------- + // Create Button Toolbar + //---------------------------------------------------- + rv = nsRepository::CreateInstance(kToolbarCID, nsnull, kIToolbarIID, + (void**)&mBtnToolbar); + if (NS_OK != rv) { + return rv; + } + + nsIWidget * toolbarWidget; + nsRect rrr(0, 0, 200, 32); + if (NS_OK != mBtnToolbar->QueryInterface(kIWidgetIID,(void**)&toolbarWidget)) { + return rv; + } + mBtnToolbar->SetMargin(1); + mBtnToolbar->SetHGap(2); + + toolbarWidget->Create(toolbarMgrWidget, rrr, HandleToolbarEvent, NULL); + toolbarWidget->Show(PR_TRUE); + mToolbarMgr->AddToolbar(mBtnToolbar); + + gBtnWidth = 54; + gBtnHeight = 42; + + nsRect r(0, 0, gBtnWidth, gBtnHeight); + nsIWidget* widget = nsnull; + + nsString baseURL("resource:/res/toolbar/"); + + // Count number of buttons and create array to hold them + mNumToolbarBtns = 0; + while (gBtnToolbarInfo[mNumToolbarBtns].mImgWidth > 0) { + mNumToolbarBtns++; + } + mToolbarBtns = (nsIWidget **)new PRInt32[mNumToolbarBtns]; + + nsRect rect(0,0, 54, 42); + PRInt32 width, height; + + // Create buttons + PRInt32 i = 0; + while (gBtnToolbarInfo[i].mImgWidth > 0) { + nsIMenuButton * btn; + nsIWidget * widget; + NS_CreateMenuButton(mBtnToolbar, btn, widget, gBtnToolbarInfo[i].mLabel, + rect, nsnull, + &font, baseURL, + gBtnToolbarInfo[i].mUpName, + gBtnToolbarInfo[i].mPressedName, + gBtnToolbarInfo[i].mDisabledName, + gBtnToolbarInfo[i].mRolloverName, + gBtnToolbarInfo[i].mImgWidth, + gBtnToolbarInfo[i].mImgHeight); + AddToolbarItem(mBtnToolbar, gBtnToolbarInfo[i].mGap, gBtnToolbarInfo[i].mEnabled, widget); + btn->SetBorderOffset(1); + btn->SetCommand(gBtnToolbarInfo[i].mCommand); + btn->SetRollOverDesc(gBtnToolbarInfo[i].mRollOverDesc); + btn->AddListener(this); + widget->GetPreferredSize(width, height); + widget->SetPreferredSize(54, height); + widget->Resize(0,0, 54, height,PR_FALSE); + mToolbarBtns[i] = widget; + rect.x += 40; + i++; + NS_RELEASE(btn); + } + mBtnToolbar->SetWrapping(PR_TRUE); + toolbarWidget->GetPreferredSize(width, height); + toolbarWidget->SetPreferredSize(width, height); + toolbarWidget->Resize(0,0,width, height,PR_FALSE); + + // Create and place throbber + r.SetRect(aWidth - THROBBER_WIDTH, 0, + THROBBER_WIDTH, THROBBER_HEIGHT); + rv = nsRepository::CreateInstance(kThrobberCID, nsnull, kIThrobberIID, + (void**)&mThrobber); + if (NS_OK != rv) { + return rv; + } + //mBtnToolbar->SetThrobber(mThrobber); + nsString throbberURL("resource:/res/throbber/LargeAnimation%02d.gif"); + mThrobber->Init(toolbarWidget, r, throbberURL, 38); + + // Get the ToolbarItem interface for adding it to the toolbar + nsIWidget * w; + if (NS_OK != mThrobber->QueryInterface(kIWidgetIID,(void**)&w)) { + return NS_OK; + } + + nsIToolbarItem * toolbarItem; + if (NS_OK != mThrobber->QueryInterface(kIToolbarItemIID,(void**)&toolbarItem)) { + return NS_OK; + } + + mBtnToolbar->AddItem(toolbarItem, 10, PR_FALSE); + NS_RELEASE(toolbarItem); + + mThrobber->Show(); + + mBtnToolbar->SetLastItemIsRightJustified(PR_TRUE); + NS_IF_RELEASE(toolbarWidget); + + //---------------------------------------------------- + // Create URL Toolbar + //---------------------------------------------------- + rv = nsRepository::CreateInstance(kToolbarCID, nsnull, kIToolbarIID, + (void**)&mURLToolbar); + if (NS_OK != rv) { + return rv; + } + nsIWidget * urlToolbarWidget; + if (NS_OK != mURLToolbar->QueryInterface(kIWidgetIID,(void**)&urlToolbarWidget)) { + return rv; + } + mURLToolbar->SetMargin(1); + mURLToolbar->SetHGap(2); + + urlToolbarWidget->Create(toolbarMgrWidget, rr, HandleToolbarEvent, NULL); + urlToolbarWidget->Show(PR_TRUE); + mToolbarMgr->AddToolbar(mURLToolbar); + + //------ + // Create and place Bookmark button + //------ + rv = nsRepository::CreateInstance(kImageButtonCID, nsnull, kIImageButtonIID, + (void**)&mBookmarks); + if (NS_OK != rv) { + return rv; + } + r.SetRect(0, 0, 105, 22); + + // Create Bookmarks Menu Btn + if (NS_OK == NS_CreateMenuButton(mURLToolbar, mBookmarks, mBookmarksWidget, "Bookmarks", + r, nsnull, &font, baseURL, + "TB_Bookmarks.gif", "TB_Bookmarks.gif", "TB_Bookmarks.gif", "TB_Bookmarks_mo.gif", + 30, 18)) { + AddToolbarItem(mURLToolbar, 10, PR_TRUE, mBookmarksWidget); + mBookmarks->SetCommand(kBookmarksCmd); + mBookmarks->SetRollOverDesc("Bookmarks functions"); + mBookmarks->AddListener(this); + mBookmarks->SetImageVerticalAlignment(eButtonVerticalAligment_Center); + mBookmarks->SetImageHorizontalAlignment(eButtonHorizontalAligment_Left); + mBookmarks->SetTextVerticalAlignment(eButtonVerticalAligment_Center); + mBookmarks->SetTextHorizontalAlignment(eButtonHorizontalAligment_Right); + mBookmarks->AddMenuItem("Add Bookmark", 3000); + } + + // Create location icon + r.SetRect(0, 0, 18, 18); + if (NS_OK == NS_CreateImageButton(mURLToolbar, mLocationIcon, mLocationIconWidget, "", + r, nsnull, &font, baseURL, + "TB_Location.gif", "TB_Location.gif", "TB_Location.gif", "TB_Location_mo.gif", + 16, 16)) { + AddToolbarItem(mURLToolbar, 10, PR_TRUE, mLocationIconWidget); + mLocationIcon->SetRollOverDesc("Drag this location to Bookmarks"); + mLocationIcon->SetImageVerticalAlignment(eButtonVerticalAligment_Center); + mLocationIcon->SetImageHorizontalAlignment(eButtonHorizontalAligment_Middle); + mLocationIcon->SetShowBorder(PR_FALSE); + } + + // Create Location Label + nsIImageButton * locationLabel; + if (NS_OK == NS_CreateImageButton(mURLToolbar, locationLabel, widget, "Location:", + r, nsnull, &font, "", "", "", "", "", 0, 0)) { + + AddToolbarItem(mURLToolbar, 1, PR_TRUE, widget); + locationLabel->SetShowImage(PR_FALSE); + locationLabel->SetShowBorder(PR_FALSE); + locationLabel->SetTextVerticalAlignment(eButtonVerticalAligment_Center); + locationLabel->SetTextHorizontalAlignment(eButtonHorizontalAligment_Right); + + PRInt32 width, height; + widget->GetPreferredSize(width, height); + widget->SetPreferredSize(width, height); + widget->Resize(0,0, width, height, PR_FALSE); + NS_RELEASE(locationLabel); + NS_RELEASE(widget); + } + + // Create and place URL Text Field + r.SetRect(0, 0, 200, 24); + + rv = nsRepository::CreateInstance(kTextFieldCID, nsnull, kITextWidgetIID, + (void**)&mLocation); + if (NS_OK != rv) { + return rv; + } + + dc = mWindow->GetDeviceContext(); + dc->GetTwipsToDevUnits(t2d); + nsFont font2(TOOL_BAR_FONT, NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL, + NS_FONT_WEIGHT_NORMAL, 0, + nscoord(t2d * NSIntPointsToTwips(TOOL_BAR_FONT_SIZE-2))); + NS_RELEASE(dc); + + NS_CreateTextWidget(urlToolbarWidget, mLocation, r, HandleLocationEvent, &font2); + if (NS_OK == mLocation->QueryInterface(kIWidgetIID,(void**)&mLocationWidget)) { + + AddToolbarItem(mURLToolbar, 2, PR_TRUE, mLocationWidget); + + mLocationWidget->SetForegroundColor(NS_RGB(0, 0, 0)); + mLocationWidget->SetBackgroundColor(NS_RGB(255, 255, 255)); + mLocationWidget->Show(PR_TRUE); + PRUint32 size; + mLocation->SetText("",size); + } + + // Create and place What's Related button + r.SetRect(0, 0, 123, 22); + if (NS_OK == NS_CreateMenuButton(mURLToolbar, mWhatsRelated, mWhatsRelatedWidget, "What's Related", + r, nsnull, &font, baseURL, + "TB_WhatsRelated.gif", "TB_WhatsRelated.gif", "TB_WhatsRelated.gif", "TB_WhatsRelated_mo.gif", + 27, 16)) { + AddToolbarItem(mURLToolbar, 2, PR_TRUE, mWhatsRelatedWidget); + mWhatsRelated->SetCommand(kWhatsRelatedCmd); + mWhatsRelated->SetRollOverDesc("View the \"What's Related\" list"); + mWhatsRelated->AddListener(this); + mWhatsRelated->SetImageVerticalAlignment(eButtonVerticalAligment_Center); + mWhatsRelated->SetImageHorizontalAlignment(eButtonHorizontalAligment_Left); + mWhatsRelated->SetTextVerticalAlignment(eButtonVerticalAligment_Center); + mWhatsRelated->SetTextHorizontalAlignment(eButtonHorizontalAligment_Right); + } + + mURLToolbar->SetLastItemIsRightJustified(PR_TRUE); + mURLToolbar->SetNextLastItemIsStretchy(PR_TRUE); + + + //---------------------------------------------- + // Load Personal Toolbar + //---------------------------------------------- + nsIToolbar * personalToolbar; + rv = nsRepository::CreateInstance(kToolbarCID, nsnull, kIToolbarIID, + (void**)&personalToolbar); + if (NS_OK != rv) { + return rv; + } + + nsIWidget * personalToolbarWidget; + rrr.SetRect(0, 0, 200, 23); + if (NS_OK != personalToolbar->QueryInterface(kIWidgetIID,(void**)&personalToolbarWidget)) { + return rv; + } + personalToolbar->SetMargin(1); + personalToolbar->SetHGap(2); + personalToolbar->SetWrapping(PR_TRUE); + + personalToolbarWidget->Create(toolbarMgrWidget, rrr, HandleToolbarEvent, NULL); + personalToolbarWidget->Show(PR_TRUE); + mToolbarMgr->AddToolbar(personalToolbar); + + // Count number of buttons and create array to hold them + mNumPersonalToolbarBtns = 0; + while (gPersonalToolbarInfo[mNumPersonalToolbarBtns].mImgWidth > 0) { + mNumPersonalToolbarBtns++; + } + mPersonalToolbarBtns = (nsIWidget **)new PRInt32[mNumPersonalToolbarBtns]; + + rect.SetRect(0,0, 100, 21); + + // Create buttons + i = 0; + while (gPersonalToolbarInfo[i].mImgWidth > 0) { + nsIImageButton * btn; + nsIWidget * widget; + NS_CreateImageButton(personalToolbar, btn, widget, gPersonalToolbarInfo[i].mLabel, + rect, nsnull, + &font, baseURL, + gPersonalToolbarInfo[i].mUpName, + gPersonalToolbarInfo[i].mPressedName, + gPersonalToolbarInfo[i].mDisabledName, + gPersonalToolbarInfo[i].mRolloverName, + gPersonalToolbarInfo[i].mImgWidth, + gPersonalToolbarInfo[i].mImgHeight); + + btn->SetImageVerticalAlignment(eButtonVerticalAligment_Center); + btn->SetImageHorizontalAlignment(eButtonHorizontalAligment_Left); + btn->SetTextVerticalAlignment(eButtonVerticalAligment_Center); + btn->SetTextHorizontalAlignment(eButtonHorizontalAligment_Right); + btn->SetCommand(gPersonalToolbarInfo[i].mCommand); + btn->SetRollOverDesc(gPersonalToolbarInfo[i].mRollOverDesc); + btn->AddListener(this); + + PRInt32 width, height; + widget->GetPreferredSize(width, height); + widget->SetPreferredSize(width, height); + widget->Resize(0, 0, width, height, PR_FALSE); + AddToolbarItem(personalToolbar, gPersonalToolbarInfo[i].mGap, gPersonalToolbarInfo[i].mEnabled, widget); + mPersonalToolbarBtns[i] = widget; + NS_RELEASE(btn); + i++; + } + NS_RELEASE(personalToolbar); + NS_RELEASE(personalToolbarWidget); + + //------ + NS_RELEASE(toolbarMgrWidget); + + return NS_OK; +} + +//----------------------------------------------------------- +nsresult +nsBrowserWindow::CreateStatusBar(PRInt32 aWidth) +{ + nsresult rv; + + nsIDeviceContext* dc = mWindow->GetDeviceContext(); + float t2d; + dc->GetTwipsToDevUnits(t2d); + nsFont font(STATUS_BAR_FONT, NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL, + NS_FONT_WEIGHT_NORMAL, 0, + nscoord(t2d * NSIntPointsToTwips(STATUS_BAR_FONT_SIZE))); + NS_RELEASE(dc); + + //---------------------------------------------------- + // Create StatusBar as a Toolbar + //---------------------------------------------------- + rv = nsRepository::CreateInstance(kToolbarCID, nsnull, kIToolbarIID, + (void**)&mStatusBar); + if (NS_OK != rv) { + return rv; + } + + nsIWidget * statusWidget; + nsRect rrr(0, 0, 200, 32); + if (NS_OK != mStatusBar->QueryInterface(kIWidgetIID,(void**)&statusWidget)) { + return rv; + } + mStatusBar->SetMargin(1); + mStatusBar->SetHGap(2); + + statusWidget->Create(mWindow, rrr, HandleToolbarEvent, NULL); + statusWidget->Show(PR_TRUE); + statusWidget->Show(PR_TRUE); + + nsRect r(0, 0, 18, 16); + nsIWidget* widget = nsnull; + + nsString baseURL("resource:/res/toolbar/"); + + nsString insecureImg("StatusBar-insecure.gif"); + nsString secureImg("StatusBar-secure.gif"); + + if (NS_OK == NS_CreateImageButton(mStatusBar, mStatusSecurityLabel, widget, "", + r, nsnull, &font, baseURL, + insecureImg, insecureImg, secureImg, insecureImg, + 16, 14)) { + + AddToolbarItem(mStatusBar, 0, PR_TRUE, widget); + // Make button look depressed and always show border + mStatusSecurityLabel->SwapHighlightShadowColors(); + mStatusSecurityLabel->SetAlwaysShowBorder(PR_TRUE); + mStatusSecurityLabel->SetShowButtonBorder(PR_FALSE); + mStatusSecurityLabel->SetShowText(PR_FALSE); + mStatusSecurityLabel->SetBorderWidth(0); + mStatusSecurityLabel->SetBorderOffset(0); + mStatusSecurityLabel->SetImageVerticalAlignment(eButtonVerticalAligment_Center); + NS_RELEASE(widget); + } + + r.SetRect(0, 0, 96, 16); + if (NS_OK == NS_CreateImageButton(mStatusBar, mStatusProcess, widget, "", + r, nsnull, &font, "", + "", "", "", "", 0, 0)) { + + AddToolbarItem(mStatusBar, 2, PR_TRUE, widget); + // Make button look depressed and always show border + mStatusProcess->SwapHighlightShadowColors(); + mStatusProcess->SetAlwaysShowBorder(PR_TRUE); + mStatusProcess->SetShowButtonBorder(PR_FALSE); + mStatusProcess->SetShowText(PR_TRUE); + mStatusProcess->SetShowImage(PR_FALSE); + mStatusProcess->SetBorderOffset(0); + widget->SetPreferredSize(96, 16); + NS_RELEASE(widget); + } + + if (NS_OK == NS_CreateImageButton(mStatusBar, mStatusText, widget, "", + r, nsnull, &font, "", + "", "", "", "", 0,0)) { + + AddToolbarItem(mStatusBar, 2, PR_TRUE, widget); + // Make button look depressed and always show border + mStatusText->SwapHighlightShadowColors(); + mStatusText->SetAlwaysShowBorder(PR_TRUE); + mStatusText->SetShowButtonBorder(PR_FALSE); + mStatusText->SetBorderOffset(0); + // Set up to just display text + mStatusText->SetShowText(PR_TRUE); + mStatusText->SetShowImage(PR_FALSE); + mStatusText->SetTextHorizontalAlignment(eButtonHorizontalAligment_Left); + NS_RELEASE(widget); + } + + //---------------------------------------------------- + // Create Mini Tools Toolbar + //---------------------------------------------------- + rrr.SetRect(0, 0, 150, 18); + rv = nsRepository::CreateInstance(kToolbarCID, nsnull, kIToolbarIID, + (void**)&mStatusAppBar); + if (NS_OK != rv) { + return rv; + } + + if (NS_OK != mStatusAppBar->QueryInterface(kIWidgetIID,(void**)&mStatusAppBarWidget)) { + return rv; + } + mStatusAppBar->SetMargin(1); + mStatusAppBar->SetHGap(2); + mStatusAppBar->SetDrawFullBorder(PR_TRUE); + + mStatusAppBarWidget->Create(statusWidget, rrr, HandleToolbarEvent, NULL); + mStatusAppBarWidget->Show(PR_TRUE); + + mStatusAppBarWidget->SetClientData(this); + + // Get the ToolbarItem interface for adding it to the toolbar + nsIToolbarItem * toolbarItem; + if (NS_OK != mStatusAppBar->QueryInterface(kIToolbarItemIID,(void**)&toolbarItem)) { + return NS_OK; + } + mStatusBar->AddItem(toolbarItem, 2, PR_FALSE); + + // Count number of buttons and create array to hold them + mNumMiniAppsBtns = 0; + while (gMiniAppsToolbarInfo[mNumMiniAppsBtns].mImgWidth > 0) { + mNumMiniAppsBtns++; + } + mMiniAppsBtns = (nsIWidget **)new PRInt32[mNumMiniAppsBtns]; + + // Create buttons + PRInt32 i = 0; + nsRect rect; + while (gMiniAppsToolbarInfo[i].mImgWidth > 0) { + if (i == 0) { + rect.SetRect(0, 0, 13, 18); + } else { + rect.SetRect(0, 0, 32, 16); + } + nsIImageButton * btn; + nsIWidget * widget; + NS_CreateImageButton(mStatusAppBar, btn, widget, gMiniAppsToolbarInfo[i].mLabel, + rect, nsnull, + &font, baseURL, + gMiniAppsToolbarInfo[i].mUpName, + gMiniAppsToolbarInfo[i].mPressedName, + gMiniAppsToolbarInfo[i].mDisabledName, + gMiniAppsToolbarInfo[i].mRolloverName, + gMiniAppsToolbarInfo[i].mImgWidth, + gMiniAppsToolbarInfo[i].mImgHeight); + AddToolbarItem(mStatusAppBar, gMiniAppsToolbarInfo[i].mGap, gMiniAppsToolbarInfo[i].mEnabled, widget); + btn->SetShowText(PR_FALSE); + btn->SetImageVerticalAlignment(eButtonVerticalAligment_Center); + btn->SetImageHorizontalAlignment(eButtonHorizontalAligment_Middle); + btn->SetShowButtonBorder(PR_FALSE); + btn->SetBorderOffset(0); + btn->SetCommand(gMiniAppsToolbarInfo[i].mCommand); + btn->SetRollOverDesc(gMiniAppsToolbarInfo[i].mRollOverDesc); + btn->AddListener(this); + if (i == 0) { + btn->SetAlwaysShowBorder(PR_TRUE); + } + mMiniAppsBtns[i] = widget; + rect.x += 40; + i++; + NS_RELEASE(btn); + } + PRInt32 width,height; + mStatusAppBarWidget->GetPreferredSize(width, height); + mStatusAppBarWidget->SetPreferredSize(width, height); + mStatusAppBarWidget->Resize(0,0,width, height, PR_FALSE); + + mStatusBar->SetLastItemIsRightJustified(PR_TRUE); + mStatusBar->SetNextLastItemIsStretchy(PR_TRUE); + + return NS_OK; +} + +//---------------------------------------------------- +NS_METHOD +nsBrowserWindow::NotifyToolbarManagerChangedSize(nsIToolbarManager* aToolbarMgr) +{ + nsRect rect; + GetBounds(rect); + Layout(rect.width, rect.height); + + return NS_OK; +} + +//---------------------------------------------------- +NS_METHOD +nsBrowserWindow::NotifyImageButtonEvent(nsIImageButton * aImgBtn, nsGUIEvent* anEvent) +{ + if (anEvent->message == NS_MOUSE_ENTER) { + nsString msg; + aImgBtn->GetRollOverDesc(msg); + SetStatus(msg); + return NS_OK; + } else if (anEvent->message == NS_MOUSE_EXIT) { + SetStatus(""); + return NS_OK; + } else if (anEvent->message != NS_MOUSE_LEFT_BUTTON_UP) { + return NS_OK; + } + + PRInt32 command; + if (NS_OK != aImgBtn->GetCommand(command)) { + return NS_ERROR_FAILURE; + } + + // Do Personal toolbar + if (command >= kPersonalCmd) { + nsString url(gPersonalURLS[command - kPersonalCmd]); + mWebShell->LoadURL(url); + return NS_OK; + } + + // Do the rest of the commands + switch (command) { + case kBackCmd : + Back(); + UpdateToolbarBtns(); + break; + + case kForwardCmd : + Forward(); + UpdateToolbarBtns(); + break; + + case kHomeCmd : { + nsString homeURL("http://www.netscape.com"); + mWebShell->LoadURL(homeURL); + } break; + + case kMiniNavCmd : + mApp->OpenWindow(); + break; + + case kMiniTabCmd : { + DoAppsDialog(); + nsIWidget * widget; + if (NS_OK == mAppsDialog->QueryInterface(kIWidgetIID,(void**)&widget)) { + widget->Show(PR_TRUE); + NS_RELEASE(widget); + } + mStatusAppBarWidget->Show(PR_FALSE); + mStatusBar->DoLayout(); + } break; + + } // switch + + return NS_OK; +} + +//---------------------------------------------------- +void +nsBrowserWindow::Layout(PRInt32 aWidth, PRInt32 aHeight) +{ + nscoord txtHeight; + nsILookAndFeel * lookAndFeel; + if (NS_OK == nsRepository::CreateInstance(kLookAndFeelCID, nsnull, kILookAndFeelIID, (void**)&lookAndFeel)) { + lookAndFeel->GetMetric(nsILookAndFeel::eMetric_TextFieldHeight, txtHeight); + NS_RELEASE(lookAndFeel); + } else { + txtHeight = 24; + } + + + nsIWidget * btnToolBarWidget; + if (NS_OK != mBtnToolbar->QueryInterface(kIWidgetIID,(void**)&btnToolBarWidget)) { + return; + } + + nsIWidget * urlToolBarWidget; + if (NS_OK != mURLToolbar->QueryInterface(kIWidgetIID,(void**)&urlToolBarWidget)) { + return; + } + + nsIWidget * tbManagerWidget; + if (NS_OK != mToolbarMgr->QueryInterface(kIWidgetIID,(void**)&tbManagerWidget)) { + return; + } + + nsRect rr(0, 0, aWidth, aHeight); + nsIWidget* locationWidget = nsnull; + + PRInt32 preferredWidth = aWidth; + PRInt32 preferredHeight = aHeight; + /*btnToolBarWidget->GetPreferredSize(preferredWidth, preferredHeight); + btnToolBarWidget->Resize(0,0, aWidth, preferredHeight, PR_TRUE); + rr.y += preferredHeight; + rr.height -= preferredHeight; + + urlToolBarWidget->GetPreferredSize(preferredWidth, preferredHeight); + urlToolBarWidget->Resize(0,rr.y, aWidth, preferredHeight, PR_TRUE); + rr.y += preferredHeight; + rr.height -= preferredHeight; + */ + tbManagerWidget->GetPreferredSize(preferredWidth, preferredHeight); + tbManagerWidget->Resize(0,0, aWidth, preferredHeight, PR_TRUE); + rr.y += preferredHeight; + rr.height -= preferredHeight; + + nsIWidget* statusWidget = nsnull; + PRInt32 statusBarHeight = 0; + + if (NS_OK == mStatusBar->QueryInterface(kIWidgetIID,(void**)&statusWidget)) { + if (mStatusBar) { + if (mChromeMask & NS_CHROME_STATUS_BAR_ON) { + //PRInt32 width; + //statusWidget->GetPreferredSize(width, statusBarHeight); + statusBarHeight = 22; + statusWidget->Resize(0, aHeight - statusBarHeight, aWidth, statusBarHeight, PR_TRUE); + rr.height -= statusBarHeight+1; + statusWidget->Show(PR_TRUE); + } + else { + statusWidget->Show(PR_FALSE); + } + } + } + + // inset the web widget + rr.x += WEBSHELL_LEFT_INSET; + rr.y += WEBSHELL_TOP_INSET; + rr.width -= WEBSHELL_LEFT_INSET + WEBSHELL_RIGHT_INSET; + rr.height -= WEBSHELL_TOP_INSET + WEBSHELL_BOTTOM_INSET; + mWebShell->SetBounds(rr.x, rr.y, rr.width, rr.height); + + NS_IF_RELEASE(locationWidget); + NS_IF_RELEASE(btnToolBarWidget); + NS_IF_RELEASE(urlToolBarWidget); + NS_IF_RELEASE(statusWidget); +} + +NS_IMETHODIMP +nsBrowserWindow::MoveTo(PRInt32 aX, PRInt32 aY) +{ + NS_PRECONDITION(nsnull != mWindow, "null window"); + mWindow->Move(aX, aY); + return NS_OK; +} + +NS_IMETHODIMP +nsBrowserWindow::SizeTo(PRInt32 aWidth, PRInt32 aHeight) +{ + NS_PRECONDITION(nsnull != mWindow, "null window"); + + // XXX We want to do this in one shot + mWindow->Resize(aWidth, aHeight, PR_FALSE); + Layout(aWidth, aHeight); + + return NS_OK; +} + +NS_IMETHODIMP +nsBrowserWindow::GetBounds(nsRect& aBounds) +{ + mWindow->GetBounds(aBounds); + return NS_OK; +} + +NS_IMETHODIMP +nsBrowserWindow::Show() +{ + NS_PRECONDITION(nsnull != mWindow, "null window"); + mWindow->Show(PR_TRUE); + return NS_OK; +} + +NS_IMETHODIMP +nsBrowserWindow::Hide() +{ + NS_PRECONDITION(nsnull != mWindow, "null window"); + mWindow->Show(PR_FALSE); + return NS_OK; +} + +NS_IMETHODIMP +nsBrowserWindow::Close() +{ + RemoveBrowser(this); + + if (nsnull != mWebShell) { + mWebShell->Destroy(); + NS_RELEASE(mWebShell); + } + +// NS_IF_RELEASE(mWindow); + if (nsnull != mWindow) { + nsIWidget* w = mWindow; + NS_RELEASE(w); + } + + /*NS_IF_RELEASE(mBack); + NS_IF_RELEASE(mForward); + NS_IF_RELEASE(mLocation); + NS_IF_RELEASE(mThrobber); + NS_IF_RELEASE(mStatus); + */ + + return NS_OK; +} + + +NS_IMETHODIMP +nsBrowserWindow::SetChrome(PRUint32 aChromeMask) +{ + mChromeMask = aChromeMask; + nsRect r; + mWindow->GetBounds(r); + Layout(r.width, r.height); + + return NS_OK; +} + +NS_IMETHODIMP +nsBrowserWindow::GetChrome(PRUint32& aChromeMaskResult) +{ + aChromeMaskResult = mChromeMask; + return NS_OK; +} + +NS_IMETHODIMP +nsBrowserWindow::GetWebShell(nsIWebShell*& aResult) +{ + aResult = mWebShell; + NS_IF_ADDREF(mWebShell); + return NS_OK; +} + +NS_IMETHODIMP +nsBrowserWindow::HandleEvent(nsGUIEvent * anEvent) +{ + if (anEvent->widget == mToolbarBtns[gBackBtnInx]) { + Back(); + UpdateToolbarBtns(); + + } else if (anEvent->widget == mToolbarBtns[gForwardBtnInx]) { + Forward(); + UpdateToolbarBtns(); + + } else if (mAppsDialogBtns != nsnull && anEvent->widget == mAppsDialogBtns[0]) { + mApp->OpenWindow(); + + } else if (anEvent->widget == mMiniAppsBtns[1]) { + mApp->OpenWindow(); + + } else if (anEvent->widget == mToolbarBtns[gHomeBtnInx]) { + nsString homeURL("http://www.netscape.com"); + mWebShell->LoadURL(homeURL); + + } else if (anEvent->widget == mMiniAppsBtns[0]) { + DoAppsDialog(); + nsIWidget * widget; + if (NS_OK == mAppsDialog->QueryInterface(kIWidgetIID,(void**)&widget)) { + widget->Show(PR_TRUE); + NS_RELEASE(widget); + } + mStatusAppBarWidget->Show(PR_FALSE); + mStatusBar->DoLayout(); + } + + PRInt32 i = 0; + for (i=0;iwidget) { + nsString url(gPersonalURLS[i]); + mWebShell->LoadURL(url); + break; + } + } + + return NS_OK; +} + +//---------------------------------------- +NS_IMETHODIMP +nsBrowserWindow::SetTitle(const PRUnichar* aTitle) +{ + NS_PRECONDITION(nsnull != mWindow, "null window"); + mTitle = aTitle; + mWindow->SetTitle(aTitle); + return NS_OK; +} + +//---------------------------------------- +NS_IMETHODIMP +nsBrowserWindow::GetTitle(PRUnichar** aResult) +{ + *aResult = mTitle; + return NS_OK; +} + +//---------------------------------------- +NS_IMETHODIMP +nsBrowserWindow::SetStatus(const PRUnichar* aStatus) +{ + nsString msg(aStatus); + SetStatus(msg); + return NS_OK; +} + +//---------------------------------------- +NS_IMETHODIMP +nsBrowserWindow::SetStatus(const nsString & aMsg) +{ + if (nsnull != mStatusText) { + mStatusText->SetLabel(aMsg); + nsIWidget * widget; + if (NS_OK == mStatusText->QueryInterface(kIWidgetIID,(void**)&widget)) { + widget->Invalidate(PR_TRUE); + NS_RELEASE(widget); + } + } + return NS_OK; +} + +//---------------------------------------- +NS_IMETHODIMP +nsBrowserWindow::GetStatus(PRUnichar** aResult) +{ + return NS_OK; +} + +//---------------------------------------- +NS_IMETHODIMP +nsBrowserWindow::SetProgress(PRInt32 aProgress, PRInt32 aProgressMax) +{ + return NS_OK; +} + +//---------------------------------------- +NS_IMETHODIMP +nsBrowserWindow::WillLoadURL(nsIWebShell* aShell, const PRUnichar* aURL, nsLoadType aReason) +{ + if (mStatusBar) { + nsAutoString url("Connecting to "); + url.Append(aURL); + + SetStatus(aURL); + } + return NS_OK; +} + +//---------------------------------------- +NS_IMETHODIMP +nsBrowserWindow::BeginLoadURL(nsIWebShell* aShell, const PRUnichar* aURL) +{ + if (mThrobber) { + mThrobber->Start(); + PRUint32 size; + mLocation->SetText(aURL,size); + } + nsIWidget * widget; + if (NS_OK == mToolbarBtns[gStopBtnInx]->QueryInterface(kIWidgetIID,(void**)&widget)) { + widget->Enable(PR_TRUE); + widget->Invalidate(PR_TRUE); + NS_RELEASE(widget); + } + return NS_OK; +} + +//---------------------------------------- +NS_IMETHODIMP +nsBrowserWindow::ProgressLoadURL(nsIWebShell* aShell, const PRUnichar* aURL, PRInt32 aProgress, PRInt32 aProgressMax) +{ + return NS_OK; +} + +//---------------------------------------- +NS_IMETHODIMP +nsBrowserWindow::EndLoadURL(nsIWebShell* aShell, const PRUnichar* aURL, PRInt32 aStatus) +{ + if (mThrobber) { + mThrobber->Stop(); + } + nsIWidget * widget; + if (NS_OK == mToolbarBtns[gStopBtnInx]->QueryInterface(kIWidgetIID,(void**)&widget)) { + widget->Enable(PR_FALSE); + widget->Invalidate(PR_TRUE); + NS_RELEASE(widget); + } + return NS_OK; +} + + +//---------------------------------------- +NS_IMETHODIMP +nsBrowserWindow::NewWebShell(nsIWebShell*& aNewWebShell) +{ + nsresult rv = NS_OK; + + // Create new window. By default, the refcnt will be 1 because of + // the registration of the browser window in gBrowsers. + nsBrowserWindow* browser; + NS_NEWXPCOM(browser, nsBrowserWindow); + + if (nsnull != browser) + { + nsRect bounds; + GetBounds(bounds); + + browser->SetApp(mApp); + rv = browser->Init(mAppShell, mPrefs, bounds, mChromeMask, mAllowPlugins); + if (NS_OK == rv) + { + browser->Show(); + nsIWebShell *shell; + rv = browser->GetWebShell(shell); + aNewWebShell = shell; + } + else + { + browser->Close(); + } + } + else + rv = NS_ERROR_OUT_OF_MEMORY; + + return rv; +} + +//---------------------------------------- + +// Stream observer implementation + +//---------------------------------------- +NS_IMETHODIMP +nsBrowserWindow::OnProgress(nsIURL* aURL, + PRInt32 aProgress, + PRInt32 aProgressMax) +{ + if (mStatusBar) { + nsAutoString url; + if (nsnull != aURL) { + aURL->ToString(url); + } + url.Append(": progress "); + url.Append(aProgress, 10); + if (0 != aProgressMax) { + url.Append(" (out of "); + url.Append(aProgressMax, 10); + url.Append(")"); + } + SetStatus(url); + } + return NS_OK; +} + +//---------------------------------------- +NS_IMETHODIMP +nsBrowserWindow::OnStatus(nsIURL* aURL, const nsString& aMsg) +{ + SetStatus(aMsg); + return NS_OK; +} + +//---------------------------------------- +NS_IMETHODIMP +nsBrowserWindow::OnStartBinding(nsIURL* aURL, const char *aContentType) +{ + if (mStatusBar) { + nsAutoString url; + if (nsnull != aURL) { + aURL->ToString(url); + } + url.Append(": start"); + SetStatus(url); + } + return NS_OK; +} + +//---------------------------------------- +NS_IMETHODIMP +nsBrowserWindow::OnStopBinding(nsIURL* aURL, + PRInt32 status, + const nsString& aMsg) +{ + if (mThrobber) { + mThrobber->Stop(); + } + + mToolbarBtns[gStopBtnInx]->Enable(PR_FALSE); + mToolbarBtns[gStopBtnInx]->Invalidate(PR_TRUE); + + nsAutoString url; + if (nsnull != aURL) { + aURL->ToString(url); + } + url.Append(": stop"); + SetStatus(url); + + return NS_OK; +} + +//---------------------------------------- +NS_IMETHODIMP_(void) +nsBrowserWindow::Alert(const nsString &aText) +{ + nsAutoString str(aText); + printf("Browser Window Alert: %s\n", str); +} + +//---------------------------------------- +NS_IMETHODIMP_(PRBool) +nsBrowserWindow::Confirm(const nsString &aText) +{ + nsAutoString str(aText); + printf("Browser Window Confirm: %s (returning false)\n", str); + + return PR_FALSE; +} + +//---------------------------------------- +NS_IMETHODIMP_(PRBool) +nsBrowserWindow::Prompt(const nsString &aText, + const nsString &aDefault, + nsString &aResult) +{ + nsAutoString str(aText); + char buf[256]; + printf("Browser Window: %s\n", str); + printf("Prompt: "); + scanf("%s", buf); + aResult = buf; + + return (aResult.Length() > 0); +} + +//---------------------------------------- +NS_IMETHODIMP_(PRBool) +nsBrowserWindow::PromptUserAndPassword(const nsString &aText, + nsString &aUser, + nsString &aPassword) +{ + nsAutoString str(aText); + char buf[256]; + printf("Browser Window: %s\n", str); + printf("User: "); + scanf("%s", buf); + aUser = buf; + printf("Password: "); + scanf("%s", buf); + aPassword = buf; + + return (aUser.Length() > 0); +} + +//---------------------------------------- +NS_IMETHODIMP_(PRBool) +nsBrowserWindow::PromptPassword(const nsString &aText, + nsString &aPassword) +{ + nsAutoString str(aText); + char buf[256]; + printf("Browser Window: %s\n", str); + printf("Password: "); + scanf("%s", buf); + aPassword = buf; + + return PR_TRUE; +} + +//---------------------------------------- +// Toolbar support +void +nsBrowserWindow::StartThrobber() +{ +} + +//---------------------------------------- +void +nsBrowserWindow::StopThrobber() +{ +} + +//---------------------------------------- +void +nsBrowserWindow::LoadThrobberImages() +{ +} + +//---------------------------------------- +void +nsBrowserWindow::DestroyThrobberImages() +{ +} + +static NS_DEFINE_IID(kIDocumentViewerIID, NS_IDOCUMENT_VIEWER_IID); + +//---------------------------------------- +nsIPresShell* +nsBrowserWindow::GetPresShell() +{ + nsIPresShell* shell = nsnull; + if (nsnull != mWebShell) { + nsIContentViewer* cv = nsnull; + mWebShell->GetContentViewer(cv); + if (nsnull != cv) { + nsIDocumentViewer* docv = nsnull; + cv->QueryInterface(kIDocumentViewerIID, (void**) &docv); + if (nsnull != docv) { + nsIPresContext* cx; + docv->GetPresContext(cx); + if (nsnull != cx) { + shell = cx->GetShell(); + NS_RELEASE(cx); + } + NS_RELEASE(docv); + } + NS_RELEASE(cv); + } + } + return shell; +} + +//---------------------------------------- +#ifdef WIN32 +void PlaceHTMLOnClipboard(PRUint32 aFormat, char* aData, int aLength) +{ + HGLOBAL hGlobalMemory; + PSTR pGlobalMemory; + + PRUint32 cf_aol = RegisterClipboardFormat(gsAOLFormat); + PRUint32 cf_html = RegisterClipboardFormat(gsHTMLFormat); + + char* preamble = ""; + char* postamble = ""; + + if (aFormat == cf_aol || aFormat == CF_TEXT) + { + preamble = ""; + postamble = ""; + } + + PRInt32 size = aLength + 1 + strlen(preamble) + strlen(postamble); + + + if (aLength) + { + // Copy text to Global Memory Area + hGlobalMemory = (HGLOBAL)GlobalAlloc(GHND, size); + if (hGlobalMemory != NULL) + { + pGlobalMemory = (PSTR) GlobalLock(hGlobalMemory); + + int i; + + // AOL requires HTML prefix/postamble + char* s = preamble; + PRInt32 len = strlen(s); + for (i=0; i < len; i++) + { + *pGlobalMemory++ = *s++; + } + + s = aData; + len = aLength; + for (i=0;i< len;i++) { + *pGlobalMemory++ = *s++; + } + + + s = postamble; + len = strlen(s); + for (i=0; i < len; i++) + { + *pGlobalMemory++ = *s++; + } + + // Put data on Clipboard + GlobalUnlock(hGlobalMemory); + SetClipboardData(aFormat, hGlobalMemory); + } + } +} +#endif + + + +//---------------------------------------- +void +nsBrowserWindow::DoCopy() +{ + nsIPresShell* shell = GetPresShell(); + if (nsnull != shell) { + nsIDocument* doc = shell->GetDocument(); + if (nsnull != doc) { + nsString buffer; + + doc->CreateXIF(buffer,PR_TRUE); + + nsIParser* parser; + + static NS_DEFINE_IID(kCParserIID, NS_IPARSER_IID); + static NS_DEFINE_IID(kCParserCID, NS_PARSER_IID); + + nsresult rv = nsRepository::CreateInstance(kCParserCID, + nsnull, + kCParserIID, + (void **)&parser); + + if (NS_OK == rv) { + nsIHTMLContentSink* sink = nsnull; + + rv = NS_New_HTML_ContentSinkStream(&sink,PR_FALSE,PR_FALSE); + + ostrstream data; + ((nsHTMLContentSinkStream*)sink)->SetOutputStream(data); + + if (NS_OK == rv) { + parser->SetContentSink(sink); + + nsIDTD* dtd = nsnull; + rv = NS_NewXIFDTD(&dtd); + if (NS_OK == rv) + { + parser->RegisterDTD(dtd); + dtd->SetContentSink(sink); + dtd->SetParser(parser); + parser->Parse(buffer, PR_FALSE); + } + NS_IF_RELEASE(dtd); + NS_IF_RELEASE(sink); + char* str = data.str(); + +#if defined(WIN32) + PRUint32 cf_aol = RegisterClipboardFormat(gsAOLFormat); + PRUint32 cf_html = RegisterClipboardFormat(gsHTMLFormat); + + PRInt32 len = data.pcount(); + if (len) + { + OpenClipboard(NULL); + EmptyClipboard(); + + PlaceHTMLOnClipboard(cf_aol,str,len); + PlaceHTMLOnClipboard(cf_html,str,len); + PlaceHTMLOnClipboard(CF_TEXT,str,len); + + CloseClipboard(); + } + // in ostrstreams if you cal the str() function + // then you are responsible for deleting the string +#endif + if (str) delete str; + + } + NS_RELEASE(parser); + } + NS_RELEASE(doc); + } + NS_RELEASE(shell); + } +} + +//---------------------------------------------------------------------- +void +nsBrowserWindow::DoJSConsole() +{ + mApp->CreateJSConsole(this); +} + +//---------------------------------------- +void +nsBrowserWindow::DoEditorMode(nsIWebShell *aWebShell) +{ + /*PRInt32 i, n; + if (nsnull != aWebShell) { + nsIContentViewer* mCViewer; + aWebShell->GetContentViewer(mCViewer); + if (nsnull != mCViewer) { + nsIDocumentViewer* mDViewer; + if (NS_OK == mCViewer->QueryInterface(kIDocumentViewerIID, (void**) &mDViewer)) { + nsIDocument* mDoc; + mDViewer->GetDocument(mDoc); + if (nsnull != mDoc) { + nsIDOMDocument* mDOMDoc; + if (NS_OK == mDoc->QueryInterface(kIDOMDocumentIID, (void**) &mDOMDoc)) { + NS_InitEditorMode(mDOMDoc); + NS_RELEASE(mDOMDoc); + } + NS_RELEASE(mDoc); + } + NS_RELEASE(mDViewer); + } + NS_RELEASE(mCViewer); + } + + aWebShell->GetChildCount(n); + for (i = 0; i < n; i++) { + nsIWebShell* mChild; + aWebShell->ChildAt(i, mChild); + DoEditorMode(mChild); + NS_RELEASE(mChild); + } + }*/ +} + +#ifdef NS_DEBUG +#include "nsIContent.h" +#include "nsIFrame.h" +#include "nsIStyleContext.h" +#include "nsISizeOfHandler.h" +#include "nsIStyleSet.h" + + +//---------------------------------------- +void +nsBrowserWindow::DumpContent(FILE* out) +{ + nsIPresShell* shell = GetPresShell(); + if (nsnull != shell) { + nsIDocument* doc = shell->GetDocument(); + if (nsnull != doc) { + nsIContent* root = doc->GetRootContent(); + if (nsnull != root) { + root->List(out); + NS_RELEASE(root); + } + NS_RELEASE(doc); + } + NS_RELEASE(shell); + } + else { + fputs("null pres shell\n", out); + } +} + +void +nsBrowserWindow::DumpFrames(FILE* out, nsString *aFilterName) +{ + nsIPresShell* shell = GetPresShell(); + if (nsnull != shell) { + nsIFrame* root = shell->GetRootFrame(); + if (nsnull != root) { + nsIListFilter *filter = nsIFrame::GetFilter(aFilterName); + root->List(out, 0, filter); + } + NS_RELEASE(shell); + } + else { + fputs("null pres shell\n", out); + } +} + +void +DumpViewsRecurse(nsBrowserWindow* aBrowser, nsIWebShell* aWebShell, FILE* out) +{ + if (nsnull != aWebShell) { + nsIPresShell* shell = aBrowser->GetPresShell(); + if (nsnull != shell) { + nsIViewManager* vm = shell->GetViewManager(); + if (nsnull != vm) { + nsIView* root; + vm->GetRootView(root); + if (nsnull != root) { + root->List(out); + } + NS_RELEASE(vm); + } + NS_RELEASE(shell); + } + else { + fputs("null pres shell\n", out); + } + // dump the views of the sub documents + PRInt32 i, n; + aWebShell->GetChildCount(n); + for (i = 0; i < n; i++) { + nsIWebShell* child; + aWebShell->ChildAt(i, child); + if (nsnull != child) { + DumpViewsRecurse(aBrowser, child, out); + } + } + } +} + +void +nsBrowserWindow::DumpViews(FILE* out) +{ + DumpViewsRecurse(this, mWebShell, out); +} + +static void DumpAWebShell(nsIWebShell* aShell, FILE* out, PRInt32 aIndent) +{ + PRUnichar *name; + nsAutoString str; + nsIWebShell* parent; + PRInt32 i, n; + + for (i = aIndent; --i >= 0; ) fprintf(out, " "); + + fprintf(out, "%p '", aShell); + aShell->GetName(&name); + aShell->GetParent(parent); + str = name; + fputs(str, out); + fprintf(out, "' parent=%p <\n", parent); + NS_IF_RELEASE(parent); + + aIndent++; + aShell->GetChildCount(n); + for (i = 0; i < n; i++) { + nsIWebShell* child; + aShell->ChildAt(i, child); + if (nsnull != child) { + DumpAWebShell(child, out, aIndent); + } + } + aIndent--; + for (i = aIndent; --i >= 0; ) fprintf(out, " "); + fputs(">\n", out); +} + +void +nsBrowserWindow::DumpWebShells(FILE* out) +{ + DumpAWebShell(mWebShell, out, 0); +} + +void +nsBrowserWindow::DumpStyleSheets(FILE* out) +{ + nsIPresShell* shell = GetPresShell(); + if (nsnull != shell) { + nsIStyleSet* styleSet = shell->GetStyleSet(); + if (nsnull == styleSet) { + fputs("null style set\n", out); + } else { + styleSet->List(out); + NS_RELEASE(styleSet); + } + NS_RELEASE(shell); + } + else { + fputs("null pres shell\n", out); + } +} + +void +nsBrowserWindow::DumpStyleContexts(FILE* out) +{ + nsIPresShell* shell = GetPresShell(); + if (nsnull != shell) { + nsIPresContext* cx = shell->GetPresContext(); + nsIStyleSet* styleSet = shell->GetStyleSet(); + if (nsnull == styleSet) { + fputs("null style set\n", out); + } else { + nsIFrame* root = shell->GetRootFrame(); + if (nsnull == root) { + fputs("null root frame\n", out); + } else { + nsIStyleContext* rootContext; + root->GetStyleContext(cx, rootContext); + if (nsnull != rootContext) { + styleSet->ListContexts(rootContext, out); + NS_RELEASE(rootContext); + } + else { + fputs("null root context", out); + } + } + NS_RELEASE(styleSet); + } + NS_IF_RELEASE(cx); + NS_RELEASE(shell); + } else { + fputs("null pres shell\n", out); + } +} + +void +nsBrowserWindow::ToggleFrameBorders() +{ + PRBool showing = nsIFrame::GetShowFrameBorders(); + nsIFrame::ShowFrameBorders(!showing); + ForceRefresh(); +} + +void +nsBrowserWindow::ShowContentSize() +{ + nsISizeOfHandler* szh; + if (NS_OK != NS_NewSizeOfHandler(&szh)) { + return; + } + + nsIPresShell* shell = GetPresShell(); + if (nsnull != shell) { + nsIDocument* doc = shell->GetDocument(); + if (nsnull != doc) { + nsIContent* content = doc->GetRootContent(); + if (nsnull != content) { + content->SizeOf(szh); + PRUint32 totalSize; + szh->GetSize(totalSize); + printf("Content model size is approximately %d bytes\n", totalSize); + NS_RELEASE(content); + } + NS_RELEASE(doc); + } + NS_RELEASE(shell); + } + NS_RELEASE(szh); +} + +void +nsBrowserWindow::ShowFrameSize() +{ + nsIPresShell* shell0 = GetPresShell(); + if (nsnull != shell0) { + nsIDocument* doc = shell0->GetDocument(); + if (nsnull != doc) { + PRInt32 i, shells = doc->GetNumberOfShells(); + for (i = 0; i < shells; i++) { + nsIPresShell* shell = doc->GetShellAt(i); + if (nsnull != shell) { + nsISizeOfHandler* szh; + if (NS_OK != NS_NewSizeOfHandler(&szh)) { + return; + } + nsIFrame* root; + root = shell->GetRootFrame(); + if (nsnull != root) { + root->SizeOf(szh); + PRUint32 totalSize; + szh->GetSize(totalSize); + printf("Frame model for shell=%p size is approximately %d bytes\n", + shell, totalSize); + } + NS_RELEASE(szh); + NS_RELEASE(shell); + } + } + NS_RELEASE(doc); + } + NS_RELEASE(shell0); + } +} + +void +nsBrowserWindow::ShowStyleSize() +{ +} + + + + +static PRBool GetSaveFileNameFromFileSelector(nsIWidget* aParentWindow, + nsString& aFileName) +{ + PRInt32 offset = aFileName.RFind('/'); + if (offset != -1) + aFileName.Cut(0,offset+1); + + PRBool selectedFileName = PR_FALSE; + nsIFileWidget *fileWidget; + nsString title("Save HTML"); + nsresult rv = nsRepository::CreateInstance(kFileWidgetCID, + nsnull, + kIFileWidgetIID, + (void**)&fileWidget); + if (NS_OK == rv) { + nsString titles[] = {"html","txt"}; + nsString filters[] = {"*.html", "*.txt"}; + fileWidget->SetFilterList(2, titles, filters); + fileWidget->Create(aParentWindow, + title, + eMode_save, + nsnull, + nsnull); + fileWidget->SetDefaultString(aFileName); + + PRUint32 result = fileWidget->Show(); + if (result) { + fileWidget->GetFile(aFileName); + selectedFileName = PR_TRUE; + } + + NS_RELEASE(fileWidget); + } + + return selectedFileName; +} + + + + +void +nsBrowserWindow::DoDebugSave() +{ + PRBool doSave = PR_FALSE; + nsString path; + + PRUnichar *urlString; + mWebShell->GetURL(0,&urlString); + nsIURL* url; + nsresult rv = NS_NewURL(&url, urlString); + + if (rv == NS_OK) + { + const char* name = url->GetFile(); + path = name; + + doSave = GetSaveFileNameFromFileSelector(mWindow, path); + NS_RELEASE(url); + + } + if (!doSave) + return; + + + nsIPresShell* shell = GetPresShell(); + if (nsnull != shell) { + nsIDocument* doc = shell->GetDocument(); + if (nsnull != doc) { + nsString buffer; + + doc->CreateXIF(buffer,PR_FALSE); + + nsIParser* parser; + + static NS_DEFINE_IID(kCParserIID, NS_IPARSER_IID); + static NS_DEFINE_IID(kCParserCID, NS_PARSER_IID); + + nsresult rv = nsRepository::CreateInstance(kCParserCID, + nsnull, + kCParserIID, + (void **)&parser); + + if (NS_OK == rv) { + nsIHTMLContentSink* sink = nsnull; + + rv = NS_New_HTML_ContentSinkStream(&sink); + +#ifdef WIN32 +#define BUFFER_SIZE MAX_PATH +#else +#define BUFFER_SIZE 1024 +#endif + char filename[BUFFER_SIZE]; + path.ToCString(filename,BUFFER_SIZE); + ofstream out(filename); + ((nsHTMLContentSinkStream*)sink)->SetOutputStream(out); + + if (NS_OK == rv) { + parser->SetContentSink(sink); + + nsIDTD* dtd = nsnull; + rv = NS_NewXIFDTD(&dtd); + if (NS_OK == rv) + { + parser->RegisterDTD(dtd); + dtd->SetContentSink(sink); + dtd->SetParser(parser); + parser->Parse(buffer, PR_FALSE); + } + out.close(); + + NS_IF_RELEASE(dtd); + NS_IF_RELEASE(sink); + } + NS_RELEASE(parser); + } + NS_RELEASE(doc); + } + NS_RELEASE(shell); + } +} + +void +nsBrowserWindow::DoToggleSelection() +{ + nsIPresShell* shell = GetPresShell(); + if (nsnull != shell) { + nsIDocument* doc = shell->GetDocument(); + if (nsnull != doc) { + PRBool current = doc->GetDisplaySelection(); + doc->SetDisplaySelection(!current); + ForceRefresh(); + NS_RELEASE(doc); + } + NS_RELEASE(shell); + } +} + + +void +nsBrowserWindow::DoDebugRobot() +{ + mApp->CreateRobot(this); +} + +void +nsBrowserWindow::DoSiteWalker() +{ + mApp->CreateSiteWalker(this); +} + +//----------------------------------------------------- +//-- Menu Struct +//----------------------------------------------------- +typedef struct _menuBtns { + char * title; + char * mneu; + long command; +} MenuBtns; + + +//----------------------------------------------------- +nsIMenu * CreateMenu(nsIMenu * aMenu, const nsString & aName, char aMneu) +{ + nsIMenu * menu; + nsresult rv = nsRepository::CreateInstance(kMenuCID, + nsnull, + kIMenuIID, + (void**)&menu); + if (NS_OK == rv) { + nsRect rect; + nsIWidget* widget; + if (NS_OK == menu->QueryInterface(kIWidgetIID,(void**)&widget)) { + widget->Create((nsIWidget *)nsnull, rect, nsnull, nsnull, nsnull, nsnull, nsnull); + NS_RELEASE(widget); + } else { + return nsnull; + } + } else { + return nsnull; + } + + menu->SetLabel(aName); + aMenu->AddMenu(menu); + + return menu; +} + +//----------------------------------------------------- +nsIMenu * CreateMenu(nsIMenuBar * aMenuBar, const nsString & aName, char aMneu) +{ + nsIMenu * menu; + nsresult rv = nsRepository::CreateInstance(kMenuCID, + nsnull, + kIMenuIID, + (void**)&menu); + if (NS_OK == rv) { + nsRect rect; + nsIWidget* widget; + if (NS_OK == menu->QueryInterface(kIWidgetIID,(void**)&widget)) { + widget->Create((nsIWidget *)nsnull, rect, nsnull, nsnull, nsnull, nsnull, nsnull); + NS_RELEASE(widget); + } else { + return nsnull; + } + } else { + return nsnull; + } + + menu->SetLabel(aName); + aMenuBar->AddMenu(menu); + + return menu; +} + +//----------------------------------------------------- +nsIMenuItem * CreateMenuItem(nsIMenu * aMenu, const nsString & aName, PRUint32 aCommand) +{ + nsIMenuItem * menuItem = nsnull; + + if (!aName.Equals("-")) { + nsresult rv = nsRepository::CreateInstance(kMenuItemCID, + nsnull, + kIMenuItemIID, + (void**)&menuItem); + if (NS_OK != rv) { + return nsnull; + } + + menuItem->SetLabel(aName); + menuItem->SetCommand(aCommand); + aMenu->AddItem(menuItem); + } else { + aMenu->AddSeparator(); + } + + return menuItem; +} + +//----------------------------------------------------- +void CreateBrowserMenus(nsIMenuBar * aMenuBar) +{ + MenuBtns editMenus[] = { + {"Cut", "T", VIEWER_EDIT_CUT}, + {"Copy", "C", VIEWER_EDIT_COPY}, + {"Paste", "P", VIEWER_EDIT_PASTE}, + {"-", NULL, 0}, + {"Select All", "A", VIEWER_EDIT_SELECTALL}, + {"-", NULL, 0}, + {"Find in Page", "F", VIEWER_EDIT_FINDINPAGE}, + {NULL, NULL, 0} + }; + + MenuBtns debugMenus[] = { + {"Visual Debugging", "V", VIEWER_VISUAL_DEBUGGING}, + {"Reflow Test", "R", VIEWER_REFLOW_TEST}, + {"-", NULL, 0}, + {"Dump Content", "C", VIEWER_DUMP_CONTENT}, + {"Dump Frames", "F", VIEWER_DUMP_FRAMES}, + {"Dump Views", "V", VIEWER_DUMP_VIEWS}, + {"-", NULL, 0}, + {"Dump Style Sheets", "S", VIEWER_DUMP_STYLE_SHEETS}, + {"Dump Style Contexts", "T", VIEWER_DUMP_STYLE_CONTEXTS}, + {"-", NULL, 0}, + {"Show Content Size", "z", VIEWER_SHOW_CONTENT_SIZE}, + {"Show Frame Size", "a", VIEWER_SHOW_FRAME_SIZE}, + {"Show Style Size", "y", VIEWER_SHOW_STYLE_SIZE}, + {"-", NULL, 0}, + {"Debug Save", "v", VIEWER_DEBUGSAVE}, + {"Debug Toggle Selection", "q", VIEWER_TOGGLE_SELECTION}, + {"-", NULL, 0}, + {"Debug Robot", "R", VIEWER_DEBUGROBOT}, + {"-", NULL, 0}, + {"Show Content Quality", ".", VIEWER_SHOW_CONTENT_QUALITY}, + {NULL, NULL, 0} + }; + + + nsIMenu * fileMenu = CreateMenu(aMenuBar, "File", 'F'); + + CreateMenuItem(fileMenu, "New Window", VIEWER_WINDOW_OPEN); + CreateMenuItem(fileMenu, "Open...", VIEWER_FILE_OPEN); + + nsIMenu * samplesMenu = CreateMenu(fileMenu, "Samples", 'S'); + PRInt32 i = 0; + for (i=0;i<10;i++) { + char buf[64]; + sprintf(buf, "Demo #%d", i); + CreateMenuItem(samplesMenu, buf, VIEWER_DEMO0+i); + } + + CreateMenuItem(fileMenu, "Top 100 Sites", VIEWER_TOP100); + + nsIMenu * printMenu = CreateMenu(fileMenu, "Print Preview", 'P'); + CreateMenuItem(printMenu, "One Column", VIEWER_ONE_COLUMN); + CreateMenuItem(printMenu, "Two Column", VIEWER_TWO_COLUMN); + CreateMenuItem(printMenu, "Three Column", VIEWER_THREE_COLUMN); + + CreateMenuItem(fileMenu, "-", 0); + CreateMenuItem(fileMenu, "Exit", VIEWER_EXIT); + + nsIMenu * editMenu = CreateMenu(aMenuBar, "Edit", 'E'); + i = 0; + while (editMenus[i].title != nsnull) { + CreateMenuItem(editMenu, editMenus[i].title, editMenus[i].command); + i++; + } + nsIMenu * viewMenu = CreateMenu(aMenuBar, "View", 'V'); + CreateMenuItem(viewMenu, "Show", 0); + CreateMenuItem(viewMenu, "-", 0); + CreateMenuItem(viewMenu, "Reload", 0); + CreateMenuItem(viewMenu, "Refresh", 0); + + nsIMenu * goMenu = CreateMenu(aMenuBar, "Go", 'G'); + nsIMenu * commMenu = CreateMenu(aMenuBar, "Communicator", 'C'); + nsIMenu * helpMenu = CreateMenu(aMenuBar, "Help", 'H'); + + /*nsIMenu * debugMenu = CreateMenu(aMenuBar, "Debug", 'D'); + i = 0; + while (debugMenus[i].title != nsnull) { + CreateMenuItem(debugMenu, debugMenus[i].title, debugMenus[i].command); + i++; + } + + nsIMenu * toolsMenu = CreateMenu(aMenuBar, "Tools", 'T'); + CreateMenuItem(toolsMenu, "Java Script Console", JS_CONSOLE); + CreateMenuItem(toolsMenu, "Editor Mode", EDITOR_MODE);*/ + +} + + +//----------------------------------------------------- +nsresult +nsBrowserWindow::CreateMenuBar(PRInt32 aWidth) +{ + /*HMENU menu = ::LoadMenu(gInstance, "Viewer"); + HWND hwnd = (HWND)mWindow->GetNativeData(NS_NATIVE_WIDGET); + ::SetMenu(hwnd, menu); + */ + + nsIMenuBar * menuBar; + + nsresult rv = nsRepository::CreateInstance(kMenuBarCID, + nsnull, + kIMenuBarIID, + (void**)&menuBar); + + if (NS_OK == rv) { + nsRect rect; + nsIWidget* widget; + if (NS_OK == menuBar->QueryInterface(kIWidgetIID,(void**)&widget)) { + widget->Create((nsIWidget *)nsnull, rect, nsnull, nsnull, mAppShell, nsnull, nsnull); + + CreateBrowserMenus(menuBar); + + HMENU menu = (HMENU)widget->GetNativeData(NS_NATIVE_WIDGET); + HWND hwnd = (HWND)mWindow->GetNativeData(NS_NATIVE_WIDGET); + ::SetMenu(hwnd, menu); + NS_RELEASE(widget); + } + + } + + return NS_OK; +} + +nsEventStatus +nsBrowserWindow::DispatchDebugMenu(PRInt32 aID) +{ + nsEventStatus result = nsEventStatus_eIgnore; + + switch(aID) { + case VIEWER_VISUAL_DEBUGGING: + ToggleFrameBorders(); + result = nsEventStatus_eConsumeNoDefault; + break; + + case VIEWER_DUMP_CONTENT: + DumpContent(); + DumpWebShells(); + result = nsEventStatus_eConsumeNoDefault; + break; + + case VIEWER_DUMP_FRAMES: + DumpFrames(); + result = nsEventStatus_eConsumeNoDefault; + break; + + case VIEWER_DUMP_VIEWS: + DumpViews(); + result = nsEventStatus_eConsumeNoDefault; + break; + + case VIEWER_DUMP_STYLE_SHEETS: + DumpStyleSheets(); + result = nsEventStatus_eConsumeNoDefault; + break; + + case VIEWER_DUMP_STYLE_CONTEXTS: + DumpStyleContexts(); + result = nsEventStatus_eConsumeNoDefault; + break; + + case VIEWER_SHOW_CONTENT_SIZE: + ShowContentSize(); + result = nsEventStatus_eConsumeNoDefault; + break; + + case VIEWER_SHOW_FRAME_SIZE: + ShowFrameSize(); + result = nsEventStatus_eConsumeNoDefault; + break; + + case VIEWER_SHOW_STYLE_SIZE: + ShowStyleSize(); + result = nsEventStatus_eConsumeNoDefault; + break; + + case VIEWER_SHOW_CONTENT_QUALITY: +#if XXX_fix_me + if ((nsnull != wd) && (nsnull != wd->observer)) { + nsIPresContext *px = wd->observer->mWebWidget->GetPresContext(); + nsIPresShell *ps = px->GetShell(); + nsIViewManager *vm = ps->GetViewManager(); + + vm->ShowQuality(!vm->GetShowQuality()); + + NS_RELEASE(vm); + NS_RELEASE(ps); + NS_RELEASE(px); + } +#endif + result = nsEventStatus_eConsumeNoDefault; + break; + + case VIEWER_DEBUGSAVE: + DoDebugSave(); + break; + + case VIEWER_TOGGLE_SELECTION: + DoToggleSelection(); + break; + + + case VIEWER_DEBUGROBOT: + DoDebugRobot(); + break; + + case VIEWER_TOP100: + DoSiteWalker(); + break; + } + return(result); +} + +#endif // NS_DEBUG + +//---------------------------------------------------------------------- + +// Factory code for creating nsBrowserWindow's + +class nsBrowserWindowFactory : public nsIFactory +{ +public: + nsBrowserWindowFactory(); + ~nsBrowserWindowFactory(); + + // nsISupports methods + NS_IMETHOD QueryInterface(const nsIID &aIID, void **aResult); + NS_IMETHOD_(nsrefcnt) AddRef(void); + NS_IMETHOD_(nsrefcnt) Release(void); + + // nsIFactory methods + NS_IMETHOD CreateInstance(nsISupports *aOuter, + const nsIID &aIID, + void **aResult); + + NS_IMETHOD LockFactory(PRBool aLock); + +private: + nsrefcnt mRefCnt; +}; + +nsBrowserWindowFactory::nsBrowserWindowFactory() +{ + mRefCnt = 0; +} + +nsBrowserWindowFactory::~nsBrowserWindowFactory() +{ + NS_ASSERTION(mRefCnt == 0, "non-zero refcnt at destruction"); +} + +nsresult +nsBrowserWindowFactory::QueryInterface(const nsIID &aIID, void **aResult) +{ + if (aResult == NULL) { + return NS_ERROR_NULL_POINTER; + } + + // Always NULL result, in case of failure + *aResult = NULL; + + if (aIID.Equals(kISupportsIID)) { + *aResult = (void *)(nsISupports*)this; + } else if (aIID.Equals(kIFactoryIID)) { + *aResult = (void *)(nsIFactory*)this; + } + + if (*aResult == NULL) { + return NS_NOINTERFACE; + } + + NS_ADDREF_THIS(); // Increase reference count for caller + return NS_OK; +} + +nsrefcnt +nsBrowserWindowFactory::AddRef() +{ + return ++mRefCnt; +} + +nsrefcnt +nsBrowserWindowFactory::Release() +{ + if (--mRefCnt == 0) { + delete this; + return 0; // Don't access mRefCnt after deleting! + } + return mRefCnt; +} + +nsresult +nsBrowserWindowFactory::CreateInstance(nsISupports *aOuter, + const nsIID &aIID, + void **aResult) +{ + nsresult rv; + nsBrowserWindow *inst; + + if (aResult == NULL) { + return NS_ERROR_NULL_POINTER; + } + *aResult = NULL; + if (nsnull != aOuter) { + rv = NS_ERROR_NO_AGGREGATION; + goto done; + } + + NS_NEWXPCOM(inst, nsBrowserWindow); + if (inst == NULL) { + rv = NS_ERROR_OUT_OF_MEMORY; + goto done; + } + + NS_ADDREF(inst); + rv = inst->QueryInterface(aIID, aResult); + NS_RELEASE(inst); + +done: + return rv; +} + +nsresult +nsBrowserWindowFactory::LockFactory(PRBool aLock) +{ + // Not implemented in simplest case. + return NS_OK; +} + +nsresult +NS_NewBrowserWindowFactory(nsIFactory** aFactory) +{ + nsresult rv = NS_OK; + nsBrowserWindowFactory* inst; + NS_NEWXPCOM(inst, nsBrowserWindowFactory); + if (nsnull == inst) { + rv = NS_ERROR_OUT_OF_MEMORY; + } + else { + NS_ADDREF(inst); + } + *aFactory = inst; + return rv; +} diff --git a/xpfe/xpviewer/src/nsBrowserWindow.h b/xpfe/xpviewer/src/nsBrowserWindow.h new file mode 100644 index 000000000000..d91a1f51cf5e --- /dev/null +++ b/xpfe/xpviewer/src/nsBrowserWindow.h @@ -0,0 +1,308 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are Copyright (C) 1998 + * Netscape Communications Corporation. All Rights Reserved. + */ +#ifndef nsBrowserWindow_h___ +#define nsBrowserWindow_h___ + +#include "nsIBrowserWindow.h" +#include "nsIStreamListener.h" +#include "nsINetSupport.h" +#include "nsIWebShell.h" +#include "nsIScriptContextOwner.h" +#include "nsString.h" +#include "nsVoidArray.h" +#include "nsCRT.h" + +#include "nsIToolbarManagerListener.h" +#include "nsIImageButtonListener.h" + +class nsILabel; +class nsICheckButton; +class nsIRadioButton; +class nsIDialog; +class nsITextWidget; +class nsIButton; +class nsIThrobber; +class nsViewerApp; +class nsIPresShell; +class nsIPref; +class nsIImageButton; +class nsIMenuButton; +class nsIToolbar; +class nsIToolbarManager; + +#define SAMPLES_BASE_URL "resource:/res/samples" + +/** + * Abstract base class for our test app's browser windows + */ +class nsBrowserWindow : public nsIBrowserWindow, + public nsIStreamObserver, + public nsINetSupport, + public nsIWebShellContainer, + public nsIToolbarManagerListener, + public nsIImageButtonListener +{ +public: + void* operator new(size_t sz) { + void* rv = new char[sz]; + nsCRT::zero(rv, sz); + return rv; + } + + nsBrowserWindow(); + virtual ~nsBrowserWindow(); + + // nsISupports + NS_DECL_ISUPPORTS + + // nsIBrowserWindow + NS_IMETHOD Init(nsIAppShell* aAppShell, + nsIPref* aPrefs, + const nsRect& aBounds, + PRUint32 aChromeMask, + PRBool aAllowPlugins = PR_TRUE); + NS_IMETHOD MoveTo(PRInt32 aX, PRInt32 aY); + NS_IMETHOD SizeTo(PRInt32 aWidth, PRInt32 aHeight); + NS_IMETHOD GetBounds(nsRect& aBounds); + NS_IMETHOD Show(); + NS_IMETHOD Hide(); + NS_IMETHOD Close(); + NS_IMETHOD SetChrome(PRUint32 aNewChromeMask); + NS_IMETHOD GetChrome(PRUint32& aChromeMaskResult); + NS_IMETHOD SetTitle(const PRUnichar* aTitle); + NS_IMETHOD GetTitle(PRUnichar** aResult); + NS_IMETHOD SetStatus(const PRUnichar* aStatus); + NS_IMETHOD SetStatus(const nsString &aStatus); + NS_IMETHOD GetStatus(PRUnichar** aResult); + NS_IMETHOD SetProgress(PRInt32 aProgress, PRInt32 aProgressMax); + NS_IMETHOD GetWebShell(nsIWebShell*& aResult); + NS_IMETHOD HandleEvent(nsGUIEvent * anEvent); + + // nsIStreamObserver + NS_IMETHOD OnStartBinding(nsIURL* aURL, const char *aContentType); + NS_IMETHOD OnProgress(nsIURL* aURL, PRInt32 aProgress, PRInt32 aProgressMax); + NS_IMETHOD OnStatus(nsIURL* aURL, const nsString& aMsg); + NS_IMETHOD OnStopBinding(nsIURL* aURL, PRInt32 status, const nsString &aMsg); + + // nsIWebShellContainer + NS_IMETHOD WillLoadURL(nsIWebShell* aShell, const PRUnichar* aURL, nsLoadType aReason); + NS_IMETHOD BeginLoadURL(nsIWebShell* aShell, const PRUnichar* aURL); + NS_IMETHOD ProgressLoadURL(nsIWebShell* aShell, const PRUnichar* aURL, PRInt32 aProgress, PRInt32 aProgressMax); + NS_IMETHOD EndLoadURL(nsIWebShell* aShell, const PRUnichar* aURL, PRInt32 aStatus); + NS_IMETHOD NewWebShell(nsIWebShell *&aNewWebShell); + + // nsINetSupport + NS_IMETHOD_(void) Alert(const nsString &aText); + NS_IMETHOD_(PRBool) Confirm(const nsString &aText); + NS_IMETHOD_(PRBool) Prompt(const nsString &aText, + const nsString &aDefault, + nsString &aResult); + NS_IMETHOD_(PRBool) PromptUserAndPassword(const nsString &aText, + nsString &aUser, + nsString &aPassword); + NS_IMETHOD_(PRBool) PromptPassword(const nsString &aText, + nsString &aPassword); + + // nsBrowserWindow + virtual nsresult CreateMenuBar(PRInt32 aWidth); + virtual nsresult CreateToolBar(PRInt32 aWidth); + virtual nsresult CreateStatusBar(PRInt32 aWidth); + void Layout(PRInt32 aWidth, PRInt32 aHeight); + void Back(); + void Forward(); + void GoTo(const PRUnichar* aURL); + void StartThrobber(); + void StopThrobber(); + void LoadThrobberImages(); + void DestroyThrobberImages(); + virtual nsEventStatus DispatchMenuItem(PRInt32 aID); + + void DoFileOpen(); + void DoCopy(); + void DoJSConsole(); + void DoEditorMode(nsIWebShell* aWebShell); + nsIPresShell* GetPresShell(); + + void DoFind(); + void DoSelectAll(); + void ForceRefresh(); + + void DoAppsDialog(); + + // nsIToolbarManager Listener Interface + NS_IMETHOD NotifyToolbarManagerChangedSize(nsIToolbarManager* aToolbarMgr); + + // nsIImageButtonListener + NS_IMETHOD NotifyImageButtonEvent(nsIImageButton * aImgBtn, nsGUIEvent* anEvent); + +#ifdef NS_DEBUG + void DumpContent(FILE *out = stdout); + void DumpFrames(FILE *out = stdout, nsString *aFilter = nsnull); + void DumpViews(FILE *out = stdout); + void DumpWebShells(FILE *out = stdout); + void DumpStyleSheets(FILE *out = stdout); + void DumpStyleContexts(FILE *out = stdout); + void ToggleFrameBorders(); + void ShowContentSize(); + void ShowFrameSize(); + void ShowStyleSize(); + void DoDebugSave(); + void DoToggleSelection(); + void DoDebugRobot(); + void DoSiteWalker(); + nsEventStatus DispatchDebugMenu(PRInt32 aID); +#endif + + nsEventStatus ProcessDialogEvent(nsGUIEvent *aEvent); + + + void SetApp(nsViewerApp* aApp) { + mApp = aApp; + } + + static void CloseAllWindows(); + + nsViewerApp* mApp; + + PRUint32 mChromeMask; + nsString mTitle; + + nsIWidget* mWindow; + nsIWebShell* mWebShell; + + nsIWidget ** mAppsDialogBtns; + PRInt32 mNumAppsDialogBtns; + + nsIWidget ** mMiniAppsBtns; + PRInt32 mNumMiniAppsBtns; + + nsIWidget ** mToolbarBtns; + PRInt32 mNumToolbarBtns; + + nsIWidget ** mPersonalToolbarBtns; + PRInt32 mNumPersonalToolbarBtns; + + // "Toolbar" + nsIToolbarManager * mToolbarMgr; + nsIToolbar * mBtnToolbar; + nsIToolbar * mURLToolbar; + + //nsIImageButton* mBack; + //nsIImageButton* mForward; + //nsIImageButton* mReload; + //nsIImageButton* mHome; + //nsIImageButton* mPrint; + //nsIImageButton* mStop; + nsIThrobber* mThrobber; + + nsIMenuButton* mBookmarks; + nsIMenuButton* mWhatsRelated; + nsITextWidget* mLocation; + nsIImageButton* mLocationIcon; + + // nsIWidget for Buttons + //nsIWidget* mBackWidget; + //nsIWidget* mForwardWidget; + //nsIWidget* mReloadWidget; + //nsIWidget* mHomeWidget; + //nsIWidget* mPrintWidget; + //nsIWidget* mStopWidget; + + nsIWidget* mBookmarksWidget; + nsIWidget* mWhatsRelatedWidget; + nsIWidget* mLocationWidget; + nsIWidget* mLocationIconWidget; + + // "Status bar" + nsITextWidget * mStatus; + nsIToolbar * mStatusBar; + nsIImageButton * mStatusSecurityLabel; + nsIImageButton * mStatusProcess; + nsIImageButton * mStatusText; + + // Mini App Bar (in StatusBar) + nsIToolbar * mStatusAppBar; + nsIImageButton * mMiniTab; + nsIImageButton * mMiniNav; + nsIImageButton * mMiniMail; + nsIImageButton * mMiniAddr; + nsIImageButton * mMiniComp; + + nsIWidget * mStatusAppBarWidget; + nsIWidget * mMiniTabWidget; + + // Apps Dialog + nsIDialog * mAppsDialog; + + // Find Dialog + nsIDialog * mDialog; + nsIButton * mCancelBtn; + nsIButton * mFindBtn; + nsITextWidget * mTextField; + nsICheckButton * mMatchCheckBtn; + nsIRadioButton * mUpRadioBtn; + nsIRadioButton * mDwnRadioBtn; + nsILabel * mLabel; + + //for creating more instances + nsIAppShell* mAppShell; //not addref'ed! + nsIPref* mPrefs; //not addref'ed! + PRBool mAllowPlugins; + + // Global window collection + static nsVoidArray gBrowsers; + static void AddBrowser(nsBrowserWindow* aBrowser); + static void RemoveBrowser(nsBrowserWindow* aBrowser); + static nsBrowserWindow* FindBrowserFor(nsIWidget* aWidget, PRIntn aWhich); + static nsBrowserWindow* FindBrowserFor(nsIWidget* aWidget); + +protected: + + + nsresult AddToolbarItem(nsIToolbar *aToolbar, + PRInt32 aGap, + PRBool aEnable, + nsIWidget *aButtonWidget); + + void UpdateToolbarBtns(); + +}; + +// XXX This is bad; because we can't hang a closure off of the event +// callback we have no way to store our This pointer; therefore we +// have to hunt to find the browswer that events belong too!!! + +// aWhich for FindBrowserFor +#define FIND_WINDOW 0 +#define FIND_BACK 1 +#define FIND_FORWARD 2 +#define FIND_LOCATION 3 + +//---------------------------------------------------------------------- + +/*class nsNativeBrowserWindow : public nsBrowserWindow { +public: + nsNativeBrowserWindow(); + ~nsNativeBrowserWindow(); + + virtual nsresult CreateMenuBar(PRInt32 aWidth); + virtual nsEventStatus DispatchMenuItem(PRInt32 aID); +};*/ + +#endif /* nsBrowserWindow_h___ */ diff --git a/xpfe/xpviewer/src/nsSetupRegistry.cpp b/xpfe/xpviewer/src/nsSetupRegistry.cpp new file mode 100644 index 000000000000..6fa84b1d4806 --- /dev/null +++ b/xpfe/xpviewer/src/nsSetupRegistry.cpp @@ -0,0 +1,153 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are Copyright (C) 1998 + * Netscape Communications Corporation. All Rights Reserved. + */ +#ifdef XP_MAC +#include "nsIPref.h" +#define NS_IMPL_IDS +#else +#define NS_IMPL_IDS +#include "nsIPref.h" +#endif + +#include "nsRepository.h" +#include "nsWidgetsCID.h" +#include "nsGfxCIID.h" +#include "nsViewsCID.h" +#include "nsPluginsCID.h" + +#include "nsIBrowserWindow.h" +#include "nsIWebShell.h" +#include "nsIDocumentLoader.h" +#include "nsIThrobber.h" + +#include "nsParserCIID.h" +#include "nsDOMCID.h" + +#ifdef XP_PC +#define WIDGET_DLL "raptorwidget.dll" +#define GFXWIN_DLL "raptorgfxwin.dll" +#define VIEW_DLL "raptorview.dll" +#define WEB_DLL "raptorweb.dll" +#define PLUGIN_DLL "raptorplugin.dll" +#define PREF_DLL "xppref32.dll" +#define PARSER_DLL "raptorhtmlpars.dll" +#define DOM_DLL "jsdom.dll" +#else +#ifdef XP_MAC +#include "nsMacRepository.h" +#else +#define WIDGET_DLL "libwidgetunix.so" +#define GFXWIN_DLL "libgfxunix.so" +#define VIEW_DLL "libraptorview.so" +#define WEB_DLL "libraptorwebwidget.so" +#define PLUGIN_DLL "raptorplugin.so" +#define PREF_DLL "libpref.so" +#define PARSER_DLL "libraptorhtmlpars.so" +#define DOM_DLL "libjsdom.so" +#endif +#endif + +// Class ID's +static NS_DEFINE_IID(kCFileWidgetCID, NS_FILEWIDGET_CID); +static NS_DEFINE_IID(kCWindowCID, NS_WINDOW_CID); +static NS_DEFINE_IID(kCMenuBarCID, NS_MENUBAR_CID); +static NS_DEFINE_IID(kCMenuCID, NS_MENU_CID); +static NS_DEFINE_IID(kCMenuItemCID, NS_MENUITEM_CID); +static NS_DEFINE_IID(kCDialogCID, NS_DIALOG_CID); +static NS_DEFINE_IID(kCLabelCID, NS_LABEL_CID); +static NS_DEFINE_IID(kCAppShellCID, NS_APPSHELL_CID); +static NS_DEFINE_IID(kCWindowIID, NS_WINDOW_CID); +static NS_DEFINE_IID(kCScrollbarIID, NS_VERTSCROLLBAR_CID); +static NS_DEFINE_IID(kCHScrollbarIID, NS_HORZSCROLLBAR_CID); +static NS_DEFINE_IID(kCButtonCID, NS_BUTTON_CID); +static NS_DEFINE_IID(kCComboBoxCID, NS_COMBOBOX_CID); +static NS_DEFINE_IID(kCListBoxCID, NS_LISTBOX_CID); +static NS_DEFINE_IID(kCRadioButtonCID, NS_RADIOBUTTON_CID); +static NS_DEFINE_IID(kCTextAreaCID, NS_TEXTAREA_CID); +static NS_DEFINE_IID(kCTextFieldCID, NS_TEXTFIELD_CID); +static NS_DEFINE_IID(kCCheckButtonIID, NS_CHECKBUTTON_CID); +static NS_DEFINE_IID(kCChildIID, NS_CHILD_CID); +static NS_DEFINE_IID(kCRenderingContextIID, NS_RENDERING_CONTEXT_CID); +static NS_DEFINE_IID(kCDeviceContextIID, NS_DEVICE_CONTEXT_CID); +static NS_DEFINE_IID(kCFontMetricsIID, NS_FONT_METRICS_CID); +static NS_DEFINE_IID(kCImageIID, NS_IMAGE_CID); +static NS_DEFINE_IID(kCRegionIID, NS_REGION_CID); +static NS_DEFINE_IID(kCViewManagerCID, NS_VIEW_MANAGER_CID); +static NS_DEFINE_IID(kCViewCID, NS_VIEW_CID); +static NS_DEFINE_IID(kCScrollingViewCID, NS_SCROLLING_VIEW_CID); +static NS_DEFINE_IID(kWebShellCID, NS_WEB_SHELL_CID); +static NS_DEFINE_IID(kCDocumentLoaderCID, NS_DOCUMENTLOADER_CID); +static NS_DEFINE_IID(kThrobberCID, NS_THROBBER_CID); +static NS_DEFINE_IID(kCPluginHostCID, NS_PLUGIN_HOST_CID); +static NS_DEFINE_IID(kCParserCID, NS_PARSER_IID); +static NS_DEFINE_IID(kLookAndFeelCID, NS_LOOKANDFEEL_CID); +static NS_DEFINE_IID(kCDOMScriptObjectFactory, NS_DOM_SCRIPT_OBJECT_FACTORY_CID); + +static NS_DEFINE_IID(kCImageButtonCID, NS_IMAGEBUTTON_CID); +static NS_DEFINE_IID(kCToolbarCID, NS_TOOLBAR_CID); +static NS_DEFINE_IID(kCToolbarManagerCID, NS_TOOLBARMANAGER_CID); +static NS_DEFINE_IID(kCToolbarItemHolderCID, NS_TOOLBARITEMHOLDER_CID); +static NS_DEFINE_IID(kCPopUpMenuCID, NS_POPUPMENU_CID); +static NS_DEFINE_IID(kCMenuButtonCID, NS_MENUBUTTON_CID); + +extern "C" void +NS_SetupRegistry() +{ + nsRepository::RegisterFactory(kLookAndFeelCID, WIDGET_DLL, PR_FALSE, PR_FALSE); + nsRepository::RegisterFactory(kCWindowIID, WIDGET_DLL, PR_FALSE, PR_FALSE); + nsRepository::RegisterFactory(kCMenuBarCID, WIDGET_DLL, PR_FALSE, PR_FALSE); + nsRepository::RegisterFactory(kCMenuCID, WIDGET_DLL, PR_FALSE, PR_FALSE); + nsRepository::RegisterFactory(kCMenuItemCID, WIDGET_DLL, PR_FALSE, PR_FALSE); + nsRepository::RegisterFactory(kCScrollbarIID, WIDGET_DLL, PR_FALSE, PR_FALSE); + nsRepository::RegisterFactory(kCHScrollbarIID, WIDGET_DLL, PR_FALSE, PR_FALSE); + nsRepository::RegisterFactory(kCDialogCID, WIDGET_DLL, PR_FALSE, PR_FALSE); + nsRepository::RegisterFactory(kCLabelCID, WIDGET_DLL, PR_FALSE, PR_FALSE); + nsRepository::RegisterFactory(kCButtonCID, WIDGET_DLL, PR_FALSE, PR_FALSE); + nsRepository::RegisterFactory(kCComboBoxCID, WIDGET_DLL, PR_FALSE, PR_FALSE); + nsRepository::RegisterFactory(kCFileWidgetCID, WIDGET_DLL, PR_FALSE, PR_FALSE); + nsRepository::RegisterFactory(kCListBoxCID, WIDGET_DLL, PR_FALSE, PR_FALSE); + nsRepository::RegisterFactory(kCRadioButtonCID, WIDGET_DLL, PR_FALSE, PR_FALSE); + nsRepository::RegisterFactory(kCTextAreaCID, WIDGET_DLL, PR_FALSE, PR_FALSE); + nsRepository::RegisterFactory(kCTextFieldCID, WIDGET_DLL, PR_FALSE, PR_FALSE); + nsRepository::RegisterFactory(kCCheckButtonIID, WIDGET_DLL, PR_FALSE, PR_FALSE); + nsRepository::RegisterFactory(kCChildIID, WIDGET_DLL, PR_FALSE, PR_FALSE); + nsRepository::RegisterFactory(kCAppShellCID, WIDGET_DLL, PR_FALSE, PR_FALSE); + nsRepository::RegisterFactory(kCRenderingContextIID, GFXWIN_DLL, PR_FALSE, PR_FALSE); + nsRepository::RegisterFactory(kCDeviceContextIID, GFXWIN_DLL, PR_FALSE, PR_FALSE); + nsRepository::RegisterFactory(kCFontMetricsIID, GFXWIN_DLL, PR_FALSE, PR_FALSE); + nsRepository::RegisterFactory(kCImageIID, GFXWIN_DLL, PR_FALSE, PR_FALSE); + nsRepository::RegisterFactory(kCRegionIID, GFXWIN_DLL, PR_FALSE, PR_FALSE); + nsRepository::RegisterFactory(kCViewManagerCID, VIEW_DLL, PR_FALSE, PR_FALSE); + nsRepository::RegisterFactory(kCViewCID, VIEW_DLL, PR_FALSE, PR_FALSE); + nsRepository::RegisterFactory(kCScrollingViewCID, VIEW_DLL, PR_FALSE, PR_FALSE); + nsRepository::RegisterFactory(kWebShellCID, WEB_DLL, PR_FALSE, PR_FALSE); + nsRepository::RegisterFactory(kCDocumentLoaderCID, WEB_DLL, PR_FALSE, PR_FALSE); + nsRepository::RegisterFactory(kThrobberCID, WEB_DLL, PR_FALSE, PR_FALSE); + nsRepository::RegisterFactory(kPrefCID, PREF_DLL, PR_FALSE, PR_FALSE); + nsRepository::RegisterFactory(kCPluginHostCID, PLUGIN_DLL, PR_FALSE, PR_FALSE); + nsRepository::RegisterFactory(kCParserCID, PARSER_DLL, PR_FALSE, PR_FALSE); + nsRepository::RegisterFactory(kCDOMScriptObjectFactory, DOM_DLL, PR_FALSE, PR_FALSE); + + nsRepository::RegisterFactory(kCImageButtonCID, WIDGET_DLL, PR_FALSE, PR_FALSE); + nsRepository::RegisterFactory(kCToolbarCID, WIDGET_DLL, PR_FALSE, PR_FALSE); + nsRepository::RegisterFactory(kCToolbarManagerCID, WIDGET_DLL, PR_FALSE, PR_FALSE); + nsRepository::RegisterFactory(kCToolbarItemHolderCID, WIDGET_DLL, PR_FALSE, PR_FALSE); + nsRepository::RegisterFactory(kCPopUpMenuCID, WIDGET_DLL, PR_FALSE, PR_FALSE); + nsRepository::RegisterFactory(kCMenuButtonCID, WIDGET_DLL, PR_FALSE, PR_FALSE); + +} diff --git a/xpfe/xpviewer/src/nsViewerApp.cpp b/xpfe/xpviewer/src/nsViewerApp.cpp new file mode 100644 index 000000000000..4caad3047fa6 --- /dev/null +++ b/xpfe/xpviewer/src/nsViewerApp.cpp @@ -0,0 +1,1248 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are Copyright (C) 1998 + * Netscape Communications Corporation. All Rights Reserved. + */ + +#include "nsViewerApp.h" +#include "nsBrowserWindow.h" +#include "nsWidgetsCID.h" +#include "nsIAppShell.h" +#include "nsIPref.h" +#include "nsINetService.h" +#include "nsRepository.h" +//#include "nsWebCrawler.h" +#include "prprf.h" +#include "plstr.h" +#include "prenv.h" + +// Needed for Dialog GUI +#include "nsIDialog.h" +#include "nsICheckButton.h" +#include "nsILabel.h" +#include "nsIButton.h" +#include "nsITextWidget.h" +#include "nsILookAndFeel.h" +#include "nsColor.h" +#include "nsWidgetSupport.h" + +// XXX For font setting below +#include "nsFont.h" +#include "nsUnitConversion.h" +#include "nsIDeviceContext.h" + +#define DIALOG_FONT "Helvetica" +#define DIALOG_FONT_SIZE 10 + + +#ifdef XP_PC +#include "JSConsole.h" +#endif + +extern nsresult NS_NewBrowserWindowFactory(nsIFactory** aFactory); +extern "C" void NS_SetupRegistry(); + +static NS_DEFINE_IID(kAppShellCID, NS_APPSHELL_CID); +static NS_DEFINE_IID(kBrowserWindowCID, NS_BROWSER_WINDOW_CID); + +static NS_DEFINE_IID(kIAppShellIID, NS_IAPPSHELL_IID); +static NS_DEFINE_IID(kIBrowserWindowIID, NS_IBROWSER_WINDOW_IID); +static NS_DEFINE_IID(kINetContainerApplicationIID, + NS_INETCONTAINERAPPLICATION_IID); +static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); + + + + +nsViewerApp::nsViewerApp() +{ + char * text = PR_GetEnv("NGLAYOUT_HOME"); + mStartURL = text ? text : "resource:/res/samples/test0.html"; + mDelay = 1; + mRepeatCount = 1; + mNumSamples = 10; + mAllowPlugins = PR_TRUE; + mIsInitialized = PR_FALSE; +} + +nsViewerApp::~nsViewerApp() +{ + Destroy(); + if (nsnull != mPrefs) { + mPrefs->Shutdown(); + NS_RELEASE(mPrefs); + } +} + +NS_IMPL_ADDREF(nsViewerApp) +NS_IMPL_RELEASE(nsViewerApp) + +nsresult +nsViewerApp::QueryInterface(REFNSIID aIID, void** aInstancePtrResult) +{ + NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer"); + if (nsnull == aInstancePtrResult) { + return NS_ERROR_NULL_POINTER; + } + if (aIID.Equals(kINetContainerApplicationIID)) { + *aInstancePtrResult = (void*) ((nsIBrowserWindow*)this); + AddRef(); + return NS_OK; + } + if (aIID.Equals(kISupportsIID)) { + *aInstancePtrResult = (void*) ((nsISupports*)((nsIBrowserWindow*)this)); + AddRef(); + return NS_OK; + } + return NS_NOINTERFACE; +} + +void +nsViewerApp::Destroy() +{ + // Close all of our windows + nsBrowserWindow::CloseAllWindows(); + + // Release the crawler + //NS_IF_RELEASE(mCrawler); + + // Only shutdown if Initialize has been called... + if (PR_TRUE == mIsInitialized) { + NS_ShutdownINetService(); + mIsInitialized = PR_FALSE; + } +} + +nsresult +nsViewerApp::SetupRegistry() +{ + NS_SetupRegistry(); + + // Register our browser window factory + nsIFactory* bwf; + NS_NewBrowserWindowFactory(&bwf); + nsRepository::RegisterFactory(kBrowserWindowCID, bwf, PR_FALSE); + + return NS_OK; +} + +nsresult +nsViewerApp::Initialize(int argc, char** argv) +{ + nsresult rv; + + rv = SetupRegistry(); + if (NS_OK != rv) { + return rv; + } + + // Create widget application shell + rv = nsRepository::CreateInstance(kAppShellCID, nsnull, kIAppShellIID, + (void**)&mAppShell); + if (NS_OK != rv) { + return rv; + } + mAppShell->Create(&argc, argv); + mAppShell->SetDispatchListener((nsDispatchListener*) this); + + // Load preferences + rv = nsRepository::CreateInstance(kPrefCID, NULL, kIPrefIID, + (void **) &mPrefs); + if (NS_OK != rv) { + return rv; + } + mPrefs->Startup("prefs.js"); + + // Setup networking library + rv = NS_InitINetService((nsINetContainerApplication*) this); + if (NS_OK != rv) { + return rv; + } + +#if 0 + // XXX where should this live + for (int i=0; iMakeRLWindowWithCallback(DumpRLValues, this); + } +#endif + + // Finally process our arguments + rv = ProcessArguments(argc, argv); + + mIsInitialized = PR_TRUE; + return rv; +} + +nsresult +nsViewerApp::Run() +{ + return mAppShell->Run(); +} + + +nsresult +nsViewerApp::Exit() +{ + Destroy(); + mAppShell->Exit(); + NS_RELEASE(mAppShell); + return NS_OK; +} + +static void +PrintHelpInfo(char **argv) +{ + fprintf(stderr, "Usage: %s [-p][-q][-md #][-f filename][-d #][-np] [starting url]\n", argv[0]); + fprintf(stderr, "\t-p[#] -- run purify, optionally with a # that says which sample to stop at. For example, -p2 says to run samples 0, 1, and 2.\n"); + fprintf(stderr, "\t-q -- run quantify\n"); + fprintf(stderr, "\t-md # -- set the crt debug flags to #\n"); + fprintf(stderr, "\t-d # -- set the delay between URL loads to # (in milliseconds)\n"); + fprintf(stderr, "\t-r # -- set the repeat count, which is the number of times the URLs will be loaded in batch mode.\n"); + fprintf(stderr, "\t-f filename -- read a list of URLs from \n"); + fprintf(stderr, "\t-o dirname -- create an output file for the frame dump of each page and put it in \n\t\t must include the trailing character appropriate for your OS\n"); + fprintf(stderr, "\t-h # -- the initial height of the viewer window."); + fprintf(stderr, "\t-w # -- the initial width of the viewer window."); + fprintf(stderr, "\t-filter filtername -- make 'Dump Frames' command use the filter to alter the output.\n\t\tfiltername = none, dump all frames\n\t\tfiltername = table, dump only table frames\n"); + fprintf(stderr, "\t-C -- enable crawler\n"); + fprintf(stderr, "\t-R filename -- record pages visited in \n"); + fprintf(stderr, "\t-S domain -- add a domain/host that is safe to crawl (e.g. www.netscape.com)\n"); + fprintf(stderr, "\t-A domain -- add a domain/host that should be avoided (e.g. microsoft.com)\n"); + fprintf(stderr, "\t-N pages -- set the max # of pages to crawl\n"); + fprintf(stderr, "\t-np -- no plugins\n"); +} + +/*static void +AddTestDocsFromFile(nsWebCrawler* aCrawler, const nsString& aFileName) +{ + char cfn[1000]; + aFileName.ToCString(cfn, sizeof(cfn)); +#ifdef XP_PC + FILE* fp = fopen(cfn, "rb"); +#else + FILE* fp = fopen(cfn, "r"); +#endif + + if (nsnull==fp) + { + fprintf(stderr, "Input file not found: %s\n", cfn); + exit (-1); + } + nsAutoString line; + for (;;) { + char linebuf[2000]; + char* cp = fgets(linebuf, sizeof(linebuf), fp); + if (nsnull == cp) { + break; + } + if (linebuf[0] == '#') { + continue; + } + + // strip crlf's from the line + int len = strlen(linebuf); + if (0 != len) { + if (('\n' == linebuf[len-1]) || ('\r' == linebuf[len-1])) { + linebuf[--len] = 0; + } + } + if (0 != len) { + if (('\n' == linebuf[len-1]) || ('\r' == linebuf[len-1])) { + linebuf[--len] = 0; + } + } + + // Add non-empty lines to the test list + if (0 != len) { + line = linebuf; + aCrawler->AddURL(line); + } + } + + fclose(fp); +}*/ + +NS_IMETHODIMP +nsViewerApp::ProcessArguments(int argc, char** argv) +{ + /*mCrawler = new nsWebCrawler(this); + mCrawler->AddRef(); + + int i; + for (i = 1; i < argc; i++) { + if (argv[i][0] == '-') { + if (PL_strncmp(argv[i], "-p", 2) == 0) { + char *optionalSampleStopIndex = &(argv[i][2]); + if ('\0' != *optionalSampleStopIndex) + { + if (1!=sscanf(optionalSampleStopIndex, "%d", &mNumSamples)) + { + PrintHelpInfo(argv); + exit(-1); + } + } + mDoPurify = PR_TRUE; + mCrawler->SetExitOnDone(PR_TRUE); + mCrawl = PR_TRUE; + } + else if (PL_strcmp(argv[i], "-q") == 0) { + mCrawler->EnableJiggleLayout(); + mCrawler->SetExitOnDone(PR_TRUE); + mCrawl = PR_TRUE; + } + else if (PL_strcmp(argv[i], "-f") == 0) { + mLoadTestFromFile = PR_TRUE; + i++; + if (i>=argc || nsnull==argv[i] || nsnull==*(argv[i])) + { + PrintHelpInfo(argv); + exit(-1); + } + mInputFileName = argv[i]; + mCrawler->SetExitOnDone(PR_TRUE); + mCrawl = PR_TRUE; + } + else if (PL_strcmp(argv[i], "-o") == 0) { + i++; + if (i>=argc || nsnull==argv[i] || nsnull==*(argv[i])) + { + PrintHelpInfo(argv); + exit(-1); + } + mCrawler->SetOutputDir(argv[i]); + } + else if (PL_strcmp(argv[i], "-filter") == 0) { + i++; + if (i>=argc || nsnull==argv[i] || nsnull==*(argv[i])) + { + PrintHelpInfo(argv); + exit(-1); + } + mCrawler->SetFilter(argv[i]); + } + else if (PL_strcmp(argv[i], "-d") == 0) { + int delay; + i++; + if (i>=argc || 1!=sscanf(argv[i], "%d", &delay)) + { + PrintHelpInfo(argv); + exit(-1); + } + mCrawler->SetDelay(delay); + } + else if (PL_strcmp(argv[i], "-w") == 0) { + int width; + i++; + if (i>=argc || 1!=sscanf(argv[i], "%d", &width)) + { + PrintHelpInfo(argv); + exit(-1); + } + mCrawler->SetWidth(width); + } + else if (PL_strcmp(argv[i], "-h") == 0) { + int height; + i++; + if (i>=argc || 1!=sscanf(argv[i], "%d", &height)) + { + PrintHelpInfo(argv); + exit(-1); + } + mCrawler->SetHeight(height); + } + else if (PL_strcmp(argv[i], "-r") == 0) { + i++; + if (i>=argc || 1!=sscanf(argv[i], "%d", &mRepeatCount)) + { + PrintHelpInfo(argv); + exit(-1); + } + } + else if (PL_strcmp(argv[i], "-C") == 0) { + mCrawler->EnableCrawler(); + mCrawler->SetExitOnDone(PR_TRUE); + mCrawl = PR_TRUE; + } + else if (PL_strcmp(argv[i], "-R") == 0) { + i++; + if (i>=argc) { + PrintHelpInfo(argv); + exit(-1); + } + FILE* fp = fopen(argv[i], "w"); + if (nsnull == fp) { + fprintf(stderr, "can't create '%s'\n", argv[i]); + exit(-1); + } + mCrawler->SetRecordFile(fp); + } + else if (PL_strcmp(argv[i], "-S") == 0) { + i++; + if (i>=argc) { + PrintHelpInfo(argv); + exit(-1); + } + mCrawler->AddSafeDomain(argv[i]); + } + else if (PL_strcmp(argv[i], "-A") == 0) { + i++; + if (i>=argc) { + PrintHelpInfo(argv); + exit(-1); + } + mCrawler->AddAvoidDomain(argv[i]); + } + else if (PL_strcmp(argv[i], "-N") == 0) { + int pages; + i++; + if (i>=argc || 1!=sscanf(argv[i], "%d", &pages)) { + PrintHelpInfo(argv); + exit(-1); + } + mCrawler->SetMaxPages(pages); + } + else if (PL_strcmp(argv[i], "-np") == 0) { + mAllowPlugins = PR_FALSE; + } + else { + PrintHelpInfo(argv); + exit(-1); + } + } + else + break; + } + if (i < argc) { + mStartURL = argv[i]; + }*/ + return NS_OK; +} + +NS_IMETHODIMP +nsViewerApp::OpenWindow() +{ + // Create browser window + // XXX Some piece of code needs to properly hold the reference to this + // browser window. For the time being the reference is released by the + // browser event handling code during processing of the NS_DESTROY event... + nsBrowserWindow* bw = nsnull; + nsresult rv = nsRepository::CreateInstance(kBrowserWindowCID, nsnull, + kIBrowserWindowIID, + (void**) &bw); + bw->SetApp(this); + bw->Init(mAppShell, mPrefs, nsRect(0, 0, 620, 400), PRUint32(~0), mAllowPlugins); + bw->Show(); + //mCrawler->SetBrowserWindow(bw); + + /*if (mDoPurify) { + for (PRInt32 i = 0; i < mRepeatCount; i++) { + for (int docnum = 0; docnum < mNumSamples; docnum++) { + char url[500]; + PR_snprintf(url, 500, "%s/test%d.html", SAMPLES_BASE_URL, docnum); + mCrawler->AddURL(url); + } + } + mCrawler->Start(); + } + else if (mLoadTestFromFile) { + for (PRInt32 i = 0; i < mRepeatCount; i++) { + AddTestDocsFromFile(mCrawler, mInputFileName); + } + mCrawler->Start(); + } + else if (mCrawl) { + mCrawler->AddURL(mStartURL); + mCrawler->Start(); + } + else {*/ + bw->GoTo(mStartURL); + //} + NS_RELEASE(bw); + + return NS_OK; +} + +NS_IMETHODIMP +nsViewerApp::OpenWindow(PRUint32 aNewChromeMask, nsIBrowserWindow*& aNewWindow) +{ + // Create browser window + nsBrowserWindow* bw = nsnull; + nsresult rv = nsRepository::CreateInstance(kBrowserWindowCID, nsnull, + kIBrowserWindowIID, + (void**) &bw); + bw->SetApp(this); + bw->Init(mAppShell, mPrefs, nsRect(0, 0, 620, 400), aNewChromeMask, mAllowPlugins); + + aNewWindow = bw; + + return NS_OK; +} + +//---------------------------------------- + +// nsINetContainerApplication implementation + +NS_IMETHODIMP +nsViewerApp::GetAppCodeName(nsString& aAppCodeName) +{ + aAppCodeName.SetString("Mozilla"); + return NS_OK; +} + +NS_IMETHODIMP +nsViewerApp::GetAppVersion(nsString& aAppVersion) +{ + //This seems kinda wrong in x-platform code + aAppVersion.SetString("4.05 [en] (WinNT;I)"); + return NS_OK; +} + +NS_IMETHODIMP +nsViewerApp::GetAppName(nsString& aAppName) +{ + aAppName.SetString("Netscape"); + return NS_OK; +} + +NS_IMETHODIMP +nsViewerApp::GetLanguage(nsString& aLanguage) +{ + aLanguage.SetString("en"); + return NS_OK; +} + +NS_IMETHODIMP +nsViewerApp::GetPlatform(nsString& aPlatform) +{ + //This seems kinda wrong in x-platform code + aPlatform.SetString("Win32"); + return NS_OK; +} + +//---------------------------------------- + +// nsDispatchListener implementation + +void +nsViewerApp::AfterDispatch() +{ +} + +//---------------------------------------- + +#include "prenv.h" +#include "resources.h" +#include "nsIPresShell.h" +#include "nsIDocument.h" +#include "nsIURL.h" + +#ifndef XP_PC +#ifndef XP_MAC +#define _MAX_PATH 512 +#endif +#endif + +#define DEBUG_EMPTY "(none)" +static PRInt32 gDebugRobotLoads = 5000; +static char gVerifyDir[_MAX_PATH]; +static PRBool gVisualDebug = TRUE; + +// Robot +static nsIDialog * mRobotDialog = nsnull; +static nsIButton * mCancelBtn; +static nsIButton * mStartBtn; +static nsITextWidget * mVerDirTxt; +static nsITextWidget * mStopAfterTxt; +static nsICheckButton * mUpdateChkBtn; + +// Site +static nsIDialog * mSiteDialog = nsnull; +static nsIButton * mSiteCancelBtn; +static nsIButton * mSitePrevBtn; +static nsIButton * mSiteNextBtn; +static nsILabel * mSiteLabel; + +static NS_DEFINE_IID(kLookAndFeelCID, NS_LOOKANDFEEL_CID); +static NS_DEFINE_IID(kButtonCID, NS_BUTTON_CID); +static NS_DEFINE_IID(kTextFieldCID, NS_TEXTFIELD_CID); +static NS_DEFINE_IID(kWindowCID, NS_WINDOW_CID); +static NS_DEFINE_IID(kDialogCID, NS_DIALOG_CID); +static NS_DEFINE_IID(kCheckButtonCID, NS_CHECKBUTTON_CID); +static NS_DEFINE_IID(kLabelCID, NS_LABEL_CID); + +static NS_DEFINE_IID(kILookAndFeelIID, NS_ILOOKANDFEEL_IID); +static NS_DEFINE_IID(kIButtonIID, NS_IBUTTON_IID); +static NS_DEFINE_IID(kITextWidgetIID, NS_ITEXTWIDGET_IID); +static NS_DEFINE_IID(kIWidgetIID, NS_IWIDGET_IID); +static NS_DEFINE_IID(kIDialogIID, NS_IDIALOG_IID); +static NS_DEFINE_IID(kICheckButtonIID, NS_ICHECKBUTTON_IID); +static NS_DEFINE_IID(kILabelIID, NS_ILABEL_IID); + + +static void* GetWidgetNativeData(nsISupports* aObject) +{ + void* result = nsnull; + nsIWidget* widget; + if (NS_OK == aObject->QueryInterface(kIWidgetIID,(void**)&widget)) + { + result = widget->GetNativeData(NS_NATIVE_WIDGET); + NS_RELEASE(widget); + } + return result; +} + + + + +#ifdef XP_PC +extern JSConsole *gConsole; +// XXX temporary robot code until it's made XP +extern HINSTANCE gInstance, gPrevInstance; + +/*extern "C" NS_EXPORT int DebugRobot( + nsVoidArray * workList, nsIWebShell * ww, + int imax, char * verify_dir, + void (*yieldProc)(const char *)); + +void yieldProc(const char * str) +{ + // Process messages + MSG msg; + while (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) { + GetMessage(&msg, NULL, 0, 0); + if (!JSConsole::sAccelTable || + !gConsole || + !gConsole->GetMainWindow() || + !TranslateAccelerator(gConsole->GetMainWindow(), + JSConsole::sAccelTable, &msg)) { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } +}*/ +#endif + + +/**-------------------------------------------------------------------------------- + * HandleRobotEvent + *-------------------------------------------------------------------------------- + */ +nsEventStatus PR_CALLBACK HandleRobotEvent(nsGUIEvent *aEvent) +{ + nsEventStatus result = nsEventStatus_eIgnore; + if (aEvent == nsnull || aEvent->widget == nsnull) { + return result; + } + + switch(aEvent->message) { + case NS_MOUSE_LEFT_BUTTON_UP: { + if (aEvent->widget->GetNativeData(NS_NATIVE_WIDGET) == GetWidgetNativeData(mCancelBtn)) { + NS_ShowWidget(mRobotDialog,PR_FALSE); + } else if (aEvent->widget->GetNativeData(NS_NATIVE_WIDGET) == GetWidgetNativeData(mStartBtn)) { + + nsString str; + PRUint32 size; + + mStopAfterTxt->GetText(str, 255, size); + char * cStr = str.ToNewCString(); + sscanf(cStr, "%d", &gDebugRobotLoads); + if (gDebugRobotLoads <= 0) { + gDebugRobotLoads = 5000; + } + delete[] cStr; + + mVerDirTxt->GetText(str, 255, size); + str.ToCString(gVerifyDir, (PRInt32)_MAX_PATH); + if (!strcmp(gVerifyDir,DEBUG_EMPTY)) { + gVerifyDir[0] = '\0'; + } + PRBool state = PR_FALSE; + mUpdateChkBtn->GetState(state); + gVisualDebug = state ? TRUE: FALSE; + + } + + } break; + + case NS_PAINT: +#ifndef XP_UNIX + // paint the background + if (aEvent->widget->GetNativeData(NS_NATIVE_WIDGET) == mRobotDialog ) { + nsIRenderingContext *drawCtx = ((nsPaintEvent*)aEvent)->renderingContext; + drawCtx->SetColor(aEvent->widget->GetBackgroundColor()); + drawCtx->FillRect(*(((nsPaintEvent*)aEvent)->rect)); + + return nsEventStatus_eIgnore; + } +#endif + break; + + default: + result = nsEventStatus_eIgnore; + } //switch + + return result; +} + +//-------------------------------------------- +// +//-------------------------------------------- +PRBool CreateRobotDialog(nsIWidget * aParent) +{ + + PRBool result = TRUE; + + if (mRobotDialog != nsnull) { + NS_ShowWidget(mRobotDialog,PR_TRUE); + NS_SetFocusToWidget(mStartBtn); + return TRUE; + } + + nsILabel * label; + + nsIDeviceContext* dc = aParent->GetDeviceContext(); + float t2d; + dc->GetTwipsToDevUnits(t2d); + nsFont font(DIALOG_FONT, NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL, + NS_FONT_WEIGHT_NORMAL, 0, + nscoord(t2d * NSIntPointsToTwips(DIALOG_FONT_SIZE))); + NS_RELEASE(dc); + + nscoord dialogWidth = 375; + // create a Dialog + // + nsRect rect; + rect.SetRect(0, 0, dialogWidth, 162); + + nsRepository::CreateInstance(kDialogCID, nsnull, kIDialogIID, (void**)&mRobotDialog); + NS_CreateDialog(aParent, mRobotDialog,rect,HandleRobotEvent,&font); + mRobotDialog->SetLabel("Debug Robot Options"); + + nscoord txtHeight = 24; + nscolor textBGColor = NS_RGB(255,255,255); + nscolor textFGColor = NS_RGB(255,255,255); + + nsILookAndFeel * lookAndFeel; + if (NS_OK == nsRepository::CreateInstance(kLookAndFeelCID, nsnull, kILookAndFeelIID, (void**)&lookAndFeel)) { + lookAndFeel->GetMetric(nsILookAndFeel::eMetric_TextFieldHeight, txtHeight); + lookAndFeel->GetColor(nsILookAndFeel::eColor_TextBackground, textBGColor); + lookAndFeel->GetColor(nsILookAndFeel::eColor_TextForeground, textFGColor); + } + + nscoord w = 65; + nscoord x = 5; + nscoord y = 10; + nscoord h = 19; + + // Create Update CheckButton + rect.SetRect(x, y, 150, 24); + nsRepository::CreateInstance(kCheckButtonCID, nsnull, kICheckButtonIID, (void**)&mUpdateChkBtn); + NS_CreateCheckButton(mRobotDialog, mUpdateChkBtn,rect,HandleRobotEvent,&font); + mUpdateChkBtn->SetLabel("Update Display (Visual)"); + mUpdateChkBtn->SetState(PR_TRUE); + y += 24 + 2; + + // Create Label + w = 115; + rect.SetRect(x, y+3, w, 24); + nsRepository::CreateInstance(kLabelCID, nsnull, kILabelIID, (void**)&label); + NS_CreateLabel(mRobotDialog,label,rect,HandleRobotEvent,&font); + label->SetAlignment(eAlign_Right); + label->SetLabel("Verfication Directory:"); + x += w + 1; + + // Create TextField + nsIWidget* widget = nsnull; + rect.SetRect(x, y, 225, txtHeight); + nsRepository::CreateInstance(kTextFieldCID, nsnull, kITextWidgetIID, (void**)&mVerDirTxt); + NS_CreateTextWidget(mRobotDialog,mVerDirTxt,rect,HandleRobotEvent,&font); + if (mVerDirTxt && NS_OK == mVerDirTxt->QueryInterface(kIWidgetIID,(void**)&widget)) + { + widget->SetBackgroundColor(textBGColor); + widget->SetForegroundColor(textFGColor); + } + nsString str(DEBUG_EMPTY); + PRUint32 size; + mVerDirTxt->SetText(str,size); + + y += txtHeight + 2; + + x = 5; + w = 55; + rect.SetRect(x, y+4, w, 24); + nsRepository::CreateInstance(kLabelCID, nsnull, kILabelIID, (void**)&label); + NS_CreateLabel(mRobotDialog,label,rect,HandleRobotEvent,&font); + label->SetAlignment(eAlign_Right); + label->SetLabel("Stop after:"); + x += w + 2; + + // Create TextField + rect.SetRect(x, y, 75, txtHeight); + nsRepository::CreateInstance(kTextFieldCID, nsnull, kITextWidgetIID, (void**)&mStopAfterTxt); + NS_CreateTextWidget(mRobotDialog,mStopAfterTxt,rect,HandleRobotEvent,&font); + if (mStopAfterTxt && NS_OK == mStopAfterTxt->QueryInterface(kIWidgetIID,(void**)&widget)) + { + widget->SetBackgroundColor(textBGColor); + widget->SetForegroundColor(textFGColor); + mStopAfterTxt->SetText("5000",size); + } + x += 75 + 2; + + w = 75; + rect.SetRect(x, y+4, w, 24); + nsRepository::CreateInstance(kLabelCID, nsnull, kILabelIID, (void**)&label); + NS_CreateLabel(mRobotDialog,label,rect,HandleRobotEvent,&font); + label->SetAlignment(eAlign_Left); + label->SetLabel("(page loads)"); + y += txtHeight + 2; + + + y += 10; + w = 75; + nscoord xx = (dialogWidth - (2*w)) / 3; + // Create Find Start Button + rect.SetRect(xx, y, w, 24); + nsRepository::CreateInstance(kButtonCID, nsnull, kIButtonIID, (void**)&mStartBtn); + NS_CreateButton(mRobotDialog,mStartBtn,rect,HandleRobotEvent,&font); + mStartBtn->SetLabel("Start"); + + xx += w + xx; + // Create Cancel Button + rect.SetRect(xx, y, w, 24); + nsRepository::CreateInstance(kButtonCID, nsnull, kIButtonIID, (void**)&mCancelBtn); + NS_CreateButton(mRobotDialog,mCancelBtn,rect,HandleRobotEvent,&font); + mCancelBtn->SetLabel("Cancel"); + + NS_ShowWidget(mRobotDialog,PR_TRUE); + NS_SetFocusToWidget(mStartBtn); + return result; +} + + +NS_IMETHODIMP +nsViewerApp::CreateRobot(nsBrowserWindow* aWindow) +{ + if (CreateRobotDialog(aWindow->mWindow)) + { + nsIPresShell* shell = aWindow->GetPresShell(); + if (nsnull != shell) { + nsIDocument* doc = shell->GetDocument(); + if (nsnull!=doc) { + const char * str = doc->GetDocumentURL()->GetSpec(); + nsVoidArray * gWorkList = new nsVoidArray(); + gWorkList->AppendElement(new nsString(str)); +#if defined(XP_PC) && defined(NS_DEBUG) + /*DebugRobot( + gWorkList, + gVisualDebug ? aWindow->mWebShell : nsnull, + gDebugRobotLoads, + PL_strdup(gVerifyDir), + yieldProc);*/ +#endif + } + } + } + return NS_OK; +} + + +//---------------------------------------- +static nsBrowserWindow* gWinData; +static int gTop100Pointer = 0; +static char * gTop100List[] = { + "http://www.yahoo.com", + "http://www.netscape.com", + "http://www.microsoft.com", + "http://www.excite.com", + "http://www.mckinley.com", + "http://www.city.net", + "http://www.webcrawler.com", + "http://www.mirabilis.com", + "http://www.infoseek.com", + "http://www.pathfinder.com", + "http://www.warnerbros.com", + "http://www.cnn.com", + "http://www.altavista.digital.com", + "http://www.altavista.com", + "http://www.usatoday.com", + "http://www.disney.com", + "http://www.starwave.com", + "http://www.hotwired.com", + "http://www.hotbot.com", + "http://www.lycos.com", + "http://www.pointcom.com", + "http://www.cnet.com", + "http://www.search.com", + "http://www.news.com", + "http://www.download.com", + "http://www.geocities.com", + "http://www.aol.com", + "http://members.aol.com", + "http://www.imdb.com", + "http://uk.imdb.com", + "http://www.macromedia.com", + "http://www.infobeat.com", + "http://www.fxweb.com", + "http://www.whowhere.com", + "http://www.real.com", + "http://www.sportsline.com", + "http://www.dejanews.com", + "http://www.the-park.com", + "http://www.cmpnet.com", + "http://www.go2net.com", + "http://www.metacrawler.com", + "http://www.playsite.com", + "http://www.stocksite.com", + "http://www.sony.com", + "http://www.music.sony.com", + "http://www.station.sony.com", + "http://www.scea.sony.com", + "http://www.infospace.com", + "http://www.zdnet.com", + "http://www.hotfiles.com", + "http://www.chathouse.com", + "http://www.looksmart.com", + "http://www.iamginegames.com", + "http://www.macaddict.com", + "http://www.rsac.org", + "http://www.apple.com", + "http://www.beseen.com", + "http://www.dogpile.com", + "http://www.xoom.com", + "http://www.tucows.com", + "http://www.freethemes.com", + "http://www.winfiles.com", + "http://www.vservers.com", + "http://www.mtv.com", + "http://www.the-xfiles.com", + "http://www.datek.com", + "http://www.cyberthrill.com", + "http://www.surplusdirect.com", + "http://www.tomshardware.com", + "http://www.bigyellow.com", + "http://www.100hot.com", + "http://www.messagemates.com", + "http://www.onelist.com", + "http://www.bluemountain.com", + "http://www.ea.com", + "http://www.bullfrog.co.uk", + "http://www.travelocity.com", + "http://www.ibm.com", + "http://www.bigcharts.com", + "http://www.davesclassics.com", + "http://www.goto.com", + "http://www.weather.com", + "http://www.gamespot.com", + "http://www.bloomberg.com", + "http://www.winzip.com", + "http://www.filez.com", + "http://www.westwood.com", + "http://www.internet.com", + "http://www.cardmaster.com", + "http://www.creaf.com", + "http://netaddress.usa.net", + "http://www.occ.com", + "http://www.as.org", + "http://www.amazon.com", + "http://www.drudgereport.com", + "http://www.hardradio.com", + "http://www.intel.com", + "http://www.mp3.com", + "http://www.ebay.com", + "http://www.msn.com", + "http://www.fifa.com", + "http://www.attitude.com", + "http://www.happypuppy.com", + "http://www.gamesdomain.com", + "http://www.onsale.com", + "http://www.tm.com", + "http://www.xlnc1.com", + "http://www.greatsports.com", + "http://www.discovery.com", + "http://www.nai.com", + "http://www.nasa.gov", + "http://www.ogr.com", + "http://www.warzone.com", + "http://www.gamestats.com", + "http://www.winamp.com", + "http://java.sun.com", + "http://www.hp.com", + "http://www.cdnow.com", + "http://www.nytimes.com", + "http://www.majorleaguebaseball.com", + "http://www.washingtonpost.com", + "http://www.planetquake.com", + "http://www.wsj.com", + "http://www.slashdot.org", + "http://www.adobe.com", + "http://www.quicken.com", + "http://www.talkcity.com", + "http://www.developer.com", + "http://www.mapquest.com", + 0 + }; + + +/**-------------------------------------------------------------------------------- + * HandleSiteEvent + *-------------------------------------------------------------------------------- + */ +nsEventStatus PR_CALLBACK HandleSiteEvent(nsGUIEvent *aEvent) +{ + nsEventStatus result = nsEventStatus_eIgnore; + if (aEvent == nsnull || aEvent->widget == nsnull) { + return result; + } + + switch(aEvent->message) { + + case NS_MOUSE_LEFT_BUTTON_UP: { + if (aEvent->widget->GetNativeData(NS_NATIVE_WIDGET) == GetWidgetNativeData(mSiteCancelBtn)) { + NS_ShowWidget(mSiteDialog,PR_FALSE); + } else if (aEvent->widget->GetNativeData(NS_NATIVE_WIDGET) == GetWidgetNativeData(mSitePrevBtn)) { + if (gTop100Pointer > 0) { + NS_EnableWidget(mSiteNextBtn,PR_TRUE); + if (gWinData) { + nsString urlStr(gTop100List[--gTop100Pointer]); + mSiteLabel->SetLabel(urlStr); + gWinData->GoTo(urlStr); + } + } else { + NS_EnableWidget(mSitePrevBtn,PR_FALSE); + NS_EnableWidget(mSiteNextBtn,PR_TRUE); + } + + } else if (aEvent->widget->GetNativeData(NS_NATIVE_WIDGET) == GetWidgetNativeData(mSiteNextBtn)) { + + char * p = gTop100List[++gTop100Pointer]; + if (p) { + if (gWinData) { + nsString urlStr(gTop100List[gTop100Pointer]); + mSiteLabel->SetLabel(urlStr); + gWinData->GoTo(urlStr); + } + NS_EnableWidget(mSitePrevBtn,PR_TRUE); + } else { + NS_EnableWidget(mSitePrevBtn,PR_TRUE); + NS_EnableWidget(mSiteNextBtn,PR_FALSE); + mSiteLabel->SetLabel("[END OF LIST]"); + } + } + } break; + + case NS_PAINT: +#ifndef XP_UNIX + // paint the background + if (aEvent->widget->GetNativeData(NS_NATIVE_WIDGET) == GetWidgetNativeData(mSiteDialog) ) { + nsIRenderingContext *drawCtx = ((nsPaintEvent*)aEvent)->renderingContext; + drawCtx->SetColor(aEvent->widget->GetBackgroundColor()); + drawCtx->FillRect(*(((nsPaintEvent*)aEvent)->rect)); + + return nsEventStatus_eIgnore; + } +#endif + break; + + default: + result = nsEventStatus_eIgnore; + } + + return result; +} + +//----------------------------------------- +//-- +//----------------------------------------- +PRBool CreateSiteDialog(nsIWidget * aParent) +{ + + PRBool result = TRUE; + + if (mSiteDialog == nsnull) { + nscoord txtHeight = 24; + nscolor textBGColor = NS_RGB(0,0,0); + nscolor textFGColor = NS_RGB(255,255,255); + + nsILookAndFeel * lookAndFeel; + if (NS_OK == nsRepository::CreateInstance(kLookAndFeelCID, nsnull, kILookAndFeelIID, (void**)&lookAndFeel)) { + //lookAndFeel->GetMetric(nsILookAndFeel::eMetric_TextFieldHeight, txtHeight); + //lookAndFeel->GetColor(nsILookAndFeel::eColor_TextBackground, textBGColor); + //lookAndFeel->GetColor(nsILookAndFeel::eColor_TextForeground, textFGColor); + } + + nsILabel * label; + + nsIDeviceContext* dc = aParent->GetDeviceContext(); + float t2d; + dc->GetTwipsToDevUnits(t2d); + nsFont font(DIALOG_FONT, NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL, + NS_FONT_WEIGHT_NORMAL, 0, + nscoord(t2d * NSIntPointsToTwips(DIALOG_FONT_SIZE))); + NS_RELEASE(dc); + + nscoord dialogWidth = 375; + // create a Dialog + // + nsRect rect; + rect.SetRect(0, 0, dialogWidth, 125); + + nsIWidget* widget = nsnull; + nsRepository::CreateInstance(kDialogCID, nsnull, kIDialogIID, (void**)&mSiteDialog); + if (mSiteDialog && NS_OK == mSiteDialog->QueryInterface(kIWidgetIID,(void**)&widget)) + { + widget->Create(aParent, rect, HandleSiteEvent, NULL); + mSiteDialog->SetLabel("Top 100 Site Walker"); + } + //mSiteDialog->SetClientData(this); + + nscoord w = 65; + nscoord x = 5; + nscoord y = 10; + nscoord h = 19; + + // Create Label + w = 50; + rect.SetRect(x, y+3, w, 24); + nsRepository::CreateInstance(kLabelCID, nsnull, kILabelIID, (void**)&label); + NS_CreateLabel(mSiteDialog,label,rect,HandleSiteEvent,&font); + label->SetAlignment(eAlign_Right); + label->SetLabel("Site:"); + x += w + 1; + + w = 250; + rect.SetRect(x, y+3, w, 24); + nsRepository::CreateInstance(kLabelCID, nsnull, kILabelIID, (void**)&mSiteLabel); + NS_CreateLabel(mSiteDialog,mSiteLabel,rect,HandleSiteEvent,&font); + mSiteLabel->SetAlignment(eAlign_Left); + mSiteLabel->SetLabel(""); + + y += 34; + w = 75; + nscoord spacing = (dialogWidth - (3*w)) / 4; + x = spacing; + // Create Previous Button + rect.SetRect(x, y, w, 24); + nsRepository::CreateInstance(kButtonCID, nsnull, kIButtonIID, (void**)&mSitePrevBtn); + NS_CreateButton(mSiteDialog,mSitePrevBtn,rect,HandleSiteEvent,&font); + mSitePrevBtn->SetLabel("<< Previous"); + x += spacing + w; + + // Create Next Button + rect.SetRect(x, y, w, 24); + nsRepository::CreateInstance(kButtonCID, nsnull, kIButtonIID, (void**)&mSiteNextBtn); + NS_CreateButton(mSiteDialog,mSiteNextBtn,rect,HandleSiteEvent,&font); + mSiteNextBtn->SetLabel("Next >>"); + x += spacing + w; + + // Create Cancel Button + rect.SetRect(x, y, w, 24); + nsRepository::CreateInstance(kButtonCID, nsnull, kIButtonIID, (void**)&mSiteCancelBtn); + NS_CreateButton(mSiteDialog,mSiteCancelBtn,rect,HandleSiteEvent,&font); + mSiteCancelBtn->SetLabel("Cancel"); + } + + NS_ShowWidget(mSiteDialog,PR_TRUE); + NS_SetFocusToWidget(mSiteNextBtn); + + // Init + NS_EnableWidget(mSitePrevBtn,PR_FALSE); + + if (gWinData) { + nsString urlStr(gTop100List[gTop100Pointer]); + gWinData->GoTo(urlStr); + mSiteLabel->SetLabel(urlStr); + } + + return result; +} + + +NS_IMETHODIMP +nsViewerApp::CreateSiteWalker(nsBrowserWindow* aWindow) +{ + if (nsnull == gWinData) { + gWinData = aWindow; + NS_ADDREF(aWindow); + CreateSiteDialog(aWindow->mWindow); + } + return NS_OK; +} + +//---------------------------------------- + +#ifdef XP_PC +#include "jsconsres.h" + +static NS_DEFINE_IID(kIScriptContextOwnerIID, NS_ISCRIPTCONTEXTOWNER_IID); + +static void DestroyConsole() +{ + if (gConsole) { + gConsole->SetNotification(NULL); + delete gConsole; + gConsole = NULL; + } +} + +static void ShowConsole(nsBrowserWindow* aWindow) +{ + HWND hWnd = (HWND)aWindow->mWindow->GetNativeData(NS_NATIVE_WIDGET); + if (!gConsole) { + + // load the accelerator table for the console + if (!JSConsole::sAccelTable) { + JSConsole::sAccelTable = LoadAccelerators(gInstance, + MAKEINTRESOURCE(ACCELERATOR_TABLE)); + } + + nsIScriptContextOwner *owner = nsnull; + nsIScriptContext *context = nsnull; + // XXX needs to change to aWindow->mWebShell + if (NS_OK == aWindow->mWebShell->QueryInterface(kIScriptContextOwnerIID, (void **)&owner)) { + if (NS_OK == owner->GetScriptContext(&context)) { + + // create the console + gConsole = JSConsole::CreateConsole(); + gConsole->SetContext(context); + // lifetime of the context is still unclear at this point. + // Anyway, as long as the web widget is alive the context is alive. + // Maybe the context shouldn't even be RefCounted + context->Release(); + gConsole->SetNotification(DestroyConsole); + } + + NS_RELEASE(owner); + } + else { + MessageBox(hWnd, "Unable to load JavaScript", "Viewer Error", MB_ICONSTOP); + } + } +} +#endif + +NS_IMETHODIMP +nsViewerApp::CreateJSConsole(nsBrowserWindow* aWindow) +{ +#ifdef XP_PC + if (nsnull == gConsole) { + ShowConsole(aWindow); + } +#endif + return NS_OK; +} diff --git a/xpfe/xpviewer/src/nsViewerApp.h b/xpfe/xpviewer/src/nsViewerApp.h new file mode 100644 index 000000000000..f49a5b552a04 --- /dev/null +++ b/xpfe/xpviewer/src/nsViewerApp.h @@ -0,0 +1,100 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are Copyright (C) 1998 + * Netscape Communications Corporation. All Rights Reserved. + */ +#ifndef nsViewerApp_h___ +#define nsViewerApp_h___ + +#include "nsINetContainerApplication.h" +#include "nsIAppShell.h" +#include "nsString.h" +#include "nsCRT.h" +#include "nsVoidArray.h" + +class nsIPref; +//class nsWebCrawler; +class nsBrowserWindow; +class nsIBrowserWindow; + +class nsViewerApp : public nsINetContainerApplication, + public nsDispatchListener +{ +public: + void* operator new(size_t sz) { + void* rv = new char[sz]; + nsCRT::zero(rv, sz); + return rv; + } + + nsViewerApp(); + virtual ~nsViewerApp(); + + // nsISupports + NS_DECL_ISUPPORTS + + // nsINetContainerApplication + NS_IMETHOD GetAppCodeName(nsString& aAppCodeName); + NS_IMETHOD GetAppVersion(nsString& aAppVersion); + NS_IMETHOD GetAppName(nsString& aAppName); + NS_IMETHOD GetLanguage(nsString& aLanguage); + NS_IMETHOD GetPlatform(nsString& aPlatform); + + // nsDispatchListener + virtual void AfterDispatch(); + + // nsViewerApp + NS_IMETHOD SetupRegistry(); + NS_IMETHOD Initialize(int argc, char** argv); + NS_IMETHOD ProcessArguments(int argc, char** argv); + NS_IMETHOD OpenWindow(); + NS_IMETHOD OpenWindow(PRUint32 aNewChromeMask, nsIBrowserWindow*& aNewWindow); + NS_IMETHOD CreateRobot(nsBrowserWindow* aWindow); + NS_IMETHOD CreateSiteWalker(nsBrowserWindow* aWindow); + NS_IMETHOD CreateJSConsole(nsBrowserWindow* aWindow); + NS_IMETHOD Exit(); + + NS_IMETHOD Run(); + +protected: + + void Destroy(); + + nsIAppShell* mAppShell; + nsIPref* mPrefs; + nsString mStartURL; + PRBool mDoPurify; + PRBool mLoadTestFromFile; + PRBool mCrawl; + nsString mInputFileName; + PRInt32 mNumSamples; + PRInt32 mDelay; + PRInt32 mRepeatCount; + //nsWebCrawler* mCrawler; + PRBool mAllowPlugins; + PRBool mIsInitialized; +}; + +/*class nsNativeViewerApp : public nsViewerApp { +public: + nsNativeViewerApp(); + ~nsNativeViewerApp(); + + virtual int Run(); +};*/ + +#endif /* nsViewerApp_h___ */ + diff --git a/xpfe/xpviewer/src/resources.h b/xpfe/xpviewer/src/resources.h new file mode 100644 index 000000000000..caa61f802ab7 --- /dev/null +++ b/xpfe/xpviewer/src/resources.h @@ -0,0 +1,88 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#ifndef resources_h___ +#define resources_h___ + +#define VIEWER_OPEN 40000 +#define VIEWER_EXIT 40002 +#define PREVIEW_CLOSE 40003 + +#define VIEWER_WINDOW_OPEN 40009 +#define VIEWER_FILE_OPEN 40010 + +// Note: must be in ascending sequential order +#define VIEWER_DEMO0 40011 +#define VIEWER_DEMO1 40012 +#define VIEWER_DEMO2 40013 +#define VIEWER_DEMO3 40014 +#define VIEWER_DEMO4 40015 +#define VIEWER_DEMO5 40016 +#define VIEWER_DEMO6 40017 +#define VIEWER_DEMO7 40018 +#define VIEWER_DEMO8 40019 +#define VIEWER_DEMO9 40020 + + +#define VIEWER_VISUAL_DEBUGGING 40021 +#define VIEWER_REFLOW_TEST 40022 +#define VIEWER_DUMP_CONTENT 40023 +#define VIEWER_DUMP_FRAMES 40024 +#define VIEWER_DUMP_VIEWS 40025 +#define VIEWER_DUMP_STYLE_SHEETS 40026 +#define VIEWER_DUMP_STYLE_CONTEXTS 40027 +#define VIEWER_DEBUGROBOT 40028 +#define VIEWER_SHOW_CONTENT_SIZE 40029 +#define VIEWER_SHOW_FRAME_SIZE 40030 +#define VIEWER_SHOW_STYLE_SIZE 40031 +#define VIEWER_DEBUGSAVE 40032 +#define VIEWER_SHOW_CONTENT_QUALITY 40033 +#define VIEWER_TOGGLE_SELECTION 40034 + +// Note: must be in ascending sequential order +#define VIEWER_ONE_COLUMN 40040 +#define VIEWER_TWO_COLUMN 40041 +#define VIEWER_THREE_COLUMN 40042 + +#define JS_CONSOLE 40100 +#define EDITOR_MODE 40120 + +#define VIEWER_EDIT_CUT 40201 +#define VIEWER_EDIT_COPY 40202 +#define VIEWER_EDIT_PASTE 40203 +#define VIEWER_EDIT_SELECTALL 40204 +#define VIEWER_EDIT_FINDINPAGE 40205 + +#define VIEWER_RL_BASE 41000 + +#define VIEWER_TOP100 40300 +/* Debug Robot dialog setup */ + +#define IDD_DEBUGROBOT 101 +#define IDC_UPDATE_DISPLAY 40301 +#define IDC_VERIFICATION_DIRECTORY 40302 +#define IDC_PAGE_LOADS 40303 +#define IDC_STATIC -1 + +#define IDD_SITEWALKER 200 +#define ID_SITE_PREVIOUS 40400 +#define ID_SITE_NEXT 40401 +#define IDC_SITE_NAME 40402 +#define ID_EXIT 40404 + +#endif /* resources_h___ */