Solved

Docking issue with DevExpress's ExpressDocking library

Posted on 2009-05-19
9
1,584 Views
Last Modified: 2012-05-07
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
Comment
Question by:Delphi_developer
  • 5
  • 4
9 Comments
 
LVL 14

Expert Comment

by:SteveBay
ID: 24436774
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
 

Author Comment

by:Delphi_developer
ID: 24437581
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
 
LVL 14

Expert Comment

by:SteveBay
ID: 24437726
As I said. "I can imagine some ways..." I will have to work on it a bit so please be patient
0
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 

Author Comment

by:Delphi_developer
ID: 24438980
SteveBay, I'll wait, any help is appreciated.
0
 
LVL 14

Expert Comment

by:SteveBay
ID: 24443100
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
 

Author Comment

by:Delphi_developer
ID: 24444297
Great! So far, it is exactly what I need.
0
 
LVL 14

Expert Comment

by:SteveBay
ID: 24453055
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
 
LVL 14

Accepted Solution

by:
SteveBay earned 500 total points
ID: 24454165
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
 

Author Comment

by:Delphi_developer
ID: 24457261
Awesome! Thank you, very much.
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question