• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

A light-weight C++ object model framework Windows API Tool Kit


コミットメタ情報

リビジョン8a62513a814901c984042683c701ce2f2f715d7b (tree)
日時2013-08-19 23:56:08
作者Keith Marshall <keithmarshall@user...>
コミッターKeith Marshall

ログメッセージ

Add facility for control of child window placement.

変更サマリ

差分

--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,24 @@
11 2013-08-19 Keith Marshall <keithmarshall@users.sourceforge.net>
22
3+ Add facility for control of child window placement.
4+
5+ * wtkalign.h: New file; it declares the API for...
6+ (AlignWindow): ...this new extern "C" function; declare it.
7+ * wtkalign.c: New file; implement it.
8+
9+ * dlgproc.cpp (GenericDialogue::Dismiss) [WM_INITDIALOG]: Use it.
10+
11+ * configure.ac (AC_INIT): Bump version number to 0.1.1
12+ (AC_PROG_CC): Add test for C compiler.
13+
14+ * Makefile.in (LIBWTK_OBJECTS): Add wtkalign.$OBJEXT
15+ (CC, CFLAGS): Define for compilation of C code, according to...
16+ (%.$OBJEXT: %.c): ...this new build rule; define it.
17+ (SRCDIST_FILES): Add wtkalign.c and wtkalign.h
18+ (install-headers): Add wtkalign.h
19+
20+2013-08-19 Keith Marshall <keithmarshall@users.sourceforge.net>
21+
322 Convert to one-shot C++ compilation with dependency tracking.
423
524 * Makefile.in (DEPFLAGS): Redefine; incorporate CPPFLAGS.
--- a/Makefile.in
+++ b/Makefile.in
@@ -44,11 +44,13 @@ exec_prefix = @exec_prefix@
4444 includedir = @includedir@
4545 libdir = @libdir@
4646
47-# Compiler identification; note that this is a C++ only project.
47+# Compiler identification.
4848 #
49+CC = @CC@
4950 CXX = @CXX@
5051 CPPFLAGS = @CPPFLAGS@
5152 CXXFLAGS = @CXXFLAGS@
53+CFLAGS = @CFLAGS@
5254 OBJEXT = @OBJEXT@
5355
5456 # Archive librarian identification.
@@ -64,7 +66,7 @@ all: libwtklite.a
6466 LIBWTK_OBJECTS = wtkbase.$(OBJEXT) wtkmain.$(OBJEXT) wndproc.$(OBJEXT) \
6567 dlgproc.$(OBJEXT) wtkchild.$(OBJEXT) wtkexcept.$(OBJEXT) errtext.$(OBJEXT) \
6668 sashctrl.$(OBJEXT) hsashctl.$(OBJEXT) vsashctl.$(OBJEXT) strres.$(OBJEXT) \
67- wtkraise.$(OBJEXT)
69+ wtkraise.$(OBJEXT) wtkalign.$(OBJEXT)
6870
6971 libwtklite.a: $(LIBWTK_OBJECTS)
7072 $(AR) $(ARFLAGS) $@ $^
@@ -88,6 +90,9 @@ vsashctl.$(OBJEXT): sashctrl.cpp sashctrl.o
8890
8991 # Other object modules may be implicitly compiled.
9092 #
93+%.$(OBJEXT): %.c
94+ $(CC) -c $(DEPFLAGS) $(CFLAGS) -o $@ $<
95+
9196 %.$(OBJEXT): %.cpp
9297 $(CXX) -c $(DEPFLAGS) $(CXXFLAGS) -o $@ $<
9398
@@ -103,7 +108,7 @@ install: install-dirs install-headers install-libs
103108 install-dirs:
104109 $(MKDIR_P) ${includedir} ${libdir}
105110
106-install-headers: wtklite.h wtkdefs.h wtkexcept.h
111+install-headers: wtklite.h wtkdefs.h wtkalign.h wtkexcept.h
107112 $(INSTALL_DATA) $^ ${includedir}
108113
109114 install-libs: libwtklite.a
@@ -113,9 +118,9 @@ install-libs: libwtklite.a
113118 #
114119 TARNAME = $(PACKAGE)-$(VERSION)-mingw32
115120 SRCDIST_FILES = ChangeLog configure configure.ac Makefile.in install-sh \
116- wtklite.h wtkdefs.h wtkexcept.h wtkbase.cpp wtkmain.cpp wtkchild.cpp \
121+ wtklite.h wtkdefs.h wtkalign.h wtkexcept.h wtkbase.cpp wtkmain.cpp wtkchild.cpp \
117122 wndproc.cpp dlgproc.cpp sashctrl.cpp wtkexcept.cpp errtext.cpp strres.cpp \
118- wtkraise.cpp
123+ wtkraise.cpp wtkalign.c
119124
120125 dist: srcdist devdist
121126
--- a/configure.ac
+++ b/configure.ac
@@ -1,6 +1,6 @@
11 # configure.ac
22 #
3- AC_INIT([wtklite],[0.1.0],[http://mingw.org/Reporting_Bugs])
3+ AC_INIT([wtklite],[0.1.1],[http://mingw.org/Reporting_Bugs])
44 #
55 # Implementation of a minimal C++ class framework for use with the
66 # Microsoft Windows Application Programming Interface.
@@ -8,7 +8,7 @@
88 # $Id$
99 #
1010 # Written by Keith Marshall <keithmarshall@users.sourceforge.net>
11-# Copyright (C) 2012, MinGW.org Project.
11+# Copyright (C) 2012, 2013, MinGW.org Project.
1212 #
1313 # ---------------------------------------------------------------------------
1414 #
@@ -35,8 +35,9 @@
3535 #
3636 AC_PREFIX_DEFAULT([/mingw])
3737
38-# Identify compiler.
38+# Identify compilers.
3939 #
40+ AC_PROG_CC
4041 AC_PROG_CXX
4142
4243 # Identify other tools.
--- a/dlgproc.cpp
+++ b/dlgproc.cpp
@@ -12,7 +12,7 @@
1212 * which is available to all window classes derived from GenericDialogue.
1313 *
1414 * Written by Keith Marshall <keithmarshall@users.sourceforge.net>
15- * Copyright (C) 2012, MinGW.org Project.
15+ * Copyright (C) 2012, 2013, MinGW.org Project.
1616 *
1717 * ---------------------------------------------------------------------------
1818 *
@@ -41,6 +41,7 @@
4141 #define WIN32_LEAN_AND_MEAN
4242
4343 #include "wtklite.h"
44+#include "wtkalign.h"
4445
4546 namespace WTK
4647 {
@@ -55,9 +56,11 @@ namespace WTK
5556 /* We need to handle only two message types:
5657 */
5758 case WM_INITDIALOG:
58- /*
59- * We make this a no-op, while marking it as handled.
59+ /* Other than positioning this dialogue box centrally,
60+ * relative to its parent window, we make this a no-op,
61+ * while marking it as handled.
6062 */
63+ AlignWindow( window, WTK_ALIGN_CENTRED );
6164 return TRUE;
6265
6366 case WM_COMMAND:
--- /dev/null
+++ b/wtkalign.c
@@ -0,0 +1,167 @@
1+/*
2+ * wtkalign.c
3+ *
4+ * ---------------------------------------------------------------------------
5+ *
6+ * Implementation of a minimal C++ class framework for use with the
7+ * Microsoft Windows Application Programming Interface.
8+ *
9+ * $Id$
10+ *
11+ * This file provides the implementation of AlignWindow(), a helper
12+ * function for controlling the placement of child windows relative
13+ * to their parent, or to the screen bounds.
14+ *
15+ * Written by Keith Marshall <keithmarshall@users.sourceforge.net>
16+ * Copyright (C) 2013, MinGW.org Project.
17+ *
18+ * ---------------------------------------------------------------------------
19+ *
20+ * Permission is hereby granted, free of charge, to any person obtaining a
21+ * copy of this software and associated documentation files (the "Software"),
22+ * to deal in the Software without restriction, including without limitation
23+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
24+ * and/or sell copies of the Software, and to permit persons to whom the
25+ * Software is furnished to do so, subject to the following conditions:
26+ *
27+ * The above copyright notice, this permission notice, and the following
28+ * disclaimer shall be included in all copies or substantial portions of
29+ * the Software.
30+ *
31+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
32+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
33+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
34+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
35+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
36+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
37+ * DEALINGS IN THE SOFTWARE.
38+ *
39+ * ---------------------------------------------------------------------------
40+ *
41+ */
42+#define WIN32_LEAN_AND_MEAN
43+
44+#include <windows.h>
45+#include "wtkalign.h"
46+
47+void AlignWindow( HWND child, unsigned int alignment )
48+{
49+ /* Helper to be invoked while handling a WM_CREATE or WM_INITDIALOG
50+ * message; it adjusts the position at which the window or dialogue
51+ * box is created, such that it is displayed either neatly centred,
52+ * or flush with specified boundaries, on the screen, or within its
53+ * parent window.
54+ */
55+ HWND parent = ((alignment & WTK_ALIGN_ONSCREEN) == 0)
56+ /*
57+ * Unless alignment relative to the screen is specified, we must
58+ * identify the parent window from which the alignment bounds are
59+ * to be deduced.
60+ */
61+ ? GetParent( child )
62+ : NULL;
63+
64+ if( parent == NULL )
65+ /* When no parent has yet been identified, we are either explicitly
66+ * attempting to align within the desktop bounds, or the window we
67+ * are attempting to align has no valid parent; in either case, we
68+ * use the desktop window as the effective parent.
69+ */
70+ parent = GetDesktopWindow();
71+
72+ if( parent != NULL )
73+ {
74+ /* We now have a valid effective parent, so we may continue...
75+ */
76+ RECT screen, window;
77+ unsigned int mode;
78+
79+ /* First, we obtain the physical co-ordinates of the four corners
80+ * for both the dialogue box in its default position, and for the
81+ * parent window, all mapped as screen co-ordinates.
82+ */
83+ GetWindowRect( child, &window );
84+ GetWindowRect( parent, &screen );
85+
86+ /* Adjust the left-right position, setting the left ordinate for the
87+ * "screen" co-ordinate group to the physical left ordinate for final
88+ * placement of the dialogue on-screen...
89+ */
90+ switch( mode = alignment & WTK_ALIGN_HCENTRE )
91+ {
92+ case WTK_ALIGN_RIGHT:
93+ case WTK_ALIGN_HCENTRE:
94+ /* In the case of right or centred alignment, we initially push
95+ * the left ordinate of the "window" co-ordinate group as far to
96+ * the right as possible, while still keeping the window within
97+ * the designated screen bounds...
98+ */
99+ window.left += screen.right - screen.left - window.right;
100+ if( mode == WTK_ALIGN_HCENTRE )
101+ /* ...then, in the centred case, we move it back to the left,
102+ * by half of the distance between the leftmost "screen" bound
103+ * and the right-adjusted "window" ordinate.
104+ */
105+ screen.left += (window.left > 0) ? window.left >> 1 : 0;
106+
107+ case WTK_ALIGN_LEFT:
108+ /* In the case of left alignment we have nothing to do -- the
109+ * left bound of the "screen" co-ordinate group is already set
110+ * to the position where we want to place the left side of the
111+ * aligned window.
112+ */
113+ break;
114+
115+ default:
116+ /* In the case where no left-right alignment is specified, we
117+ * can simply make the left "screen" ordinate coincide with the
118+ * default position of the window.
119+ */
120+ screen.left = window.left;
121+ }
122+
123+ /* Adjust the top-bottom position, setting the top ordinate for the
124+ * "screen" co-ordinate group to the physical top ordinate for final
125+ * placement of the dialogue on-screen...
126+ */
127+ switch( mode = alignment & WTK_ALIGN_VCENTRE )
128+ {
129+ case WTK_ALIGN_BOTTOM:
130+ case WTK_ALIGN_VCENTRE:
131+ /* In the case of bottom or centred alignment, we initially push
132+ * the top ordinate of the "window" co-ordinate group downwards as
133+ * far as is possible, while still keeping the window within the
134+ * designated screen bounds...
135+ */
136+ window.top += screen.bottom - screen.top - window.bottom;
137+ if( mode == WTK_ALIGN_VCENTRE )
138+ /* ...then, in the centred case, we adjust it upwards again,
139+ * by half of the distance between the topmost "screen" bound
140+ * and the downwards adjusted top "window" ordinate.
141+ */
142+ screen.top += (window.top > 0) ? window.top >> 1 : 0;
143+
144+ case WTK_ALIGN_TOP:
145+ /* In the case of top alignment we have nothing to do -- the
146+ * top bound of the "screen" co-ordinate group is already set
147+ * to the position where we want to place the top edge of the
148+ * aligned window.
149+ */
150+ break;
151+
152+ default:
153+ /* In the case where no top-bottom alignment is specified, we
154+ * can simply make the top "screen" ordinate coincide with the
155+ * default position of the window.
156+ */
157+ screen.top = window.top;
158+ }
159+
160+ /* Finally, we reposition the dialogue box to the top left screen
161+ * co-ordinate we've just computed, preserving its original size.
162+ */
163+ SetWindowPos( child, HWND_TOP, screen.left, screen.top, 0, 0, SWP_NOSIZE );
164+ }
165+}
166+
167+/* $RCSfile$: end of file */
--- /dev/null
+++ b/wtkalign.h
@@ -0,0 +1,95 @@
1+#ifndef WTKALIGN_H
2+/*
3+ * wtkalign.h
4+ *
5+ * ---------------------------------------------------------------------------
6+ *
7+ * Implementation of an AlignWindow() function, to complement the
8+ * Microsoft Windows Application Programming Interface.
9+ *
10+ * $Id$
11+ *
12+ * This header file is to be included by all users of AlignWindow().
13+ *
14+ * Written by Keith Marshall <keithmarshall@users.sourceforge.net>
15+ * Copyright (C) 2013, MinGW.org Project.
16+ *
17+ * ---------------------------------------------------------------------------
18+ *
19+ * Permission is hereby granted, free of charge, to any person obtaining a
20+ * copy of this software and associated documentation files (the "Software"),
21+ * to deal in the Software without restriction, including without limitation
22+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
23+ * and/or sell copies of the Software, and to permit persons to whom the
24+ * Software is furnished to do so, subject to the following conditions:
25+ *
26+ * The above copyright notice, this permission notice, and the following
27+ * disclaimer shall be included in all copies or substantial portions of
28+ * the Software.
29+ *
30+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
31+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
32+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
33+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
34+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
35+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
36+ * DEALINGS IN THE SOFTWARE.
37+ *
38+ * ---------------------------------------------------------------------------
39+ *
40+ */
41+#define WTKALIGN_H 1
42+
43+/* AlignWindow() is written in C, but for C++ clients we subsume
44+ * it into the WTK namespace.
45+ */
46+#include "wtkdefs.h"
47+
48+BEGIN_NAMESPACE( WTK )
49+
50+/* Specify reference bounds for child window alignment.
51+ * By default, child windows are aligned within the frame of their parent.
52+ * Adding this bit-flag, (by bit-wise OR), to the alignment parameter which
53+ * is passed to the WTK::AlignWindow function, will override this default,
54+ * so alignment becomes relative to the screen bounds.
55+ */
56+#define WTK_ALIGN_ONSCREEN 0x0100
57+
58+/* Define the individual component flags, for specification of window
59+ * placement relative to each of the four alignment boundaries.
60+ */
61+#define WTK_ALIGN_LEFT 0x0001
62+#define WTK_ALIGN_RIGHT 0x0002
63+#define WTK_ALIGN_HCENTRE 0x0003
64+#define WTK_ALIGN_TOP 0x0010
65+#define WTK_ALIGN_BOTTOM 0x0020
66+#define WTK_ALIGN_VCENTRE 0x0030
67+
68+/* Combine these, to define the nine logical placement classes.
69+ */
70+#define WTK_ALIGN_TOPLEFT ( WTK_ALIGN_TOP | WTK_ALIGN_LEFT )
71+#define WTK_ALIGN_TOPRIGHT ( WTK_ALIGN_TOP | WTK_ALIGN_RIGHT )
72+#define WTK_ALIGN_CENTRETOP ( WTK_ALIGN_TOP | WTK_ALIGN_HCENTRE )
73+#define WTK_ALIGN_CENTRELEFT ( WTK_ALIGN_LEFT | WTK_ALIGN_VCENTRE )
74+#define WTK_ALIGN_CENTRERIGHT ( WTK_ALIGN_RIGHT | WTK_ALIGN_VCENTRE )
75+#define WTK_ALIGN_CENTRED ( WTK_ALIGN_HCENTRE | WTK_ALIGN_VCENTRE )
76+#define WTK_ALIGN_CENTREBOTTOM ( WTK_ALIGN_BOTTOM | WTK_ALIGN_HCENTRE )
77+#define WTK_ALIGN_BOTTOMRIGHT ( WTK_ALIGN_BOTTOM | WTK_ALIGN_RIGHT )
78+#define WTK_ALIGN_BOTTOMLEFT ( WTK_ALIGN_BOTTOM | WTK_ALIGN_LEFT )
79+
80+/* Provide a set of aliases to suit American users, (and any others
81+ * who can't spell "centre").
82+ */
83+#define WTK_ALIGN_CENTERED WTK_ALIGN_CENTRED
84+#define WTK_ALIGN_CENTERTOP WTK_ALIGN_CENTRETOP
85+#define WTK_ALIGN_CENTERLEFT WTK_ALIGN_CENTRELEFT
86+#define WTK_ALIGN_CENTERBOTTOM WTK_ALIGN_CENTREBOTTOM
87+#define WTK_ALIGN_CENTERRIGHT WTK_ALIGN_CENTRERIGHT
88+
89+/* Declare the prototype for the alignmemnt function.
90+ */
91+EXTERN_C void AlignWindow( HWND child, unsigned int alignment );
92+
93+END_NAMESPACE( WTK )
94+
95+#endif /* WTKALIGN_H: $RCSfile$: end of file */