diff options
| author | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2022-06-19 10:23:24 +0200 |
|---|---|---|
| committer | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2022-06-19 10:23:24 +0200 |
| commit | 02870242eea8b729b3dbd6d23eb77372f61c6318 (patch) | |
| tree | 1c754a9b01c71b3e68aa795469c30b6c32074e17 /src/drivers | |
| parent | 232743c3a5d903be813f6c4445f3f96bab25cae0 (diff) | |
Move input method support to Fl_Screen_Driver from Fl_Graphics_Driver
Diffstat (limited to 'src/drivers')
| -rw-r--r-- | src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.H | 2 | ||||
| -rw-r--r-- | src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx | 8 | ||||
| -rw-r--r-- | src/drivers/GDI/Fl_GDI_Graphics_Driver.H | 1 | ||||
| -rw-r--r-- | src/drivers/GDI/Fl_GDI_Graphics_Driver.cxx | 37 | ||||
| -rw-r--r-- | src/drivers/Quartz/Fl_Quartz_Graphics_Driver.H | 2 | ||||
| -rw-r--r-- | src/drivers/Quartz/Fl_Quartz_Graphics_Driver.cxx | 8 | ||||
| -rw-r--r-- | src/drivers/Wayland/Fl_Wayland_Graphics_Driver.H | 2 | ||||
| -rw-r--r-- | src/drivers/Wayland/Fl_Wayland_Graphics_Driver.cxx | 12 | ||||
| -rw-r--r-- | src/drivers/Wayland/Fl_Wayland_Screen_Driver.H | 2 | ||||
| -rw-r--r-- | src/drivers/Wayland/Fl_Wayland_Screen_Driver.cxx | 12 | ||||
| -rw-r--r-- | src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.H | 2 | ||||
| -rw-r--r-- | src/drivers/X11/Fl_X11_Screen_Driver.H | 21 | ||||
| -rw-r--r-- | src/drivers/X11/Fl_X11_Screen_Driver.cxx | 96 | ||||
| -rw-r--r-- | src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H | 3 | ||||
| -rw-r--r-- | src/drivers/Xlib/Fl_Xlib_Graphics_Driver.cxx | 85 |
15 files changed, 139 insertions, 154 deletions
diff --git a/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.H b/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.H index 74e1a8123..a2303d0be 100644 --- a/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.H +++ b/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.H @@ -100,6 +100,8 @@ public: virtual void copy(const char *stuff, int len, int clipboard, const char *type); virtual void paste(Fl_Widget &receiver, int clipboard, const char *type); virtual int clipboard_contains(const char *type); + virtual void set_spot(int font, int size, int X, int Y, int W, int H, Fl_Window *win); + virtual void reset_spot(); private: float scale_; }; diff --git a/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx b/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx index 33f92a6db..01c3b0f95 100644 --- a/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx +++ b/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx @@ -381,3 +381,11 @@ Fl_RGB_Image *Fl_Cocoa_Screen_Driver::read_win_rectangle(int X, int Y, int w, in rgb->alloc_array = 1; return rgb; } + +void Fl_Cocoa_Screen_Driver::set_spot(int /*font*/, int size, int X, int Y, int /*W*/, int /*H*/, Fl_Window* /*win*/) { + Fl_Cocoa_Screen_Driver::insertion_point_location(X, Y, size); +} + +void Fl_Cocoa_Screen_Driver::reset_spot() { + Fl_Cocoa_Screen_Driver::reset_marked_text(); +} diff --git a/src/drivers/GDI/Fl_GDI_Graphics_Driver.H b/src/drivers/GDI/Fl_GDI_Graphics_Driver.H index c916fc65e..49ad98e21 100644 --- a/src/drivers/GDI/Fl_GDI_Graphics_Driver.H +++ b/src/drivers/GDI/Fl_GDI_Graphics_Driver.H @@ -143,7 +143,6 @@ protected: void color(uchar r, uchar g, uchar b); void set_color(Fl_Color i, unsigned int c); void free_color(Fl_Color i, int overlay); - void set_spot(int font, int size, int X, int Y, int W, int H, Fl_Window *win); virtual Fl_Font set_fonts(const char *name); virtual int get_font_sizes(Fl_Font fnum, int*& sizep); virtual const char* get_font_name(Fl_Font fnum, int* ap); diff --git a/src/drivers/GDI/Fl_GDI_Graphics_Driver.cxx b/src/drivers/GDI/Fl_GDI_Graphics_Driver.cxx index 0bdc53ffe..87adc44f0 100644 --- a/src/drivers/GDI/Fl_GDI_Graphics_Driver.cxx +++ b/src/drivers/GDI/Fl_GDI_Graphics_Driver.cxx @@ -245,43 +245,6 @@ void Fl_GDI_Graphics_Driver::XDestroyRegion(Fl_Region r) { } -typedef BOOL(WINAPI* flTypeImmAssociateContextEx)(HWND, HIMC, DWORD); -extern flTypeImmAssociateContextEx flImmAssociateContextEx; -typedef HIMC(WINAPI* flTypeImmGetContext)(HWND); -extern flTypeImmGetContext flImmGetContext; -typedef BOOL(WINAPI* flTypeImmSetCompositionWindow)(HIMC, LPCOMPOSITIONFORM); -extern flTypeImmSetCompositionWindow flImmSetCompositionWindow; -typedef BOOL(WINAPI* flTypeImmReleaseContext)(HWND, HIMC); -extern flTypeImmReleaseContext flImmReleaseContext; - - -void Fl_GDI_Graphics_Driver::set_spot(int font, int size, int X, int Y, int W, int H, Fl_Window *win) -{ - if (!win) return; - Fl_Window* tw = win->top_window(); - - if (!tw->shown()) - return; - - HIMC himc = flImmGetContext(fl_xid(tw)); - - if (himc) { - COMPOSITIONFORM cfs; - float s = scale(); - cfs.dwStyle = CFS_POINT; - cfs.ptCurrentPos.x = int(X * s); - cfs.ptCurrentPos.y = int(Y * s) - int(tw->labelsize() * s); - // Attempt to have temporary text entered by input method use scaled font. - // Does good, but still not always effective. - Fl_GDI_Font_Descriptor *desc = (Fl_GDI_Font_Descriptor*)font_descriptor(); - if (desc) SelectObject((HDC)gc(), desc->fid); - MapWindowPoints(fl_xid(win), fl_xid(tw), &cfs.ptCurrentPos, 1); - flImmSetCompositionWindow(himc, &cfs); - flImmReleaseContext(fl_xid(tw), himc); - } -} - - void Fl_GDI_Graphics_Driver::scale(float f) { if (f != scale()) { size_ = 0; diff --git a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver.H b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver.H index a62fae898..b073d633a 100644 --- a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver.H +++ b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver.H @@ -173,8 +173,6 @@ protected: virtual void restore_scale(float); virtual void antialias(int state); virtual int antialias(); - virtual void set_spot(int font, int size, int X, int Y, int W, int H, Fl_Window *win); - virtual void reset_spot(); }; class Fl_Quartz_Printer_Graphics_Driver : public Fl_Quartz_Graphics_Driver { diff --git a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver.cxx b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver.cxx index ee9542c21..b50309438 100644 --- a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver.cxx +++ b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver.cxx @@ -174,11 +174,3 @@ void Fl_Quartz_Graphics_Driver::restore_scale(float s) { CGContextScaleCTM(gc_, s, s); } } - -void Fl_Quartz_Graphics_Driver::set_spot(int /*font*/, int size, int X, int Y, int /*W*/, int /*H*/, Fl_Window* /*win*/) { - Fl_Cocoa_Screen_Driver::insertion_point_location(X, Y, size); -} - -void Fl_Quartz_Graphics_Driver::reset_spot() { - Fl_Cocoa_Screen_Driver::reset_marked_text(); -} diff --git a/src/drivers/Wayland/Fl_Wayland_Graphics_Driver.H b/src/drivers/Wayland/Fl_Wayland_Graphics_Driver.H index 1a15312ad..a87a59878 100644 --- a/src/drivers/Wayland/Fl_Wayland_Graphics_Driver.H +++ b/src/drivers/Wayland/Fl_Wayland_Graphics_Driver.H @@ -81,8 +81,6 @@ public: static void buffer_release(struct wld_window *window); static void buffer_commit(struct wld_window *window); static void cairo_init(struct fl_wld_buffer *buffer, int width, int height, int stride, cairo_format_t format); - void set_spot(int font, int height, int x, int y, int w, int h, Fl_Window *win); - void reset_spot(); virtual void *gc(); virtual void gc(void *gc); }; diff --git a/src/drivers/Wayland/Fl_Wayland_Graphics_Driver.cxx b/src/drivers/Wayland/Fl_Wayland_Graphics_Driver.cxx index 8ed03f47e..7e7e1f0d7 100644 --- a/src/drivers/Wayland/Fl_Wayland_Graphics_Driver.cxx +++ b/src/drivers/Wayland/Fl_Wayland_Graphics_Driver.cxx @@ -144,18 +144,6 @@ void Fl_Wayland_Graphics_Driver::set_color(Fl_Color i, unsigned c) { } -void Fl_Wayland_Graphics_Driver::set_spot(int font, int height, int x, int y, int w, int h, Fl_Window *win) { - Fl_Wayland_Screen_Driver::insertion_point_location(x, y, height); -} - - -void Fl_Wayland_Graphics_Driver::reset_spot() { - Fl::compose_state = 0; - Fl_Wayland_Screen_Driver::next_marked_length = 0; - Fl_Wayland_Screen_Driver::insertion_point_location_is_valid = false; -} - - void Fl_Wayland_Graphics_Driver::copy_offscreen(int x, int y, int w, int h, Fl_Offscreen osrc, int srcx, int srcy) { // draw portion srcx,srcy,w,h of osrc to position x,y (top-left) of the graphics driver's surface int height = osrc->data_size / osrc->stride; diff --git a/src/drivers/Wayland/Fl_Wayland_Screen_Driver.H b/src/drivers/Wayland/Fl_Wayland_Screen_Driver.H index 6af144fab..c24cad238 100644 --- a/src/drivers/Wayland/Fl_Wayland_Screen_Driver.H +++ b/src/drivers/Wayland/Fl_Wayland_Screen_Driver.H @@ -170,6 +170,8 @@ public: static bool own_output(struct wl_output *output); typedef enum {unspecified, MUTTER, WESTON, KDE} compositor_name; static compositor_name compositor; // identifies the used Wayland compositor + void set_spot(int font, int height, int x, int y, int w, int h, Fl_Window *win); + void reset_spot(); }; diff --git a/src/drivers/Wayland/Fl_Wayland_Screen_Driver.cxx b/src/drivers/Wayland/Fl_Wayland_Screen_Driver.cxx index 4a1cd1bc4..81f6b9258 100644 --- a/src/drivers/Wayland/Fl_Wayland_Screen_Driver.cxx +++ b/src/drivers/Wayland/Fl_Wayland_Screen_Driver.cxx @@ -1429,3 +1429,15 @@ int Fl_Wayland_Screen_Driver::get_mouse(int &xx, int &yy) { yy = yy/s; return snum; } + + +void Fl_Wayland_Screen_Driver::set_spot(int font, int height, int x, int y, int w, int h, Fl_Window *win) { + Fl_Wayland_Screen_Driver::insertion_point_location(x, y, height); +} + + +void Fl_Wayland_Screen_Driver::reset_spot() { + Fl::compose_state = 0; + Fl_Wayland_Screen_Driver::next_marked_length = 0; + Fl_Wayland_Screen_Driver::insertion_point_location_is_valid = false; +} diff --git a/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.H b/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.H index 6754396ff..a2c7719bf 100644 --- a/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.H +++ b/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.H @@ -92,6 +92,8 @@ public: virtual int clipboard_contains(const char *type); // this one is implemented in Fl_win32.cxx virtual void clipboard_notify_change(); + // this one is implemented in Fl_win32.cxx + void set_spot(int font, int size, int X, int Y, int W, int H, Fl_Window *win); }; diff --git a/src/drivers/X11/Fl_X11_Screen_Driver.H b/src/drivers/X11/Fl_X11_Screen_Driver.H index 4b877c937..ead653078 100644 --- a/src/drivers/X11/Fl_X11_Screen_Driver.H +++ b/src/drivers/X11/Fl_X11_Screen_Driver.H @@ -25,6 +25,7 @@ #include <config.h> #include "../../Fl_Screen_Driver.H" +#include <X11/Xlib.h> class Fl_Window; @@ -87,8 +88,7 @@ public: virtual int text_display_can_leak() const; virtual Fl_RGB_Image *read_win_rectangle(int X, int Y, int w, int h, Fl_Window *win, bool may_capture_subwins, bool *did_capture_subwins); virtual int get_mouse(int &x, int &y); - virtual void enable_im(); - virtual void disable_im(); + virtual void open_display_platform(); virtual void close_display(); // --- compute dimensions of an Fl_Offscreen @@ -102,6 +102,23 @@ public: virtual int clipboard_contains(const char *type); // this one is in Fl_x.cxx virtual void clipboard_notify_change(); + // for support of input methods + static char fl_is_over_the_spot; + static XRectangle fl_spot; + static int fl_spotf; + static int fl_spots; + static XIM xim_im; + static XIC xim_ic; + static Window xim_win; + static void new_ic(); + static void xim_activate(Window xid); + static void xim_deactivate(void); + static void init_xim(); + virtual void enable_im(); + virtual void disable_im(); + virtual void set_spot(int font, int size, int X, int Y, int W, int H, Fl_Window *win); + virtual void reset_spot(); + virtual void set_status(int X, int Y, int W, int H); }; diff --git a/src/drivers/X11/Fl_X11_Screen_Driver.cxx b/src/drivers/X11/Fl_X11_Screen_Driver.cxx index 3c942d654..b1a62b29e 100644 --- a/src/drivers/X11/Fl_X11_Screen_Driver.cxx +++ b/src/drivers/X11/Fl_X11_Screen_Driver.cxx @@ -49,7 +49,6 @@ #endif // DEBUG extern Atom fl_NET_WORKAREA; -extern XIC fl_xim_ic; // in Fl_x.cxx // these are set by Fl::args() and override any system colors: from Fl_get_system_colors.cxx extern const char *fl_fg; @@ -58,6 +57,18 @@ extern const char *fl_bg2; // end of extern additions workaround +XIM Fl_X11_Screen_Driver::xim_im = 0; + +XIC Fl_X11_Screen_Driver::xim_ic = 0; + +int Fl_X11_Screen_Driver::fl_spotf = -1; +int Fl_X11_Screen_Driver::fl_spots = -1; +XRectangle Fl_X11_Screen_Driver::fl_spot; +char Fl_X11_Screen_Driver::fl_is_over_the_spot = 0; + +Window Fl_X11_Screen_Driver::xim_win = 0; + + void Fl_X11_Screen_Driver::display(const char *d) { if (d) setenv("DISPLAY", d, 1); @@ -486,7 +497,7 @@ int Fl_X11_Screen_Driver::compose(int& del) { void Fl_X11_Screen_Driver::compose_reset() { Fl::compose_state = 0; - if (fl_xim_ic) XmbResetIC(fl_xim_ic); + if (xim_ic) XmbResetIC(xim_ic); } int Fl_X11_Screen_Driver::text_display_can_leak() const { @@ -976,6 +987,87 @@ void Fl_X11_Screen_Driver::offscreen_size(Fl_Offscreen off, int &width, int &hei height = (int)h; } + +void Fl_X11_Screen_Driver::reset_spot(void) +{ + fl_spot.x = -1; + fl_spot.y = -1; + //if (xim_ic) XUnsetICFocus(xim_ic); +} + + +void Fl_X11_Screen_Driver::set_spot(int font, int size, int X, int Y, int W, int H, Fl_Window *win) +{ + int change = 0; + XVaNestedList preedit_attr; + static XFontSet fs = NULL; + char **missing_list; + int missing_count; + char *def_string; + char *fnt = NULL; + bool must_free_fnt =true; + + static XIC ic = NULL; + + if (!xim_ic || !fl_is_over_the_spot) return; + if (Fl::focus()) { // handle case when text widget is inside subwindow + Fl_Window *focuswin = Fl::focus()->window(); + while (focuswin && focuswin->parent()) { + X += focuswin->x(); Y += focuswin->y(); + focuswin = focuswin->window(); + } + } + //XSetICFocus(xim_ic); + if (X != fl_spot.x || Y != fl_spot.y) { + fl_spot.x = X; + fl_spot.y = Y; + fl_spot.height = H; + fl_spot.width = W; + change = 1; + } + if (font != fl_spotf || size != fl_spots) { + fl_spotf = font; + fl_spots = size; + change = 1; + if (fs) { + XFreeFontSet(fl_display, fs); + } +#if USE_XFT + +#if defined(__GNUC__) + // FIXME: warning XFT support here +#endif /*__GNUC__*/ + + fnt = NULL; // fl_get_font_xfld(font, size); + if (!fnt) {fnt = (char*)"-misc-fixed-*";must_free_fnt=false;} + fs = XCreateFontSet(fl_display, fnt, &missing_list, + &missing_count, &def_string); +#else + fnt = fl_get_font_xfld(font, size); + if (!fnt) {fnt = (char*)"-misc-fixed-*";must_free_fnt=false;} + fs = XCreateFontSet(fl_display, fnt, &missing_list, + &missing_count, &def_string); +#endif + } + if (xim_ic != ic) { + ic = xim_ic; + change = 1; + } + + if (fnt && must_free_fnt) free(fnt); + if (!change) return; + + float s = Fl_Graphics_Driver::default_driver().scale(); + XRectangle fl_spot_unscaled = { short(fl_spot.x * s), short(fl_spot.y * s), + (unsigned short)(fl_spot.width * s), (unsigned short)(fl_spot.height * s) }; + preedit_attr = XVaCreateNestedList(0, + XNSpotLocation, &fl_spot_unscaled, + XNFontSet, fs, NULL); + XSetICValues(xim_ic, XNPreeditAttributes, preedit_attr, NULL); + XFree(preedit_attr); +} + + #if USE_XFT //NOTICE: returns -1 if x,y is not in any screen int Fl_X11_Screen_Driver::screen_num_unscaled(int x, int y) diff --git a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H index e22d10691..9e3c44dce 100644 --- a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H +++ b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H @@ -205,9 +205,6 @@ protected: void color(uchar r, uchar g, uchar b); virtual float scale_font_for_PostScript(Fl_Font_Descriptor *desc, int s); virtual float scale_bitmap_for_PostScript(); - virtual void set_spot(int font, int size, int X, int Y, int W, int H, Fl_Window *win); - virtual void reset_spot(); - virtual void set_status(int X, int Y, int W, int H); virtual const char* get_font_name(Fl_Font fnum, int* ap); virtual int get_font_sizes(Fl_Font fnum, int*& sizep); #if !USE_XFT diff --git a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver.cxx b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver.cxx index 8a9380486..13a67f428 100644 --- a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver.cxx +++ b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver.cxx @@ -24,8 +24,6 @@ #include <string.h> #include <stdlib.h> -extern XIC fl_xim_ic; -extern char fl_is_over_the_spot; #if !USE_XFT extern char *fl_get_font_xfld(int fnum, int size); #endif @@ -100,89 +98,6 @@ void Fl_Xlib_Graphics_Driver::fixloop() { // remove equal points from closed pa while (n>2 && short_point[n-1].x == short_point[0].x && short_point[n-1].y == short_point[0].y) n--; } -// FIXME: should be members of Fl_Xlib_Graphics_Driver -XRectangle fl_spot; -int fl_spotf = -1; -int fl_spots = -1; - -void Fl_Xlib_Graphics_Driver::reset_spot(void) -{ - fl_spot.x = -1; - fl_spot.y = -1; - //if (fl_xim_ic) XUnsetICFocus(fl_xim_ic); -} - -void Fl_Xlib_Graphics_Driver::set_spot(int font, int size, int X, int Y, int W, int H, Fl_Window *win) -{ - int change = 0; - XVaNestedList preedit_attr; - static XFontSet fs = NULL; - char **missing_list; - int missing_count; - char *def_string; - char *fnt = NULL; - bool must_free_fnt =true; - - static XIC ic = NULL; - - if (!fl_xim_ic || !fl_is_over_the_spot) return; - if (Fl::focus()) { // handle case when text widget is inside subwindow - Fl_Window *focuswin = Fl::focus()->window(); - while (focuswin && focuswin->parent()) { - X += focuswin->x(); Y += focuswin->y(); - focuswin = focuswin->window(); - } - } - //XSetICFocus(fl_xim_ic); - if (X != fl_spot.x || Y != fl_spot.y) { - fl_spot.x = X; - fl_spot.y = Y; - fl_spot.height = H; - fl_spot.width = W; - change = 1; - } - if (font != fl_spotf || size != fl_spots) { - fl_spotf = font; - fl_spots = size; - change = 1; - if (fs) { - XFreeFontSet(fl_display, fs); - } -#if USE_XFT - -#if defined(__GNUC__) - // FIXME: warning XFT support here -#endif /*__GNUC__*/ - - fnt = NULL; // fl_get_font_xfld(font, size); - if (!fnt) {fnt = (char*)"-misc-fixed-*";must_free_fnt=false;} - fs = XCreateFontSet(fl_display, fnt, &missing_list, - &missing_count, &def_string); -#else - fnt = fl_get_font_xfld(font, size); - if (!fnt) {fnt = (char*)"-misc-fixed-*";must_free_fnt=false;} - fs = XCreateFontSet(fl_display, fnt, &missing_list, - &missing_count, &def_string); -#endif - } - if (fl_xim_ic != ic) { - ic = fl_xim_ic; - change = 1; - } - - if (fnt && must_free_fnt) free(fnt); - if (!change) return; - - float s = scale(); - XRectangle fl_spot_unscaled = { short(fl_spot.x * s), short(fl_spot.y * s), - (unsigned short)(fl_spot.width * s), (unsigned short)(fl_spot.height * s) }; - preedit_attr = XVaCreateNestedList(0, - XNSpotLocation, &fl_spot_unscaled, - XNFontSet, fs, NULL); - XSetICValues(fl_xim_ic, XNPreeditAttributes, preedit_attr, NULL); - XFree(preedit_attr); -} - #if !USE_XFT unsigned Fl_Xlib_Graphics_Driver::font_desc_size() { return (unsigned)sizeof(Fl_Xlib_Fontdesc); |
