diff --git a/common/string_utils.cpp b/common/string_utils.cpp index 63ef6593f5..ac2d4ebe65 100644 --- a/common/string_utils.cpp +++ b/common/string_utils.cpp @@ -646,8 +646,8 @@ wxString RemoveHTMLTags( const wxString& aInput ) wxString LinkifyHTML( wxString aStr ) { - wxRegEx regex( wxS( "\\b(https?|ftp|file)://([-\\w+&@#/%?=~|!:,.;]*[^.,:;<>\\s\u00b6])" ), - wxRE_ICASE ); + static wxRegEx regex( wxS( "\\b(https?|ftp|file)://([-\\w+&@#/%?=~|!:,.;]*[^.,:;<>\\s\u00b6])" ), + wxRE_ICASE ); regex.ReplaceAll( &aStr, "<a href=\"\\0\">\\0</a>" ); @@ -655,6 +655,17 @@ wxString LinkifyHTML( wxString aStr ) } +bool IsURL( wxString aStr ) +{ + static wxRegEx regex( wxS( "(https?|ftp|file)://([-\\w+&@#/%?=~|!:,.;]*[^.,:;<>\\s\u00b6])" ), + wxRE_ICASE ); + + regex.ReplaceAll( &aStr, "<a href=\"\\0\">\\0</a>" ); + + return regex.Matches( aStr ); +} + + bool NoPrintableChars( const wxString& aString ) { wxString tmp = aString; diff --git a/eeschema/sch_painter.cpp b/eeschema/sch_painter.cpp index 5fa4662fae..4002b9e88e 100644 --- a/eeschema/sch_painter.cpp +++ b/eeschema/sch_painter.cpp @@ -1757,7 +1757,7 @@ void SCH_PAINTER::draw( const SCH_TEXT* aText, int aLayer, bool aDimmed ) } else { - if( aText->IsHypertext() && aText->IsRollover() ) + if( aText->IsHypertext() && aText->IsRollover() && !aText->IsMoving() ) { m_gal->SetStrokeColor( m_schSettings.GetLayerColor( LAYER_HOVERED ) ); m_gal->SetFillColor( m_schSettings.GetLayerColor( LAYER_HOVERED ) ); @@ -1876,7 +1876,7 @@ void SCH_PAINTER::draw( const SCH_TEXTBOX* aTextBox, int aLayer, bool aDimmed ) attrs.m_Angle = aTextBox->GetDrawRotation(); attrs.m_StrokeWidth = KiROUND( getTextThickness( aTextBox ) ); - if( aTextBox->IsHypertext() && aTextBox->IsRollover() ) + if( aTextBox->IsHypertext() && aTextBox->IsRollover() && !aTextBox->IsMoving() ) { m_gal->SetStrokeColor( m_schSettings.GetLayerColor( LAYER_HOVERED ) ); m_gal->SetFillColor( m_schSettings.GetLayerColor( LAYER_HOVERED ) ); @@ -2390,7 +2390,7 @@ void SCH_PAINTER::draw( const SCH_FIELD* aField, int aLayer, bool aDimmed ) if( drawingShadows ) attributes.m_StrokeWidth += getShadowWidth( !aField->IsSelected() ); - if( aField->IsHypertext() && aField->IsRollover() ) + if( aField->IsHypertext() && aField->IsRollover() && !aField->IsMoving() ) { m_gal->SetStrokeColor( m_schSettings.GetLayerColor( LAYER_HOVERED ) ); m_gal->SetFillColor( m_schSettings.GetLayerColor( LAYER_HOVERED ) ); diff --git a/eeschema/sch_textbox.cpp b/eeschema/sch_textbox.cpp index 521e60ab14..ac2593246c 100644 --- a/eeschema/sch_textbox.cpp +++ b/eeschema/sch_textbox.cpp @@ -407,13 +407,26 @@ bool SCH_TEXTBOX::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) } +bool SCH_TEXTBOX::IsHypertext() const +{ + if( HasHyperlink() ) + return true; + + return IsURL( GetShownText( false ) ); +} + + void SCH_TEXTBOX::DoHypertextAction( EDA_DRAW_FRAME* aFrame ) const { wxCHECK_MSG( IsHypertext(), /* void */, wxT( "Calling a hypertext menu on a SCH_TEXTBOX with no hyperlink?" ) ); SCH_NAVIGATE_TOOL* navTool = aFrame->GetToolManager()->GetTool<SCH_NAVIGATE_TOOL>(); - navTool->HypertextCommand( m_hyperlink ); + + if( HasHyperlink() ) + navTool->HypertextCommand( m_hyperlink ); + else + navTool->HypertextCommand( GetShownText( false ) ); } diff --git a/eeschema/sch_textbox.h b/eeschema/sch_textbox.h index e0f47a3120..e33ccb262e 100644 --- a/eeschema/sch_textbox.h +++ b/eeschema/sch_textbox.h @@ -83,11 +83,7 @@ public: return GetShownText( sheetPath, aAllowExtraText, aDepth ); } - bool IsHypertext() const override - { - return HasHyperlink(); - } - + bool IsHypertext() const override; void DoHypertextAction( EDA_DRAW_FRAME* aFrame ) const override; void SetExcludedFromSim( bool aExclude ) override { m_excludedFromSim = aExclude; } diff --git a/eeschema/tools/ee_selection_tool.cpp b/eeschema/tools/ee_selection_tool.cpp index 5a7d6b8e1f..f9345ce182 100644 --- a/eeschema/tools/ee_selection_tool.cpp +++ b/eeschema/tools/ee_selection_tool.cpp @@ -1000,14 +1000,15 @@ int EE_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) evt->SetPassEvent(); } - if( rolloverItem != lastRolloverItem ) + if( lastRolloverItem != niluuid && lastRolloverItem != rolloverItem ) { - if( EDA_ITEM* item = m_frame->GetItem( lastRolloverItem ) ) - { - item->ClearFlags( IS_ROLLOVER ); - lastRolloverItem = niluuid; + EDA_ITEM* item = m_frame->GetItem( lastRolloverItem ); - if( item->Type() == SCH_FIELD_T ) + if( item->IsRollover() ) + { + item->SetIsRollover( false ); + + if( item->Type() == SCH_FIELD_T || item->Type() == SCH_TABLECELL_T ) m_frame->GetCanvas()->GetView()->Update( item->GetParent() ); else m_frame->GetCanvas()->GetView()->Update( item ); @@ -1018,18 +1019,19 @@ int EE_SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) { EDA_ITEM* item = m_frame->GetItem( rolloverItem ); - if( item && !( item->GetFlags() & IS_ROLLOVER ) ) + if( !item->IsRollover() ) { - item->SetFlags( IS_ROLLOVER ); - lastRolloverItem = rolloverItem; + item->SetIsRollover( true ); - if( item->Type() == SCH_FIELD_T ) + if( item->Type() == SCH_FIELD_T || item->Type() == SCH_TABLECELL_T ) m_frame->GetCanvas()->GetView()->Update( item->GetParent() ); else m_frame->GetCanvas()->GetView()->Update( item ); } } + lastRolloverItem = rolloverItem; + if( m_frame->ToolStackIsEmpty() ) { if( displayWireCursor ) diff --git a/include/eda_item.h b/include/eda_item.h index d61d8eb4d8..d79e276a70 100644 --- a/include/eda_item.h +++ b/include/eda_item.h @@ -111,10 +111,8 @@ public: inline bool IsEntered() const { return m_flags & ENTERED; } inline bool IsBrightened() const { return m_flags & BRIGHTENED; } - inline bool IsRollover() const - { - return ( m_flags & ( IS_ROLLOVER | IS_MOVING ) ) == IS_ROLLOVER; - } + inline bool IsRollover() const { return m_isRollover; } + inline void SetIsRollover( bool aIsRollover ) { m_isRollover = aIsRollover; } inline void SetSelected() { SetFlags( SELECTED ); } inline void SetBrightened() { SetFlags( BRIGHTENED ); } @@ -501,6 +499,7 @@ protected: EDA_ITEM_FLAGS m_flags; EDA_ITEM* m_parent; ///< Linked list: Link (parent struct). bool m_forceVisible; + bool m_isRollover; }; diff --git a/include/eda_item_flags.h b/include/eda_item_flags.h index fe318acf80..fe5e655125 100644 --- a/include/eda_item_flags.h +++ b/include/eda_item_flags.h @@ -63,8 +63,7 @@ // 23 is unused #define HOLE_PROXY (1 << 24) ///< Indicates the BOARD_ITEM is a proxy for its hole -#define IS_ROLLOVER (1 << 25) ///< Rollover active. Used for hyperlink highlighting. -#define SHOW_ELEC_TYPE (1 << 25) ///< Show pin electrical type. Shared with IS_ROLLOVER. +#define SHOW_ELEC_TYPE (1 << 25) ///< Show pin electrical type #define BRIGHTENED (1 << 26) ///< item is drawn with a bright contour // 27 is unused diff --git a/include/string_utils.h b/include/string_utils.h index eede09a9cf..c49dc6376b 100644 --- a/include/string_utils.h +++ b/include/string_utils.h @@ -142,6 +142,11 @@ KICOMMON_API wxString RemoveHTMLTags( const wxString& aInput ); */ KICOMMON_API wxString LinkifyHTML( wxString aStr ); +/** + * Performs a URL sniff-test on a string. + */ +KICOMMON_API bool IsURL( wxString aStr ); + /** * Read one line line from \a aFile. *