Skip to content

Commit

Permalink
Rewrite Fl_Text_Editor.cxx under the driver model.
Browse files Browse the repository at this point in the history
Fl_Cocoa_Screen_Driver contains the Mac OS-specific text editor key bindings.

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11497 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
  • Loading branch information
Manolo Gouy authored and Manolo Gouy committed Apr 1, 2016
1 parent 88ab084 commit 20b00f2
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 28 deletions.
3 changes: 3 additions & 0 deletions FL/Fl_Screen_Driver.H
Expand Up @@ -22,6 +22,7 @@
#include <FL/Fl_Device.H>
#include <FL/fl_types.h>
#include <FL/Fl.H> // for Fl_Timeout_Handler
#include <FL/Fl_Text_Editor.H>


// TODO: add text composition?
Expand Down Expand Up @@ -107,6 +108,8 @@ public:
// implement to support drag-n-drop. use_selection = 1 means the GUI is welcome to display
// the selected text during the D&D operation
virtual int dnd(int use_selection = 0) {return 0;}
// null means no platform-specific key bindings for Fl_Text_Editor
Fl_Text_Editor::Key_Binding *text_editor_extra_key_bindings;
};


Expand Down
2 changes: 1 addition & 1 deletion src/Fl_Screen_Driver.cxx
Expand Up @@ -28,7 +28,7 @@ char Fl_Screen_Driver::fg_set = 0;


Fl_Screen_Driver::Fl_Screen_Driver() :
num_screens(-1)
num_screens(-1), text_editor_extra_key_bindings(NULL)
{
}

Expand Down
37 changes: 10 additions & 27 deletions src/Fl_Text_Editor.cxx
Expand Up @@ -26,12 +26,6 @@
#include <FL/Fl_Screen_Driver.H>
#include <FL/fl_ask.H>

#if defined(WIN32) || defined(__APPLE__) // PORTME: Fl_Screen_Driver - platform editor
#elif defined(FL_PORTING)
# pragma message "FL_PORTING: add common shortcut for your platform here"
#else
#endif

/* Keyboard Control Matrix
key\modifier plain Ctrl Alt Meta
Expand Down Expand Up @@ -146,24 +140,6 @@ static struct {
{ 'v', FL_CTRL, Fl_Text_Editor::kf_paste },
{ FL_Insert, FL_SHIFT, Fl_Text_Editor::kf_paste },
{ 'a', FL_CTRL, Fl_Text_Editor::kf_select_all },

#ifdef __APPLE__ // PORTME: Fl_Screen_Driver - platform editor feel
// Define CMD+key accelerators...
{ 'z', FL_COMMAND, Fl_Text_Editor::kf_undo },
{ 'x', FL_COMMAND, Fl_Text_Editor::kf_cut },
{ 'c', FL_COMMAND, Fl_Text_Editor::kf_copy },
{ 'v', FL_COMMAND, Fl_Text_Editor::kf_paste },
{ 'a', FL_COMMAND, Fl_Text_Editor::kf_select_all },
{ FL_Left, FL_COMMAND, Fl_Text_Editor::kf_meta_move },
{ FL_Right, FL_COMMAND, Fl_Text_Editor::kf_meta_move },
{ FL_Up, FL_COMMAND, Fl_Text_Editor::kf_meta_move },
{ FL_Down, FL_COMMAND, Fl_Text_Editor::kf_meta_move },
{ FL_Left, FL_COMMAND|FL_SHIFT, Fl_Text_Editor::kf_m_s_move },
{ FL_Right, FL_COMMAND|FL_SHIFT, Fl_Text_Editor::kf_m_s_move },
{ FL_Up, FL_COMMAND|FL_SHIFT, Fl_Text_Editor::kf_m_s_move },
{ FL_Down, FL_COMMAND|FL_SHIFT, Fl_Text_Editor::kf_m_s_move },
#endif // __APPLE__ // PORTME: Fl_Screen_Driver - platform editor feel

{ 0, 0, 0 }
};

Expand All @@ -175,6 +151,15 @@ void Fl_Text_Editor::add_default_key_bindings(Key_Binding** list) {
default_key_bindings[i].func,
list);
}
Key_Binding *extra_key_bindings = Fl::screen_driver()->text_editor_extra_key_bindings;
if (extra_key_bindings) { // add platform-specific key bindings, if any
for (int i = 0; extra_key_bindings[i].key; i++) {
add_key_binding(extra_key_bindings[i].key,
extra_key_bindings[i].state,
extra_key_bindings[i].function,
list);
}
}
}

/** Returns the function associated with a key binding.*/
Expand Down Expand Up @@ -544,12 +529,10 @@ int Fl_Text_Editor::handle_key() {
if (insert_mode()) insert(Fl::event_text());
else overstrike(Fl::event_text());
}
#ifdef __APPLE__ // PORTME: Fl_Screen_Driver - platform compose
if (Fl::compose_state) {
if (Fl::screen_driver()->has_marked_text() && Fl::compose_state) {
int pos = this->insert_position();
this->buffer()->select(pos - Fl::compose_state, pos);
}
#endif
show_insert_position();
set_changed();
if (when()&FL_WHEN_CHANGED) do_callback();
Expand Down
1 change: 1 addition & 0 deletions src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.H
Expand Up @@ -53,6 +53,7 @@ protected:
static int insertion_point_height;
static bool insertion_point_location_is_valid;
public:
Fl_Cocoa_Screen_Driver();
// --- display management
// --- screen configuration
virtual void init();
Expand Down
23 changes: 23 additions & 0 deletions src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx
Expand Up @@ -43,6 +43,29 @@ Fl_Screen_Driver *Fl_Screen_Driver::newScreenDriver()
return new Fl_Cocoa_Screen_Driver();
}

static Fl_Text_Editor::Key_Binding extra_bindings[] = {
// Define CMD+key accelerators...
{ 'z', FL_COMMAND, Fl_Text_Editor::kf_undo ,0},
{ 'x', FL_COMMAND, Fl_Text_Editor::kf_cut ,0},
{ 'c', FL_COMMAND, Fl_Text_Editor::kf_copy ,0},
{ 'v', FL_COMMAND, Fl_Text_Editor::kf_paste ,0},
{ 'a', FL_COMMAND, Fl_Text_Editor::kf_select_all ,0},
{ FL_Left, FL_COMMAND, Fl_Text_Editor::kf_meta_move ,0},
{ FL_Right, FL_COMMAND, Fl_Text_Editor::kf_meta_move ,0},
{ FL_Up, FL_COMMAND, Fl_Text_Editor::kf_meta_move ,0},
{ FL_Down, FL_COMMAND, Fl_Text_Editor::kf_meta_move ,0},
{ FL_Left, FL_COMMAND|FL_SHIFT, Fl_Text_Editor::kf_m_s_move ,0},
{ FL_Right, FL_COMMAND|FL_SHIFT, Fl_Text_Editor::kf_m_s_move ,0},
{ FL_Up, FL_COMMAND|FL_SHIFT, Fl_Text_Editor::kf_m_s_move ,0},
{ FL_Down, FL_COMMAND|FL_SHIFT, Fl_Text_Editor::kf_m_s_move ,0},
{ 0, 0, 0 ,0}
};


Fl_Cocoa_Screen_Driver::Fl_Cocoa_Screen_Driver() {
text_editor_extra_key_bindings = extra_bindings;
}


void Fl_Cocoa_Screen_Driver::init()
{
Expand Down

0 comments on commit 20b00f2

Please sign in to comment.