1998-04-14 00:24:54 +04:00
|
|
|
/* -*- 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#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-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
ScribbleApp scribbleData;
|
|
|
|
|
1998-07-08 20:58:51 +04:00
|
|
|
#ifdef XP_PC
|
|
|
|
#define WIDGET_DLL "raptorwidget.dll"
|
|
|
|
#define GFX_DLL "raptorgfxwin.dll"
|
|
|
|
#define TEXT_HEIGHT 25
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XP_UNIX
|
|
|
|
#define WIDGET_DLL "libwidgetunix.so"
|
|
|
|
#define GFX_DLL "libgfxunix.so"
|
|
|
|
#define TEXT_HEIGHT 30
|
|
|
|
#endif
|
|
|
|
|
1998-08-26 18:15:34 +04:00
|
|
|
#ifdef XP_MAC
|
|
|
|
#define WIDGET_DLL "WIDGET_DLL"
|
|
|
|
#define GFX_DLL "GFXWIN_DLL"
|
|
|
|
#define TEXT_HEIGHT 30
|
|
|
|
#endif
|
|
|
|
|
1998-07-08 20:58:51 +04:00
|
|
|
|
1998-05-21 02:02:14 +04:00
|
|
|
static NS_DEFINE_IID(kCAppShellCID, NS_APPSHELL_CID);
|
|
|
|
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);
|
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) {
|
|
|
|
nsISupports *next;
|
|
|
|
next = enumer->Next();
|
|
|
|
if (next) {
|
|
|
|
nsIWidget *widget;
|
|
|
|
if (NS_OK == next->QueryInterface(kIWidgetIID, (void**)&widget)) {
|
1998-07-29 22:51:45 +04:00
|
|
|
widget->Resize(0, 0, 200,
|
|
|
|
((nsSizeEvent*)aEvent)->windowSize->height, PR_TRUE);
|
1998-04-14 00:24:54 +04:00
|
|
|
NS_RELEASE(widget);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
|
|
|
NS_RELEASE(scribbleData.red);
|
|
|
|
NS_RELEASE(scribbleData.green);
|
|
|
|
NS_RELEASE(scribbleData.blue);
|
|
|
|
NS_RELEASE(scribbleData.scribble);
|
|
|
|
NS_RELEASE(scribbleData.lines);
|
|
|
|
// 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
|
|
|
|
|
|
|
nsEventStatus result = nsEventStatus_eConsumeNoDefault;
|
|
|
|
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-07-08 20:58:51 +04:00
|
|
|
int y = 351;
|
1998-04-14 00:24:54 +04:00
|
|
|
nsString red("Red");
|
|
|
|
drawCtx->SetColor(NS_RGB(255, 0, 0));
|
1998-07-08 20:58:51 +04:00
|
|
|
drawCtx->DrawString(red, 50, y, 200);
|
|
|
|
y += TEXT_HEIGHT+2;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
nsString green("Green");
|
|
|
|
drawCtx->SetColor(NS_RGB(0, 255, 0));
|
1998-07-08 20:58:51 +04:00
|
|
|
drawCtx->DrawString(green, 50, y, 100);
|
|
|
|
y += TEXT_HEIGHT+2;
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
nsString blue("Blue");
|
|
|
|
drawCtx->SetColor(NS_RGB(0, 0, 255));
|
1998-07-08 20:58:51 +04:00
|
|
|
drawCtx->DrawString(blue, 50, y, 100);
|
|
|
|
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
|
|
|
|
|
|
|
nsEventStatus result = nsEventStatus_eConsumeNoDefault;
|
|
|
|
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) {
|
|
|
|
nsIRenderingContext *drawCtx = aEvent->widget->GetRenderingContext();
|
1998-08-31 19:08:46 +04:00
|
|
|
//drawCtx->SetColor(aEvent->widget->GetForegroundColor());
|
|
|
|
drawCtx->SetColor(NS_RGB(255, 0, 0));
|
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-08-26 18:15:34 +04:00
|
|
|
//if (scribbleData.scribble->GetState())
|
|
|
|
//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
|
|
|
|
PRBool state = option->GetState();
|
|
|
|
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);
|
|
|
|
nscoord width = rect.width;
|
|
|
|
nscoord height = rect.height;
|
|
|
|
|
|
|
|
nsString circles("Circles");
|
|
|
|
nsString rects("Rectangles");
|
|
|
|
if (buf.Equals(circles)) {
|
|
|
|
for (int i = 0; i < 100; i++) {
|
|
|
|
drawCtx->SetColor((nscolor)rand());
|
|
|
|
|
|
|
|
rect.MoveTo(rand() % width, rand() % height);
|
|
|
|
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());
|
|
|
|
|
|
|
|
rect.MoveTo(rand() % width, rand() % height);
|
|
|
|
rect.SizeTo(rand() % (width - rect.x),
|
|
|
|
rand() % (height - rect.y));
|
|
|
|
drawCtx->DrawRect(rect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
if (NS_OK == aEvent->widget->QueryInterface(kITextWidgetIID, (void**)&text)) {
|
|
|
|
if (text == scribbleData.red) {
|
|
|
|
scribbleData.red->GetText(buf, 0);
|
|
|
|
PRInt32 value, err;
|
|
|
|
value = buf.ToInteger(&err);
|
|
|
|
color = NS_RGB(value, NS_GET_G(color), NS_GET_B(color));
|
|
|
|
}
|
|
|
|
else if (text == scribbleData.green) {
|
|
|
|
scribbleData.green->GetText(buf, 0);
|
|
|
|
PRInt32 value, err;
|
|
|
|
value = buf.ToInteger(&err);
|
|
|
|
color = NS_RGB(NS_GET_R(color), value, NS_GET_B(color));
|
|
|
|
}
|
|
|
|
else if (text == scribbleData.blue) {
|
|
|
|
scribbleData.blue->GetText(buf, 0);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
1998-09-01 04:26:28 +04:00
|
|
|
nsRepository::RegisterFactory(kCRenderingContextIID, GFX_DLL, PR_FALSE, PR_FALSE);
|
|
|
|
nsRepository::RegisterFactory(kCDeviceContextIID, GFX_DLL, PR_FALSE, PR_FALSE);
|
|
|
|
nsRepository::RegisterFactory(kCFontMetricsIID, GFX_DLL, PR_FALSE, PR_FALSE);
|
|
|
|
nsRepository::RegisterFactory(kCImageIID, GFX_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
|
|
|
|
1998-09-01 04:26:28 +04:00
|
|
|
nsRepository::RegisterFactory(kCAppShellCID, WIDGET_DLL, PR_FALSE, PR_FALSE);
|
|
|
|
nsRepository::RegisterFactory(kCWindowCID, WIDGET_DLL, PR_FALSE, PR_FALSE);
|
|
|
|
nsRepository::RegisterFactory(kCChildCID, WIDGET_DLL, PR_FALSE, PR_FALSE);
|
|
|
|
nsRepository::RegisterFactory(kCButtonCID, WIDGET_DLL, PR_FALSE, PR_FALSE);
|
|
|
|
nsRepository::RegisterFactory(kCCheckButtonCID, 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(kCHorzScrollbarCID, WIDGET_DLL, PR_FALSE, PR_FALSE);
|
|
|
|
nsRepository::RegisterFactory(kCVertScrollbarCID, 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(kCLookAndFeelCID, WIDGET_DLL, PR_FALSE, PR_FALSE)
|
1998-07-29 22:51:45 +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);
|
|
|
|
|
1998-09-01 04:26:28 +04:00
|
|
|
res = nsRepository::CreateInstance(kDeviceContextCID, nsnull, kDeviceContextIID, (void **)&scribbleData.mContext);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
if (NS_OK == res)
|
1998-06-12 01:26:21 +04:00
|
|
|
scribbleData.mContext->Init(nsnull);
|
1998-05-21 02:02:14 +04:00
|
|
|
|
|
|
|
|
|
|
|
// Create an application shell
|
|
|
|
nsIAppShell *appShell;
|
1998-09-01 04:26:28 +04:00
|
|
|
nsRepository::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-04-14 00:24:54 +04:00
|
|
|
|
1998-07-29 22:51:45 +04:00
|
|
|
|
1998-08-26 18:15:34 +04:00
|
|
|
//nsILookAndFeel *laf;
|
1998-09-01 04:26:28 +04:00
|
|
|
//nsRepository::CreateInstance(kCLookAndFeelCID, nsnull, kILookAndFeelIID,(void**)&laf);
|
1998-08-26 18:15:34 +04:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
//
|
|
|
|
// create the main window
|
|
|
|
//
|
1998-09-01 04:26:28 +04:00
|
|
|
nsRepository::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);
|
1998-09-01 04:26:28 +04:00
|
|
|
nsRepository::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-08-31 19:08:46 +04:00
|
|
|
controlPane->SetBackgroundColor(NS_RGB(0,0,255));
|
1998-07-29 22:51:45 +04:00
|
|
|
controlPane->Show(PR_TRUE);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-08-26 18:15:34 +04:00
|
|
|
#ifdef NOTNOW
|
1998-04-14 00:24:54 +04:00
|
|
|
//
|
|
|
|
// Add the scribble/lines section
|
|
|
|
//
|
|
|
|
|
|
|
|
// create the "Scribble" check button
|
|
|
|
rect.SetRect(50, 50, 100, 25);
|
|
|
|
|
1998-09-01 04:26:28 +04:00
|
|
|
nsRepository::CreateInstance(kCRadioButtonCID, nsnull, kIRadioButtonIID, (void **)&(scribbleData.scribble));
|
1998-07-07 21:56:24 +04:00
|
|
|
scribbleData.scribble->Create(controlPane, rect, HandleEventRadioButton, NULL);
|
1998-04-14 00:24:54 +04:00
|
|
|
nsString cbLabel("Scribble");
|
|
|
|
scribbleData.scribble->SetLabel(cbLabel);
|
|
|
|
scribbleData.scribble->SetState(PR_FALSE);
|
1998-07-29 22:51:45 +04:00
|
|
|
scribbleData.scribble->SetBackgroundColor(laf->GetColor(nsLAF::WindowBackground));
|
1998-04-14 00:24:54 +04:00
|
|
|
scribbleData.scribble->Show(PR_TRUE);
|
|
|
|
|
|
|
|
// create the "Lines" check button
|
|
|
|
rect.SetRect(50, 75, 100, 25);
|
|
|
|
|
1998-09-01 04:26:28 +04:00
|
|
|
nsRepository::CreateInstance(kCRadioButtonCID, nsnull, kIRadioButtonIID, (void **)&(scribbleData.lines));
|
1998-07-07 21:56:24 +04:00
|
|
|
scribbleData.lines->Create(controlPane, rect, HandleEventRadioButton, NULL);
|
1998-04-14 00:24:54 +04:00
|
|
|
nsString cbLabel1("Lines");
|
|
|
|
scribbleData.lines->SetLabel(cbLabel1);
|
|
|
|
scribbleData.lines->SetState(PR_TRUE);
|
1998-07-29 22:51:45 +04:00
|
|
|
scribbleData.lines->SetBackgroundColor(laf->GetColor(nsLAF::WindowBackground));
|
1998-04-14 00:24:54 +04:00
|
|
|
scribbleData.lines->Show(PR_TRUE);
|
|
|
|
//
|
|
|
|
// Add the circle/rectangle section
|
|
|
|
//
|
|
|
|
|
|
|
|
// create the "Circles" check button
|
|
|
|
nsICheckButton * checkButton;
|
|
|
|
rect.SetRect(50, 200, 100, 25);
|
|
|
|
|
1998-09-01 04:26:28 +04:00
|
|
|
nsRepository::CreateInstance(kCCheckButtonCID, nsnull, kICheckButtonIID, (void **)&checkButton);
|
1998-04-14 00:24:54 +04:00
|
|
|
checkButton->Create(controlPane, rect, HandleEventCheck, NULL);
|
|
|
|
nsString cbLabel2("Circles");
|
|
|
|
checkButton->SetLabel(cbLabel2);
|
1998-07-29 22:51:45 +04:00
|
|
|
checkButton->SetBackgroundColor(laf->GetColor(nsLAF::WindowBackground));
|
1998-04-14 00:24:54 +04:00
|
|
|
checkButton->Show(PR_TRUE);
|
|
|
|
NS_RELEASE(checkButton);
|
|
|
|
|
|
|
|
// create the "Rectangles" check button
|
|
|
|
rect.SetRect(50, 225, 100, 25);
|
|
|
|
|
1998-09-01 04:26:28 +04:00
|
|
|
nsRepository::CreateInstance(kCCheckButtonCID, nsnull, kICheckButtonIID, (void **)&checkButton);
|
1998-04-14 00:24:54 +04:00
|
|
|
checkButton->Create(controlPane, rect, HandleEventCheck, NULL);
|
|
|
|
nsString cbLabel3("Rectangles");
|
|
|
|
checkButton->SetLabel(cbLabel3);
|
1998-07-29 22:51:45 +04:00
|
|
|
checkButton->SetBackgroundColor(laf->GetColor(nsLAF::WindowBackground));
|
1998-04-14 00:24:54 +04:00
|
|
|
checkButton->Show(PR_TRUE);
|
|
|
|
NS_RELEASE(checkButton);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Add the color section
|
|
|
|
//
|
|
|
|
|
1998-07-08 20:58:51 +04:00
|
|
|
int y = 350;
|
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-01 04:26:28 +04:00
|
|
|
nsRepository::CreateInstance(kCTextFieldCID, nsnull, kITextWidgetIID, (void **)&(scribbleData.red));
|
1998-04-14 00:24:54 +04:00
|
|
|
scribbleData.red->Create(controlPane, rect, HandleEventText, NULL);
|
|
|
|
nsString initText("0");
|
|
|
|
scribbleData.red->SetText(initText);
|
|
|
|
scribbleData.red->SetBackgroundColor(NS_RGB(0, 0, 255));
|
|
|
|
scribbleData.red->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
|
|
|
|
1998-09-01 04:26:28 +04:00
|
|
|
nsRepository::CreateInstance(kCTextFieldCID, nsnull, kITextWidgetIID, (void **)&(scribbleData.green));
|
1998-04-14 00:24:54 +04:00
|
|
|
scribbleData.green->Create(controlPane, rect, HandleEventText, NULL);
|
|
|
|
scribbleData.green->SetText(initText);
|
|
|
|
scribbleData.green->SetBackgroundColor(NS_RGB(255, 0, 0));
|
|
|
|
scribbleData.green->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
|
|
|
|
1998-09-01 04:26:28 +04:00
|
|
|
nsRepository::CreateInstance(kCTextFieldCID, nsnull, kITextWidgetIID, (void **)&(scribbleData.blue));
|
1998-04-14 00:24:54 +04:00
|
|
|
scribbleData.blue->Create(controlPane, rect, HandleEventText, NULL);
|
|
|
|
scribbleData.blue->SetText(initText);
|
|
|
|
scribbleData.blue->SetBackgroundColor(NS_RGB(0, 255, 0));
|
|
|
|
scribbleData.blue->Show(PR_TRUE);
|
1998-07-08 20:58:51 +04:00
|
|
|
y += rect.height +2;
|
1998-08-26 18:15:34 +04:00
|
|
|
#endif
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
//
|
|
|
|
// create a button
|
|
|
|
//
|
|
|
|
nsIButton *button;
|
|
|
|
rect.SetRect(50, 500, 100, 25);
|
1998-09-01 04:26:28 +04:00
|
|
|
nsRepository::CreateInstance(kCButtonCID, nsnull, kIButtonIID, (void **)&button);
|
1998-04-14 00:24:54 +04:00
|
|
|
button->Create(controlPane, rect, HandleEventButton, NULL);
|
|
|
|
nsString label("Clear");
|
|
|
|
button->SetLabel(label);
|
|
|
|
button->Show(PR_TRUE);
|
|
|
|
NS_RELEASE(button);
|
|
|
|
|
|
|
|
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);
|
1998-09-01 04:26:28 +04:00
|
|
|
nsRepository::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-05-21 02:02:14 +04:00
|
|
|
return(appShell->Run());
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|