The following examples shows how to dynamically add a notebook to a window and then add pages with scroll bars to it. Notice the use of the subpartNamed:put: message. This message is sent to the parent part. Its first parameter is a string that names the new part and its second parameter is the part to be added to the parent part.
The following example builds a nonportable OS/2 - Windows Notebook. To use the code in this example, add AbtCwConstants as a pool dictionary to a class definition and add the code to a script in the same class. Or, if you simply want to evaluate the code in a Workspace, change XmMAJORTAB to AbtCwConstants::XmMAJORTAB before you evaluate the code.
"The example creates a notebook in a window part. It has two pages, each of which has a scrolled area for adding widgets." | pageView noteBookView aShell scroll attachAll | "Create the window" aShell := AbtShellView new title: 'A notebook in a window'; initWidgetSize: 300 @ 300. "Define an attachment that maximizes the size of a child" attachAll := AbtViewAttachmentConstraint new. attachAll leftEdge: (AbtEdgeAttachmentConstraint new attachForm); rightEdge: (AbtEdgeAttachmentConstraint new attachForm); topEdge: (AbtEdgeAttachmentConstraint new attachForm); bottomEdge: (AbtEdgeAttachmentConstraint new attachForm). "Add the notebook to the window" noteBookView := AbtNoteBookView new backPageForeground: 'blue'; framingSpec: attachAll. aShell subpartNamed: 'Notebook' put: noteBookView.
"Add two pages to the notebook, each with a scrolled window" 1 to: 2 do: [:i | "Add a page to the notebook" pageView := AbtNoteBookPageView new statusText: ('Page ', i printString); tabContents: i printString; tabType: XmMAJORTAB. "Or, AbtCwConstants::XmMAJORTAB" noteBookView subpartNamed: (i printString, '_page') put: pageView. "Add a scrolled window to the page" scroll := AbtScrolledWindowView new borderWidth: 1; scrollBarDisplayPolicy: XmASNEEDED; scrollingPolicy: XmAUTOMATIC; visualPolicy: XmCONSTANT; framingSpec: attachAll. pageView subpartNamed: (i printString, '_ScrollWindow') put: scroll. ]. aShell openWidget. "Open the window"
The following example builds a PM Notebook, which is portable. Like the previous example, add EwConstants as a pool dictionary to a class definition and add the code to a script in the same class. Or, to evaluate the code in a Workspace, change XmMAJOR to EwConstants::XmMAJOR before evaluating the code.
"The example creates a notebook in a window part. It has two pages, each of which has a scrolled area for adding widgets." | pageView noteBookView aShell scroll attachAll | "Create the window" aShell := AbtShellView new title: 'A notebook in a window'; initWidgetSize: 300 @ 300. "Define an attachment that maximizes the size of a child" attachAll := AbtViewAttachmentConstraint new. attachAll leftEdge: (AbtEdgeAttachmentConstraint new attachForm); rightEdge: (AbtEdgeAttachmentConstraint new attachForm); topEdge: (AbtEdgeAttachmentConstraint new attachForm); bottomEdge: (AbtEdgeAttachmentConstraint new attachForm). "Add the notebook to the window" noteBookView := AbtPortablePMNotebookView new foregroundColor: 'blue'; framingSpec: attachAll. aShell subpartNamed: 'Notebook' put: noteBookView. "Add two pages to the notebook, each with a scrolled window" 1 to: 2 do: [:i | "Add a page to the notebook" pageView := AbtPortableNotebookPageView new tabLabel: i printString; pageLabel: ('Page ', i printString); tabType: XmMAJOR. "Or, EwConstants::XmMAJOR" noteBookView subpartNamed: (i printString, '_page') put: pageView. "Add a scrolled window to the page" scroll := AbtScrolledWindowView new borderWidth: 1; scrollBarDisplayPolicy: XmASNEEDED; scrollingPolicy: XmAUTOMATIC; visualPolicy: XmCONSTANT; framingSpec: attachAll. pageView subpartNamed: (i printString, '_ScrollWindow') put: scroll. ]. aShell openWidget. "Open the window"
The following example builds a Windows Notebook, which is portable. To use the code, add EwConstants as a pool dictionary to a class definition and add the code to a script in the same class. Or, to evaluate the code in a Workspace, change XmMAJOR to EwConstants::XmMAJOR before evaluating the code.
"The example creates a notebook in a window part. It has two pages, each of which has a scrolled area for adding widgets." | pageView noteBookView aShell scroll attachAll | "Create the window" aShell := AbtShellView new title: 'A notebook in a window'; initWidgetSize: 300 @ 300. "Define an attachment that maximizes the size of a child" attachAll := AbtViewAttachmentConstraint new. attachAll leftEdge: (AbtEdgeAttachmentConstraint new attachForm); rightEdge: (AbtEdgeAttachmentConstraint new attachForm); topEdge: (AbtEdgeAttachmentConstraint new attachForm); bottomEdge: (AbtEdgeAttachmentConstraint new attachForm). "Add the notebook to the window" noteBookView := AbtPortableWINNotebookView new foregroundColor: 'blue'; framingSpec: attachAll. aShell subpartNamed: 'Notebook' put: noteBookView. "Add two pages to the notebook, each with a scrolled window" 1 to: 2 do: [:i | "Add a page to the notebook" pageView := AbtPortableNotebookPageView new tabLabel: i printString; pageLabel: ('Page ', i printString); tabType: XmMAJOR. "Or, EwConstants::XmMAJOR" noteBookView subpartNamed: (i printString, '_page') put: pageView. "Add a scrolled window to the page" scroll := AbtScrolledWindowView new borderWidth: 1; scrollBarDisplayPolicy: XmASNEEDED; scrollingPolicy: XmAUTOMATIC; visualPolicy: XmCONSTANT; framingSpec: attachAll. pageView subpartNamed: (i printString, '_ScrollWindow') put: scroll. ]. aShell openWidget. "Open the window"