Index: ctl/ctlSQLBox.cpp
===================================================================
--- ctl/ctlSQLBox.cpp	(revision 8173)
+++ ctl/ctlSQLBox.cpp	(working copy)
@@ -80,6 +80,21 @@
     extern sysSettings *settings;
     wxFont fntSQLBox = settings->GetSQLFont();
 
+	wxColour bgColor = settings->GetSQLBoxColourBackground();
+	if (settings->GetSQLBoxUseSystemBackground())
+	{
+		bgColor = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
+	}
+
+	wxColour frColor = settings->GetSQLBoxColourForeground();
+	if (settings->GetSQLBoxUseSystemForeground())
+	{
+		frColor = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
+	}
+
+	StyleSetBackground(wxSTC_STYLE_DEFAULT, bgColor);
+	StyleSetForeground(wxSTC_STYLE_DEFAULT, frColor);
+
     StyleSetFont(wxSTC_STYLE_DEFAULT, fntSQLBox);
     StyleSetFont(0, fntSQLBox);
     StyleSetFont(1, fntSQLBox);
@@ -99,18 +114,11 @@
     SetUseTabs(!settings->GetSpacesForTabs());
     
     // Setup the different highlight colurs
-    StyleSetForeground(0,  wxColour(0x80, 0x80, 0x80));
-    StyleSetForeground(1,  wxColour(0x00, 0x7f, 0x00));
-    StyleSetForeground(2,  wxColour(0x00, 0x7f, 0x00));
-    StyleSetForeground(3,  wxColour(0x7f, 0x7f, 0x7f));
-    StyleSetForeground(4,  wxColour(0x00, 0x7f, 0x7f));
-    StyleSetForeground(5,  wxColour(0x00, 0x00, 0x7f));
-    StyleSetForeground(6,  wxColour(0x7f, 0x00, 0x7f));
-    StyleSetForeground(7,  wxColour(0x7f, 0x00, 0x7f));
-    StyleSetForeground(8,  wxColour(0x00, 0x7f, 0x7f));
-    StyleSetForeground(9,  wxColour(0x7f, 0x7f, 0x7f));
-    StyleSetForeground(10, wxColour(0x00, 0x00, 0x00));
-    StyleSetForeground(11, wxColour(0x00, 0x00, 0x00));
+	for (int i = 0; i <= 11; ++ i )
+	{
+		StyleSetForeground(i, settings->GetSQLBoxColour(i));
+		StyleSetBackground(i, bgColor);
+	}
 
     // Brace maching styles
     StyleSetBackground(34, wxColour(0x99, 0xF9, 0xFF));
Index: frm/frmOptions.cpp
===================================================================
--- frm/frmOptions.cpp	(revision 8173)
+++ frm/frmOptions.cpp	(working copy)
@@ -73,6 +73,10 @@
 #define pickerActiveProcessColour   CTRL_COLOURPICKER("pickerActiveProcessColour")
 #define pickerSlowProcessColour     CTRL_COLOURPICKER("pickerSlowProcessColour")
 #define pickerBlockedProcessColour  CTRL_COLOURPICKER("pickerBlockedProcessColour")
+#define chkSQLUseSystemBackgroundColour  CTRL_CHECKBOX("chkSQLUseSystemBackgroundColour")
+#define chkSQLUseSystemForegroundColour  CTRL_CHECKBOX("chkSQLUseSystemForegroundColour")
+#define pickerSQLBackgroundColour     CTRL_COLOURPICKER("pickerSQLBackgroundColour")
+#define pickerSQLForegroundColour     CTRL_COLOURPICKER("pickerSQLForegroundColour")
 
 BEGIN_EVENT_TABLE(frmOptions, pgDialog)
     EVT_MENU(MNU_HELP,                                            frmOptions::OnHelp)
@@ -227,6 +231,18 @@
     pickerSlowProcessColour->SetColour(settings->GetSlowProcessColour());
     pickerBlockedProcessColour->SetColour(settings->GetBlockedProcessColour());
 
+	chkSQLUseSystemBackgroundColour->SetValue(settings->GetSQLBoxUseSystemBackground());
+	chkSQLUseSystemForegroundColour->SetValue(settings->GetSQLBoxUseSystemForeground());
+	pickerSQLBackgroundColour->SetColour(settings->GetSQLBoxColourBackground());
+    pickerSQLForegroundColour->SetColour(settings->GetSQLBoxColourForeground());
+
+	for (int i = 0; i <= 11; ++i)
+	{
+		wxString pickerId = wxString::Format(wxT("pickerSQLColour%i"), i);
+		wxColourPickerCtrl* picker = wxStaticCast(FindWindow(pickerId), wxColourPickerCtrl);
+		picker->SetColour(settings->GetSQLBoxColour(i));
+	}
+
     cbLanguage->Append(_("Default"));
     int sel=0;
     wxLanguage langId=settings->GetCanonicalLanguage();
@@ -594,6 +610,42 @@
         changed = true;
     settings->SetBlockedProcessColour(sColour);
 
+	// Change SQL Syntax colours
+	if (settings->GetSQLBoxUseSystemBackground() != chkSQLUseSystemBackgroundColour->GetValue())
+	{
+		changed = true;
+		settings->SetSQLBoxUseSystemBackground(chkSQLUseSystemBackgroundColour->GetValue());
+	}
+	
+	if (settings->GetSQLBoxUseSystemForeground() != chkSQLUseSystemForegroundColour->GetValue())
+	{
+		changed = true;
+		settings->SetSQLBoxUseSystemForeground(chkSQLUseSystemForegroundColour->GetValue());
+	}
+	
+	colour = pickerSQLBackgroundColour->GetColour();
+    sColour = colour.GetAsString(wxC2S_HTML_SYNTAX);
+    if (sColour != settings->GetSQLBoxColourBackground())
+        changed = true;
+    settings->SetSQLBoxColourBackground(sColour);
+
+	colour = pickerSQLForegroundColour->GetColour();
+    sColour = colour.GetAsString(wxC2S_HTML_SYNTAX);
+    if (sColour != settings->GetSQLBoxColourForeground())
+        changed = true;
+    settings->SetSQLBoxColourForeground(sColour);
+
+	for (int i = 0; i <= 11; ++i)
+	{
+		wxString pickerId = wxString::Format(wxT("pickerSQLColour%i"), i);
+		wxColourPickerCtrl* picker = wxStaticCast(FindWindow(pickerId), wxColourPickerCtrl);
+		colour = picker->GetColour();
+		sColour = colour.GetAsString(wxC2S_HTML_SYNTAX);
+		if (sColour != settings->GetSQLBoxColour(i))
+			changed = true;
+		settings->SetSQLBoxColour(i, sColour);
+	}
+
     // Change the language last, as it will affect our tests for changes
     // in the display object types.
     int langNo=cbLanguage->GetCurrentSelection();
Index: include/utils/sysSettings.h
===================================================================
--- include/utils/sysSettings.h	(revision 8173)
+++ include/utils/sysSettings.h	(working copy)
@@ -133,6 +133,20 @@
     wxString GetBlockedProcessColour() const { wxString s; Read(wxT("BlockedProcessColour"), &s, wxT("#d96e5f")); return s; }
 	void SetBlockedProcessColour(const wxString &newval) { Write(wxT("BlockedProcessColour"), newval); }
 
+	// SQL Editor Colours options
+	bool GetSQLBoxUseSystemBackground() const { bool b; Read(wxT("ctlSQLBox/UseSystemBackground"), &b, false); return b; }
+	void SetSQLBoxUseSystemBackground(const bool newval) { Write(wxT("ctlSQLBox/UseSystemBackground"), newval); }
+	bool GetSQLBoxUseSystemForeground() const { bool b; Read(wxT("ctlSQLBox/UseSystemForeground"), &b, false); return b; }
+	void SetSQLBoxUseSystemForeground(const bool newval) { Write(wxT("ctlSQLBox/UseSystemForeground"), newval); }
+
+    wxString GetSQLBoxColourBackground() const { wxString s; Read(wxT("ctlSQLBox/ColourBackground"), &s, wxT("#ffffff")); return s; }
+	void SetSQLBoxColourBackground(const wxString &newval) { Write(wxT("ctlSQLBox/ColourBackground"), newval); }
+    wxString GetSQLBoxColourForeground() const { wxString s; Read(wxT("ctlSQLBox/ColourForeground"), &s, wxT("#000000")); return s; }
+	void SetSQLBoxColourForeground(const wxString &newval) { Write(wxT("ctlSQLBox/ColourForeground"), newval); }
+
+    wxString GetSQLBoxColour(int index) const { wxString s; Read(wxString::Format(wxT("ctlSQLBox/Colour%i"), index), &s, getDefaultElementColor(index)); return s; }
+	void SetSQLBoxColour(int index, const wxString &newval) { Write(wxString::Format(wxT("ctlSQLBox/Colour%i"), index), newval); }
+
     // Misc options
     long GetAutoRowCountThreshold() const { long l; Read(wxT("AutoRowCount"), &l, 2000L); return l; }
 	void SetAutoRowCountThreshold(const long newval) { Write(wxT("AutoRowCount"), newval); }
@@ -187,6 +201,17 @@
 
 private:
 
+	static const wxString& getDefaultElementColor(int index)
+	{
+		static const wxString colors[] =
+		{
+			wxT("#808080"), wxT("#007f00"), wxT("#007f00"), wxT("#7f7f7f"), 
+			wxT("#007f7f"), wxT("#00007f"), wxT("#7f007f"), wxT("#7f007f"), 
+			wxT("#007f7f"), wxT("#7f7f7f"), wxT("#000000"), wxT("#000000")
+		};
+		return colors[index];
+	}
+
     bool moveStringValue(const wxChar *oldKey, const wxChar *newKey, int index=-1);
     bool moveLongValue(const wxChar *oldKey, const wxChar *newKey, int index=-1);
 
Index: ui/frmOptions.xrc
===================================================================
--- ui/frmOptions.xrc	(revision 8173)
+++ ui/frmOptions.xrc	(working copy)
@@ -419,6 +419,151 @@
           </object>
         </object>
       </object>
+      <object class="notebookpage">
+        <label>SQL Syntax Highlight</label>
+        <object class="wxPanel" name="pnlSQLSyntaxHighlight">
+          <object class="wxCheckBox" name="chkSQLUseSystemBackgroundColour">
+            <label>Use system background color</label>
+            <pos>5,5d</pos>
+            <size>226,12d</size>
+            <style></style>
+          </object>
+          
+          <object class="wxCheckBox" name="chkSQLUseSystemForegroundColour">
+            <label>Use system foreground color</label>
+            <pos>5,20d</pos>
+            <size>226,12d</size>
+            <style></style>
+          </object>
+          
+          <object class="wxStaticText" name="stSQLCustomBackgroundColour">
+            <label>Custom background</label>
+            <pos>5,35d</pos>
+          </object>
+          <object class="wxColourPickerCtrl" name="pickerSQLBackgroundColour">
+            <pos>100,35d</pos>
+            <size>50,12d</size>
+          </object>
+
+          <object class="wxStaticText" name="stSQLCustomForegroundColour">
+            <label>Custom foreground</label>
+            <pos>5,50d</pos>
+          </object>
+          <object class="wxColourPickerCtrl" name="pickerSQLForegroundColour">
+            <pos>100,50d</pos>
+            <size>50,12d</size>
+          </object>
+
+          <object class="wxStaticText" name="stSQLColour0">
+            <label>Element colour 1</label>
+            <pos>5,75d</pos>
+          </object>
+          <object class="wxColourPickerCtrl" name="pickerSQLColour0">
+            <pos>70,75d</pos>
+            <size>50,12d</size>
+          </object>
+
+          <object class="wxStaticText" name="stSQLColour1">
+            <label>Element colour 2</label>
+            <pos>5,90d</pos>
+          </object>
+          <object class="wxColourPickerCtrl" name="pickerSQLColour1">
+            <pos>70,90d</pos>
+            <size>50,12d</size>
+          </object>
+
+          <object class="wxStaticText" name="stSQLColour2">
+            <label>Element colour 3</label>
+            <pos>5,105d</pos>
+          </object>
+          <object class="wxColourPickerCtrl" name="pickerSQLColour2">
+            <pos>70,105d</pos>
+            <size>50,12d</size>
+          </object>
+
+          <object class="wxStaticText" name="stSQLColour3">
+            <label>Element colour 4</label>
+            <pos>5,120d</pos>
+          </object>
+          <object class="wxColourPickerCtrl" name="pickerSQLColour3">
+            <pos>70,120d</pos>
+            <size>50,12d</size>
+          </object>
+
+          <object class="wxStaticText" name="stSQLColour4">
+            <label>Element colour 5</label>
+            <pos>5,135d</pos>
+          </object>
+          <object class="wxColourPickerCtrl" name="pickerSQLColour4">
+            <pos>70,135d</pos>
+            <size>50,12d</size>
+          </object>
+
+          <object class="wxStaticText" name="stSQLColour5">
+            <label>Element colour 6</label>
+            <pos>5,150d</pos>
+          </object>
+          <object class="wxColourPickerCtrl" name="pickerSQLColour5">
+            <pos>70,150d</pos>
+            <size>50,12d</size>
+          </object>
+
+          <object class="wxStaticText" name="stSQLColour6">
+            <label>Element colour 7</label>
+            <pos>125,75d</pos>
+          </object>
+          <object class="wxColourPickerCtrl" name="pickerSQLColour6">
+            <pos>195,75d</pos>
+            <size>50,12d</size>
+          </object>
+
+          <object class="wxStaticText" name="stSQLColour7">
+            <label>Element colour 8</label>
+            <pos>125,90d</pos>
+          </object>
+          <object class="wxColourPickerCtrl" name="pickerSQLColour7">
+            <pos>195,90d</pos>
+            <size>50,12d</size>
+          </object>
+
+          <object class="wxStaticText" name="stSQLColour8">
+            <label>Element colour 9</label>
+            <pos>125,105d</pos>
+          </object>
+          <object class="wxColourPickerCtrl" name="pickerSQLColour8">
+            <pos>195,105d</pos>
+            <size>50,12d</size>
+          </object>
+
+          <object class="wxStaticText" name="stSQLColour9">
+            <label>Element colour 10</label>
+            <pos>125,120d</pos>
+          </object>
+          <object class="wxColourPickerCtrl" name="pickerSQLColour9">
+            <pos>195,120d</pos>
+            <size>50,12d</size>
+          </object>
+
+          <object class="wxStaticText" name="stSQLColour10">
+            <label>Element colour 11</label>
+            <pos>125,135d</pos>
+          </object>
+          <object class="wxColourPickerCtrl" name="pickerSQLColour10">
+            <pos>195,135d</pos>
+            <size>50,12d</size>
+          </object>
+
+          <object class="wxStaticText" name="stSQLColour11">
+            <label>Element colour 12</label>
+            <pos>125,150d</pos>
+          </object>
+          <object class="wxColourPickerCtrl" name="pickerSQLColour11">
+            <pos>195,150d</pos>
+            <size>50,12d</size>
+          </object>
+          
+        </object>
+      </object>
     </object>
     <object class="wxButton" name="wxID_HELP">
       <label>&amp;Help</label>
