1 //////////////////////////////////////////////////////////////////////////
2 //
3 // pgAdmin III - PostgreSQL Tools
4 //
5 // Copyright (C) 2002 - 2016, The pgAdmin Development Team
6 // This software is released under the PostgreSQL Licence
7 //
8 // hdRemoveDeleteDialog.cpp - Utility dialog class to allow user to select between delete / remove a figure
9 //
10 //////////////////////////////////////////////////////////////////////////
11
12 #include "pgAdmin3.h"
13
14 // wxWindows headers
15 #include <wx/wx.h>
16 #include <wx/statline.h>
17
18 // App headers
19 #include "hotdraw/utilities/hdRemoveDeleteDialog.h"
20
IMPLEMENT_CLASS(hdRemoveDeleteDialog,wxDialog)21 IMPLEMENT_CLASS( hdRemoveDeleteDialog, wxDialog )
22
23 BEGIN_EVENT_TABLE(hdRemoveDeleteDialog, wxDialog)
24 EVT_BUTTON(DD_REMOVE, hdRemoveDeleteDialog::OnRemove)
25 EVT_BUTTON(DD_DELETE, hdRemoveDeleteDialog::OnDelete)
26 EVT_BUTTON(wxID_CANCEL, hdRemoveDeleteDialog::OnCancel)
27 END_EVENT_TABLE()
28
29 hdRemoveDeleteDialog::hdRemoveDeleteDialog( const wxString &message,
30 const wxString &caption,
31 wxWindow *parent, bool allowRemove
32 )
33 {
34 allowRemoveButton = allowRemove;
35 SetFont(settings->GetSystemFont());
36 Init();
37 Create(parent, wxID_ANY, message, caption);
38 cancelButton->SetFocus();
39 }
40
~hdRemoveDeleteDialog()41 hdRemoveDeleteDialog::~hdRemoveDeleteDialog()
42 {
43 if(staticText)
44 delete staticText;
45 if(staticText2)
46 delete staticText2;
47 if(staticText3)
48 delete staticText3;
49 if(line)
50 delete line;
51 if(removeButton)
52 delete removeButton;
53 if(deleteButton)
54 delete deleteButton;
55 if(cancelButton)
56 delete cancelButton;
57 }
58
hdRemoveDeleteDialog()59 hdRemoveDeleteDialog::hdRemoveDeleteDialog()
60 {
61 Init();
62 }
63
64
Init()65 void hdRemoveDeleteDialog::Init( )
66 {
67 }
68
69 // Creation
Create(wxWindow * parent,wxWindowID id,const wxString & caption,const wxString & message)70 bool hdRemoveDeleteDialog::Create( wxWindow *parent,
71 wxWindowID id,
72 const wxString &caption,
73 const wxString &message
74 )
75 {
76 SetFont(settings->GetSystemFont());
77
78 if (!wxDialog::Create( parent, id, message, wxDefaultPosition, wxDefaultSize, wxCAPTION))
79 return false;
80
81 CreateControls(caption);
82
83 // This fits the dialog to the minimum size dictated by
84 // the sizers
85 GetSizer()->Fit(this);
86
87 // This ensures that the dialog cannot be sized smaller
88 // than the minimum size
89 GetSizer()->SetSizeHints(this);
90
91 // Centre the dialog on the parent or (if none) screen
92
93 Centre();
94
95 return true;
96 }
97
98
99 // Creates the controls and sizers
CreateControls(const wxString & message)100 void hdRemoveDeleteDialog::CreateControls(const wxString &message)
101 {
102 // A top-level sizer
103 topSizer = new wxBoxSizer(wxVERTICAL );
104 this->SetSizer(topSizer);
105 topSizer->AddSpacer(10);
106 //Message Sizer
107 messageSizer = new wxBoxSizer(wxHORIZONTAL );
108 topSizer->Add(messageSizer);
109 messageSizer->AddSpacer(25);
110
111 staticText = new wxStaticText(this, wxID_STATIC, message, wxDefaultPosition, wxDefaultSize, wxALIGN_CENTER);
112 messageSizer->Add(staticText, 0, wxALIGN_CENTER, 5);
113
114 messageSizer->AddSpacer(45);
115
116 // Add important user info
117 wxString info = _(" Choose Remove from Diagram to remove only from current diagram. ");
118 wxString info2 = _(" Choose Remove from Model to delete permanently. ");
119
120 this->SetForegroundColour(wxColour(wxT("GREY")));
121 staticText2 = new wxStaticText(this, wxID_STATIC, info, wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);
122 topSizer->Add(staticText2, 0, wxALIGN_LEFT, 5);
123
124 staticText3 = new wxStaticText(this, wxID_STATIC, info2, wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);
125 topSizer->Add(staticText3, 0, wxALIGN_LEFT, 5);
126
127 // A space and a dividing line before the Remove Delete and Cancel buttons
128 topSizer->AddSpacer(10);
129 line = new wxStaticLine ( this, wxID_STATIC,
130 wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
131 topSizer->Add(line, 0, wxGROW | wxALL, 5);
132
133 //Buttons Sizer
134 buttonsSizer = new wxBoxSizer(wxHORIZONTAL );
135
136 topSizer->Add(buttonsSizer, 0, wxALIGN_CENTER, 5);
137
138 removeButton = new wxButton ( this, DD_REMOVE, wxT("&Remove from Diagram"),
139 wxDefaultPosition, wxDefaultSize, 0 );
140
141 if(!allowRemoveButton)
142 removeButton->Enable(false);
143
144 buttonsSizer->Add(removeButton, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
145
146 deleteButton = new wxButton ( this, DD_DELETE, wxT("&Remove from Model"),
147 wxDefaultPosition, wxDefaultSize, 0 );
148 buttonsSizer->Add(deleteButton, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
149
150 cancelButton = new wxButton ( this, wxID_CANCEL, wxT("&Cancel"),
151 wxDefaultPosition, wxDefaultSize, 0 );
152 buttonsSizer->Add(cancelButton, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
153 topSizer->AddSpacer(10);
154 }
155
OnRemove(wxCommandEvent & WXUNUSED (event))156 void hdRemoveDeleteDialog::OnRemove(wxCommandEvent &WXUNUSED(event))
157 {
158 EndModal( DD_REMOVE );
159 }
160
OnDelete(wxCommandEvent & WXUNUSED (event))161 void hdRemoveDeleteDialog::OnDelete(wxCommandEvent &WXUNUSED(event))
162 {
163 EndModal( DD_DELETE );
164 }
165
OnCancel(wxCommandEvent & WXUNUSED (event))166 void hdRemoveDeleteDialog::OnCancel(wxCommandEvent &WXUNUSED(event))
167 {
168 EndModal( wxID_CANCEL );
169 }
170