From bea330233da7a7f083347765ec9afd2387ed6944 Mon Sep 17 00:00:00 2001 From: Martin Stransky Date: Thu, 13 Sep 2012 21:56:59 -0400 Subject: [PATCH] Bug 627699 - Port GTK2 to GTK3, gtk-rest. r=karlt --- widget/gtk2/gtk2compat.h | 14 ++++++++ widget/gtk2/nsClipboard.cpp | 56 ++++++++++++++++++----------- widget/gtk2/nsDeviceContextSpecG.h | 4 +++ widget/gtk2/nsDragService.cpp | 38 ++++++++++++++------ widget/gtk2/nsFilePicker.cpp | 5 +-- widget/gtk2/nsGTKToolkit.h | 5 --- widget/gtk2/nsGtkIMModule.cpp | 10 +++++- widget/gtk2/nsGtkKeyUtils.cpp | 3 ++ widget/gtk2/nsIdleServiceGTK.cpp | 8 +++-- widget/gtk2/nsNativeKeyBindings.cpp | 6 +++- widget/gtk2/nsPrintDialogGTK.cpp | 21 ++++++++++- widget/gtk2/nsPrintSettingsGTK.h | 4 +++ widget/gtk2/nsScreenGtk.cpp | 7 ++-- widget/gtk2/nsScreenManagerGtk.cpp | 15 +++++--- widget/gtk2/nsToolkit.cpp | 32 +---------------- widget/gtk2/nsWindow.cpp | 17 +++------ 16 files changed, 151 insertions(+), 94 deletions(-) diff --git a/widget/gtk2/gtk2compat.h b/widget/gtk2/gtk2compat.h index 766c6514d2f3..a77f2ed5cc45 100644 --- a/widget/gtk2/gtk2compat.h +++ b/widget/gtk2/gtk2compat.h @@ -177,6 +177,20 @@ gtk_window_group_get_current_grab(GtkWindowGroup *window_group) return GTK_WIDGET(window_group->grabs->data); } + +static inline GList * +gdk_drag_context_list_targets(GdkDragContext *context) +{ + return context->targets; +} +#endif + +#if !GTK_CHECK_VERSION(2, 23, 3) +static inline GdkWindow * +gdk_drag_context_get_dest_window(GdkDragContext *context) +{ + return context->dest_window; +} #endif #if !GTK_CHECK_VERSION(2, 24, 0) diff --git a/widget/gtk2/nsClipboard.cpp b/widget/gtk2/nsClipboard.cpp index 1eaabb8c408e..36a3adf54432 100644 --- a/widget/gtk2/nsClipboard.cpp +++ b/widget/gtk2/nsClipboard.cpp @@ -31,6 +31,10 @@ #include #include +#if (MOZ_WIDGET_GTK == 2) +#include "gtk2compat.h" +#endif + using namespace mozilla; // Callback when someone asks us for the data @@ -331,8 +335,10 @@ nsClipboard::GetData(nsITransferable *aTransferable, int32_t aWhichClipboard) continue; nsCOMPtr byteStream; - NS_NewByteInputStream(getter_AddRefs(byteStream), (const char*)selectionData->data, - selectionData->length, NS_ASSIGNMENT_COPY); + NS_NewByteInputStream(getter_AddRefs(byteStream), + (const char*)gtk_selection_data_get_data(selectionData), + gtk_selection_data_get_length(selectionData), + NS_ASSIGNMENT_COPY); aTransferable->SetTransferData(flavorStr, byteStream, sizeof(nsIInputStream*)); gtk_selection_data_free(selectionData); return NS_OK; @@ -344,13 +350,14 @@ nsClipboard::GetData(nsITransferable *aTransferable, int32_t aWhichClipboard) GtkSelectionData *selectionData; selectionData = wait_for_contents(clipboard, atom); if (selectionData) { - length = selectionData->length; + const guchar *clipboardData = gtk_selection_data_get_data(selectionData); + length = gtk_selection_data_get_length(selectionData); // Special case text/html since we can convert into UCS2 if (!strcmp(flavorStr, kHTMLMime)) { PRUnichar* htmlBody= nullptr; int32_t htmlBodyLen = 0; // Convert text/html into our unicode format - ConvertHTMLtoUCS2((guchar *)selectionData->data, length, + ConvertHTMLtoUCS2(const_cast(clipboardData), length, &htmlBody, htmlBodyLen); // Try next data format? if (!htmlBodyLen) @@ -361,7 +368,7 @@ nsClipboard::GetData(nsITransferable *aTransferable, int32_t aWhichClipboard) data = (guchar *)nsMemory::Alloc(length); if (!data) break; - memcpy(data, selectionData->data, length); + memcpy(data, clipboardData, length); } foundData = true; foundFlavor = flavorStr; @@ -513,9 +520,10 @@ nsClipboard::SelectionGetEvent(GtkClipboard *aClipboard, int32_t whichClipboard; // which clipboard? - if (aSelectionData->selection == GDK_SELECTION_PRIMARY) + GdkAtom selection = gtk_selection_data_get_selection(aSelectionData); + if (selection == GDK_SELECTION_PRIMARY) whichClipboard = kSelectionClipboard; - else if (aSelectionData->selection == GDK_SELECTION_CLIPBOARD) + else if (selection == GDK_SELECTION_CLIPBOARD) whichClipboard = kGlobalClipboard; else return; // THAT AIN'T NO CLIPBOARD I EVER HEARD OF @@ -534,12 +542,15 @@ nsClipboard::SelectionGetEvent(GtkClipboard *aClipboard, nsCOMPtr item; uint32_t len; + + GdkAtom selectionTarget = gtk_selection_data_get_target(aSelectionData); + // Check to see if the selection data includes any of the string // types that we support. - if (aSelectionData->target == gdk_atom_intern ("STRING", FALSE) || - aSelectionData->target == gdk_atom_intern ("TEXT", FALSE) || - aSelectionData->target == gdk_atom_intern ("COMPOUND_TEXT", FALSE) || - aSelectionData->target == gdk_atom_intern ("UTF8_STRING", FALSE)) { + if (selectionTarget == gdk_atom_intern ("STRING", FALSE) || + selectionTarget == gdk_atom_intern ("TEXT", FALSE) || + selectionTarget == gdk_atom_intern ("COMPOUND_TEXT", FALSE) || + selectionTarget == gdk_atom_intern ("UTF8_STRING", FALSE)) { // Try to convert our internal type into a text string. Get // the transferable for this clipboard and try to get the // text/unicode type for it. @@ -567,7 +578,7 @@ nsClipboard::SelectionGetEvent(GtkClipboard *aClipboard, } // Check to see if the selection data is an image type - if (gtk_targets_include_image(&aSelectionData->target, 1, TRUE)) { + if (gtk_targets_include_image(&selectionTarget, 1, TRUE)) { // Look through our transfer data for the image static const char* const imageMimeTypes[] = { kNativeImageMime, kPNGImageMime, kJPEGImageMime, kJPGImageMime, kGIFImageMime }; @@ -598,7 +609,7 @@ nsClipboard::SelectionGetEvent(GtkClipboard *aClipboard, // Try to match up the selection data target to something our // transferable provides. - gchar *target_name = gdk_atom_name(aSelectionData->target); + gchar *target_name = gdk_atom_name(selectionTarget); if (!target_name) return; @@ -615,7 +626,7 @@ nsClipboard::SelectionGetEvent(GtkClipboard *aClipboard, if (primitive_data) { // Check to see if the selection data is text/html - if (aSelectionData->target == gdk_atom_intern (kHTMLMime, FALSE)) { + if (selectionTarget == gdk_atom_intern (kHTMLMime, FALSE)) { /* * "text/html" can be encoded UCS2. It is recommended that * documents transmitted as UCS2 always begin with a ZERO-WIDTH @@ -635,7 +646,7 @@ nsClipboard::SelectionGetEvent(GtkClipboard *aClipboard, len += sizeof(prefix); } - gtk_selection_data_set(aSelectionData, aSelectionData->target, + gtk_selection_data_set(aSelectionData, selectionTarget, 8, /* 8 bits in a unit */ (const guchar *)primitive_data, len); nsMemory::Free(primitive_data); @@ -816,7 +827,7 @@ DispatchSelectionNotifyEvent(GtkWidget *widget, XEvent *xevent) { GdkEvent event; event.selection.type = GDK_SELECTION_NOTIFY; - event.selection.window = widget->window; + event.selection.window = gtk_widget_get_window(widget); event.selection.selection = gdk_x11_xatom_to_atom(xevent->xselection.selection); event.selection.target = gdk_x11_xatom_to_atom(xevent->xselection.target); event.selection.property = gdk_x11_xatom_to_atom(xevent->xselection.property); @@ -828,10 +839,11 @@ DispatchSelectionNotifyEvent(GtkWidget *widget, XEvent *xevent) static void DispatchPropertyNotifyEvent(GtkWidget *widget, XEvent *xevent) { - if (((GdkWindowObject *) widget->window)->event_mask & GDK_PROPERTY_CHANGE_MASK) { + GdkWindow *window = gtk_widget_get_window(widget); + if ((gdk_window_get_events(window)) & GDK_PROPERTY_CHANGE_MASK) { GdkEvent event; event.property.type = GDK_PROPERTY_NOTIFY; - event.property.window = widget->window; + event.property.window = window; event.property.atom = gdk_x11_xatom_to_atom(xevent->xproperty.atom); event.property.time = xevent->xproperty.time; event.property.state = xevent->xproperty.state; @@ -855,7 +867,9 @@ checkEventProc(Display *display, XEvent *event, XPointer arg) (event->xany.type == PropertyNotify && event->xproperty.atom == context->selAtom)) { - GdkWindow *cbWindow = gdk_window_lookup(event->xany.window); + GdkWindow *cbWindow = + gdk_x11_window_lookup_for_display(gdk_x11_lookup_xdisplay(display), + event->xany.window); if (cbWindow) { GtkWidget *cbWidget = NULL; gdk_window_get_user_data(cbWindow, (gpointer *)&cbWidget); @@ -878,7 +892,7 @@ wait_for_retrieval(GtkClipboard *clipboard, retrieval_context *r_context) if (r_context->completed) // the request completed synchronously return true; - Display *xDisplay = GDK_DISPLAY(); + Display *xDisplay = GDK_DISPLAY_XDISPLAY(gdk_display_get_default()) ; checkEventContext context; context.cbWidget = NULL; context.selAtom = gdk_x11_atom_to_xatom(gdk_atom_intern("GDK_SELECTION", @@ -937,7 +951,7 @@ clipboard_contents_received(GtkClipboard *clipboard, context->completed = true; - if (selection_data->length >= 0) + if (gtk_selection_data_get_length(selection_data) >= 0) context->data = gtk_selection_data_copy(selection_data); } diff --git a/widget/gtk2/nsDeviceContextSpecG.h b/widget/gtk2/nsDeviceContextSpecG.h index b273718e55ef..e7823c70287f 100644 --- a/widget/gtk2/nsDeviceContextSpecG.h +++ b/widget/gtk2/nsDeviceContextSpecG.h @@ -16,8 +16,12 @@ #include "nsCRT.h" /* should be ? */ #include +#if (MOZ_WIDGET_GTK == 2) #include #include +#else +#include +#endif #define NS_PORTRAIT 0 #define NS_LANDSCAPE 1 diff --git a/widget/gtk2/nsDragService.cpp b/widget/gtk2/nsDragService.cpp index 78be20309d6f..d2deaf393b81 100644 --- a/widget/gtk2/nsDragService.cpp +++ b/widget/gtk2/nsDragService.cpp @@ -25,7 +25,7 @@ #include "nsCRT.h" #include "mozilla/Services.h" -#if defined(MOZ_WIDGET_GTK2) +#if (MOZ_WIDGET_GTK == 2) #include "gtk2compat.h" #endif @@ -351,7 +351,7 @@ nsDragService::InvokeDragSession(nsIDOMNode *aDOMNode, GdkEvent event; memset(&event, 0, sizeof(GdkEvent)); event.type = GDK_BUTTON_PRESS; - event.button.window = mHiddenWidget->window; + event.button.window = gtk_widget_get_window(mHiddenWidget); event.button.time = nsWindow::GetLastUserInputTime(); // Put the drag widget in the window group of the source node so that the @@ -362,6 +362,13 @@ nsDragService::InvokeDragSession(nsIDOMNode *aDOMNode, gtk_window_group_add_window(window_group, GTK_WINDOW(mHiddenWidget)); +#if (MOZ_WIDGET_GTK == 3) + // Get device for event source + GdkDisplay *display = gdk_display_get_default(); + GdkDeviceManager *device_manager = gdk_display_get_device_manager(display); + event.button.device = gdk_device_manager_get_client_pointer(device_manager); +#endif + // start our drag. GdkDragContext *context = gtk_drag_begin(mHiddenWidget, sourceList, @@ -402,6 +409,7 @@ nsDragService::SetAlphaPixmap(gfxASurface *aSurface, int32_t aYOffset, const nsIntRect& dragRect) { +#if (MOZ_WIDGET_GTK == 2) GdkScreen* screen = gtk_widget_get_screen(mHiddenWidget); // Transparent drag icons need, like a lot of transparency-related things, @@ -443,6 +451,10 @@ nsDragService::SetAlphaPixmap(gfxASurface *aSurface, aXOffset, aYOffset); g_object_unref(pixmap); return true; +#else + // TODO GTK3 + return false; +#endif } NS_IMETHODIMP @@ -974,7 +986,8 @@ nsDragService::IsDataFlavorSupported(const char *aDataFlavor, // check the target context vs. this flavor, one at a time GList *tmp; - for (tmp = mTargetDragContext->targets; tmp; tmp = tmp->next) { + for (tmp = gdk_drag_context_list_targets(mTargetDragContext); + tmp; tmp = tmp->next) { /* Bug 331198 */ GdkAtom atom = GDK_POINTER_TO_ATOM(tmp->data); gchar *name = NULL; @@ -1058,15 +1071,16 @@ nsDragService::TargetDataReceived(GtkWidget *aWidget, PR_LOG(sDragLm, PR_LOG_DEBUG, ("nsDragService::TargetDataReceived")); TargetResetData(); mTargetDragDataReceived = true; - if (aSelectionData->length > 0) { - mTargetDragDataLen = aSelectionData->length; + mTargetDragDataLen = gtk_selection_data_get_length(aSelectionData); + if (mTargetDragDataLen > 0) { mTargetDragData = g_malloc(mTargetDragDataLen); - memcpy(mTargetDragData, aSelectionData->data, mTargetDragDataLen); + memcpy(mTargetDragData, gtk_selection_data_get_data(aSelectionData), + mTargetDragDataLen); } else { PR_LOG(sDragLm, PR_LOG_DEBUG, ("Failed to get data. selection data len was %d\n", - aSelectionData->length)); + mTargetDragDataLen)); } } @@ -1086,7 +1100,8 @@ nsDragService::IsTargetContextList(void) // walk the list of context targets and see if one of them is a list // of items. - for (tmp = mTargetDragContext->targets; tmp; tmp = tmp->next) { + for (tmp = gdk_drag_context_list_targets(mTargetDragContext); + tmp; tmp = tmp->next) { /* Bug 331198 */ GdkAtom atom = GDK_POINTER_TO_ATOM(tmp->data); gchar *name = NULL; @@ -1363,7 +1378,8 @@ nsDragService::SourceEndDragSession(GdkDragContext *aContext, // cancelled (but no drag-failed signal would have been sent). // aContext->dest_window will be non-NULL only if the drop was sent. GdkDragAction action = - aContext->dest_window ? aContext->action : (GdkDragAction)0; + gdk_drag_context_get_dest_window(aContext) ? + gdk_drag_context_get_actions(aContext) : (GdkDragAction)0; // Only one bit of action should be set, but, just in case someone // does something funny, erring away from MOVE, and not recording @@ -1556,7 +1572,7 @@ nsDragService::SourceDataGet(GtkWidget *aWidget, if (tmpData) { // this copies the data gtk_selection_data_set(aSelectionData, - aSelectionData->target, + gtk_selection_data_get_target(aSelectionData), 8, (guchar *)tmpData, tmpDataLen); // this wasn't allocated with glib @@ -1569,7 +1585,7 @@ nsDragService::SourceDataGet(GtkWidget *aWidget, gint length; CreateUriList(mSourceDataItems, &uriList, &length); gtk_selection_data_set(aSelectionData, - aSelectionData->target, + gtk_selection_data_get_target(aSelectionData), 8, (guchar *)uriList, length); g_free(uriList); return; diff --git a/widget/gtk2/nsFilePicker.cpp b/widget/gtk2/nsFilePicker.cpp index 56629cde613f..2a54d3c5347c 100644 --- a/widget/gtk2/nsFilePicker.cpp +++ b/widget/gtk2/nsFilePicker.cpp @@ -433,8 +433,9 @@ nsFilePicker::Open(nsIFilePickerShownCallback *aCallback) gtk_window_set_modal(window, TRUE); if (parent_widget) { gtk_window_set_destroy_with_parent(window, TRUE); - if (parent_widget->group) { - gtk_window_group_add_window(parent_widget->group, window); + GtkWindowGroup *parentGroup = gtk_window_get_group(parent_widget); + if (parentGroup) { + gtk_window_group_add_window(parentGroup, window); } } diff --git a/widget/gtk2/nsGTKToolkit.h b/widget/gtk2/nsGTKToolkit.h index df5d81183494..ae0d55b632e9 100644 --- a/widget/gtk2/nsGTKToolkit.h +++ b/widget/gtk2/nsGTKToolkit.h @@ -21,7 +21,6 @@ class nsGTKToolkit { public: nsGTKToolkit(); - virtual ~nsGTKToolkit(); static nsGTKToolkit* GetToolkit(); @@ -30,9 +29,6 @@ public: gToolkit = nullptr; } - void CreateSharedGC(void); - GdkGC *GetSharedGC(void); - /** * Get/set our value of DESKTOP_STARTUP_ID. When non-empty, this is applied * to the next toplevel window to be shown or focused (and then immediately @@ -51,7 +47,6 @@ public: private: static nsGTKToolkit* gToolkit; - GdkGC *mSharedGC; nsCString mDesktopStartupID; uint32_t mFocusTimestamp; }; diff --git a/widget/gtk2/nsGtkIMModule.cpp b/widget/gtk2/nsGtkIMModule.cpp index f3e7877b3ec2..5b1629f1962e 100644 --- a/widget/gtk2/nsGtkIMModule.cpp +++ b/widget/gtk2/nsGtkIMModule.cpp @@ -24,6 +24,10 @@ #include "mozilla/Services.h" #endif +#if (MOZ_WIDGET_GTK == 2) +#include "gtk2compat.h" +#endif + using namespace mozilla; using namespace mozilla::widget; @@ -101,7 +105,7 @@ nsGtkIMModule::Init() MozContainer* container = mOwnerWindow->GetMozContainer(); NS_PRECONDITION(container, "container is null"); - GdkWindow* gdkWindow = GTK_WIDGET(container)->window; + GdkWindow* gdkWindow = gtk_widget_get_window(GTK_WIDGET(container)); // NOTE: gtk_im_*_new() abort (kill) the whole process when it fails. // So, we don't need to check the result. @@ -255,7 +259,11 @@ nsGtkIMModule::PrepareToDestroyContext(GtkIMContext *aContext) NS_PRECONDITION(container, "The container of the window is null"); GtkIMMulticontext *multicontext = GTK_IM_MULTICONTEXT(aContext); +#if (MOZ_WIDGET_GTK == 2) GtkIMContext *slave = multicontext->slave; +#else + GtkIMContext *slave = NULL; //TODO GTK3 +#endif if (!slave) { return; } diff --git a/widget/gtk2/nsGtkKeyUtils.cpp b/widget/gtk2/nsGtkKeyUtils.cpp index 026e342f4989..7166b83a8727 100644 --- a/widget/gtk2/nsGtkKeyUtils.cpp +++ b/widget/gtk2/nsGtkKeyUtils.cpp @@ -18,6 +18,9 @@ #ifdef MOZ_X11 #include #endif /* MOZ_X11 */ +#if (MOZ_WIDGET_GTK == 3) +#include +#endif #include "nsGUIEvent.h" #include "WidgetUtils.h" #include "keysym2ucs.h" diff --git a/widget/gtk2/nsIdleServiceGTK.cpp b/widget/gtk2/nsIdleServiceGTK.cpp index 8fa5f4b16d84..89a4043583f2 100644 --- a/widget/gtk2/nsIdleServiceGTK.cpp +++ b/widget/gtk2/nsIdleServiceGTK.cpp @@ -5,12 +5,16 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include + #include "nsIdleServiceGTK.h" #include "nsIServiceManager.h" #include "nsDebug.h" #include "prlink.h" #include "prlog.h" - +#if (MOZ_WIDGET_GTK == 2) +#include "gtk2compat.h" +#endif #ifdef PR_LOGGING static PRLogModuleInfo* sIdleLog = nullptr; @@ -102,7 +106,7 @@ nsIdleServiceGTK::PollIdleTime(uint32_t *aIdleTime) *aIdleTime = 0; // We might not have a display (cf. in xpcshell) - Display *dplay = GDK_DISPLAY(); + Display *dplay = GDK_DISPLAY_XDISPLAY(gdk_display_get_default()); if (!dplay) { #ifdef PR_LOGGING PR_LOG(sIdleLog, PR_LOG_WARNING, ("No display found!\n")); diff --git a/widget/gtk2/nsNativeKeyBindings.cpp b/widget/gtk2/nsNativeKeyBindings.cpp index cb8ea9c2900e..655e6864346d 100644 --- a/widget/gtk2/nsNativeKeyBindings.cpp +++ b/widget/gtk2/nsNativeKeyBindings.cpp @@ -308,9 +308,13 @@ nsNativeKeyBindings::KeyPressInternal(const nsNativeKeyEvent& aEvent, gCurrentCallbackData = aCallbackData; gHandled = false; - +#if (MOZ_WIDGET_GTK == 2) gtk_bindings_activate(GTK_OBJECT(mNativeTarget), aKeyCode, GdkModifierType(modifiers)); +#else + gtk_bindings_activate(G_OBJECT(mNativeTarget), + aKeyCode, GdkModifierType(modifiers)); +#endif gCurrentCallback = nullptr; gCurrentCallbackData = nullptr; diff --git a/widget/gtk2/nsPrintDialogGTK.cpp b/widget/gtk2/nsPrintDialogGTK.cpp index ae8776caed28..0be3f62d674a 100644 --- a/widget/gtk2/nsPrintDialogGTK.cpp +++ b/widget/gtk2/nsPrintDialogGTK.cpp @@ -4,7 +4,12 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include +#if (MOZ_WIDGET_GTK == 2) #include +#include "gtk2compat.h" +#else +#include +#endif #include #include "mozilla/Util.h" @@ -77,7 +82,11 @@ ShowCustomDialog(GtkComboBox *changed_box, gpointer user_data) printBundle->GetStringFromName(NS_LITERAL_STRING("headerFooterCustom").get(), getter_Copies(intlString)); GtkWidget* prompt_dialog = gtk_dialog_new_with_buttons(NS_ConvertUTF16toUTF8(intlString).get(), printDialog, +#if (MOZ_WIDGET_GTK == 2) (GtkDialogFlags)(GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR), +#else + (GtkDialogFlags)(GTK_DIALOG_MODAL), +#endif GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, NULL); @@ -110,7 +119,8 @@ ShowCustomDialog(GtkComboBox *changed_box, gpointer user_data) gtk_container_set_border_width(GTK_CONTAINER(custom_hbox), 2); gtk_widget_show_all(custom_hbox); - gtk_box_pack_start(GTK_BOX(GTK_DIALOG(prompt_dialog)->vbox), custom_hbox, FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(prompt_dialog))), + custom_hbox, FALSE, FALSE, 0); gint diag_response = gtk_dialog_run(GTK_DIALOG(prompt_dialog)); if (diag_response == GTK_RESPONSE_ACCEPT) { @@ -481,14 +491,23 @@ nsPrintDialogWidgetGTK::ExportSettings(nsIPrintSettings *aNSSettings) GtkWidget* nsPrintDialogWidgetGTK::ConstructHeaderFooterDropdown(const PRUnichar *currentString) { +#if (MOZ_WIDGET_GTK == 2) GtkWidget* dropdown = gtk_combo_box_new_text(); +#else + GtkWidget* dropdown = gtk_combo_box_text_new(); +#endif const char hf_options[][22] = {"headerFooterBlank", "headerFooterTitle", "headerFooterURL", "headerFooterDate", "headerFooterPage", "headerFooterPageTotal", "headerFooterCustom"}; for (unsigned int i = 0; i < ArrayLength(hf_options); i++) { +#if (MOZ_WIDGET_GTK == 2) gtk_combo_box_append_text(GTK_COMBO_BOX(dropdown), GetUTF8FromBundle(hf_options[i]).get()); +#else + gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(dropdown), NULL, + GetUTF8FromBundle(hf_options[i]).get()); +#endif } bool shouldBeCustom = true; diff --git a/widget/gtk2/nsPrintSettingsGTK.h b/widget/gtk2/nsPrintSettingsGTK.h index d85d0c72a948..d008e847719e 100644 --- a/widget/gtk2/nsPrintSettingsGTK.h +++ b/widget/gtk2/nsPrintSettingsGTK.h @@ -11,8 +11,12 @@ extern "C" { #include +#if (MOZ_WIDGET_GTK == 2) #include #include +#else +#include +#endif } #define NS_PRINTSETTINGSGTK_IID \ diff --git a/widget/gtk2/nsScreenGtk.cpp b/widget/gtk2/nsScreenGtk.cpp index 076b7de9a24e..31545e50f7c4 100644 --- a/widget/gtk2/nsScreenGtk.cpp +++ b/widget/gtk2/nsScreenGtk.cpp @@ -11,6 +11,9 @@ #include #endif #include +#if (MOZ_WIDGET_GTK == 2) +#include "gtk2compat.h" +#endif nsScreenGtk :: nsScreenGtk ( ) : mScreenNum(0), @@ -54,8 +57,8 @@ nsScreenGtk :: GetAvailRect(int32_t *outLeft, int32_t *outTop, int32_t *outWidth NS_IMETHODIMP nsScreenGtk :: GetPixelDepth(int32_t *aPixelDepth) { - GdkVisual * rgb_visual = gdk_rgb_get_visual(); - *aPixelDepth = rgb_visual->depth; + GdkVisual * visual = gdk_screen_get_system_visual(gdk_screen_get_default()); + *aPixelDepth = gdk_visual_get_depth(visual); return NS_OK; diff --git a/widget/gtk2/nsScreenManagerGtk.cpp b/widget/gtk2/nsScreenManagerGtk.cpp index 9311abfd9532..c9428ade6331 100644 --- a/widget/gtk2/nsScreenManagerGtk.cpp +++ b/widget/gtk2/nsScreenManagerGtk.cpp @@ -132,9 +132,9 @@ nsScreenManagerGtk :: Init() PR_FindFunctionSymbol(mXineramalib, "XineramaQueryScreens"); // get the number of screens via xinerama - if (_XnrmIsActive && _XnrmQueryScreens && - _XnrmIsActive(GDK_DISPLAY())) { - screenInfo = _XnrmQueryScreens(GDK_DISPLAY(), &numScreens); + Display *display = GDK_DISPLAY_XDISPLAY(gdk_display_get_default()); + if (_XnrmIsActive && _XnrmQueryScreens && _XnrmIsActive(display)) { + screenInfo = _XnrmQueryScreens(display, &numScreens); } } @@ -297,11 +297,18 @@ nsScreenManagerGtk :: ScreenForNativeWidget (void *aWidget, nsIScreen **outScree if (mCachedScreenArray.Count() > 1) { // I don't know how to go from GtkWindow to nsIScreen, especially // given xinerama and stuff, so let's just do this - gint x, y, width, height, depth; + gint x, y, width, height; +#if (MOZ_WIDGET_GTK == 2) + gint depth; +#endif x = y = width = height = 0; +#if (MOZ_WIDGET_GTK == 2) gdk_window_get_geometry(GDK_WINDOW(aWidget), &x, &y, &width, &height, &depth); +#else + gdk_window_get_geometry(GDK_WINDOW(aWidget), &x, &y, &width, &height); +#endif gdk_window_get_origin(GDK_WINDOW(aWidget), &x, &y); rv = ScreenForRect(x, y, width, height, outScreen); } else { diff --git a/widget/gtk2/nsToolkit.cpp b/widget/gtk2/nsToolkit.cpp index f5b71a787568..41d47ff9605d 100644 --- a/widget/gtk2/nsToolkit.cpp +++ b/widget/gtk2/nsToolkit.cpp @@ -16,38 +16,8 @@ nsGTKToolkit* nsGTKToolkit::gToolkit = nullptr; // //------------------------------------------------------------------------- nsGTKToolkit::nsGTKToolkit() - : mSharedGC(nullptr), mFocusTimestamp(0) + : mFocusTimestamp(0) { - CreateSharedGC(); -} - -//------------------------------------------------------------------------- -// -// destructor -// -//------------------------------------------------------------------------- -nsGTKToolkit::~nsGTKToolkit() -{ - if (mSharedGC) { - g_object_unref(mSharedGC); - } -} - -void nsGTKToolkit::CreateSharedGC(void) -{ - GdkPixmap *pixmap; - - if (mSharedGC) - return; - - pixmap = gdk_pixmap_new(NULL, 1, 1, gdk_rgb_get_visual()->depth); - mSharedGC = gdk_gc_new(pixmap); - g_object_unref(pixmap); -} - -GdkGC *nsGTKToolkit::GetSharedGC(void) -{ - return (GdkGC *)g_object_ref(mSharedGC); } //------------------------------------------------------------------------------- diff --git a/widget/gtk2/nsWindow.cpp b/widget/gtk2/nsWindow.cpp index 8ae32cf9b31a..a7b62a36fbfa 100644 --- a/widget/gtk2/nsWindow.cpp +++ b/widget/gtk2/nsWindow.cpp @@ -26,7 +26,7 @@ #include "nsGtkCursors.h" #include -#if defined(MOZ_WIDGET_GTK3) +#if (MOZ_WIDGET_GTK == 3) #include #endif #ifdef MOZ_X11 @@ -34,7 +34,7 @@ #include #include #include -#if defined(MOZ_WIDGET_GTK3) +#if (MOZ_WIDGET_GTK == 3) #include #endif @@ -44,7 +44,9 @@ #include #endif +#if (MOZ_WIDGET_GTK == 2) #include "gtk2xtbin.h" +#endif #endif /* MOZ_X11 */ #include #if defined(MOZ_WIDGET_GTK2) @@ -1681,17 +1683,6 @@ nsWindow::GetNativeData(uint32_t aDataType) #endif /* MOZ_X11 */ break; - case NS_NATIVE_GRAPHIC: { -#if defined(MOZ_WIDGET_GTK2) - nsGTKToolkit* toolkit = nsGTKToolkit::GetToolkit(); - NS_ASSERTION(nullptr != toolkit, "NULL toolkit, unable to get a GC"); - return toolkit->GetSharedGC(); -#else - return nullptr; -#endif - break; - } - case NS_NATIVE_SHELLWIDGET: return (void *) mShell;