mirror of
https://github.com/rozniak/xfce-winxp-tc.git
synced 2026-01-26 11:39:44 +00:00
Enhancement: Fixes #404, UI resource preview tool
This commit is contained in:
@@ -25,7 +25,7 @@ void wintc_ctl_cpl_notebook_append_page_from_resource(
|
||||
//
|
||||
wintc_lc_builder_preprocess_widget_text(builder);
|
||||
|
||||
box_page = GTK_WIDGET(gtk_builder_get_object(builder, "page-box"));
|
||||
box_page = GTK_WIDGET(gtk_builder_get_object(builder, "page"));
|
||||
label_title = GTK_WIDGET(gtk_builder_get_object(builder, "label-title"));
|
||||
|
||||
gtk_notebook_append_page(
|
||||
|
||||
@@ -33,6 +33,8 @@ configure_file(src/version.c.in ${PROJECT_ROOT}/src/version.c @ONLY)
|
||||
|
||||
add_library(
|
||||
libwintc-comgtk
|
||||
src/accelerator.c
|
||||
public/accelerator.h
|
||||
src/application.c
|
||||
public/application.h
|
||||
public/assets.h
|
||||
|
||||
41
shared/comgtk/public/accelerator.h
Normal file
41
shared/comgtk/public/accelerator.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/** @file */
|
||||
|
||||
#ifndef __COMGTK_ACCELERATOR_H__
|
||||
#define __COMGTK_ACCELERATOR_H__
|
||||
|
||||
#include <glib.h>
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
//
|
||||
// PUBLIC STRUCTURES
|
||||
//
|
||||
|
||||
/**
|
||||
* Convenience structure for defining accelerators for use with
|
||||
* wintc_application_set_accelerators.
|
||||
*/
|
||||
typedef struct _WinTCAccelEntry
|
||||
{
|
||||
const gchar* action_name;
|
||||
const gchar* accelerator[2];
|
||||
} WinTCAccelEntry;
|
||||
|
||||
//
|
||||
// PUBLIC FUNCTIONS
|
||||
//
|
||||
|
||||
/**
|
||||
* Convenience function for setting up many accelerators at once with
|
||||
* gtk_application_set_accels_for_action().
|
||||
*
|
||||
* @param application The application.
|
||||
* @param accelerators The array of accelerator entries.
|
||||
* @param n_accelerators The number of accelerators in the array.
|
||||
*/
|
||||
void wintc_application_set_accelerators(
|
||||
GtkApplication* application,
|
||||
const WinTCAccelEntry* accelerators,
|
||||
guint n_accelerators
|
||||
);
|
||||
|
||||
#endif
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef __WINTC_COMGTK_H__
|
||||
#define __WINTC_COMGTK_H__
|
||||
|
||||
#include "@LIB_HEADER_DIR@/accelerator.h"
|
||||
#include "@LIB_HEADER_DIR@/application.h"
|
||||
#include "@LIB_HEADER_DIR@/assets.h"
|
||||
#include "@LIB_HEADER_DIR@/builder.h"
|
||||
|
||||
23
shared/comgtk/src/accelerator.c
Normal file
23
shared/comgtk/src/accelerator.c
Normal file
@@ -0,0 +1,23 @@
|
||||
#include <glib.h>
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "../public/accelerator.h"
|
||||
|
||||
//
|
||||
// PUBLIC FUNCTIONS
|
||||
//
|
||||
void wintc_application_set_accelerators(
|
||||
GtkApplication* application,
|
||||
const WinTCAccelEntry* accelerators,
|
||||
guint n_accelerators
|
||||
)
|
||||
{
|
||||
for (guint i = 0; i < n_accelerators; i++)
|
||||
{
|
||||
gtk_application_set_accels_for_action(
|
||||
application,
|
||||
accelerators[i].action_name,
|
||||
accelerators[i].accelerator
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -12,9 +12,9 @@ void wintc_builder_get_objects(
|
||||
...
|
||||
)
|
||||
{
|
||||
va_list ap;
|
||||
GtkWidget** next_dst;
|
||||
gchar* next_name;
|
||||
va_list ap;
|
||||
GObject** next_dst;
|
||||
gchar* next_name;
|
||||
|
||||
va_start(ap, builder);
|
||||
|
||||
@@ -22,8 +22,8 @@ void wintc_builder_get_objects(
|
||||
|
||||
while (next_name)
|
||||
{
|
||||
next_dst = va_arg(ap, GtkWidget**);
|
||||
*next_dst = GTK_WIDGET(gtk_builder_get_object(builder, next_name));
|
||||
next_dst = va_arg(ap, GObject**);
|
||||
*next_dst = gtk_builder_get_object(builder, next_name);
|
||||
|
||||
next_name = va_arg(ap, gchar*);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<property name="can-focus">True</property>
|
||||
<property name="label" translatable="yes">Appearance</property>
|
||||
</object>
|
||||
<object class="GtkBox" id="page-box">
|
||||
<object class="GtkBox" id="page">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="orientation">vertical</property>
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
<property name="can-focus">True</property>
|
||||
<property name="label" translatable="yes">Desktop</property>
|
||||
</object>
|
||||
<object class="GtkBox" id="page-box">
|
||||
<object class="GtkBox" id="page">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="orientation">vertical</property>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<property name="can-focus">True</property>
|
||||
<property name="label" translatable="yes">Screen Saver</property>
|
||||
</object>
|
||||
<object class="GtkBox" id="page-box">
|
||||
<object class="GtkBox" id="page">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="orientation">vertical</property>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<property name="can-focus">True</property>
|
||||
<property name="label" translatable="yes">Settings</property>
|
||||
</object>
|
||||
<object class="GtkBox" id="page-box">
|
||||
<object class="GtkBox" id="page">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="orientation">vertical</property>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<property name="can-focus">True</property>
|
||||
<property name="label" translatable="yes">Themes</property>
|
||||
</object>
|
||||
<object class="GtkBox" id="page-box">
|
||||
<object class="GtkBox" id="page">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="orientation">vertical</property>
|
||||
|
||||
90
tools/resvwr/CMakeLists.txt
Normal file
90
tools/resvwr/CMakeLists.txt
Normal file
@@ -0,0 +1,90 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
project(
|
||||
wintc-resvwr
|
||||
VERSION 1.0
|
||||
DESCRIPTION "Windows Total Conversion resource viewer tool."
|
||||
LANGUAGES C
|
||||
)
|
||||
|
||||
set(PROJECT_ANYARCH false)
|
||||
set(PROJECT_FREESTATUS true)
|
||||
set(PROJECT_MAINTAINER "Rory Fewell <roryf@oddmatics.uk>")
|
||||
|
||||
set(PROJECT_ROOT ${CMAKE_CURRENT_LIST_DIR})
|
||||
|
||||
include(GNUInstallDirs)
|
||||
|
||||
include(../../packaging/cmake-inc/common/CMakeLists.txt)
|
||||
include(../../packaging/cmake-inc/linking/CMakeLists.txt)
|
||||
include(../../packaging/cmake-inc/packaging/CMakeLists.txt)
|
||||
include(../../packaging/cmake-inc/resources/CMakeLists.txt)
|
||||
|
||||
wintc_resolve_library(glib-2.0 GLIB)
|
||||
wintc_resolve_library(gtk+-3.0 GTK3)
|
||||
wintc_resolve_library(wintc-comctl WINTC_COMCTL)
|
||||
wintc_resolve_library(wintc-comgtk WINTC_COMGTK)
|
||||
wintc_resolve_library(wintc-shcommon WINTC_SHCOMMON)
|
||||
wintc_resolve_library(wintc-shlang WINTC_SHLANG)
|
||||
|
||||
wintc_compile_resources()
|
||||
|
||||
add_executable(
|
||||
wintc-resvwr
|
||||
src/application.c
|
||||
src/application.h
|
||||
src/main.c
|
||||
src/resources.c
|
||||
src/window.c
|
||||
src/window.h
|
||||
)
|
||||
|
||||
target_compile_options(
|
||||
wintc-resvwr
|
||||
PRIVATE ${WINTC_COMPILE_OPTIONS}
|
||||
)
|
||||
|
||||
target_include_directories(
|
||||
wintc-resvwr
|
||||
SYSTEM
|
||||
PRIVATE ${GLIB_INCLUDE_DIRS}
|
||||
PRIVATE ${GTK3_INCLUDE_DIRS}
|
||||
PRIVATE ${WINTC_COMCTL_INCLUDE_DIRS}
|
||||
PRIVATE ${WINTC_COMGTK_INCLUDE_DIRS}
|
||||
PRIVATE ${WINTC_SHCOMMON_INCLUDE_DIRS}
|
||||
PRIVATE ${WINTC_SHLANG_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
target_link_directories(
|
||||
wintc-resvwr
|
||||
PRIVATE ${GLIB_LIBRARY_DIRS}
|
||||
PRIVATE ${GTK3_LIBRARY_DIRS}
|
||||
PRIVATE ${WINTC_COMCTL_LIBRARY_DIRS}
|
||||
PRIVATE ${WINTC_COMGTK_LIBRARY_DIRS}
|
||||
PRIVATE ${WINTC_SHCOMMON_LIBRARY_DIRS}
|
||||
PRIVATE ${WINTC_SHLANG_LIBRARY_DIRS}
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
wintc-resvwr
|
||||
PRIVATE ${GLIB_LIBRARIES}
|
||||
PRIVATE ${GTK3_LIBRARIES}
|
||||
PRIVATE ${WINTC_COMCTL_LIBRARIES}
|
||||
PRIVATE ${WINTC_COMGTK_LIBRARIES}
|
||||
PRIVATE ${WINTC_SHCOMMON_LIBRARIES}
|
||||
PRIVATE ${WINTC_SHLANG_LIBRARIES}
|
||||
)
|
||||
|
||||
# Installation
|
||||
#
|
||||
wintc_configure_and_install_packaging()
|
||||
wintc_install_icons_into_package()
|
||||
|
||||
install(
|
||||
FILES wintc-resvwr.desktop
|
||||
DESTINATION share/applications
|
||||
)
|
||||
install(
|
||||
TARGETS wintc-resvwr
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
)
|
||||
20
tools/resvwr/README.MD
Normal file
20
tools/resvwr/README.MD
Normal file
@@ -0,0 +1,20 @@
|
||||
# Resource Viewer
|
||||
This directory contains the source code for the *Resource Viewer* tool.
|
||||
|
||||

|
||||
|
||||
## Installation
|
||||
This tool must be compiled before it can be used. Build, package, and install it the same way you would with any other program in this repo, eg:
|
||||
```
|
||||
(in the /packaging dir)
|
||||
./build.sh tools/resvwr
|
||||
./package.sh tools/resvwr
|
||||
sudo dpkg -i local-out/wintc-resvwr.deb
|
||||
```
|
||||
|
||||
Adjust the `dpkg` command to whatever the package manager is on your distro (eg. for Fedora do `sudo dnf install ./local-out/wintc-resvwr.rpm`)
|
||||
|
||||
# Usage
|
||||
The tool allows you to view most of the GTK builder XML resources in this project. Some of course require custom widgets which may not be available.
|
||||
|
||||
It's a viewer only, to aid with development. It is not a fully featured editor like Glade.
|
||||
5
tools/resvwr/deps
Normal file
5
tools/resvwr/deps
Normal file
@@ -0,0 +1,5 @@
|
||||
bt,rt:glib2
|
||||
bt,rt:gtk3
|
||||
bt,rt:wintc-comctl
|
||||
bt,rt:wintc-comgtk
|
||||
bt,rt:wintc-shlang
|
||||
BIN
tools/resvwr/icons/16x16/wintc-resvwr.png
Normal file
BIN
tools/resvwr/icons/16x16/wintc-resvwr.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 637 B |
BIN
tools/resvwr/icons/32x32/wintc-resvwr.png
Normal file
BIN
tools/resvwr/icons/32x32/wintc-resvwr.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.7 KiB |
124
tools/resvwr/src/application.c
Normal file
124
tools/resvwr/src/application.c
Normal file
@@ -0,0 +1,124 @@
|
||||
#include <glib.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <wintc/comctl.h>
|
||||
#include <wintc/comgtk.h>
|
||||
|
||||
#include "application.h"
|
||||
#include "window.h"
|
||||
|
||||
//
|
||||
// FORWARD DECLARATIONS
|
||||
//
|
||||
static void wintc_resvwr_application_activate(
|
||||
GApplication* application
|
||||
);
|
||||
static void wintc_resvwr_application_startup(
|
||||
GApplication* application
|
||||
);
|
||||
|
||||
//
|
||||
// STATIC DATA
|
||||
//
|
||||
static const WinTCAccelEntry S_ACCELS[] = {
|
||||
{
|
||||
"win.open",
|
||||
{
|
||||
"<Ctrl>O",
|
||||
NULL
|
||||
}
|
||||
},
|
||||
{
|
||||
"win.refresh",
|
||||
{
|
||||
"F5",
|
||||
NULL
|
||||
}
|
||||
},
|
||||
{
|
||||
"win.exit",
|
||||
{
|
||||
"<Alt>F4",
|
||||
NULL
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// GTK OOP CLASS/INSTANCE DEFINITIONS
|
||||
//
|
||||
typedef struct _WinTCResvwrApplication
|
||||
{
|
||||
GtkApplication __parent__;
|
||||
} WinTCResvwrApplication;
|
||||
|
||||
//
|
||||
// GTK TYPE DEFINITIONS & CTORS
|
||||
//
|
||||
G_DEFINE_TYPE(
|
||||
WinTCResvwrApplication,
|
||||
wintc_resvwr_application,
|
||||
GTK_TYPE_APPLICATION
|
||||
)
|
||||
|
||||
static void wintc_resvwr_application_class_init(
|
||||
WinTCResvwrApplicationClass* klass
|
||||
)
|
||||
{
|
||||
GApplicationClass* application_class = G_APPLICATION_CLASS(klass);
|
||||
|
||||
application_class->activate = wintc_resvwr_application_activate;
|
||||
application_class->startup = wintc_resvwr_application_startup;
|
||||
}
|
||||
|
||||
static void wintc_resvwr_application_init(
|
||||
WINTC_UNUSED(WinTCResvwrApplication* self)
|
||||
) { }
|
||||
|
||||
//
|
||||
// CLASS VIRTUAL METHODS
|
||||
//
|
||||
static void wintc_resvwr_application_activate(
|
||||
GApplication* application
|
||||
)
|
||||
{
|
||||
GtkWidget* new_window =
|
||||
wintc_resvwr_window_new(WINTC_RESVWR_APPLICATION(application));
|
||||
|
||||
gtk_widget_show_all(new_window);
|
||||
}
|
||||
|
||||
static void wintc_resvwr_application_startup(
|
||||
GApplication* application
|
||||
)
|
||||
{
|
||||
(G_APPLICATION_CLASS(wintc_resvwr_application_parent_class))
|
||||
->startup(application);
|
||||
|
||||
// Init comctl
|
||||
//
|
||||
wintc_ctl_install_default_styles();
|
||||
|
||||
g_type_ensure(WINTC_TYPE_CTL_ANIMATION);
|
||||
|
||||
// Init accelerators
|
||||
//
|
||||
wintc_application_set_accelerators(
|
||||
GTK_APPLICATION(application),
|
||||
S_ACCELS,
|
||||
G_N_ELEMENTS(S_ACCELS)
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// PUBLIC FUNCTIONS
|
||||
//
|
||||
WinTCResvwrApplication* wintc_resvwr_application_new(void)
|
||||
{
|
||||
return WINTC_RESVWR_APPLICATION(
|
||||
g_object_new(
|
||||
wintc_resvwr_application_get_type(),
|
||||
"application-id", "uk.oddmatics.wintc.tools.resvwr",
|
||||
NULL
|
||||
)
|
||||
);
|
||||
}
|
||||
25
tools/resvwr/src/application.h
Normal file
25
tools/resvwr/src/application.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef __APPLICATION_H__
|
||||
#define __APPLICATION_H__
|
||||
|
||||
#include <glib.h>
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
//
|
||||
// GTK OOP BOILERPLATE
|
||||
//
|
||||
#define WINTC_TYPE_RESVWR_APPLICATION (wintc_resvwr_application_get_type())
|
||||
|
||||
G_DECLARE_FINAL_TYPE(
|
||||
WinTCResvwrApplication,
|
||||
wintc_resvwr_application,
|
||||
WINTC,
|
||||
RESVWR_APPLICATION,
|
||||
GtkApplication
|
||||
)
|
||||
|
||||
//
|
||||
// PUBLIC FUNCTIONS
|
||||
//
|
||||
WinTCResvwrApplication* wintc_resvwr_application_new(void);
|
||||
|
||||
#endif
|
||||
20
tools/resvwr/src/main.c
Normal file
20
tools/resvwr/src/main.c
Normal file
@@ -0,0 +1,20 @@
|
||||
#include <glib.h>
|
||||
|
||||
#include "application.h"
|
||||
|
||||
int main(
|
||||
int argc,
|
||||
char* argv[]
|
||||
)
|
||||
{
|
||||
WinTCResvwrApplication* app = wintc_resvwr_application_new();
|
||||
int status;
|
||||
|
||||
g_set_application_name("Resvwr");
|
||||
|
||||
status = g_application_run(G_APPLICATION(app), argc, argv);
|
||||
|
||||
g_object_unref(app);
|
||||
|
||||
return status;
|
||||
}
|
||||
30
tools/resvwr/src/res/menubar.ui
Normal file
30
tools/resvwr/src/res/menubar.ui
Normal file
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
<menu id="menubar">
|
||||
<submenu>
|
||||
<attribute name="label">File</attribute>
|
||||
|
||||
<section>
|
||||
<item>
|
||||
<attribute name="accel"><Control>O</attribute>
|
||||
<attribute name="action">win.open</attribute>
|
||||
<attribute name="label">Open</attribute>
|
||||
</item>
|
||||
</section>
|
||||
<section>
|
||||
<item>
|
||||
<attribute name="accel">F5</attribute>
|
||||
<attribute name="action">win.refresh</attribute>
|
||||
<attribute name="label">Refresh</attribute>
|
||||
</item>
|
||||
</section>
|
||||
<section>
|
||||
<item>
|
||||
<attribute name="accel"><Alt>F4</attribute>
|
||||
<attribute name="action">win.exit</attribute>
|
||||
<attribute name="label">Exit</attribute>
|
||||
</item>
|
||||
</section>
|
||||
</submenu>
|
||||
</menu>
|
||||
</interface>
|
||||
7
tools/resvwr/src/res/resources.xml
Normal file
7
tools/resvwr/src/res/resources.xml
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<gresources>
|
||||
<gresource prefix="/uk/oddmatics/wintc/tools/resvwr">
|
||||
<file>menubar.ui</file>
|
||||
<file>resvwr.ui</file>
|
||||
</gresource>
|
||||
</gresources>
|
||||
32
tools/resvwr/src/res/resvwr.ui
Normal file
32
tools/resvwr/src/res/resvwr.ui
Normal file
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
<object class="GtkBox" id="main-box">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<property name="orientation">vertical</property>
|
||||
|
||||
<child>
|
||||
<object class="GtkMenuBar" id="menubar-main">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkScrolledWindow" id="scrollwnd-view">
|
||||
<property name="visible">True</property>
|
||||
<property name="can-focus">True</property>
|
||||
<property name="shadow-type">in</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</interface>
|
||||
422
tools/resvwr/src/window.c
Normal file
422
tools/resvwr/src/window.c
Normal file
@@ -0,0 +1,422 @@
|
||||
#include <glib.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <wintc/comgtk.h>
|
||||
#include <wintc/shlang.h>
|
||||
|
||||
#include "application.h"
|
||||
#include "window.h"
|
||||
|
||||
//
|
||||
// FORWARD DECLARATIONS
|
||||
//
|
||||
static void wintc_resvwr_window_finalize(
|
||||
GObject* object
|
||||
);
|
||||
|
||||
static void wintc_resvwr_window_refresh(
|
||||
WinTCResvwrWindow* wnd
|
||||
);
|
||||
|
||||
static void action_exit(
|
||||
GSimpleAction* action,
|
||||
GVariant* parameter,
|
||||
gpointer user_data
|
||||
);
|
||||
static void action_open(
|
||||
GSimpleAction* action,
|
||||
GVariant* parameter,
|
||||
gpointer user_data
|
||||
);
|
||||
static void action_refresh(
|
||||
GSimpleAction* action,
|
||||
GVariant* parameter,
|
||||
gpointer user_data
|
||||
);
|
||||
|
||||
//
|
||||
// STATIC DATA
|
||||
//
|
||||
static GActionEntry s_window_actions[] = {
|
||||
{
|
||||
.name = "exit",
|
||||
.activate = action_exit,
|
||||
.parameter_type = NULL,
|
||||
.state = NULL,
|
||||
.change_state = NULL
|
||||
},
|
||||
{
|
||||
.name = "open",
|
||||
.activate = action_open,
|
||||
.parameter_type = NULL,
|
||||
.state = NULL,
|
||||
.change_state = NULL
|
||||
},
|
||||
{
|
||||
.name = "refresh",
|
||||
.activate = action_refresh,
|
||||
.parameter_type = NULL,
|
||||
.state = NULL,
|
||||
.change_state = NULL
|
||||
},
|
||||
};
|
||||
|
||||
//
|
||||
// GTK OOP CLASS/INSTANCE DEFINITIONS
|
||||
//
|
||||
typedef struct _WinTCResvwrWindow
|
||||
{
|
||||
GtkApplicationWindow __parent__;
|
||||
|
||||
// State
|
||||
//
|
||||
gchar* path_resource;
|
||||
GtkWidget* scrollwnd_view;
|
||||
} WinTCResvwrWindow;
|
||||
|
||||
//
|
||||
// GTK TYPE DEFINITION & CTORS
|
||||
//
|
||||
G_DEFINE_TYPE(
|
||||
WinTCResvwrWindow,
|
||||
wintc_resvwr_window,
|
||||
GTK_TYPE_APPLICATION_WINDOW
|
||||
)
|
||||
|
||||
static void wintc_resvwr_window_class_init(
|
||||
WinTCResvwrWindowClass* klass
|
||||
)
|
||||
{
|
||||
GObjectClass* object_class = G_OBJECT_CLASS(klass);
|
||||
|
||||
object_class->finalize = wintc_resvwr_window_finalize;
|
||||
}
|
||||
|
||||
static void wintc_resvwr_window_init(
|
||||
WinTCResvwrWindow* self
|
||||
)
|
||||
{
|
||||
GtkBuilder* builder;
|
||||
|
||||
// Set up action map
|
||||
//
|
||||
g_action_map_add_action_entries(
|
||||
G_ACTION_MAP(self),
|
||||
s_window_actions,
|
||||
G_N_ELEMENTS(s_window_actions),
|
||||
self
|
||||
);
|
||||
|
||||
// Build menu
|
||||
//
|
||||
GMenuModel* menubar;
|
||||
|
||||
builder =
|
||||
gtk_builder_new_from_resource(
|
||||
"/uk/oddmatics/wintc/tools/resvwr/menubar.ui"
|
||||
);
|
||||
|
||||
menubar =
|
||||
G_MENU_MODEL(
|
||||
g_object_ref(
|
||||
gtk_builder_get_object(builder, "menubar")
|
||||
)
|
||||
);
|
||||
|
||||
g_object_unref(builder);
|
||||
|
||||
// Initialize UI
|
||||
//
|
||||
GtkWidget* menubar_main;
|
||||
|
||||
builder =
|
||||
gtk_builder_new_from_resource(
|
||||
"/uk/oddmatics/wintc/tools/resvwr/resvwr.ui"
|
||||
);
|
||||
|
||||
wintc_lc_builder_preprocess_widget_text(builder);
|
||||
|
||||
wintc_builder_get_objects(
|
||||
builder,
|
||||
"menubar-main", &menubar_main,
|
||||
"scrollwnd-view", &(self->scrollwnd_view),
|
||||
NULL
|
||||
);
|
||||
|
||||
gtk_menu_shell_bind_model(
|
||||
GTK_MENU_SHELL(menubar_main),
|
||||
menubar,
|
||||
NULL,
|
||||
FALSE
|
||||
);
|
||||
|
||||
gtk_container_add(
|
||||
GTK_CONTAINER(self),
|
||||
GTK_WIDGET(gtk_builder_get_object(builder, "main-box"))
|
||||
);
|
||||
|
||||
g_object_unref(builder);
|
||||
g_object_unref(menubar);
|
||||
|
||||
gtk_window_set_default_size(
|
||||
GTK_WINDOW(self),
|
||||
320,
|
||||
260
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// CLASS VIRTUAL METHODS
|
||||
//
|
||||
static void wintc_resvwr_window_finalize(
|
||||
GObject* object
|
||||
)
|
||||
{
|
||||
WinTCResvwrWindow* wnd = WINTC_RESVWR_WINDOW(object);
|
||||
|
||||
g_free(wnd->path_resource);
|
||||
|
||||
(G_OBJECT_CLASS(wintc_resvwr_window_parent_class))
|
||||
->finalize(object);
|
||||
}
|
||||
|
||||
//
|
||||
// PUBLIC FUNCTIONS
|
||||
//
|
||||
GtkWidget* wintc_resvwr_window_new(
|
||||
WinTCResvwrApplication* app
|
||||
)
|
||||
{
|
||||
return GTK_WIDGET(
|
||||
g_object_new(
|
||||
WINTC_TYPE_RESVWR_WINDOW,
|
||||
"application", GTK_APPLICATION(app),
|
||||
"title", "Resource Viewer",
|
||||
NULL
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// PRIVATE FUNCTIONS
|
||||
//
|
||||
static void wintc_resvwr_window_refresh(
|
||||
WinTCResvwrWindow* wnd
|
||||
)
|
||||
{
|
||||
// Have we got any selection?
|
||||
//
|
||||
if (!(wnd->path_resource))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Clear existing stuff (if any)
|
||||
//
|
||||
GtkWidget* child = gtk_bin_get_child(GTK_BIN(wnd->scrollwnd_view));
|
||||
|
||||
if (child)
|
||||
{
|
||||
gtk_container_remove(GTK_CONTAINER(wnd->scrollwnd_view), child);
|
||||
}
|
||||
|
||||
// Create new from file
|
||||
//
|
||||
GtkBuilder* builder = gtk_builder_new();
|
||||
GError* error = NULL;
|
||||
|
||||
if (
|
||||
gtk_builder_add_from_file(
|
||||
builder,
|
||||
wnd->path_resource,
|
||||
&error
|
||||
)
|
||||
)
|
||||
{
|
||||
// Based on what we find in the builder, construct the UI in the
|
||||
// scrolled window
|
||||
//
|
||||
GtkWidget* label_title;
|
||||
GMenuModel* menu;
|
||||
GMenuModel* menubar;
|
||||
GtkWidget* main_box;
|
||||
GtkWidget* page;
|
||||
GtkWidget* toolbar;
|
||||
|
||||
wintc_builder_get_objects(
|
||||
builder,
|
||||
"label-title", &label_title,
|
||||
"main-box", &main_box,
|
||||
"menu", &menu,
|
||||
"menubar", &menubar,
|
||||
"page", &page,
|
||||
"toolbar", &toolbar,
|
||||
NULL
|
||||
);
|
||||
|
||||
if (main_box)
|
||||
{
|
||||
gtk_container_add(
|
||||
GTK_CONTAINER(wnd->scrollwnd_view),
|
||||
main_box
|
||||
);
|
||||
}
|
||||
else if (menu || menubar)
|
||||
{
|
||||
GtkWidget* box_wrapper = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
|
||||
GtkWidget* menu_built;
|
||||
|
||||
if (menu) // Floating menu - create menubar to attach to
|
||||
{
|
||||
GtkWidget* submenu_built = gtk_menu_new_from_model(menu);
|
||||
GtkWidget* submenu_item = gtk_menu_item_new_with_label("_");
|
||||
|
||||
menu_built = gtk_menu_bar_new();
|
||||
|
||||
gtk_menu_item_set_submenu(
|
||||
GTK_MENU_ITEM(submenu_item),
|
||||
submenu_built
|
||||
);
|
||||
gtk_menu_shell_append(
|
||||
GTK_MENU_SHELL(menu_built),
|
||||
submenu_item
|
||||
);
|
||||
}
|
||||
else // Menubar - attach immediately
|
||||
{
|
||||
menu_built = gtk_menu_bar_new_from_model(menubar);
|
||||
}
|
||||
|
||||
gtk_container_add(
|
||||
GTK_CONTAINER(box_wrapper),
|
||||
menu_built
|
||||
);
|
||||
gtk_container_add(
|
||||
GTK_CONTAINER(wnd->scrollwnd_view),
|
||||
box_wrapper
|
||||
);
|
||||
}
|
||||
else if (page)
|
||||
{
|
||||
GtkWidget* notebook = gtk_notebook_new();
|
||||
|
||||
gtk_notebook_append_page(
|
||||
GTK_NOTEBOOK(notebook),
|
||||
page,
|
||||
label_title
|
||||
);
|
||||
|
||||
gtk_container_add(
|
||||
GTK_CONTAINER(wnd->scrollwnd_view),
|
||||
notebook
|
||||
);
|
||||
}
|
||||
else if (toolbar)
|
||||
{
|
||||
GtkWidget* box_wrapper = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
|
||||
|
||||
gtk_container_add(
|
||||
GTK_CONTAINER(box_wrapper),
|
||||
toolbar
|
||||
);
|
||||
gtk_container_add(
|
||||
GTK_CONTAINER(wnd->scrollwnd_view),
|
||||
box_wrapper
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
// FIXME: Probably just append the first item? Who knows...
|
||||
//
|
||||
wintc_messagebox_show(
|
||||
GTK_WINDOW(wnd),
|
||||
"Don't know how to deal with this widget tree.",
|
||||
"Unrecognised Widget Tree",
|
||||
GTK_BUTTONS_OK,
|
||||
GTK_MESSAGE_ERROR
|
||||
);
|
||||
}
|
||||
|
||||
gtk_widget_show_all(wnd->scrollwnd_view);
|
||||
}
|
||||
else
|
||||
{
|
||||
wintc_display_error_and_clear(&error);
|
||||
}
|
||||
|
||||
g_object_unref(builder);
|
||||
}
|
||||
|
||||
//
|
||||
// CALLBACKS
|
||||
//
|
||||
static void action_exit(
|
||||
WINTC_UNUSED(GSimpleAction* action),
|
||||
WINTC_UNUSED(GVariant* parameter),
|
||||
gpointer user_data
|
||||
)
|
||||
{
|
||||
gtk_window_close(GTK_WINDOW(user_data));
|
||||
}
|
||||
|
||||
static void action_open(
|
||||
WINTC_UNUSED(GSimpleAction* action),
|
||||
WINTC_UNUSED(GVariant* parameter),
|
||||
gpointer user_data
|
||||
)
|
||||
{
|
||||
WinTCResvwrWindow* wnd = WINTC_RESVWR_WINDOW(user_data);
|
||||
|
||||
// Open file dialog stuff
|
||||
//
|
||||
GtkWidget* dlg;
|
||||
GtkFileFilter* filter_xml;
|
||||
|
||||
filter_xml = gtk_file_filter_new();
|
||||
|
||||
gtk_file_filter_set_name(filter_xml, "XML Files");
|
||||
gtk_file_filter_add_mime_type(filter_xml, "text/xml");
|
||||
|
||||
dlg =
|
||||
gtk_file_chooser_dialog_new(
|
||||
wintc_lc_get_control_text(WINTC_CTLTXT_OPEN, WINTC_PUNC_NONE),
|
||||
GTK_WINDOW(wnd),
|
||||
GTK_FILE_CHOOSER_ACTION_OPEN,
|
||||
wintc_lc_get_control_text(WINTC_CTLTXT_CANCEL, WINTC_PUNC_NONE),
|
||||
GTK_RESPONSE_CANCEL,
|
||||
wintc_lc_get_control_text(WINTC_CTLTXT_OPEN, WINTC_PUNC_NONE),
|
||||
GTK_RESPONSE_ACCEPT,
|
||||
NULL
|
||||
);
|
||||
|
||||
gtk_file_chooser_add_filter(
|
||||
GTK_FILE_CHOOSER(dlg),
|
||||
filter_xml
|
||||
);
|
||||
|
||||
// Execute dialog and handle result
|
||||
//
|
||||
gint result = gtk_dialog_run(GTK_DIALOG(dlg));
|
||||
|
||||
if (result == GTK_RESPONSE_ACCEPT)
|
||||
{
|
||||
wnd->path_resource =
|
||||
gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dlg));
|
||||
|
||||
wintc_resvwr_window_refresh(wnd);
|
||||
}
|
||||
|
||||
gtk_widget_destroy(dlg);
|
||||
}
|
||||
|
||||
static void action_refresh(
|
||||
WINTC_UNUSED(GSimpleAction* action),
|
||||
WINTC_UNUSED(GVariant* parameter),
|
||||
gpointer user_data
|
||||
)
|
||||
{
|
||||
WinTCResvwrWindow* wnd = WINTC_RESVWR_WINDOW(user_data);
|
||||
|
||||
WINTC_LOG_DEBUG("resvwr: refreshing...");
|
||||
|
||||
wintc_resvwr_window_refresh(wnd);
|
||||
}
|
||||
29
tools/resvwr/src/window.h
Normal file
29
tools/resvwr/src/window.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef __WINDOW_H__
|
||||
#define __WINDOW_H__
|
||||
|
||||
#include <glib.h>
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "application.h"
|
||||
|
||||
//
|
||||
// GTK OOP BOILERPLATE
|
||||
//
|
||||
#define WINTC_TYPE_RESVWR_WINDOW (wintc_resvwr_window_get_type())
|
||||
|
||||
G_DECLARE_FINAL_TYPE(
|
||||
WinTCResvwrWindow,
|
||||
wintc_resvwr_window,
|
||||
WINTC,
|
||||
RESVWR_WINDOW,
|
||||
GtkApplicationWindow
|
||||
)
|
||||
|
||||
//
|
||||
// PUBLIC FUNCTIONS
|
||||
//
|
||||
GtkWidget* wintc_resvwr_window_new(
|
||||
WinTCResvwrApplication* app
|
||||
);
|
||||
|
||||
#endif
|
||||
9
tools/resvwr/wintc-resvwr.desktop
Normal file
9
tools/resvwr/wintc-resvwr.desktop
Normal file
@@ -0,0 +1,9 @@
|
||||
[Desktop Entry]
|
||||
Name=Resource Viewer (WinTC)
|
||||
Comment=Development tool for viewing resources in the WinTC project.
|
||||
Exec=wintc-resvwr
|
||||
Icon=wintc-resvwr
|
||||
Terminal=false
|
||||
StartupNotify=false
|
||||
Type=Application
|
||||
Categories=Development;GTK;
|
||||
Reference in New Issue
Block a user