Skip to content

Commit

Permalink
Merge pull request #128 from ma8ma/fix-tooltip
Browse files Browse the repository at this point in the history
Fix tooltips which are not near mouse pointer on bbs list/thread list for GTK3
  • Loading branch information
ma8ma committed Oct 5, 2019
2 parents ad3b476 + fddc965 commit 620b8fd
Show file tree
Hide file tree
Showing 26 changed files with 91 additions and 370 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -199,6 +199,8 @@ GDK_CORE_DEVICE_EVENTS=1 ./src/jdim
* ~~スレビュー表示内にアスキーアート(AA)と判定されたレスがあると、スレビュー全体にAAのフォント設定が適用される。
この問題はオプション `--with-pangolayout` を追加してビルドすると回避できる。~~
**0.2.0-20190921以降のバージョンで修正されています。**
* ~~お気に入りにマウスオーバーすると表示されるツールチップがポインターからずれる。~~
**0.2.0-20191005以降のバージョンで修正されています。**


## 通常の起動
Expand Down
6 changes: 6 additions & 0 deletions docs/manual/2019.md
Expand Up @@ -10,6 +10,12 @@ layout: default

<a name="0.3.0-unreleased"></a>
### [0.3.0-unreleased](https://github.com/JDimproved/JDim/compare/JDim-v0.2.0...master) (unreleased)
- Fix tooltips which are not near mouse pointer on bbs list/thread list for GTK3
([#128](https://github.com/JDimproved/JDim/pull/128))
- Add github links for previous version manuals
([#130](https://github.com/JDimproved/JDim/pull/130))
- Revert "[WORKAROUND] Fix build error for manual"
([#129](https://github.com/JDimproved/JDim/pull/129))
- Use range-based for
([#126](https://github.com/JDimproved/JDim/pull/126))
- Refactor string operation
Expand Down
2 changes: 2 additions & 0 deletions docs/manual/start.md
Expand Up @@ -147,6 +147,8 @@ GDK_CORE_DEVICE_EVENTS=1 ./src/jdim
* ~~スレビュー表示内にアスキーアート(AA)と判定されたレスがあると、スレビュー全体にAAのフォント設定が適用される。
この問題はオプション `--with-pangolayout` を追加してビルドすると回避できる。~~
**0.2.0-20190921以降のバージョンで修正された。**
* ~~お気に入りにマウスオーバーすると表示されるツールチップがポインターからずれる。~~
**0.2.0-20191005以降のバージョンで修正された。**


[pr-merged]: https://github.com/JDimproved/JDim/pulls?q=is%3Apr+is%3Amerged
Expand Down
51 changes: 38 additions & 13 deletions src/bbslist/bbslistviewbase.cpp
Expand Up @@ -183,6 +183,8 @@ BBSListViewBase::BBSListViewBase( const std::string& url,const std::string& arg1
// treeviewのシグナルにコネクト
m_treeview.signal_row_expanded().connect( sigc::mem_fun(*this, &BBSListViewBase::slot_row_exp ) );
m_treeview.signal_row_collapsed().connect( sigc::mem_fun(*this, &BBSListViewBase::slot_row_col ) );
m_treeview.set_has_tooltip( true );
m_treeview.signal_query_tooltip().connect( sigc::mem_fun(*this, &BBSListViewBase::slot_query_tooltip) );

m_treeview.sig_button_press().connect( sigc::mem_fun(*this, &BBSListViewBase::slot_button_press ) );
m_treeview.sig_button_release().connect( sigc::mem_fun(*this, &BBSListViewBase::slot_button_release ) );
Expand Down Expand Up @@ -676,7 +678,6 @@ void BBSListViewBase::focus_out()
{
SKELETON::View::focus_out();

m_treeview.hide_tooltip();
m_treeview.hide_popup();
}

Expand Down Expand Up @@ -1155,8 +1156,6 @@ bool BBSListViewBase::slot_motion_notify( GdkEventMotion* event )

if( m_treeview.get_path_at_pos( x, y, path, column, cell_x, cell_y ) && m_treeview.get_row( path ) ){

const int mrg = 16; // アイコンの横幅。計算するのが面倒だったのでとりあえず

Gtk::TreeModel::Row row = m_treeview.get_row( path );
Glib::ustring subject = row[ m_columns.m_name ];
Glib::ustring url = row[ m_columns.m_url ];
Expand All @@ -1167,8 +1166,6 @@ bool BBSListViewBase::slot_motion_notify( GdkEventMotion* event )
// 画像ポップアップ
if( type == TYPE_IMAGE ){

m_treeview.hide_tooltip();

if( DBIMG::get_type_ext( url ) != DBIMG::T_UNKNOWN && DBIMG::get_code( url ) != HTTP_INIT ){

if( m_treeview.pre_popup_url() != url ){
Expand All @@ -1180,19 +1177,12 @@ bool BBSListViewBase::slot_motion_notify( GdkEventMotion* event )
else m_treeview.hide_popup();
}

// ツールチップ
// ツールチップはslot_query_tooltipでセットする
else{

m_treeview.hide_popup();

Gdk::Rectangle rect;
m_treeview.get_cell_area( path, *column, rect );
m_treeview.set_tooltip_min_width( rect.get_width() - mrg );
m_treeview.set_str_tooltip( subject );
}
}
else{
m_treeview.hide_tooltip();
m_treeview.hide_popup();
}

Expand Down Expand Up @@ -3163,6 +3153,41 @@ void BBSListViewBase::slot_hide_editlistwin()
}


//
// ツールチップのセット
//
bool BBSListViewBase::slot_query_tooltip( int x, int y, bool keyboard_tooltip,
const Glib::RefPtr<Gtk::Tooltip>& tooltip )
{
// NOTE: GTK2版で Gtk::TreeView::get_tooltip_context_path() を使うと
// マウスポインターをヘッダーや空行へ動かしたときに segmentation fault でクラッシュする
Gtk::TreeModel::iterator iter;
if( m_treeview.get_tooltip_context_iter( x, y, keyboard_tooltip, iter ) ) {

const Gtk::TreeModel::Path path = m_treestore->get_path( iter );
m_treeview.set_tooltip_row( tooltip, path );

const Gtk::TreeModel::Row row = m_treeview.get_row( path );
const Glib::ustring& subject = row[ m_columns.m_name ];
const Glib::ustring& url = row[ m_columns.m_url ];
const int type = row[ m_columns.m_type ];

m_treeview.reset_pre_popupurl( url );

// 画像ポップアップはslot_motion_notifyでセットする
if( type == TYPE_IMAGE ) return false;

// ツールチップ
m_treeview.hide_popup();
tooltip->set_text( subject );
return true;
}
m_treeview.hide_popup();
return false;
}



//
// XML保存
//
Expand Down
2 changes: 2 additions & 0 deletions src/bbslist/bbslistviewbase.h
Expand Up @@ -322,6 +322,8 @@ namespace BBSLIST

// ツリーの編集ウィンドウが閉じた
void slot_hide_editlistwin();

bool slot_query_tooltip( int x, int y, bool keyboard_tooltip, const Glib::RefPtr<Gtk::Tooltip>& tooltip );
};
}

Expand Down
52 changes: 29 additions & 23 deletions src/board/boardviewbase.cpp
Expand Up @@ -177,6 +177,8 @@ BoardViewBase::BoardViewBase( const std::string& url, const bool show_col_board
m_treeview.sig_key_press().connect( sigc::mem_fun(*this, &BoardViewBase::slot_key_press ) );
m_treeview.sig_key_release().connect( sigc::mem_fun(*this, &BoardViewBase::slot_key_release ) );
m_treeview.sig_scroll_event().connect( sigc::mem_fun(*this, &BoardViewBase::slot_scroll_event ) );
m_treeview.set_has_tooltip( true );
m_treeview.signal_query_tooltip().connect( sigc::mem_fun(*this, &BoardViewBase::slot_query_tooltip) );
m_treeview.signal_drag_data_get().connect( sigc::mem_fun(*this, &BoardViewBase::slot_drag_data_get ) );
m_treeview.sig_dropped_uri_list().connect( sigc::mem_fun(*this, &BoardViewBase::slot_dropped_url_list ) );

Expand Down Expand Up @@ -1370,8 +1372,6 @@ void BoardViewBase::focus_view()
void BoardViewBase::focus_out()
{
SKELETON::View::focus_out();

m_treeview.hide_tooltip();
}


Expand Down Expand Up @@ -2131,27 +2131,6 @@ bool BoardViewBase::slot_motion_notify( GdkEventMotion* event )
/// マウスジェスチャ
get_control().MG_motion( event );

const int x = (int)event->x;
const int y = (int)event->y;
Gtk::TreeModel::Path path;
Gtk::TreeView::Column* column;
int cell_x;
int cell_y;

// ツールチップに文字列をセットする
if( m_treeview.get_path_at_pos( x, y, path, column, cell_x, cell_y ) ){

// 列幅よりもツールチップの幅が広い場合はツールチップを表示する
m_treeview.set_tooltip_min_width( column->get_width() );

if( column->get_title() == ITEM_NAME_BOARD ) m_treeview.set_str_tooltip( get_name_of_cell( path, m_columns.m_col_board ) );
else if( column->get_title() == ITEM_NAME_NAME ) m_treeview.set_str_tooltip( get_name_of_cell( path, m_columns.m_col_subject ) );
else if( column->get_title() == ITEM_NAME_SINCE ) m_treeview.set_str_tooltip( get_name_of_cell( path, m_columns.m_col_since ) );
else if( column->get_title() == ITEM_NAME_LASTWRITE ) m_treeview.set_str_tooltip( get_name_of_cell( path, m_columns.m_col_write ) );
else if( column->get_title() == ITEM_NAME_ACCESS ) m_treeview.set_str_tooltip( get_name_of_cell( path, m_columns.m_col_access ) );
else m_treeview.set_str_tooltip( std::string() );
}

return true;
}

Expand Down Expand Up @@ -2220,6 +2199,33 @@ bool BoardViewBase::slot_scroll_event( GdkEventScroll* event )
}


//
// ツールチップのセット
//
bool BoardViewBase::slot_query_tooltip( int x, int y, bool keyboard_tooltip,
const Glib::RefPtr<Gtk::Tooltip>& tooltip )
{
// NOTE: GTK2版で Gtk::TreeView::get_tooltip_context_path() を使うと
// マウスポインターをヘッダーや空行へ動かしたときに segmentation fault でクラッシュする
Gtk::TreeModel::iterator iter;
if( m_treeview.get_tooltip_context_iter( x, y, keyboard_tooltip, iter ) ) {

const Gtk::TreeModel::Path path = m_liststore->get_path( iter );
m_treeview.set_tooltip_row( tooltip, path );

const Gtk::TreeModel::Row row = m_treeview.get_row( path );
const Glib::ustring& subject = row[ m_columns.m_col_subject ];

#ifdef _DEBUG
std::cout << "BoardViewBase::slot_query_tooltip subject: " << subject << std::endl;
#endif
tooltip->set_text( subject );
return true;
}
return false;
}


//
// D&Dで受信側がデータ送信を要求してきた
//
Expand Down
1 change: 1 addition & 0 deletions src/board/boardviewbase.h
Expand Up @@ -255,6 +255,7 @@ namespace BOARD
bool slot_motion_notify( GdkEventMotion* event );
bool slot_key_release( GdkEventKey* event );
bool slot_scroll_event( GdkEventScroll* event );
bool slot_query_tooltip( int x, int y, bool keyboard_tooltip, const Glib::RefPtr<Gtk::Tooltip>& tooltip );

void slot_bookmark( int bookmark );
void slot_open_tab();
Expand Down
37 changes: 4 additions & 33 deletions src/fontcolorpref.cpp
Expand Up @@ -98,13 +98,8 @@ FontColorPref::FontColorPref( Gtk::Window* parent, const std::string& url )

m_combo_font.set_active( 0 );
m_fontbutton.set_font_name( CONFIG::get_fontname( m_font_tbl[ 0 ] ) );
#if GTKMM_CHECK_VERSION(2,12,0)
m_event_font.set_tooltip_text( m_tooltips_font[ 0 ] );
m_fontbutton.set_tooltip_text( m_tooltips_font[ 0 ] );
#else
m_tooltips.set_tip( m_event_font, m_tooltips_font[ 0 ] );
m_tooltips.set_tip( m_fontbutton, m_tooltips_font[ 0 ] );
#endif

set_title( "フォントと色の詳細設定" );
#if GTKMM_CHECK_VERSION(3,0,0)
Expand Down Expand Up @@ -135,11 +130,7 @@ void FontColorPref::pack_widget()

m_checkbutton_font.add_label( "スレビューでフォント幅の近似計算を厳密に行う(_S)", true ),
m_checkbutton_font.set_active( CONFIG::get_strict_char_width() );
#if GTKMM_CHECK_VERSION(2,12,0)
m_checkbutton_font.set_tooltip_text( WARNING_STRICTCHAR );
#else
m_tooltips.set_tip( m_checkbutton_font, WARNING_STRICTCHAR );
#endif
m_hbox_checkbutton.pack_start( m_checkbutton_font, Gtk::PACK_SHRINK );
m_vbox_font.pack_start( m_hbox_checkbutton, Gtk::PACK_SHRINK, mrg/2 );

Expand All @@ -154,12 +145,7 @@ void FontColorPref::pack_widget()
m_hbox_space.set_spacing ( mrg );
m_hbox_space.pack_start( m_label_space, Gtk::PACK_SHRINK );
m_hbox_space.pack_start( m_spin_space, Gtk::PACK_SHRINK );
constexpr const char* ss_tip = "スレビューにおいて行の高さを調節します( 標準は 1 )";
#if GTKMM_CHECK_VERSION(2,12,0)
m_spin_space.set_tooltip_text( ss_tip );
#else
m_tooltips.set_tip( m_spin_space, ss_tip );
#endif
m_spin_space.set_tooltip_text( "スレビューにおいて行の高さを調節します( 標準は 1 )" );
m_vbox_font.pack_start( m_hbox_space, Gtk::PACK_SHRINK, mrg/2 );

set_activate_entry( m_spin_space );
Expand All @@ -175,25 +161,15 @@ void FontColorPref::pack_widget()
m_hbox_ubar.pack_start( m_label_ubar, Gtk::PACK_SHRINK );
m_hbox_ubar.pack_start( m_spin_ubar, Gtk::PACK_SHRINK );
m_vbox_font.pack_start( m_hbox_ubar, Gtk::PACK_SHRINK, mrg/2 );
constexpr const char* su_tip = "スレビューにおいてアンカーなどの下線の位置を調節します( 標準は 1 )";
#if GTKMM_CHECK_VERSION(2,12,0)
m_spin_ubar.set_tooltip_text( su_tip );
#else
m_tooltips.set_tip( m_spin_ubar, su_tip );
#endif
m_spin_ubar.set_tooltip_text( "スレビューにおいてアンカーなどの下線の位置を調節します( 標準は 1 )" );

set_activate_entry( m_spin_ubar );

// AAレスと判定する正規表現
m_label_aafont.set_text( CONFIG::get_regex_res_aa() );
m_vbox_font.pack_start( m_label_aafont, Gtk::PACK_SHRINK, mrg/2 );
constexpr const char* la_tip =
"この正規表現に一致したレスは、アスキーアートフォントで表示します( 次に開いたスレから有効 )";
#if GTKMM_CHECK_VERSION(2,12,0)
m_label_aafont.set_tooltip_text( la_tip );
#else
m_tooltips.set_tip( m_label_aafont, la_tip );
#endif
m_label_aafont.set_tooltip_text(
"この正規表現に一致したレスは、アスキーアートフォントで表示します( 次に開いたスレから有効 )" );

set_activate_entry( m_label_aafont );

Expand Down Expand Up @@ -348,13 +324,8 @@ void FontColorPref::slot_combo_font_changed()
{
const int num = m_combo_font.get_active_row_number();
m_fontbutton.set_font_name( CONFIG::get_fontname( m_font_tbl[ num ] ) );
#if GTKMM_CHECK_VERSION(2,12,0)
m_event_font.set_tooltip_text( m_tooltips_font[ num ] );
m_fontbutton.set_tooltip_text( m_tooltips_font[ num ] );
#else
m_tooltips.set_tip( m_event_font, m_tooltips_font[ num ] );
m_tooltips.set_tip( m_fontbutton, m_tooltips_font[ num ] );
#endif
}


Expand Down
5 changes: 0 additions & 5 deletions src/fontcolorpref.h
Expand Up @@ -37,11 +37,6 @@ namespace CORE
{
Gtk::Notebook m_notebook;

#if !GTKMM_CHECK_VERSION(2,12,0)
// ツールチップ
Gtk::Tooltips m_tooltips;
#endif

// フォントの設定
std::vector< int > m_font_tbl;
std::vector< std::string > m_tooltips_font;
Expand Down
11 changes: 2 additions & 9 deletions src/message/messageviewbase.cpp
Expand Up @@ -441,15 +441,8 @@ void MessageViewBase::pack_widget()
m_check_fixname.set_label( "固定" );
m_check_fixmail.set_label( "固定" );

constexpr const char* name_tip = "チェックすると名前欄を保存して固定にする";
constexpr const char* mail_tip = "チェックするとメール欄を保存して固定にする";
#if GTKMM_CHECK_VERSION(2,12,0)
m_check_fixname.set_tooltip_text( name_tip );
m_check_fixmail.set_tooltip_text( mail_tip );
#else
m_tooltip.set_tip( m_check_fixname, name_tip );
m_tooltip.set_tip( m_check_fixmail, mail_tip );
#endif
m_check_fixname.set_tooltip_text( "チェックすると名前欄を保存して固定にする" );
m_check_fixmail.set_tooltip_text( "チェックするとメール欄を保存して固定にする" );

set_name();
set_mail();
Expand Down
4 changes: 0 additions & 4 deletions src/message/messageviewbase.h
Expand Up @@ -37,10 +37,6 @@ namespace MESSAGE
{
Post* m_post;

#if !GTKMM_CHECK_VERSION(2,12,0)
Gtk::Tooltips m_tooltip;
#endif

Gtk::Notebook m_notebook;
SKELETON::View* m_preview;
Gtk::VBox m_msgview;
Expand Down
2 changes: 0 additions & 2 deletions src/skeleton/Makefile.am
Expand Up @@ -28,7 +28,6 @@ libskeleton_a_SOURCES = \
backforwardbutton.cpp \
popupwinbase.cpp \
popupwin.cpp \
tooltip.cpp \
entry.cpp \
compentry.cpp \
label_entry.cpp \
Expand Down Expand Up @@ -80,7 +79,6 @@ noinst_HEADERS = \
popupwinbase.h \
popupwin.h \
iconpopup.h \
tooltip.h \
entry.h \
compentry.h \
label_entry.h \
Expand Down
1 change: 0 additions & 1 deletion src/skeleton/admin.cpp
Expand Up @@ -1804,7 +1804,6 @@ void Admin::focus_out()

SKELETON::View* view = get_current_view();
if( view ) view->focus_out();
m_notebook->focus_out();
}


Expand Down

0 comments on commit 620b8fd

Please sign in to comment.