2000-06-20 07:22:47 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Netscape Public
|
|
|
|
* License Version 1.1 (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.org 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.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Doug Turner <dougt@netscape.com>
|
|
|
|
*/
|
|
|
|
|
2000-06-24 04:03:10 +04:00
|
|
|
#include <stdio.h>
|
2000-06-20 07:22:47 +04:00
|
|
|
#include "stdafx.h"
|
2000-06-27 05:30:20 +04:00
|
|
|
#include "Windows.h"
|
2000-06-20 07:22:47 +04:00
|
|
|
#include "resource.h"
|
|
|
|
|
|
|
|
|
2000-08-01 05:37:07 +04:00
|
|
|
#include "nsIContentViewerEdit.h"
|
|
|
|
|
2000-06-27 05:30:20 +04:00
|
|
|
#include "nsEmbedAPI.h"
|
2000-07-05 01:53:27 +04:00
|
|
|
#include "WebBrowserChrome.h"
|
2000-06-20 07:22:47 +04:00
|
|
|
|
|
|
|
#define MAX_LOADSTRING 100
|
|
|
|
|
2000-08-01 05:37:07 +04:00
|
|
|
#define IDC_Status 100
|
|
|
|
|
2000-06-20 07:22:47 +04:00
|
|
|
// Global Variables:
|
2000-07-05 01:53:27 +04:00
|
|
|
HINSTANCE hInst;
|
|
|
|
TCHAR szTitle[MAX_LOADSTRING];
|
|
|
|
|
|
|
|
TCHAR szWindowClass[MAX_LOADSTRING];
|
2000-06-20 07:22:47 +04:00
|
|
|
|
|
|
|
// Foward declarations of functions included in this code module:
|
|
|
|
ATOM MyRegisterClass(HINSTANCE hInstance);
|
|
|
|
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
|
2000-06-27 05:30:20 +04:00
|
|
|
LRESULT CALLBACK GetURI(HWND, UINT, WPARAM, LPARAM);
|
2000-06-24 04:03:10 +04:00
|
|
|
|
|
|
|
|
2000-06-27 05:30:20 +04:00
|
|
|
char gLastURI[100];
|
2000-06-24 04:03:10 +04:00
|
|
|
|
2000-08-01 05:37:07 +04:00
|
|
|
// utility function
|
|
|
|
nsresult ResizeEmbedding(nsIWebBrowserChrome* chrome)
|
|
|
|
{
|
|
|
|
if (!chrome)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIBaseWindow> 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(char* url)
|
|
|
|
{
|
|
|
|
WebBrowserChrome * chrome = new WebBrowserChrome();
|
|
|
|
if (!chrome)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
NS_ADDREF(chrome); // native window will hold the addref.
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWebBrowser> newBrowser;
|
|
|
|
chrome->GetNewBrowser(0, getter_AddRefs(newBrowser));
|
|
|
|
if (!newBrowser)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// Place it where we want it.
|
|
|
|
ResizeEmbedding(NS_STATIC_CAST(nsIWebBrowserChrome*, chrome));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(newBrowser));
|
|
|
|
return webNav->LoadURI(NS_ConvertASCIItoUCS2(url).GetUnicode());
|
|
|
|
}
|
|
|
|
|
2000-06-24 04:03:10 +04:00
|
|
|
int main ()
|
|
|
|
{
|
|
|
|
|
2000-07-05 01:53:27 +04:00
|
|
|
printf("\nYou are embedded, man!\n\n");
|
2000-06-24 04:03:10 +04:00
|
|
|
|
|
|
|
MSG msg;
|
|
|
|
HINSTANCE hInstance = GetModuleHandle(NULL);
|
|
|
|
|
2000-06-20 07:22:47 +04:00
|
|
|
// Initialize global strings
|
|
|
|
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
|
|
|
|
LoadString(hInstance, IDC_WINEMBED, szWindowClass, MAX_LOADSTRING);
|
|
|
|
MyRegisterClass(hInstance);
|
|
|
|
|
2000-06-27 05:30:20 +04:00
|
|
|
// Init Embedding APIs
|
2000-08-10 10:46:00 +04:00
|
|
|
NS_InitEmbedding("");
|
2000-06-24 04:03:10 +04:00
|
|
|
|
2000-06-27 05:30:20 +04:00
|
|
|
// put up at lease on browser window ....
|
|
|
|
/////////////////////////////////////////////////////////////
|
2000-08-01 05:37:07 +04:00
|
|
|
OpenWebPage("http://people.netscape.com/dougt");
|
2000-06-27 05:30:20 +04:00
|
|
|
/////////////////////////////////////////////////////////////
|
2000-06-24 04:03:10 +04:00
|
|
|
|
2000-06-20 07:22:47 +04:00
|
|
|
|
|
|
|
// Main message loop:
|
|
|
|
while (GetMessage(&msg, NULL, 0, 0))
|
|
|
|
{
|
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessage(&msg);
|
|
|
|
}
|
2000-06-24 04:03:10 +04:00
|
|
|
|
2000-08-01 05:37:07 +04:00
|
|
|
// Close down Embedding APIs
|
2000-06-20 07:22:47 +04:00
|
|
|
NS_TermEmbedding();
|
|
|
|
|
|
|
|
return msg.wParam;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// FUNCTION: MyRegisterClass()
|
|
|
|
//
|
|
|
|
// PURPOSE: Registers the window class.
|
|
|
|
//
|
|
|
|
// COMMENTS:
|
|
|
|
//
|
|
|
|
// This function and its usage is only necessary if you want this code
|
|
|
|
// to be compatible with Win32 systems prior to the 'RegisterClassEx'
|
|
|
|
// function that was added to Windows 95. It is important to call this function
|
|
|
|
// so that the application will get 'well formed' small icons associated
|
|
|
|
// with it.
|
|
|
|
//
|
|
|
|
ATOM MyRegisterClass(HINSTANCE hInstance)
|
|
|
|
{
|
|
|
|
WNDCLASSEX wcex;
|
|
|
|
|
|
|
|
wcex.cbSize = sizeof(WNDCLASSEX);
|
|
|
|
|
|
|
|
wcex.style = CS_HREDRAW | CS_VREDRAW;
|
|
|
|
wcex.lpfnWndProc = (WNDPROC)WndProc;
|
|
|
|
wcex.cbClsExtra = 0;
|
|
|
|
wcex.cbWndExtra = 0;
|
|
|
|
wcex.hInstance = hInstance;
|
|
|
|
wcex.hIcon = LoadIcon(hInstance, (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);
|
|
|
|
|
|
|
|
return RegisterClassEx(&wcex);
|
|
|
|
}
|
|
|
|
|
2000-06-24 04:03:10 +04:00
|
|
|
|
|
|
|
|
2000-08-01 05:37:07 +04:00
|
|
|
nativeWindow CreateNativeWindow(nsIWebBrowserChrome* chrome)
|
2000-06-20 07:22:47 +04:00
|
|
|
{
|
2000-08-01 05:37:07 +04:00
|
|
|
HWND mainWindow;
|
|
|
|
|
|
|
|
mainWindow = CreateWindow( szWindowClass,
|
|
|
|
szTitle,
|
|
|
|
WS_OVERLAPPEDWINDOW,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
450,
|
|
|
|
450,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
GetModuleHandle(NULL),
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (!mainWindow)
|
2000-07-05 01:53:27 +04:00
|
|
|
return NULL;
|
2000-06-27 05:30:20 +04:00
|
|
|
|
2000-08-01 05:37:07 +04:00
|
|
|
SetWindowLong( mainWindow, GWL_USERDATA, (LONG)chrome); // save the browser LONG_PTR.
|
2000-06-20 07:22:47 +04:00
|
|
|
|
2000-08-01 05:37:07 +04:00
|
|
|
ShowWindow(mainWindow, SW_SHOWDEFAULT);
|
|
|
|
UpdateWindow(mainWindow);
|
2000-06-20 07:22:47 +04:00
|
|
|
|
2000-08-01 05:37:07 +04:00
|
|
|
return mainWindow;
|
2000-06-20 07:22:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
|
|
|
|
//
|
|
|
|
// PURPOSE: Processes messages for the main window.
|
|
|
|
//
|
|
|
|
// WM_COMMAND - process the application menu
|
|
|
|
// WM_PAINT - Paint the main window
|
|
|
|
// WM_DESTROY - post a quit message and return
|
|
|
|
//
|
|
|
|
//
|
|
|
|
LRESULT CALLBACK WndProc(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);
|
2000-08-01 05:37:07 +04:00
|
|
|
nsIWebBrowserChrome *chrome = (nsIWebBrowserChrome *) GetWindowLong(hWnd, GWL_USERDATA);
|
2000-06-20 07:22:47 +04:00
|
|
|
|
|
|
|
switch (message)
|
|
|
|
{
|
|
|
|
case WM_COMMAND:
|
|
|
|
wmId = LOWORD(wParam);
|
|
|
|
wmEvent = HIWORD(wParam);
|
|
|
|
// Parse the menu selections:
|
|
|
|
switch (wmId)
|
|
|
|
{
|
2000-06-27 05:30:20 +04:00
|
|
|
case MOZ_NewBrowser:
|
|
|
|
gLastURI[0] = 0;
|
|
|
|
if (DialogBox(hInst, (LPCTSTR)MOZ_GetURI, hWnd, (DLGPROC)GetURI))
|
2000-08-01 05:37:07 +04:00
|
|
|
OpenWebPage(gLastURI);
|
2000-06-27 05:30:20 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MOZ_NewEditor:
|
|
|
|
gLastURI[0] = 0;
|
|
|
|
break;
|
|
|
|
|
2000-06-20 07:22:47 +04:00
|
|
|
case MOZ_Open:
|
2000-06-27 05:30:20 +04:00
|
|
|
gLastURI[0] = 0;
|
2000-08-01 05:37:07 +04:00
|
|
|
if (chrome && DialogBox(hInst, (LPCTSTR)MOZ_GetURI, hWnd, (DLGPROC)GetURI))
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIWebBrowser> wb;
|
|
|
|
chrome->GetWebBrowser(getter_AddRefs(wb));
|
|
|
|
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(wb));
|
|
|
|
webNav->LoadURI(NS_ConvertASCIItoUCS2(gLastURI).GetUnicode());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MOZ_Save:
|
|
|
|
|
|
|
|
if (chrome)
|
2000-06-27 05:30:20 +04:00
|
|
|
{
|
2000-08-01 05:37:07 +04:00
|
|
|
nsCOMPtr<nsIWebBrowser> wb;
|
|
|
|
chrome->GetWebBrowser(getter_AddRefs(wb));
|
|
|
|
|
|
|
|
nsCOMPtr <nsIDocShell> rootDocShell;
|
|
|
|
wb->GetDocShell(getter_AddRefs(rootDocShell));
|
|
|
|
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContentViewer> pContentViewer;
|
|
|
|
nsresult res = rootDocShell->GetContentViewer(getter_AddRefs(pContentViewer));
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(res))
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContentViewerFile> spContentViewerFile = do_QueryInterface(pContentViewer);
|
|
|
|
spContentViewerFile->Save();
|
|
|
|
}
|
2000-06-27 05:30:20 +04:00
|
|
|
}
|
|
|
|
break;
|
2000-08-01 05:37:07 +04:00
|
|
|
|
2000-06-20 07:22:47 +04:00
|
|
|
case MOZ_Print:
|
2000-06-27 05:30:20 +04:00
|
|
|
|
2000-08-01 05:37:07 +04:00
|
|
|
if (chrome)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIWebBrowser> wb;
|
|
|
|
chrome->GetWebBrowser(getter_AddRefs(wb));
|
|
|
|
|
|
|
|
nsCOMPtr <nsIDocShell> rootDocShell;
|
|
|
|
wb->GetDocShell(getter_AddRefs(rootDocShell));
|
|
|
|
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContentViewer> pContentViewer;
|
|
|
|
nsresult res = rootDocShell->GetContentViewer(getter_AddRefs(pContentViewer));
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(res))
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContentViewerFile> 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<nsIWebBrowser> wb;
|
|
|
|
chrome->GetWebBrowser(getter_AddRefs(wb));
|
|
|
|
|
|
|
|
nsCOMPtr <nsIDocShell> rootDocShell;
|
|
|
|
wb->GetDocShell(getter_AddRefs(rootDocShell));
|
|
|
|
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContentViewer> pContentViewer;
|
|
|
|
nsresult res = rootDocShell->GetContentViewer(getter_AddRefs(pContentViewer));
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(res))
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContentViewerEdit> spContentViewerEdit = do_QueryInterface(pContentViewer);
|
|
|
|
if (message == MOZ_Cut)
|
|
|
|
spContentViewerEdit->CopySelection();
|
|
|
|
else if (message == MOZ_Copy)
|
|
|
|
spContentViewerEdit->CutSelection();
|
|
|
|
else if (message == MOZ_SelectAll)
|
|
|
|
spContentViewerEdit->SelectAll();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-06-20 07:22:47 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return DefWindowProc(hWnd, message, wParam, lParam);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2000-08-01 05:37:07 +04:00
|
|
|
case WM_SIZE:
|
|
|
|
ResizeEmbedding(chrome);
|
2000-06-20 07:22:47 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_PAINT:
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
EndPaint(hWnd, &ps);
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case WM_DESTROY:
|
2000-06-27 05:30:20 +04:00
|
|
|
PostQuitMessage(0);
|
2000-08-01 05:37:07 +04:00
|
|
|
NS_RELEASE(chrome);
|
2000-06-20 07:22:47 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return DefWindowProc(hWnd, message, wParam, lParam);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mesage handler for about box.
|
2000-06-27 05:30:20 +04:00
|
|
|
LRESULT CALLBACK GetURI(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
|
2000-06-20 07:22:47 +04:00
|
|
|
{
|
|
|
|
switch (message)
|
|
|
|
{
|
|
|
|
case WM_INITDIALOG:
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case WM_COMMAND:
|
|
|
|
if (LOWORD(wParam) == IDOK)
|
|
|
|
{
|
2000-06-27 05:30:20 +04:00
|
|
|
GetDlgItemText(hDlg, MOZ_EDIT_URI, gLastURI, 100);
|
2000-06-20 07:22:47 +04:00
|
|
|
EndDialog(hDlg, LOWORD(wParam));
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else if (LOWORD(wParam) == IDNO)
|
|
|
|
{
|
|
|
|
EndDialog(hDlg, LOWORD(wParam));
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|