User Tools

Site Tools


k12:k12.3:k12.3.1:start

12.3.1 Workspace

The Workspace class (gb.form.mdi) implements a workspace into which you can add top-level windows. To add new windows to the workspace, they must first be instantiated. Use the Add() method to insert a top-level window into a workspace. You can switch between windows in the workspace by switching tabs. The terms workspace, workspace and tab are used interchangeably in this chapter.

B1
Figure 12.3.1.1: Four top-level windows in a workspace

12.3.1.1 Properties

The Workspace class has these selected properties, among others:

PropertyDataTypeDescription
ActiveWindow WindowSets the active window or returns the active window in the workspace.
BackgroundIntegerSets the background colour in case there is no window in the workspace or returns the colour value.
ImageImageReturns the background image for the workspace or sets the image (→ from version 3.7). The background image is only displayed if there is no window in the workspace. By default, a dark background is displayed.
CountIntegerIndicates the number of windows managed by the workspace.
WindowsWindow[]Returns a list of all windows that are anchored in the workspace.
Children.Container.ChildrenThe virtual class .Container.Children represents a top-level window in a workspace. You can use a workspace like an array to get an object of the class .Container.Children (i.e. a top-level window) via its index.

Table 12.3.1.1 : Properties of the class Workspace

12.3.1.2 Methods

The following table describes some methods of the Workspace class:

MethodDescription
Add( hWindow As Window ) As WindowInserts a top-level window into a workspace and then redraws it.
Detach( hWindow As Window )Detaches a window from a workspace and makes it a (free) top-level window. You can anchor the window in the workspace again at any time with the Attach() method.
Attach( hWindow As Window )Anchors a top-level window that has been detached with the Detach() method back into a workspace.
Exist( hWindow As Window ) As BooleanThe function returns True if the window passed as argument is managed by the workspace.
Lock( )Locks the workspace. The tabs are not updated when the workspace is locked.
Unlock( )Unlocks the workspace. As soon as the workspace is unlocked, the tab sheets are updated again.

Table 12.3.1.2.1 : Methods of the Workspace Class

12.3.1.3 Events

Of the events of the Workspace class, only these four are presented to you:

EventDescription
Activate()The event is triggered when the active window has been changed.
Attach( Window As Window )The event is triggered when a window is added back to the workspace.
Detach( Window As Window )The event is triggered when a window has been detached from the workspace.
Close( Window As Window )The event is triggered when a tab is closed.

Table 12.3.1.3.1 : Selected Events of the Class Workspace

The workspace has a context menu - callable in the tab tab line - with which you can implement the following features:

  • Display of a specific window → Window list.
  • Sorting of the tabs - but only in one sorting order.
  • Delete all tabs.
  • Delete the left or right tab - depending on the active window or delete all tabs - except the active tab.
  • Detach a window managed by a workspace - i.e. anchored there - from the workspace or insert a top-level window managed by a workspace back into the workspace.

Hints:

  • If you are standing with the mouse over a tab card tab in the workspace, you can navigate through the anchored programmes with the mouse wheel (carefully).
  • You can also sort the tabs by holding down the left mouse button and moving the selected tab to the desired new position.
  • If you close a top-level window in the tab-map tab, then the window is no longer managed by the workspace.

12.3.1.4 Project

The project provides, among other things, a workspace in which 4 top-level windows are anchored, behind which 4 external programmes are located. It has proved advantageous to store all the programmes to be inserted in their own directories in the project folder. In addition, the main programme has a menu that allows you to add a window back to the workspace if you had removed it from the workspace management. You can detach a special window in the workspace (OpenStreetMap) from the workspace and add it again. The 4 top-level windows in the presented project do not belong together in terms of content. In a productive environment, one would choose programmes with which to solve a task. For example, a programme for calculating value tables would fit well with a function plotter.

B2
Figure 12.3.1.4.1: Main programme with the workspace (4 windows)

In the source code of each external programme, you should set the Caption and Icon properties with appropriate values. Note: The programme icon is also adopted as the icon for the corresponding tab in the workspace. Unfortunately, the icon - unlike the programme icon - is not scaled to the required size. Therefore, already choose a programme icon with a size of 16×16 pixels → line 4 in the following source code excerpt:

[1] Public Sub Form_Open()
[2]   FGeoMap.Center
[3]   FGeoMap.Caption = "  OpenStreetMap"
[4]   FGeoMap.Icon = Picture["icon:/16/internet"]
[5]   ShowMap()
[6] End ' Form_Open()

The source code is manageable and holds no surprises:

[1] ' Gambas class file
[2]
[3] Public Sub Form_Open()
[4]
[5]   FMain.Center
[6]   FMain.Resizable = True
[7]   FMain.Caption = "Container Workspace"
[8]
[9]   Workspace1.Image = Image.Load("Symbols/intro.jpg")
[10]   Workspace1.Add(FDBWizard)
[11]   Workspace1.Add(FGeoMap)
[12]   Workspace1.Add(FTools)
[13]   Workspace1.Add(FPing)
[14]   Workspace1.ActiveWindow = FTools
[15]
[16]   btnInOut.Text = "  Solve OpenStreetMap"
[17]
[18] End ' Form_Open
[19]
[20] Public Sub Menu11_Click()
[21]   If Not Workspace1.Exist(FDBWizard) Then Try Workspace1.Add(FDBWizard)
[22] End ' Menu11
[23]
[24] Public Sub Menu12_Click()
[25]   If Not Workspace1.Exist(FGeoMap) Then Workspace1.Add(FGeoMap)
[26]   btnInOut.Visible = True
[27]   Print Last.Text
[28] End ' Menu12
[29]
[30] Public Sub Menu13_Click()
[31]   If Not Workspace1.Exist(FTools) Then Workspace1.Add(FTools)
[32] End ' Menu13
[33]
[34] Public Sub Menu14_Click()
[35]   If Not Workspace1.Exist(FPing) Then Workspace1.Add(FPing)
[36]   Print Last.Text
[37] End ' Menu14
[38]
[39] Public Sub btnInOut_Click()
[40]
[41]   If Workspace1.Exist(FGeoMap)
[42]      If Not Workspace1.Tag Then
[43]         Workspace1.Detach(FGeoMap)
[44]         Workspace1.Tag = "A"
[45]         btnInOut.Text = "  Anchor OpenStreetMap"
[46]      Else
[47]         Workspace1.Tag = ""
[48]         Workspace1.Attach(FGeoMap)
[49]         btnInOut.Text = "  Solve OpenStreetMap"
[50]         Workspace1.ActiveWindow = FGeoMap
[51]      Endif
[52]   Endif
[53]
[54] End ' btnInOut_Click()
[55]
[56] Public Sub Workspace1_Activate()
[57]   Dim sProgramName As String
[58] ' For control:
[59]   If Workspace1.Count > 1 Then Print Workspace1.ActiveWindow.Name
[60] End ' Workspace1_Activate()
[61]
[62] Public Sub Workspace1_Close(hWindow As Window)
[63] ' For control:
[64]   Print "OK 1"
[65]   If hWindow = FGeoMap.Window Then btnInOut.Visible = False
[66] End ' Workspace1_Close(hWindow As Window)

Notes:

  • As an alternative for the background image - in the absence of content for the workspace - in line 9, for example, this could be used: Workspace1.Background = Color.LightGray.
  • Lines 20 to 37 define the actions in the 4 menu items.
  • The detachment for a specific window from the workspace and the reinsertion into the workspace is defined in lines 39 to 54.
  • The last two procedures helped in the development of the programme and can be omitted.
  • When testing the project, please use SQLite3 as the database management system in the 'DB Manager' programme (→ menu) and the supplied database 'kontakte.sqlite'.

Download

Project

Download

The website uses a temporary session cookie. This technically necessary cookie is deleted when the browser is closed. You can find information on cookies in our privacy policy.
k12/k12.3/k12.3.1/start.txt · Last modified: 01.02.2022 (external edit)

Page Tools