1998-04-14 00:24:54 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* 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/
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* 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.
|
1998-04-14 00:24:54 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1998-04-14 00:24:54 +04:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 06:40:37 +03:00
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
1998-04-14 00:24:54 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
1999-04-18 23:02:18 +04:00
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIEventQueueService.h"
|
1999-05-07 10:48:55 +04:00
|
|
|
#include "nsIEventQueue.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsIButton.h"
|
|
|
|
#include "nsICheckButton.h"
|
1998-07-29 22:51:45 +04:00
|
|
|
#include "nsILookAndFeel.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsIRadioButton.h"
|
|
|
|
#include "nsITextWidget.h"
|
|
|
|
#include "nsIScrollbar.h"
|
|
|
|
#include "nsGUIEvent.h"
|
|
|
|
#include "nsIEnumerator.h"
|
|
|
|
#include "nsIRenderingContext.h"
|
|
|
|
#include "nsFont.h"
|
|
|
|
#include "nsUnitConversion.h"
|
|
|
|
#include "nsColor.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "Scribble.h"
|
|
|
|
#include "nsIDeviceContext.h"
|
|
|
|
#include "nsTransform2D.h"
|
|
|
|
#include "nsGfxCIID.h"
|
|
|
|
#include "nsWidgetsCID.h"
|
1998-05-21 02:02:14 +04:00
|
|
|
#include "nsIAppShell.h"
|
1998-09-15 00:43:58 +04:00
|
|
|
#include "nsWidgetSupport.h"
|
1998-09-14 19:46:23 +04:00
|
|
|
#include "nsIImageManager.h"
|
|
|
|
#include "nsIImageRequest.h"
|
|
|
|
#include "nsIImageObserver.h"
|
1998-09-16 01:58:25 +04:00
|
|
|
#include "nsIImageGroup.h"
|
|
|
|
#include "net.h"
|
1998-09-15 00:43:58 +04:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
ScribbleApp scribbleData;
|
|
|
|
|
1998-09-16 01:58:25 +04:00
|
|
|
static nsIImageManager *gImageManager = nsnull;
|
|
|
|
static nsIImageGroup *gImageGroup = nsnull;
|
|
|
|
static nsIImageRequest *gImageReq = nsnull;
|
|
|
|
|
1998-07-08 20:58:51 +04:00
|
|
|
#ifdef XP_PC
|
1999-04-18 23:02:18 +04:00
|
|
|
#define XPCOM_DLL "xpcom32.dll"
|
1999-10-10 05:32:59 +04:00
|
|
|
#define WIDGET_DLL "gkwidget.dll"
|
|
|
|
#define GFXWIN_DLL "gkgfxwin.dll"
|
1998-07-08 20:58:51 +04:00
|
|
|
#define TEXT_HEIGHT 25
|
1998-09-16 01:58:25 +04:00
|
|
|
#define FILE_URL_PREFIX "file://"
|
1998-07-08 20:58:51 +04:00
|
|
|
#endif
|
|
|
|
|
1999-06-25 17:34:39 +04:00
|
|
|
#if defined(XP_UNIX) || defined(XP_BEOS)
|
1999-06-05 02:17:30 +04:00
|
|
|
#define XPCOM_DLL "libxpcom"MOZ_DLL_SUFFIX
|
1998-07-08 20:58:51 +04:00
|
|
|
#define TEXT_HEIGHT 30
|
1998-09-16 01:58:25 +04:00
|
|
|
#define FILE_URL_PREFIX "file://"
|
1998-07-08 20:58:51 +04:00
|
|
|
#endif
|
|
|
|
|
1998-08-26 18:15:34 +04:00
|
|
|
#ifdef XP_MAC
|
1999-04-18 23:02:18 +04:00
|
|
|
#define XPCOM_DLL "XPCOM_DLL"
|
1998-08-26 18:15:34 +04:00
|
|
|
#define WIDGET_DLL "WIDGET_DLL"
|
1998-11-09 06:03:09 +03:00
|
|
|
#define GFXWIN_DLL "GFXWIN_DLL"
|
1998-08-26 18:15:34 +04:00
|
|
|
#define TEXT_HEIGHT 30
|
1998-09-16 01:58:25 +04:00
|
|
|
#define FILE_URL_PREFIX "file:///"
|
1998-08-26 18:15:34 +04:00
|
|
|
#endif
|
|
|
|
|
2000-02-03 01:39:43 +03:00
|
|
|
#if !defined(WIDGET_DLL)
|
|
|
|
#error WIDGET_DLL must be defined
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(GFXWIN_DLL)
|
|
|
|
#error GFXWIN_DLL must be defined
|
|
|
|
#endif
|
|
|
|
|
1998-11-04 09:36:48 +03:00
|
|
|
#define COLOR_FIELDS_X 50
|
|
|
|
#define COLOR_FIELDS_Y 350
|
1998-09-14 19:46:23 +04:00
|
|
|
|
|
|
|
static nsIImage *gImage = nsnull;
|
|
|
|
static PRBool gInstalledColorMap = PR_FALSE;
|
|
|
|
|
1998-09-16 01:58:25 +04:00
|
|
|
void MyLoadImage(char *aFileName);
|
1998-09-14 19:46:23 +04:00
|
|
|
|
1999-04-18 23:02:18 +04:00
|
|
|
static NS_DEFINE_IID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
|
1999-05-07 10:48:55 +04:00
|
|
|
static NS_DEFINE_IID(kEventQueueCID, NS_EVENTQUEUE_CID);
|
1998-05-21 02:02:14 +04:00
|
|
|
static NS_DEFINE_IID(kCAppShellCID, NS_APPSHELL_CID);
|
1998-10-29 17:06:26 +03:00
|
|
|
static NS_DEFINE_IID(kCToolkitCID, NS_TOOLKIT_CID);
|
1999-04-18 23:02:18 +04:00
|
|
|
static NS_DEFINE_IID(kIEventQueueServiceIID, NS_IEVENTQUEUESERVICE_IID);
|
1998-05-21 02:02:14 +04:00
|
|
|
static NS_DEFINE_IID(kIAppShellIID, NS_IAPPSHELL_IID);
|
1998-04-14 00:24:54 +04:00
|
|
|
static NS_DEFINE_IID(kIWidgetIID, NS_IWIDGET_IID);
|
|
|
|
static NS_DEFINE_IID(kIButtonIID, NS_IBUTTON_IID);
|
|
|
|
static NS_DEFINE_IID(kIScrollbarIID, NS_ISCROLLBAR_IID);
|
|
|
|
static NS_DEFINE_IID(kICheckButtonIID, NS_ICHECKBUTTON_IID);
|
|
|
|
static NS_DEFINE_IID(kITextWidgetIID, NS_ITEXTWIDGET_IID);
|
|
|
|
static NS_DEFINE_IID(kIRadioButtonIID, NS_IRADIOBUTTON_IID);
|
1998-07-29 22:51:45 +04:00
|
|
|
static NS_DEFINE_IID(kILookAndFeelIID, NS_ILOOKANDFEEL_IID);
|
1999-05-07 11:35:36 +04:00
|
|
|
static NS_DEFINE_IID(kCClipboardCID, NS_CLIPBOARD_CID);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
//
|
|
|
|
// Main window events
|
|
|
|
//
|
|
|
|
nsEventStatus PR_CALLBACK HandleEventMain(nsGUIEvent *aEvent)
|
|
|
|
{
|
|
|
|
|
1998-07-08 20:58:51 +04:00
|
|
|
//printf("aEvent->message %d on 0x%X\n", aEvent->message, aEvent->widget);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
nsEventStatus result = nsEventStatus_eConsumeNoDefault;
|
|
|
|
switch(aEvent->message) {
|
|
|
|
|
|
|
|
case NS_SIZE:
|
|
|
|
{
|
|
|
|
nsIEnumerator *enumer = aEvent->widget->GetChildren();
|
|
|
|
if (enumer) {
|
1998-12-01 20:58:50 +03:00
|
|
|
nsISupports *child;
|
|
|
|
if (NS_SUCCEEDED(enumer->CurrentItem(&child))) {
|
1998-04-14 00:24:54 +04:00
|
|
|
nsIWidget *widget;
|
1998-12-01 20:58:50 +03:00
|
|
|
if (NS_OK == child->QueryInterface(kIWidgetIID, (void**)&widget)) {
|
1998-07-29 22:51:45 +04:00
|
|
|
widget->Resize(0, 0, 200,
|
|
|
|
((nsSizeEvent*)aEvent)->windowSize->height, PR_TRUE);
|
1998-12-01 23:58:53 +03:00
|
|
|
NS_IF_RELEASE(widget);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1998-12-01 23:58:53 +03:00
|
|
|
NS_IF_RELEASE(child);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(enumer);
|
|
|
|
delete enumer;
|
|
|
|
}
|
|
|
|
|
|
|
|
scribbleData.drawPane->Resize(200,
|
1998-07-29 22:51:45 +04:00
|
|
|
0,
|
|
|
|
((nsSizeEvent*)aEvent)->windowSize->width - 200,
|
|
|
|
((nsSizeEvent*)aEvent)->windowSize->height,
|
|
|
|
PR_TRUE);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case NS_DESTROY:
|
|
|
|
printf("Destroy Window...Release window\n");
|
1998-09-15 00:43:58 +04:00
|
|
|
NS_IF_RELEASE(scribbleData.red);
|
|
|
|
NS_IF_RELEASE(scribbleData.green);
|
|
|
|
NS_IF_RELEASE(scribbleData.blue);
|
|
|
|
NS_IF_RELEASE(scribbleData.scribble);
|
|
|
|
NS_IF_RELEASE(scribbleData.lines);
|
1998-04-14 00:24:54 +04:00
|
|
|
// NS_RELEASE(scribbleData.drawPane);
|
|
|
|
// NS_RELEASE(scribbleData.mainWindow);
|
|
|
|
|
|
|
|
exit(0); // for now
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
result = nsEventStatus_eIgnore;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Control pane events
|
|
|
|
//
|
|
|
|
nsEventStatus PR_CALLBACK HandleEventControlPane(nsGUIEvent *aEvent)
|
|
|
|
{
|
1998-07-08 20:58:51 +04:00
|
|
|
//printf("aEvent->message %d on 0x%X\n", aEvent->message, aEvent->widget);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
switch(aEvent->message) {
|
|
|
|
case NS_PAINT:
|
|
|
|
{
|
|
|
|
// paint the background
|
|
|
|
nsIRenderingContext *drawCtx = ((nsPaintEvent*)aEvent)->renderingContext;
|
|
|
|
drawCtx->SetColor(aEvent->widget->GetBackgroundColor());
|
|
|
|
drawCtx->FillRect(*(((nsPaintEvent*)aEvent)->rect));
|
|
|
|
|
|
|
|
// draw the line separating the two panes
|
|
|
|
drawCtx->SetColor(aEvent->widget->GetForegroundColor());
|
|
|
|
drawCtx->DrawLine(198, 0, 198, 800);
|
|
|
|
drawCtx->DrawLine(199, 0, 199, 800);
|
|
|
|
drawCtx->DrawLine(200, 0, 200, 800);
|
|
|
|
|
|
|
|
// draw the colors text
|
|
|
|
nsFont font("Times", NS_FONT_STYLE_NORMAL,
|
|
|
|
NS_FONT_VARIANT_NORMAL,
|
|
|
|
NS_FONT_WEIGHT_BOLD,
|
|
|
|
0,
|
|
|
|
12);
|
|
|
|
drawCtx->SetFont(font);
|
|
|
|
|
1998-11-04 09:36:48 +03:00
|
|
|
int y = COLOR_FIELDS_Y + TEXT_HEIGHT/2 - font.size/2;
|
1998-04-14 00:24:54 +04:00
|
|
|
nsString red("Red");
|
|
|
|
drawCtx->SetColor(NS_RGB(255, 0, 0));
|
1999-01-28 08:06:06 +03:00
|
|
|
drawCtx->DrawString(red, 50, y);
|
1998-07-08 20:58:51 +04:00
|
|
|
y += TEXT_HEIGHT+2;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
nsString green("Green");
|
|
|
|
drawCtx->SetColor(NS_RGB(0, 255, 0));
|
1999-01-28 08:06:06 +03:00
|
|
|
drawCtx->DrawString(green, 50, y);
|
1998-07-08 20:58:51 +04:00
|
|
|
y += TEXT_HEIGHT+2;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
nsString blue("Blue");
|
|
|
|
drawCtx->SetColor(NS_RGB(0, 0, 255));
|
1999-01-28 08:06:06 +03:00
|
|
|
drawCtx->DrawString(blue, 50, y);
|
1998-07-08 20:58:51 +04:00
|
|
|
y += TEXT_HEIGHT+2;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
return nsEventStatus_eConsumeNoDefault;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Graphic pane events
|
|
|
|
//
|
|
|
|
nsEventStatus PR_CALLBACK HandleEventGraphicPane(nsGUIEvent *aEvent)
|
|
|
|
{
|
1998-07-08 20:58:51 +04:00
|
|
|
//printf("aEvent->message %d on 0x%X\n", aEvent->message, aEvent->widget);
|
1998-04-14 00:24:54 +04:00
|
|
|
switch(aEvent->message) {
|
|
|
|
|
|
|
|
case NS_PAINT:
|
|
|
|
{
|
|
|
|
nsIRenderingContext *drawCtx = ((nsPaintEvent*)aEvent)->renderingContext;
|
|
|
|
drawCtx->SetColor(aEvent->widget->GetBackgroundColor());
|
|
|
|
drawCtx->FillRect(*(((nsPaintEvent*)aEvent)->rect));
|
|
|
|
|
|
|
|
return nsEventStatus_eConsumeNoDefault;
|
|
|
|
}
|
|
|
|
|
|
|
|
case NS_MOUSE_LEFT_BUTTON_DOWN:
|
|
|
|
aEvent->widget->SetFocus();
|
|
|
|
scribbleData.isDrawing = PR_TRUE;
|
|
|
|
scribbleData.mousePos = ((nsGUIEvent*)aEvent)->point;
|
|
|
|
return nsEventStatus_eConsumeNoDefault;
|
|
|
|
|
|
|
|
case NS_MOUSE_LEFT_BUTTON_UP:
|
|
|
|
scribbleData.isDrawing = PR_FALSE;
|
|
|
|
return nsEventStatus_eConsumeNoDefault;
|
|
|
|
|
|
|
|
case NS_MOUSE_MOVE:
|
|
|
|
{
|
|
|
|
if (scribbleData.isDrawing) {
|
1998-09-03 02:01:18 +04:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
nsIRenderingContext *drawCtx = aEvent->widget->GetRenderingContext();
|
1998-09-14 19:46:23 +04:00
|
|
|
drawCtx->SetColor(aEvent->widget->GetForegroundColor());
|
1998-04-14 00:24:54 +04:00
|
|
|
drawCtx->DrawLine(scribbleData.mousePos.x,
|
|
|
|
scribbleData.mousePos.y,
|
|
|
|
((nsGUIEvent*)aEvent)->point.x,
|
|
|
|
((nsGUIEvent*)aEvent)->point.y);
|
|
|
|
|
1998-09-15 00:43:58 +04:00
|
|
|
PRBool state;
|
|
|
|
scribbleData.scribble->GetState(state);
|
|
|
|
if (state)
|
1998-09-03 02:01:18 +04:00
|
|
|
scribbleData.mousePos = ((nsGUIEvent*)aEvent)->point;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
|
|
|
|
NS_RELEASE(drawCtx);
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsEventStatus_eConsumeNoDefault;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Buttons events
|
|
|
|
//
|
|
|
|
nsEventStatus PR_CALLBACK HandleEventButton(nsGUIEvent *aEvent)
|
|
|
|
{
|
1998-07-08 20:58:51 +04:00
|
|
|
//printf("aEvent->message %d on 0x%X\n", aEvent->message, aEvent->widget);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
switch(aEvent->message) {
|
|
|
|
case NS_MOUSE_LEFT_BUTTON_UP:
|
|
|
|
scribbleData.drawPane->Invalidate(PR_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
}
|
|
|
|
|
1998-07-07 21:56:24 +04:00
|
|
|
//
|
|
|
|
// Buttons events
|
|
|
|
//
|
|
|
|
nsEventStatus PR_CALLBACK HandleEventRadioButton(nsGUIEvent *aEvent)
|
|
|
|
{
|
1998-07-08 20:58:51 +04:00
|
|
|
//printf("aEvent->message %d on 0x%X\n", aEvent->message, aEvent->widget);
|
1998-07-07 21:56:24 +04:00
|
|
|
|
|
|
|
switch(aEvent->message) {
|
|
|
|
case NS_MOUSE_LEFT_BUTTON_UP: {
|
|
|
|
nsIWidget * win;
|
|
|
|
if (NS_OK == scribbleData.lines->QueryInterface(kIWidgetIID, (void**)&win)) {
|
|
|
|
if (win == aEvent->widget) {
|
|
|
|
scribbleData.lines->SetState(PR_TRUE);
|
|
|
|
scribbleData.scribble->SetState(PR_FALSE);
|
|
|
|
} else {
|
|
|
|
scribbleData.lines->SetState(PR_FALSE);
|
|
|
|
scribbleData.scribble->SetState(PR_TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
}
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Handle events for the auto-mode (rectangles/circles)
|
|
|
|
//
|
|
|
|
nsEventStatus PR_CALLBACK HandleEventCheck(nsGUIEvent *aEvent)
|
|
|
|
{
|
1998-07-08 20:58:51 +04:00
|
|
|
//printf("aEvent->message %d on 0x%X\n", aEvent->message, aEvent->widget);
|
|
|
|
//printf("aEvent->message %d == %d on 0x%X\n", aEvent->message, NS_MOUSE_LEFT_BUTTON_UP, aEvent->widget);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
switch(aEvent->message) {
|
|
|
|
case NS_MOUSE_LEFT_BUTTON_UP:
|
|
|
|
{
|
|
|
|
nsICheckButton *option;
|
|
|
|
|
|
|
|
if (NS_OK == aEvent->widget->QueryInterface(kICheckButtonIID, (void**)&option)) {
|
|
|
|
// invert the two checkboxes state
|
1998-09-15 00:43:58 +04:00
|
|
|
PRBool state;
|
|
|
|
option->GetState(state);
|
1998-04-14 00:24:54 +04:00
|
|
|
option->SetState((state) ? PR_FALSE : PR_TRUE);
|
|
|
|
|
|
|
|
if (state == PR_FALSE) {
|
|
|
|
nsAutoString buf;
|
|
|
|
option->GetLabel(buf);
|
|
|
|
|
|
|
|
nsIRenderingContext *drawCtx = scribbleData.drawPane->GetRenderingContext();
|
|
|
|
|
|
|
|
//
|
|
|
|
srand(aEvent->time);
|
|
|
|
if (drawCtx) {
|
|
|
|
|
|
|
|
// a sort of random rect
|
|
|
|
nsRect rect;
|
|
|
|
scribbleData.drawPane->GetBounds(rect);
|
1998-10-29 17:06:26 +03:00
|
|
|
#if 0
|
1998-09-05 01:12:12 +04:00
|
|
|
nscoord x = rect.x;
|
|
|
|
nscoord y = rect.y;
|
1998-10-29 17:06:26 +03:00
|
|
|
#else
|
|
|
|
nscoord x = 0;
|
|
|
|
nscoord y = 0;
|
|
|
|
#endif
|
1998-04-14 00:24:54 +04:00
|
|
|
nscoord width = rect.width;
|
|
|
|
nscoord height = rect.height;
|
|
|
|
|
|
|
|
nsString circles("Circles");
|
|
|
|
nsString rects("Rectangles");
|
1998-09-14 19:46:23 +04:00
|
|
|
nsString image("Image");
|
1998-04-14 00:24:54 +04:00
|
|
|
if (buf.Equals(circles)) {
|
|
|
|
for (int i = 0; i < 100; i++) {
|
|
|
|
drawCtx->SetColor((nscolor)rand());
|
|
|
|
|
1998-09-05 01:12:12 +04:00
|
|
|
rect.MoveTo(x+(rand() % width),y+( rand() % height));
|
1998-04-14 00:24:54 +04:00
|
|
|
rect.SizeTo(rand() % (width - rect.x),
|
|
|
|
rand() % (height - rect.y));
|
|
|
|
drawCtx->DrawEllipse(rect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (buf.Equals(rects)) {
|
|
|
|
for (int i = 0; i < 100; i++) {
|
|
|
|
drawCtx->SetColor((nscolor)rand());
|
|
|
|
|
1998-09-15 00:43:58 +04:00
|
|
|
rect.MoveTo(x+(rand() % width+1),y+( rand() % height+1));
|
|
|
|
rect.SizeTo(rand() % (width - rect.x)+1,
|
|
|
|
rand() % (height - rect.y)+1);
|
1998-04-14 00:24:54 +04:00
|
|
|
drawCtx->DrawRect(rect);
|
|
|
|
}
|
|
|
|
}
|
1998-09-14 19:46:23 +04:00
|
|
|
else
|
|
|
|
if (buf.Equals(image))
|
|
|
|
{
|
1998-09-16 20:24:21 +04:00
|
|
|
#ifdef XP_MAC
|
1998-10-29 17:06:26 +03:00
|
|
|
char szFile[256] = "file:///Raptor/moz/mozilla/webshell/tests/viewer/samples/raptor.jpg";
|
1998-09-16 20:24:21 +04:00
|
|
|
#else
|
1998-09-16 01:58:25 +04:00
|
|
|
char szFile[256] = "S:\\mozilla\\dist\\WIN32_D.OBJ\\bin\\res\\samples\\raptor.jpg";
|
1998-09-16 20:24:21 +04:00
|
|
|
#endif
|
1998-09-16 01:58:25 +04:00
|
|
|
|
|
|
|
// put up an image
|
|
|
|
MyLoadImage(szFile);
|
1998-09-14 19:46:23 +04:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
NS_RELEASE(drawCtx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Handle events for the text fields
|
|
|
|
//
|
|
|
|
nsEventStatus PR_CALLBACK HandleEventText(nsGUIEvent *aEvent)
|
|
|
|
{
|
1998-07-08 20:58:51 +04:00
|
|
|
//if (aEvent->message != 300)
|
|
|
|
//printf("HandleEventText message %d on 0x%X\n", aEvent->message, aEvent->widget);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
switch(aEvent->message) {
|
|
|
|
case NS_LOSTFOCUS:
|
|
|
|
{
|
|
|
|
nscolor color = scribbleData.drawPane->GetForegroundColor();
|
|
|
|
nsAutoString buf;
|
|
|
|
|
|
|
|
nsITextWidget *text;
|
1998-09-15 00:43:58 +04:00
|
|
|
PRUint32 size;
|
1998-04-14 00:24:54 +04:00
|
|
|
if (NS_OK == aEvent->widget->QueryInterface(kITextWidgetIID, (void**)&text)) {
|
|
|
|
if (text == scribbleData.red) {
|
1998-09-15 00:43:58 +04:00
|
|
|
scribbleData.red->GetText(buf, 0, size);
|
1998-04-14 00:24:54 +04:00
|
|
|
PRInt32 value, err;
|
|
|
|
value = buf.ToInteger(&err);
|
|
|
|
color = NS_RGB(value, NS_GET_G(color), NS_GET_B(color));
|
|
|
|
}
|
|
|
|
else if (text == scribbleData.green) {
|
1998-09-15 00:43:58 +04:00
|
|
|
scribbleData.green->GetText(buf, 0, size);
|
1998-04-14 00:24:54 +04:00
|
|
|
PRInt32 value, err;
|
|
|
|
value = buf.ToInteger(&err);
|
|
|
|
color = NS_RGB(NS_GET_R(color), value, NS_GET_B(color));
|
|
|
|
}
|
|
|
|
else if (text == scribbleData.blue) {
|
1998-09-15 00:43:58 +04:00
|
|
|
scribbleData.blue->GetText(buf, 0, size);
|
1998-04-14 00:24:54 +04:00
|
|
|
PRInt32 value, err;
|
|
|
|
value = buf.ToInteger(&err);
|
|
|
|
color = NS_RGB(NS_GET_R(color), NS_GET_G(color), value);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
scribbleData.drawPane->SetForegroundColor(color);
|
|
|
|
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-09-15 00:43:58 +04:00
|
|
|
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
//
|
|
|
|
// Main application entry function
|
|
|
|
//
|
1998-07-08 20:58:51 +04:00
|
|
|
nsresult CreateApplication(int * argc, char ** argv)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
scribbleData.isDrawing = PR_FALSE;
|
|
|
|
|
1999-04-18 23:02:18 +04:00
|
|
|
// register xpcom classes
|
1999-07-07 13:29:35 +04:00
|
|
|
nsComponentManager::RegisterComponentLib(kEventQueueServiceCID, NULL, NULL, XPCOM_DLL, PR_FALSE, PR_FALSE);
|
|
|
|
nsComponentManager::RegisterComponentLib(kEventQueueCID, NULL, NULL, XPCOM_DLL, PR_FALSE, PR_FALSE);
|
1999-04-18 23:02:18 +04:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
// register graphics classes
|
|
|
|
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);
|
|
|
|
|
1999-07-07 13:29:35 +04:00
|
|
|
nsComponentManager::RegisterComponentLib(kCRenderingContextIID, NULL, NULL, GFXWIN_DLL, PR_FALSE, PR_FALSE);
|
|
|
|
nsComponentManager::RegisterComponentLib(kCDeviceContextIID, NULL, NULL, GFXWIN_DLL, PR_FALSE, PR_FALSE);
|
|
|
|
nsComponentManager::RegisterComponentLib(kCFontMetricsIID, NULL, NULL, GFXWIN_DLL, PR_FALSE, PR_FALSE);
|
|
|
|
nsComponentManager::RegisterComponentLib(kCImageIID, NULL, NULL, GFXWIN_DLL, PR_FALSE, PR_FALSE);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
// register widget classes
|
|
|
|
static NS_DEFINE_IID(kCWindowCID, NS_WINDOW_CID);
|
|
|
|
static NS_DEFINE_IID(kCChildCID, NS_CHILD_CID);
|
|
|
|
static NS_DEFINE_IID(kCButtonCID, NS_BUTTON_CID);
|
|
|
|
static NS_DEFINE_IID(kCCheckButtonCID, NS_CHECKBUTTON_CID);
|
|
|
|
static NS_DEFINE_IID(kCComboBoxCID, NS_COMBOBOX_CID);
|
|
|
|
static NS_DEFINE_IID(kCFileWidgetCID, NS_FILEWIDGET_CID);
|
|
|
|
static NS_DEFINE_IID(kCListBoxCID, NS_LISTBOX_CID);
|
|
|
|
static NS_DEFINE_IID(kCRadioButtonCID, NS_RADIOBUTTON_CID);
|
|
|
|
static NS_DEFINE_IID(kCHorzScrollbarCID, NS_HORZSCROLLBAR_CID);
|
|
|
|
static NS_DEFINE_IID(kCVertScrollbarCID, NS_VERTSCROLLBAR_CID);
|
|
|
|
static NS_DEFINE_IID(kCTextAreaCID, NS_TEXTAREA_CID);
|
|
|
|
static NS_DEFINE_IID(kCTextFieldCID, NS_TEXTFIELD_CID);
|
1998-07-29 22:51:45 +04:00
|
|
|
static NS_DEFINE_IID(kCLookAndFeelCID, NS_LOOKANDFEEL_CID);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1999-07-07 13:29:35 +04:00
|
|
|
nsComponentManager::RegisterComponentLib(kCAppShellCID, NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE);
|
|
|
|
nsComponentManager::RegisterComponentLib(kCToolkitCID, NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE);
|
|
|
|
nsComponentManager::RegisterComponentLib(kCWindowCID, NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE);
|
|
|
|
nsComponentManager::RegisterComponentLib(kCChildCID, NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE);
|
|
|
|
nsComponentManager::RegisterComponentLib(kCButtonCID, NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE);
|
|
|
|
nsComponentManager::RegisterComponentLib(kCCheckButtonCID, NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE);
|
|
|
|
nsComponentManager::RegisterComponentLib(kCComboBoxCID, NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE);
|
|
|
|
nsComponentManager::RegisterComponentLib(kCFileWidgetCID, NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE);
|
|
|
|
nsComponentManager::RegisterComponentLib(kCListBoxCID, NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE);
|
|
|
|
nsComponentManager::RegisterComponentLib(kCRadioButtonCID, NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE);
|
|
|
|
nsComponentManager::RegisterComponentLib(kCHorzScrollbarCID, NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE);
|
|
|
|
nsComponentManager::RegisterComponentLib(kCVertScrollbarCID, NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE);
|
|
|
|
nsComponentManager::RegisterComponentLib(kCTextAreaCID, NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE);
|
|
|
|
nsComponentManager::RegisterComponentLib(kCTextFieldCID, NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE);
|
|
|
|
nsComponentManager::RegisterComponentLib(kCLookAndFeelCID, NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE);
|
|
|
|
nsComponentManager::RegisterComponentLib(kCClipboardCID, NULL, NULL, WIDGET_DLL, PR_FALSE, PR_FALSE);
|
1998-09-03 02:01:18 +04:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
//NS_InitToolkit(PR_GetCurrentThread());
|
|
|
|
|
|
|
|
nsresult res;
|
|
|
|
|
|
|
|
static NS_DEFINE_IID(kDeviceContextCID, NS_DEVICE_CONTEXT_CID);
|
|
|
|
static NS_DEFINE_IID(kDeviceContextIID, NS_IDEVICE_CONTEXT_IID);
|
|
|
|
|
1999-04-18 23:02:18 +04:00
|
|
|
// Create the Event Queue for the UI thread...
|
|
|
|
res = nsServiceManager::GetService(kEventQueueServiceCID,
|
|
|
|
kIEventQueueServiceIID,
|
|
|
|
(nsISupports **)&scribbleData.mEventQService);
|
|
|
|
|
|
|
|
if (NS_OK != res) {
|
|
|
|
NS_ASSERTION(PR_FALSE, "Could not obtain the event queue service");
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
1999-04-18 23:45:46 +04:00
|
|
|
printf("Going to create the event queue\n");
|
1999-04-18 23:02:18 +04:00
|
|
|
res = scribbleData.mEventQService->CreateThreadEventQueue();
|
|
|
|
if (NS_OK != res) {
|
1999-04-18 23:45:46 +04:00
|
|
|
NS_ASSERTION(PR_FALSE, "Could not create the event queue for the thread");
|
1999-04-18 23:02:18 +04:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
1998-05-21 02:02:14 +04:00
|
|
|
// Create an application shell
|
1998-09-15 00:43:58 +04:00
|
|
|
nsIAppShell *appShell = nsnull;
|
1999-03-09 12:44:27 +03:00
|
|
|
nsComponentManager::CreateInstance(kCAppShellCID, nsnull, kIAppShellIID,
|
1998-07-29 22:51:45 +04:00
|
|
|
(void**)&appShell);
|
1998-07-08 20:58:51 +04:00
|
|
|
appShell->Create(argc, argv);
|
1998-07-29 22:51:45 +04:00
|
|
|
|
1999-03-09 12:44:27 +03:00
|
|
|
res = nsComponentManager::CreateInstance(kDeviceContextCID, nsnull, kDeviceContextIID, (void **)&scribbleData.mContext);
|
1998-11-09 06:03:09 +03:00
|
|
|
|
|
|
|
if (NS_OK == res)
|
|
|
|
scribbleData.mContext->Init(nsnull);
|
|
|
|
|
1998-09-03 02:01:18 +04:00
|
|
|
|
1998-08-26 18:15:34 +04:00
|
|
|
//nsILookAndFeel *laf;
|
1999-03-09 12:44:27 +03:00
|
|
|
//nsComponentManager::CreateInstance(kCLookAndFeelCID, nsnull, kILookAndFeelIID,(void**)&laf);
|
1998-09-03 02:01:18 +04:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
//
|
|
|
|
// create the main window
|
|
|
|
//
|
1999-04-20 07:58:29 +04:00
|
|
|
nsComponentManager::CreateInstance(kCWindowCID, nsnull, kIWidgetIID,
|
1998-07-29 22:51:45 +04:00
|
|
|
(void **)&(scribbleData.mainWindow));
|
1998-07-08 20:58:51 +04:00
|
|
|
nsRect rect(100, 100, 600, 700);
|
1998-07-29 22:51:45 +04:00
|
|
|
scribbleData.mainWindow->Create((nsIWidget*)NULL,
|
|
|
|
rect,
|
|
|
|
HandleEventMain,
|
|
|
|
NULL,
|
|
|
|
appShell);
|
1998-08-26 18:15:34 +04:00
|
|
|
//scribbleData.mainWindow->SetBackgroundColor(laf->GetColor(nsLAF::WindowBackground));
|
1998-08-31 19:08:46 +04:00
|
|
|
scribbleData.mainWindow->SetBackgroundColor(NS_RGB(255,255,255));
|
1998-07-29 22:51:45 +04:00
|
|
|
scribbleData.mainWindow->SetTitle("Scribble");
|
1998-04-14 00:24:54 +04:00
|
|
|
//
|
|
|
|
// create the control pane
|
|
|
|
//
|
|
|
|
nsIWidget *controlPane;
|
1998-07-29 22:51:45 +04:00
|
|
|
rect.SetRect(0, 0, 200, 700);
|
1999-03-09 12:44:27 +03:00
|
|
|
nsComponentManager::CreateInstance(kCChildCID, nsnull, kIWidgetIID, (void **)&controlPane);
|
1998-04-14 00:24:54 +04:00
|
|
|
controlPane->Create(scribbleData.mainWindow, rect, HandleEventControlPane, NULL);
|
1998-08-26 18:15:34 +04:00
|
|
|
//controlPane->SetBackgroundColor(laf->GetColor(nsLAF::WindowBackground));
|
1998-09-03 02:01:18 +04:00
|
|
|
controlPane->SetBackgroundColor(NS_RGB(100,128,128));
|
1998-07-29 22:51:45 +04:00
|
|
|
controlPane->Show(PR_TRUE);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
//
|
|
|
|
// Add the scribble/lines section
|
|
|
|
//
|
|
|
|
|
1998-09-05 01:12:12 +04:00
|
|
|
// create the "Scribble" radio button
|
1998-04-14 00:24:54 +04:00
|
|
|
rect.SetRect(50, 50, 100, 25);
|
1999-03-09 12:44:27 +03:00
|
|
|
nsComponentManager::CreateInstance(kCRadioButtonCID, nsnull, kIRadioButtonIID, (void **)&(scribbleData.scribble));
|
1998-09-15 00:43:58 +04:00
|
|
|
NS_CreateRadioButton(controlPane,scribbleData.scribble,rect,HandleEventRadioButton);
|
|
|
|
scribbleData.scribble->SetLabel("Scribble");
|
1998-04-14 00:24:54 +04:00
|
|
|
scribbleData.scribble->SetState(PR_FALSE);
|
1998-09-03 02:01:18 +04:00
|
|
|
//scribbleData.scribble->SetBackgroundColor(laf->GetColor(nsLAF::WindowBackground));
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-09-05 01:12:12 +04:00
|
|
|
// create the "Lines" radio button
|
1998-04-14 00:24:54 +04:00
|
|
|
rect.SetRect(50, 75, 100, 25);
|
|
|
|
|
1999-03-09 12:44:27 +03:00
|
|
|
nsComponentManager::CreateInstance(kCRadioButtonCID, nsnull, kIRadioButtonIID, (void **)&(scribbleData.lines));
|
1998-09-15 00:43:58 +04:00
|
|
|
NS_CreateRadioButton(controlPane,scribbleData.lines,rect,HandleEventRadioButton);
|
|
|
|
scribbleData.lines->SetLabel("Lines");
|
1998-04-14 00:24:54 +04:00
|
|
|
scribbleData.lines->SetState(PR_TRUE);
|
1998-09-03 02:01:18 +04:00
|
|
|
//scribbleData.lines->SetBackgroundColor(laf->GetColor(nsLAF::WindowBackground));
|
1998-04-14 00:24:54 +04:00
|
|
|
// Add the circle/rectangle section
|
|
|
|
|
|
|
|
// create the "Circles" check button
|
|
|
|
nsICheckButton * checkButton;
|
|
|
|
rect.SetRect(50, 200, 100, 25);
|
|
|
|
|
1998-09-15 00:43:58 +04:00
|
|
|
nsIWidget* widget = nsnull;
|
1999-03-09 12:44:27 +03:00
|
|
|
nsComponentManager::CreateInstance(kCCheckButtonCID, nsnull, kICheckButtonIID, (void **)&checkButton);
|
1998-09-15 00:43:58 +04:00
|
|
|
if (NS_OK == checkButton->QueryInterface(kIWidgetIID,(void **)&widget))
|
|
|
|
{
|
|
|
|
widget->Create(controlPane, rect, HandleEventCheck, NULL);
|
|
|
|
nsString cbLabel2("Circles");
|
|
|
|
checkButton->SetLabel(cbLabel2);
|
|
|
|
//checkButton->SetBackgroundColor(laf->GetColor(nsLAF::WindowBackground));
|
|
|
|
widget->Show(PR_TRUE);
|
|
|
|
NS_RELEASE(widget);
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
NS_RELEASE(checkButton);
|
|
|
|
|
|
|
|
// create the "Rectangles" check button
|
|
|
|
rect.SetRect(50, 225, 100, 25);
|
|
|
|
|
1999-03-09 12:44:27 +03:00
|
|
|
nsComponentManager::CreateInstance(kCCheckButtonCID, nsnull, kICheckButtonIID, (void **)&checkButton);
|
1998-09-15 00:43:58 +04:00
|
|
|
NS_CreateCheckButton(controlPane,checkButton,rect,HandleEventCheck);
|
|
|
|
if (NS_OK == checkButton->QueryInterface(kIWidgetIID,(void**)&widget))
|
|
|
|
{
|
|
|
|
// widget->SetBackgroundColor(laf->GetColor(nsLAF::WindowBackground));
|
|
|
|
checkButton->SetLabel("Rectangles");
|
|
|
|
NS_RELEASE(widget);
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
NS_RELEASE(checkButton);
|
|
|
|
|
1998-09-14 19:46:23 +04:00
|
|
|
// create the "Images" check button
|
|
|
|
rect.SetRect(50, 250, 100, 25);
|
|
|
|
|
1999-03-09 12:44:27 +03:00
|
|
|
nsComponentManager::CreateInstance(kCCheckButtonCID, nsnull, kICheckButtonIID, (void **)&checkButton);
|
1998-09-15 00:43:58 +04:00
|
|
|
if (NS_OK == checkButton->QueryInterface(kIWidgetIID,(void **)&widget))
|
|
|
|
{
|
|
|
|
widget->Create(controlPane, rect, HandleEventCheck, NULL);
|
|
|
|
nsString cbLabel4("Image");
|
|
|
|
checkButton->SetLabel(cbLabel4);
|
|
|
|
//checkButton->SetBackgroundColor(laf->GetColor(nsLAF::WindowBackground));
|
|
|
|
widget->Show(PR_TRUE);
|
|
|
|
NS_RELEASE(widget);
|
|
|
|
}
|
1998-09-14 19:46:23 +04:00
|
|
|
NS_RELEASE(checkButton);
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
//
|
|
|
|
// Add the color section
|
|
|
|
//
|
|
|
|
|
1998-11-04 09:36:48 +03:00
|
|
|
int y = COLOR_FIELDS_Y;
|
1998-04-14 00:24:54 +04:00
|
|
|
// create the "red" text widget
|
1998-07-08 20:58:51 +04:00
|
|
|
rect.SetRect(100, y, 50, TEXT_HEIGHT);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-09-15 00:43:58 +04:00
|
|
|
PRUint32 size;
|
1998-04-14 00:24:54 +04:00
|
|
|
nsString initText("0");
|
1999-03-09 12:44:27 +03:00
|
|
|
nsComponentManager::CreateInstance(kCTextFieldCID, nsnull, kITextWidgetIID, (void **)&(scribbleData.red));
|
1998-09-15 00:43:58 +04:00
|
|
|
if (NS_OK == scribbleData.red->QueryInterface(kIWidgetIID,(void **)&widget))
|
|
|
|
{
|
|
|
|
widget->Create(controlPane, rect, HandleEventText, NULL);
|
|
|
|
scribbleData.red->SetText(initText,size);
|
|
|
|
widget->SetBackgroundColor(NS_RGB(0, 0, 255));
|
|
|
|
widget->Show(PR_TRUE);
|
|
|
|
}
|
1998-07-08 20:58:51 +04:00
|
|
|
y += rect.height +2;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
// create the "green" text widget
|
1998-07-08 20:58:51 +04:00
|
|
|
rect.SetRect(100, y, 50, TEXT_HEIGHT);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1999-03-09 12:44:27 +03:00
|
|
|
nsComponentManager::CreateInstance(kCTextFieldCID, nsnull, kITextWidgetIID, (void **)&(scribbleData.green));
|
1998-09-15 00:43:58 +04:00
|
|
|
if (NS_OK == scribbleData.green->QueryInterface(kIWidgetIID,(void **)&widget))
|
|
|
|
{
|
|
|
|
widget->Create(controlPane, rect, HandleEventText, NULL);
|
|
|
|
scribbleData.green->SetText(initText,size);
|
|
|
|
widget->SetBackgroundColor(NS_RGB(255, 0, 0));
|
|
|
|
widget->Show(PR_TRUE);
|
|
|
|
}
|
1998-07-08 20:58:51 +04:00
|
|
|
y += rect.height +2;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
// create the "blue" text widget
|
1998-07-08 20:58:51 +04:00
|
|
|
rect.SetRect(100, y, 50, TEXT_HEIGHT);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1999-03-09 12:44:27 +03:00
|
|
|
nsComponentManager::CreateInstance(kCTextFieldCID, nsnull, kITextWidgetIID, (void **)&(scribbleData.blue));
|
1998-09-15 00:43:58 +04:00
|
|
|
if (NS_OK == scribbleData.blue->QueryInterface(kIWidgetIID,(void **)&widget))
|
|
|
|
{
|
|
|
|
widget->Create(controlPane, rect, HandleEventText, NULL);
|
|
|
|
scribbleData.blue->SetText(initText,size);
|
|
|
|
widget->SetBackgroundColor(NS_RGB(0, 255, 0));
|
|
|
|
widget->Show(PR_TRUE);
|
|
|
|
}
|
1998-07-08 20:58:51 +04:00
|
|
|
y += rect.height +2;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
//
|
|
|
|
// create a button
|
|
|
|
//
|
|
|
|
nsIButton *button;
|
|
|
|
rect.SetRect(50, 500, 100, 25);
|
1999-03-09 12:44:27 +03:00
|
|
|
nsComponentManager::CreateInstance(kCButtonCID, nsnull, kIButtonIID, (void **)&button);
|
1998-09-15 00:43:58 +04:00
|
|
|
NS_CreateButton(controlPane,button,rect,HandleEventButton);
|
|
|
|
button->SetLabel("Clear");
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-09-15 00:43:58 +04:00
|
|
|
NS_RELEASE(button);
|
1998-04-14 00:24:54 +04:00
|
|
|
NS_RELEASE(controlPane); // the parent keeps a reference on this child
|
|
|
|
|
|
|
|
//
|
|
|
|
// create the draw pane
|
|
|
|
//
|
1998-07-29 22:51:45 +04:00
|
|
|
rect.SetRect(200, 0, 400, 700);
|
1999-03-09 12:44:27 +03:00
|
|
|
nsComponentManager::CreateInstance(kCChildCID, nsnull, kIWidgetIID, (void **)&scribbleData.drawPane);
|
1998-04-14 00:24:54 +04:00
|
|
|
scribbleData.drawPane->Create(scribbleData.mainWindow, rect, HandleEventGraphicPane, NULL);
|
1998-08-26 18:15:34 +04:00
|
|
|
//scribbleData.drawPane->SetBackgroundColor(laf->GetColor(nsLAF::WindowBackground));
|
1998-08-31 19:08:46 +04:00
|
|
|
scribbleData.drawPane->SetBackgroundColor(NS_RGB(255,250,250));
|
1998-07-29 22:51:45 +04:00
|
|
|
scribbleData.drawPane->Show(PR_TRUE);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
// show. We are in business...
|
|
|
|
scribbleData.mainWindow->Show(PR_TRUE);
|
|
|
|
|
1998-08-26 18:15:34 +04:00
|
|
|
//laf->Release();
|
1998-07-29 22:51:45 +04:00
|
|
|
|
1998-09-16 01:58:25 +04:00
|
|
|
polllistener *plistener = new polllistener;
|
|
|
|
appShell->SetDispatchListener(plistener);
|
1999-04-18 23:02:18 +04:00
|
|
|
|
1998-05-21 02:02:14 +04:00
|
|
|
return(appShell->Run());
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-09-14 19:46:23 +04:00
|
|
|
//=================================================================
|
|
|
|
|
|
|
|
class MyObserver : public nsIImageRequestObserver
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MyObserver();
|
1999-04-18 23:02:18 +04:00
|
|
|
virtual ~MyObserver();
|
1998-09-14 19:46:23 +04:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
virtual void Notify(nsIImageRequest *aImageRequest,nsIImage *aImage,nsImageNotification aNotificationType,
|
|
|
|
PRInt32 aParam1,PRInt32 aParam2,void *aParam3);
|
|
|
|
|
|
|
|
virtual void NotifyError(nsIImageRequest *aImageRequest,nsImageError aErrorType);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
//=================================================================
|
|
|
|
|
|
|
|
MyObserver::MyObserver()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================
|
|
|
|
|
|
|
|
MyObserver::~MyObserver()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//=================================================================
|
|
|
|
|
|
|
|
static NS_DEFINE_IID(kIImageObserverIID,NS_IIMAGEREQUESTOBSERVER_IID);
|
|
|
|
NS_IMPL_ISUPPORTS(MyObserver,kIImageObserverIID)
|
|
|
|
|
|
|
|
void
|
|
|
|
MyObserver::Notify(nsIImageRequest *aImageRequest,
|
|
|
|
nsIImage *aImage,
|
|
|
|
nsImageNotification aNotificationType,
|
|
|
|
PRInt32 aParam1,PRInt32 aParam2,void *aParam3)
|
|
|
|
{
|
|
|
|
|
|
|
|
switch (aNotificationType)
|
|
|
|
{
|
|
|
|
case nsImageNotification_kDimensions:
|
|
|
|
{
|
|
|
|
char buffer[40];
|
|
|
|
sprintf(buffer, "Image:%d x %d", aParam1, aParam2);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsImageNotification_kPixmapUpdate:
|
|
|
|
case nsImageNotification_kImageComplete:
|
|
|
|
case nsImageNotification_kFrameComplete:
|
|
|
|
{
|
|
|
|
if (gImage == nsnull && aImage)
|
|
|
|
{
|
|
|
|
gImage = aImage;
|
|
|
|
NS_ADDREF(aImage);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gInstalledColorMap && gImage)
|
|
|
|
{
|
|
|
|
nsColorMap *cmap = gImage->GetColorMap();
|
|
|
|
|
|
|
|
if (cmap != nsnull && cmap->NumColors > 0)
|
|
|
|
{
|
1998-09-16 01:58:25 +04:00
|
|
|
//gWindow->SetColorMap(cmap);
|
1998-09-14 19:46:23 +04:00
|
|
|
}
|
|
|
|
gInstalledColorMap = PR_TRUE;
|
|
|
|
}
|
1998-09-16 01:58:25 +04:00
|
|
|
|
|
|
|
nsIRenderingContext *drawCtx = scribbleData.drawPane->GetRenderingContext();
|
1998-09-14 19:46:23 +04:00
|
|
|
|
|
|
|
if (gImage)
|
|
|
|
{
|
1998-09-16 21:18:56 +04:00
|
|
|
nscoord x = 0;
|
|
|
|
nscoord y = 0;
|
1998-09-16 20:24:21 +04:00
|
|
|
|
1998-09-16 21:18:56 +04:00
|
|
|
scribbleData.drawPane->ConvertToDeviceCoordinates(x,y);
|
1998-09-16 20:24:21 +04:00
|
|
|
drawCtx->DrawImage(gImage,x, y, gImage->GetWidth(), gImage->GetHeight());
|
1998-09-14 19:46:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
1999-04-18 23:02:18 +04:00
|
|
|
default: /* should never get here? */
|
|
|
|
break;
|
1998-09-14 19:46:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------
|
|
|
|
|
|
|
|
void
|
|
|
|
MyObserver::NotifyError(nsIImageRequest *aImageRequest,
|
|
|
|
nsImageError aErrorType)
|
|
|
|
{
|
|
|
|
//::MessageBox(NULL, "Image loading error!",class1Name, MB_OK);
|
|
|
|
}
|
|
|
|
|
1998-09-16 01:58:25 +04:00
|
|
|
//------------------------------------------------------------
|
|
|
|
|
|
|
|
void
|
|
|
|
MyInterrupt()
|
|
|
|
{
|
|
|
|
if (gImageGroup)
|
|
|
|
{
|
|
|
|
gImageGroup->Interrupt();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
MyLoadImage(char *aFileName)
|
|
|
|
{
|
|
|
|
char fileURL[256];
|
1999-04-18 23:02:18 +04:00
|
|
|
#ifdef XP_PC
|
1998-09-16 01:58:25 +04:00
|
|
|
char *str;
|
1999-04-18 23:02:18 +04:00
|
|
|
#endif
|
1998-09-16 01:58:25 +04:00
|
|
|
|
|
|
|
MyInterrupt();
|
|
|
|
|
|
|
|
if (gImageReq)
|
|
|
|
{
|
|
|
|
NS_RELEASE(gImageReq);
|
|
|
|
gImageReq = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gImage)
|
|
|
|
{
|
|
|
|
NS_RELEASE(gImage);
|
|
|
|
gImage = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gImageGroup == NULL)
|
|
|
|
{
|
|
|
|
nsIDeviceContext *deviceCtx = scribbleData.mContext;
|
1998-10-02 01:53:52 +04:00
|
|
|
if (NS_NewImageGroup(&gImageGroup) != NS_OK || gImageGroup->Init(deviceCtx, nsnull) != NS_OK)
|
1998-09-16 01:58:25 +04:00
|
|
|
{
|
|
|
|
NS_RELEASE(deviceCtx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
NS_RELEASE(deviceCtx);
|
|
|
|
}
|
|
|
|
|
1998-10-29 17:06:26 +03:00
|
|
|
#ifdef XP_MAC
|
|
|
|
strcpy(fileURL, aFileName);
|
|
|
|
#else
|
1998-09-16 01:58:25 +04:00
|
|
|
strcpy(fileURL, FILE_URL_PREFIX);
|
|
|
|
strcpy(fileURL + strlen(FILE_URL_PREFIX), aFileName);
|
1998-10-29 17:06:26 +03:00
|
|
|
#endif
|
1998-09-16 01:58:25 +04:00
|
|
|
|
|
|
|
#ifdef XP_PC
|
|
|
|
str = fileURL;
|
|
|
|
while ((str = strchr(str, '\\')) != NULL)
|
|
|
|
*str = '/';
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nscolor white;
|
|
|
|
|
|
|
|
MyObserver *observer = new MyObserver();
|
1999-07-18 04:36:25 +04:00
|
|
|
NS_ColorNameToRGB(nsAutoString("white"), &white);
|
1998-09-16 01:58:25 +04:00
|
|
|
gImageReq = gImageGroup->GetImage(fileURL,observer,&white, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
polllistener::AfterDispatch()
|
|
|
|
{
|
|
|
|
}
|