Skip to content

Commit 75d0f0d

Browse files
committed
FEAT: Native request-color function on Windows
1 parent 4907ed0 commit 75d0f0d

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed

make/rebol3.nest

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,7 @@ include-png-filter-native: [
883883
include-view: [
884884
; currently only on Windows!
885885
host-files: :host-files-view
886+
core-files: %core/n-request-color.c
886887
#if Windows? [
887888
define: REB_VIEW
888889
:include-image-os-codec

src/core/n-request-color.c

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/***********************************************************************
2+
**
3+
** REBOL [R3] Language Interpreter and Run-time Environment
4+
**
5+
** Copyright 2012 REBOL Technologies
6+
** Copyright 2026 Rebol Open Source Developers
7+
** REBOL is a trademark of REBOL Technologies
8+
**
9+
** Licensed under the Apache License, Version 2.0 (the "License");
10+
** you may not use this file except in compliance with the License.
11+
** You may obtain a copy of the License at
12+
**
13+
** http://www.apache.org/licenses/LICENSE-2.0
14+
**
15+
** Unless required by applicable law or agreed to in writing, software
16+
** distributed under the License is distributed on an "AS IS" BASIS,
17+
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
** See the License for the specific language governing permissions and
19+
** limitations under the License.
20+
**
21+
************************************************************************
22+
**
23+
** Module: n-request-color.c
24+
** Summary: native request-color function
25+
** Section: natives
26+
** Author: Oldes
27+
** Notes:
28+
** So fat it is used only on Windows. On macOS it's implementented
29+
** as Rebol mezzanine function in file mezz-osx-dialogs.reb
30+
***********************************************************************/
31+
32+
#include "sys-core.h"
33+
34+
/***********************************************************************
35+
**
36+
*/ REBNATIVE(request_color)
37+
/*
38+
// request-color: native [
39+
// {Asks user to select a color.}
40+
// /default "Default RGB color"
41+
// color [tuple!]
42+
// ]
43+
//
44+
***********************************************************************/
45+
{
46+
#ifdef TO_WINDOWS
47+
static REBYTE color[4];
48+
if (D_REF(1)) {
49+
COPY_MEM(color, VAL_TUPLE(D_ARG(2)), 4);
50+
}
51+
if (OS_Request_Color((REBCNT*)&color)) {
52+
VAL_SET(DS_RETURN, REB_TUPLE);
53+
VAL_TUPLE_LEN(DS_RETURN) = 3;
54+
COPY_MEM(VAL_TUPLE(DS_RETURN), &color, 4);
55+
return R_RET;
56+
}
57+
else return R_NONE;
58+
#else
59+
Trap0(RE_FEATURE_NA);
60+
return R_NONE;
61+
#endif
62+
}

src/os/win32/host-lib.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,6 +1461,31 @@ static INT CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPAR
14611461
}
14621462

14631463

1464+
/***********************************************************************
1465+
**
1466+
*/ OS_API REBOOL OS_Request_Color(REBCNT* color)
1467+
/*
1468+
***********************************************************************/
1469+
{
1470+
// Static so custom colors persist across calls
1471+
static COLORREF customColors[16] = { 0 };
1472+
1473+
CHOOSECOLOR cc;
1474+
ZeroMemory(&cc, sizeof(cc));
1475+
cc.lStructSize = sizeof(cc);
1476+
//cc.hwndOwner = owner;
1477+
cc.rgbResult = (COLORREF)*color;
1478+
cc.lpCustColors = customColors;
1479+
cc.Flags = CC_FULLOPEN | CC_RGBINIT; // start expanded, use rgbResult as initial
1480+
1481+
if (ChooseColor(&cc)) {
1482+
*color = cc.rgbResult; // in format: 00bbggrr
1483+
return TRUE;
1484+
}
1485+
return FALSE;
1486+
}
1487+
1488+
14641489
/***********************************************************************
14651490
**
14661491
*/ OS_API void OS_Request_Password(REBREQ *req)

0 commit comments

Comments
 (0)