From 37e2cb08cd1910ec5a14b38f0addfc6e2e8e172e Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Thu, 13 Jan 2000 07:58:45 +0000 Subject: [PATCH] cw pro 5.3 adaptions git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@5367 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/datetime.cpp | 3 + src/common/image.cpp | 32 ----- src/common/log.cpp | 3 + src/common/resource.cpp | 252 ++++++++++++++++++++++++++++++++++++ src/mac/bmpbuttn.cpp | 2 +- src/mac/button.cpp | 2 +- src/mac/carbon/bmpbuttn.cpp | 2 +- src/mac/carbon/button.cpp | 2 +- src/mac/carbon/control.cpp | 21 ++- src/mac/carbon/listbox.cpp | 2 +- src/mac/carbon/menuitem.cpp | 6 + src/mac/carbon/spinbutt.cpp | 2 +- src/mac/carbon/statbmp.cpp | 2 +- src/mac/carbon/toolbar.cpp | 172 ++++++++++++++++-------- src/mac/carbon/window.cpp | 11 +- src/mac/control.cpp | 21 ++- src/mac/listbox.cpp | 2 +- src/mac/menuitem.cpp | 6 + src/mac/spinbutt.cpp | 2 +- src/mac/statbmp.cpp | 2 +- src/mac/toolbar.cpp | 172 ++++++++++++++++-------- src/mac/window.cpp | 11 +- 22 files changed, 550 insertions(+), 180 deletions(-) diff --git a/src/common/datetime.cpp b/src/common/datetime.cpp index 650f65bf1b..4d22420581 100644 --- a/src/common/datetime.cpp +++ b/src/common/datetime.cpp @@ -95,6 +95,9 @@ #ifndef WX_TIMEZONE #if defined(__BORLANDC__) || defined(__MINGW32__) || defined(__VISAGECPP__) #define WX_TIMEZONE _timezone + #elif defined(__WXMAC__) + long wxmac_timezone = 28800; + #define WX_TIMEZONE wxmac_timezone ; #else // unknown platform - try timezone #define WX_TIMEZONE timezone #endif diff --git a/src/common/image.cpp b/src/common/image.cpp index 3fa3751748..bbd261d3cf 100644 --- a/src/common/image.cpp +++ b/src/common/image.cpp @@ -1113,37 +1113,6 @@ wxBitmap wxImage::ConvertToBitmap() const int index = 0; for (int y = 0; y < height; y++) { -#if 0 - unsigned char lastr = 0 ; - unsigned char lastg = 0 ; - unsigned char lastb = 0 ; - RGBColor lastcolor ; - - MoveTo( 0 , y ) ; - for (int x = 0; x < width; x++) - { - unsigned char r = data[index++]; - unsigned char g = data[index++]; - unsigned char b = data[index++]; - - if ( r != lastr || g != lastg || b != lastb ) - { - lastcolor.red = ( lastr << 8 ) + lastr ; - lastcolor.green = ( lastg << 8 ) + lastg ; - lastcolor.blue = ( lastb << 8 ) + lastb ; - RGBForeColor( &lastcolor ) ; - LineTo( x , y ) ; - lastr = r ; - lastg = g ; - lastb = b ; - } - } // for width - lastcolor.red = ( lastr << 8 ) + lastr ; - lastcolor.green = ( lastg << 8 ) + lastg ; - lastcolor.blue = ( lastb << 8 ) + lastb ; - RGBForeColor( &lastcolor ) ; - LineTo( width - 1 , y ) ; -#else for (int x = 0; x < width; x++) { unsigned char r = data[index++]; @@ -1155,7 +1124,6 @@ wxBitmap wxImage::ConvertToBitmap() const color.blue = ( b << 8 ) + b ; SetCPixel( x , y , &color ) ; } -#endif } // for height SetGWorld( origPort , origDevice ) ; diff --git a/src/common/log.cpp b/src/common/log.cpp index 076a9203e6..129b253054 100644 --- a/src/common/log.cpp +++ b/src/common/log.cpp @@ -398,6 +398,9 @@ void wxLogStderr::DoLogString(const wxChar *szString, time_t WXUNUSED(t)) #if defined(__WXMSW__) && wxUSE_GUI OutputDebugString(str + wxT("\r\n")); #endif // MSW +#if defined(__WXMAC__) && wxUSE_GUI + debugstr(str + wxT("\r\n")); +#endif // MSW } // ---------------------------------------------------------------------------- diff --git a/src/common/resource.cpp b/src/common/resource.cpp index e600787ff3..cd930265e0 100644 --- a/src/common/resource.cpp +++ b/src/common/resource.cpp @@ -79,6 +79,7 @@ #include "wx/wxexpr.h" #include "wx/settings.h" +#include "wx/stream.h" // Forward (private) declarations bool wxResourceInterpretResources(wxResourceTable& table, wxExprDatabase& db); @@ -93,6 +94,7 @@ wxItemResource *wxResourceInterpretIcon(wxResourceTable& table, wxExpr *expr); wxFont wxResourceInterpretFontSpec(wxExpr *expr); bool wxResourceReadOneResource(FILE *fd, wxExprDatabase& db, bool *eof, wxResourceTable *table = (wxResourceTable *) NULL); +bool wxResourceReadOneResource(wxInputStream *fd, wxExprDatabase& db, bool *eof, wxResourceTable *table) ; bool wxResourceParseIncludeFile(const wxString& f, wxResourceTable *table = (wxResourceTable *) NULL); wxResourceTable *wxDefaultResourceTable = (wxResourceTable *) NULL; @@ -208,6 +210,19 @@ bool wxResourceTable::DeleteResource(const wxString& name) return FALSE; } +bool wxResourceTable::ParseResourceFile( wxInputStream *is ) +{ + wxExprDatabase db; + int len = is->StreamSize() ; + + bool eof = FALSE; + while ( is->TellI() + 10 < len) // it's a hack because the streams dont support EOF + { + wxResourceReadOneResource(is, db, &eof, this) ; + } + return wxResourceInterpretResources(*this, db); +} + bool wxResourceTable::ParseResourceFile(const wxString& filename) { wxExprDatabase db; @@ -1537,6 +1552,49 @@ static bool wxEatWhiteSpace(FILE *fd) } return FALSE; } +static bool wxEatWhiteSpace(wxInputStream *is) +{ + int ch = is->GetC() ; + if ((ch != ' ') && (ch != '/') && (ch != ' ') && (ch != 10) && (ch != 13) && (ch != 9)) + { + is->Ungetch(ch); + return TRUE; + } + + // Eat whitespace + while (ch == ' ' || ch == 10 || ch == 13 || ch == 9) + ch = is->GetC(); + // Check for comment + if (ch == '/') + { + ch = is->GetC(); + if (ch == '*') + { + bool finished = FALSE; + while (!finished) + { + ch = is->GetC(); + if (ch == EOF) + return FALSE; + if (ch == '*') + { + int newCh = is->GetC(); + if (newCh == '/') + finished = TRUE; + else + { + is->Ungetch(ch); + } + } + } + } + else // False alarm + return FALSE; + } + else + is->Ungetch(ch); + return wxEatWhiteSpace(is); +} bool wxGetResourceToken(FILE *fd) { @@ -1601,6 +1659,71 @@ bool wxGetResourceToken(FILE *fd) return TRUE; } +bool wxGetResourceToken(wxInputStream *is) +{ + if (!wxResourceBuffer) + wxReallocateResourceBuffer(); + wxResourceBuffer[0] = 0; + wxEatWhiteSpace(is); + + int ch = is->GetC() ; + if (ch == '"') + { + // Get string + wxResourceBufferCount = 0; + ch = is->GetC(); + while (ch != '"') + { + int actualCh = ch; + if (ch == EOF) + { + wxResourceBuffer[wxResourceBufferCount] = 0; + return FALSE; + } + // Escaped characters + else if (ch == '\\') + { + int newCh = is->GetC(); + if (newCh == '"') + actualCh = '"'; + else if (newCh == 10) + actualCh = 10; + else if (newCh == 13) // mac + actualCh = 10; + else + { + is->Ungetch(newCh); + } + } + + if (wxResourceBufferCount >= wxResourceBufferSize-1) + wxReallocateResourceBuffer(); + wxResourceBuffer[wxResourceBufferCount] = (char)actualCh; + wxResourceBufferCount ++; + ch = is->GetC(); + } + wxResourceBuffer[wxResourceBufferCount] = 0; + } + else + { + wxResourceBufferCount = 0; + // Any other token + while (ch != ' ' && ch != EOF && ch != ' ' && ch != 13 && ch != 9 && ch != 10) + { + if (wxResourceBufferCount >= wxResourceBufferSize-1) + wxReallocateResourceBuffer(); + wxResourceBuffer[wxResourceBufferCount] = (char)ch; + wxResourceBufferCount ++; + + ch = is->GetC(); + } + wxResourceBuffer[wxResourceBufferCount] = 0; + if (ch == EOF) + return FALSE; + } + return TRUE; +} + /* * Files are in form: static char *name = "...."; @@ -1737,6 +1860,135 @@ bool wxResourceReadOneResource(FILE *fd, wxExprDatabase& db, bool *eof, wxResour return TRUE; } +bool wxResourceReadOneResource(wxInputStream *fd, wxExprDatabase& db, bool *eof, wxResourceTable *table) +{ + if (!table) + table = wxDefaultResourceTable; + + // static or #define + if (!wxGetResourceToken(fd)) + { + *eof = TRUE; + return FALSE; + } + + if (strcmp(wxResourceBuffer, "#define") == 0) + { + wxGetResourceToken(fd); + char *name = copystring(wxResourceBuffer); + wxGetResourceToken(fd); + char *value = copystring(wxResourceBuffer); + if (isalpha(value[0])) + { + int val = (int)atol(value); + wxResourceAddIdentifier(name, val, table); + } + else + { + wxLogWarning(_("#define %s must be an integer."), name); + delete[] name; + delete[] value; + return FALSE; + } + delete[] name; + delete[] value; + + return TRUE; + } + else if (strcmp(wxResourceBuffer, "#include") == 0) + { + wxGetResourceToken(fd); + char *name = copystring(wxResourceBuffer); + char *actualName = name; + if (name[0] == '"') + actualName = name + 1; + int len = strlen(name); + if ((len > 0) && (name[len-1] == '"')) + name[len-1] = 0; + if (!wxResourceParseIncludeFile(actualName, table)) + { + wxLogWarning(_("Could not find resource include file %s."), actualName); + } + delete[] name; + return TRUE; + } + else if (strcmp(wxResourceBuffer, "static") != 0) + { + char buf[300]; + strcpy(buf, _("Found ")); + strncat(buf, wxResourceBuffer, 30); + strcat(buf, _(", expected static, #include or #define\nwhilst parsing resource.")); + wxLogWarning(buf); + return FALSE; + } + + // char + if (!wxGetResourceToken(fd)) + { + wxLogWarning(_("Unexpected end of file whilst parsing resource.")); + *eof = TRUE; + return FALSE; + } + + if (strcmp(wxResourceBuffer, "char") != 0) + { + wxLogWarning(_("Expected 'char' whilst parsing resource.")); + return FALSE; + } + + // *name + if (!wxGetResourceToken(fd)) + { + wxLogWarning(_("Unexpected end of file whilst parsing resource.")); + *eof = TRUE; + return FALSE; + } + + if (wxResourceBuffer[0] != '*') + { + wxLogWarning(_("Expected '*' whilst parsing resource.")); + return FALSE; + } + char nameBuf[100]; + strncpy(nameBuf, wxResourceBuffer+1, 99); + + // = + if (!wxGetResourceToken(fd)) + { + wxLogWarning(_("Unexpected end of file whilst parsing resource.")); + *eof = TRUE; + return FALSE; + } + + if (strcmp(wxResourceBuffer, "=") != 0) + { + wxLogWarning(_("Expected '=' whilst parsing resource.")); + return FALSE; + } + + // String + if (!wxGetResourceToken(fd)) + { + wxLogWarning(_("Unexpected end of file whilst parsing resource.")); + *eof = TRUE; + return FALSE; + } + else + { + if (!db.ReadPrologFromString(wxResourceBuffer)) + { + wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf); + return FALSE; + } + } + // Semicolon + if (!wxGetResourceToken(fd)) + { + *eof = TRUE; + } + return TRUE; +} + /* * Parses string window style into integer window style */ diff --git a/src/mac/bmpbuttn.cpp b/src/mac/bmpbuttn.cpp index 7c8d8d5b31..f435ab2b32 100644 --- a/src/mac/bmpbuttn.cpp +++ b/src/mac/bmpbuttn.cpp @@ -56,7 +56,7 @@ bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bit m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , true , 0 , kControlBehaviorOffsetContents + kControlContentPictHandle , 0, - kControlBevelButtonNormalBevelProc , (long) this ) ; + (( style & wxBU_AUTODRAW ) ? kControlBevelButtonSmallBevelProc : kControlBevelButtonNormalBevelProc ), (long) this ) ; wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ; m_buttonBitmap = bitmap; diff --git a/src/mac/button.cpp b/src/mac/button.cpp index 849aeee0e3..4635492a17 100644 --- a/src/mac/button.cpp +++ b/src/mac/button.cpp @@ -64,7 +64,7 @@ void wxButton::SetDefault() } } -wxSize wxButton::DoGetBestSize() +wxSize wxButton::DoGetBestSize() const { int wBtn = m_label.Length() * 8 + 12 + 2 * m_macHorizontalBorder; int hBtn = 13 + 2 * m_macVerticalBorder; diff --git a/src/mac/carbon/bmpbuttn.cpp b/src/mac/carbon/bmpbuttn.cpp index 7c8d8d5b31..f435ab2b32 100644 --- a/src/mac/carbon/bmpbuttn.cpp +++ b/src/mac/carbon/bmpbuttn.cpp @@ -56,7 +56,7 @@ bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bit m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , true , 0 , kControlBehaviorOffsetContents + kControlContentPictHandle , 0, - kControlBevelButtonNormalBevelProc , (long) this ) ; + (( style & wxBU_AUTODRAW ) ? kControlBevelButtonSmallBevelProc : kControlBevelButtonNormalBevelProc ), (long) this ) ; wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ; m_buttonBitmap = bitmap; diff --git a/src/mac/carbon/button.cpp b/src/mac/carbon/button.cpp index 849aeee0e3..4635492a17 100644 --- a/src/mac/carbon/button.cpp +++ b/src/mac/carbon/button.cpp @@ -64,7 +64,7 @@ void wxButton::SetDefault() } } -wxSize wxButton::DoGetBestSize() +wxSize wxButton::DoGetBestSize() const { int wBtn = m_label.Length() * 8 + 12 + 2 * m_macHorizontalBorder; int hBtn = 13 + 2 * m_macVerticalBorder; diff --git a/src/mac/carbon/control.cpp b/src/mac/carbon/control.cpp index 5065b239e9..122f58de8f 100644 --- a/src/mac/carbon/control.cpp +++ b/src/mac/carbon/control.cpp @@ -18,9 +18,9 @@ #include "wx/tabctrl.h" #include "wx/spinbutt.h" -IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow) +IMPLEMENT_ABSTRACT_CLASS(wxControl, wxControlBase) -BEGIN_EVENT_TABLE(wxControl, wxWindow) +BEGIN_EVENT_TABLE(wxControl, wxControlBase) EVT_MOUSE_EVENTS( wxControl::OnMouseEvent ) EVT_CHAR( wxControl::OnKeyDown ) EVT_PAINT( wxControl::OnPaint ) @@ -79,6 +79,21 @@ wxControl::~wxControl() } } +bool wxControl::Create(wxWindow *parent, wxWindowID id, + const wxPoint& pos, + const wxSize& size, long style, + const wxValidator& validator, + const wxString& name) +{ + bool rval = wxWindow::Create(parent, id, pos, size, style, name); + if (rval) { +#if wxUSE_VALIDATORS + SetValidator(validator); +#endif + } + return rval; +} + void wxControl::SetLabel(const wxString& title) { m_label = title ; @@ -100,7 +115,7 @@ void wxControl::SetLabel(const wxString& title) } } -wxSize wxControl::DoGetBestSize() +wxSize wxControl::DoGetBestSize() const { return wxSize(20, 20); } diff --git a/src/mac/carbon/listbox.cpp b/src/mac/carbon/listbox.cpp index ae89e0bcab..3b062f04e5 100644 --- a/src/mac/carbon/listbox.cpp +++ b/src/mac/carbon/listbox.cpp @@ -369,7 +369,7 @@ void wxListBox::SetString(int N, const wxString& s) MacSet( N , s ) ; } -wxSize wxListBox::DoGetBestSize() +wxSize wxListBox::DoGetBestSize() const { return wxSize(100, 100); } diff --git a/src/mac/carbon/menuitem.cpp b/src/mac/carbon/menuitem.cpp index 83ae7e0d84..22b07f575d 100644 --- a/src/mac/carbon/menuitem.cpp +++ b/src/mac/carbon/menuitem.cpp @@ -28,6 +28,12 @@ IMPLEMENT_DYNAMIC_CLASS(wxMenuItem, wxObject) void wxMacBuildMenuString(StringPtr outMacItemText, char *outMacShortcutChar , short *outMacModifiers , const char *inItemName , bool useShortcuts ) ; + +wxString wxMenuItemBase::GetLabelFromText(const wxString& text) +{ + return wxStripMenuCodes(text); +} + // ---------------------------------------------------------------------------- // wxMenuItem // ---------------------------------------------------------------------------- diff --git a/src/mac/carbon/spinbutt.cpp b/src/mac/carbon/spinbutt.cpp index 5ec5e1b8a2..944f72dc10 100644 --- a/src/mac/carbon/spinbutt.cpp +++ b/src/mac/carbon/spinbutt.cpp @@ -128,7 +128,7 @@ void wxSpinButton::MacHandleControlClick( ControlHandle control , SInt16 control // size calculation // ---------------------------------------------------------------------------- -wxSize wxSpinButton::DoGetBestSize() +wxSize wxSpinButton::DoGetBestSize() const { if ( (GetWindowStyle() & wxSP_VERTICAL) != 0 ) { diff --git a/src/mac/carbon/statbmp.cpp b/src/mac/carbon/statbmp.cpp index 8bd5fecb71..ce1e5d1ec8 100644 --- a/src/mac/carbon/statbmp.cpp +++ b/src/mac/carbon/statbmp.cpp @@ -46,7 +46,7 @@ bool wxStaticBitmap::Create(wxWindow *parent, wxWindowID id, m_windowStyle = style; - bool ret = wxControl::Create( parent, id, pos, size, style , name ); + bool ret = wxControl::Create( parent, id, pos, size, style , wxDefaultValidator , name ); SetSizeOrDefault() ; diff --git a/src/mac/carbon/toolbar.cpp b/src/mac/carbon/toolbar.cpp index 81d3711a54..26f3a748cb 100644 --- a/src/mac/carbon/toolbar.cpp +++ b/src/mac/carbon/toolbar.cpp @@ -26,7 +26,76 @@ END_EVENT_TABLE() #include -wxToolBar::wxToolBar() +// ---------------------------------------------------------------------------- +// private classes +// ---------------------------------------------------------------------------- + +class wxToolBarTool : public wxToolBarToolBase +{ +public: + wxToolBarTool(wxToolBar *tbar, + int id, + const wxBitmap& bitmap1, + const wxBitmap& bitmap2, + bool toggle, + wxObject *clientData, + const wxString& shortHelpString, + const wxString& longHelpString) + : wxToolBarToolBase(tbar, id, bitmap1, bitmap2, toggle, + clientData, shortHelpString, longHelpString) + { + m_nSepCount = 0; + m_index = 0 ; + } + + wxToolBarTool(wxToolBar *tbar, wxControl *control) + : wxToolBarToolBase(tbar, control) + { + m_nSepCount = 1; + m_index = 0 ; + } + + // set/get the number of separators which we use to cover the space used by + // a control in the toolbar + void SetSeparatorsCount(size_t count) { m_nSepCount = count; } + size_t GetSeparatorsCount() const { return m_nSepCount; } + + int m_index ; +private: + size_t m_nSepCount; +}; + + +// ============================================================================ +// implementation +// ============================================================================ + +// ---------------------------------------------------------------------------- +// wxToolBarTool +// ---------------------------------------------------------------------------- + +wxToolBarToolBase *wxToolBar::CreateTool(int id, + const wxBitmap& bitmap1, + const wxBitmap& bitmap2, + bool toggle, + wxObject *clientData, + const wxString& shortHelpString, + const wxString& longHelpString) +{ + return new wxToolBarTool(this, id, bitmap1, bitmap2, toggle, + clientData, shortHelpString, longHelpString); +} + +wxToolBarToolBase *wxToolBar::CreateTool(wxControl *control) +{ + return new wxToolBarTool(this, control); +} + +// ---------------------------------------------------------------------------- +// wxToolBar construction +// ---------------------------------------------------------------------------- + +void wxToolBar::Init() { m_maxWidth = -1; m_maxHeight = -1; @@ -135,7 +204,7 @@ PicHandle MakePictWhite(GWorldPtr wp) const short kwxMacToolBarTopMargin = 2 ; const short kwxMacToolBarLeftMargin = 2 ; -bool wxToolBar::CreateTools() +bool wxToolBar::Realize() { if (m_tools.Number() == 0) return FALSE; @@ -155,9 +224,9 @@ bool wxToolBar::CreateTools() while (node) { wxToolBarTool *tool = (wxToolBarTool *)node->Data(); - wxBitmapRefData * bmap = (wxBitmapRefData*) ( tool->m_bitmap1.GetRefData()) ; + wxBitmapRefData * bmap = (wxBitmapRefData*) ( tool->GetBitmap1().GetRefData()) ; - if( tool->m_toolStyle != wxTOOL_STYLE_SEPARATOR ) + if( !tool->IsSeparator() ) { Rect toolrect = { toolbarrect.top + kwxMacToolBarTopMargin , toolbarrect.left + x + kwxMacToolBarLeftMargin , 0 , 0 } ; toolrect.right = toolrect.left + toolSize.x ; @@ -235,11 +304,6 @@ void wxToolBar::SetToolBitmapSize(const wxSize& size) m_defaultWidth = size.x; m_defaultHeight = size.y; } -wxSize wxToolBar::GetMaxSize() const -{ - return wxSize(m_maxWidth, m_maxHeight); -} - // The button size is bigger than the bitmap size wxSize wxToolBar::GetToolSize() const { @@ -253,73 +317,69 @@ void wxToolBar::MacHandleControlClick( ControlHandle control , SInt16 controlpar { if ( m_macToolHandles[index] == (void*) control ) { - OnLeftClick( ( (wxToolBarTool*) (m_tools.Nth( index )->Data() ) ) ->m_index , ( (wxToolBarTool*) (m_tools.Nth( index )->Data() ) ) ->m_toggleState ) ; + OnLeftClick( ( (wxToolBarTool*) (m_tools.Nth( index )->Data() ) ) ->m_index , ( (wxToolBarTool*) (m_tools.Nth( index )->Data() ) ) ->IsToggled() ) ; } } } -void wxToolBar::EnableTool(int toolIndex, bool enable) +void wxToolBar::SetRows(int nRows) { - wxNode *node = m_tools.Find((long)toolIndex); - if (node) + if ( nRows == m_maxRows ) { - wxToolBarTool *tool = (wxToolBarTool *)node->Data(); - tool->m_enabled = enable; - // TODO enable button + // avoid resizing the frame uselessly + return; } + + m_maxRows = nRows; } -void wxToolBar::ToggleTool(int toolIndex, bool toggle) +wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord x, wxCoord y) const { - wxNode *node = m_tools.Find((long)toolIndex); - if (node) - { - wxToolBarTool *tool = (wxToolBarTool *)node->Data(); - if (tool->m_isToggle) - { - tool->m_toggleState = toggle; - // TODO: set toggle state - } - } + MacClientToRootWindow( &x , &y ) ; + Point pt = { x ,y } ; + + int index = 0 ; + for ( index = 0 ; index < m_macToolHandles.Count() ; ++index ) + { + if ( PtInRect( pt , &(**(ControlHandle)(m_macToolHandles[index])).contrlRect) ) + { + return (wxToolBarTool*) (m_tools.Nth( index )->Data() ) ; + } + } + + return (wxToolBarToolBase *)NULL; } -void wxToolBar::ClearTools() +void wxToolBar::DoEnableTool(wxToolBarToolBase *t, bool enable) { - // TODO - wxToolBarBase::ClearTools(); + wxToolBarTool *tool = (wxToolBarTool *)t; } -// If pushedBitmap is NULL, a reversed version of bitmap is -// created and used as the pushed/toggled image. -// If toggle is TRUE, the button toggles between the two states. - -wxToolBarTool *wxToolBar::AddTool(int index, const wxBitmap& bitmap, const wxBitmap& pushedBitmap, - bool toggle, long xPos, long yPos, wxObject *clientData, const wxString& helpString1, const wxString& helpString2) +void wxToolBar::DoToggleTool(wxToolBarToolBase *t, bool toggle) { - wxToolBarTool *tool = new wxToolBarTool(index, bitmap, wxNullBitmap, toggle, xPos, yPos, helpString1, helpString2); - tool->m_clientData = clientData; - - if (xPos > -1) - tool->m_x = xPos; - else - tool->m_x = m_xMargin; - - if (yPos > -1) - tool->m_y = yPos; - else - tool->m_y = m_yMargin; - - tool->SetSize(GetToolSize().x, GetToolSize().y); + wxToolBarTool *tool = (wxToolBarTool *)t; + // TODO: set toggle state +} - if ((tool->m_x + bitmap.GetWidth() + m_xMargin) > m_maxWidth) - m_maxWidth = (tool->m_x + tool->GetWidth() + m_xMargin); +bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), + wxToolBarToolBase *tool) +{ + // nothing special to do here - we really create the toolbar buttons in + // Realize() later + tool->Attach(this); - if ((tool->m_y + bitmap.GetHeight() + m_yMargin) > m_maxHeight) - m_maxHeight = (tool->m_y + tool->GetHeight() + m_yMargin); + return TRUE; +} - m_tools.Append((long)index, tool); - return tool; +void wxToolBar::DoSetToggle(wxToolBarToolBase *t, bool toggle) +{ + wxToolBarTool *tool = (wxToolBarTool *)t; + // TODO: set toggle state } +bool wxToolBar::DoDeleteTool(size_t pos, wxToolBarToolBase *tool) +{ + return TRUE ; +} #endif // wxUSE_TOOLBAR diff --git a/src/mac/carbon/window.cpp b/src/mac/carbon/window.cpp index cae38465c2..516e3ba7b7 100644 --- a/src/mac/carbon/window.cpp +++ b/src/mac/carbon/window.cpp @@ -318,18 +318,9 @@ 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) { diff --git a/src/mac/control.cpp b/src/mac/control.cpp index 5065b239e9..122f58de8f 100644 --- a/src/mac/control.cpp +++ b/src/mac/control.cpp @@ -18,9 +18,9 @@ #include "wx/tabctrl.h" #include "wx/spinbutt.h" -IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow) +IMPLEMENT_ABSTRACT_CLASS(wxControl, wxControlBase) -BEGIN_EVENT_TABLE(wxControl, wxWindow) +BEGIN_EVENT_TABLE(wxControl, wxControlBase) EVT_MOUSE_EVENTS( wxControl::OnMouseEvent ) EVT_CHAR( wxControl::OnKeyDown ) EVT_PAINT( wxControl::OnPaint ) @@ -79,6 +79,21 @@ wxControl::~wxControl() } } +bool wxControl::Create(wxWindow *parent, wxWindowID id, + const wxPoint& pos, + const wxSize& size, long style, + const wxValidator& validator, + const wxString& name) +{ + bool rval = wxWindow::Create(parent, id, pos, size, style, name); + if (rval) { +#if wxUSE_VALIDATORS + SetValidator(validator); +#endif + } + return rval; +} + void wxControl::SetLabel(const wxString& title) { m_label = title ; @@ -100,7 +115,7 @@ void wxControl::SetLabel(const wxString& title) } } -wxSize wxControl::DoGetBestSize() +wxSize wxControl::DoGetBestSize() const { return wxSize(20, 20); } diff --git a/src/mac/listbox.cpp b/src/mac/listbox.cpp index ae89e0bcab..3b062f04e5 100644 --- a/src/mac/listbox.cpp +++ b/src/mac/listbox.cpp @@ -369,7 +369,7 @@ void wxListBox::SetString(int N, const wxString& s) MacSet( N , s ) ; } -wxSize wxListBox::DoGetBestSize() +wxSize wxListBox::DoGetBestSize() const { return wxSize(100, 100); } diff --git a/src/mac/menuitem.cpp b/src/mac/menuitem.cpp index 83ae7e0d84..22b07f575d 100644 --- a/src/mac/menuitem.cpp +++ b/src/mac/menuitem.cpp @@ -28,6 +28,12 @@ IMPLEMENT_DYNAMIC_CLASS(wxMenuItem, wxObject) void wxMacBuildMenuString(StringPtr outMacItemText, char *outMacShortcutChar , short *outMacModifiers , const char *inItemName , bool useShortcuts ) ; + +wxString wxMenuItemBase::GetLabelFromText(const wxString& text) +{ + return wxStripMenuCodes(text); +} + // ---------------------------------------------------------------------------- // wxMenuItem // ---------------------------------------------------------------------------- diff --git a/src/mac/spinbutt.cpp b/src/mac/spinbutt.cpp index 5ec5e1b8a2..944f72dc10 100644 --- a/src/mac/spinbutt.cpp +++ b/src/mac/spinbutt.cpp @@ -128,7 +128,7 @@ void wxSpinButton::MacHandleControlClick( ControlHandle control , SInt16 control // size calculation // ---------------------------------------------------------------------------- -wxSize wxSpinButton::DoGetBestSize() +wxSize wxSpinButton::DoGetBestSize() const { if ( (GetWindowStyle() & wxSP_VERTICAL) != 0 ) { diff --git a/src/mac/statbmp.cpp b/src/mac/statbmp.cpp index 8bd5fecb71..ce1e5d1ec8 100644 --- a/src/mac/statbmp.cpp +++ b/src/mac/statbmp.cpp @@ -46,7 +46,7 @@ bool wxStaticBitmap::Create(wxWindow *parent, wxWindowID id, m_windowStyle = style; - bool ret = wxControl::Create( parent, id, pos, size, style , name ); + bool ret = wxControl::Create( parent, id, pos, size, style , wxDefaultValidator , name ); SetSizeOrDefault() ; diff --git a/src/mac/toolbar.cpp b/src/mac/toolbar.cpp index 81d3711a54..26f3a748cb 100644 --- a/src/mac/toolbar.cpp +++ b/src/mac/toolbar.cpp @@ -26,7 +26,76 @@ END_EVENT_TABLE() #include -wxToolBar::wxToolBar() +// ---------------------------------------------------------------------------- +// private classes +// ---------------------------------------------------------------------------- + +class wxToolBarTool : public wxToolBarToolBase +{ +public: + wxToolBarTool(wxToolBar *tbar, + int id, + const wxBitmap& bitmap1, + const wxBitmap& bitmap2, + bool toggle, + wxObject *clientData, + const wxString& shortHelpString, + const wxString& longHelpString) + : wxToolBarToolBase(tbar, id, bitmap1, bitmap2, toggle, + clientData, shortHelpString, longHelpString) + { + m_nSepCount = 0; + m_index = 0 ; + } + + wxToolBarTool(wxToolBar *tbar, wxControl *control) + : wxToolBarToolBase(tbar, control) + { + m_nSepCount = 1; + m_index = 0 ; + } + + // set/get the number of separators which we use to cover the space used by + // a control in the toolbar + void SetSeparatorsCount(size_t count) { m_nSepCount = count; } + size_t GetSeparatorsCount() const { return m_nSepCount; } + + int m_index ; +private: + size_t m_nSepCount; +}; + + +// ============================================================================ +// implementation +// ============================================================================ + +// ---------------------------------------------------------------------------- +// wxToolBarTool +// ---------------------------------------------------------------------------- + +wxToolBarToolBase *wxToolBar::CreateTool(int id, + const wxBitmap& bitmap1, + const wxBitmap& bitmap2, + bool toggle, + wxObject *clientData, + const wxString& shortHelpString, + const wxString& longHelpString) +{ + return new wxToolBarTool(this, id, bitmap1, bitmap2, toggle, + clientData, shortHelpString, longHelpString); +} + +wxToolBarToolBase *wxToolBar::CreateTool(wxControl *control) +{ + return new wxToolBarTool(this, control); +} + +// ---------------------------------------------------------------------------- +// wxToolBar construction +// ---------------------------------------------------------------------------- + +void wxToolBar::Init() { m_maxWidth = -1; m_maxHeight = -1; @@ -135,7 +204,7 @@ PicHandle MakePictWhite(GWorldPtr wp) const short kwxMacToolBarTopMargin = 2 ; const short kwxMacToolBarLeftMargin = 2 ; -bool wxToolBar::CreateTools() +bool wxToolBar::Realize() { if (m_tools.Number() == 0) return FALSE; @@ -155,9 +224,9 @@ bool wxToolBar::CreateTools() while (node) { wxToolBarTool *tool = (wxToolBarTool *)node->Data(); - wxBitmapRefData * bmap = (wxBitmapRefData*) ( tool->m_bitmap1.GetRefData()) ; + wxBitmapRefData * bmap = (wxBitmapRefData*) ( tool->GetBitmap1().GetRefData()) ; - if( tool->m_toolStyle != wxTOOL_STYLE_SEPARATOR ) + if( !tool->IsSeparator() ) { Rect toolrect = { toolbarrect.top + kwxMacToolBarTopMargin , toolbarrect.left + x + kwxMacToolBarLeftMargin , 0 , 0 } ; toolrect.right = toolrect.left + toolSize.x ; @@ -235,11 +304,6 @@ void wxToolBar::SetToolBitmapSize(const wxSize& size) m_defaultWidth = size.x; m_defaultHeight = size.y; } -wxSize wxToolBar::GetMaxSize() const -{ - return wxSize(m_maxWidth, m_maxHeight); -} - // The button size is bigger than the bitmap size wxSize wxToolBar::GetToolSize() const { @@ -253,73 +317,69 @@ void wxToolBar::MacHandleControlClick( ControlHandle control , SInt16 controlpar { if ( m_macToolHandles[index] == (void*) control ) { - OnLeftClick( ( (wxToolBarTool*) (m_tools.Nth( index )->Data() ) ) ->m_index , ( (wxToolBarTool*) (m_tools.Nth( index )->Data() ) ) ->m_toggleState ) ; + OnLeftClick( ( (wxToolBarTool*) (m_tools.Nth( index )->Data() ) ) ->m_index , ( (wxToolBarTool*) (m_tools.Nth( index )->Data() ) ) ->IsToggled() ) ; } } } -void wxToolBar::EnableTool(int toolIndex, bool enable) +void wxToolBar::SetRows(int nRows) { - wxNode *node = m_tools.Find((long)toolIndex); - if (node) + if ( nRows == m_maxRows ) { - wxToolBarTool *tool = (wxToolBarTool *)node->Data(); - tool->m_enabled = enable; - // TODO enable button + // avoid resizing the frame uselessly + return; } + + m_maxRows = nRows; } -void wxToolBar::ToggleTool(int toolIndex, bool toggle) +wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord x, wxCoord y) const { - wxNode *node = m_tools.Find((long)toolIndex); - if (node) - { - wxToolBarTool *tool = (wxToolBarTool *)node->Data(); - if (tool->m_isToggle) - { - tool->m_toggleState = toggle; - // TODO: set toggle state - } - } + MacClientToRootWindow( &x , &y ) ; + Point pt = { x ,y } ; + + int index = 0 ; + for ( index = 0 ; index < m_macToolHandles.Count() ; ++index ) + { + if ( PtInRect( pt , &(**(ControlHandle)(m_macToolHandles[index])).contrlRect) ) + { + return (wxToolBarTool*) (m_tools.Nth( index )->Data() ) ; + } + } + + return (wxToolBarToolBase *)NULL; } -void wxToolBar::ClearTools() +void wxToolBar::DoEnableTool(wxToolBarToolBase *t, bool enable) { - // TODO - wxToolBarBase::ClearTools(); + wxToolBarTool *tool = (wxToolBarTool *)t; } -// If pushedBitmap is NULL, a reversed version of bitmap is -// created and used as the pushed/toggled image. -// If toggle is TRUE, the button toggles between the two states. - -wxToolBarTool *wxToolBar::AddTool(int index, const wxBitmap& bitmap, const wxBitmap& pushedBitmap, - bool toggle, long xPos, long yPos, wxObject *clientData, const wxString& helpString1, const wxString& helpString2) +void wxToolBar::DoToggleTool(wxToolBarToolBase *t, bool toggle) { - wxToolBarTool *tool = new wxToolBarTool(index, bitmap, wxNullBitmap, toggle, xPos, yPos, helpString1, helpString2); - tool->m_clientData = clientData; - - if (xPos > -1) - tool->m_x = xPos; - else - tool->m_x = m_xMargin; - - if (yPos > -1) - tool->m_y = yPos; - else - tool->m_y = m_yMargin; - - tool->SetSize(GetToolSize().x, GetToolSize().y); + wxToolBarTool *tool = (wxToolBarTool *)t; + // TODO: set toggle state +} - if ((tool->m_x + bitmap.GetWidth() + m_xMargin) > m_maxWidth) - m_maxWidth = (tool->m_x + tool->GetWidth() + m_xMargin); +bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), + wxToolBarToolBase *tool) +{ + // nothing special to do here - we really create the toolbar buttons in + // Realize() later + tool->Attach(this); - if ((tool->m_y + bitmap.GetHeight() + m_yMargin) > m_maxHeight) - m_maxHeight = (tool->m_y + tool->GetHeight() + m_yMargin); + return TRUE; +} - m_tools.Append((long)index, tool); - return tool; +void wxToolBar::DoSetToggle(wxToolBarToolBase *t, bool toggle) +{ + wxToolBarTool *tool = (wxToolBarTool *)t; + // TODO: set toggle state } +bool wxToolBar::DoDeleteTool(size_t pos, wxToolBarToolBase *tool) +{ + return TRUE ; +} #endif // wxUSE_TOOLBAR diff --git a/src/mac/window.cpp b/src/mac/window.cpp index cae38465c2..516e3ba7b7 100644 --- a/src/mac/window.cpp +++ b/src/mac/window.cpp @@ -318,18 +318,9 @@ 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) { -- 2.45.2