• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1771
  • Last Modified:

Docking issue with DevExpress's ExpressDocking library

Hi

I need some help with creating 'docking' appearance with ExpressDocking from DevExpress.com. I use TdxDocSite and TdxDockPanel.

I would like to create simple docking application, with one fixed left dxDocPanel which opens new dxDocPanels on the right. Attached image shows that if I open only one new dxDocPanel, it opens it as 'client' aligned, so they both occupy full dxDocSite.
If I open another 'window', it will align both opened as half/half (2. on image) and if three.. they would all be same width to fully occupy dxDocsite and if I open the fourth window, they would all be fitted squarely.

So, the left panel has a list of 'items' and on right-click I can 'open' them as 'window' (dxDocPanel) on the right. It all appears in dxDocSite.

I was trying to create the mechanism but I just don't know how to.

In image:

1. first stage - only left panel is seen
2. I opened first 'window'
3. second window
4. third window
5. fourth window is opened

This is how I create only left panel:


----
Var
  gPanel1: TdxDockPanel;
Begin

  FTreeViewFrameCount := 0;

  gPanel1 := TdxDockPanel.Create(Self);

  gPanel1.DockTo(DxdockSite1, dtLeft, 0);
  CreateFrame(TCodeView_Tasks_form, gPanel1); -- THIS IS WHERE I CREATE CONTENT OF THE LEFT PANEL!! - LISTVIEW/TREEVIEW
  gPanel1.CaptionButtons := gPanel1.CaptionButtons - [cbClose];
  gPanel1.Caption := 'List of windows';

---
 
 
Please help.

Thank you
docking.jpg
0
Delphi_developer
Asked:
Delphi_developer
  • 5
  • 4
1 Solution
 
SteveBayCommented:
I can imagine some ways of doing this with code but none are particularly simple. The first three are fairly straightforward however the four panel screen adds another layer of complexity.  Do you intend to handle more than 4 dynamic panels? If so, some rather complex calculations would be necessary to deal with panels contained in panels contained in panels kind of thing.
0
 
Delphi_developerAuthor Commented:
Well, I believe I would go to max 4 windows opened at one time. More would be very hard to read, since each window has a lot of info shown.

I thought my task is pretty simple, but I'm struggling even with the first two options. Any help would be appreciated.
0
 
SteveBayCommented:
As I said. "I can imagine some ways..." I will have to work on it a bit so please be patient
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
Delphi_developerAuthor Commented:
SteveBay, I'll wait, any help is appreciated.
0
 
SteveBayCommented:
This is not nearly complete but it's a pretty good start. I will work to refine it more later.
unit Unit2;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, dxDockControl, dxDockPanel, ExtCtrls, StdCtrls,
  FileCtrl;
 
type
  TForm2 = class(TForm)
    dxDockSite1: TdxDockSite;
    DockingMgr: TdxDockingManager;
    OpenDialog1: TOpenDialog;
    procedure FormCreate(Sender: TObject);
  private
     DockSite : TdxDockSite;
     MainBar : TdxDockPanel;
     procedure FileListBoxClick(Sender: TObject);
     function GetPanelByCaption(aCaption : String) : TdxDockPanel ;
     procedure AddPanel(FileName : string);
     procedure DeletePanelByCaption(aCaption : String);
    { Private declarations }
  public
    { Public declarations }
  end;
 
var
  Form2: TForm2;
 
implementation
 
{$R *.dfm}
 
procedure TForm2.FormCreate(Sender: TObject);
var  APanel: TdxDockPanel;
     FileListBox: TFileListBox;
begin
     DockingMgr.Options := DockingMgr.Options + [doFreeOnClose];
     DockingMgr.DefaultTabContainerSiteProperties.TabsPosition := tctpTop;
     DockingMgr.ViewStyle := vsOffice11;
     FileListBox := TFileListBox.Create(Self);
     FileListBox.Align := alLeft;
     FileListBox.Parent := Self;
     FileListBox.Mask := '*.bmp';
     FileListBox.ApplyFilePath('C:\Windows');
     FileListBox.MultiSelect := True;
     FileListBox.OnClick := FileListBoxClick;
     dxDockSite1.Align := alClient;
end;
 
procedure TForm2.FileListBoxClick(Sender: TObject);
var i : Integer;
     FileListBox : TFileListBox;
     Path : String;
begin
     if not (Sender is TFileListBox) then
          Exit;
 
     FileListBox := TFileListBox(Sender);
     for i := 0 to FileListBox.Count - 1 do
          begin
          if FileListBox.Selected[i] then
               begin
               Path := ExtractFilePath(FileListBox.FileName);
               if GetPanelByCaption(FileListBox.Items[i] ) = nil then
                    AddPanel(Path + FileListBox.Items[i]);
               end
          else begin
               DeletePanelByCaption(FileListBox.Items[i]);
               end;
          end;
end;
 
procedure TForm2.AddPanel(FileName: string);
var APicture: TPicture;
    APanel: TdxDockPanel;
    AImage: TImage;
    ALastIndex, I: Integer;
begin
     // open the file and create the corresponding image object
     if not FileExists(FileName) then
          Exit;
 
     APicture := TPicture.Create();
     APicture.LoadFromFile(FileName);
     // create a new panel that will hold the image
     APanel := TdxDockPanel.Create(Self);
     APanel.Caption := ExtractFileName(FileName);
 
     // dock the panel to the dock site
     APanel.DockTo(dxDockSite1, dtLeft, 0);
 
     // create an image control and place it on the panel
     AImage := TImage.Create(Self);
     AImage.Parent := APanel;
     AImage.Align := alClient;
     AImage.Center := True;
     AImage.Picture := APicture;
end;
 
function TForm2.GetPanelByCaption(aCaption: String): TdxDockPanel;
var i : integer;
begin
     Result := nil;
     for i := 0 to dxDockingController.DockControlCount - 1 do
          begin
          if (dxDockingController.DockControls[i] is TdxDockPanel) and
              SameText(TdxDockPanel(dxDockingController.DockControls[i]).Caption,aCaption) then
               begin
               Result := TdxDockPanel(dxDockingController.DockControls[i]);
               break;
               end;
          end;
 
end;
 
procedure TForm2.DeletePanelByCaption(aCaption: String);
var i : Integer;
begin
     for i := 0 to dxDockingController.DockControlCount - 1 do
          begin
          if (dxDockingController.DockControls[i] is TdxDockPanel) and
              SameText(TdxDockPanel(dxDockingController.DockControls[i]).Caption,aCaption) then
               dxDockingController.DockControls[i].Close;
          end;
end;
 
end.

Open in new window

0
 
Delphi_developerAuthor Commented:
Great! So far, it is exactly what I need.
0
 
SteveBayCommented:
Getting closer. I still dont have #5. It's a bit more complicated than 1 - 4.
unit Unit2;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, dxDockControl, dxDockPanel, ExtCtrls, StdCtrls,
  FileCtrl,jpeg ,
  CodeSiteLogging   ;
 
type
  TForm2 = class(TForm)
    dxDockSite1: TdxDockSite;
    DockingMgr: TdxDockingManager;
    OpenDialog1: TOpenDialog;
    procedure FormCreate(Sender: TObject);
  private
     procedure FileListBoxClick(Sender: TObject);
     function GetPanelByCaption(aCaption : String) : TdxDockPanel ;
     procedure AddPanel(FileName : string);
     procedure DeletePanelByCaption(aCaption : String);
    { Private declarations }
  public
    { Public declarations }
  end;
 
var
  Form2: TForm2;
 
implementation
 
uses Unit3;
 
{$R *.dfm}
 
procedure TForm2.FormCreate(Sender: TObject);
var  APanel: TdxDockPanel;
     FileListBox: TFileListBox;
begin
     DockingMgr.Options := DockingMgr.Options + [doFreeOnClose];
     DockingMgr.DefaultTabContainerSiteProperties.TabsPosition := tctpTop;
     DockingMgr.ViewStyle := vsOffice11;
     FileListBox := TFileListBox.Create(Self);
     FileListBox.Align := alLeft;
     FileListBox.Parent := Self;
     FileListBox.Mask := '*.bmp';
     FileListBox.ApplyFilePath('C:\Windows');
     FileListBox.MultiSelect := True;
     FileListBox.OnClick := FileListBoxClick;
     //FileListBox.OnDblClick := FileListBoxDblClick;
     dxDockSite1.Align := alClient;
end;
 
procedure TForm2.FileListBoxClick(Sender: TObject);
var i : Integer;
     FileListBox : TFileListBox;
     Path : String;
     bmp : TBitmap;
begin
     if not (Sender is TFileListBox) then
          Exit;
     FileListBox := TFileListBox(Sender);
 
     // Delete existing panels that have been unselected panels first.
     for i := 0 to FileListBox.Count - 1 do
          begin
          if not FileListBox.Selected[i] then
               DeletePanelByCaption(FileListBox.Items[i]);
          end;
 
     // Add panels that are not found to alread exist.
     for i := 0 to FileListBox.Count - 1 do
          begin
          if FileListBox.Selected[i] then
               begin
               Path := ExtractFilePath(FileListBox.FileName);
               if GetPanelByCaption(FileListBox.Items[i] ) = nil then
                    AddPanel(Path + FileListBox.Items[i]);
               end
          end;
end;
 
procedure TForm2.AddPanel(FileName: string);
var aPicture: TPicture;
    aPanel: TdxDockPanel;
    aImage: TImage;
    I: Integer;
    aPanelList : TList;
begin
     // open the file and create the corresponding image object
     if not FileExists(FileName) then
          Exit;
 
     aPanelList := TList.Create;
     for i := 0 to dxDockingController.DockControlCount -1 do
          begin
          if (dxDockingController.DockControls[i] is TdxDockPanel) and
             (TdxDockPanel(dxDockingController.DockControls[i]).Tag <> 0) then
               aPanelList.Add(dxDockingController.DockControls[i]);
          end;
 
     // Don't allow more than four Panels
     if aPanelList.Count < 4 then
          begin
          APicture := TPicture.Create();
          APicture.LoadFromFile(FileName);
          // create a new panel that will hold the image
          APanel := TdxDockPanel.Create(Self);
          // Use tag to Identifiy panels WE Created.
          aPanel.Tag := aPanelList.Count + 1;
          APanel.Caption := ExtractFileName(FileName);
          // create an image control and place it on the panel
          AImage := TImage.Create(Self);
          AImage.Parent := APanel;
          AImage.Align := alClient;
          AImage.Center := True;
          AImage.Picture := APicture;
          end;
 
     if aPanelList.Count = 0 then
          APanel.DockTo(dxDockSite1, dtClient, maxint)
     else if aPanelList.Count = 1 then
          begin
          APanel.DockTo(dxDockSite1 , dtRight, maxint);
          APanel.Width := dxDockSite1.Width div 2;
          end
     else if aPanelList.Count = 2 then
          begin
          APanel.DockTo(dxDockSite1, dtRight, maxint);
          TdxDockPanel(aPanelList[0]).Width := dxDockSite1.Width div 3;
          TdxDockPanel(aPanelList[1]).Width := dxDockSite1.Width div 3;
          aPanel.Width := dxDockSite1.Width div 3;
          end
     else if aPanelList.Count = 3 then
          begin
          APanel.DockTo(dxDockSite1, dtRight, maxint);
          TdxDockPanel(aPanelList[0]).Width := dxDockSite1.Width div 4;
          TdxDockPanel(aPanelList[1]).Width := dxDockSite1.Width div 4;
          TdxDockPanel(aPanelList[2]).Width := dxDockSite1.Width div 4;
          aPanel.Width := dxDockSite1.Width div 4;
          APanel.DockTo(dxDockSite1, dtRight, maxint);
          end;
     aPanelList.Free;
end;
 
function TForm2.GetPanelByCaption(aCaption: String): TdxDockPanel;
var i : integer;
begin
     Result := nil;
     for i := 0 to dxDockingController.DockControlCount - 1 do
          begin
          if (dxDockingController.DockControls[i] is TdxDockPanel) and
              SameText(TdxDockPanel(dxDockingController.DockControls[i]).Caption,aCaption) then
               begin
               Result := TdxDockPanel(dxDockingController.DockControls[i]);
               break;
               end;
          end;
 
end;
 
procedure TForm2.DeletePanelByCaption(aCaption: String);
var i : Integer;
begin
     for i := dxDockingController.DockControlCount - 1 downto 0  do
          begin
          if (dxDockingController.DockControls[i] is TdxDockPanel) and
              SameText(TdxDockPanel(dxDockingController.DockControls[i]).Caption,aCaption) then
               begin
               dxDockingController.DockControls[i].Close;
               TdxDockPanel(dxDockingController.DockControls[i]).Free;
               end;
          end;
end;
 
 
end.

Open in new window

0
 
SteveBayCommented:
This is it! I suppose it's likely that there are more efficient ways of doing this but I'm exhausted.:-)
unit Unit2;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, dxDockControl, dxDockPanel, ExtCtrls, StdCtrls,
  FileCtrl,jpeg ,
  CodeSiteLogging   ;
 
type
  TForm2 = class(TForm)
    dxDockSite1: TdxDockSite;
    DockingMgr: TdxDockingManager;
    OpenDialog1: TOpenDialog;
    procedure FormCreate(Sender: TObject);
  private
     procedure FileListBoxClick(Sender: TObject);
     function GetPanelByCaption(aCaption : String) : TdxDockPanel ;
     procedure AddPanel(FileName : string);
     procedure DeletePanelByCaption(aCaption : String);
    { Private declarations }
  public
    { Public declarations }
  end;
 
var
  Form2: TForm2;
 
implementation
 
{$R *.dfm}
 
procedure TForm2.FormCreate(Sender: TObject);
var  APanel: TdxDockPanel;
     FileListBox: TFileListBox;
begin
     DockingMgr.Options := DockingMgr.Options + [doFreeOnClose];
     DockingMgr.DefaultTabContainerSiteProperties.TabsPosition := tctpTop;
     DockingMgr.ViewStyle := vsOffice11;
     FileListBox := TFileListBox.Create(Self);
     FileListBox.Align := alLeft;
     FileListBox.Parent := Self;
     FileListBox.Mask := '*.bmp';
     FileListBox.ApplyFilePath('C:\Windows');
     FileListBox.MultiSelect := True;
     FileListBox.OnClick := FileListBoxClick;
     dxDockSite1.Align := alClient;
end;
 
procedure TForm2.FileListBoxClick(Sender: TObject);
var i : Integer;
     FileListBox : TFileListBox;
     Path : String;
     bmp : TBitmap;
begin
     if not (Sender is TFileListBox) then
          Exit;
     FileListBox := TFileListBox(Sender);
 
     // Delete existing panels that have been unselected panels first.
     for i := 0 to FileListBox.Count - 1 do
          begin
          if not FileListBox.Selected[i] then
               DeletePanelByCaption(FileListBox.Items[i]);
          end;
 
     // Add panels that are not found to alread exist.
     for i := 0 to FileListBox.Count - 1 do
          begin
          if FileListBox.Selected[i] then
               begin
               Path := ExtractFilePath(FileListBox.FileName);
               if GetPanelByCaption(FileListBox.Items[i] ) = nil then
                    AddPanel(Path + FileListBox.Items[i]);
               end
          end;
end;
 
procedure TForm2.AddPanel(FileName: string);
var aPicture: TPicture;
    aPanel: TdxDockPanel;
    aImage: TImage;
    I: Integer;
    aPanelList : TList;
begin
     // open the file and create the corresponding image object
     if not FileExists(FileName) then
          Exit;
 
     // Find panels we created and add then to a list.
     aPanelList := TList.Create;
     for i := 0 to dxDockingController.DockControlCount -1 do
          begin
          if (dxDockingController.DockControls[i] is TdxDockPanel) and
             (TdxDockPanel(dxDockingController.DockControls[i]).Tag <> 0) then
               aPanelList.Add(dxDockingController.DockControls[i]);
          end;
 
     // Don't allow more than four Panels
     if aPanelList.Count < 4 then
          begin
          APicture := TPicture.Create();
          APicture.LoadFromFile(FileName);
          // create a new panel that will hold the image
          APanel := TdxDockPanel.Create(Self);
          // Use tag to Identifiy panels WE Created.
          aPanel.Tag := aPanelList.Count + 1;
          APanel.Caption := ExtractFileName(FileName);
          // create an image control and place it on the panel
          AImage := TImage.Create(Self);
          AImage.Parent := APanel;
          AImage.Align := alClient;
          AImage.Center := True;
          AImage.Picture := APicture;
          end;
 
     if aPanelList.Count = 0 then
          // fill client area with 1
          APanel.DockTo(dxDockSite1, dtClient, maxint)
     else if aPanelList.Count = 1 then
          begin
          // arrange 2 side by side
          APanel.DockTo(dxDockSite1 , dtRight, maxint);
          APanel.Width := dxDockSite1.Width div 2;
          end
     else if aPanelList.Count = 2 then
          begin
          // Arrange 3 side by side by side
          APanel.DockTo(dxDockSite1, dtRight, maxint);
          TdxDockPanel(aPanelList[0]).Width := dxDockSite1.Width div 3;
          TdxDockPanel(aPanelList[1]).Width := dxDockSite1.Width div 3;
          aPanel.Width := dxDockSite1.Width div 3;
          end
     else if aPanelList.Count = 3 then
          begin
          // Arrange 4 - 2 over 2
          APanel.DockTo(dxDockSite1, dtRight, maxint);
          TdxDockPanel(aPanelList[0]).Width := dxDockSite1.Width div 2;
          TdxDockPanel(aPanelList[1]).DockTo(TdxDockPanel(aPanelList[0]),dtBottom, MaxInt);
          TdxDockPanel(aPanelList[0]).Height := dxDockSite1.Height div 2;
          TdxDockPanel(aPanelList[2]).Width := dxDockSite1.Width div 2;
          APanel.DockTo(TdxDockPanel(aPanelList[2]), dtBottom, MaxInt);
          TdxDockPanel(aPanelList[2]).Height := dxDockSite1.Height div 2;
          end;
     aPanelList.Free;
end;
 
function TForm2.GetPanelByCaption(aCaption: String): TdxDockPanel;
var i : integer;
begin
     Result := nil;
     for i := 0 to dxDockingController.DockControlCount - 1 do
          begin
          if (dxDockingController.DockControls[i] is TdxDockPanel) and
              SameText(TdxDockPanel(dxDockingController.DockControls[i]).Caption,aCaption) then
               begin
               Result := TdxDockPanel(dxDockingController.DockControls[i]);
               break;
               end;
          end;
 
end;
 
procedure TForm2.DeletePanelByCaption(aCaption: String);
var i : Integer;
begin
     for i := dxDockingController.DockControlCount - 1 downto 0  do
          begin
          if (dxDockingController.DockControls[i] is TdxDockPanel) and
              SameText(TdxDockPanel(dxDockingController.DockControls[i]).Caption,aCaption) then
               begin
               dxDockingController.DockControls[i].Close;
               TdxDockPanel(dxDockingController.DockControls[i]).Free;
               end;
          end;
end;
 
 
end.

Open in new window

0
 
Delphi_developerAuthor Commented:
Awesome! Thank you, very much.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now