mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-09 17:38:00 +00:00
Break up gtkmisc.c.
It's another file that should have been subdivided into lots of tiny separate things in the utils library - especially since for some reason I made a completely separate 'guimisc' cmake-level library for it when there was no need.
This commit is contained in:
parent
7f3a3a21eb
commit
d9f217323e
@ -145,14 +145,17 @@ target_link_libraries(uppity
|
|||||||
|
|
||||||
if(GTK_FOUND)
|
if(GTK_FOUND)
|
||||||
add_sources_from_current_dir(utils
|
add_sources_from_current_dir(utils
|
||||||
|
utils/align_label_left.c
|
||||||
|
utils/buildinfo_gtk_version.c
|
||||||
|
utils/get_label_text_dimensions.c
|
||||||
|
utils/get_x11_display.c
|
||||||
|
utils/our_dialog.c
|
||||||
|
utils/string_width.c
|
||||||
gtkcols.c)
|
gtkcols.c)
|
||||||
add_sources_from_current_dir(guiterminal
|
add_sources_from_current_dir(guiterminal
|
||||||
gtkwin.c gtkfont.c gtkdlg.c gtkcfg.c gtkcomm.c uxcfg.c uxucs.c uxprint.c)
|
gtkwin.c gtkfont.c gtkdlg.c gtkcfg.c gtkcomm.c uxcfg.c uxucs.c uxprint.c)
|
||||||
add_dependencies(guiterminal generated_licence_h) # gtkdlg.c uses licence.h
|
add_dependencies(guiterminal generated_licence_h) # gtkdlg.c uses licence.h
|
||||||
|
|
||||||
add_library(guimisc STATIC
|
|
||||||
gtkmisc.c)
|
|
||||||
|
|
||||||
add_executable(pageant
|
add_executable(pageant
|
||||||
uxpgnt.c
|
uxpgnt.c
|
||||||
${CMAKE_SOURCE_DIR}/be_misc.c
|
${CMAKE_SOURCE_DIR}/be_misc.c
|
||||||
@ -163,7 +166,7 @@ if(GTK_FOUND)
|
|||||||
uxnoise.c
|
uxnoise.c
|
||||||
${CMAKE_SOURCE_DIR}/ssh/x11fwd.c)
|
${CMAKE_SOURCE_DIR}/ssh/x11fwd.c)
|
||||||
target_link_libraries(pageant
|
target_link_libraries(pageant
|
||||||
guimisc eventloop console agent settings network crypto utils
|
eventloop console agent settings network crypto utils
|
||||||
${GTK_LIBRARIES})
|
${GTK_LIBRARIES})
|
||||||
installed_program(pageant)
|
installed_program(pageant)
|
||||||
|
|
||||||
@ -174,7 +177,7 @@ if(GTK_FOUND)
|
|||||||
${CMAKE_SOURCE_DIR}/nogss.c
|
${CMAKE_SOURCE_DIR}/nogss.c
|
||||||
uxpty.c)
|
uxpty.c)
|
||||||
target_link_libraries(pterm
|
target_link_libraries(pterm
|
||||||
guiterminal guimisc eventloop settings charset utils
|
guiterminal eventloop settings charset utils
|
||||||
${GTK_LIBRARIES} ${X11_LIBRARIES})
|
${GTK_LIBRARIES} ${X11_LIBRARIES})
|
||||||
installed_program(pterm)
|
installed_program(pterm)
|
||||||
|
|
||||||
@ -186,7 +189,7 @@ if(GTK_FOUND)
|
|||||||
${CMAKE_SOURCE_DIR}/nogss.c
|
${CMAKE_SOURCE_DIR}/nogss.c
|
||||||
uxpty.c)
|
uxpty.c)
|
||||||
target_link_libraries(ptermapp
|
target_link_libraries(ptermapp
|
||||||
guiterminal guimisc eventloop settings charset utils
|
guiterminal eventloop settings charset utils
|
||||||
${GTK_LIBRARIES} ${X11_LIBRARIES})
|
${GTK_LIBRARIES} ${X11_LIBRARIES})
|
||||||
|
|
||||||
add_executable(putty
|
add_executable(putty
|
||||||
@ -194,7 +197,7 @@ if(GTK_FOUND)
|
|||||||
gtkmain.c
|
gtkmain.c
|
||||||
${CMAKE_SOURCE_DIR}/be_all_s.c)
|
${CMAKE_SOURCE_DIR}/be_all_s.c)
|
||||||
target_link_libraries(putty
|
target_link_libraries(putty
|
||||||
guiterminal guimisc eventloop sshclient otherbackends settings
|
guiterminal eventloop sshclient otherbackends settings
|
||||||
network crypto charset utils
|
network crypto charset utils
|
||||||
${GTK_LIBRARIES} ${X11_LIBRARIES})
|
${GTK_LIBRARIES} ${X11_LIBRARIES})
|
||||||
set_target_properties(putty
|
set_target_properties(putty
|
||||||
@ -207,7 +210,7 @@ if(GTK_FOUND)
|
|||||||
${CMAKE_SOURCE_DIR}/nocmdline.c
|
${CMAKE_SOURCE_DIR}/nocmdline.c
|
||||||
${CMAKE_SOURCE_DIR}/be_all_s.c)
|
${CMAKE_SOURCE_DIR}/be_all_s.c)
|
||||||
target_link_libraries(puttyapp
|
target_link_libraries(puttyapp
|
||||||
guiterminal guimisc eventloop sshclient otherbackends settings
|
guiterminal eventloop sshclient otherbackends settings
|
||||||
network crypto charset utils
|
network crypto charset utils
|
||||||
${GTK_LIBRARIES} ${X11_LIBRARIES})
|
${GTK_LIBRARIES} ${X11_LIBRARIES})
|
||||||
|
|
||||||
@ -219,6 +222,6 @@ if(GTK_FOUND)
|
|||||||
${CMAKE_SOURCE_DIR}/norand.c
|
${CMAKE_SOURCE_DIR}/norand.c
|
||||||
${CMAKE_SOURCE_DIR}/nocproxy.c)
|
${CMAKE_SOURCE_DIR}/nocproxy.c)
|
||||||
target_link_libraries(puttytel
|
target_link_libraries(puttytel
|
||||||
guiterminal guimisc eventloop otherbackends settings network charset utils
|
guiterminal eventloop otherbackends settings network charset utils
|
||||||
${GTK_LIBRARIES} ${X11_LIBRARIES})
|
${GTK_LIBRARIES} ${X11_LIBRARIES})
|
||||||
endif()
|
endif()
|
||||||
|
20
unix/utils/align_label_left.c
Normal file
20
unix/utils/align_label_left.c
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* Helper function to align the text in a GtkLabel to the left, which
|
||||||
|
* has to be done in several different ways depending on GTK version.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <gtk/gtk.h>
|
||||||
|
#include "putty.h"
|
||||||
|
#include "gtkcompat.h"
|
||||||
|
#include "gtkmisc.h"
|
||||||
|
|
||||||
|
void align_label_left(GtkLabel *label)
|
||||||
|
{
|
||||||
|
#if GTK_CHECK_VERSION(3,16,0)
|
||||||
|
gtk_label_set_xalign(label, 0.0);
|
||||||
|
#elif GTK_CHECK_VERSION(3,14,0)
|
||||||
|
gtk_widget_set_halign(GTK_WIDGET(label), GTK_ALIGN_START);
|
||||||
|
#else
|
||||||
|
gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0);
|
||||||
|
#endif
|
||||||
|
}
|
14
unix/utils/buildinfo_gtk_version.c
Normal file
14
unix/utils/buildinfo_gtk_version.c
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
/*
|
||||||
|
* Return the version of GTK we were compiled against, for buildinfo.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <gtk/gtk.h>
|
||||||
|
#include "putty.h"
|
||||||
|
#include "gtkcompat.h"
|
||||||
|
#include "gtkmisc.h"
|
||||||
|
|
||||||
|
char *buildinfo_gtk_version(void)
|
||||||
|
{
|
||||||
|
return dupprintf("%d.%d.%d",
|
||||||
|
GTK_MAJOR_VERSION, GTK_MINOR_VERSION, GTK_MICRO_VERSION);
|
||||||
|
}
|
42
unix/utils/get_label_text_dimensions.c
Normal file
42
unix/utils/get_label_text_dimensions.c
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* Determine the dimensions of a piece of text in the standard
|
||||||
|
* font used in GTK interface elements like labels. We do this by
|
||||||
|
* instantiating an actual GtkLabel, and then querying its size.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <gtk/gtk.h>
|
||||||
|
#include "putty.h"
|
||||||
|
#include "gtkcompat.h"
|
||||||
|
#include "gtkmisc.h"
|
||||||
|
|
||||||
|
void get_label_text_dimensions(const char *text, int *width, int *height)
|
||||||
|
{
|
||||||
|
GtkWidget *label = gtk_label_new(text);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* GTK2 and GTK3 require us to query the size completely
|
||||||
|
* differently. I'm sure there ought to be an easier approach than
|
||||||
|
* the way I'm doing this in GTK3, too!
|
||||||
|
*/
|
||||||
|
#if GTK_CHECK_VERSION(3,0,0)
|
||||||
|
PangoLayout *layout = gtk_label_get_layout(GTK_LABEL(label));
|
||||||
|
PangoRectangle logrect;
|
||||||
|
pango_layout_get_extents(layout, NULL, &logrect);
|
||||||
|
if (width)
|
||||||
|
*width = logrect.width / PANGO_SCALE;
|
||||||
|
if (height)
|
||||||
|
*height = logrect.height / PANGO_SCALE;
|
||||||
|
#else
|
||||||
|
GtkRequisition req;
|
||||||
|
gtk_widget_size_request(label, &req);
|
||||||
|
if (width)
|
||||||
|
*width = req.width;
|
||||||
|
if (height)
|
||||||
|
*height = req.height;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
g_object_ref_sink(G_OBJECT(label));
|
||||||
|
#if GTK_CHECK_VERSION(2,10,0)
|
||||||
|
g_object_unref(label);
|
||||||
|
#endif
|
||||||
|
}
|
34
unix/utils/get_x11_display.c
Normal file
34
unix/utils/get_x11_display.c
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* Return the Xlib 'Display *' underlying our GTK environment, if any.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <gtk/gtk.h>
|
||||||
|
#include "putty.h"
|
||||||
|
#include "gtkcompat.h"
|
||||||
|
#include "gtkmisc.h"
|
||||||
|
|
||||||
|
#ifndef NOT_X_WINDOWS
|
||||||
|
|
||||||
|
#include <gdk/gdkx.h>
|
||||||
|
#include <X11/Xlib.h>
|
||||||
|
|
||||||
|
Display *get_x11_display(void)
|
||||||
|
{
|
||||||
|
#if GTK_CHECK_VERSION(3,0,0)
|
||||||
|
if (!GDK_IS_X11_DISPLAY(gdk_display_get_default()))
|
||||||
|
return NULL;
|
||||||
|
#endif
|
||||||
|
return GDK_DISPLAY_XDISPLAY(gdk_display_get_default());
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Include _something_ in this file to prevent an annoying compiler
|
||||||
|
* warning, and to avoid having to condition out this file in
|
||||||
|
* CMakeLists. It's in a library, so this variable shouldn't end up in
|
||||||
|
* any actual program, because nothing will refer to it.
|
||||||
|
*/
|
||||||
|
const int get_x11_display_dummy_variable = 0;
|
||||||
|
|
||||||
|
#endif
|
@ -1,80 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
* Miscellaneous GTK helper functions.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <assert.h>
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <ctype.h>
|
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
#include <gtk/gtk.h>
|
|
||||||
#if !GTK_CHECK_VERSION(3,0,0)
|
|
||||||
#include <gdk/gdkkeysyms.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "putty.h"
|
|
||||||
#include "gtkcompat.h"
|
|
||||||
|
|
||||||
#ifndef NOT_X_WINDOWS
|
|
||||||
#include <gdk/gdkx.h>
|
|
||||||
#include <X11/Xlib.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void get_label_text_dimensions(const char *text, int *width, int *height)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* Determine the dimensions of a piece of text in the standard
|
|
||||||
* font used in GTK interface elements like labels. We do this by
|
|
||||||
* instantiating an actual GtkLabel, and then querying its size.
|
|
||||||
*
|
|
||||||
* But GTK2 and GTK3 require us to query the size completely
|
|
||||||
* differently. I'm sure there ought to be an easier approach than
|
|
||||||
* the way I'm doing this in GTK3, too!
|
|
||||||
*/
|
|
||||||
GtkWidget *label = gtk_label_new(text);
|
|
||||||
|
|
||||||
#if GTK_CHECK_VERSION(3,0,0)
|
|
||||||
PangoLayout *layout = gtk_label_get_layout(GTK_LABEL(label));
|
|
||||||
PangoRectangle logrect;
|
|
||||||
pango_layout_get_extents(layout, NULL, &logrect);
|
|
||||||
if (width)
|
|
||||||
*width = logrect.width / PANGO_SCALE;
|
|
||||||
if (height)
|
|
||||||
*height = logrect.height / PANGO_SCALE;
|
|
||||||
#else
|
|
||||||
GtkRequisition req;
|
|
||||||
gtk_widget_size_request(label, &req);
|
|
||||||
if (width)
|
|
||||||
*width = req.width;
|
|
||||||
if (height)
|
|
||||||
*height = req.height;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
g_object_ref_sink(G_OBJECT(label));
|
|
||||||
#if GTK_CHECK_VERSION(2,10,0)
|
|
||||||
g_object_unref(label);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
int string_width(const char *text)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
get_label_text_dimensions(text, &ret, NULL);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
void align_label_left(GtkLabel *label)
|
|
||||||
{
|
|
||||||
#if GTK_CHECK_VERSION(3,16,0)
|
|
||||||
gtk_label_set_xalign(label, 0.0);
|
|
||||||
#elif GTK_CHECK_VERSION(3,14,0)
|
|
||||||
gtk_widget_set_halign(GTK_WIDGET(label), GTK_ALIGN_START);
|
|
||||||
#else
|
|
||||||
gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------
|
|
||||||
* Functions to arrange controls in a basically dialog-like window.
|
* Functions to arrange controls in a basically dialog-like window.
|
||||||
*
|
*
|
||||||
* The best method for doing this has varied wildly with versions of
|
* The best method for doing this has varied wildly with versions of
|
||||||
@ -108,6 +32,11 @@ void align_label_left(GtkLabel *label)
|
|||||||
* vbox.
|
* vbox.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <gtk/gtk.h>
|
||||||
|
#include "putty.h"
|
||||||
|
#include "gtkcompat.h"
|
||||||
|
#include "gtkmisc.h"
|
||||||
|
|
||||||
GtkWidget *our_dialog_new(void)
|
GtkWidget *our_dialog_new(void)
|
||||||
{
|
{
|
||||||
#if GTK_CHECK_VERSION(3,0,0)
|
#if GTK_CHECK_VERSION(3,0,0)
|
||||||
@ -204,20 +133,3 @@ void our_dialog_add_to_content_area(GtkWindow *dlg, GtkWidget *w,
|
|||||||
w, expand, fill, padding);
|
w, expand, fill, padding);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
char *buildinfo_gtk_version(void)
|
|
||||||
{
|
|
||||||
return dupprintf("%d.%d.%d",
|
|
||||||
GTK_MAJOR_VERSION, GTK_MINOR_VERSION, GTK_MICRO_VERSION);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef NOT_X_WINDOWS
|
|
||||||
Display *get_x11_display(void)
|
|
||||||
{
|
|
||||||
#if GTK_CHECK_VERSION(3,0,0)
|
|
||||||
if (!GDK_IS_X11_DISPLAY(gdk_display_get_default()))
|
|
||||||
return NULL;
|
|
||||||
#endif
|
|
||||||
return GDK_DISPLAY_XDISPLAY(gdk_display_get_default());
|
|
||||||
}
|
|
||||||
#endif
|
|
18
unix/utils/string_width.c
Normal file
18
unix/utils/string_width.c
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
/*
|
||||||
|
* Return the width of a string in the font used in GTK controls. Used
|
||||||
|
* as a means of picking a sensible size for dialog boxes and pieces
|
||||||
|
* of them, in a way that should adapt sensibly to changes in font and
|
||||||
|
* resolution.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <gtk/gtk.h>
|
||||||
|
#include "putty.h"
|
||||||
|
#include "gtkcompat.h"
|
||||||
|
#include "gtkmisc.h"
|
||||||
|
|
||||||
|
int string_width(const char *text)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
get_label_text_dimensions(text, &ret, NULL);
|
||||||
|
return ret;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user