Hi Dave Page,
Dave Page wrote:
I think you missed couple of files:
xh_ctlListArranger.h
xh_ctlListArranger.cpp
You are right.
I missed to added two files: :(
* ctl/ctlListItemArranger.cpp
* include/ctl/ctlListArranger.h
Please find the updated patch.
Regards,
Ashesh
Index: ctl/xh_ctlListArranger.cpp
===================================================================
--- ctl/xh_ctlListArranger.cpp (revision 0)
+++ ctl/xh_ctlListArranger.cpp (revision 0)
@@ -0,0 +1,34 @@
+//////////////////////////////////////////////////////////////////////////
+//
+// pgAdmin III - PostgreSQL Tools
+// RCS-ID: $id$
+// Copyright (C) 2002 - 2008, The pgAdmin Development Team
+// This software is released under the Artistic Licence
+//
+// xh_ctlListArranger.cpp - ctlListArranger handler
+//
+//////////////////////////////////////////////////////////////////////////
+
+
+#include "wx/wx.h"
+
+#include "pgAdmin3.h"
+#include "ctl/ctlListItemArranger.h"
+#include "ctl/xh_ctlListArranger.h"
+
+IMPLEMENT_DYNAMIC_CLASS(ctlListArrangerXmlHandler, wxPanelXmlHandler)
+
+
+wxObject *ctlListArrangerXmlHandler::DoCreateResource()
+{
+ ctlListItemArranger *ctl=new ctlListItemArranger(m_parentAsWindow, GetID(), GetPosition(), GetSize(), GetStyle());
+
+ SetupWindow(ctl);
+
+ return ctl;
+}
+
+bool ctlListArrangerXmlHandler::CanHandle(wxXmlNode *node)
+{
+ return IsOfClass(node, wxT("ctlListArranger"));
+}
Index: ctl/module.mk
===================================================================
--- ctl/module.mk (revision 7500)
+++ ctl/module.mk (working copy)
@@ -26,7 +26,9 @@
$(srcdir)/ctl/xh_ctlcombo.cpp \
$(srcdir)/ctl/xh_ctltree.cpp \
$(srcdir)/ctl/xh_sqlbox.cpp \
- $(srcdir)/ctl/xh_timespin.cpp
+ $(srcdir)/ctl/xh_timespin.cpp \
+ $(srcdir)/ctl/xh_ctlListArranger.cpp \
+ $(srcdir)/ctl/ctlListItemArranger.cpp
EXTRA_DIST += \
$(srcdir)/ctl/module.mk
Index: include/ctl/module.mk
===================================================================
--- include/ctl/module.mk (revision 7500)
+++ include/ctl/module.mk (working copy)
@@ -26,7 +26,9 @@
$(srcdir)/include/ctl/xh_ctlcombo.h \
$(srcdir)/include/ctl/xh_ctltree.h \
$(srcdir)/include/ctl/xh_sqlbox.h \
- $(srcdir)/include/ctl/xh_timespin.h
+ $(srcdir)/include/ctl/xh_timespin.h \
+ $(srcdir)/include/ctl/xh_ctlListArranger.h \
+ $(srcdir)/include/ctl/ctlListItemArranger.h
EXTRA_DIST += \
$(srcdir)/include/ctl/module.mk
Index: include/utils/misc.h
===================================================================
--- include/utils/misc.h (revision 7500)
+++ include/utils/misc.h (working copy)
@@ -86,6 +86,7 @@
#define CTRL_CHECKLISTBOX(id) (XRCCTRL(*this, id, wxCheckListBox))
#define CTRL_DATEPICK(id) (XRCCTRL(*this, id, wxDatePickerCtrl))
#define CTRL_TREE(id) (XRCCTRL(*this, id, ctlTree))
+#define CTRL_LISTARRANGER(id) ((ctlListView*)((ctlListItemArranger*)(XRCCTRL(*this, id, wxPanel)))->GetList())
#endif // PGSCLI
Index: include/images/ctlListItemArrangerLast.xpm
===================================================================
--- include/images/ctlListItemArrangerLast.xpm (revision 0)
+++ include/images/ctlListItemArrangerLast.xpm (revision 0)
@@ -0,0 +1,38 @@
+/* XPM */
+const char * ctlListItemArranger_Last_xpm[] = {
+"13 8 27 1",
+" c None",
+". c #8BB161",
+"+ c #5A9B13",
+"@ c #CEE0A7",
+"# c #BAD381",
+"$ c #B2CE71",
+"% c #B0CD6C",
+"& c #ADCB62",
+"* c #ABC95E",
+"= c #A9C856",
+"- c #AFCC63",
+"; c #C5DA8D",
+"> c #BAD485",
+", c #9FC353",
+"' c #97BD40",
+") c #92BA33",
+"! c #90B82C",
+"~ c #94BB2F",
+"{ c #AFCC64",
+"] c #BAD483",
+"^ c #9FC251",
+"/ c #94BB38",
+"( c #92B931",
+"_ c #B1CD69",
+": c #A5C55A",
+"< c #B6D178",
+"[ c #CCDFA3",
+" .+++++++++. ",
+" [EMAIL PROTECTED]&*=-;+ ",
+" .+>,')!~{+. ",
+" .+]^/(_+. ",
+" .+#:<+. ",
+" .+[+. ",
+" .+. ",
+" .+++++++++. "};
Index: include/images/ctlListItemArrangerDown.xpm
===================================================================
--- include/images/ctlListItemArrangerDown.xpm (revision 0)
+++ include/images/ctlListItemArrangerDown.xpm (revision 0)
@@ -0,0 +1,49 @@
+/* XPM */
+const char * ctlListItemArranger_Down_xpm[] = {
+"13 8 38 1",
+" c None",
+". c #8BB161",
+"+ c #5A9B13",
+"@ c #CEE0A7",
+"# c #BAD381",
+"$ c #B2CE71",
+"% c #B0CD6C",
+"& c #AECB67",
+"* c #ADCB62",
+"= c #ABC95E",
+"- c #AAC85A",
+"; c #A9C856",
+"> c #AFCC63",
+", c #C5DA8D",
+"' c #BAD485",
+") c #9FC353",
+"! c #97BD40",
+"~ c #95BB39",
+"{ c #92BA33",
+"] c #90B82C",
+"^ c #8EB726",
+"/ c #94BB2F",
+"( c #AFCC64",
+"_ c #BAD483",
+": c #9FC251",
+"< c #96BD3E",
+"[ c #94BB38",
+"} c #92B931",
+"| c #97BC38",
+"1 c #B1CD69",
+"2 c #BAD383",
+"3 c #9EC24F",
+"4 c #96BC3D",
+"5 c #9BBF43",
+"6 c #B4CF70",
+"7 c #A5C55A",
+"8 c #B6D178",
+"9 c #CCDFA3",
+".+++++++++++.",
+"[EMAIL PROTECTED]&*=-;>,+",
+".+')!~{]^/(+.",
+" .+_:<[}|1+. ",
+" .+23456+. ",
+" .+#78+. ",
+" .+9+. ",
+" .+. "};
Index: include/images/ctlListItemArrangerUp.xpm
===================================================================
--- include/images/ctlListItemArrangerUp.xpm (revision 0)
+++ include/images/ctlListItemArrangerUp.xpm (revision 0)
@@ -0,0 +1,49 @@
+/* XPM */
+const char * ctlListItemArranger_Up_xpm[] = {
+"13 8 38 1",
+" c None",
+". c #8BB161",
+"+ c #5A9B13",
+"@ c #CCDFA3",
+"# c #BAD381",
+"$ c #A5C55A",
+"% c #B6D178",
+"& c #BAD383",
+"* c #9EC24F",
+"= c #96BC3D",
+"- c #9BBF43",
+"; c #B4CF70",
+"> c #BAD483",
+", c #9FC251",
+"' c #96BD3E",
+") c #94BB38",
+"! c #92B931",
+"~ c #97BC38",
+"{ c #B1CD69",
+"] c #BAD485",
+"^ c #9FC353",
+"/ c #97BD40",
+"( c #95BB39",
+"_ c #92BA33",
+": c #90B82C",
+"< c #8EB726",
+"[ c #94BB2F",
+"} c #AFCC64",
+"| c #CEE0A7",
+"1 c #B2CE71",
+"2 c #B0CD6C",
+"3 c #AECB67",
+"4 c #ADCB62",
+"5 c #ABC95E",
+"6 c #AAC85A",
+"7 c #A9C856",
+"8 c #AFCC63",
+"9 c #C5DA8D",
+" .+. ",
+" [EMAIL PROTECTED] ",
+" .+#$%+. ",
+" .+&*=-;+. ",
+" .+>,')!~{+. ",
+".+]^/(_:<[}+.",
+"+|#123456789+",
+".+++++++++++."};
Index: include/images/ctlListItemArrangerFirst.xpm
===================================================================
--- include/images/ctlListItemArrangerFirst.xpm (revision 0)
+++ include/images/ctlListItemArrangerFirst.xpm (revision 0)
@@ -0,0 +1,38 @@
+/* XPM */
+const char * ctlListItemArranger_First_xpm[] = {
+"13 8 27 1",
+" c None",
+". c #8BB161",
+"+ c #5A9B13",
+"@ c #CCDFA3",
+"# c #BAD381",
+"$ c #A5C55A",
+"% c #B6D178",
+"& c #BAD483",
+"* c #9FC251",
+"= c #94BB38",
+"- c #92B931",
+"; c #B1CD69",
+"> c #BAD485",
+", c #9FC353",
+"' c #97BD40",
+") c #92BA33",
+"! c #90B82C",
+"~ c #94BB2F",
+"{ c #AFCC64",
+"] c #CEE0A7",
+"^ c #B2CE71",
+"/ c #B0CD6C",
+"( c #ADCB62",
+"_ c #ABC95E",
+": c #A9C856",
+"< c #AFCC63",
+"[ c #C5DA8D",
+" .+++++++++. ",
+" .+. ",
+" [EMAIL PROTECTED] ",
+" .+#$%+. ",
+" .+&*=-;+. ",
+" .+>,')!~{+. ",
+" +]#^/(_:<[+ ",
+" .+++++++++. "};
Index: include/images/module.mk
===================================================================
--- include/images/module.mk (revision 7500)
+++ include/images/module.mk (working copy)
@@ -202,7 +202,11 @@
$(srcdir)/include/images/view.xpm \
$(srcdir)/include/images/viewdata.xpm \
$(srcdir)/include/images/viewfiltereddata.xpm \
- $(srcdir)/include/images/views.xpm
+ $(srcdir)/include/images/views.xpm \
+ $(srcdir)/include/images/ctlListItemArrangerDown.xpm \
+ $(srcdir)/include/images/ctlListItemArrangerFirst.xpm \
+ $(srcdir)/include/images/ctlListItemArrangerLast.xpm \
+ $(srcdir)/include/images/ctlListItemArrangerUp.xpm
EXTRA_DIST += \
$(srcdir)/include/images/module.mk \
Index: include/dlg/dlgType.h
===================================================================
--- include/dlg/dlgType.h (revision 7500)
+++ include/dlg/dlgType.h (working copy)
@@ -14,6 +14,7 @@
#define __DLG_TYPEPROP
#include "dlg/dlgProperty.h"
+#include "ctl/ctlListItemArranger.h"
class pgType;
Index: utils/sysSettings.cpp
===================================================================
--- utils/sysSettings.cpp (revision 7500)
+++ utils/sysSettings.cpp (working copy)
@@ -147,7 +147,7 @@
else if (objtype == _("Types"))
{
engtype = wxT("Types");
- def = false;
+ def = true;
}
else if (objtype == _("Views"))
engtype = wxT("Views");
Index: pgAdmin3.vcproj
===================================================================
--- pgAdmin3.vcproj (revision 7500)
+++ pgAdmin3.vcproj (working copy)
@@ -411,6 +411,10 @@
>
</File>
<File
+ RelativePath=".\ctl\ctlListItemArranger.cpp"
+ >
+ </File>
+ <File
RelativePath=".\ctl\explainCanvas.cpp"
>
</File>
@@ -439,6 +443,10 @@
>
</File>
<File
+ RelativePath=".\ctl\xh_ctlListArranger.cpp"
+ >
+ </File>
+ <File
RelativePath=".\ctl\xh_sqlbox.cpp"
>
</File>
@@ -938,6 +946,10 @@
>
</File>
<File
+ RelativePath=".\include\ctl\ctlListItemArranger.h"
+ >
+ </File>
+ <File
RelativePath=".\include\ctl\explainCanvas.h"
>
</File>
@@ -966,6 +978,10 @@
>
</File>
<File
+ RelativePath=".\include\ctl\xh_ctlListArranger.h"
+ >
+ </File>
+ <File
RelativePath=".\include\ctl\xh_sqlbox.h"
>
</File>
Index: dlg/dlgType.cpp
===================================================================
--- dlg/dlgType.cpp (revision 7500)
+++ dlg/dlgType.cpp (working copy)
@@ -21,6 +21,7 @@
#include "schema/pgSchema.h"
#include "schema/pgType.h"
#include "schema/pgDatatype.h"
+#include "ctl/ctlListItemArranger.h"
// pointer to controls
@@ -40,7 +41,7 @@
#define chkByValue CTRL_CHECKBOX("chkByValue")
#define cbAlignment CTRL_COMBOBOX("cbAlignment")
#define cbStorage CTRL_COMBOBOX("cbStorage")
-#define lstMembers CTRL_LISTVIEW("lstMembers")
+#define lstMembers CTRL_LISTARRANGER("lstMembers")
#define txtMembername CTRL_TEXT("txtMembername")
#define lstLabels CTRL_LISTVIEW("lstLabels")
#define txtLabel CTRL_TEXT("txtLabel")
@@ -182,15 +183,18 @@
wxArrayString elements=type->GetTypesArray();
size_t i;
- for (i=0 ; i < elements.GetCount() ; i+=2)
+ for (i=0 ; i < elements.GetCount() ; i+=2)
lstMembers->AppendItem(0, elements.Item(i), elements.Item(i+1));
+ // disable order re-arranging when a type exists
+ //lstMembers->setEnable(false);
+
cbDatatype->Disable();
txtLength->Disable();
// Load the enum labels
elements=type->GetLabelArray();
- for (i=0 ; i < elements.GetCount() ; i++)
+ for (i=0 ; i < elements.GetCount() ; i++)
lstLabels->AppendItem(0, elements.Item(i));
if (!connection->BackendMinimumVersion(7, 5))
Index: ui/dlgType.xrc
===================================================================
--- ui/dlgType.xrc (revision 7500)
+++ ui/dlgType.xrc (working copy)
@@ -136,8 +136,7 @@
<growablecols>0</growablecols>
<growablerows>0</growablerows>
<object class="sizeritem">
- <object class="wxListCtrl" name="lstMembers">
- <style>wxLC_REPORT|wxLC_SINGLE_SEL</style>
+ <object class="ctlListArranger" name="lstMembers">
</object>
<flag>wxEXPAND|wxALIGN_CENTRE_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
<border>4</border>
Index: pgAdmin3.cpp
===================================================================
--- pgAdmin3.cpp (revision 7500)
+++ pgAdmin3.cpp (working copy)
@@ -64,6 +64,7 @@
#include "ctl/xh_sqlbox.h"
#include "ctl/xh_ctlcombo.h"
#include "ctl/xh_ctltree.h"
+#include "ctl/xh_ctlListArranger.h"
#define DOC_DIR wxT("/docs")
#define UI_DIR wxT("/ui")
@@ -369,6 +370,7 @@
wxXmlResource::Get()->AddHandler(new wxTimeSpinXmlHandler);
wxXmlResource::Get()->AddHandler(new ctlSQLBoxXmlHandler);
wxXmlResource::Get()->AddHandler(new ctlComboBoxXmlHandler);
+ wxXmlResource::Get()->AddHandler(new ctlListArrangerXmlHandler);
wxXmlResource::Get()->AddHandler(new ctlTreeXmlHandler);
InitXml();
Index: include/ctl/xh_ctlListArranger.h
===================================================================
--- include/ctl/xh_ctlListArranger.h (revision 0)
+++ include/ctl/xh_ctlListArranger.h (revision 0)
@@ -0,0 +1,31 @@
+//////////////////////////////////////////////////////////////////////////
+//
+// pgAdmin III - PostgreSQL Tools
+// RCS-ID: $id$
+// Copyright (C) 2002 - 2008, The pgAdmin Development Team
+// This software is released under the Artistic Licence
+//
+// xh_ctlListArranger.h - ctlListArranger handler
+//
+//////////////////////////////////////////////////////////////////////////
+
+
+#ifndef _WX_XH_CTLLISTARRANGER_H_
+#define _WX_XH_CTLLISTARRANGER_H_
+
+
+#include "wx/xrc/xmlres.h"
+#include "wx/xrc/xh_panel.h"
+
+//class WXDLLIMPEXP_XRC
+class ctlListArrangerXmlHandler : public wxPanelXmlHandler
+{
+DECLARE_DYNAMIC_CLASS(ctlListArrangerXmlHandler)
+public:
+ ctlListArrangerXmlHandler() : wxPanelXmlHandler() {}
+ virtual wxObject *DoCreateResource();
+ virtual bool CanHandle(wxXmlNode *node);
+};
+
+
+#endif
Index: ctl/ctlListItemArranger.cpp
===================================================================
--- ctl/ctlListItemArranger.cpp (revision 0)
+++ ctl/ctlListItemArranger.cpp (revision 0)
@@ -0,0 +1,380 @@
+//////////////////////////////////////////////////////////////////////////
+//
+// pgAdmin III - PostgreSQL Tools
+// RCS-ID: $id$
+// Copyright (C) 2002 - 2008, The pgAdmin Development Team
+// This software is released under the Artistic Licence
+//
+// ListItemArranger.h - Custom control to help order/arrange list items
+//
+//
+//////////////////////////////////////////////////////////////////////////
+
+
+//Main app header
+#include "pgAdmin3.h"
+
+// wxWindows headers
+#include "wx/wx.h"
+#include <wx/listctrl.h>
+
+// App headers
+#include "ctl/ctlListItemArranger.h"
+#include "images/ctlListItemArrangerUp.xpm"
+#include "images/ctlListItemArrangerDown.xpm"
+#include "images/ctlListItemArrangerFirst.xpm"
+#include "images/ctlListItemArrangerLast.xpm"
+
+// defining the button event IDs
+#define ID_BUTTON_UP 1000
+#define ID_BUTTON_DOWN 1001
+#define ID_BUTTON_FIRST 1002
+#define ID_BUTTON_LAST 1003
+
+// declaring the event table
+BEGIN_EVENT_TABLE(ctlListItemArranger,wxPanel)
+ EVT_BUTTON(ID_BUTTON_UP,ctlListItemArranger::OnButtonUp)
+ EVT_BUTTON(ID_BUTTON_DOWN,ctlListItemArranger::OnButtonDown)
+ EVT_BUTTON(ID_BUTTON_FIRST,ctlListItemArranger::OnButtonFirst)
+ EVT_BUTTON(ID_BUTTON_LAST,ctlListItemArranger::OnButtonLast)
+ EVT_SIZE( ctlListItemArranger::OnSize)
+#ifdef __WXMSW__
+ EVT_ERASE_BACKGROUND(ctlListItemArranger::OnErase)
+#endif
+END_EVENT_TABLE()
+
+IMPLEMENT_DYNAMIC_CLASS(ctlListItemArranger,wxPanel)
+
+#ifdef __WXMSW__
+// Background paint hack for windows theme.
+// Here we make a gradient fill based on two pixels (0,y1,0,y2)
+// from the parent where this wxPanel sits. This way we emulate a
+// background transparenct.
+void ctlListItemArranger::OnErase(wxEraseEvent& event)
+{
+ wxColor c1,c2;
+ wxPoint p1,p2;
+ wxClientDC* parentDC = NULL;
+
+ wxClientDC* clientDC = NULL;
+ if (!event.GetDC())
+ clientDC = new wxClientDC(this);
+ wxDC* dc = clientDC ? clientDC : event.GetDC();
+
+ parentDC = new wxClientDC(this->GetParent());
+ p1 = dc->GetWindow()->GetPosition();
+ parentDC->GetPixel(p1.x,p1.y,&c1);
+ p2.x = p1.x;
+ p2.y = p1.y + this->GetSize().y;
+ parentDC->GetPixel(p2.x,p2.y,&c2);
+
+ wxRect clientRect = GetClientRect();
+ wxRect gradientRect = clientRect;
+
+ dc->GradientFillLinear(gradientRect,c1, c2, wxSOUTH);
+ dc->SetPen(wxPen(GetBackgroundColour()));
+ dc->SetBrush(*wxTRANSPARENT_BRUSH);
+ dc->DrawRectangle(-1, -1, clientRect.GetWidth()+2, clientRect.GetHeight()+2);
+
+ if (clientDC)
+ delete clientDC;
+
+ delete parentDC;
+}
+#endif
+
+ctlListItemArranger::ctlListItemArranger(wxWindow *parent,
+ wxWindowID id, wxPoint pos, wxSize siz, long attr) : wxPanel(parent,id,wxDefaultPosition,wxDefaultSize,wxNO_BORDER | wxTAB_TRAVERSAL)
+{
+ Init();
+ Initialize();
+}
+
+void ctlListItemArranger::Initialize()
+{
+ this->button_state = true;
+
+ wxFlexGridSizer* bodySizer = new wxFlexGridSizer(1, 2, 0, 0);
+ bodySizer->AddGrowableCol(0);
+
+ this->listControl = new ctlListView(this, wxID_ANY, wxPoint(0,0), wxDefaultSize, wxLC_REPORT|wxLC_SINGLE_SEL);
+ // attach list event and disable button. then button get enabled when an
+ // item is selected on the list.
+ AttachListControlEvents();
+
+ bodySizer->Add(listControl,0,wxALL,2);
+
+ // creating a sizer for buttons
+ vboxSizer = new wxBoxSizer(wxVERTICAL);
+
+ CreateButtonImages();
+ CreateButtonControls();
+
+ bodySizer->Add(vboxSizer);
+
+ // adding the sizer to this wxPanel
+ this->SetSizer(bodySizer);
+
+}
+
+void ctlListItemArranger::setEnable(bool state)
+{
+ this->button_state = state;
+}
+
+bool ctlListItemArranger::getEnable()
+{
+ return this->button_state;
+}
+
+
+void ctlListItemArranger::OnListItemActivity(wxListEvent &event)
+{
+ // we set the button state when an item is selected on the
+ // listbox
+ ValidateState();
+
+ event.Skip();
+}
+
+void ctlListItemArranger::AttachListControlEvents()
+{
+ // item selected event
+ this->listControl->Connect(
+ this->listControl->GetId(),
+ wxEVT_COMMAND_LIST_ITEM_SELECTED,
+ wxListEventHandler(ctlListItemArranger::OnListItemActivity),0,this);
+
+ // item selected event
+ this->listControl->Connect(
+ this->listControl->GetId(),
+ wxEVT_COMMAND_LIST_ITEM_ACTIVATED,
+ wxListEventHandler(ctlListItemArranger::OnListItemActivity),0,this);
+
+
+ // item insert
+ this->listControl->Connect(
+ this->listControl->GetId(),
+ wxEVT_COMMAND_LIST_INSERT_ITEM,
+ wxListEventHandler(ctlListItemArranger::OnListItemActivity),0,this);
+
+ // item delete
+ this->listControl->Connect(
+ this->listControl->GetId(),
+ wxEVT_COMMAND_LIST_DELETE_ITEM,
+ wxListEventHandler(ctlListItemArranger::OnListItemActivity),0,this);
+
+ // item delete all
+ this->listControl->Connect(
+ this->listControl->GetId(),
+ wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS,
+ wxListEventHandler(ctlListItemArranger::OnListItemActivity),0,this);
+
+}
+
+void ctlListItemArranger::CreateButtonControls(void)
+{
+ // creating buttons
+ buttonUp = new wxBitmapButton( this, ID_BUTTON_UP, upBitmap, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW, wxDefaultValidator, wxT("Column(s) Up") );
+ buttonDown = new wxBitmapButton( this, ID_BUTTON_DOWN, downBitmap, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW, wxDefaultValidator, wxT("Column(s) Down") );
+ buttonFirst = new wxBitmapButton( this, ID_BUTTON_FIRST, firstBitmap, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW, wxDefaultValidator, wxT("Column(s) up first") );
+ buttonLast = new wxBitmapButton( this, ID_BUTTON_LAST, lastBitmap, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW, wxDefaultValidator, wxT("Column(s) down last") );
+
+ // adding the buttons
+ this->vboxSizer->Add(buttonFirst,0,wxALL,3);
+ this->vboxSizer->Add(buttonUp,0,wxALL,3);
+ this->vboxSizer->Add(buttonDown,0,wxALL,3);
+ this->vboxSizer->Add(buttonLast,0,wxALL,3);
+
+ this->ValidateState();
+}
+
+void ctlListItemArranger::CreateButtonImages(void)
+{
+ // creating button images
+ upBitmap = wxBitmap(ctlListItemArranger_Up_xpm);
+ downBitmap = wxBitmap(ctlListItemArranger_Down_xpm);
+ firstBitmap = wxBitmap(ctlListItemArranger_First_xpm);
+ lastBitmap = wxBitmap(ctlListItemArranger_Last_xpm);
+}
+
+void ctlListItemArranger::ValidateState(void)
+{
+ int icount = 0,sel=-1;
+ if(this->listControl)
+ icount = this->listControl->GetItemCount();
+
+ // handle only when one item is selected
+ if(this->listControl->GetSelectedItemCount() != 1)
+ {
+ this->SetButtonStateAll(false);
+ return;
+ }
+
+ // disable all when single item
+ if(icount <= 1)
+ this->SetButtonStateAll(false);
+
+ // when two items enable up and down
+ if(icount == 2)
+ {
+ this->SetButtonStateAll(false);
+ SetButtonState(ID_BUTTON_UP,true);
+ SetButtonState(ID_BUTTON_DOWN,true);
+ }
+
+ // when more than two items enable all
+ if(icount >= 3)
+ {
+ this->SetButtonStateAll(true);
+ }
+
+ // set the buttons based on selection
+ sel = this->GetSelection();
+ if(sel != -1)
+ {
+ if(sel == 0)
+ {
+ SetButtonState(ID_BUTTON_UP,false);
+ SetButtonState(ID_BUTTON_FIRST,false);
+ }
+
+ if(sel == this->listControl->GetItemCount()-1)
+ {
+ SetButtonState(ID_BUTTON_DOWN,false);
+ SetButtonState(ID_BUTTON_LAST,false);
+ }
+ }
+}
+
+void ctlListItemArranger::SetButtonState(wxWindowID id,bool state)
+{
+ switch(id)
+ {
+ case ID_BUTTON_UP:
+ this->buttonUp->Enable(state);
+ this->buttonFirst->Enable(state);
+ break;
+
+ case ID_BUTTON_DOWN:
+ this->buttonDown->Enable(state);
+ this->buttonLast->Enable(state);
+ break;
+ }
+}
+
+void ctlListItemArranger::SetButtonStateAll(bool state)
+{
+ if(this->button_state == false)
+ state = false;
+
+ this->buttonUp->Enable(state);
+ this->buttonDown->Enable(state);
+ this->buttonFirst->Enable(state);
+ this->buttonLast->Enable(state);
+}
+
+// -1 is one up
+// +1 is one down
+// 0 is set first
+// -2 is set last
+void ctlListItemArranger::MoveCurrentItemBy(int position)
+{
+ wxListItem curItem,tmpItem;
+ wxArrayString iarray;
+
+ long colcnt;
+ int ItemIndex = this->GetSelection();
+
+ // paranoid check
+ if(ItemIndex >= 0)
+ {
+ // copy item into memory
+ curItem.SetId(ItemIndex);
+ curItem.SetMask(wxLIST_MASK_DATA | wxLIST_MASK_FORMAT | wxLIST_MASK_IMAGE | wxLIST_MASK_STATE | wxLIST_MASK_TEXT | wxLIST_MASK_WIDTH);
+ curItem.SetColumn(0);
+ this->listControl->GetItem(curItem);
+
+ // copy remaining columns. text and with only
+ colcnt = this->listControl->GetColumnCount();
+
+ // copy from the second column if possible
+ if(colcnt > 1)
+ {
+ for(int a = 1; a < colcnt; a++)
+ {
+ tmpItem.SetId(ItemIndex);
+ tmpItem.SetMask(wxLIST_MASK_DATA | wxLIST_MASK_FORMAT | wxLIST_MASK_IMAGE | wxLIST_MASK_STATE | wxLIST_MASK_TEXT | wxLIST_MASK_WIDTH);
+ tmpItem.SetColumn(a);
+ this->listControl->GetItem(tmpItem);
+ iarray.Add(tmpItem.GetText());
+ }
+ }
+
+ // remove the item
+ this->listControl->DeleteItem(ItemIndex);
+
+ if(position == 0)
+ ItemIndex = 0;
+ else if(position == -2)
+ ItemIndex = this->listControl->GetItemCount();
+ else
+ ItemIndex += position;
+
+ // insert the new positiond item and select it
+ curItem.SetId(ItemIndex);
+ curItem.SetColumn(0);
+ this->listControl->InsertItem(curItem);
+
+ for(int a = 0; a < (int)iarray.Count(); a++)
+ {
+ this->listControl->SetItem(ItemIndex,(a+1),iarray.Item(a));
+ }
+
+ this->listControl->SetItemState(ItemIndex, wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED,
+ wxLIST_STATE_SELECTED | wxLIST_STATE_FOCUSED);
+
+ ValidateState();
+ }
+
+ // set the focus back to the list selected item
+ this->listControl->SetFocus();
+}
+
+
+long ctlListItemArranger::GetSelection()
+{
+ if(this->listControl)
+ return this->listControl->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
+ else
+ return -1;
+}
+
+void ctlListItemArranger::OnButtonUp(wxCommandEvent &event)
+{
+ MoveCurrentItemBy(-1);
+}
+
+
+void ctlListItemArranger::OnButtonDown(wxCommandEvent &event)
+{
+ MoveCurrentItemBy(1);
+}
+
+void ctlListItemArranger::OnButtonFirst(wxCommandEvent &event)
+{
+ MoveCurrentItemBy(0);
+}
+
+void ctlListItemArranger::OnButtonLast(wxCommandEvent &event)
+{
+ MoveCurrentItemBy(-2);
+}
+
+void ctlListItemArranger::OnSize(wxSizeEvent& event)
+{
+ wxPanel::OnSize(event);
+ wxSize panelSize = this->GetSize();
+ this->listControl->SetMinSize(wxSize(panelSize.GetWidth() - 30, panelSize.GetHeight() - 5));
+}
+
Index: include/ctl/ctlListItemArranger.h
===================================================================
--- include/ctl/ctlListItemArranger.h (revision 0)
+++ include/ctl/ctlListItemArranger.h (revision 0)
@@ -0,0 +1,68 @@
+//////////////////////////////////////////////////////////////////////////
+//
+// pgAdmin III - PostgreSQL Tools
+// RCS-ID: $id$
+// Copyright (C) 2002 - 2008, The pgAdmin Development Team
+// This software is released under the Artistic Licence
+//
+// ListItemArranger.h - Custom control to help order/arrange list items
+//
+//
+//////////////////////////////////////////////////////////////////////////
+
+#ifndef _WX_LIST_ITEM_ARRANGER_H_
+#define _WX_LIST_ITEM_ARRANGER_H_
+
+// wxWindows headers
+#include <wx/listctrl.h>
+
+// Application headers
+#include "ctl/ctlListView.h"
+
+class ctlListItemArranger : public wxPanel
+{
+public:
+ ctlListItemArranger() { Init(); listControl = NULL; }
+ ctlListItemArranger(wxWindow *parent,
+ wxWindowID id, wxPoint pos, wxSize siz, long attr=0);
+ virtual void Initialize();
+ void OnButtonUp(wxCommandEvent& event);
+ void OnButtonDown(wxCommandEvent& event);
+ void OnButtonFirst(wxCommandEvent& event);
+ void OnButtonLast(wxCommandEvent& event);
+ void OnListItemActivity(wxListEvent& event);
+ void OnSize(wxSizeEvent& event);
+ void setEnable(bool state);
+ bool getEnable();
+ long GetSelection();
+#if __WXMSW__
+ void OnErase(wxEraseEvent& event);
+#endif
+ void ValidateState(void);
+
+ ctlListView *GetList()
+ {
+ return this->listControl;
+ }
+
+private:
+ wxBitmap upBitmap, downBitmap, firstBitmap, lastBitmap;
+ wxBitmapButton *buttonUp, *buttonDown, *buttonFirst, *buttonLast;
+ wxBoxSizer *hboxSizer, *vboxSizer;
+ ctlListView *listControl;
+
+ void CreateButtonImages(void);
+ void CreateButtonControls(void);
+ void SetButtonState(wxWindowID id,bool state);
+ void AttachListControlEvents(void);
+ void MoveCurrentItemBy(int position);
+ void SetButtonStateAll(bool state);
+ bool button_state;
+
+ DECLARE_DYNAMIC_CLASS(ctlListItemArranger)
+ DECLARE_EVENT_TABLE()
+ DECLARE_NO_COPY_CLASS(ctlListItemArranger)
+
+};
+
+#endif
--
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers