Skip to content

Commit 92f458b

Browse files
committed
Fix text's left/right margins under GTK+
1 parent be52522 commit 92f458b

File tree

4 files changed

+43
-26
lines changed

4 files changed

+43
-26
lines changed

src/spellchecking.cpp

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "spellchecking.h"
2727

2828
#include "str_helpers.h"
29+
#include "text_control.h"
2930

3031
#ifdef __WXGTK__
3132
#include <gtk/gtk.h>
@@ -46,27 +47,10 @@
4647

4748

4849
#ifdef __WXGTK__
49-
// helper functions that finds GtkTextView of wxTextCtrl:
50-
static GtkTextView *GetTextView(wxTextCtrl *ctrl)
51-
{
52-
GtkWidget *parent = ctrl->m_widget;
53-
GList *child = gtk_container_get_children(GTK_CONTAINER(parent));
54-
while (child)
55-
{
56-
if (GTK_IS_TEXT_VIEW(child->data))
57-
{
58-
return GTK_TEXT_VIEW(child->data);
59-
}
60-
child = child->next;
61-
}
62-
63-
wxFAIL_MSG( "couldn't find GtkTextView for text control" );
64-
return NULL;
65-
}
6650

67-
bool InitTextCtrlSpellchecker(wxTextCtrl *text, bool enable, const Language& lang)
51+
bool InitTextCtrlSpellchecker(CustomizedTextCtrl *text, bool enable, const Language& lang)
6852
{
69-
GtkTextView *textview = GetTextView(text);
53+
GtkTextView *textview = GTK_TEXT_VIEW(text->GetGtkTextView());
7054
wxASSERT_MSG( textview, "wxTextCtrl is supposed to use GtkTextView" );
7155

7256
GtkSpellChecker *spell = gtk_spell_checker_get_from_text_view(textview);
@@ -100,7 +84,7 @@ bool SetSpellcheckerLang(const wxString& lang)
10084
return [sc setLanguage: nslang];
10185
}
10286

103-
bool InitTextCtrlSpellchecker(wxTextCtrl *text, bool enable, const Language& /*lang*/)
87+
bool InitTextCtrlSpellchecker(CustomizedTextCtrl *text, bool enable, const Language& /*lang*/)
10488
{
10589
NSScrollView *scroll = (NSScrollView*)text->GetHandle();
10690
NSTextView *view = [scroll documentView];
@@ -113,7 +97,7 @@ bool InitTextCtrlSpellchecker(wxTextCtrl *text, bool enable, const Language& /*l
11397
#endif // __WXOSX__
11498

11599
#ifdef __WXMSW__
116-
void PrepareTextCtrlForSpellchecker(wxTextCtrl *text)
100+
void PrepareTextCtrlForSpellchecker(CustomizedTextCtrl *text)
117101
{
118102
// Set spellchecking-friendly style on the text control. Enabling spellchecking
119103
// itself is done with EM_SETLANGOPTIONS in InitTextCtrlSpellchecker()
@@ -122,7 +106,7 @@ void PrepareTextCtrlForSpellchecker(wxTextCtrl *text)
122106
::SendMessage(hwnd, EM_SETEDITSTYLE, editStyle, editStyle);
123107
}
124108

125-
bool InitTextCtrlSpellchecker(wxTextCtrl *text, bool enable, const Language& /*lang*/)
109+
bool InitTextCtrlSpellchecker(CustomizedTextCtrl *text, bool enable, const Language& /*lang*/)
126110
{
127111
HWND hwnd = (HWND) text->GetHWND();
128112
auto langOptions = ::SendMessage(hwnd, EM_GETLANGOPTIONS, 0, 0);

src/spellchecking.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@
3232
#include <wx/platinfo.h>
3333
#endif
3434

35-
#include <wx/textctrl.h>
36-
3735
#include "language.h"
3836

37+
class CustomizedTextCtrl;
38+
39+
3940
inline bool IsSpellcheckingAvailable()
4041
{
4142
#ifdef __WXMSW__
@@ -52,11 +53,11 @@ bool SetSpellcheckerLang(const wxString& lang);
5253

5354
// Does any initialization needed to be able to use spellchecker with the control later.
5455
#ifdef __WXMSW__
55-
void PrepareTextCtrlForSpellchecker(wxTextCtrl *text);
56+
void PrepareTextCtrlForSpellchecker(CustomizedTextCtrl *text);
5657
#endif
5758

5859
// Init given text control to do (or not) spellchecking for given language
59-
bool InitTextCtrlSpellchecker(wxTextCtrl *text, bool enable, const Language& lang);
60+
bool InitTextCtrlSpellchecker(CustomizedTextCtrl *text, bool enable, const Language& lang);
6061

6162
#ifndef __WXMSW__
6263
// Show help about how to add more dictionaries for spellchecking.

src/text_control.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
#import <Foundation/NSUndoManager.h>
3434
#endif
3535

36+
#ifdef __WXGTK__
37+
#include <gtk/gtk.h>
38+
#endif
39+
3640
#ifdef __WXMSW__
3741
#include <windows.h>
3842
#include <richedit.h>
@@ -305,10 +309,16 @@ CustomizedTextCtrl::CustomizedTextCtrl(wxWindow *parent, wxWindowID winid, long
305309
{
306310
wxTextCtrl::Create(parent, winid, "", wxDefaultPosition, wxDefaultSize, style | ALWAYS_USED_STYLE);
307311

312+
#ifdef __WXGTK__
313+
GtkTextView *tv = GTK_TEXT_VIEW(GetGtkTextView());
314+
gtk_text_view_set_left_margin(tv, 5);
315+
gtk_text_view_set_right_margin(tv, 5);
316+
#else
308317
wxTextAttr padding;
309318
padding.SetLeftIndent(9);
310319
padding.SetRightIndent(9);
311320
SetDefaultStyle(padding);
321+
#endif
312322

313323
Bind(wxEVT_TEXT_COPY, &CustomizedTextCtrl::OnCopy, this);
314324
Bind(wxEVT_TEXT_CUT, &CustomizedTextCtrl::OnCut, this);
@@ -506,6 +516,26 @@ void CustomizedTextCtrl::Redo()
506516
SetInsertionPoint(m_history[m_historyIndex].insertionPoint);
507517
m_historyIndex++;
508518
}
519+
520+
void *CustomizedTextCtrl::GetGtkTextView() const
521+
{
522+
// helper function that finds GtkTextView of wxTextCtrl
523+
524+
GtkWidget *parent = m_widget;
525+
GList *child = gtk_container_get_children(GTK_CONTAINER(parent));
526+
while (child)
527+
{
528+
if (GTK_IS_TEXT_VIEW(child->data))
529+
{
530+
return GTK_TEXT_VIEW(child->data);
531+
}
532+
child = child->next;
533+
}
534+
535+
wxFAIL_MSG( "couldn't find GtkTextView for text control" );
536+
return nullptr;
537+
}
538+
509539
#endif // __WXGTK__
510540

511541
void CustomizedTextCtrl::ShowFindIndicator(int from, int length)

src/text_control.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ class CustomizedTextCtrl : public wxTextCtrl
5858
void BeginUndoGrouping();
5959
void EndUndoGrouping();
6060
void SaveSnapshot();
61+
62+
void *GetGtkTextView() const;
6163
#endif
6264

6365
#ifdef __WXMSW__

0 commit comments

Comments
 (0)