+/////////////////////////////////////////////////////////////////////////////
+// Name: extdlgg.cpp
+// Purpose: extended generic dialog
+// Author: Robert Roebling
+// Modified by:
+// Created: 04/01/98
+// RCS-ID: $Id$
+// Copyright: (c) Robert Roebling
+// Licence: wxWindows license
+/////////////////////////////////////////////////////////////////////////////
+
+#ifdef __GNUG__
+#pragma implementation "extdlgg.h"
+#endif
+
+// For compilers that support precompilation, includes "wx.h".
+#include "wx/wxprec.h"
+
+#ifdef __BORLANDC__
+#pragma hdrstop
+#endif
+
+#ifndef WX_PRECOMP
+#include <stdio.h>
+#include "wx/intl.h"
+#include "wx/dialog.h"
+#include "wx/button.h"
+#endif
+
+#if wxUSE_STATLINE
+#include "wx/statline.h"
+#endif
+
+#include "wx/generic/extdlgg.h"
+
+//-----------------------------------------------------------------------------
+// wxExtDialog
+//-----------------------------------------------------------------------------
+
+#define STATIC_LINE_MARGIN 15
+#define CLIENT_AREA_MARGIN 10
+#define BUTTON_AREA_MARGIN 10
+
+#if !USE_SHARED_LIBRARY
+IMPLEMENT_DYNAMIC_CLASS(wxExtDialog, wxDialog)
+
+BEGIN_EVENT_TABLE(wxExtDialog, wxDialog)
+ EVT_SIZE(wxExtDialog::OnSize)
+ EVT_BUTTON(wxID_YES, wxExtDialog::OnYes)
+ EVT_BUTTON(wxID_NO, wxExtDialog::OnNo)
+ EVT_BUTTON(wxID_CANCEL, wxExtDialog::OnCancel)
+END_EVENT_TABLE()
+#endif
+
+wxExtDialog::wxExtDialog( wxWindow *parent, wxWindowID id,
+ const wxString& title, long extraStyle,
+ const wxPoint& pos, const wxSize& size,
+ long style, const wxString &name )
+{
+ Create( parent, id, title, extraStyle, pos, size, style, name );
+}
+
+bool wxExtDialog::Create( wxWindow *parent, wxWindowID id,
+ const wxString& title, long extraStyle,
+ const wxPoint& pos, const wxSize& size,
+ long style, const wxString &name )
+{
+ if (!wxDialog::Create( parent, id, title, pos, size, style, name ))
+ return FALSE;
+
+ m_extraStyle = extraStyle;
+
+ wxButton *ok = (wxButton *) NULL;
+ wxButton *cancel = (wxButton *) NULL;
+ wxButton *yes = (wxButton *) NULL;
+ wxButton *no = (wxButton *) NULL;
+
+
+ if (m_extraStyle & wxYES_NO)
+ {
+ yes = new wxButton( this, wxID_YES, _("Yes") );
+ m_buttons.Append( yes );
+ no = new wxButton( this, wxID_NO, _("No") );
+ m_buttons.Append( no );
+ }
+
+ if (m_extraStyle & wxYES)
+ {
+ yes = new wxButton( this, wxID_YES, _("Yes") );
+ m_buttons.Append( yes );
+ }
+
+ if (m_extraStyle & wxNO)
+ {
+ no = new wxButton( this, wxID_NO, _("No") );
+ m_buttons.Append( no );
+ }
+
+ if (m_extraStyle & wxOK)
+ {
+ ok = new wxButton( this, wxID_OK, _("OK") );
+ m_buttons.Append( ok );
+ }
+
+ if (m_extraStyle & wxFORWARD)
+ AddButton( new wxButton( this, wxID_FORWARD, _("Forward") ) );
+
+ if (m_extraStyle & wxBACKWARD)
+ AddButton( new wxButton( this, wxID_BACKWARD, _("Backward") ) );
+
+ if (m_extraStyle & wxSETUP)
+ AddButton( new wxButton( this, wxID_SETUP, _("Setup") ) );
+
+ if (m_extraStyle & wxMORE)
+ AddButton( new wxButton( this, wxID_MORE, _("More..") ) );
+
+ if (m_extraStyle & wxCANCEL)
+ {
+ cancel = new wxButton( this, wxID_CANCEL, _("Cancel") );
+ m_buttons.Append( cancel );
+ }
+
+ if ((m_extraStyle & wxNO_DEFAULT) == 0)
+ {
+ if (ok)
+ {
+ ok->SetDefault();
+ ok->SetFocus();
+ }
+ else if (yes)
+ {
+ yes->SetDefault();
+ yes->SetFocus();
+ }
+ }
+
+#if wxUSE_STATLINE
+ if (style & wxED_STATIC_LINE)
+ {
+ int line_style = wxLI_HORIZONTAL;
+ if (style & wxED_BUTTONS_RIGHT) line_style = wxLI_VERTICAL;
+
+ m_statLine = new wxStaticLine( this, -1, wxDefaultPosition, wxDefaultSize, line_style );
+ }
+ else
+ m_statLine = (wxStaticLine*) NULL;
+#endif
+
+ if (m_extraStyle & wxCENTRE)
+ Centre( wxBOTH );
+
+ return TRUE;
+}
+
+void wxExtDialog::AddButton( wxButton *button )
+{
+ m_buttons.Append( button );
+}
+
+void wxExtDialog::SetDefaultButton( wxWindowID button )
+{
+ wxNode *node = m_buttons.First();
+ while (node)
+ {
+ wxButton *but = (wxButton*) node->Data();
+ if (but->GetId() == button)
+ {
+ but->SetDefault();
+ but->SetFocus();
+ return;
+ }
+ }
+}
+
+void wxExtDialog::EnableButton( wxWindowID button, bool enable )
+{
+ wxNode *node = m_buttons.First();
+ while (node)
+ {
+ wxButton *but = (wxButton*) node->Data();
+ if (but->GetId() == button)
+ {
+ but->Enable(enable);
+ return;
+ }
+ }
+}
+
+bool wxExtDialog::ButtonIsEnabled( wxWindowID button )
+{
+ wxNode *node = m_buttons.First();
+ while (node)
+ {
+ wxButton *but = (wxButton*) node->Data();
+ if (but->GetId() == button)
+ return but->IsEnabled();
+ }
+ return FALSE;
+}
+
+void wxExtDialog::OnSize( wxSizeEvent &WXUNUSED(event) )
+{
+ wxSize client_size( GetClientSize() );
+ wxSize button_area( LayoutButtons() );
+
+ if (HasFlag(wxED_BUTTONS_RIGHT))
+ client_size.x -= button_area.x;
+ else
+ client_size.y -= button_area.y;
+
+ if (m_clientWindow)
+ {
+ if (m_windowStyle & wxED_CLIENT_MARGIN)
+ m_clientWindow->SetSize( CLIENT_AREA_MARGIN,
+ CLIENT_AREA_MARGIN,
+ client_size.x - 2*CLIENT_AREA_MARGIN,
+ client_size.y - 2*CLIENT_AREA_MARGIN );
+ else
+ m_clientWindow->SetSize( 0, 0, client_size.x, client_size.y );
+
+ if (m_clientWindow->GetAutoLayout())
+ m_clientWindow->Layout();
+ }
+}
+
+void wxExtDialog::OnYes(wxCommandEvent& event)
+{
+ EndModal( wxID_YES );
+}
+
+void wxExtDialog::OnNo(wxCommandEvent& event)
+{
+ EndModal( wxID_NO );
+}
+
+void wxExtDialog::OnCancel(wxCommandEvent& event)
+{
+ /* allow cancellation via ESC/Close button except if
+ only YES and NO are specified. */
+ if ((m_extraStyle & wxYES_NO) != wxYES_NO || (m_extraStyle & wxCANCEL))
+ {
+ EndModal( wxID_CANCEL );
+ }
+}
+
+wxSize wxExtDialog::GetButtonAreaSize()
+{
+ if (m_buttons.GetCount() == 0) return wxSize(0,0);
+
+ wxSize ret(0,0);
+
+ // this routine can be improved to measure the string length
+ // of the button text or the bitmap size if using wxBmpButton
+ // or to query the standard button size somehow.
+
+ int button_size_and_margin_x = 110;
+ int button_size_and_margin_y = 44;
+
+ if (m_windowStyle & wxED_BUTTONS_RIGHT)
+ {
+ ret.x = button_size_and_margin_x;
+ ret.y = m_buttons.GetCount()*button_size_and_margin_y + 2*BUTTON_AREA_MARGIN;
+#if wxUSE_STATLINE
+ if (m_statLine)
+ ret.x += STATIC_LINE_MARGIN;
+#endif
+ }
+ else
+ {
+ ret.x = m_buttons.GetCount()*button_size_and_margin_x + 2*BUTTON_AREA_MARGIN;
+ ret.y = button_size_and_margin_y;
+#if wxUSE_STATLINE
+ if (m_statLine)
+ ret.y += STATIC_LINE_MARGIN;
+#endif
+ }
+
+ return ret;
+}
+
+wxSize wxExtDialog::LayoutButtons()
+{
+ if (m_buttons.GetCount() == 0) return wxSize(0,0);
+
+ wxSize area_used( GetButtonAreaSize() );
+ wxSize client_area( GetClientSize() );
+
+ if (m_windowStyle & wxED_BUTTONS_RIGHT)
+ {
+ area_used.y = client_area.y;
+
+ int space_for_each_button = (client_area.y-2*BUTTON_AREA_MARGIN) / m_buttons.GetCount();
+ int n = 0;
+ wxNode *node = m_buttons.First();
+ while (node)
+ {
+ wxButton *button = (wxButton*)node->Data();
+
+ wxSize button_size( button->GetSize() );
+ if (button_size.x < 80) button_size.x = 80;
+
+ int center_of_button_y = n*space_for_each_button + space_for_each_button/2;
+ int button_y = BUTTON_AREA_MARGIN + center_of_button_y - button_size.y/2;
+
+ int center_of_button_x = client_area.x - area_used.x/2;
+ int button_x = center_of_button_x - button_size.x/2;
+
+ button->SetSize( button_x, button_y, button_size.x, button_size.y );
+
+ node = node->Next();
+ n++;
+ }
+
+#if wxUSE_STATLINE
+ if (m_statLine)
+ m_statLine->SetSize( client_area.x - area_used.x,
+ 0,
+ wxStaticLine::GetDefaultSize(),
+ client_area.y );
+#endif
+ }
+ else
+ {
+ area_used.x = client_area.x;
+
+ int space_for_each_button = (client_area.x-2*BUTTON_AREA_MARGIN) / m_buttons.GetCount();
+ int n = 0;
+ wxNode *node = m_buttons.First();
+ while (node)
+ {
+ wxButton *button = (wxButton*)node->Data();
+
+ wxSize button_size( button->GetSize() );
+ if (button_size.x < 80) button_size.x = 80;
+
+ int center_of_button_x = n*space_for_each_button + space_for_each_button/2;
+ int button_x = BUTTON_AREA_MARGIN + center_of_button_x - button_size.x/2;
+
+ int center_of_button_y = client_area.y - area_used.y/2;
+ int button_y = center_of_button_y - button_size.y/2;
+
+ button->SetSize( button_x, button_y, button_size.x, button_size.y );
+
+ node = node->Next();
+ n++;
+ }
+
+#if wxUSE_STATLINE
+ if (m_statLine)
+ m_statLine->SetSize( 0,
+ client_area.y - area_used.y,
+ client_area.x,
+ wxStaticLine::GetDefaultSize() );
+#endif
+ }
+
+ return area_used;
+}
+
+