From: Stefan Csomor Date: Wed, 10 Nov 1999 11:32:00 +0000 (+0000) Subject: wxMac (debug) builds and runs wxMinimal again X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/51abe921b849be69f02c174365c9a7bc8b46bd08 wxMac (debug) builds and runs wxMinimal again git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4463 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/fontutil.h b/include/wx/fontutil.h index 635641e0fa..de51565a22 100644 --- a/include/wx/fontutil.h +++ b/include/wx/fontutil.h @@ -53,7 +53,7 @@ struct WXDLLEXPORT wxNativeEncodingInfo { wxString facename; // may be empty meaning "any" -#if defined(__WXMSW__) || defined(__WXPM__) +#if defined(__WXMSW__) || defined(__WXPM__) || defined(__WXMAC__) wxNativeEncodingInfo() { charset = 0; /* ANSI_CHARSET */ } int charset; diff --git a/include/wx/mac/font.h b/include/wx/mac/font.h index 1dd3f3da7c..fb985307b7 100644 --- a/include/wx/mac/font.h +++ b/include/wx/mac/font.h @@ -133,16 +133,7 @@ public: // implementation only from now on // ------------------------------- - int GetFontId() const; - virtual bool IsFree() const; virtual bool RealizeResource(); - virtual WXHANDLE GetResourceHandle(); - virtual bool FreeResource(bool force = FALSE); - void MacInstall() const ; - /* - virtual bool UseResource(); - virtual bool ReleaseResource(); - */ protected: // common part of all ctors diff --git a/include/wx/mac/listbox.h b/include/wx/mac/listbox.h index 061c146b0e..96be3d0f0e 100644 --- a/include/wx/mac/listbox.h +++ b/include/wx/mac/listbox.h @@ -104,11 +104,6 @@ public: int GetItemIndex(wxOwnerDrawn *item) const { return m_aItems.Index(item); } #endif // wxUSE_OWNER_DRAWN - // Windows-specific code to set the horizontal extent of the listbox, if - // necessary. If s is non-NULL, it's used to calculate the horizontal - // extent. Otherwise, all strings are used. - virtual void SetHorizontalExtent(const wxString& s = wxEmptyString); - // Windows callbacks virtual void SetupColours(); diff --git a/include/wx/mac/radiobox.h b/include/wx/mac/radiobox.h index 8a4529edca..9e2f3611ba 100644 --- a/include/wx/mac/radiobox.h +++ b/include/wx/mac/radiobox.h @@ -22,6 +22,7 @@ WXDLLEXPORT_DATA(extern const char*) wxRadioBoxNameStr; // List box item class WXDLLEXPORT wxBitmap ; +class WXDLLEXPORT wxRadioButton ; class WXDLLEXPORT wxRadioBox: public wxControl { @@ -77,8 +78,7 @@ public: // implementation only from now on // ------------------------------- - WXHWND *GetRadioButtons() const { return m_radioButtons; } - bool ContainsHWND(WXHWND hWnd) const; + wxRadioButton *GetRadioButtons() const { return m_radioButtons; } void SendNotificationEvent(); // get the number of buttons per column/row @@ -95,7 +95,7 @@ public: protected: void SubclassRadioButton(WXHWND hWndBtn); - WXHWND * m_radioButtons; + wxRadioButton * m_radioButtons; int m_majorDim; int * m_radioWidth; // for bitmaps int * m_radioHeight; diff --git a/include/wx/mac/setup.h b/include/wx/mac/setup.h index 0ae5dd8e72..569e0ee255 100644 --- a/include/wx/mac/setup.h +++ b/include/wx/mac/setup.h @@ -187,7 +187,7 @@ // if enabled, compiles built-in OS independent wxConfig // class and it's file (any platform) and registry (Win) // based implementations -#define wxUSE_THREADS 1 +#define wxUSE_THREADS 0 // support for multithreaded applications: if // 1, compile in thread classes (thread.h) // and make the library thread safe @@ -205,7 +205,7 @@ #define wxUSE_TOOLTIPS 1 // Define to use wxToolTip class and // wxWindow::SetToolTip() method -#define wxUSE_SOCKETS 1 // 0 +#define wxUSE_SOCKETS 0 // 0 // Set to 1 to use socket classes #define wxUSE_HTML 1 // 0 // Set to 1 to use wxHTML sub-library @@ -306,7 +306,7 @@ #define wxUSE_PENWINDOWS 0 // Set to 1 to use PenWindows -#define wxUSE_OWNER_DRAWN 1 +#define wxUSE_OWNER_DRAWN 0 // Owner-drawn menus and listboxes #define wxUSE_NATIVE_STATUSBAR 1 diff --git a/include/wx/mac/window.h b/include/wx/mac/window.h index 8a33aa8051..66eba027a2 100644 --- a/include/wx/mac/window.h +++ b/include/wx/mac/window.h @@ -155,8 +155,6 @@ public: // Native resource loading (implemented in src/msw/nativdlg.cpp) // FIXME: should they really be all virtual? - virtual bool LoadNativeDialog(wxWindow* parent, wxWindowID& id); - virtual bool LoadNativeDialog(wxWindow* parent, const wxString& name); wxWindow* GetWindowChild1(wxWindowID id); wxWindow* GetWindowChild(wxWindowID id); @@ -209,12 +207,6 @@ public: virtual void MSWDeviceToLogical(float *x, float *y) const; #endif // WXWIN_COMPATIBILITY - // Create an appropriate wxWindow from a HWND - virtual wxWindow* CreateWindowFromHWND(wxWindow* parent, WXHWND hWnd); - - // Make sure the window style reflects the HWND style (roughly) - virtual void AdoptAttributesFromHWND(); - // Setup background and foreground colours correctly virtual void SetupColours(); diff --git a/include/wx/statline.h b/include/wx/statline.h index 956dc75a68..a5657107a5 100644 --- a/include/wx/statline.h +++ b/include/wx/statline.h @@ -66,6 +66,8 @@ protected: #include "wx/gtk/statline.h" #elif defined(__WXPM__) #include "wx/os2/statline.h" +#elif defined(__WXMAC__) + #include "wx/mac/statline.h" #else // use generic implementation for all other platforms #include "wx/generic/statline.h" #endif diff --git a/src/common/cmndata.cpp b/src/common/cmndata.cpp index d5772633af..d6d38e477c 100644 --- a/src/common/cmndata.cpp +++ b/src/common/cmndata.cpp @@ -82,6 +82,11 @@ IMPLEMENT_DYNAMIC_CLASS(wxColourData, wxObject) #endif +#ifdef __WXMAC__ +#define mm2pt 2.83464566929 +#define pt2mm 0.352777777778 +#endif + // ============================================================================ // implementation // ============================================================================ @@ -166,6 +171,8 @@ wxPrintData::wxPrintData() { #ifdef __WXMSW__ m_devMode = NULL; +#elif defined( __WXMAC__ ) + m_macPrintInfo = NULL ; #endif m_printOrientation = wxPORTRAIT; m_printNoCopies = 1; @@ -207,6 +214,9 @@ wxPrintData::~wxPrintData() HGLOBAL hDevMode = (HGLOBAL)(DWORD) m_devMode; if (hDevMode ) GlobalFree(hDevMode); +#elif defined(__WXMAC__) + if ( m_macPrintInfo ) + ::DisposeHandle( (Handle) m_macPrintInfo ) ; #endif } @@ -593,6 +603,35 @@ void wxPrintData::ConvertFromNative() #endif +#ifdef __WXMAC__ +void wxPrintData::ConvertToNative() +{ + if ( !m_macPrintInfo ) + { + m_macPrintInfo = (THPrint) NewHandleClear( sizeof( TPrint ) ) ; + if ( m_macPrintInfo ) + { + ::PrintDefault( m_macPrintInfo ) ; + // todo setup the global pagesetup ? + } + } + if ( m_macPrintInfo ) + { + (**m_macPrintInfo).prJob.iCopies = m_printNoCopies ; + (**m_macPrintInfo).prJob.iFstPage = 0 ; + (**m_macPrintInfo).prJob.iLstPage = 0 ; + } +} + +void wxPrintData::ConvertFromNative() +{ + if ( m_macPrintInfo ) + { + m_printNoCopies = (**m_macPrintInfo).prJob.iCopies ; + } +} +#endif + void wxPrintData::operator=(const wxPrintData& data) { m_printNoCopies = data.m_printNoCopies; @@ -679,6 +718,8 @@ wxPrintDialogData::wxPrintDialogData(const wxPrintData& printData) { #ifdef __WXMSW__ m_printDlgData = NULL; +#elif defined( __WXMAC__ ) + m_macPrintInfo = NULL ; #endif m_printFromPage = 0; m_printToPage = 0; @@ -706,6 +747,9 @@ wxPrintDialogData::~wxPrintDialogData() GlobalFree(pd->hDevMode); if ( pd ) delete pd; +#elif defined(__WXMAC__) + if ( m_macPrintInfo ) + ::DisposeHandle( (Handle) m_macPrintInfo ) ; #endif } @@ -861,6 +905,38 @@ void wxPrintDialogData::SetOwnerWindow(wxWindow* win) } #endif // MSW +#ifdef __WXMAC__ +void wxPrintDialogData::ConvertToNative() +{ + if ( !m_macPrintInfo ) + { + m_macPrintInfo = (THPrint) NewHandleClear( sizeof( TPrint ) ) ; + if ( m_macPrintInfo ) + { + ::PrintDefault( m_macPrintInfo ) ; + // todo setup the global pagesetup ? + } + } + if ( m_macPrintInfo ) + { + (**m_macPrintInfo).prJob.iCopies = m_printNoCopies ; + (**m_macPrintInfo).prJob.iFstPage = m_printFromPage ; + (**m_macPrintInfo).prJob.iLstPage = m_printToPage ; + } +} + +void wxPrintDialogData::ConvertFromNative() +{ + if ( m_macPrintInfo ) + { + m_printNoCopies = (**m_macPrintInfo).prJob.iCopies ; + m_printFromPage = (**m_macPrintInfo).prJob.iFstPage ; + m_printToPage = (**m_macPrintInfo).prJob.iLstPage ; + } +} +#endif + + void wxPrintDialogData::operator=(const wxPrintDialogData& data) { m_printFromPage = data.m_printFromPage; @@ -894,6 +970,8 @@ wxPageSetupDialogData::wxPageSetupDialogData() { #if defined(__WIN95__) m_pageSetupData = NULL; +#elif defined( __WXMAC__ ) + m_macPageSetupInfo = NULL ; #endif m_paperSize = wxSize(0, 0); @@ -923,6 +1001,8 @@ wxPageSetupDialogData::wxPageSetupDialogData(const wxPrintData& printData) { #if defined(__WIN95__) m_pageSetupData = NULL; +#elif defined( __WXMAC__ ) + m_macPageSetupInfo = NULL ; #endif m_paperSize = wxSize(0, 0); m_minMarginTopLeft = wxPoint(0, 0); @@ -954,6 +1034,9 @@ wxPageSetupDialogData::~wxPageSetupDialogData() GlobalFree(pd->hDevMode); if ( pd ) delete pd; +#elif defined( __WXMAC__ ) + if( m_macPageSetupInfo ) + ::DisposeHandle( (Handle) m_macPageSetupInfo ) ; #endif } @@ -1126,6 +1209,69 @@ void wxPageSetupDialogData::SetOwnerWindow(wxWindow* win) } #endif // Win95 +#ifdef __WXMAC__ +void wxPageSetupData::ConvertToNative() +{ + if ( !m_macPageSetupInfo ) + { + m_macPageSetupInfo = (THPrint) NewHandleClear( sizeof( TPrint ) ) ; + if ( m_macPageSetupInfo ) + { + ::PrintDefault( m_macPageSetupInfo ) ; + } + } + if ( m_macPageSetupInfo ) + { + // on mac the paper rect has a negative top left corner, because the page rect (printable area) is at 0,0 + (**m_macPageSetupInfo).rPaper.left = int( ((double) m_minMarginTopLeft.x)*mm2pt ) ; + (**m_macPageSetupInfo).rPaper.top = int( ((double) m_minMarginTopLeft.y)*mm2pt ) ; + + (**m_macPageSetupInfo).rPaper.right = int( ((double) m_paperSize.x - m_minMarginTopLeft.x)*mm2pt ) ; + (**m_macPageSetupInfo).rPaper.bottom = int( ((double) m_paperSize.y - m_minMarginTopLeft.y)*mm2pt ) ; + + (**m_macPageSetupInfo).prInfo.rPage.left = 0 ; + (**m_macPageSetupInfo).prInfo.rPage.top = 0 ; + (**m_macPageSetupInfo).prInfo.rPage.right = int( ((double) m_paperSize.x - m_minMarginTopLeft.x - m_minMarginBottomRight.x)*mm2pt ) ; + (**m_macPageSetupInfo).prInfo.rPage.bottom = int( ((double) m_paperSize.y - m_minMarginTopLeft.y - m_minMarginBottomRight.y)*mm2pt ) ; + + //TODO add custom fields in dialog for margins + + } +} + +void wxPageSetupData::ConvertFromNative() +{ + if ( m_macPageSetupInfo ) + { + m_paperSize.x = ((double) (**m_macPageSetupInfo).rPaper.right - (**m_macPageSetupInfo).rPaper.left ) * pt2mm ; + m_paperSize.y = ((double) (**m_macPageSetupInfo).rPaper.bottom - (**m_macPageSetupInfo).rPaper.top ) * pt2mm ; + + m_minMarginTopLeft.x = ((double) -(**m_macPageSetupInfo).rPaper.left ) * pt2mm ; + m_minMarginTopLeft.y = ((double) -(**m_macPageSetupInfo).rPaper.top ) * pt2mm ; + + m_minMarginBottomRight.x = ((double) (**m_macPageSetupInfo).rPaper.right - (**m_macPageSetupInfo).prInfo.rPage.right ) * pt2mm ; + m_minMarginBottomRight.y = ((double)(**m_macPageSetupInfo).rPaper.bottom - (**m_macPageSetupInfo).prInfo.rPage.bottom ) * pt2mm ; + + // adjust minimal values + //TODO add custom fields in dialog for margins + + if ( m_marginTopLeft.x < m_minMarginTopLeft.x ) + m_marginTopLeft.x = m_minMarginTopLeft.x ; + + if ( m_marginBottomRight.x < m_minMarginBottomRight.x ) + m_marginBottomRight.x = m_minMarginBottomRight.x ; + + if ( m_marginTopLeft.y < m_minMarginTopLeft.y ) + m_marginTopLeft.y = m_minMarginTopLeft.y ; + + if ( m_marginBottomRight.y < m_minMarginBottomRight.y ) + m_marginBottomRight.y = m_minMarginBottomRight.y ; + + } +} +#endif + + // If a corresponding paper type is found in the paper database, will set the m_printData // paper size id member as well. void wxPageSetupDialogData::SetPaperSize(const wxSize& sz) diff --git a/src/common/init.cpp b/src/common/init.cpp index 50b8642fbe..8925cb193f 100644 --- a/src/common/init.cpp +++ b/src/common/init.cpp @@ -26,9 +26,11 @@ #ifndef WX_PRECOMP #include "wx/app.h" #include "wx/debug.h" - #include "wx/module.h" #endif +#include "wx/module.h" + + // ---------------------------------------------------------------------------- // global vars // ---------------------------------------------------------------------------- diff --git a/src/mac/app.cpp b/src/mac/app.cpp index 7d28b4bb30..245bdbee45 100644 --- a/src/mac/app.cpp +++ b/src/mac/app.cpp @@ -50,7 +50,7 @@ extern wxList wxPendingDelete; extern wxList *wxWinMacWindowList; extern wxList *wxWinMacControlList; -wxApp *wxTheApp = NULL; +extern wxApp *wxTheApp ; #if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler) diff --git a/src/mac/button.cpp b/src/mac/button.cpp index 1f42bad606..826a7756d8 100644 --- a/src/mac/button.cpp +++ b/src/mac/button.cpp @@ -66,6 +66,14 @@ void wxButton::SetDefault() } } +wxSize wxButton::DoGetBestSize() +{ + int wBtn = m_label.Length() * 8 + 12 + 2 * m_macHorizontalBorder; + int hBtn = 13 + 2 * m_macVerticalBorder; + + return wxSize(wBtn, hBtn); +} + void wxButton::Command (wxCommandEvent & event) { ProcessCommand (event); diff --git a/src/mac/carbon/app.cpp b/src/mac/carbon/app.cpp index 7d28b4bb30..245bdbee45 100644 --- a/src/mac/carbon/app.cpp +++ b/src/mac/carbon/app.cpp @@ -50,7 +50,7 @@ extern wxList wxPendingDelete; extern wxList *wxWinMacWindowList; extern wxList *wxWinMacControlList; -wxApp *wxTheApp = NULL; +extern wxApp *wxTheApp ; #if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler) diff --git a/src/mac/carbon/button.cpp b/src/mac/carbon/button.cpp index 1f42bad606..826a7756d8 100644 --- a/src/mac/carbon/button.cpp +++ b/src/mac/carbon/button.cpp @@ -66,6 +66,14 @@ void wxButton::SetDefault() } } +wxSize wxButton::DoGetBestSize() +{ + int wBtn = m_label.Length() * 8 + 12 + 2 * m_macHorizontalBorder; + int hBtn = 13 + 2 * m_macVerticalBorder; + + return wxSize(wBtn, hBtn); +} + void wxButton::Command (wxCommandEvent & event) { ProcessCommand (event); diff --git a/src/mac/carbon/control.cpp b/src/mac/carbon/control.cpp index 220ff1e0a9..037d95784f 100644 --- a/src/mac/carbon/control.cpp +++ b/src/mac/carbon/control.cpp @@ -587,6 +587,14 @@ void wxControl::OnPaint(wxPaintEvent& event) // wxWindow::OnPaint( event ) ; } } +void wxControl::OnEraseBackground(wxEraseEvent& event) +{ + // In general, you don't want to erase the background of a control, + // or you'll get a flicker. + // TODO: move this 'null' function into each control that + // might flicker. +} + void wxControl::OnKeyDown( wxKeyEvent &event ) { diff --git a/src/mac/carbon/data.cpp b/src/mac/carbon/data.cpp index 297686b9d1..5715b65c8f 100644 --- a/src/mac/carbon/data.cpp +++ b/src/mac/carbon/data.cpp @@ -119,7 +119,7 @@ const char *wxButtonBarNameStr = "buttonbar"; const char *wxEnhDialogNameStr = "Shell"; const char *wxToolBarNameStr = "toolbar"; const char *wxStatusLineNameStr = "status_line"; -const char *wxEmptyString = ""; + const char *wxGetTextFromUserPromptStr = "Input Text"; const char *wxMessageBoxCaptionStr = "Message"; const char *wxFileSelectorPromptStr = "Select a file"; diff --git a/src/mac/carbon/dialog.cpp b/src/mac/carbon/dialog.cpp index 2acc18174e..304fbb915b 100644 --- a/src/mac/carbon/dialog.cpp +++ b/src/mac/carbon/dialog.cpp @@ -44,6 +44,8 @@ END_EVENT_TABLE() wxDialog::wxDialog() { + m_isShown = FALSE; + m_modalShowing = FALSE; SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE)); } @@ -55,7 +57,12 @@ bool wxDialog::Create(wxWindow *parent, wxWindowID id, const wxString& name) { m_windowStyle = style; + m_isShown = FALSE; + m_modalShowing = FALSE; +#if wxUSE_TOOLTIPS + m_hwndToolTip = 0; +#endif SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE)); SetName(name); @@ -165,15 +172,36 @@ void wxDialog::OnCharHook(wxKeyEvent& event) void wxDialog::Iconize(bool WXUNUSED(iconize)) { - // TODO + // mac dialogs cannot be iconized } bool wxDialog::IsIconized() const { - // TODO + // mac dialogs cannot be iconized return FALSE; } +void wxDialog::DoSetClientSize(int width, int height) +{ + wxWindow::DoSetClientSize( width , height ) ; +} + +void wxDialog::GetPosition(int *x, int *y) const +{ + DoGetPosition( x , y ) ; +} + +bool wxDialog::IsShown() const +{ + return m_isShown; +} + +bool wxDialog::IsModal() const +{ + return wxModalDialogs.Find((wxDialog *)this) != 0; // const_cast +} + + extern bool s_macIsInModalLoop ; bool wxDialog::Show(bool show) @@ -255,42 +283,79 @@ bool wxDialog::Show(bool show) return TRUE ; } +void wxDialog::SetTitle(const wxString& title) +{ + wxWindow::SetTitle( title ) ; +} + +wxString wxDialog::GetTitle() const +{ + return wxWindow::GetTitle() ; +} + +void wxDialog::Centre(int direction) +{ + int x_offset,y_offset ; + int display_width, display_height; + int width, height, x, y; + wxWindow *parent = GetParent(); + if ((direction & wxCENTER_FRAME) && parent) + { + parent->GetPosition(&x_offset,&y_offset) ; + parent->GetSize(&display_width,&display_height) ; + } + else + { + wxDisplaySize(&display_width, &display_height); + x_offset = 0 ; + y_offset = 0 ; + } + + GetSize(&width, &height); + GetPosition(&x, &y); + + if (direction & wxHORIZONTAL) + x = (int)((display_width - width)/2); + if (direction & wxVERTICAL) + y = (int)((display_height - height)/2); + + SetSize(x+x_offset, y+y_offset, width, height); +} // Replacement for Show(TRUE) for modal dialogs - returns return code int wxDialog::ShowModal() { m_windowStyle |= wxDIALOG_MODAL; - Show(TRUE); - return GetReturnCode(); + Show(TRUE); + return GetReturnCode(); } void wxDialog::EndModal(int retCode) { - SetReturnCode(retCode); - // TODO modal un-showing - Show(FALSE); + SetReturnCode(retCode); + Show(FALSE); } // Standard buttons void wxDialog::OnOK(wxCommandEvent& event) { - if ( Validate() && TransferDataFromWindow() ) - { + if ( Validate() && TransferDataFromWindow() ) + { if ( IsModal() ) EndModal(wxID_OK); else { - SetReturnCode(wxID_OK); - this->Show(FALSE); + SetReturnCode(wxID_OK); + this->Show(FALSE); } - } + } } void wxDialog::OnApply(wxCommandEvent& event) { - if (Validate()) - TransferDataFromWindow(); - // TODO probably need to disable the Apply button until things change again + if (Validate()) + TransferDataFromWindow(); + // TODO probably need to disable the Apply button until things change again } void wxDialog::OnCancel(wxCommandEvent& event) @@ -300,7 +365,7 @@ void wxDialog::OnCancel(wxCommandEvent& event) else { SetReturnCode(wxID_CANCEL); - this->Show(FALSE); + this->Show(FALSE); } } @@ -321,12 +386,12 @@ void wxDialog::OnCloseWindow(wxCloseEvent& event) // The default OnCancel (above) simply ends a modal dialog, and hides a modeless dialog. static wxList closing; - + if ( closing.Member(this) ) return; - + closing.Append(this); - + wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL); cancelEvent.SetEventObject( this ); GetEventHandler()->ProcessEvent(cancelEvent); // This may close the dialog @@ -346,7 +411,8 @@ void wxDialog::OnSize(wxSizeEvent& WXUNUSED(event)) { // if we're using constraints - do use them #if wxUSE_CONSTRAINTS - if ( GetAutoLayout() ) { + if ( GetAutoLayout() ) + { Layout(); } #endif diff --git a/src/mac/carbon/font.cpp b/src/mac/carbon/font.cpp index d7d7b12cc8..988d1c81e2 100644 --- a/src/mac/carbon/font.cpp +++ b/src/mac/carbon/font.cpp @@ -149,6 +149,15 @@ bool wxFont::RealizeResource() return TRUE; } +void wxFont::SetEncoding(wxFontEncoding encoding) +{ + Unshare(); + + M_FONTDATA->m_encoding = encoding; + + RealizeResource(); +} + void wxFont::Unshare() { // Don't change shared data @@ -232,11 +241,6 @@ int wxFont::GetFamily() const return M_FONTDATA->m_family; } -int wxFont::GetFontId() const -{ - return M_FONTDATA->m_fontId; -} - int wxFont::GetStyle() const { return M_FONTDATA->m_style; diff --git a/src/mac/carbon/frame.cpp b/src/mac/carbon/frame.cpp index cd7a3deeff..59b57e6cb5 100644 --- a/src/mac/carbon/frame.cpp +++ b/src/mac/carbon/frame.cpp @@ -57,6 +57,7 @@ wxFrame::wxFrame() m_frameMenuBar = NULL; m_frameStatusBar = NULL; m_iconized = FALSE; + m_isShown = FALSE; } bool wxFrame::Create(wxWindow *parent, @@ -73,6 +74,7 @@ bool wxFrame::Create(wxWindow *parent, SetName(name); m_windowStyle = style; m_frameMenuBar = NULL; + m_isShown = FALSE; #if wxUSE_TOOLBAR m_frameToolBar = NULL ; diff --git a/src/mac/carbon/listbox.cpp b/src/mac/carbon/listbox.cpp index 3b9c54ce77..9d1220bc90 100644 --- a/src/mac/carbon/listbox.cpp +++ b/src/mac/carbon/listbox.cpp @@ -156,7 +156,6 @@ void wxListBox::Delete(int N) m_noItems --; MacDelete( N ) ; - SetHorizontalExtent(""); } int wxListBox::DoAppend(const wxString& item) @@ -171,8 +170,6 @@ int wxListBox::DoAppend(const wxString& item) m_noItems ++; MacAppend( item ) ; - SetHorizontalExtent(item); - return index ; } @@ -260,7 +257,6 @@ void wxListBox::Clear() m_stringArray.Empty() ; m_dataArray.Empty() ; MacClear() ; - SetHorizontalExtent(); } void wxListBox::SetSelection(int N, bool select) @@ -286,6 +282,11 @@ void *wxListBox::DoGetItemClientData(int N) const return (void *)m_dataArray[N]; } +wxClientData *wxListBox::DoGetItemClientObject(int N) const +{ + return (wxClientData *) DoGetItemClientData( N ) ; +} + void wxListBox::DoSetItemClientData(int N, void *Client_data) { wxCHECK_RET( N >= 0 && N < m_noItems, @@ -375,6 +376,37 @@ wxSize wxListBox::DoGetBestSize() return wxSize(100, 100); } +int wxListBox::GetCount() const +{ + return m_noItems; +} + +void wxListBox::SetupColours() +{ + SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW)); + SetForegroundColour(GetParent()->GetForegroundColour()); +} + +#if wxUSE_OWNER_DRAWN + +class wxListBoxItem : public wxOwnerDrawn +{ +public: + wxListBoxItem(const wxString& str = ""); +}; + +wxListBoxItem::wxListBoxItem(const wxString& str) : wxOwnerDrawn(str, FALSE) +{ + // no bitmaps/checkmarks + SetMarginWidth(0); +} + +wxOwnerDrawn *wxListBox::CreateItem(size_t n) +{ + return new wxListBoxItem(); +} + +#endif //USE_OWNER_DRAWN // ============================================================================ // list box control implementation diff --git a/src/mac/carbon/menu.cpp b/src/mac/carbon/menu.cpp index 35589ca6e1..f288bc80e1 100644 --- a/src/mac/carbon/menu.cpp +++ b/src/mac/carbon/menu.cpp @@ -57,7 +57,7 @@ void wxMacCtoPString(const char* theCString, Str255 thePString); // remove inappropriate characters, if useShortcuts is false, the ampersand will not auto-generate a mac menu-shortcut -static void wxMacBuildMenuString(StringPtr outMacItemText, char *outMacShortcutChar , short *outMacModifiers , const char *inItemName , bool useShortcuts ) +void wxMacBuildMenuString(StringPtr outMacItemText, char *outMacShortcutChar , short *outMacModifiers , const char *inItemName , bool useShortcuts ) { char *p = (char *) &outMacItemText[1] ; short macModifiers = 0 ; @@ -117,18 +117,18 @@ static void wxMacBuildMenuString(StringPtr outMacItemText, char *outMacShortcutC ++inItemName ; while( *inItemName ) { - if (strncmp("Ctrl+", inItemName, 5) == 0) + if (strncmp("Ctrl", inItemName, 4) == 0) { inItemName = inItemName + 5; macShortCut = *inItemName; } - else if (strncmp("Alt+", inItemName, 4) == 0) + else if (strncmp("Alt", inItemName, 3) == 0) { inItemName = inItemName + 4; macModifiers |= kMenuOptionModifier ; macShortCut = *inItemName ; } - else if (strncmp("Shift+", inItemName, 6) == 0) + else if (strncmp("Shift", inItemName, 5) == 0) { inItemName = inItemName + 6; macModifiers |= kMenuShiftModifier ; @@ -602,21 +602,7 @@ wxWindow *wxMenu::GetWindow() const return NULL; } -/* -bool wxWindow::PopupMenu(wxMenu *menu, int x, int y) -{ - menu->SetInvokingWindow(this); - ClientToScreen( &x , &y ) ; - ::InsertMenu( menu->m_hMenu , -1 ) ; - long menuResult = ::PopUpMenuSelect(menu->m_hMenu ,y,x, 0) ; - menu->MacMenuSelect( this , TickCount() , HiWord(menuResult) , LoWord(menuResult) ) ; - ::DeleteMenu( menu->m_macMenuId ) ; - menu->SetInvokingWindow(NULL); - - return TRUE; -} -*/ // helper functions returning the mac menu position for a certain item, note that this is // mac-wise 1 - based, i.e. the first item has index 1 whereas on MSWin it has pos 0 @@ -682,7 +668,28 @@ bool wxMenu::MacMenuSelect( wxEvtHandler* handler, long when , int macMenuId, in event.m_timeStamp = when; event.SetEventObject(handler); event.SetInt( pItem->GetId() ); - ProcessCommand( event ) ; + { + bool processed = false ; + +#if WXWIN_COMPATIBILITY + // Try a callback + if (m_callback) + { + (void) (*(m_callback)) (*this, event); + processed = TRUE; + } +#endif + // Try the menu's event handler + if ( !processed && handler) + { + processed = handler->ProcessEvent(event); + } + + // Try the window the menu was popped up from (and up + // through the hierarchy) + if ( !processed && GetInvokingWindow()) + processed = GetInvokingWindow()->GetEventHandler()->ProcessEvent(event); + } return true ; } } @@ -708,7 +715,27 @@ bool wxMenu::MacMenuSelect( wxEvtHandler* handler, long when , int macMenuId, in event.m_timeStamp = when; event.SetEventObject(handler); event.SetInt( pItem->GetId() ); - ProcessCommand( event ) ; + { + bool processed = false ; +#if WXWIN_COMPATIBILITY + // Try a callback + if (m_callback) + { + (void) (*(m_callback)) (*this, event); + processed = TRUE; + } +#endif + // Try the menu's event handler + if ( !processed && handler) + { + processed = handler->ProcessEvent(event); + } + + // Try the window the menu was popped up from (and up + // through the hierarchy) + if ( !processed && GetInvokingWindow()) + processed = GetInvokingWindow()->GetEventHandler()->ProcessEvent(event); + } return true ; } } @@ -757,6 +784,16 @@ void wxMenuBar::Init() m_menuBarFrame = NULL; } +wxMenuBar::wxMenuBar() +{ + Init(); +} + +wxMenuBar::wxMenuBar( long WXUNUSED(style) ) +{ + Init(); +} + wxMenuBar::wxMenuBar(int count, wxMenu *menus[], const wxString titles[]) { @@ -790,6 +827,37 @@ void wxMenuBar::Refresh() DrawMenuBar(); } +#if wxUSE_ACCEL + +void wxMenuBar::RebuildAccelTable() +{ + // merge the accelerators of all menus into one accel table + size_t nAccelCount = 0; + size_t i, count = GetMenuCount(); + for ( i = 0; i < count; i++ ) + { + nAccelCount += m_menus[i]->GetAccelCount(); + } + + if ( nAccelCount ) + { + wxAcceleratorEntry *accelEntries = new wxAcceleratorEntry[nAccelCount]; + + nAccelCount = 0; + for ( i = 0; i < count; i++ ) + { + nAccelCount += m_menus[i]->CopyAccels(&accelEntries[nAccelCount]); + } + + m_accelTable = wxAcceleratorTable(nAccelCount, accelEntries); + + delete [] accelEntries; + } +} + +#endif // wxUSE_ACCEL + + void wxMenuBar::MacInstallMenuBar() { Handle menubar = ::GetNewMBar( kwxMacMenuBarResource ) ; @@ -1047,7 +1115,107 @@ void wxMenuBar::MacMenuSelect(wxEvtHandler* handler, long when , int macMenuId, { break ; } - } + } } } +wxMenu *wxMenuBar::Remove(size_t pos) +{ + wxMenu *menu = wxMenuBarBase::Remove(pos); + if ( !menu ) + return NULL; + + if ( IsAttached() ) + { + if (s_macInstalledMenuBar == this) + { + ::DeleteMenu( menu->MacGetMenuId() /* m_menus[pos]->MacGetMenuId() */ ) ; + } + + menu->Detach(); + +#if wxUSE_ACCEL + if ( menu->HasAccels() ) + { + // need to rebuild accell table + RebuildAccelTable(); + } +#endif // wxUSE_ACCEL + + Refresh(); + } + + m_titles.Remove(pos); + + return menu; +} + +bool wxMenuBar::Append(wxMenu *menu, const wxString& title) +{ + WXHMENU submenu = menu ? menu->GetHMenu() : 0; + wxCHECK_MSG( submenu, FALSE, wxT("can't append invalid menu to menubar") ); + + if ( !wxMenuBarBase::Append(menu, title) ) + return FALSE; + + menu->Attach(this); + + m_titles.Add(title); + + if ( IsAttached() ) + { + if (s_macInstalledMenuBar == this) + { + ::InsertMenu( menu->GetHMenu() , 0 ) ; + } + +#if wxUSE_ACCEL + if ( menu->HasAccels() ) + { + // need to rebuild accell table + RebuildAccelTable(); + } +#endif // wxUSE_ACCEL + + Refresh(); + } + + return TRUE; +} + +// --------------------------------------------------------------------------- +// wxMenuBar searching for menu items +// --------------------------------------------------------------------------- + +// Find the itemString in menuString, and return the item id or wxNOT_FOUND +int wxMenuBar::FindMenuItem(const wxString& menuString, + const wxString& itemString) const +{ + wxString menuLabel = wxStripMenuCodes(menuString); + size_t count = GetMenuCount(); + for ( size_t i = 0; i < count; i++ ) + { + wxString title = wxStripMenuCodes(m_titles[i]); + if ( menuString == title ) + return m_menus[i]->FindItem(itemString); + } + + return wxNOT_FOUND; +} + +wxMenuItem *wxMenuBar::FindItem(int id, wxMenu **itemMenu) const +{ + if ( itemMenu ) + *itemMenu = NULL; + + wxMenuItem *item = NULL; + size_t count = GetMenuCount(); + for ( size_t i = 0; !item && (i < count); i++ ) + { + item = m_menus[i]->FindItem(id, itemMenu); + } + + return item; +} + + diff --git a/src/mac/carbon/menuitem.cpp b/src/mac/carbon/menuitem.cpp index ef67483ca3..fc8d7885af 100644 --- a/src/mac/carbon/menuitem.cpp +++ b/src/mac/carbon/menuitem.cpp @@ -29,6 +29,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxMenuItem, wxObject) #endif //USE_SHARED_LIBRARY +void wxMacBuildMenuString(StringPtr outMacItemText, char *outMacShortcutChar , short *outMacModifiers , const char *inItemName , bool useShortcuts ) ; // ---------------------------------------------------------------------------- // wxMenuItem // ---------------------------------------------------------------------------- @@ -63,6 +64,28 @@ wxMenuItem::~wxMenuItem() { } +bool wxMenuItem::IsChecked() const +{ + return wxMenuItemBase::IsChecked() ; +} + +wxString wxMenuItem::GetLabel() const +{ + return wxStripMenuCodes(m_text); +} + +// accelerators +// ------------ + +#if wxUSE_ACCEL + +wxAcceleratorEntry *wxMenuItem::GetAccel() const +{ + return wxGetAccelFromString(GetText()); +} + +#endif // wxUSE_ACCEL + // misc // ---- @@ -139,4 +162,50 @@ void wxMenuItem::Check(bool bDoCheck) } } } -} \ No newline at end of file +} + +void wxMenuItem::SetText(const wxString& text) +{ + // don't do anything if label didn't change + if ( m_text == text ) + return; + + wxMenuItemBase::SetText(text); +// OWNER_DRAWN_ONLY( wxOwnerDrawn::SetName(text) ); + + wxCHECK_RET( m_parentMenu && m_parentMenu->GetHMenu(), wxT("menuitem without menu") ); + if ( m_parentMenu->GetHMenu() ) + { + int index = m_parentMenu->MacGetIndexFromItem( this ) ; + if ( index >= 1 ) + { + Str255 label; + wxMacBuildMenuString( label , NULL , NULL , text ,false); + ::SetMenuItemText( m_parentMenu->GetHMenu() , index , label ) ; // checkmark + } + } + +#if wxUSE_ACCEL + m_parentMenu->UpdateAccel(this); +#endif // wxUSE_ACCEL + +} +void wxMenuItem::SetCheckable(bool checkable) +{ + wxMenuItemBase::SetCheckable(checkable); + // OWNER_DRAWN_ONLY( wxOwnerDrawn::SetCheckable(checkable) ); +} + +// ---------------------------------------------------------------------------- +// wxMenuItemBase +// ---------------------------------------------------------------------------- + +wxMenuItem *wxMenuItemBase::New(wxMenu *parentMenu, + int id, + const wxString& name, + const wxString& help, + bool isCheckable, + wxMenu *subMenu) +{ + return new wxMenuItem(parentMenu, id, name, help, isCheckable, subMenu); +} diff --git a/src/mac/carbon/spinbutt.cpp b/src/mac/carbon/spinbutt.cpp index d91374445a..f48ad3de9e 100644 --- a/src/mac/carbon/spinbutt.cpp +++ b/src/mac/carbon/spinbutt.cpp @@ -126,4 +126,23 @@ void wxSpinButton::MacHandleControlClick( ControlHandle control , SInt16 control GetEventHandler()->ProcessEvent(event); } +// ---------------------------------------------------------------------------- +// size calculation +// ---------------------------------------------------------------------------- + +wxSize wxSpinButton::DoGetBestSize() +{ + if ( (GetWindowStyle() & wxSP_VERTICAL) != 0 ) + { + // vertical control + return wxSize(16, + 2*16); + } + else + { + // horizontal control + return wxSize(2*16, + 16); + } +} diff --git a/src/mac/carbon/window.cpp b/src/mac/carbon/window.cpp index 18ab38338a..dbfb493a09 100644 --- a/src/mac/carbon/window.cpp +++ b/src/mac/carbon/window.cpp @@ -295,6 +295,34 @@ void wxWindow::DoGetPosition(int *x, int *y) const } } +wxSize wxWindow::DoGetBestSize() +{ + return wxSize( 0 , 0 ) ; +} + +bool wxWindow::Reparent(wxWindow *parent) +{ + if ( !wxWindowBase::Reparent(parent) ) + return FALSE; + + return TRUE; +} + +bool wxWindow::DoPopupMenu(wxMenu *menu, int x, int y) +{ + menu->SetInvokingWindow(this); + menu->UpdateUI(); + ClientToScreen( &x , &y ) ; + + ::InsertMenu( menu->GetHMenu() , -1 ) ; + long menuResult = ::PopUpMenuSelect(menu->GetHMenu() ,y,x, 0) ; + menu->MacMenuSelect( this , TickCount() , HiWord(menuResult) , LoWord(menuResult) ) ; + ::DeleteMenu( menu->MacGetMenuId() ) ; + menu->SetInvokingWindow(NULL); + + return TRUE; +} + void wxWindow::DoScreenToClient(int *x, int *y) const { WindowRef window = GetMacRootWindow() ; @@ -401,6 +429,28 @@ void wxWindow::DoGetClientSize(int *x, int *y) const (*y) -= MAC_SCROLLBAR_SIZE; } + +// ---------------------------------------------------------------------------- +// tooltips +// ---------------------------------------------------------------------------- + +#if wxUSE_TOOLTIPS + +void wxWindow::DoSetToolTip(wxToolTip *tooltip) +{ + wxWindowBase::DoSetToolTip(tooltip); + +// if ( m_tooltip ) +// m_tooltip->SetWindow(this); +} + +#endif // wxUSE_TOOLTIPS + +void wxWindow::DoMoveWindow(int x, int y, int width, int height) +{ + DoSetSize( x,y, width, height ) ; +} + void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags) { int former_x = m_x ; @@ -1764,13 +1814,3 @@ wxMacDrawingClientHelper::~wxMacDrawingClientHelper() if ( m_formerPort != m_currentPort ) SetPort( m_formerPort ) ; } - -// ---------------------------------------------------------------------------- -// list classes implementation -// ---------------------------------------------------------------------------- - -void wxWindowListNode::DeleteData() -{ - delete (wxWindow *)GetData(); -} - diff --git a/src/mac/control.cpp b/src/mac/control.cpp index 220ff1e0a9..037d95784f 100644 --- a/src/mac/control.cpp +++ b/src/mac/control.cpp @@ -587,6 +587,14 @@ void wxControl::OnPaint(wxPaintEvent& event) // wxWindow::OnPaint( event ) ; } } +void wxControl::OnEraseBackground(wxEraseEvent& event) +{ + // In general, you don't want to erase the background of a control, + // or you'll get a flicker. + // TODO: move this 'null' function into each control that + // might flicker. +} + void wxControl::OnKeyDown( wxKeyEvent &event ) { diff --git a/src/mac/data.cpp b/src/mac/data.cpp index 297686b9d1..5715b65c8f 100644 --- a/src/mac/data.cpp +++ b/src/mac/data.cpp @@ -119,7 +119,7 @@ const char *wxButtonBarNameStr = "buttonbar"; const char *wxEnhDialogNameStr = "Shell"; const char *wxToolBarNameStr = "toolbar"; const char *wxStatusLineNameStr = "status_line"; -const char *wxEmptyString = ""; + const char *wxGetTextFromUserPromptStr = "Input Text"; const char *wxMessageBoxCaptionStr = "Message"; const char *wxFileSelectorPromptStr = "Select a file"; diff --git a/src/mac/dialog.cpp b/src/mac/dialog.cpp index 2acc18174e..304fbb915b 100644 --- a/src/mac/dialog.cpp +++ b/src/mac/dialog.cpp @@ -44,6 +44,8 @@ END_EVENT_TABLE() wxDialog::wxDialog() { + m_isShown = FALSE; + m_modalShowing = FALSE; SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE)); } @@ -55,7 +57,12 @@ bool wxDialog::Create(wxWindow *parent, wxWindowID id, const wxString& name) { m_windowStyle = style; + m_isShown = FALSE; + m_modalShowing = FALSE; +#if wxUSE_TOOLTIPS + m_hwndToolTip = 0; +#endif SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE)); SetName(name); @@ -165,15 +172,36 @@ void wxDialog::OnCharHook(wxKeyEvent& event) void wxDialog::Iconize(bool WXUNUSED(iconize)) { - // TODO + // mac dialogs cannot be iconized } bool wxDialog::IsIconized() const { - // TODO + // mac dialogs cannot be iconized return FALSE; } +void wxDialog::DoSetClientSize(int width, int height) +{ + wxWindow::DoSetClientSize( width , height ) ; +} + +void wxDialog::GetPosition(int *x, int *y) const +{ + DoGetPosition( x , y ) ; +} + +bool wxDialog::IsShown() const +{ + return m_isShown; +} + +bool wxDialog::IsModal() const +{ + return wxModalDialogs.Find((wxDialog *)this) != 0; // const_cast +} + + extern bool s_macIsInModalLoop ; bool wxDialog::Show(bool show) @@ -255,42 +283,79 @@ bool wxDialog::Show(bool show) return TRUE ; } +void wxDialog::SetTitle(const wxString& title) +{ + wxWindow::SetTitle( title ) ; +} + +wxString wxDialog::GetTitle() const +{ + return wxWindow::GetTitle() ; +} + +void wxDialog::Centre(int direction) +{ + int x_offset,y_offset ; + int display_width, display_height; + int width, height, x, y; + wxWindow *parent = GetParent(); + if ((direction & wxCENTER_FRAME) && parent) + { + parent->GetPosition(&x_offset,&y_offset) ; + parent->GetSize(&display_width,&display_height) ; + } + else + { + wxDisplaySize(&display_width, &display_height); + x_offset = 0 ; + y_offset = 0 ; + } + + GetSize(&width, &height); + GetPosition(&x, &y); + + if (direction & wxHORIZONTAL) + x = (int)((display_width - width)/2); + if (direction & wxVERTICAL) + y = (int)((display_height - height)/2); + + SetSize(x+x_offset, y+y_offset, width, height); +} // Replacement for Show(TRUE) for modal dialogs - returns return code int wxDialog::ShowModal() { m_windowStyle |= wxDIALOG_MODAL; - Show(TRUE); - return GetReturnCode(); + Show(TRUE); + return GetReturnCode(); } void wxDialog::EndModal(int retCode) { - SetReturnCode(retCode); - // TODO modal un-showing - Show(FALSE); + SetReturnCode(retCode); + Show(FALSE); } // Standard buttons void wxDialog::OnOK(wxCommandEvent& event) { - if ( Validate() && TransferDataFromWindow() ) - { + if ( Validate() && TransferDataFromWindow() ) + { if ( IsModal() ) EndModal(wxID_OK); else { - SetReturnCode(wxID_OK); - this->Show(FALSE); + SetReturnCode(wxID_OK); + this->Show(FALSE); } - } + } } void wxDialog::OnApply(wxCommandEvent& event) { - if (Validate()) - TransferDataFromWindow(); - // TODO probably need to disable the Apply button until things change again + if (Validate()) + TransferDataFromWindow(); + // TODO probably need to disable the Apply button until things change again } void wxDialog::OnCancel(wxCommandEvent& event) @@ -300,7 +365,7 @@ void wxDialog::OnCancel(wxCommandEvent& event) else { SetReturnCode(wxID_CANCEL); - this->Show(FALSE); + this->Show(FALSE); } } @@ -321,12 +386,12 @@ void wxDialog::OnCloseWindow(wxCloseEvent& event) // The default OnCancel (above) simply ends a modal dialog, and hides a modeless dialog. static wxList closing; - + if ( closing.Member(this) ) return; - + closing.Append(this); - + wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL); cancelEvent.SetEventObject( this ); GetEventHandler()->ProcessEvent(cancelEvent); // This may close the dialog @@ -346,7 +411,8 @@ void wxDialog::OnSize(wxSizeEvent& WXUNUSED(event)) { // if we're using constraints - do use them #if wxUSE_CONSTRAINTS - if ( GetAutoLayout() ) { + if ( GetAutoLayout() ) + { Layout(); } #endif diff --git a/src/mac/font.cpp b/src/mac/font.cpp index d7d7b12cc8..988d1c81e2 100644 --- a/src/mac/font.cpp +++ b/src/mac/font.cpp @@ -149,6 +149,15 @@ bool wxFont::RealizeResource() return TRUE; } +void wxFont::SetEncoding(wxFontEncoding encoding) +{ + Unshare(); + + M_FONTDATA->m_encoding = encoding; + + RealizeResource(); +} + void wxFont::Unshare() { // Don't change shared data @@ -232,11 +241,6 @@ int wxFont::GetFamily() const return M_FONTDATA->m_family; } -int wxFont::GetFontId() const -{ - return M_FONTDATA->m_fontId; -} - int wxFont::GetStyle() const { return M_FONTDATA->m_style; diff --git a/src/mac/frame.cpp b/src/mac/frame.cpp index cd7a3deeff..59b57e6cb5 100644 --- a/src/mac/frame.cpp +++ b/src/mac/frame.cpp @@ -57,6 +57,7 @@ wxFrame::wxFrame() m_frameMenuBar = NULL; m_frameStatusBar = NULL; m_iconized = FALSE; + m_isShown = FALSE; } bool wxFrame::Create(wxWindow *parent, @@ -73,6 +74,7 @@ bool wxFrame::Create(wxWindow *parent, SetName(name); m_windowStyle = style; m_frameMenuBar = NULL; + m_isShown = FALSE; #if wxUSE_TOOLBAR m_frameToolBar = NULL ; diff --git a/src/mac/listbox.cpp b/src/mac/listbox.cpp index 3b9c54ce77..9d1220bc90 100644 --- a/src/mac/listbox.cpp +++ b/src/mac/listbox.cpp @@ -156,7 +156,6 @@ void wxListBox::Delete(int N) m_noItems --; MacDelete( N ) ; - SetHorizontalExtent(""); } int wxListBox::DoAppend(const wxString& item) @@ -171,8 +170,6 @@ int wxListBox::DoAppend(const wxString& item) m_noItems ++; MacAppend( item ) ; - SetHorizontalExtent(item); - return index ; } @@ -260,7 +257,6 @@ void wxListBox::Clear() m_stringArray.Empty() ; m_dataArray.Empty() ; MacClear() ; - SetHorizontalExtent(); } void wxListBox::SetSelection(int N, bool select) @@ -286,6 +282,11 @@ void *wxListBox::DoGetItemClientData(int N) const return (void *)m_dataArray[N]; } +wxClientData *wxListBox::DoGetItemClientObject(int N) const +{ + return (wxClientData *) DoGetItemClientData( N ) ; +} + void wxListBox::DoSetItemClientData(int N, void *Client_data) { wxCHECK_RET( N >= 0 && N < m_noItems, @@ -375,6 +376,37 @@ wxSize wxListBox::DoGetBestSize() return wxSize(100, 100); } +int wxListBox::GetCount() const +{ + return m_noItems; +} + +void wxListBox::SetupColours() +{ + SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW)); + SetForegroundColour(GetParent()->GetForegroundColour()); +} + +#if wxUSE_OWNER_DRAWN + +class wxListBoxItem : public wxOwnerDrawn +{ +public: + wxListBoxItem(const wxString& str = ""); +}; + +wxListBoxItem::wxListBoxItem(const wxString& str) : wxOwnerDrawn(str, FALSE) +{ + // no bitmaps/checkmarks + SetMarginWidth(0); +} + +wxOwnerDrawn *wxListBox::CreateItem(size_t n) +{ + return new wxListBoxItem(); +} + +#endif //USE_OWNER_DRAWN // ============================================================================ // list box control implementation diff --git a/src/mac/menu.cpp b/src/mac/menu.cpp index 35589ca6e1..f288bc80e1 100644 --- a/src/mac/menu.cpp +++ b/src/mac/menu.cpp @@ -57,7 +57,7 @@ void wxMacCtoPString(const char* theCString, Str255 thePString); // remove inappropriate characters, if useShortcuts is false, the ampersand will not auto-generate a mac menu-shortcut -static void wxMacBuildMenuString(StringPtr outMacItemText, char *outMacShortcutChar , short *outMacModifiers , const char *inItemName , bool useShortcuts ) +void wxMacBuildMenuString(StringPtr outMacItemText, char *outMacShortcutChar , short *outMacModifiers , const char *inItemName , bool useShortcuts ) { char *p = (char *) &outMacItemText[1] ; short macModifiers = 0 ; @@ -117,18 +117,18 @@ static void wxMacBuildMenuString(StringPtr outMacItemText, char *outMacShortcutC ++inItemName ; while( *inItemName ) { - if (strncmp("Ctrl+", inItemName, 5) == 0) + if (strncmp("Ctrl", inItemName, 4) == 0) { inItemName = inItemName + 5; macShortCut = *inItemName; } - else if (strncmp("Alt+", inItemName, 4) == 0) + else if (strncmp("Alt", inItemName, 3) == 0) { inItemName = inItemName + 4; macModifiers |= kMenuOptionModifier ; macShortCut = *inItemName ; } - else if (strncmp("Shift+", inItemName, 6) == 0) + else if (strncmp("Shift", inItemName, 5) == 0) { inItemName = inItemName + 6; macModifiers |= kMenuShiftModifier ; @@ -602,21 +602,7 @@ wxWindow *wxMenu::GetWindow() const return NULL; } -/* -bool wxWindow::PopupMenu(wxMenu *menu, int x, int y) -{ - menu->SetInvokingWindow(this); - ClientToScreen( &x , &y ) ; - ::InsertMenu( menu->m_hMenu , -1 ) ; - long menuResult = ::PopUpMenuSelect(menu->m_hMenu ,y,x, 0) ; - menu->MacMenuSelect( this , TickCount() , HiWord(menuResult) , LoWord(menuResult) ) ; - ::DeleteMenu( menu->m_macMenuId ) ; - menu->SetInvokingWindow(NULL); - - return TRUE; -} -*/ // helper functions returning the mac menu position for a certain item, note that this is // mac-wise 1 - based, i.e. the first item has index 1 whereas on MSWin it has pos 0 @@ -682,7 +668,28 @@ bool wxMenu::MacMenuSelect( wxEvtHandler* handler, long when , int macMenuId, in event.m_timeStamp = when; event.SetEventObject(handler); event.SetInt( pItem->GetId() ); - ProcessCommand( event ) ; + { + bool processed = false ; + +#if WXWIN_COMPATIBILITY + // Try a callback + if (m_callback) + { + (void) (*(m_callback)) (*this, event); + processed = TRUE; + } +#endif + // Try the menu's event handler + if ( !processed && handler) + { + processed = handler->ProcessEvent(event); + } + + // Try the window the menu was popped up from (and up + // through the hierarchy) + if ( !processed && GetInvokingWindow()) + processed = GetInvokingWindow()->GetEventHandler()->ProcessEvent(event); + } return true ; } } @@ -708,7 +715,27 @@ bool wxMenu::MacMenuSelect( wxEvtHandler* handler, long when , int macMenuId, in event.m_timeStamp = when; event.SetEventObject(handler); event.SetInt( pItem->GetId() ); - ProcessCommand( event ) ; + { + bool processed = false ; +#if WXWIN_COMPATIBILITY + // Try a callback + if (m_callback) + { + (void) (*(m_callback)) (*this, event); + processed = TRUE; + } +#endif + // Try the menu's event handler + if ( !processed && handler) + { + processed = handler->ProcessEvent(event); + } + + // Try the window the menu was popped up from (and up + // through the hierarchy) + if ( !processed && GetInvokingWindow()) + processed = GetInvokingWindow()->GetEventHandler()->ProcessEvent(event); + } return true ; } } @@ -757,6 +784,16 @@ void wxMenuBar::Init() m_menuBarFrame = NULL; } +wxMenuBar::wxMenuBar() +{ + Init(); +} + +wxMenuBar::wxMenuBar( long WXUNUSED(style) ) +{ + Init(); +} + wxMenuBar::wxMenuBar(int count, wxMenu *menus[], const wxString titles[]) { @@ -790,6 +827,37 @@ void wxMenuBar::Refresh() DrawMenuBar(); } +#if wxUSE_ACCEL + +void wxMenuBar::RebuildAccelTable() +{ + // merge the accelerators of all menus into one accel table + size_t nAccelCount = 0; + size_t i, count = GetMenuCount(); + for ( i = 0; i < count; i++ ) + { + nAccelCount += m_menus[i]->GetAccelCount(); + } + + if ( nAccelCount ) + { + wxAcceleratorEntry *accelEntries = new wxAcceleratorEntry[nAccelCount]; + + nAccelCount = 0; + for ( i = 0; i < count; i++ ) + { + nAccelCount += m_menus[i]->CopyAccels(&accelEntries[nAccelCount]); + } + + m_accelTable = wxAcceleratorTable(nAccelCount, accelEntries); + + delete [] accelEntries; + } +} + +#endif // wxUSE_ACCEL + + void wxMenuBar::MacInstallMenuBar() { Handle menubar = ::GetNewMBar( kwxMacMenuBarResource ) ; @@ -1047,7 +1115,107 @@ void wxMenuBar::MacMenuSelect(wxEvtHandler* handler, long when , int macMenuId, { break ; } - } + } } } +wxMenu *wxMenuBar::Remove(size_t pos) +{ + wxMenu *menu = wxMenuBarBase::Remove(pos); + if ( !menu ) + return NULL; + + if ( IsAttached() ) + { + if (s_macInstalledMenuBar == this) + { + ::DeleteMenu( menu->MacGetMenuId() /* m_menus[pos]->MacGetMenuId() */ ) ; + } + + menu->Detach(); + +#if wxUSE_ACCEL + if ( menu->HasAccels() ) + { + // need to rebuild accell table + RebuildAccelTable(); + } +#endif // wxUSE_ACCEL + + Refresh(); + } + + m_titles.Remove(pos); + + return menu; +} + +bool wxMenuBar::Append(wxMenu *menu, const wxString& title) +{ + WXHMENU submenu = menu ? menu->GetHMenu() : 0; + wxCHECK_MSG( submenu, FALSE, wxT("can't append invalid menu to menubar") ); + + if ( !wxMenuBarBase::Append(menu, title) ) + return FALSE; + + menu->Attach(this); + + m_titles.Add(title); + + if ( IsAttached() ) + { + if (s_macInstalledMenuBar == this) + { + ::InsertMenu( menu->GetHMenu() , 0 ) ; + } + +#if wxUSE_ACCEL + if ( menu->HasAccels() ) + { + // need to rebuild accell table + RebuildAccelTable(); + } +#endif // wxUSE_ACCEL + + Refresh(); + } + + return TRUE; +} + +// --------------------------------------------------------------------------- +// wxMenuBar searching for menu items +// --------------------------------------------------------------------------- + +// Find the itemString in menuString, and return the item id or wxNOT_FOUND +int wxMenuBar::FindMenuItem(const wxString& menuString, + const wxString& itemString) const +{ + wxString menuLabel = wxStripMenuCodes(menuString); + size_t count = GetMenuCount(); + for ( size_t i = 0; i < count; i++ ) + { + wxString title = wxStripMenuCodes(m_titles[i]); + if ( menuString == title ) + return m_menus[i]->FindItem(itemString); + } + + return wxNOT_FOUND; +} + +wxMenuItem *wxMenuBar::FindItem(int id, wxMenu **itemMenu) const +{ + if ( itemMenu ) + *itemMenu = NULL; + + wxMenuItem *item = NULL; + size_t count = GetMenuCount(); + for ( size_t i = 0; !item && (i < count); i++ ) + { + item = m_menus[i]->FindItem(id, itemMenu); + } + + return item; +} + + diff --git a/src/mac/menuitem.cpp b/src/mac/menuitem.cpp index ef67483ca3..fc8d7885af 100644 --- a/src/mac/menuitem.cpp +++ b/src/mac/menuitem.cpp @@ -29,6 +29,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxMenuItem, wxObject) #endif //USE_SHARED_LIBRARY +void wxMacBuildMenuString(StringPtr outMacItemText, char *outMacShortcutChar , short *outMacModifiers , const char *inItemName , bool useShortcuts ) ; // ---------------------------------------------------------------------------- // wxMenuItem // ---------------------------------------------------------------------------- @@ -63,6 +64,28 @@ wxMenuItem::~wxMenuItem() { } +bool wxMenuItem::IsChecked() const +{ + return wxMenuItemBase::IsChecked() ; +} + +wxString wxMenuItem::GetLabel() const +{ + return wxStripMenuCodes(m_text); +} + +// accelerators +// ------------ + +#if wxUSE_ACCEL + +wxAcceleratorEntry *wxMenuItem::GetAccel() const +{ + return wxGetAccelFromString(GetText()); +} + +#endif // wxUSE_ACCEL + // misc // ---- @@ -139,4 +162,50 @@ void wxMenuItem::Check(bool bDoCheck) } } } -} \ No newline at end of file +} + +void wxMenuItem::SetText(const wxString& text) +{ + // don't do anything if label didn't change + if ( m_text == text ) + return; + + wxMenuItemBase::SetText(text); +// OWNER_DRAWN_ONLY( wxOwnerDrawn::SetName(text) ); + + wxCHECK_RET( m_parentMenu && m_parentMenu->GetHMenu(), wxT("menuitem without menu") ); + if ( m_parentMenu->GetHMenu() ) + { + int index = m_parentMenu->MacGetIndexFromItem( this ) ; + if ( index >= 1 ) + { + Str255 label; + wxMacBuildMenuString( label , NULL , NULL , text ,false); + ::SetMenuItemText( m_parentMenu->GetHMenu() , index , label ) ; // checkmark + } + } + +#if wxUSE_ACCEL + m_parentMenu->UpdateAccel(this); +#endif // wxUSE_ACCEL + +} +void wxMenuItem::SetCheckable(bool checkable) +{ + wxMenuItemBase::SetCheckable(checkable); + // OWNER_DRAWN_ONLY( wxOwnerDrawn::SetCheckable(checkable) ); +} + +// ---------------------------------------------------------------------------- +// wxMenuItemBase +// ---------------------------------------------------------------------------- + +wxMenuItem *wxMenuItemBase::New(wxMenu *parentMenu, + int id, + const wxString& name, + const wxString& help, + bool isCheckable, + wxMenu *subMenu) +{ + return new wxMenuItem(parentMenu, id, name, help, isCheckable, subMenu); +} diff --git a/src/mac/spinbutt.cpp b/src/mac/spinbutt.cpp index d91374445a..f48ad3de9e 100644 --- a/src/mac/spinbutt.cpp +++ b/src/mac/spinbutt.cpp @@ -126,4 +126,23 @@ void wxSpinButton::MacHandleControlClick( ControlHandle control , SInt16 control GetEventHandler()->ProcessEvent(event); } +// ---------------------------------------------------------------------------- +// size calculation +// ---------------------------------------------------------------------------- + +wxSize wxSpinButton::DoGetBestSize() +{ + if ( (GetWindowStyle() & wxSP_VERTICAL) != 0 ) + { + // vertical control + return wxSize(16, + 2*16); + } + else + { + // horizontal control + return wxSize(2*16, + 16); + } +} diff --git a/src/mac/window.cpp b/src/mac/window.cpp index 18ab38338a..dbfb493a09 100644 --- a/src/mac/window.cpp +++ b/src/mac/window.cpp @@ -295,6 +295,34 @@ void wxWindow::DoGetPosition(int *x, int *y) const } } +wxSize wxWindow::DoGetBestSize() +{ + return wxSize( 0 , 0 ) ; +} + +bool wxWindow::Reparent(wxWindow *parent) +{ + if ( !wxWindowBase::Reparent(parent) ) + return FALSE; + + return TRUE; +} + +bool wxWindow::DoPopupMenu(wxMenu *menu, int x, int y) +{ + menu->SetInvokingWindow(this); + menu->UpdateUI(); + ClientToScreen( &x , &y ) ; + + ::InsertMenu( menu->GetHMenu() , -1 ) ; + long menuResult = ::PopUpMenuSelect(menu->GetHMenu() ,y,x, 0) ; + menu->MacMenuSelect( this , TickCount() , HiWord(menuResult) , LoWord(menuResult) ) ; + ::DeleteMenu( menu->MacGetMenuId() ) ; + menu->SetInvokingWindow(NULL); + + return TRUE; +} + void wxWindow::DoScreenToClient(int *x, int *y) const { WindowRef window = GetMacRootWindow() ; @@ -401,6 +429,28 @@ void wxWindow::DoGetClientSize(int *x, int *y) const (*y) -= MAC_SCROLLBAR_SIZE; } + +// ---------------------------------------------------------------------------- +// tooltips +// ---------------------------------------------------------------------------- + +#if wxUSE_TOOLTIPS + +void wxWindow::DoSetToolTip(wxToolTip *tooltip) +{ + wxWindowBase::DoSetToolTip(tooltip); + +// if ( m_tooltip ) +// m_tooltip->SetWindow(this); +} + +#endif // wxUSE_TOOLTIPS + +void wxWindow::DoMoveWindow(int x, int y, int width, int height) +{ + DoSetSize( x,y, width, height ) ; +} + void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags) { int former_x = m_x ; @@ -1764,13 +1814,3 @@ wxMacDrawingClientHelper::~wxMacDrawingClientHelper() if ( m_formerPort != m_currentPort ) SetPort( m_formerPort ) ; } - -// ---------------------------------------------------------------------------- -// list classes implementation -// ---------------------------------------------------------------------------- - -void wxWindowListNode::DeleteData() -{ - delete (wxWindow *)GetData(); -} -