OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Delphi + OOo.Draw

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Code Snippets
View previous topic :: View next topic  
Author Message
pasha_golub
General User
General User


Joined: 29 Jun 2004
Posts: 24
Location: Ukraine

PostPosted: Fri Jul 16, 2004 4:16 am    Post subject: Delphi + OOo.Draw Reply with quote

I am very grateful to DannyB and others (moderators and users). He (they Smile ) is doing so much. So I decide to help him (them Smile ) in this hard work. I will try to translate all popular macros in Basic to Delphi+OLE. And I want to start from Drawing examples.

Code:

unit uMain;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, comObj, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  end;

var
  Form1: TForm1;
  StarOffice, StarDesktop, DrawDoc, DrawPage, Shape: OLEVariant;
implementation

{$R *.dfm}

function MakePoint(const X, Y: integer):variant;
var Struct: variant;
begin
    Struct := StarOffice.Bridge_GetStruct('com.sun.star.awt.Point');
    Struct.X := X;
    Struct.Y := Y;
    Result := Struct;
end;

function MakeSize(const Width, Height: integer):variant;
var Struct: variant;
begin
    Struct := StarOffice.Bridge_GetStruct('com.sun.star.awt.Size');
    Struct.Width := Width;
    Struct.Height := Height;
    Result := Struct;
end;

function Connect: boolean;
begin
   if VarIsEmpty(StarOffice) then
      StarOffice := CreateOleObject('com.sun.star.ServiceManager');
   StarDesktop := StarOffice.createInstance('com.sun.star.frame.Desktop');
   Result := not (VarIsEmpty(StarOffice) or VarIsNull(StarOffice));
end;

function CreateDrawDocument: boolean;
begin
 DrawDoc := StarDesktop.loadComponentFromURL( 'private:factory/sdraw', '_blank',
   0, VarArrayCreate([0,-1],varVariant));
 Result := not (VarIsEmpty(DrawDoc) or VarIsNull(DrawDoc));
 DrawPage := DrawDoc.getDrawPages.getByIndex(0);
end;

procedure DrawRectangle(const X,Y,Width,Height: integer);
begin
   Shape := DrawDoc.createInstance('com.sun.star.drawing.RectangleShape');
   Shape.Position := MakePoint(X,Y);
   Shape.Size := MakeSize(Width,Height);
   DrawPage.Add(Shape);
end;

procedure DrawEllipse(const X,Y,Width,Height: integer);
begin
   Shape := DrawDoc.createInstance('com.sun.star.drawing.EllipseShape');
   Shape.Position := MakePoint(X,Y);
   Shape.Size := MakeSize(Width,Height);
   DrawPage.Add(Shape);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
 If Connect then
    if CreateDrawDocument then
     begin
      DrawRectangle(200,200,10000,10000);
      DrawEllipse(600,600, 11500,1350);
     end;
 StarOffice := UnAssigned;
end;

end.


Since it only translation, I shall not place additional comments. I shall give only the reference to the original:
http://www.oooforum.org/forum/viewtopic.php?t=10795

This example can draw rectangle and ellipse only. But I hope I will work on this and it will be usefull for others.
_________________
Nullus est in vitae sensus, ipsa vera est sensus!
Back to top
View user's profile Send private message
pasha_golub
General User
General User


Joined: 29 Jun 2004
Posts: 24
Location: Ukraine

PostPosted: Wed Jul 21, 2004 11:31 pm    Post subject: Reply with quote

As I said I will translate some usefull code. So, the second portion of it. In this post we will learn to create text shapes, and to change some properties of common shapes such ellipse, rectangle and text shape.

Unfortunately, I did not manage to find out how to use constants (enums) from fillstyle and linestyle types through OLE-bridge.

If anybody knows how should I use enums values through OLE-bridge, please let me know.

In StarBasic this look so (code by DannyB):
Code:

oShape.LineStyle = com.sun.star.drawing.LineStyle.SOLID


But I found another way. Just redeclare them in the units body. All external constants that I use have prefix OO, followed by two letters means group (type) of constant.

For example: OOfsNone means OpenOfficeFillStyleNone.

All values I took from API reference. I hope it all right.

Starbasic analog: http://www.oooforum.org/forum/viewtopic.php?p=27227#27227

Code:

function DrawTextShape(const X,Y,Width,Height: integer):variant;
begin
   Result := DrawDoc.createInstance('com.sun.star.drawing.TextShape');
   Result.Position := MakePoint(X,Y);
   Result.Size := MakeSize(Width,Height);
   DrawPage.Add(Result);
end;

{ Fill styles:
NONE     the area is not filled.
SOLID    use a solid color to fill the area.
GRADIENT    use a gradient color to fill the area.
HATCH    use a hatch to fill the area.
BITMAP     use a bitmap to fill the area.}

const
OOfsNone = 0;
OOfsSolid = 1;
OOfsGradient = 2;
OOfsHatch = 3;
OOfsBitmap = 4;

{ Line styles:
NONE     the line is hidden.
SOLID    the line is solid.
DASH    the line use dashes.}

const
OOlsNone = 0;
OOlsSolid = 1;
OOlsDash = 2;

{ Circle kinds:
FULL     a full circle
SECTION    a circle with a cut connected by a line
CUT    a circle with a cut connected by two lines
ARC    a circle with an open cut
}

const
OOckFull = 0;
OOckSection = 1;
OOckCut = 2;
OOckArc = 3;

procedure DrawSimplePieChart;
var Circle1, Square1, Text1: Variant;
begin

   Circle1 := DrawEllipse(8000, 10000, 5000, 5000);
   Circle1.LineStyle := OOlsSolid;
   Circle1.LineWidth := 10;
   Circle1.FillStyle := OOfsSolid;
   Circle1.FillColor := $FF0000; //RGB notation
   Circle1.CircleKind := OOckSection;
   Circle1.CircleStartAngle := 0;
   Circle1.CircleEndAngle := 1000;

   Circle1 := DrawEllipse(8000, 10000, 5000, 5000);
   Circle1.LineStyle := OOlsSolid;
   Circle1.LineWidth := 10;
   Circle1.FillStyle := OOfsSolid;
   Circle1.FillColor := $0000FF; //RGB notation
   Circle1.CircleKind := OOckSection;
   Circle1.CircleStartAngle := 1000;
   Circle1.CircleEndAngle := 36000;


   Square1 := DrawRectangle(8000, 16000, 500, 500);
   Square1.LineStyle := OOlsSolid;
   Square1.LineWidth := 10;
   Square1.FillStyle := OOfsSolid;
   Square1.FillColor := $FF0000;


   Square1 := DrawRectangle(8000, 17000, 500, 500);
   Square1.LineStyle := OOlsSolid;
   Square1.LineWidth := 10;
   Square1.FillStyle := OOfsSolid;
   Square1.FillColor := $0000FF;

   Text1 := DrawTextShape(9000, 16000, 8000, 500);
   Text1.LineStyle := OOlsNone;
   Text1.FillStyle := OOfsNone;
   Text1.Text.setString('SCO True statements');

   Text1 := DrawTextShape(9000, 17000, 8000, 500);
   Text1.LineStyle := 0;
   Text1.FillStyle := 0;
   Text1.Text.setString('SCO False statements');
end;

_________________
Nullus est in vitae sensus, ipsa vera est sensus!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Code Snippets All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group