Index: ctl/ctlListItemArranger.cpp =================================================================== --- ctl/ctlListItemArranger.cpp (revision 0) +++ ctl/ctlListItemArranger.cpp (revision 0) @@ -0,0 +1,361 @@ +////////////////////////////////////////////////////////////////////////// +// +// 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 + +// 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) +#if __WXMSW__ + EVT_ERASE_BACKGROUND(ctlListItemArranger::OnErase) +#endif +END_EVENT_TABLE() + +IMPLEMENT_DYNAMIC_CLASS(ctlListItemArranger,wxPanel) + +#if __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,wxListCtrl *listControl) : wxPanel(parent,id,wxDefaultPosition,wxDefaultSize,wxNO_BORDER | wxTAB_TRAVERSAL) +{ + Init(); + + this->button_state = true; + + this->listControl = listControl; + // attach list event and disable button. then button get enabled when an + // item is selected on the list. + AttachListControlEvents(); + + // creating a sizer for buttons + boxSizer = new wxBoxSizer(wxVERTICAL); + + CreateButtonImages(); + CreateButtonControls(); + + // adding the sizer to this wxPanel + this->SetSizer(boxSizer); + +} + +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->boxSizer->Add(buttonFirst,0,wxALL,3); + this->boxSizer->Add(buttonUp,0,wxALL,3); + this->boxSizer->Add(buttonDown,0,wxALL,3); + this->boxSizer->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); +} + Index: ctl/module.mk =================================================================== --- ctl/module.mk (revision 7491) +++ ctl/module.mk (working copy) @@ -26,7 +26,8 @@ $(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/ctlListItemArranger.cpp EXTRA_DIST += \ $(srcdir)/ctl/module.mk Index: dlg/dlgType.cpp =================================================================== --- dlg/dlgType.cpp (revision 7491) +++ 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 @@ -91,6 +92,11 @@ lstMembers->CreateColumns(0, _("Member"), _("Data type"), -1); lstLabels->InsertColumn(0, _("Label"), wxLIST_FORMAT_LEFT, GetClientSize().GetWidth()); + // attaching the list arranger to lstMembers + lstMembers_ItemArranger = new ctlListItemArranger(this,wxID_ANY,lstMembers); + bool ok = wxXmlResource::Get()->AttachUnknownControl(wxT("lstMembersArrangerHolder"),lstMembers_ItemArranger); + assert(ok); + wxNotifyEvent event; OnTypeChange(event); } @@ -185,6 +191,9 @@ 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_ItemArranger->setEnable(false); + cbDatatype->Disable(); txtLength->Disable(); @@ -198,6 +207,9 @@ } else { + // enable order re-arranging on new types + lstMembers_ItemArranger->setEnable(true); + // Create mode cbOwner->Append(wxEmptyString); cbOwner->Disable(); Index: include/ctl/ctlListItemArranger.h =================================================================== --- include/ctl/ctlListItemArranger.h (revision 0) +++ include/ctl/ctlListItemArranger.h (revision 0) @@ -0,0 +1,59 @@ +////////////////////////////////////////////////////////////////////////// +// +// 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 + +class ctlListItemArranger : public wxPanel +{ +public: + ctlListItemArranger() { Init(); } + ctlListItemArranger(wxWindow *parent, + wxWindowID id, + wxListCtrl *listControl); + void OnButtonUp(wxCommandEvent& event); + void OnButtonDown(wxCommandEvent& event); + void OnButtonFirst(wxCommandEvent& event); + void OnButtonLast(wxCommandEvent& event); + void OnListItemActivity(wxListEvent& event); + void setEnable(bool state); + bool getEnable(); +#if __WXMSW__ + void OnErase(wxEraseEvent& event); +#endif + void ValidateState(void); +private: + wxBitmap upBitmap, downBitmap, firstBitmap, lastBitmap; + wxBitmapButton *buttonUp, *buttonDown, *buttonFirst, *buttonLast; + wxBoxSizer *boxSizer; + wxListCtrl *listControl; + + void CreateButtonImages(void); + void CreateButtonControls(void); + void SetButtonState(wxWindowID id,bool state); + void AttachListControlEvents(void); + void MoveCurrentItemBy(int position); + void SetButtonStateAll(bool state); + long GetSelection(); + bool button_state; + + + DECLARE_DYNAMIC_CLASS(ctlListItemArranger) + DECLARE_EVENT_TABLE() + DECLARE_NO_COPY_CLASS(ctlListItemArranger) + +}; + +#endif Index: include/ctl/module.mk =================================================================== --- include/ctl/module.mk (revision 7491) +++ include/ctl/module.mk (working copy) @@ -26,7 +26,8 @@ $(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/ctlListItemArranger.h EXTRA_DIST += \ $(srcdir)/include/ctl/module.mk Index: include/dlg/dlgType.h =================================================================== --- include/dlg/dlgType.h (revision 7491) +++ include/dlg/dlgType.h (working copy) @@ -14,6 +14,7 @@ #define __DLG_TYPEPROP #include "dlg/dlgProperty.h" +#include "ctl/ctlListItemArranger.h" class pgType; @@ -47,6 +48,8 @@ wxArrayString memberTypes, memberSizes; + ctlListItemArranger *lstMembers_ItemArranger; + DECLARE_EVENT_TABLE() }; 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", +".+++++++++++.", +"+@#$%&*=-;>,+", +".+')!~{]^/(+.", +" .+_:<[}|1+. ", +" .+23456+. ", +" .+#78+. ", +" .+9+. ", +" .+. "}; 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", +" .+++++++++. ", +" .+. ", +" .+@+. ", +" .+#$%+. ", +" .+&*=-;+. ", +" .+>,')!~{+. ", +" +]#^/(_:<[+ ", +" .+++++++++. "}; 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", +" .+++++++++. ", +" +@#$%&*=-;+ ", +" .+>,')!~{+. ", +" .+]^/(_+. ", +" .+#:<+. ", +" .+[+. ", +" .+. ", +" .+++++++++. "}; 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", +" .+. ", +" .+@+. ", +" .+#$%+. ", +" .+&*=-;+. ", +" .+>,')!~{+. ", +".+]^/(_:<[}+.", +"+|#123456789+", +".+++++++++++."}; Index: include/images/module.mk =================================================================== --- include/images/module.mk (revision 7491) +++ 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: ui/dlgType.xrc =================================================================== --- ui/dlgType.xrc (revision 7491) +++ ui/dlgType.xrc (working copy) @@ -136,9 +136,38 @@ 0 0 - - - + + 2 + 1 + 5 + 0 + 0 + 0 + + wxGROW|wxGROW|wxALL + 0 + + 2 + 1 + 0 + 0 + 0 + 0 + + wxGROW|wxGROW|wxALL + 0 + + + + + + wxALIGN_CENTER_HORIZONTAL + 0 + + + + + wxEXPAND|wxALIGN_CENTRE_VERTICAL|wxTOP|wxLEFT|wxRIGHT 4