diff --git a/mozilla/embedding/tests/winEmbed/WebBrowserChrome.cpp b/mozilla/embedding/tests/winEmbed/WebBrowserChrome.cpp index 818346d2e3b..03e358004eb 100644 --- a/mozilla/embedding/tests/winEmbed/WebBrowserChrome.cpp +++ b/mozilla/embedding/tests/winEmbed/WebBrowserChrome.cpp @@ -40,10 +40,20 @@ WebBrowserChrome::WebBrowserChrome() { NS_INIT_REFCNT(); mNativeWindow = nsnull; + mUI = nsnull; } WebBrowserChrome::~WebBrowserChrome() { + if (mUI) + { + delete mUI; + } +} + +void WebBrowserChrome::SetUI(WebBrowserChromeUI *aUI) +{ + mUI = aUI; } //***************************************************************************** @@ -58,7 +68,7 @@ NS_INTERFACE_MAP_BEGIN(WebBrowserChrome) NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor) NS_INTERFACE_MAP_ENTRY(nsIWebBrowserChrome) NS_INTERFACE_MAP_ENTRY(nsIBaseWindow) - NS_INTERFACE_MAP_ENTRY(nsIWebProgressListener) //optional + NS_INTERFACE_MAP_ENTRY(nsIWebProgressListener) // optional // NS_INTERFACE_MAP_ENTRY(nsIPrompt) NS_INTERFACE_MAP_END @@ -77,6 +87,7 @@ NS_IMETHODIMP WebBrowserChrome::GetInterface(const nsIID &aIID, void** aInstance NS_IMETHODIMP WebBrowserChrome::SetStatus(PRUint32 aType, const PRUnichar* aStatus) { + mUI->UpdateStatusBarText(this, aStatus); return NS_OK; } @@ -111,10 +122,6 @@ NS_IMETHODIMP WebBrowserChrome::SetChromeFlags(PRUint32 aChromeMask) return NS_ERROR_FAILURE; } - -// in winEmbed.cpp -extern nativeWindow CreateNativeWindow(nsIWebBrowserChrome* chrome); - NS_IMETHODIMP WebBrowserChrome::CreateBrowserWindow(PRUint32 chromeMask, PRInt32 aX, PRInt32 aY, PRInt32 aCX, PRInt32 aCY, nsIWebBrowser **aWebBrowser) { static int gCount = 0; @@ -137,14 +144,14 @@ NS_IMETHODIMP WebBrowserChrome::CreateBrowserWindow(PRUint32 chromeMask, PRInt32 mBaseWindow = do_QueryInterface(mWebBrowser); - mNativeWindow = CreateNativeWindow(NS_STATIC_CAST(nsIWebBrowserChrome*, this)); + mNativeWindow = mUI->CreateNativeWindow(NS_STATIC_CAST(nsIWebBrowserChrome*, this)); if (!mNativeWindow) return NS_ERROR_FAILURE; mBaseWindow->InitWindow( mNativeWindow, nsnull, - 0, 0, 450, 450); + aX, aY, aCX, aCY); mBaseWindow->Create(); NS_IF_ADDREF(*aWebBrowser = mWebBrowser); @@ -215,17 +222,26 @@ NS_IMETHODIMP WebBrowserChrome::OnProgressChange(nsIWebProgress *progress, nsIRe PRInt32 curSelfProgress, PRInt32 maxSelfProgress, PRInt32 curTotalProgress, PRInt32 maxTotalProgress) { - return NS_ERROR_NOT_IMPLEMENTED; + mUI->UpdateProgress(this, curTotalProgress, maxTotalProgress); + return NS_OK; } NS_IMETHODIMP WebBrowserChrome::OnStateChange(nsIWebProgress *progress, nsIRequest *request, PRInt32 progressStateFlags, PRUint32 status) { - - if ((progressStateFlags & STATE_STOP) && (progressStateFlags & STATE_IS_REQUEST)) + if ((progressStateFlags & STATE_START) && (progressStateFlags & STATE_IS_DOCUMENT)) { + mUI->UpdateBusyState(this, PR_TRUE); } - return NS_ERROR_NOT_IMPLEMENTED; + + if ((progressStateFlags & STATE_STOP) && (progressStateFlags & STATE_IS_DOCUMENT)) + { + mUI->UpdateBusyState(this, PR_FALSE); + mUI->UpdateProgress(this, 0, 100); + mUI->UpdateStatusBarText(this, nsnull); + } + + return NS_OK; } @@ -233,7 +249,8 @@ NS_IMETHODIMP WebBrowserChrome::OnLocationChange(nsIWebProgress* aWebProgress, nsIRequest* aRequest, nsIURI *location) { - return NS_ERROR_NOT_IMPLEMENTED; + mUI->UpdateCurrentURI(this); + return NS_OK; } NS_IMETHODIMP @@ -242,6 +259,7 @@ WebBrowserChrome::OnStatusChange(nsIWebProgress* aWebProgress, nsresult aStatus, const PRUnichar* aMessage) { + mUI->UpdateStatusBarText(this, aMessage); return NS_OK; } diff --git a/mozilla/embedding/tests/winEmbed/WebBrowserChrome.h b/mozilla/embedding/tests/winEmbed/WebBrowserChrome.h index b732d2bf46c..b36ccc2d9c6 100644 --- a/mozilla/embedding/tests/winEmbed/WebBrowserChrome.h +++ b/mozilla/embedding/tests/winEmbed/WebBrowserChrome.h @@ -38,7 +38,23 @@ #include "nsIWebBrowser.h" #include "nsVoidArray.h" +class WebBrowserChromeUI +{ +public: + virtual nativeWindow CreateNativeWindow(nsIWebBrowserChrome* chrome) = 0; + virtual void UpdateStatusBarText(nsIWebBrowserChrome *aChrome, const PRUnichar* aStatusText) = 0; + virtual void UpdateCurrentURI(nsIWebBrowserChrome *aChrome) = 0; + virtual void UpdateBusyState(nsIWebBrowserChrome *aChrome, PRBool aBusy) = 0; + virtual void UpdateProgress(nsIWebBrowserChrome *aChrome, PRInt32 aCurrent, PRInt32 aMax) = 0; +}; +#define NS_DECL_WEBBROWSERCHROMEUI \ + public: \ + virtual nativeWindow CreateNativeWindow(nsIWebBrowserChrome* chrome); \ + virtual void UpdateStatusBarText(nsIWebBrowserChrome *aChrome, const PRUnichar* aStatusText); \ + virtual void UpdateCurrentURI(nsIWebBrowserChrome *aChrome); \ + virtual void UpdateBusyState(nsIWebBrowserChrome *aChrome, PRBool aBusy); \ + virtual void UpdateProgress(nsIWebBrowserChrome *aChrome, PRInt32 aCurrent, PRInt32 aMax); class WebBrowserChrome : public nsIWebBrowserChrome, public nsIWebProgressListener, @@ -50,6 +66,7 @@ public: WebBrowserChrome(); virtual ~WebBrowserChrome(); + void SetUI(WebBrowserChromeUI *aUI); NS_DECL_ISUPPORTS NS_DECL_NSIWEBBROWSERCHROME @@ -62,6 +79,7 @@ protected: nativeWindow mNativeWindow; + WebBrowserChromeUI *mUI; nsCOMPtr mWebBrowser; nsCOMPtr mBaseWindow; nsCOMPtr mTopWindow; diff --git a/mozilla/embedding/tests/winEmbed/resource.h b/mozilla/embedding/tests/winEmbed/resource.h index 80e18ccc5d0..ddcd664ae47 100644 --- a/mozilla/embedding/tests/winEmbed/resource.h +++ b/mozilla/embedding/tests/winEmbed/resource.h @@ -12,10 +12,22 @@ #define IDM_EXIT 105 #define IDS_HELLO 106 #define IDI_WINEMBED 107 +#define IDS_ABOUT 107 #define IDI_SMALL 108 +#define IDS_ABOUT_TITLE 108 #define IDC_WINEMBED 109 #define IDR_MAINFRAME 128 +#define IDD_BROWSER 130 #define MOZ_EDIT_URI 1001 +#define IDC_GO 1003 +#define IDC_BROWSER 1004 +#define IDC_ADDRESS 1005 +#define IDC_STOP 1006 +#define IDC_STATUS 1007 +#define IDC_BACK 1008 +#define IDC_FORWARD 1009 +#define IDC_PROGRESS 1010 +#define IDC_RELOAD 1011 #define MOZ_Open 32771 #define MOZ_Print 32772 #define MOZ_NewBrowser 32773 @@ -26,15 +38,20 @@ #define MOZ_Paste 32778 #define MOZ_Delete 32779 #define MOZ_SelectAll 32780 +#define MOZ_SelectNone 32781 +#define MOZ_GoBack 32782 +#define MOZ_GoForward 32783 +#define MOZ_About 32784 +#define ID_DEBUG_THISSPACEFORRENT 32786 #define IDC_STATIC -1 // Next default values for new objects // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 130 -#define _APS_NEXT_COMMAND_VALUE 32781 -#define _APS_NEXT_CONTROL_VALUE 1002 +#define _APS_NEXT_RESOURCE_VALUE 132 +#define _APS_NEXT_COMMAND_VALUE 32787 +#define _APS_NEXT_CONTROL_VALUE 1011 #define _APS_NEXT_SYMED_VALUE 110 #endif #endif diff --git a/mozilla/embedding/tests/winEmbed/winEmbed.cpp b/mozilla/embedding/tests/winEmbed/winEmbed.cpp index 155217f828c..0e501427901 100644 --- a/mozilla/embedding/tests/winEmbed/winEmbed.cpp +++ b/mozilla/embedding/tests/winEmbed/winEmbed.cpp @@ -23,109 +23,69 @@ #include #include "stdafx.h" -#include "Windows.h" -#include "resource.h" +// Win32 header files +#include "windows.h" +#include "commctrl.h" +#include "commdlg.h" -#include "nsIContentViewerEdit.h" - +// Mozilla header files #include "nsEmbedAPI.h" +#include "nsIClipboardCommands.h" +#include "nsXPIDLString.h" +#include "nsIWebBrowserPersist.h" + +// Local header files #include "WebBrowserChrome.h" +#include "resource.h" #define MAX_LOADSTRING 100 -#define IDC_Status 100 - -// Global Variables: -HINSTANCE hInst; -TCHAR szTitle[MAX_LOADSTRING]; - -TCHAR szWindowClass[MAX_LOADSTRING]; +const TCHAR *szWindowClass = _T("WINEMBED"); // Foward declarations of functions included in this code module: -ATOM MyRegisterClass(HINSTANCE hInstance); -LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); -LRESULT CALLBACK GetURI(HWND, UINT, WPARAM, LPARAM); +static ATOM MyRegisterClass(HINSTANCE hInstance); +static LRESULT CALLBACK BrowserWndProc(HWND, UINT, WPARAM, LPARAM); +static BOOL CALLBACK BrowserDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); +static LRESULT CALLBACK GetURI(HWND, UINT, WPARAM, LPARAM); +static nsresult OpenWebPage(const char * url); +static nsresult ResizeEmbedding(nsIWebBrowserChrome* chrome); +// Global variables +static char gLastURI[100]; +static UINT gDialogCount = 0; +static PRBool gDumbBanner = PR_TRUE; +static PRInt32 gDumbBannerSize = 32; +static HINSTANCE ghInstanceResources = NULL; +static HINSTANCE ghInstanceApp = NULL; -char gLastURI[100]; - -// utility function -nsresult ResizeEmbedding(nsIWebBrowserChrome* chrome) +int main(int argc, char *argv[]) { - if (!chrome) - return NS_ERROR_FAILURE; - - nsCOMPtr baseWindow = do_QueryInterface(chrome); - - HWND hWnd; - baseWindow->GetParentNativeWindow((void**)&hWnd); - - if (!hWnd) - return NS_ERROR_NULL_POINTER; - - RECT rect; - GetClientRect(hWnd, &rect); - rect.top += 32; - rect.bottom -= 32; - baseWindow->SetPositionAndSize(rect.left, - rect.top, - rect.right - rect.left, - rect.bottom - rect.top, - PR_TRUE); - - baseWindow->SetVisibility(PR_TRUE); - return NS_OK; -} - - -nsresult OpenWebPage(const char* url) -{ - WebBrowserChrome * chrome = new WebBrowserChrome(); - if (!chrome) - return NS_ERROR_FAILURE; - - NS_ADDREF(chrome); // native window will hold the addref. - - nsCOMPtr newBrowser; - chrome->CreateBrowserWindow(0, -1, -1, -1, -1, getter_AddRefs(newBrowser)); - if (!newBrowser) - return NS_ERROR_FAILURE; - - // Place it where we want it. - ResizeEmbedding(NS_STATIC_CAST(nsIWebBrowserChrome*, chrome)); - - nsCOMPtr webNav(do_QueryInterface(newBrowser)); - return webNav->LoadURI(NS_ConvertASCIItoUCS2(url).GetUnicode(), nsIWebNavigation::LOAD_FLAGS_NONE); -} - -int main (int argc, char* argv[]) -{ - printf("\nYou are embedded, man!\n\n"); - - const char* url = "http://www.mozilla.org/projects/embedding"; - if (argc > 1) - url = argv[argc - 1]; - MSG msg; - HINSTANCE hInstance = GetModuleHandle(NULL); + // Sophisticated command-line parsing in action + char *szFirstURL = "http://www.mozilla.org/projects/embedding"; + if (argc > 1) + { + szFirstURL = argv[1]; + } + + ghInstanceApp = GetModuleHandle(NULL); + ghInstanceResources = GetModuleHandle(NULL); // Initialize global strings - LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); - LoadString(hInstance, IDC_WINEMBED, szWindowClass, MAX_LOADSTRING); - MyRegisterClass(hInstance); + TCHAR szTitle[MAX_LOADSTRING]; + LoadString(ghInstanceResources, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); + MyRegisterClass(ghInstanceApp); -// Init Embedding APIs + // Init Embedding APIs NS_InitEmbedding(nsnull, nsnull); -// put up at lease on browser window .... -///////////////////////////////////////////////////////////// - OpenWebPage(url); -///////////////////////////////////////////////////////////// - + // Open the initial browser window + OpenWebPage(szFirstURL); // Main message loop: + MSG msg; while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); @@ -139,6 +99,190 @@ int main (int argc, char* argv[]) } +class Win32ChromeUI : public WebBrowserChromeUI +{ + NS_DECL_WEBBROWSERCHROMEUI; +}; + + +// +// FUNCTION: OpenWebPage() +// +// PURPOSE: Opens a new browser dialog and starts it loading to the +// specified url. +// +nsresult OpenWebPage(const char *url) +{ + WebBrowserChrome * chrome = new WebBrowserChrome(); + if (!chrome) + return NS_ERROR_FAILURE; + NS_ADDREF(chrome); // native window will hold the addref. + + // Note, the chrome owns the UI object once set & will delete it + chrome->SetUI(new Win32ChromeUI); + + // Create the browser window + nsCOMPtr newBrowser; + chrome->CreateBrowserWindow(0, -1, -1, -1, -1, getter_AddRefs(newBrowser)); + if (!newBrowser) + return NS_ERROR_FAILURE; + + // Place it where we want it. + ResizeEmbedding(NS_STATIC_CAST(nsIWebBrowserChrome*, chrome)); + + // Start loading a page + nsCOMPtr webNav(do_QueryInterface(newBrowser)); + return webNav->LoadURI(NS_ConvertASCIItoUCS2(url).GetUnicode(), nsIWebNavigation::LOAD_FLAGS_NONE); +} + + +// +// FUNCTION: GetBrowserFromChrome() +// +// PURPOSE: Returns the HWND for the webbrowser container associated +// with the specified chrome. +// +HWND GetBrowserFromChrome(nsIWebBrowserChrome *aChrome) +{ + if (!aChrome) + { + return NULL; + } + nsCOMPtr baseWindow = do_QueryInterface(aChrome); + HWND hwnd = NULL; + baseWindow->GetParentNativeWindow((void**)&hwnd); + return hwnd; +} + + +// +// FUNCTION: GetBrowserDlgFromChrome() +// +// PURPOSE: Returns the HWND for the browser dialog associated with +// the specified chrome. +// +HWND GetBrowserDlgFromChrome(nsIWebBrowserChrome *aChrome) +{ + return GetParent(GetBrowserFromChrome(aChrome)); +} + + +// +// FUNCTION: SaveWebPage() +// +// PURPOSE: Saves the contents of the web page to a file +// +void SaveWebPage(nsIWebBrowser *aWebBrowser) +{ + // Use the browser window title as the initial file name + nsCOMPtr webBrowserAsWin = do_QueryInterface(aWebBrowser); + nsXPIDLString windowTitle; + webBrowserAsWin->GetTitle(getter_Copies(windowTitle)); + nsCString fileName; fileName.AssignWithConversion(windowTitle); + + // Sanitize the title of all illegal characters + fileName.CompressWhitespace(); // Remove whitespace from the ends + fileName.StripChars("\\*|:\"> persist(do_QueryInterface(aWebBrowser)); + persist->SaveDocument(nsnull, szFile, pszDataPath); + } +} + + +// +// FUNCTION: ResizeEmbedding() +// +// PURPOSE: Resizes the webbrowser window to fit it's container. +// +nsresult ResizeEmbedding(nsIWebBrowserChrome* chrome) +{ + if (!chrome) + return NS_ERROR_FAILURE; + + nsCOMPtr baseWindow = do_QueryInterface(chrome); + + HWND hWnd; + baseWindow->GetParentNativeWindow((void**)&hWnd); + + if (!hWnd) + return NS_ERROR_NULL_POINTER; + + RECT rect; + GetClientRect(hWnd, &rect); + + // Add space for the banner if there is enough to show it + if (gDumbBanner && rect.bottom - rect.top > gDumbBannerSize) + { + rect.top += gDumbBannerSize; + } + + baseWindow->SetPositionAndSize(rect.left, + rect.top, + rect.right - rect.left, + rect.bottom - rect.top, + PR_TRUE); + + baseWindow->SetVisibility(PR_TRUE); + return NS_OK; +} + // // FUNCTION: MyRegisterClass() @@ -157,226 +301,539 @@ ATOM MyRegisterClass(HINSTANCE hInstance) { WNDCLASSEX wcex; + memset(&wcex, 0, sizeof(wcex)); wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; - wcex.lpfnWndProc = (WNDPROC)WndProc; + wcex.lpfnWndProc = (WNDPROC) BrowserWndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; - wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_WINEMBED); + wcex.hIcon = LoadIcon(ghInstanceResources, (LPCTSTR)IDI_WINEMBED); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); - wcex.lpszMenuName = (LPCSTR)IDC_WINEMBED; wcex.lpszClassName = szWindowClass; - wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL); + wcex.hIconSm = LoadIcon(ghInstanceResources, (LPCTSTR)IDI_SMALL); return RegisterClassEx(&wcex); } - -nativeWindow CreateNativeWindow(nsIWebBrowserChrome* chrome) +// +// FUNCTION: UpdateUI() +// +// PURPOSE: Refreshes the buttons and menu items in the browser dialog +// +void UpdateUI(nsIWebBrowserChrome *aChrome) { - HWND mainWindow; + HWND hwndDlg = GetBrowserDlgFromChrome(aChrome); + nsCOMPtr webBrowser; + nsCOMPtr webNavigation; + aChrome->GetWebBrowser(getter_AddRefs(webBrowser)); + webNavigation = do_QueryInterface(webBrowser); - mainWindow = CreateWindow( szWindowClass, - szTitle, - WS_OVERLAPPEDWINDOW, - 0, - 0, - 450, - 450, - NULL, - NULL, - GetModuleHandle(NULL), - NULL); + PRBool canGoBack = PR_FALSE; + PRBool canGoForward = PR_FALSE; + if (webNavigation) + { + webNavigation->GetCanGoBack(&canGoBack); + webNavigation->GetCanGoForward(&canGoForward); + } - if (!mainWindow) - return NULL; - - SetWindowLong( mainWindow, GWL_USERDATA, (LONG)chrome); // save the browser LONG_PTR. + PRBool canCutSelection = PR_FALSE; + PRBool canCopySelection = PR_FALSE; + PRBool canPasteSelection = PR_FALSE; - ShowWindow(mainWindow, SW_SHOWDEFAULT); - UpdateWindow(mainWindow); + nsCOMPtr clipCmds = do_GetInterface(webBrowser); + if (nsIClipboardCommands) + { + clipCmds->CanCutSelection(&canCutSelection); + clipCmds->CanCopySelection(&canCopySelection); + clipCmds->CanPasteSelection(&canPasteSelection); + } - return mainWindow; + HMENU hmenu = GetMenu(hwndDlg); + if (hmenu) + { + EnableMenuItem(hmenu, MOZ_GoBack, MF_BYCOMMAND | + ((canGoBack) ? MF_ENABLED : (MF_DISABLED | MF_GRAYED))); + EnableMenuItem(hmenu, MOZ_GoForward, MF_BYCOMMAND | + ((canGoForward) ? MF_ENABLED : (MF_DISABLED | MF_GRAYED))); + + EnableMenuItem(hmenu, MOZ_Cut, MF_BYCOMMAND | + ((canCutSelection) ? MF_ENABLED : (MF_DISABLED | MF_GRAYED))); + EnableMenuItem(hmenu, MOZ_Copy, MF_BYCOMMAND | + ((canCopySelection) ? MF_ENABLED : (MF_DISABLED | MF_GRAYED))); + EnableMenuItem(hmenu, MOZ_Paste, MF_BYCOMMAND | + ((canPasteSelection) ? MF_ENABLED : (MF_DISABLED | MF_GRAYED))); + } + + EnableWindow(GetDlgItem(hwndDlg, IDC_BACK), canGoBack); + EnableWindow(GetDlgItem(hwndDlg, IDC_FORWARD), canGoForward); } + // -// FUNCTION: WndProc(HWND, unsigned, WORD, LONG) +// FUNCTION: BrowserDlgProc() // -// PURPOSE: Processes messages for the main window. +// PURPOSE: Browser dialog windows message handler. // -// WM_COMMAND - process the application menu -// WM_PAINT - Paint the main window -// WM_DESTROY - post a quit message and return +// COMMENTS: // +// The code for handling buttons and menu actions is here. // -LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +BOOL CALLBACK BrowserDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + // Get the browser and other pointers since they are used a lot below + HWND hwndBrowser = GetDlgItem(hwndDlg, IDC_BROWSER); + nsIWebBrowserChrome *chrome = nsnull; + if (hwndBrowser) + { + chrome = (nsIWebBrowserChrome *) GetWindowLong(hwndBrowser, GWL_USERDATA); + } + nsCOMPtr webBrowser; + nsCOMPtr webNavigation; + if (chrome) + { + chrome->GetWebBrowser(getter_AddRefs(webBrowser)); + webNavigation = do_QueryInterface(webBrowser); + } + + // Test the message + switch (uMsg) + { + case WM_INITMENU: + UpdateUI(chrome); + return TRUE; + + case WM_NOTIFY: + + case WM_COMMAND: + if (!webBrowser) + { + return TRUE; + } + + // Test which command was selected + switch (LOWORD(wParam)) + { + case IDC_ADDRESS: + if (HIWORD(wParam) == CBN_EDITCHANGE || HIWORD(wParam) == CBN_SELCHANGE) + { + // User has changed the address field so enable the Go button + EnableWindow(GetDlgItem(hwndDlg, IDC_GO), TRUE); + } + break; + + case IDC_GO: + { + TCHAR szURL[2048]; + memset(szURL, 0, sizeof(szURL)); + GetDlgItemText(hwndDlg, IDC_ADDRESS, szURL, sizeof(szURL) / sizeof(szURL[0]) - 1); + webNavigation->LoadURI(NS_ConvertASCIItoUCS2(szURL).GetUnicode(), nsIWebNavigation::LOAD_FLAGS_NONE); + } + break; + + case IDC_STOP: + webNavigation->Stop(); + UpdateUI(chrome); + break; + + case IDC_RELOAD: + webNavigation->Reload(nsIWebNavigation::LOAD_FLAGS_NONE); + break; + + case IDM_EXIT: + PostMessage(hwndDlg, WM_SYSCOMMAND, SC_CLOSE, 0); + break; + + // File menu commands + + case MOZ_NewBrowser: + gLastURI[0] = 0; + if (DialogBox(ghInstanceResources, (LPCTSTR)MOZ_GetURI, hwndDlg, (DLGPROC)GetURI) == IDOK) + { + OpenWebPage(gLastURI); + } + break; + + case MOZ_Save: + SaveWebPage(webBrowser); + break; + + case MOZ_Print: + { + // NOTE: Embedding code shouldn't need to get the docshell or + // contentviewer AT ALL. This code below will break one + // day but will have to do until the embedding API has + // a cleaner way to do the same thing. + + nsCOMPtr rootDocShell = do_GetInterface(webBrowser); + nsCOMPtr pContentViewer; + nsresult res = rootDocShell->GetContentViewer(getter_AddRefs(pContentViewer)); + + if (NS_SUCCEEDED(res)) + { + nsCOMPtr spContentViewerFile = do_QueryInterface(pContentViewer); + spContentViewerFile->Print(PR_TRUE, nsnull); + } + } + break; + + // Edit menu commands + + case MOZ_Cut: + { + nsCOMPtr clipCmds = do_GetInterface(webBrowser); + clipCmds->CutSelection(); + } + break; + + case MOZ_Copy: + { + nsCOMPtr clipCmds = do_GetInterface(webBrowser); + clipCmds->CopySelection(); + } + break; + + case MOZ_Paste: + { + nsCOMPtr clipCmds = do_GetInterface(webBrowser); + clipCmds->PasteSelection(); + } + break; + + case MOZ_SelectAll: + { + nsCOMPtr clipCmds = do_GetInterface(webBrowser); + clipCmds->SelectAll(); + } + break; + + case MOZ_SelectNone: + { + nsCOMPtr clipCmds = do_GetInterface(webBrowser); + clipCmds->SelectNone(); + } + break; + + // Go menu commands + case IDC_BACK: + case MOZ_GoBack: + webNavigation->GoBack(); + UpdateUI(chrome); + break; + + case IDC_FORWARD: + case MOZ_GoForward: + webNavigation->GoForward(); + UpdateUI(chrome); + break; + + // Help menu commands + case MOZ_About: + { + TCHAR szAboutTitle[MAX_LOADSTRING]; + TCHAR szAbout[MAX_LOADSTRING]; + LoadString(ghInstanceResources, IDS_ABOUT_TITLE, szAboutTitle, MAX_LOADSTRING); + LoadString(ghInstanceResources, IDS_ABOUT, szAbout, MAX_LOADSTRING); + MessageBox(NULL, szAbout, szAboutTitle, MB_OK); + } + break; + } + + return TRUE; + + case WM_SIZE: + { + UINT newDlgWidth = LOWORD(lParam); + UINT newDlgHeight = HIWORD(lParam); + + // TODO Reposition the control bar - for the moment it's fixed size + + // Reposition the status area. Status bar + // gets any space that the fixed size progress bar doesn't use. + RECT rcStatus; + RECT rcProgress; + HWND hwndStatus = GetDlgItem(hwndDlg, IDC_STATUS); + HWND hwndProgress = GetDlgItem(hwndDlg, IDC_PROGRESS); + GetWindowRect(hwndStatus, &rcStatus); + GetWindowRect(hwndProgress, &rcProgress); + int progressWidth = rcProgress.right - rcProgress.left; + int statusWidth = newDlgWidth - progressWidth; + int statusHeight = rcStatus.bottom - rcStatus.top; + SetWindowPos(hwndStatus, + HWND_TOP, + 0, newDlgHeight - statusHeight, + statusWidth, + statusHeight, + SWP_NOZORDER); + SetWindowPos(hwndProgress, + HWND_TOP, + statusWidth, newDlgHeight - statusHeight, + 0, 0, + SWP_NOSIZE | SWP_NOZORDER); + + // Resize the browser area (assuming the browse is + // sandwiched between the control bar and status area) + RECT rcBrowser; + POINT ptBrowser; + GetWindowRect(hwndBrowser, &rcBrowser); + ptBrowser.x = rcBrowser.left; + ptBrowser.y = rcBrowser.top; + ScreenToClient(hwndDlg, &ptBrowser); + int browserHeight = newDlgHeight - ptBrowser.y - statusHeight; + if (browserHeight < 1) + { + browserHeight = 1; + } + SetWindowPos(hwndBrowser, + HWND_TOP, + 0, 0, + newDlgWidth, + newDlgHeight - ptBrowser.y - statusHeight, + SWP_NOMOVE | SWP_NOZORDER); + } + return TRUE; + + case WM_SYSCOMMAND: + if (wParam == SC_CLOSE) + { + DestroyWindow(hwndDlg); + return TRUE; + } + break; + + case WM_DESTROY: + gDialogCount--; + if (webNavigation) + { + webNavigation->Stop(); + } + // Quit when there are no more browser windows + if (gDialogCount == 0) + { + PostQuitMessage(0); + } + return TRUE; + } + return FALSE; +} + + +// +// FUNCTION: BrowserWndProc(HWND, unsigned, WORD, LONG) +// +// PURPOSE: Processes messages for the browser container window. +// +// WM_PAINT - Paint the main window +// WM_DESTROY - Cleanup +// +// +LRESULT CALLBACK BrowserWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { - int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; TCHAR szHello[MAX_LOADSTRING]; - LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING); + LoadString(ghInstanceResources, IDS_HELLO, szHello, MAX_LOADSTRING); nsIWebBrowserChrome *chrome = (nsIWebBrowserChrome *) GetWindowLong(hWnd, GWL_USERDATA); switch (message) { - case WM_COMMAND: - wmId = LOWORD(wParam); - wmEvent = HIWORD(wParam); - // Parse the menu selections: - switch (wmId) - { - case MOZ_NewBrowser: - gLastURI[0] = 0; - if (DialogBox(hInst, (LPCTSTR)MOZ_GetURI, hWnd, (DLGPROC)GetURI)) - OpenWebPage(gLastURI); - break; - - case MOZ_NewEditor: - gLastURI[0] = 0; - break; - - case MOZ_Open: - gLastURI[0] = 0; - if (chrome && DialogBox(hInst, (LPCTSTR)MOZ_GetURI, hWnd, (DLGPROC)GetURI)) - { - nsCOMPtr wb; - chrome->GetWebBrowser(getter_AddRefs(wb)); - nsCOMPtr webNav(do_QueryInterface(wb)); - webNav->LoadURI(NS_ConvertASCIItoUCS2(gLastURI).GetUnicode(), nsIWebNavigation::LOAD_FLAGS_NONE); - } - break; - - case MOZ_Save: - - if (chrome) - { - nsCOMPtr wb; - chrome->GetWebBrowser(getter_AddRefs(wb)); - - nsCOMPtr rootDocShell = do_GetInterface(wb); - - nsCOMPtr pContentViewer; - nsresult res = rootDocShell->GetContentViewer(getter_AddRefs(pContentViewer)); - - if (NS_SUCCEEDED(res)) - { - nsCOMPtr spContentViewerFile = do_QueryInterface(pContentViewer); - spContentViewerFile->Save(); - } - } - break; - - case MOZ_Print: - - if (chrome) - { - nsCOMPtr wb; - chrome->GetWebBrowser(getter_AddRefs(wb)); - - nsCOMPtr rootDocShell = do_GetInterface(wb); - - nsCOMPtr pContentViewer; - nsresult res = rootDocShell->GetContentViewer(getter_AddRefs(pContentViewer)); - - if (NS_SUCCEEDED(res)) - { - nsCOMPtr spContentViewerFile = do_QueryInterface(pContentViewer); - spContentViewerFile->Print(PR_TRUE, nsnull); - } - } - break; - - case MOZ_Cut: - case MOZ_Copy: - case MOZ_Paste: - case MOZ_SelectAll: - if (chrome) - { - nsCOMPtr wb; - chrome->GetWebBrowser(getter_AddRefs(wb)); - - nsCOMPtr rootDocShell = do_GetInterface(wb); - - nsCOMPtr pContentViewer; - nsresult res = rootDocShell->GetContentViewer(getter_AddRefs(pContentViewer)); - - if (NS_SUCCEEDED(res)) - { - nsCOMPtr spContentViewerEdit = do_QueryInterface(pContentViewer); - if (message == MOZ_Cut) - spContentViewerEdit->CopySelection(); - else if (message == MOZ_Copy) - spContentViewerEdit->CutSelection(); - else if (message == MOZ_SelectAll) - spContentViewerEdit->SelectAll(); - } - } - - break; - - default: - return DefWindowProc(hWnd, message, wParam, lParam); - } - break; - - case WM_SIZE: - ResizeEmbedding(chrome); - break; + case WM_SIZE: + // Resize the embedded browser + ResizeEmbedding(chrome); + break; - case WM_PAINT: - + case WM_ERASEBKGND: + // Reduce flicker by not painting the non-visible background + return 1; + + case WM_PAINT: + // Draw a banner message above the browser + if (gDumbBanner) + { // this draws that silly text at the top of the window. hdc = BeginPaint(hWnd, &ps); - RECT rt; - GetClientRect(hWnd, &rt); - rt.bottom = 32; - - FrameRect(hdc, &rt, CreateSolidBrush( 0x00 ) ); - - rt.top = 4; - - DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER); + RECT rc; + GetClientRect(hWnd, &rc); + // Only draw banner if there is space + if (rc.bottom - rc.top > gDumbBannerSize) + { + rc.bottom = gDumbBannerSize; + FillRect(hdc, &rc, (HBRUSH) GetStockObject(WHITE_BRUSH)); + FrameRect(hdc, &rc, CreateSolidBrush( 0x00 ) ); + rc.top = 4; + DrawText(hdc, szHello, strlen(szHello), &rc, DT_CENTER); + } EndPaint(hWnd, &ps); - break; + } + break; + case WM_DESTROY: + NS_RELEASE(chrome); + break; - case WM_DESTROY: - PostQuitMessage(0); - NS_RELEASE(chrome); - break; - default: - return DefWindowProc(hWnd, message, wParam, lParam); + default: + return DefWindowProc(hWnd, message, wParam, lParam); } return 0; } -// Mesage handler for about box. + +// +// FUNCTION: GetURI(HWND, unsigned, WORD, LONG) +// +// PURPOSE: Dialog handler procedure for the open uri dialog. +// LRESULT CALLBACK GetURI(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { - case WM_INITDIALOG: - return TRUE; + case WM_INITDIALOG: + return TRUE; - case WM_COMMAND: - if (LOWORD(wParam) == IDOK) - { - GetDlgItemText(hDlg, MOZ_EDIT_URI, gLastURI, 100); - EndDialog(hDlg, LOWORD(wParam)); - return TRUE; - } - else if (LOWORD(wParam) == IDNO) - { - EndDialog(hDlg, LOWORD(wParam)); - } - - break; + case WM_COMMAND: + if (LOWORD(wParam) == IDOK) + { + GetDlgItemText(hDlg, MOZ_EDIT_URI, gLastURI, 100); + } + EndDialog(hDlg, LOWORD(wParam)); + return TRUE; } + return FALSE; } + +/////////////////////////////////////////////////////////////////////////////// +// Win32ChromeUI + +// +// FUNCTION: CreateNativeWindow() +// +// PURPOSE: Creates a new browser dialog. +// +// COMMENTS: +// +// This function loads the browser dialog from a resource template +// and returns the HWND for the webbrowser container dialog item +// to the caller. +// +nativeWindow Win32ChromeUI::CreateNativeWindow(nsIWebBrowserChrome* chrome) +{ + // Load the browser dialog from resource + HWND hwndDialog = CreateDialog(ghInstanceResources, + MAKEINTRESOURCE(IDD_BROWSER), + NULL, + BrowserDlgProc); + if (!hwndDialog) + { + return NULL; + } + + gDialogCount++; + + // Stick a menu onto it + HMENU hmenuDlg = LoadMenu(ghInstanceResources, MAKEINTRESOURCE(IDC_WINEMBED)); + SetMenu(hwndDialog, hmenuDlg); + + // Add some interesting URLs to the address drop down + HWND hwndAddress = GetDlgItem(hwndDialog, IDC_ADDRESS); + SendMessage(hwndAddress, CB_ADDSTRING, 0, (LPARAM) _T("http://www.mozilla.org/")); + SendMessage(hwndAddress, CB_ADDSTRING, 0, (LPARAM) _T("http://www.netscape.com/")); + SendMessage(hwndAddress, CB_ADDSTRING, 0, (LPARAM) _T("http://127.0.0.1/")); + SendMessage(hwndAddress, CB_ADDSTRING, 0, (LPARAM) _T("http://www.yahoo.com/")); + SendMessage(hwndAddress, CB_ADDSTRING, 0, (LPARAM) _T("http://www.travelocity.com/")); + SendMessage(hwndAddress, CB_ADDSTRING, 0, (LPARAM) _T("http://www.disney.com/")); + SendMessage(hwndAddress, CB_ADDSTRING, 0, (LPARAM) _T("http://www.go.com/")); + SendMessage(hwndAddress, CB_ADDSTRING, 0, (LPARAM) _T("http://www.google.com/")); + SendMessage(hwndAddress, CB_ADDSTRING, 0, (LPARAM) _T("http://www.ebay.com/")); + SendMessage(hwndAddress, CB_ADDSTRING, 0, (LPARAM) _T("http://www.shockwave.com/")); + SendMessage(hwndAddress, CB_ADDSTRING, 0, (LPARAM) _T("http://www.slashdot.org/")); + SendMessage(hwndAddress, CB_ADDSTRING, 0, (LPARAM) _T("http://www.quicken.com/")); + + // Fetch the browser window handle + HWND hwndBrowser = GetDlgItem(hwndDialog, IDC_BROWSER); + SetWindowLong(hwndBrowser, GWL_USERDATA, (LONG)chrome); // save the browser LONG_PTR. + SetWindowLong(hwndBrowser, GWL_STYLE, GetWindowLong(hwndBrowser, GWL_STYLE) | WS_CLIPCHILDREN); + return hwndBrowser; +} + + +// +// FUNCTION: UpdateStatusBarText() +// +// PURPOSE: Set the status bar text. +// +void Win32ChromeUI::UpdateStatusBarText(nsIWebBrowserChrome *aChrome, const PRUnichar* aStatusText) +{ + HWND hwndDlg = GetBrowserDlgFromChrome(aChrome); + nsCString status; + if (aStatusText) + status.AssignWithConversion(aStatusText); + SetDlgItemText(hwndDlg, IDC_STATUS, status.GetBuffer()); +} + + +// +// FUNCTION: UpdateCurrentURI() +// +// PURPOSE: Updates the URL address field +// +void Win32ChromeUI::UpdateCurrentURI(nsIWebBrowserChrome *aChrome) +{ + nsCOMPtr webBrowser; + nsCOMPtr webNavigation; + aChrome->GetWebBrowser(getter_AddRefs(webBrowser)); + webNavigation = do_QueryInterface(webBrowser); + + nsCOMPtr currentURI; + webNavigation->GetCurrentURI(getter_AddRefs(currentURI)); + if (currentURI) + { + nsXPIDLCString uriString; + currentURI->GetSpec(getter_Copies(uriString)); + HWND hwndDlg = GetBrowserDlgFromChrome(aChrome); + SetDlgItemText(hwndDlg, IDC_ADDRESS, uriString.get()); + } +} + + +// +// FUNCTION: UpdateBusyState() +// +// PURPOSE: Refreshes the stop/go buttons in the browser dialog +// +void Win32ChromeUI::UpdateBusyState(nsIWebBrowserChrome *aChrome, PRBool aBusy) +{ + HWND hwndDlg = GetBrowserDlgFromChrome(aChrome); + EnableWindow(GetDlgItem(hwndDlg, IDC_STOP), aBusy); + EnableWindow(GetDlgItem(hwndDlg, IDC_GO), !aBusy); + UpdateUI(aChrome); +} + + +// +// FUNCTION: UpdateProgress() +// +// PURPOSE: Refreshes the progress bar in the browser dialog +// +void Win32ChromeUI::UpdateProgress(nsIWebBrowserChrome *aChrome, PRInt32 aCurrent, PRInt32 aMax) +{ + HWND hwndDlg = GetBrowserDlgFromChrome(aChrome); + HWND hwndProgress = GetDlgItem(hwndDlg, IDC_PROGRESS); + if (aCurrent < 0) + { + aCurrent = 0; + } + if (aCurrent > aMax) + { + aMax = aCurrent + 20; // What to do? + } + SendMessage(hwndProgress, PBM_SETRANGE, 0, MAKELPARAM(0, aMax)); + SendMessage(hwndProgress, PBM_SETPOS, aCurrent, 0); +} + + + diff --git a/mozilla/embedding/tests/winEmbed/winEmbed.rc b/mozilla/embedding/tests/winEmbed/winEmbed.rc index af1a84ea7cb..554190f5a21 100644 --- a/mozilla/embedding/tests/winEmbed/winEmbed.rc +++ b/mozilla/embedding/tests/winEmbed/winEmbed.rc @@ -44,20 +44,33 @@ BEGIN POPUP "&File" BEGIN MENUITEM "New Browser...", MOZ_NewBrowser - MENUITEM "Goto...", MOZ_Open MENUITEM SEPARATOR - MENUITEM "Save...", MOZ_Save + MENUITEM "&Save As...", MOZ_Save MENUITEM "Print Page", MOZ_Print MENUITEM "E&xit", IDM_EXIT END POPUP "&Edit" BEGIN - MENUITEM "Cut", MOZ_Cut - MENUITEM "Copy", MOZ_Copy - MENUITEM "Paste", MOZ_Paste, GRAYED - MENUITEM "Delete", MOZ_Delete, GRAYED + MENUITEM "Cu&t", MOZ_Cut + MENUITEM "&Copy", MOZ_Copy + MENUITEM "&Paste", MOZ_Paste MENUITEM SEPARATOR MENUITEM "Select All", MOZ_SelectAll + MENUITEM "Select None", MOZ_SelectNone + END + POPUP "&Go" + BEGIN + MENUITEM "&Back", MOZ_GoBack + MENUITEM "&Forward", MOZ_GoForward + END + POPUP "&Debug" + BEGIN + MENUITEM "&This space for rent", ID_DEBUG_THISSPACEFORRENT + , GRAYED + END + POPUP "&Help" + BEGIN + MENUITEM "&About winEmbed...", MOZ_About END END @@ -67,16 +80,15 @@ END // Dialog // -MOZ_GetURI DIALOG DISCARDABLE 22, 17, 230, 75 +MOZ_GetURI DIALOG DISCARDABLE 22, 17, 210, 40 STYLE DS_MODALFRAME | WS_CAPTION | WS_SYSMENU -CAPTION "Enter A URL" -FONT 8, "System" +CAPTION "New address" +FONT 8, "MS Sans Serif" BEGIN - EDITTEXT MOZ_EDIT_URI,34,33,182,14,ES_AUTOHSCROLL - DEFPUSHBUTTON "OK",IDOK,182,55,30,11,WS_GROUP - PUSHBUTTON "Cancel",IDNO,146,55,30,11,WS_GROUP - ICON IDI_WINEMBED,IDC_MYICON,8,4,20,20 - LTEXT "URL:",IDC_STATIC,13,34,17,8 + EDITTEXT MOZ_EDIT_URI,34,6,171,12,ES_AUTOHSCROLL + DEFPUSHBUTTON "OK",IDOK,74,23,30,13,WS_GROUP + PUSHBUTTON "Cancel",IDNO,109,23,30,13,WS_GROUP + LTEXT "Address:",IDC_STATIC,4,7,30,8 END @@ -117,14 +129,73 @@ END STRINGTABLE DISCARDABLE BEGIN IDS_APP_TITLE "winEmbed" - IDS_HELLO "Embedding Mozilla is fun!!" - IDC_WINEMBED "WINEMBED" + IDS_HELLO "Embedding Mozilla is so much fun!!" + IDS_ABOUT "winEmbed - Gecko embedding sample" + IDS_ABOUT_TITLE "About winEmbed" END #endif // English (U.S.) resources ///////////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////// +// English (U.K.) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENG) +#ifdef _WIN32 +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_UK +#pragma code_page(1252) +#endif //_WIN32 + +///////////////////////////////////////////////////////////////////////////// +// +// Dialog +// + +IDD_BROWSER DIALOG DISCARDABLE 0, 0, 400, 217 +STYLE WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP | WS_VISIBLE | + WS_CLIPCHILDREN | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME +CAPTION "winEmbed sample" +MENU IDC_WINEMBED +FONT 8, "MS Sans Serif" +BEGIN + PUSHBUTTON "Back",IDC_BACK,1,1,21,13 + PUSHBUTTON "Forward",IDC_FORWARD,23,1,30,13 + PUSHBUTTON "Reload",IDC_RELOAD,57,1,28,13 + PUSHBUTTON "Stop",IDC_STOP,86,1,25,13 + LTEXT "Address:",IDC_STATIC,115,3,28,8 + COMBOBOX IDC_ADDRESS,145,1,193,52,CBS_DROPDOWN | WS_VSCROLL | + WS_TABSTOP + DEFPUSHBUTTON "Go",IDC_GO,340,1,25,13 + CONTROL "Embedded Browser",IDC_BROWSER,"WINEMBED",WS_TABSTOP,0, + 16,400,192 + CONTROL "Status",IDC_STATUS,"Static",SS_LEFTNOWORDWRAP | + SS_SUNKEN | WS_GROUP,0,208,316,9 + CONTROL "Progress1",IDC_PROGRESS,"msctls_progress32",WS_BORDER, + 316,208,84,9 +END + + +///////////////////////////////////////////////////////////////////////////// +// +// DESIGNINFO +// + +#ifdef APSTUDIO_INVOKED +GUIDELINES DESIGNINFO DISCARDABLE +BEGIN + IDD_BROWSER, DIALOG + BEGIN + RIGHTMARGIN, 292 + BOTTOMMARGIN, 216 + END +END +#endif // APSTUDIO_INVOKED + +#endif // English (U.K.) resources +///////////////////////////////////////////////////////////////////////////// + + #ifndef APSTUDIO_INVOKED /////////////////////////////////////////////////////////////////////////////