Skip to content

Commit

Permalink
Use cursor name instead of Gdk::CursorType (#449)
Browse files Browse the repository at this point in the history
GTK4で削除される`Gdk::CursorType`のかわりにカーソルテーマの名前[*]を
使います。カーソル名の入力ミスを予防するため文字列リテラルを直接指定する
かわりに定数を使います。

非推奨のシンボルを無効化するマクロ
```
GDK_DISABLE_DEPRECATED
GTK_DISABLE_DEPRECATED
GDKMM_DISABLE_DEPRECATED
GTKMM_DISABLE_DEPRECATED
GIOMM_DISABLE_DEPRECATED
GLIBMM_DISABLE_DEPRECATED
```

コンパイラのレポート
```
../src/article/drawareabase.cpp:5226:70: error: no matching function for call to 'Gdk::Cursor::create(Gdk::CursorType&)'
 5226 |             m_window->set_cursor( Gdk::Cursor::create( m_cursor_type ) );
      |                                                                      ^
```

[*]: https://developer.gnome.org/gdk3/stable/gdk3-Cursors.html#gdk-cursor-new-from-name
  • Loading branch information
ma8ma committed Aug 23, 2020
1 parent aff5cba commit 85478c3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
40 changes: 27 additions & 13 deletions src/article/drawareabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,20 @@ enum
};


namespace {
namespace cursor_names {

// カーソル名の入力ミスを予防するため文字列リテラルのかわりに定数を使う
// 参考: https://developer.gnome.org/gdk3/stable/gdk3-Cursors.html#gdk-cursor-new-from-name
constexpr const char kAllScroll[] = "all-scroll";
constexpr const char kDefault[] = "default";
constexpr const char kPointer[] = "pointer";
constexpr const char kText[] = "text";

} // namespace cursor_names
} // namespace


#define SCROLLSPEED_FAST ( m_vscrbar ? \
m_vscrbar->get_adjustment()->get_page_size() \
- m_vscrbar->get_adjustment()->get_step_increment()*CONFIG::get_key_fastscroll_size() \
Expand Down Expand Up @@ -108,7 +122,7 @@ DrawAreaBase::DrawAreaBase( const std::string& url )
, m_back_frame_bottom( nullptr, cairo_surface_destroy )
, m_pre_pos_y{ -1 }
, m_back_marker( nullptr, cairo_surface_destroy )
, m_cursor_type( Gdk::ARROW )
, m_cursor_type( cursor_names::kDefault )
{
#ifdef _DEBUG
std::cout << "DrawAreaBase::DrawAreaBase " << m_url << std::endl;;
Expand Down Expand Up @@ -465,7 +479,7 @@ void DrawAreaBase::focus_out()
std::cout << "DrawAreaBase::focus_out\n";
#endif

change_cursor( Gdk::ARROW );
change_cursor( cursor_names::kDefault );

m_key_press = false;
m_key_locked = false;
Expand Down Expand Up @@ -4896,7 +4910,7 @@ bool DrawAreaBase::slot_button_press_event( GdkEventButton* event )
// 直後に slot_button_release_event() が呼び出されて m_scrollinfo がリセットされる
m_scrollinfo.autoscroll_finished = true;

change_cursor( Gdk::ARROW );
change_cursor( cursor_names::kDefault );
}
else {

Expand All @@ -4923,7 +4937,7 @@ bool DrawAreaBase::slot_button_press_event( GdkEventButton* event )

if ( ! ( m_layout_current && m_layout_current->link ) ){ // リンク上で無いなら

change_cursor( Gdk::DOUBLE_ARROW );
change_cursor( cursor_names::kAllScroll );

m_scrollinfo.reset();
m_scrollinfo.mode = SCROLL_AUTO;
Expand Down Expand Up @@ -5195,16 +5209,16 @@ bool DrawAreaBase::motion_mouse()
//
// 現在のポインターの下のノードからカーソルのタイプを決定する
//
Gdk::CursorType DrawAreaBase::get_cursor_type()
Glib::ustring DrawAreaBase::get_cursor_type()
{
Gdk::CursorType cursor_type = Gdk::ARROW;
Glib::ustring cursor_type = cursor_names::kDefault;
if( m_layout_current ){

// テキストの上ではカーソルを I に変える
if( m_layout_current->text && ! m_layout_current->link ) cursor_type = Gdk::XTERM;
if( m_layout_current->text && ! m_layout_current->link ) cursor_type = cursor_names::kText;

// リンクの上にポインタがある
if( m_layout_current->link ) cursor_type = Gdk::HAND2;
if( m_layout_current->link ) cursor_type = cursor_names::kPointer;
}

return cursor_type;
Expand All @@ -5214,16 +5228,16 @@ Gdk::CursorType DrawAreaBase::get_cursor_type()
//
// カーソルの形状の変更
//
void DrawAreaBase::change_cursor( const Gdk::CursorType type )
void DrawAreaBase::change_cursor( const Glib::ustring& cursor_type )
{
//オートスクロール中
if( m_scrollinfo.mode == SCROLL_AUTO ) return;

if( m_cursor_type != type ){
m_cursor_type = type;
if( m_cursor_type == Gdk::ARROW ) m_window->set_cursor();
if( m_cursor_type != cursor_type ){
m_cursor_type = cursor_type;
if( m_cursor_type == cursor_names::kDefault ) m_window->set_cursor();
else {
m_window->set_cursor( Gdk::Cursor::create( m_cursor_type ) );
m_window->set_cursor( Gdk::Cursor::create( m_window->get_display(), m_cursor_type ) );
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/article/drawareabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ namespace ARTICLE
bool m_r_drugging{}; // 右ドラッグ中
std::string m_link_current; // 現在マウスポインタの下にあるリンクの文字列
LAYOUT* m_layout_current{}; // 現在マウスポインタの下にあるlayoutノード(下が空白ならnullptr)
Gdk::CursorType m_cursor_type; // カーソルの形状
Glib::ustring m_cursor_type; // カーソルの形状

// 入力コントローラ
CONTROL::Control m_control;
Expand Down Expand Up @@ -460,10 +460,10 @@ namespace ARTICLE
bool motion_mouse();

// 現在のポインターの下のノードからカーソルのタイプを決定する
Gdk::CursorType get_cursor_type();
Glib::ustring get_cursor_type();

// カーソルの形状の変更
void change_cursor( const Gdk::CursorType type );
void change_cursor( const Glib::ustring& cursor_type );

// スクロールマーカの描画
void draw_marker();
Expand Down

0 comments on commit 85478c3

Please sign in to comment.