Handle of scrolling in Win32 along with various painting and view fixes.
[SquirrelJME.git] / nanocoat / lib / scritchui / gtk2 / gtk2View.c
blob502215cf53cbc7c1bec699603c6061023c87b7db
1 /* -*- Mode: C; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // SquirrelJME
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // -------------------------------------------------------------------------*/
10 #include <gdk/gdk.h>
12 #include "lib/scritchui/gtk2/gtk2.h"
13 #include "lib/scritchui/gtk2/gtk2Intern.h"
14 #include "lib/scritchui/scritchuiTypes.h"
16 sjme_errorCode sjme_scritchui_gtk2_viewGetView(
17 sjme_attrInNotNull sjme_scritchui inState,
18 sjme_attrInNotNull sjme_scritchui_uiComponent inComponent,
19 sjme_attrOutNotNull sjme_scritchui_rect* outViewRect)
21 GtkWidget* topWidget;
22 GtkWidget* binChild;
23 GtkAdjustment* hAdjust;
24 GtkAdjustment* vAdjust;
25 GtkAllocation alloc;
27 if (inState == NULL || inComponent == NULL || outViewRect == NULL)
28 return SJME_ERROR_NULL_ARGUMENTS;
30 /* Get wrapped widget. */
31 topWidget = inComponent->common.handle[SJME_SUI_GTK2_H_WIDGET];
33 /* Depends on the type. */
34 switch (inComponent->common.type)
36 case SJME_SCRITCHUI_TYPE_SCROLL_PANEL:
37 /* Get the allocation of the window. */
38 memset(&alloc, 0, sizeof(alloc));
39 binChild = gtk_bin_get_child(GTK_BIN(topWidget));
40 gtk_widget_get_allocation(binChild, &alloc);
42 /* Get adjustment. */
43 hAdjust = gtk_scrolled_window_get_hadjustment(
44 GTK_SCROLLED_WINDOW(topWidget));
45 vAdjust = gtk_scrolled_window_get_vadjustment(
46 GTK_SCROLLED_WINDOW(topWidget));
48 if (hAdjust != NULL)
50 outViewRect->s.x = gtk_adjustment_get_value(
51 hAdjust);
53 outViewRect->d.width = gtk_adjustment_get_page_size(
54 hAdjust);
55 if (alloc.width > outViewRect->d.width)
56 outViewRect->d.width = alloc.width;
59 if (vAdjust != NULL)
61 outViewRect->s.y = gtk_adjustment_get_value(
62 vAdjust);
64 /* Get the higher of the two widths/heights. */
65 outViewRect->d.height = gtk_adjustment_get_page_size(
66 vAdjust);
67 if (alloc.height > outViewRect->d.height)
68 outViewRect->d.height = alloc.height;
70 break;
72 default:
73 return sjme_error_notImplemented(0);
76 /* Success? */
77 return inState->implIntern->checkError(inState, SJME_ERROR_NONE);
80 sjme_errorCode sjme_scritchui_gtk2_viewSetArea(
81 sjme_attrInNotNull sjme_scritchui inState,
82 sjme_attrInNotNull sjme_scritchui_uiComponent inComponent,
83 sjme_attrInNotNull const sjme_scritchui_dim* inViewArea,
84 sjme_attrInNotNull const sjme_scritchui_dim* inViewPage)
86 GtkWidget* topWidget;
87 GtkAdjustment* hAdjust;
88 GtkAdjustment* vAdjust;
90 if (inState == NULL || inComponent == NULL || inViewArea == NULL)
91 return SJME_ERROR_NULL_ARGUMENTS;
93 /* Get wrapped widget. */
94 topWidget = inComponent->common.handle[SJME_SUI_GTK2_H_WIDGET];
96 /* Depends on the type. */
97 switch (inComponent->common.type)
99 case SJME_SCRITCHUI_TYPE_SCROLL_PANEL:
100 /* Change adjustment. */
101 hAdjust = gtk_scrolled_window_get_hadjustment(
102 GTK_SCROLLED_WINDOW(topWidget));
103 vAdjust = gtk_scrolled_window_get_vadjustment(
104 GTK_SCROLLED_WINDOW(topWidget));
106 gtk_adjustment_set_upper(hAdjust,
107 inViewArea->width);
108 gtk_adjustment_set_upper(vAdjust,
109 inViewArea->height);
110 break;
112 default:
113 return sjme_error_notImplemented(0);
116 /* Success? */
117 return inState->implIntern->checkError(inState, SJME_ERROR_NONE);
120 sjme_errorCode sjme_scritchui_gtk2_viewSetView(
121 sjme_attrInNotNull sjme_scritchui inState,
122 sjme_attrInNotNull sjme_scritchui_uiComponent inComponent,
123 sjme_attrInNotNull const sjme_scritchui_point* inViewPos)
125 sjme_todo("Impl?");
126 return sjme_error_notImplemented(0);
129 sjme_errorCode sjme_scritchui_gtk2_viewSetViewListener(
130 sjme_attrInNotNull sjme_scritchui inState,
131 sjme_attrInNotNull sjme_scritchui_uiComponent inComponent,
132 SJME_SCRITCHUI_SET_LISTENER_ARGS(view))
134 sjme_todo("Impl?");
135 return sjme_error_notImplemented(0);