I have some code that (roughly - this is probably not a compilable example) does:
VAR
text: TextModels.Model;
view: TextViews.View;
BEGIN
Create text ...
view := TextViews.dir.New(text);
Views.OpenView(view);
What I would like to do is have this opened in landscape mode, A4, with 2 cm margins, and with the Document width set to the page width.
I know how to use the GUI tools to do all this, but would like the program to do it for me.
Can anyone advise how to do this?
Cheers
Robert
Opening a Document
Opening a Document
Last edited by Robert on Tue May 26, 2015 10:18 am, edited 1 time in total.
Re: Opening a Document
I use this piece of code to open a window that shows a text (document) so that document's width is equal to window's width:
Perhaps you can try something similar.
Regards,
Manuel
Code: Select all
md: TextModels.Model;
vw: TextViews.View;
cr: Containers.Controller;
prop: Properties.BoundsPref;
vw := TextViews.dir.New(md);
cr := vw.ThisController();
cr.SetOpts(cr.opts + {Containers.noCaret});
prop.w := Views.undefined; prop.h := Views.undefined; Views.HandlePropMsg(vw, prop);
Views.OpenAux(Documents.dir.New(vw, prop.w + 10 * Ports.mm, prop.h), 'Search result')
Regards,
Manuel
Re: Opening a Document
[quote="manumart1"]Perhaps you can try something similar./quote]
Thanks for the suggestions.
Two difficulties are:
1 - Some of the required Modules are completely undocumented
2 - Lack of orthogonality. OpenAux takes a "title" parameter but OpenView does not.
The code below (after a LOT of trial and error) seems to do what I wanted.
Regards
PS - How do you get the "Quote" tags to work properly?
Thanks for the suggestions.
Two difficulties are:
1 - Some of the required Modules are completely undocumented
2 - Lack of orthogonality. OpenAux takes a "title" parameter but OpenView does not.
The code below (after a LOT of trial and error) seems to do what I wanted.
Code: Select all
CONST
margin = 20 * Ports.mm;
VAR
text : TextModels.Model;
view : TextViews.View;
doc : Documents.Document;
w, h, l, t, r, b : INTEGER;
decorate : BOOLEAN;
win : Windows.Window;
BEGIN
text := ...;
view := TextViews.dir.New (text);
doc := Documents.dir.New (view, Views.undefined, Views.undefined);
doc.PollPage (w, h, l, t, r, b, decorate);
IF w < h THEN
I.Swap (w, h);
doc.SetPage (w, h, margin, margin, w - margin, h - margin, decorate)
END;
Views.OpenView (doc);
win := Windows.dir.First ();
LOOP
IF win = NIL THEN EXIT END;
IF win.doc = doc THEN win.SetTitle ('My Title'); EXIT END;
win := Windows.dir.Next (win)
END
PS - How do you get the "Quote" tags to work properly?
Re: Opening a Document
To reply you can push the button "Post reply" or "quote". In either case the editor is opened, but it is empty if "Post reply".Robert wrote:...
PS - How do you get the "Quote" tags to work properly?
If you pushed "quote" then the entire message you wanted to quote is included in the editor area, surrounded by
Code: Select all
[quote="Robert"]
Code: Select all
[/quote]
In your case, you lost the "[" before "/quote]"
Re: Opening a Document
Magic!manumart1 wrote: In your case, you lost the "[" before "/quote]"
Re: Opening a Document
Also, I noted a difference in the persistence of the model shown in the window (view) opened.Robert wrote: Lack of orthogonality. OpenAux takes a "title" parameter but OpenView does not.
If I open a window via OpenView and modify some text, then when I try to close it I am asked to save the changes.
But if the window was opened via OpenAux I am not; supposedly because they are temporary or auxiliary data, only intended to be viewed.
Regards
Re: Opening a Document
I am also interested in opening a document in a given page size and orientation. Rather than using Documents (which, somewhat ironically, is undocumented), I use Properties to set the page size and orientation. I created a module that allows me to set the page size and orientation. This works fine, but there's still an inconsistency between this and the Page Setup setting accessible under the File menu. To interact with this via code requires knowledge of the HostDialog internals, which are also undocumented.
MODULE SolarPage;
IMPORT Dialog, Ports, Properties, TextModels, TextViews, Views;
CONST
maxTypes = 10;
letter* = 0;
legal* = 1;
ledger* = 2;
mm = Ports.mm;
margin20 = 20*mm;
TYPE
Page* = RECORD (* do fields need to be exported *)
(* size: INTEGER; *)
(* orientation: INTEGER; *)
type: ARRAY 20 OF CHAR;
w*, h*: INTEGER;
l*, t*, r*, b*: INTEGER;
END;
Orientation* = RECORD
i: INTEGER;
END;
VAR
stdPages*: ARRAY maxTypes OF Page;
numOfTypes: INTEGER;
portrait-, landscape-: Orientation;
PROCEDURE (VAR page: Page) Set*( paper: INTEGER; orientation: Orientation), NEW;
BEGIN
page.w:= (1-orientation.i)*stdPages[paper].w + orientation.i*stdPages[paper].h;
page.h:= orientation.i*stdPages[paper].w + (1-orientation.i)*stdPages[paper].h;
page.l:= margin20;
page.t:= margin20;
page.r:= margin20;
page.b:= margin20;
END Set;
PROCEDURE (VAR page: Page) Open*( name: ARRAY OF CHAR; t: TextModels.Model), NEW;
VAR v: TextViews.View;
BEGIN
v := TextViews.dir.New(t); (* create a new text view for t *)
Properties.PreferredSize( v, stdPages[letter].w, stdPages[ledger].h, stdPages[letter].w, stdPages[ledger].h, stdPages[letter].h, stdPages[letter].w, page.w, page.h);
Views.OpenAux( v, name$); (* open the view in a window *)
END Open;
PROCEDURE (VAR page: Page) SetMargins*( l, t, r, b: INTEGER), NEW;
BEGIN
page.l:= l;
page.t:= t;
page.r:= r;
page.b:= b;
END SetMargins;
(* or could be Dir *)
PROCEDURE initPapers* (VAR papers: Dialog.List);
VAR i: INTEGER;
BEGIN
FOR i:= 0 TO numOfTypes - 1 DO
papers.SetItem( i, stdPages[ i].type );
END;
papers.SetLen( numOfTypes);
papers.index:=0;
END initPapers;
BEGIN
portrait.i:= 0;
landscape.i:= 1;
stdPages[letter].type:= "letter";
stdPages[letter].w:= 216 * mm;
stdPages[letter].h:= 279 * mm;
stdPages[legal].type:= "legal";
stdPages[legal].w:= 216 * mm;
stdPages[legal].h:= 356 * mm;
stdPages[ledger].type:= "ledger";
stdPages[ledger].w:= 279 * mm;
stdPages[ledger].h:= 432 * mm;
numOfTypes:= 3;
END SolarPage.
in client:
VAR page: SolarPage.Page;
page.Set( Page.letter, Page.portrait);
page.SetMargins( l, t, r, b);