Solved

Docking issue with DevExpress's ExpressDocking library

Posted on 2009-05-19
9
1,567 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
 

Author Comment

by:Delphi_developer
ID: 24438980
SteveBay, I'll wait, any help is appreciated.
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now