OWLNext    7.0
Borland's Object Windows Library for the modern age
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
chooseco.cpp
Go to the documentation of this file.
1//----------------------------------------------------------------------------
2// ObjectWindows
3// Copyright (c) 1992, 1996 by Borland International, All Rights Reserved
4//
5/// \file
6/// Implementation of TChooseColorDialog, a Choose Color Common Dialog class
7//----------------------------------------------------------------------------
8#include <owl/pch.h>
9#include <owl/chooseco.h>
10
11namespace owl {
12
14DIAG_DECLARE_GROUP(OwlCommDialog); // diagnostic group for common dialogs
15
17
20
21//
22/// Initialize the choose color common dialog data members.
23//
24/// Constructs a dialog box with specified parent window, data, resource identifier,
25/// window caption, and module ID. Sets the attributes of the dialog box based on
26/// info in the TChooseColor::TData structure.
27//
29 TData& data,
32 TModule* module)
33:
34 TCommonDialog(parent, title, module),
35 Data(data)
36{
38}
39
40//
41/// String-aware overload
42//
44: TCommonDialog(parent, title, module),
45 Data(data)
46{
48}
49
51{
52 if (!SetRGBMsgId)
54
55 memset(&Cc, 0, sizeof Cc);
56 Cc.lStructSize = sizeof Cc;
57 Cc.hwndOwner = GetParentO() ? GetParentO()->GetHandle() : nullptr;
58 Cc.hInstance = HWND(GetModule()->GetHandle()); // hInstance is badly typed
59 Cc.Flags = CC_ENABLEHOOK | Data.Flags;
60 if (templateId) {
61 Cc.lpTemplateName = templateId;
62 Cc.Flags |= CC_ENABLETEMPLATE;
63 }
64 else
65 Cc.Flags &= ~CC_ENABLETEMPLATE;
66 Cc.lpfnHook = nullptr;
67
68 Cc.rgbResult = Data.Color;
69 Cc.lpCustColors = reinterpret_cast<COLORREF *>(Data.CustColors);
70
71 TRACEX(OwlCommDialog, OWL_CDLEVEL, "TChooseColorDialog constructed @" << (void*)this);
72}
73
74//
75/// Destructor does nothing in non diagnostic versions of the library.
76/// In the diagnostic version, it displays a trace message.
77//
79{
80 TRACEX(OwlCommDialog, OWL_CDLEVEL, "TChooseColorDialog destructed @" << (void*)this);
81}
82
83//
84/// Override the virtual DialogFunction.
85/// Does no additional processing.
86///
87/// Returns true if a message is handled.
88//
94
95//
96/// Execute the dialog to retrieve user's choice of color.
97//
98/// If no error occurs, DoExecute copies flags and colors into Data and returns
99/// zero. If an error occurs, DoExecute returns the IDCANCEL with Data.Error set to
100/// the value returned from CommDlgExtendedError.
101//
102int
104{
105 Cc.lpfnHook = LPCCHOOKPROC(StdDlgProc);
106 int ret = ChooseColor(&Cc);
107 if (ret) {
108 Data.Flags = Cc.Flags;
109 Data.Error = 0;
110 Data.Color = Cc.rgbResult;
111 }
112 else {
114 }
115 return ret ? IDOK : IDCANCEL;
116}
117
122
124{
125 Flags = other.Flags;
126 Error = other.Error;
127 Color = other.Color;
128
129 // Copy the custom colors owned by 'other', if any.
130 //
131 CustColorsArray = other.CustColorsArray;
132
133 // If 'other' is using its custom colors, 'this' will use its custom colors too.
134 // Otherwise, both will use the same external custom colors.
135 //
136 bool custColorsArrayInUse = (!other.CustColorsArray.empty() && other.CustColors == &other.CustColorsArray[0]);
137 CustColors = custColorsArrayInUse ? &CustColorsArray[0] : other.CustColors;
138
139 return *this;
140}
141
142} // OWL namespace
143///////////////////////////////////////////
144
#define DIAG_DECLARE_GROUP(group)
Definition checks.h:404
#define TRACEX(group, level, message)
Definition checks.h:263
Definition of Choose Color Common Dialog class.
Defines information necessary to initialize the dialog box with the user's color selection.
Definition chooseco.h:43
uint32 Flags
Flags can be a combination of the following values that control the appearance and functionality of t...
Definition chooseco.h:60
TColor * CustColors
Points to an array of 16 colors.
Definition chooseco.h:76
TData & operator=(const TData &other)
Definition chooseco.cpp:123
uint32 Error
If the dialog box is successfully executed, Error is 0.
Definition chooseco.h:69
TColor Color
Specifies the color that is initially selected when the dialog box is created.
Definition chooseco.h:73
TData(uint32 flags=0, bool allocCustColor=false)
Definition chooseco.h:193
Wrapper for the Choose-Color common dialog.
Definition chooseco.h:38
static uint SetRGBMsgId
Registered messages this class sends (to itself)
Definition chooseco.h:111
void Init(TResId templateId)
Definition chooseco.cpp:50
auto DoExecute() -> int override
Execute the dialog to retrieve user's choice of color.
Definition chooseco.cpp:103
~TChooseColorDialog() override
Destructor does nothing in non diagnostic versions of the library.
Definition chooseco.cpp:78
auto DialogFunction(TMsgId, TParam1, TParam2) -> INT_PTR override
Override the virtual DialogFunction.
Definition chooseco.cpp:90
CHOOSECOLOR Cc
New name.
Definition chooseco.h:119
TChooseColorDialog(TWindow *parent, TData &data, TResId templateId=0, LPCTSTR title=0, TModule *module=0)
Initialize the choose color common dialog data members.
Definition chooseco.cpp:28
Derived from TDialog, TCommonDialog is the abstract base class for TCommonDialog objects.
Definition commdial.h:62
virtual INT_PTR DialogFunction(TMsgId, TParam1, TParam2)
Override this to process messages within the dialog function.
Definition dialog.cpp:353
static INT_PTR CALLBACK StdDlgProc(HWND, UINT, WPARAM, LPARAM) noexcept
Callback procs for hooking TDialog to native window.
Definition dialog.cpp:440
ObjectWindows dynamic-link libraries (DLLs) construct an instance of TModule, which acts as an object...
Definition module.h:75
TWindow, derived from TEventHandler and TStreamableBase, provides window-specific behavior and encaps...
Definition window.h:414
TWindow * GetParentO() const
Return the OWL's parent for this window.
Definition window.h:2006
TModule * GetModule() const
Returns a pointer to the module object.
Definition window.h:1841
HWND GetHandle() const
Returns the handle of the window.
Definition window.h:2020
#define DEFINE_RESPONSE_TABLE1(cls, base)
Macro to define a response table for a class with one base.
Definition eventhan.h:492
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
UINT TMsgId
Message ID type.
Definition dispatch.h:53
LPARAM TParam2
Second parameter type.
Definition dispatch.h:55
WPARAM TParam1
First parameter type.
Definition dispatch.h:54
OWL_DIAGINFO
Definition animctrl.cpp:14
END_RESPONSE_TABLE
Definition button.cpp:26
std::string tstring
Definition defs.h:79
unsigned int uint
Definition number.h:25
#define OWL_CDLEVEL
Definition defs.h:171